diff --git a/spec/stdlib/fs-utils-spec.coffee b/spec/stdlib/fs-utils-spec.coffee index ff85ca850..1e214e1dc 100644 --- a/spec/stdlib/fs-utils-spec.coffee +++ b/spec/stdlib/fs-utils-spec.coffee @@ -124,9 +124,22 @@ describe "fs", -> expect(fs.md5ForPath(require.resolve('fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b' describe ".list(path, extensions)", -> - it "returns the paths with the specified extensions", -> - path = require.resolve('fixtures/css.css') - expect(fs.list(fs.resolveOnLoadPath('fixtures'), ['.css'])).toEqual [path] + it "returns the absolute paths of entries within the given directory", -> + paths = fs.list(project.getPath()) + expect(paths).toContain project.resolve('css.css') + expect(paths).toContain project.resolve('coffee.coffee') + expect(paths).toContain project.resolve('two-hundred.txt') + + it "returns undefined for paths that aren't directories or don't exist", -> + expect(fs.list(project.resolve('sample.js'))).toBeUndefined() + expect(fs.list('/non/existent/directory')).toBeUndefined() + + it "can filter the paths by an optional array of file extensions", -> + paths = fs.list(project.getPath(), ['.css', 'coffee']) + expect(paths).toContain project.resolve('css.css') + expect(paths).toContain project.resolve('coffee.coffee') + expect(path).toMatch /(css|coffee)$/ for path in paths + describe ".listAsync(path, [extensions,] callback)", -> paths = null diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 29bb42195..f063296ad 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -43,19 +43,19 @@ class AtomPackage extends Package loadStylesheets: -> stylesheetDirPath = fs.join(@path, 'stylesheets') - for stylesheetPath in fs.list(stylesheetDirPath) + for stylesheetPath in fs.list(stylesheetDirPath) ? [] requireStylesheet(stylesheetPath) loadGrammars: -> grammarsDirPath = fs.join(@path, 'grammars') - for grammarPath in fs.list(grammarsDirPath, ['.cson', '.json']) + for grammarPath in fs.list(grammarsDirPath, ['.cson', '.json']) ? [] grammarContent = fs.readObject(grammarPath) grammar = new TextMateGrammar(grammarContent) syntax.addGrammar(grammar) loadScopedProperties: -> scopedPropertiessDirPath = fs.join(@path, 'scoped-properties') - for scopedPropertiesPath in fs.list(scopedPropertiessDirPath, ['.cson', '.json']) + for scopedPropertiesPath in fs.list(scopedPropertiessDirPath, ['.cson', '.json']) ? [] for selector, properties of fs.readObject(scopedPropertiesPath) syntax.addProperties(selector, properties) diff --git a/src/app/keymap.coffee b/src/app/keymap.coffee index f83181d50..ec260f417 100644 --- a/src/app/keymap.coffee +++ b/src/app/keymap.coffee @@ -37,7 +37,7 @@ class Keymap @loadDirectory(fs.join(config.configDirPath, 'keymaps')) loadDirectory: (directoryPath) -> - @load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json']) + @load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json']) ? [] load: (path) -> @add(CSON.readObject(path)) diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index b85a896db..724b5e7bb 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -81,16 +81,10 @@ module.exports = # Returns an array with all the names of files contained # in the directory path. list: (rootPath, extensions) -> - paths = [] - if extensions - onPath = (path) => - paths.push(path) if _.contains(extensions, @extension(path)) - false - else - onPath = (path) => - paths.push(path) - false - @traverseTreeSync(rootPath, onPath, onPath) + return unless @isDirectory(rootPath) + paths = fs.readdirSync(rootPath) + paths = @filterExtensions(paths, extensions) if extensions + paths = paths.map (path) => @join(rootPath, path) paths listAsync: (rootPath, rest...) ->