Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 5cf83aa

Browse files
author
Wliu
authored
Merge pull request #729 from FrederickGeek8/master
Textmate conversion error reporting & apm list --enabled
2 parents ec68b90 + 58fad18 commit 5cf83aa

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

spec/list-spec.coffee

+26
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ describe 'apm list', ->
8888
listPackages [], ->
8989
expect(console.log.argsForCall[1][0]).toContain 'test-module@1.0.0 (disabled)'
9090

91+
it 'displays only enabled packages when --enabled is called', ->
92+
atomPackages =
93+
'test-module':
94+
metadata:
95+
name: 'test-module'
96+
version: '1.0.0'
97+
'test2-module':
98+
metadata:
99+
name: 'test2-module'
100+
version: '1.0.0'
101+
102+
fs.writeFileSync(path.join(resourcePath, 'package.json'), JSON.stringify(_atomPackages: atomPackages))
103+
104+
packagesPath = path.join(atomHome, 'packages')
105+
fs.makeTreeSync(packagesPath)
106+
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module'), path.join(packagesPath, 'test-module'))
107+
configPath = path.join(atomHome, 'config.cson')
108+
CSON.writeFileSync configPath, '*':
109+
core: disabledPackages: ["test-module"]
110+
111+
listPackages ['--enabled'], ->
112+
expect(console.log.argsForCall[1][0]).toContain 'test2-module@1.0.0'
113+
expect(console.log.argsForCall[4][0]).toContain 'dev-package@1.0.0'
114+
expect(console.log.argsForCall[7][0]).toContain 'user-package@1.0.0'
115+
expect(console.log.argsForCall[10][0]).toContain 'git-package@1.0.0'
116+
91117
it 'lists packages in json format when --json is passed', ->
92118
listPackages ['--json'], ->
93119
json = JSON.parse(console.log.argsForCall[0][0])

src/list.coffee

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ class List extends Command
3030
apm list --themes
3131
apm list --packages
3232
apm list --installed
33+
apm list --installed --enabled
3334
apm list --installed --bare > my-packages.txt
3435
apm list --json
3536
3637
List all the installed packages and also the packages bundled with Atom.
3738
"""
3839
options.alias('b', 'bare').boolean('bare').describe('bare', 'Print packages one per line with no formatting')
40+
options.alias('e', 'enabled').boolean('enabled').describe('enabled', 'Print only enabled packages')
3941
options.alias('d', 'dev').boolean('dev').default('dev', true).describe('dev', 'Include dev packages')
4042
options.alias('h', 'help').describe('help', 'Print this usage message')
4143
options.alias('i', 'installed').boolean('installed').describe('installed', 'Only list installed packages/themes')
@@ -81,11 +83,14 @@ class List extends Command
8183
manifest ?= {}
8284
manifest.name = child
8385
if options.argv.themes
84-
packages.push(manifest) if manifest.theme
86+
if manifest.theme and not (options.argv.enabled and @isPackageDisabled(manifest.name))
87+
packages.push(manifest)
8588
else if options.argv.packages
86-
packages.push(manifest) unless manifest.theme
89+
unless manifest.theme or (options.argv.enabled and @isPackageDisabled(manifest.name))
90+
packages.push(manifest)
8791
else
88-
packages.push(manifest)
92+
unless options.argv.enabled and @isPackageDisabled(manifest.name)
93+
packages.push(manifest)
8994

9095
packages
9196

@@ -114,18 +119,20 @@ class List extends Command
114119
callback?(null, gitPackages)
115120

116121
listBundledPackages: (options, callback) ->
117-
config.getResourcePath (resourcePath) ->
122+
config.getResourcePath (resourcePath) =>
118123
try
119124
metadataPath = path.join(resourcePath, 'package.json')
120125
{_atomPackages} = JSON.parse(fs.readFileSync(metadataPath))
121126
_atomPackages ?= {}
122127
packages = (metadata for packageName, {metadata} of _atomPackages)
123128

124-
packages = packages.filter (metadata) ->
129+
packages = packages.filter (metadata) =>
125130
if options.argv.themes
126131
metadata.theme
127132
else if options.argv.packages
128133
not metadata.theme
134+
else if options.argv.enabled
135+
not @isPackageDisabled(metadata.name)
129136
else
130137
true
131138

src/package-converter.coffee

+10-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ class PackageConverter
162162
extension = path.extname(child)
163163
name = path.basename(child, extension)
164164

165-
selector = new ScopeSelector(scope).toCssSelector() if scope
165+
try
166+
selector = new ScopeSelector(scope).toCssSelector() if scope
167+
catch e
168+
e.message = "In file #{e.fileName} at #{JSON.stringify(scope)}: #{e.message}"
169+
throw e
166170
selector ?= '*'
167171

168172
snippetsBySelector[selector] ?= {}
@@ -184,7 +188,11 @@ class PackageConverter
184188
continue unless scope and settings
185189

186190
if properties = @convertSettings(settings)
187-
selector = new ScopeSelector(scope).toCssSelector()
191+
try
192+
selector = new ScopeSelector(scope).toCssSelector()
193+
catch e
194+
e.message = "In file #{e.fileName} at #{JSON.stringify(scope)}: #{e.message}"
195+
throw e
188196
for key, value of properties
189197
preferencesBySelector[selector] ?= {}
190198
if preferencesBySelector[selector][key]?

0 commit comments

Comments
 (0)