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.
This commit is contained in:
Kevin Sawicki 2013-02-06 18:30:07 -08:00 committed by Corey Johnson & Kevin Sawicki
parent 856b378f54
commit d884bf58e8
3 changed files with 10 additions and 4 deletions

View File

@ -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)

View File

@ -1,7 +1,4 @@
AtomPackage = require 'atom-package'
module.exports =
class StripTrailingWhitespace extends AtomPackage
activate: (rootView) ->
rootView.eachBuffer (buffer) => @stripTrailingWhitespaceBeforeSave(buffer)

View File

@ -0,0 +1 @@
'main': 'strip-trailing-whitespace/lib/strip-trailing-whitespace'