From d884bf58e886164a91738f5e2260a1520abe27a2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Feb 2013 18:30:07 -0800 Subject: [PATCH] Support specifying main module in package.cson Migrated strip-trailing-whitespace package to include a package.cson with a main being a file in the lib directory instead of the index.coffee at the root of the package. --- src/app/atom-package.coffee | 10 +++++++++- .../strip-trailing-whitespace.coffee} | 3 --- src/packages/strip-trailing-whitespace/package.cson | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) rename src/packages/strip-trailing-whitespace/{index.coffee => lib/strip-trailing-whitespace.coffee} (87%) create mode 100644 src/packages/strip-trailing-whitespace/package.cson diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 291bb7ae4..4b0ebe55b 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -16,11 +16,19 @@ class AtomPackage extends Package @loadMetadata() @loadKeymaps() @loadStylesheets() if @autoloadStylesheets - rootView?.activatePackage(@name, this) if require.resolve(@path) + if packageMain = @getPackageMain() + rootView?.activatePackage(@name, packageMain) catch e console.warn "Failed to load package named '#{@name}'", e.stack this + getPackageMain: -> + mainPath = require.resolve(@metadata.main) if @metadata.main + if mainPath + require(mainPath) + else if require.resolve(@path) + this + loadMetadata: -> if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json']) @metadata = fs.readObject(metadataPath) diff --git a/src/packages/strip-trailing-whitespace/index.coffee b/src/packages/strip-trailing-whitespace/lib/strip-trailing-whitespace.coffee similarity index 87% rename from src/packages/strip-trailing-whitespace/index.coffee rename to src/packages/strip-trailing-whitespace/lib/strip-trailing-whitespace.coffee index 20b3e6d74..bf01c6bbe 100644 --- a/src/packages/strip-trailing-whitespace/index.coffee +++ b/src/packages/strip-trailing-whitespace/lib/strip-trailing-whitespace.coffee @@ -1,7 +1,4 @@ -AtomPackage = require 'atom-package' - module.exports = -class StripTrailingWhitespace extends AtomPackage activate: (rootView) -> rootView.eachBuffer (buffer) => @stripTrailingWhitespaceBeforeSave(buffer) diff --git a/src/packages/strip-trailing-whitespace/package.cson b/src/packages/strip-trailing-whitespace/package.cson new file mode 100644 index 000000000..25e3026d8 --- /dev/null +++ b/src/packages/strip-trailing-whitespace/package.cson @@ -0,0 +1 @@ +'main': 'strip-trailing-whitespace/lib/strip-trailing-whitespace'