diff --git a/spec/app/config-spec.coffee b/spec/app/config-spec.coffee index 30eadd6c7..6da04c8da 100644 --- a/spec/app/config-spec.coffee +++ b/spec/app/config-spec.coffee @@ -1,5 +1,6 @@ fs = require 'fs' fsUtils = require 'fs-utils' +path = require 'path' describe "Config", -> describe ".get(keyPath)", -> @@ -81,7 +82,7 @@ describe "Config", -> describe "when ~/.atom/config.json exists", -> it "writes any non-default properties to ~/.atom/config.json", -> - config.configFilePath = fsUtils.join(config.configDirPath, "config.json") + config.configFilePath = path.join(config.configDirPath, "config.json") config.set("a.b.c", 1) config.set("a.b.d", 2) config.set("x.y.z", 3) @@ -90,13 +91,13 @@ describe "Config", -> fs.writeFileSync.reset() config.save() - expect(fs.writeFileSync.argsForCall[0][0]).toBe(fsUtils.join(config.configDirPath, "config.json")) + expect(fs.writeFileSync.argsForCall[0][0]).toBe(path.join(config.configDirPath, "config.json")) writtenConfig = JSON.parse(fs.writeFileSync.argsForCall[0][1]) expect(writtenConfig).toEqual config.settings describe "when ~/.atom/config.json doesn't exist", -> it "writes any non-default properties to ~/.atom/config.cson", -> - config.configFilePath = fsUtils.join(config.configDirPath, "config.cson") + config.configFilePath = path.join(config.configDirPath, "config.cson") config.set("a.b.c", 1) config.set("a.b.d", 2) config.set("x.y.z", 3) @@ -105,7 +106,7 @@ describe "Config", -> fs.writeFileSync.reset() config.save() - expect(fs.writeFileSync.argsForCall[0][0]).toBe(fsUtils.join(config.configDirPath, "config.cson")) + expect(fs.writeFileSync.argsForCall[0][0]).toBe(path.join(config.configDirPath, "config.cson")) CoffeeScript = require 'coffee-script' writtenConfig = CoffeeScript.eval(fs.writeFileSync.argsForCall[0][1], bare: true) expect(writtenConfig).toEqual config.settings @@ -176,10 +177,10 @@ describe "Config", -> runs -> expect(fsUtils.exists(config.configDirPath)).toBeTruthy() - expect(fsUtils.exists(fsUtils.join(config.configDirPath, 'packages'))).toBeTruthy() - expect(fsUtils.exists(fsUtils.join(config.configDirPath, 'snippets'))).toBeTruthy() - expect(fsUtils.exists(fsUtils.join(config.configDirPath, 'themes'))).toBeTruthy() - expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'config.cson'))).toBeTruthy() + expect(fsUtils.exists(path.join(config.configDirPath, 'packages'))).toBeTruthy() + expect(fsUtils.exists(path.join(config.configDirPath, 'snippets'))).toBeTruthy() + expect(fsUtils.exists(path.join(config.configDirPath, 'themes'))).toBeTruthy() + expect(fsUtils.isFile(path.join(config.configDirPath, 'config.cson'))).toBeTruthy() it "copies the bundles themes to ~/.atom", -> initializationDone = false @@ -190,15 +191,15 @@ describe "Config", -> waitsFor -> initializationDone runs -> - expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'themes/atom-dark-ui/package.cson'))).toBeTruthy() - expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'themes/atom-light-ui/package.cson'))).toBeTruthy() - expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'themes/atom-dark-syntax.less'))).toBeTruthy() - expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'themes/atom-light-syntax.less'))).toBeTruthy() + expect(fsUtils.isFile(path.join(config.configDirPath, 'themes/atom-dark-ui/package.cson'))).toBeTruthy() + expect(fsUtils.isFile(path.join(config.configDirPath, 'themes/atom-light-ui/package.cson'))).toBeTruthy() + expect(fsUtils.isFile(path.join(config.configDirPath, 'themes/atom-dark-syntax.less'))).toBeTruthy() + expect(fsUtils.isFile(path.join(config.configDirPath, 'themes/atom-light-syntax.less'))).toBeTruthy() describe ".loadUserConfig()", -> beforeEach -> config.configDirPath = '/tmp/dot-atom-dir' - config.configFilePath = fsUtils.join(config.configDirPath, "config.cson") + config.configFilePath = path.join(config.configDirPath, "config.cson") expect(fsUtils.exists(config.configDirPath)).toBeFalsy() afterEach -> @@ -228,7 +229,7 @@ describe "Config", -> beforeEach -> config.configDirPath = '/tmp/dot-atom-dir' - config.configFilePath = fsUtils.join(config.configDirPath, "config.cson") + config.configFilePath = path.join(config.configDirPath, "config.cson") expect(fsUtils.exists(config.configDirPath)).toBeFalsy() fsUtils.write(config.configFilePath, "foo: bar: 'baz'") config.loadUserConfig() diff --git a/spec/app/directory-spec.coffee b/spec/app/directory-spec.coffee index a56eee671..277f2e7de 100644 --- a/spec/app/directory-spec.coffee +++ b/spec/app/directory-spec.coffee @@ -1,5 +1,6 @@ Directory = require 'directory' fsUtils = require 'fs-utils' +path = require 'path' describe "Directory", -> directory = null @@ -14,7 +15,7 @@ describe "Directory", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures'), 'temporary') + temporaryFilePath = path.join(fsUtils.resolveOnLoadPath('fixtures'), 'temporary') fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) afterEach -> @@ -40,7 +41,7 @@ describe "Directory", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fsUtils.join(directory.path, 'temporary') + temporaryFilePath = path.join(directory.path, 'temporary') fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) afterEach -> diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 6921e1779..a4a95b965 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -83,9 +83,9 @@ describe "Editor", -> describe "when the activeEditSession's file is modified on disk", -> it "triggers an alert", -> - path = "/tmp/atom-changed-file.txt" - fsUtils.write(path, "") - editSession = project.open(path) + filePath = "/tmp/atom-changed-file.txt" + fsUtils.write(filePath, "") + editSession = project.open(filePath) editor.edit(editSession) editor.insertText("now the buffer is modified") @@ -94,7 +94,7 @@ describe "Editor", -> spyOn(atom, "confirm") - fsUtils.write(path, "a file change") + fsUtils.write(filePath, "a file change") waitsFor "file to trigger contents-changed event", -> fileChangeHandler.callCount > 0 @@ -148,9 +148,9 @@ describe "Editor", -> expect(editor.lineElementForScreenRow(3).text()).toMatch /^ vgoodbyear/ it "triggers alert if edit session's buffer goes into conflict with changes on disk", -> - path = "/tmp/atom-changed-file.txt" - fsUtils.write(path, "") - tempEditSession = project.open(path) + filePath = "/tmp/atom-changed-file.txt" + fsUtils.write(filePath, "") + tempEditSession = project.open(filePath) editor.edit(tempEditSession) tempEditSession.insertText("a buffer change") @@ -158,7 +158,7 @@ describe "Editor", -> contentsConflictedHandler = jasmine.createSpy("contentsConflictedHandler") tempEditSession.on 'contents-conflicted', contentsConflictedHandler - fsUtils.write(path, "a file change") + fsUtils.write(filePath, "a file change") waitsFor -> contentsConflictedHandler.callCount > 0 @@ -241,24 +241,25 @@ describe "Editor", -> expect(openHandler).not.toHaveBeenCalled() describe "editor:path-changed event", -> - path = null + filePath = null + beforeEach -> - path = "/tmp/something.txt" - fsUtils.write(path, path) + filePath = "/tmp/something.txt" + fsUtils.write(filePath, filePath) afterEach -> - fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(filePath) if fsUtils.exists(filePath) it "emits event when buffer's path is changed", -> eventHandler = jasmine.createSpy('eventHandler') editor.on 'editor:path-changed', eventHandler - editor.getBuffer().saveAs(path) + editor.getBuffer().saveAs(filePath) expect(eventHandler).toHaveBeenCalled() it "emits event when editor receives a new buffer", -> eventHandler = jasmine.createSpy('eventHandler') editor.on 'editor:path-changed', eventHandler - editor.edit(project.open(path)) + editor.edit(project.open(filePath)) expect(eventHandler).toHaveBeenCalled() it "stops listening to events on previously set buffers", -> @@ -266,7 +267,7 @@ describe "Editor", -> oldBuffer = editor.getBuffer() editor.on 'editor:path-changed', eventHandler - editor.edit(project.open(path)) + editor.edit(project.open(filePath)) expect(eventHandler).toHaveBeenCalled() eventHandler.reset() @@ -279,7 +280,7 @@ describe "Editor", -> it "loads the grammar for the new path", -> expect(editor.getGrammar().name).toBe 'JavaScript' - editor.getBuffer().saveAs(path) + editor.getBuffer().saveAs(filePath) expect(editor.getGrammar().name).toBe 'Plain Text' describe "font family", -> @@ -2074,15 +2075,15 @@ describe "Editor", -> expect(editor.getFirstVisibleScreenRow()).toBe(0) describe ".checkoutHead()", -> - [path, originalPathText] = [] + [filePath, originalPathText] = [] beforeEach -> - path = project.resolve('git/working-dir/file.txt') - originalPathText = fsUtils.read(path) - editor.edit(project.open(path)) + filePath = project.resolve('git/working-dir/file.txt') + originalPathText = fsUtils.read(filePath) + editor.edit(project.open(filePath)) afterEach -> - fsUtils.write(path, originalPathText) + fsUtils.write(filePath, originalPathText) it "restores the contents of the editor to the HEAD revision", -> editor.setText('') @@ -2190,19 +2191,19 @@ describe "Editor", -> expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [12,2]] describe ".reloadGrammar()", -> - [path] = [] + [filePath] = [] beforeEach -> - path = fsUtils.join(fsUtils.absolute("/tmp"), "grammar-change.txt") - fsUtils.write(path, "var i;") + filePath = path.join(fsUtils.absolute("/tmp"), "grammar-change.txt") + fsUtils.write(filePath, "var i;") afterEach -> - fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(filePath) if fsUtils.exists(filePath) it "updates all the rendered lines when the grammar changes", -> - editor.edit(project.open(path)) + editor.edit(project.open(filePath)) expect(editor.getGrammar().name).toBe 'Plain Text' - syntax.setGrammarOverrideForPath(path, 'source.js') + syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(editor.getGrammar().name).toBe 'JavaScript' @@ -2220,7 +2221,7 @@ describe "Editor", -> expect(editor.getGrammar().name).toBe 'JavaScript' it "emits an editor:grammar-changed event when updated", -> - editor.edit(project.open(path)) + editor.edit(project.open(filePath)) eventHandler = jasmine.createSpy('eventHandler') editor.on('editor:grammar-changed', eventHandler) @@ -2228,7 +2229,7 @@ describe "Editor", -> expect(eventHandler).not.toHaveBeenCalled() - syntax.setGrammarOverrideForPath(path, 'source.js') + syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(eventHandler).toHaveBeenCalled() diff --git a/spec/app/file-spec.coffee b/spec/app/file-spec.coffee index 4c429fa83..47d2fd4c8 100644 --- a/spec/app/file-spec.coffee +++ b/spec/app/file-spec.coffee @@ -6,7 +6,7 @@ describe 'File', -> [filePath, file] = [] beforeEach -> - filePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test + filePath = path.join(fsUtils.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test fsUtils.remove(filePath) if fsUtils.exists(filePath) fsUtils.write(filePath, "this is old!") file = new File(filePath) @@ -47,7 +47,7 @@ describe 'File', -> newPath = null beforeEach -> - newPath = fsUtils.join(path.dirname(filePath), "atom-file-was-moved-test.txt") + newPath = path.join(path.dirname(filePath), "atom-file-was-moved-test.txt") afterEach -> if fsUtils.exists(newPath) diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 3b1064dd5..da714fc39 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -1,5 +1,6 @@ Git = require 'git' fsUtils = require 'fs-utils' +path = require 'path' Task = require 'task' describe "Git", -> @@ -48,40 +49,40 @@ describe "Git", -> expect(repo.isPathIgnored('b.txt')).toBeFalsy() describe ".isPathModified(path)", -> - [repo, path, newPath, originalPathText] = [] + [repo, filePath, newPath, originalPathText] = [] beforeEach -> repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) - path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - newPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') - originalPathText = fsUtils.read(path) + filePath = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + newPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') + originalPathText = fsUtils.read(filePath) afterEach -> - fsUtils.write(path, originalPathText) + fsUtils.write(filePath, originalPathText) fsUtils.remove(newPath) if fsUtils.exists(newPath) describe "when the path is unstaged", -> it "returns false if the path has not been modified", -> - expect(repo.isPathModified(path)).toBeFalsy() + expect(repo.isPathModified(filePath)).toBeFalsy() it "returns true if the path is modified", -> - fsUtils.write(path, "change") - expect(repo.isPathModified(path)).toBeTruthy() + fsUtils.write(filePath, "change") + expect(repo.isPathModified(filePath)).toBeTruthy() it "returns true if the path is deleted", -> - fsUtils.remove(path) - expect(repo.isPathModified(path)).toBeTruthy() + fsUtils.remove(filePath) + expect(repo.isPathModified(filePath)).toBeTruthy() it "returns false if the path is new", -> expect(repo.isPathModified(newPath)).toBeFalsy() describe ".isPathNew(path)", -> - [path, newPath] = [] + [filePath, newPath] = [] beforeEach -> repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) - path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - newPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') + filePath = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + newPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') fsUtils.write(newPath, "i'm new here") afterEach -> @@ -92,7 +93,7 @@ describe "Git", -> expect(repo.isPathNew(newPath)).toBeTruthy() it "returns false if the path isn't new", -> - expect(repo.isPathNew(path)).toBeFalsy() + expect(repo.isPathNew(filePath)).toBeFalsy() describe ".checkoutHead(path)", -> [path1, path2, originalPath1Text, originalPath2Text] = [] @@ -146,28 +147,28 @@ describe "Git", -> expect(-> repo.getHead()).toThrow() describe ".getDiffStats(path)", -> - [path, originalPathText] = [] + [filePath, originalPathText] = [] beforeEach -> repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) - path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - originalPathText = fsUtils.read(path) + filePath = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + originalPathText = fsUtils.read(filePath) afterEach -> fsUtils.write(path, originalPathText) it "returns the number of lines added and deleted", -> - expect(repo.getDiffStats(path)).toEqual {added: 0, deleted: 0} + expect(repo.getDiffStats(filePath)).toEqual {added: 0, deleted: 0} fsUtils.write(path, "#{originalPathText} edited line") - expect(repo.getDiffStats(path)).toEqual {added: 1, deleted: 1} + expect(repo.getDiffStats(filePath)).toEqual {added: 1, deleted: 1} describe ".getPathStatus(path)", -> - [path, originalPathText] = [] + [filePath, originalPathText] = [] beforeEach -> repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - originalPathText = fsUtils.read(path) + originalPathText = fsUtils.read(filePath) afterEach -> fsUtils.write(path, originalPathText) @@ -176,12 +177,12 @@ describe "Git", -> statusHandler = jasmine.createSpy("statusHandler") repo.on 'status-changed', statusHandler fsUtils.write(path, '') - status = repo.getPathStatus(path) + status = repo.getPathStatus(filePath) expect(statusHandler.callCount).toBe 1 expect(statusHandler.argsForCall[0][0..1]).toEqual [path, status] fsUtils.write(path, 'abc') - status = repo.getPathStatus(path) + status = repo.getPathStatus(filePath) expect(statusHandler.callCount).toBe 1 describe ".refreshStatus()", -> diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index 8909adf0c..22e7cae75 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -115,9 +115,9 @@ describe "Project", -> describe ".relativize(path)", -> it "returns an relative path based on the project's root", -> absolutePath = fsUtils.resolveOnLoadPath('fixtures/dir') - expect(project.relativize(fsUtils.join(absolutePath, "b"))).toBe "b" - expect(project.relativize(fsUtils.join(absolutePath, "b/file.coffee"))).toBe "b/file.coffee" - expect(project.relativize(fsUtils.join(absolutePath, "file.coffee"))).toBe "file.coffee" + expect(project.relativize(path.join(absolutePath, "b"))).toBe "b" + expect(project.relativize(path.join(absolutePath, "b/file.coffee"))).toBe "b/file.coffee" + expect(project.relativize(path.join(absolutePath, "file.coffee"))).toBe "file.coffee" describe ".setPath(path)", -> describe "when path is a file", -> @@ -173,7 +173,7 @@ describe "Project", -> ignoredFile = null beforeEach -> - ignoredFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored.txt') + ignoredFile = path.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored.txt') fsUtils.write(ignoredFile, "") afterEach -> @@ -192,7 +192,7 @@ describe "Project", -> ignoredFile = null beforeEach -> - ignoredFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored/ignored.txt') + ignoredFile = path.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored/ignored.txt') fsUtils.write(ignoredFile, "") afterEach -> @@ -246,9 +246,9 @@ describe "Project", -> paths = [] matches = [] waitsForPromise -> - project.scan /evil/, ({path, match, range}) -> - paths.push(path) - matches.push(match) + project.scan /evil/, (result) -> + paths.push(result.path) + matches.push(result.match) runs -> expect(paths.length).toBe 5 @@ -284,7 +284,7 @@ describe "Project", -> beforeEach -> projectPath = fsUtils.resolveOnLoadPath('fixtures/git/working-dir') - ignoredPath = fsUtils.join(projectPath, 'ignored.txt') + ignoredPath = path.join(projectPath, 'ignored.txt') fsUtils.write(ignoredPath, 'this match should not be included') afterEach -> @@ -306,7 +306,7 @@ describe "Project", -> it "includes files and folders that begin with a '.'", -> projectPath = '/tmp/atom-tests/folder-with-dot-file' - filePath = fsUtils.join(projectPath, '.text') + filePath = path.join(projectPath, '.text') fsUtils.write(filePath, 'match this') project.setPath(projectPath) paths = [] @@ -323,7 +323,7 @@ describe "Project", -> it "excludes values in core.ignoredNames", -> projectPath = '/tmp/atom-tests/folder-with-dot-git/.git' - filePath = fsUtils.join(projectPath, 'test.txt') + filePath = path.join(projectPath, 'test.txt') fsUtils.write(filePath, 'match this') project.setPath(projectPath) paths = [] diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index de910eda9..71abdbc20 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -45,19 +45,19 @@ describe 'TextBuffer', -> expect(buffer .getText()).toBe "" describe "path-changed event", -> - [path, newPath, bufferToChange, eventHandler] = [] + [filePath, newPath, bufferToChange, eventHandler] = [] beforeEach -> - path = fsUtils.join(fsUtils.resolveOnLoadPath("fixtures"), "atom-manipulate-me") - newPath = "#{path}-i-moved" - fsUtils.write(path, "") - bufferToChange = project.bufferForPath(path) + filePath = path.join(fsUtils.resolveOnLoadPath("fixtures"), "atom-manipulate-me") + newPath = "#{filePath}-i-moved" + fsUtils.write(filePath, "") + bufferToChange = project.bufferForPath(filePath) eventHandler = jasmine.createSpy('eventHandler') bufferToChange.on 'path-changed', eventHandler afterEach -> bufferToChange.destroy() - fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(filePath) if fsUtils.exists(filePath) fsUtils.remove(newPath) if fsUtils.exists(newPath) it "triggers a `path-changed` event when path is changed", -> @@ -68,7 +68,7 @@ describe 'TextBuffer', -> jasmine.unspy(window, "setTimeout") fsUtils.remove(newPath) if fsUtils.exists(newPath) - fsUtils.move(path, newPath) + fsUtils.move(filePath, newPath) waitsFor "buffer path change", -> eventHandler.callCount > 0 @@ -77,17 +77,18 @@ describe 'TextBuffer', -> expect(eventHandler).toHaveBeenCalledWith(bufferToChange) describe "when the buffer's on-disk contents change", -> - path = null + filePath = null + beforeEach -> - path = "/tmp/tmp.txt" - fsUtils.write(path, "first") + filePath = "/tmp/tmp.txt" + fsUtils.write(filePath, "first") buffer.release() - buffer = project.bufferForPath(path).retain() + buffer = project.bufferForPath(filePath).retain() afterEach -> buffer.release() buffer = null - fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(filePath) if fsUtils.exists(filePath) it "does not trigger a change event when Atom modifies the file", -> buffer.insert([0,0], "HELLO!") @@ -103,7 +104,7 @@ describe 'TextBuffer', -> it "changes the memory contents of the buffer to match the new disk contents and triggers a 'changed' event", -> changeHandler = jasmine.createSpy('changeHandler') buffer.on 'changed', changeHandler - fsUtils.write(path, "second") + fsUtils.write(filePath, "second") expect(changeHandler.callCount).toBe 0 waitsFor "file to trigger change event", -> @@ -123,7 +124,7 @@ describe 'TextBuffer', -> buffer.file.on 'contents-changed', fileChangeHandler buffer.insert([0, 0], "a change") - fsUtils.write(path, "second") + fsUtils.write(filePath, "second") expect(fileChangeHandler.callCount).toBe 0 waitsFor "file to trigger 'contents-changed' event", -> @@ -138,7 +139,7 @@ describe 'TextBuffer', -> buffer.insert([0, 0], "a second change") handler = jasmine.createSpy('fileChange') - fsUtils.write(path, "second") + fsUtils.write(filePath, "second") buffer.on 'contents-conflicted', handler expect(handler.callCount).toBe 0 @@ -149,20 +150,20 @@ describe 'TextBuffer', -> expect(handler.callCount).toBe 1 describe "when the buffer's file is deleted (via another process)", -> - [path, bufferToDelete] = [] + [filePath, bufferToDelete] = [] beforeEach -> - path = "/tmp/atom-file-to-delete.txt" - fsUtils.write(path, 'delete me') - bufferToDelete = project.bufferForPath(path) - path = bufferToDelete.getPath() # symlinks may have been converted + filePath = "/tmp/atom-file-to-delete.txt" + fsUtils.write(filePath, 'delete me') + bufferToDelete = project.bufferForPath(filePath) + filePath = bufferToDelete.getPath() # symlinks may have been converted - expect(bufferToDelete.getPath()).toBe path + expect(bufferToDelete.getPath()).toBe filePath expect(bufferToDelete.isModified()).toBeFalsy() removeHandler = jasmine.createSpy('removeHandler') bufferToDelete.file.on 'removed', removeHandler - fsUtils.remove(path) + fsUtils.remove(filePath) waitsFor "file to be removed", -> removeHandler.callCount > 0 @@ -170,7 +171,7 @@ describe 'TextBuffer', -> bufferToDelete.destroy() it "retains its path and reports the buffer as modified", -> - expect(bufferToDelete.getPath()).toBe path + expect(bufferToDelete.getPath()).toBe filePath expect(bufferToDelete.isModified()).toBeTruthy() it "resumes watching of the file when it is re-saved", -> @@ -178,7 +179,7 @@ describe 'TextBuffer', -> expect(bufferToDelete.fileExists()).toBeTruthy() expect(bufferToDelete.isInConflict()).toBeFalsy() - fsUtils.write(path, 'moo') + fsUtils.write(filePath, 'moo') changeHandler = jasmine.createSpy('changeHandler') bufferToDelete.on 'changed', changeHandler diff --git a/spec/app/text-mate-theme-spec.coffee b/spec/app/text-mate-theme-spec.coffee index 0292c714b..73479358b 100644 --- a/spec/app/text-mate-theme-spec.coffee +++ b/spec/app/text-mate-theme-spec.coffee @@ -1,4 +1,5 @@ fsUtils = require 'fs-utils' +path = require 'path' plist = require 'plist' TextMateTheme = require 'text-mate-theme' Theme = require 'theme' @@ -7,7 +8,7 @@ describe "TextMateTheme", -> [theme, themePath] = [] beforeEach -> - themePath = fsUtils.resolveOnLoadPath(fsUtils.join('fixtures', 'test.tmTheme')) + themePath = fsUtils.resolveOnLoadPath(path.join('fixtures', 'test.tmTheme')) theme = Theme.load(themePath) afterEach -> diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index b447a8cf1..7cc60f88a 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -1,5 +1,6 @@ $ = require 'jquery' fsUtils = require 'fs-utils' +path = require 'path' Theme = require 'theme' describe "@load(name)", -> @@ -15,7 +16,7 @@ describe "@load(name)", -> it "applies the theme's stylesheet to the current window", -> expect($(".editor").css("background-color")).not.toBe("rgb(20, 20, 20)") - themePath = fsUtils.resolveOnLoadPath(fsUtils.join('fixtures', 'test.tmTheme')) + themePath = fsUtils.resolveOnLoadPath(path.join('fixtures', 'test.tmTheme')) theme = Theme.load(themePath) expect($(".editor").css("background-color")).toBe("rgb(20, 20, 20)") diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index f2449c51c..95b311226 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -1,6 +1,7 @@ $ = require 'jquery' {$$} = require 'space-pen' fsUtils = require 'fs-utils' +path = require 'path' {less} = require 'less' WindowEventHandler = require 'window-event-handler' @@ -114,7 +115,7 @@ describe "Window", -> describe ".removeStylesheet(path)", -> it "removes styling applied by given stylesheet path", -> - cssPath = require.resolve(fsUtils.join("fixtures", "css.css")) + cssPath = require.resolve(path.join("fixtures", "css.css")) expect($(document.body).css('font-weight')).not.toBe("bold") requireStylesheet(cssPath) diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index 7fc7cdadd..cbae9d571 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -2,14 +2,15 @@ require 'window' measure 'spec suite require time', -> fsUtils = require 'fs-utils' + path = require 'path' require 'spec-helper' # Run core specs - for path in fsUtils.listTree(fsUtils.resolveOnLoadPath("spec")) when /-spec\.coffee$/.test path - require path + for specPath in fsUtils.listTree(fsUtils.resolveOnLoadPath("spec")) when /-spec\.coffee$/.test specPath + require specPath # Run extension specs for packageDirPath in config.packageDirPaths for packagePath in fsUtils.list(packageDirPath) - for path in fsUtils.listTree(fsUtils.join(packagePath, "spec")) when /-spec\.coffee$/.test path - require path + for specPath in fsUtils.listTree(path.join(packagePath, "spec")) when /-spec\.coffee$/.test specPath + require specPath diff --git a/spec/stdlib/fs-utils-spec.coffee b/spec/stdlib/fs-utils-spec.coffee index 8d680c4f2..25a361b90 100644 --- a/spec/stdlib/fs-utils-spec.coffee +++ b/spec/stdlib/fs-utils-spec.coffee @@ -1,4 +1,5 @@ fsUtils = require 'fs-utils' +path = require 'path' describe "fsUtils", -> describe ".read(path)", -> @@ -12,13 +13,13 @@ describe "fsUtils", -> fixturesDir = fsUtils.resolveOnLoadPath('fixtures') it "returns true with a file path", -> - expect(fsUtils.isFile(fsUtils.join(fixturesDir, 'sample.js'))).toBe true + expect(fsUtils.isFile(path.join(fixturesDir, 'sample.js'))).toBe true it "returns false with a directory path", -> expect(fsUtils.isFile(fixturesDir)).toBe false it "returns false with a non-existent path", -> - expect(fsUtils.isFile(fsUtils.join(fixturesDir, 'non-existent'))).toBe false + expect(fsUtils.isFile(path.join(fixturesDir, 'non-existent'))).toBe false expect(fsUtils.isFile(null)).toBe false describe ".exists(path)", -> @@ -30,13 +31,6 @@ describe "fsUtils", -> expect(fsUtils.exists("")).toBe false expect(fsUtils.exists(null)).toBe false - describe ".join(paths...)", -> - it "concatenates the given paths with the directory separator", -> - expect(fsUtils.join('a')).toBe 'a' - expect(fsUtils.join('a', 'b', 'c')).toBe 'a/b/c' - expect(fsUtils.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d' - expect(fsUtils.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/' - describe ".split(path)", -> it "returns path components", -> expect(fsUtils.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"] @@ -79,11 +73,11 @@ describe "fsUtils", -> expect(path).not.toMatch /\/dir\// it "returns entries if path is a symlink", -> - symlinkPath = fsUtils.join(fixturesDir, 'symlink-to-dir') + symlinkPath = path.join(fixturesDir, 'symlink-to-dir') symlinkPaths = [] onSymlinkPath = (path) -> symlinkPaths.push(path.substring(symlinkPath.length + 1)) - regularPath = fsUtils.join(fixturesDir, 'dir') + regularPath = path.join(fixturesDir, 'dir') paths = [] onPath = (path) -> paths.push(path.substring(regularPath.length + 1)) diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 5d5b881d6..05ec367a6 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -1,6 +1,7 @@ TextMateGrammar = require 'text-mate-grammar' Package = require 'package' fsUtils = require 'fs-utils' +path = require 'path' _ = require 'underscore' $ = require 'jquery' CSON = require 'season' @@ -64,7 +65,7 @@ class AtomPackage extends Package @keymaps = @getKeymapPaths().map (path) -> [path, CSON.readFileSync(path)] getKeymapPaths: -> - keymapsDirPath = fsUtils.join(@path, 'keymaps') + keymapsDirPath = path.join(@path, 'keymaps') if @metadata.keymaps @metadata.keymaps.map (name) -> fsUtils.resolve(keymapsDirPath, name, ['json', 'cson', '']) else @@ -74,7 +75,7 @@ class AtomPackage extends Package @stylesheets = @getStylesheetPaths().map (path) -> [path, loadStylesheet(path)] getStylesheetPaths: -> - stylesheetDirPath = fsUtils.join(@path, 'stylesheets') + stylesheetDirPath = path.join(@path, 'stylesheets') if @metadata.stylesheets @metadata.stylesheets.map (name) -> fsUtils.resolve(stylesheetDirPath, name, ['css', 'less', '']) else @@ -82,13 +83,13 @@ class AtomPackage extends Package loadGrammars: -> @grammars = [] - grammarsDirPath = fsUtils.join(@path, 'grammars') + grammarsDirPath = path.join(@path, 'grammars') for grammarPath in fsUtils.list(grammarsDirPath, ['.json', '.cson']) @grammars.push(TextMateGrammar.loadSync(grammarPath)) loadScopedProperties: -> @scopedProperties = [] - scopedPropertiessDirPath = fsUtils.join(@path, 'scoped-properties') + scopedPropertiessDirPath = path.join(@path, 'scoped-properties') for scopedPropertiesPath in fsUtils.list(scopedPropertiessDirPath, ['.json', '.cson']) for selector, properties of fsUtils.readObject(scopedPropertiesPath) @scopedProperties.push([scopedPropertiesPath, selector, properties]) @@ -124,9 +125,9 @@ class AtomPackage extends Package @resolvedMainModulePath = true mainModulePath = if @metadata.main - fsUtils.join(@path, @metadata.main) + path.join(@path, @metadata.main) else - fsUtils.join(@path, 'index') + path.join(@path, 'index') @mainModulePath = fsUtils.resolveExtension(mainModulePath, ["", _.keys(require.extensions)...]) registerDeferredDeserializers: -> diff --git a/src/app/atom-theme.coffee b/src/app/atom-theme.coffee index 482c630b8..f82b1b6d8 100644 --- a/src/app/atom-theme.coffee +++ b/src/app/atom-theme.coffee @@ -17,12 +17,12 @@ class AtomTheme extends Theme if path.extname(@path) in ['.css', '.less'] @loadStylesheet(@path) else - metadataPath = fsUtils.resolveExtension(fsUtils.join(@path, 'package'), ['cson', 'json']) + metadataPath = fsUtils.resolveExtension(path.join(@path, 'package'), ['cson', 'json']) if fsUtils.isFile(metadataPath) stylesheetNames = fsUtils.readObject(metadataPath)?.stylesheets if stylesheetNames for name in stylesheetNames - filename = fsUtils.resolveExtension(fsUtils.join(@path, name), ['.css', '.less', '']) + filename = fsUtils.resolveExtension(path.join(@path, name), ['.css', '.less', '']) @loadStylesheet(filename) else @loadStylesheet(stylesheetPath) for stylesheetPath in fsUtils.list(@path, ['.css', '.less']) diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 69d559a55..5b2027bbc 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -90,7 +90,7 @@ window.atom = packagePath = fsUtils.resolve(config.packageDirPaths..., name) return packagePath if fsUtils.isDirectory(packagePath) - packagePath = fsUtils.join(window.resourcePath, 'node_modules', name) + packagePath = path.join(window.resourcePath, 'node_modules', name) return packagePath if @isInternalPackage(packagePath) isInternalPackage: (packagePath) -> @@ -116,7 +116,7 @@ window.atom = for packagePath in fsUtils.list(packageDirPath) packagePaths.push(packagePath) if fsUtils.isDirectory(packagePath) - for packagePath in fsUtils.list(fsUtils.join(window.resourcePath, 'node_modules')) + for packagePath in fsUtils.list(path.join(window.resourcePath, 'node_modules')) packagePaths.push(packagePath) if @isInternalPackage(packagePath) _.uniq(packagePaths) @@ -151,7 +151,7 @@ window.atom = @loadedThemes.push Theme.load(name) loadUserStylesheet: -> - userStylesheetPath = fsUtils.resolve(fsUtils.join(config.configDirPath, 'user'), ['css', 'less']) + userStylesheetPath = fsUtils.resolve(path.join(config.configDirPath, 'user'), ['css', 'less']) if fsUtils.isFile(userStylesheetPath) userStyleesheetContents = loadStylesheet(userStylesheetPath) applyStylesheet(userStylesheetPath, userStyleesheetContents, 'userTheme') @@ -237,7 +237,7 @@ window.atom = filename = "editor-#{sha1}" filename ?= 'undefined' - fsUtils.join(config.userStoragePath, filename) + path.join(config.userStoragePath, filename) setWindowState: (keyPath, value) -> windowState = @getWindowState() @@ -273,7 +273,7 @@ window.atom = process.crash() requireUserInitScript: -> - userInitScriptPath = fsUtils.join(config.configDirPath, "user.coffee") + userInitScriptPath = path.join(config.configDirPath, "user.coffee") try require userInitScriptPath if fsUtils.isFile(userInitScriptPath) catch error diff --git a/src/app/config.coffee b/src/app/config.coffee index 1bf22cae2..806500c2e 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -3,18 +3,19 @@ _ = require 'underscore' EventEmitter = require 'event-emitter' CSON = require 'season' fs = require 'fs' +path = require 'path' async = require 'async' pathWatcher = require 'pathwatcher' configDirPath = fsUtils.absolute("~/.atom") -bundledPackagesDirPath = fsUtils.join(resourcePath, "src/packages") -nodeModulesDirPath = fsUtils.join(resourcePath, "node_modules") -bundledThemesDirPath = fsUtils.join(resourcePath, "themes") -vendoredPackagesDirPath = fsUtils.join(resourcePath, "vendor/packages") -vendoredThemesDirPath = fsUtils.join(resourcePath, "vendor/themes") -userThemesDirPath = fsUtils.join(configDirPath, "themes") -userPackagesDirPath = fsUtils.join(configDirPath, "packages") -userStoragePath = fsUtils.join(configDirPath, ".storage") +bundledPackagesDirPath = path.join(resourcePath, "src/packages") +nodeModulesDirPath = path.join(resourcePath, "node_modules") +bundledThemesDirPath = path.join(resourcePath, "themes") +vendoredPackagesDirPath = path.join(resourcePath, "vendor/packages") +vendoredThemesDirPath = .join(resourcePath, "vendor/themes") +userThemesDirPath = path.join(configDirPath, "themes") +userPackagesDirPath = path.join(configDirPath, "packages") +userStoragePath = path.join(configDirPath, ".storage") # Public: Handles all of Atom's configuration details. # @@ -28,7 +29,7 @@ class Config packageDirPaths: [userPackagesDirPath, vendoredPackagesDirPath, bundledPackagesDirPath] userPackagesDirPath: userPackagesDirPath userStoragePath: userStoragePath - lessSearchPaths: [fsUtils.join(resourcePath, 'static'), fsUtils.join(resourcePath, 'vendor')] + lessSearchPaths: [path.join(resourcePath, 'static'), path.join(resourcePath, 'vendor')] defaultSettings: null settings: null configFileHasErrors: null @@ -41,7 +42,7 @@ class Config editor: _.clone(require('editor').configDefaults) @settings = {} @configFilePath = fsUtils.resolve(configDirPath, 'config', ['json', 'cson']) - @configFilePath ?= fsUtils.join(configDirPath, 'config.cson') + @configFilePath ?= path.join(configDirPath, 'config.cson') initializeConfigDirectory: (done) -> return if fsUtils.exists(@configDirPath) @@ -55,14 +56,14 @@ class Config templateConfigDirPath = fsUtils.resolve(window.resourcePath, 'dot-atom') onConfigDirFile = (sourcePath) => relativePath = sourcePath.substring(templateConfigDirPath.length + 1) - destinationPath = fsUtils.join(@configDirPath, relativePath) + destinationPath = path.join(@configDirPath, relativePath) queue.push({sourcePath, destinationPath}) fsUtils.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true) - configThemeDirPath = fsUtils.join(@configDirPath, 'themes') + configThemeDirPath = path.join(@configDirPath, 'themes') onThemeDirFile = (sourcePath) -> relativePath = sourcePath.substring(bundledThemesDirPath.length + 1) - destinationPath = fsUtils.join(configThemeDirPath, relativePath) + destinationPath = path.join(configThemeDirPath, relativePath) queue.push({sourcePath, destinationPath}) fsUtils.traverseTree(bundledThemesDirPath, onThemeDirFile, (path) -> true) diff --git a/src/app/keymap.coffee b/src/app/keymap.coffee index ee2cebba4..13556aae1 100644 --- a/src/app/keymap.coffee +++ b/src/app/keymap.coffee @@ -39,7 +39,7 @@ class Keymap @loadDirectory(fsUtils.resolveOnLoadPath('keymaps')) loadUserKeymaps: -> - @loadDirectory(fsUtils.join(config.configDirPath, 'keymaps')) + @loadDirectory(path.join(config.configDirPath, 'keymaps')) loadDirectory: (directoryPath) -> @load(filePath) for filePath in fsUtils.list(directoryPath, ['.cson', '.json']) diff --git a/src/app/project.coffee b/src/app/project.coffee index 4747ebd6f..bdae9b346 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -96,11 +96,11 @@ class Project # Identifies if a path is ignored. # - # path - The {String} name of the path to check + # repositoryPath - The {String} name of the path to check # # Returns a {Boolean}. - ignoreRepositoryPath: (path) -> - config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fsUtils.join(@getPath(), path)) + ignoreRepositoryPath: (repositoryPath) -> + config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(path.join(@getPath(), repositoryPath)) # Given a uri, this resolves it relative to the project directory. If the path # is already absolute or if it is prefixed with a scheme, it is returned unchanged. @@ -112,7 +112,7 @@ class Project if uri?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme uri else - uri = fsUtils.join(@getPath(), uri) unless uri[0] == '/' + uri = path.join(@getPath(), uri) unless uri[0] == '/' fsUtils.absolute uri # Given a path, this makes it relative to the project directory. diff --git a/src/app/repository-status-handler.coffee b/src/app/repository-status-handler.coffee index 05f866a96..c9b736f7e 100644 --- a/src/app/repository-status-handler.coffee +++ b/src/app/repository-status-handler.coffee @@ -1,5 +1,6 @@ Git = require 'git-utils' fsUtils = require 'fs-utils' +path = require 'path' module.exports = loadStatuses: (path) -> @@ -8,7 +9,7 @@ module.exports = workingDirectoryPath = repo.getWorkingDirectory() statuses = {} for path, status of repo.getStatus() - statuses[fsUtils.join(workingDirectoryPath, path)] = status + statuses[path.join(workingDirectoryPath, path)] = status upstream = repo.getAheadBehindCount() repo.release() else diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 6540267f0..7b5471df5 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -1,5 +1,6 @@ Package = require 'package' fsUtils = require 'fs-utils' +path = require 'path' _ = require 'underscore' TextMateGrammar = require 'text-mate-grammar' async = require 'async' @@ -74,18 +75,18 @@ class TextMatePackage extends Package getGrammars: -> @grammars getSyntaxesPath: -> - syntaxesPath = fsUtils.join(@path, "syntaxes") + syntaxesPath = path.join(@path, "syntaxes") if fsUtils.isDirectory(syntaxesPath) syntaxesPath else - fsUtils.join(@path, "Syntaxes") + path.join(@path, "Syntaxes") getPreferencesPath: -> - preferencesPath = fsUtils.join(@path, "preferences") + preferencesPath = path.join(@path, "preferences") if fsUtils.isDirectory(preferencesPath) preferencesPath else - fsUtils.join(@path, "Preferences") + path.join(@path, "Preferences") loadScopedPropertiesSync: -> for grammar in @getGrammars() diff --git a/src/app/window.coffee b/src/app/window.coffee index 9c983c9c7..261221fa4 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -89,11 +89,11 @@ window.unloadEditorWindow = -> window.git = null window.installAtomCommand = (callback) -> - commandPath = fsUtils.join(window.resourcePath, 'atom.sh') + commandPath = path.join(window.resourcePath, 'atom.sh') require('command-installer').install(commandPath, callback) window.installApmCommand = (callback) -> - commandPath = fsUtils.join(window.resourcePath, 'node_modules', '.bin', 'apm') + commandPath = path.join(window.resourcePath, 'node_modules', '.bin', 'apm') require('command-installer').install(commandPath, callback) window.unloadConfigWindow = -> diff --git a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee index 684802e01..b6b0c9347 100644 --- a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee +++ b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee @@ -369,7 +369,7 @@ describe 'FuzzyFinder', -> ignoreFile = null beforeEach -> - ignoreFile = fsUtils.join(project.getPath(), '.gitignore') + ignoreFile = path.join(project.getPath(), '.gitignore') fsUtils.write(ignoreFile, 'sample.js') config.set("core.excludeVcsIgnoredPaths", true) diff --git a/src/packages/package-generator/lib/package-generator-view.coffee b/src/packages/package-generator/lib/package-generator-view.coffee index afd27b5c6..cfec1464b 100644 --- a/src/packages/package-generator/lib/package-generator-view.coffee +++ b/src/packages/package-generator/lib/package-generator-view.coffee @@ -25,7 +25,7 @@ class PackageGeneratorView extends View @previouslyFocusedElement = $(':focus') @message.text("Enter package path") placeholderName = "package-name" - @miniEditor.setText(fsUtils.join(config.userPackagesDirPath, placeholderName)) + @miniEditor.setText(path.join(config.userPackagesDirPath, placeholderName)) pathLength = @miniEditor.getText().length @miniEditor.setSelectedBufferRange([[0, pathLength - placeholderName.length], [0, pathLength]]) @@ -46,7 +46,7 @@ class PackageGeneratorView extends View getPackagePath: -> packagePath = @miniEditor.getText() packageName = _.dasherize(path.basename(packagePath)) - fsUtils.join(path.dirname(packagePath), packageName) + path.join(path.dirname(packagePath), packageName) validPackagePath: -> if fsUtils.exists(@getPackagePath()) @@ -57,7 +57,7 @@ class PackageGeneratorView extends View true createPackageFiles: -> - templatePath = fsUtils.resolveOnLoadPath(fsUtils.join("package-generator", "template")) + templatePath = fsUtils.resolveOnLoadPath(path.join("package-generator", "template")) packageName = path.basename(@getPackagePath()) for path in fsUtils.listTree(templatePath) @@ -66,7 +66,7 @@ class PackageGeneratorView extends View relativePath = relativePath.replace(/\.template$/, '') relativePath = @replacePackageNamePlaceholders(relativePath, packageName) - sourcePath = fsUtils.join(@getPackagePath(), relativePath) + sourcePath = path.join(@getPackagePath(), relativePath) if fsUtils.isDirectory(path) fsUtils.makeTree(sourcePath) if fsUtils.isFile(path) diff --git a/src/packages/package-generator/spec/package-generator-spec.coffee b/src/packages/package-generator/spec/package-generator-spec.coffee index 5fea6e7c1..3785f842d 100644 --- a/src/packages/package-generator/spec/package-generator-spec.coffee +++ b/src/packages/package-generator/spec/package-generator-spec.coffee @@ -42,14 +42,14 @@ describe 'Package Generator', -> it "forces the package's name to be lowercase with dashes", -> packageName = "CamelCaseIsForTheBirds" - packagePath = fsUtils.join(path.dirname(packagePath), packageName) + packagePath = path.join(path.dirname(packagePath), packageName) rootView.trigger("package-generator:generate") packageGeneratorView = rootView.find(".package-generator").view() packageGeneratorView.miniEditor.setText(packagePath) packageGeneratorView.trigger "core:confirm" expect(packagePath).not.toExistOnDisk() - expect(fsUtils.join(path.dirname(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() + expect(path.join(path.dirname(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() it "correctly lays out the package files and closes the package generator view", -> rootView.attachToDom() diff --git a/src/packages/snippets/lib/snippets.coffee b/src/packages/snippets/lib/snippets.coffee index e45804c35..a370ece34 100644 --- a/src/packages/snippets/lib/snippets.coffee +++ b/src/packages/snippets/lib/snippets.coffee @@ -1,6 +1,7 @@ AtomPackage = require 'atom-package' fs = require 'fs' fsUtils = require 'fs-utils' +path = require 'path' _ = require 'underscore' SnippetExpansion = require './snippet-expansion' Snippet = require './snippet' @@ -34,13 +35,13 @@ module.exports = else @loadAtomSnippets(pack.path, done) - loadAtomSnippets: (path, done) -> - snippetsDirPath = fsUtils.join(path, 'snippets') + loadAtomSnippets: (packagePath, done) -> + snippetsDirPath = path.join(packagePath, 'snippets') return done() unless fsUtils.isDirectory(snippetsDirPath) loadSnippetFile = (filename, done) => return done() if filename.indexOf('.') is 0 - filepath = fsUtils.join(snippetsDirPath, filename) + filepath = path.join(snippetsDirPath, filename) CSON.readFile filepath, (err, object) => if err console.warn "Error reading snippets file '#{filepath}': #{err.stack}" @@ -51,14 +52,14 @@ module.exports = fs.readdir snippetsDirPath, (err, paths) -> async.eachSeries(paths, loadSnippetFile, done) - loadTextMateSnippets: (path, done) -> - snippetsDirPath = fsUtils.join(path, 'Snippets') + loadTextMateSnippets: (bundlePath, done) -> + snippetsDirPath = path.join(bundlePath, 'Snippets') return done() unless fsUtils.isDirectory(snippetsDirPath) loadSnippetFile = (filename, done) => return done() if filename.indexOf('.') is 0 - filepath = fsUtils.join(snippetsDirPath, filename) + filepath = path.join(snippetsDirPath, filename) logError = (err) -> console.warn "Error reading snippets file '#{filepath}': #{err.stack ? err}" diff --git a/src/packages/status-bar/spec/status-bar-spec.coffee b/src/packages/status-bar/spec/status-bar-spec.coffee index 83d50d9bb..54b185ecc 100644 --- a/src/packages/status-bar/spec/status-bar-spec.coffee +++ b/src/packages/status-bar/spec/status-bar-spec.coffee @@ -3,6 +3,7 @@ _ = require 'underscore' RootView = require 'root-view' StatusBar = require 'status-bar/lib/status-bar-view' fsUtils = require 'fs-utils' +path = require 'path' {$$} = require 'space-pen' describe "StatusBar", -> @@ -57,9 +58,9 @@ describe "StatusBar", -> describe "when the buffer content has changed from the content on disk", -> it "disables the buffer modified indicator on save", -> - path = "/tmp/atom-whitespace.txt" - fsUtils.write(path, "") - rootView.open(path) + filePath = "/tmp/atom-whitespace.txt" + fsUtils.write(filePath, "") + rootView.open(filePath) expect(statusBar.bufferModified.text()).toBe '' editor.insertText("\n") advanceClock(buffer.stoppedChangingDelay) @@ -127,32 +128,32 @@ describe "StatusBar", -> expect(statusBar.branchLabel.text()).toBe '' describe "git status label", -> - [repo, path, originalPathText, newPath, ignoredPath] = [] + [repo, filePath, originalPathText, newPath, ignoredPath] = [] beforeEach -> - path = require.resolve('fixtures/git/working-dir/file.txt') - newPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new.txt') + filePath = require.resolve('fixtures/git/working-dir/file.txt') + newPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new.txt') fsUtils.write(newPath, "I'm new here") - ignoredPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt') + ignoredPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt') fsUtils.write(ignoredPath, 'ignored.txt') - git.getPathStatus(path) + git.getPathStatus(filePath) git.getPathStatus(newPath) - originalPathText = fsUtils.read(path) + originalPathText = fsUtils.read(filePath) rootView.attachToDom() afterEach -> - fsUtils.write(path, originalPathText) + fsUtils.write(filePath, originalPathText) fsUtils.remove(newPath) if fsUtils.exists(newPath) fsUtils.remove(ignoredPath) if fsUtils.exists(ignoredPath) it "displays the modified icon for a changed file", -> - fsUtils.write(path, "i've changed for the worse") - git.getPathStatus(path) - rootView.open(path) + fsUtils.write(filePath, "i've changed for the worse") + git.getPathStatus(filePath) + rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') it "doesn't display the modified icon for an unchanged file", -> - rootView.open(path) + rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveText('') it "displays the new icon for a new file", -> @@ -164,18 +165,18 @@ describe "StatusBar", -> expect(statusBar.gitStatusIcon).toHaveClass('ignored-status-icon') it "updates when a status-changed event occurs", -> - fsUtils.write(path, "i've changed for the worse") - git.getPathStatus(path) - rootView.open(path) + fsUtils.write(filePath, "i've changed for the worse") + git.getPathStatus(filePath) + rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') - fsUtils.write(path, originalPathText) - git.getPathStatus(path) + fsUtils.write(filePath, originalPathText) + git.getPathStatus(filePath) expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon') it "displays the diff stat for modified files", -> - fsUtils.write(path, "i've changed for the worse") - git.getPathStatus(path) - rootView.open(path) + fsUtils.write(filePath, "i've changed for the worse") + git.getPathStatus(filePath) + rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveText('+1,-1') it "displays the diff stat for new files", -> diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index d289507a8..8f6089f85 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -596,11 +596,11 @@ describe "TreeView", -> beforeEach -> atom.deactivatePackage('tree-view') - rootDirPath = fsUtils.join(fsUtils.absolute("/tmp"), "atom-tests") + rootDirPath = path.join(fsUtils.absolute("/tmp"), "atom-tests") fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath) - dirPath = fsUtils.join(rootDirPath, "test-dir") - filePath = fsUtils.join(dirPath, "test-file.txt") + dirPath = path.join(rootDirPath, "test-dir") + filePath = path.join(dirPath, "test-file.txt") fsUtils.makeDirectory(rootDirPath) fsUtils.makeDirectory(dirPath) fsUtils.write(filePath, "doesn't matter") @@ -646,7 +646,7 @@ describe "TreeView", -> describe "when the path without a trailing '/' is changed and confirmed", -> describe "when no file exists at that location", -> it "add a file, closes the dialog and selects the file in the tree-view", -> - newPath = fsUtils.join(dirPath, "new-test-file.txt") + newPath = path.join(dirPath, "new-test-file.txt") addDialog.miniEditor.insertText(path.basename(newPath)) addDialog.trigger 'core:confirm' expect(fsUtils.exists(newPath)).toBeTruthy() @@ -662,7 +662,7 @@ describe "TreeView", -> describe "when a file already exists at that location", -> it "shows an error message and does not close the dialog", -> - newPath = fsUtils.join(dirPath, "new-test-file.txt") + newPath = path.join(dirPath, "new-test-file.txt") fsUtils.write(newPath, '') addDialog.miniEditor.insertText(path.basename(newPath)) addDialog.trigger 'core:confirm' @@ -676,7 +676,7 @@ describe "TreeView", -> describe "when no file or directory exists at the given path", -> it "adds a directory and closes the dialog", -> treeView.attachToDom() - newPath = fsUtils.join(dirPath, "new/dir") + newPath = path.join(dirPath, "new/dir") addDialog.miniEditor.insertText("new/dir/") addDialog.trigger 'core:confirm' expect(fsUtils.exists(newPath)).toBeTruthy() @@ -689,7 +689,7 @@ describe "TreeView", -> it "selects the created directory", -> treeView.attachToDom() - newPath = fsUtils.join(dirPath, "new2/") + newPath = path.join(dirPath, "new2/") addDialog.miniEditor.insertText("new2/") addDialog.trigger 'core:confirm' expect(fsUtils.exists(newPath)).toBeTruthy() @@ -702,7 +702,7 @@ describe "TreeView", -> describe "when a file or directory already exists at the given path", -> it "shows an error message and does not close the dialog", -> - newPath = fsUtils.join(dirPath, "new-dir") + newPath = path.join(dirPath, "new-dir") fsUtils.makeDirectory(newPath) addDialog.miniEditor.insertText("new-dir/") addDialog.trigger 'core:confirm' @@ -784,7 +784,7 @@ describe "TreeView", -> describe "when the path is changed and confirmed", -> describe "when all the directories along the new path exist", -> it "moves the file, updates the tree view, and closes the dialog", -> - newPath = fsUtils.join(rootDirPath, 'renamed-test-file.txt') + newPath = path.join(rootDirPath, 'renamed-test-file.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' @@ -803,7 +803,7 @@ describe "TreeView", -> describe "when the directories along the new path don't exist", -> it "creates the target directory before moving the file", -> - newPath = fsUtils.join(rootDirPath, 'new/directory', 'renamed-test-file.txt') + newPath = path.join(rootDirPath, 'new/directory', 'renamed-test-file.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' @@ -818,8 +818,8 @@ describe "TreeView", -> describe "when a file or directory already exists at the target path", -> it "shows an error message and does not close the dialog", -> runs -> - fsUtils.write(fsUtils.join(rootDirPath, 'target.txt'), '') - newPath = fsUtils.join(rootDirPath, 'target.txt') + fsUtils.write(path.join(rootDirPath, 'target.txt'), '') + newPath = path.join(rootDirPath, 'target.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' @@ -847,7 +847,7 @@ describe "TreeView", -> [dotFilePath, dotFileView, moveDialog] = [] beforeEach -> - dotFilePath = fsUtils.join(dirPath, ".dotfile") + dotFilePath = path.join(dirPath, ".dotfile") fsUtils.write(dotFilePath, "dot") dirView.collapse() dirView.expand() @@ -878,7 +878,7 @@ describe "TreeView", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary') + temporaryFilePath = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary') if fsUtils.exists(temporaryFilePath) fsUtils.remove(temporaryFilePath) waits(20) @@ -910,7 +910,7 @@ describe "TreeView", -> [ignoreFile] = [] beforeEach -> - ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') + ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') fsUtils.write(ignoreFile, 'tree-view.js') config.set "core.hideGitIgnoredFiles", false @@ -933,15 +933,15 @@ describe "TreeView", -> beforeEach -> config.set "core.hideGitIgnoredFiles", false - ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') + ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') fsUtils.write(ignoreFile, 'tree-view.js') git.getPathStatus(ignoreFile) - newFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2') + newFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2') fsUtils.write(newFile, '') git.getPathStatus(newFile) - modifiedFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1') + modifiedFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1') originalFileContent = fsUtils.read(modifiedFile) fsUtils.write modifiedFile, 'ch ch changes' git.getPathStatus(modifiedFile) diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 0d4f0a419..aa573fa6c 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -27,11 +27,6 @@ module.exports = exists: (path) -> path? and fs.existsSync(path) - join: (paths...) -> - return paths[0] if paths.length == 1 - [first, rest...] = paths - first.replace(/\/?$/, "/") + @join(rest...) - # Returns true if the file specified by path exists and is a # directory. isDirectory: (path) -> @@ -75,7 +70,7 @@ module.exports = return [] unless @isDirectory(rootPath) paths = fs.readdirSync(rootPath) paths = @filterExtensions(paths, extensions) if extensions - paths = paths.map (path) => @join(rootPath, path) + paths = paths.map (path) -> Path.join(rootPath, path) paths listAsync: (rootPath, rest...) -> @@ -84,7 +79,7 @@ module.exports = fs.readdir rootPath, (err, paths) => return done(err) if err paths = @filterExtensions(paths, extensions) if extensions - paths = paths.map (path) => @join(rootPath, path) + paths = paths.map (path) -> Path.join(rootPath, path) done(null, paths) filterExtensions: (paths, extensions) -> @@ -171,11 +166,11 @@ module.exports = traverseTreeSync: (rootPath, onFile, onDirectory) -> return unless @isDirectory(rootPath) - traverse = (rootPath, prefix, onFile, onDirectory) => + traverse = (rootPath, prefix, onFile, onDirectory) -> prefix = "#{prefix}/" if prefix for file in fs.readdirSync(rootPath) relativePath = "#{prefix}#{file}" - absolutePath = @join(rootPath, file) + absolutePath = Path.join(rootPath, file) stats = fs.statSync(absolutePath) if stats.isDirectory() traverse(absolutePath, relativePath, onFile, onDirectory) if onDirectory(absolutePath) @@ -185,12 +180,12 @@ module.exports = traverse(rootPath, '', onFile, onDirectory) traverseTree: (rootPath, onFile, onDirectory, onDone) -> - fs.readdir rootPath, (error, files) => + fs.readdir rootPath, (error, files) -> if error onDone?() else - queue = async.queue (path, callback) => - fs.stat path, (error, stats) => + queue = async.queue (path, callback) -> + fs.stat path, (error, stats) -> if error callback(error) else if stats.isFile() @@ -198,18 +193,18 @@ module.exports = callback() else if stats.isDirectory() if onDirectory(path) - fs.readdir path, (error, files) => + fs.readdir path, (error, files) -> if error callback(error) else for file in files - queue.unshift(@join(path, file)) + queue.unshift(Path.join(path, file)) callback() else callback() queue.concurrency = 1 queue.drain = onDone - queue.push(@join(rootPath, file)) for file in files + queue.push(Path.join(rootPath, file)) for file in files md5ForPath: (path) -> contents = fs.readFileSync(path) @@ -227,7 +222,7 @@ module.exports = return pathToResolve if @exists(pathToResolve) for loadPath in loadPaths - candidatePath = @join(loadPath, pathToResolve) + candidatePath = Path.join(loadPath, pathToResolve) if extensions if resolvedPath = @resolveExtension(candidatePath, extensions) return resolvedPath