From 07b40265fbdc57e4983d82eb211c55e71e0d5557 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 Apr 2013 14:40:30 -0700 Subject: [PATCH 01/33] Log error when no stack exists --- spec/spec-bootstrap.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec-bootstrap.coffee b/spec/spec-bootstrap.coffee index f3a961207..410262423 100644 --- a/spec/spec-bootstrap.coffee +++ b/spec/spec-bootstrap.coffee @@ -6,5 +6,5 @@ try document.title = "Spec Suite" runSpecSuite "spec-suite" catch e - console.error(e.stack) + console.error(e.stack ? e) atom.exit(1) if window.location.params.exitWhenDone From 9a8fd062c4ed43571c9449becfab2376ad079158 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 Apr 2013 14:40:55 -0700 Subject: [PATCH 02/33] Throw error instead of string --- spec/spec-helper.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 65a1b85dd..0475902a7 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -242,4 +242,4 @@ $.fn.textInput = (data) -> $(this).trigger(event) unless fs.md5ForPath(require.resolve('fixtures/sample.js')) == "dd38087d0d7e3e4802a6d3f9b9745f2b" - throw "Sample.js is modified" + throw new Error("Sample.js is modified") From 693d8258adba8b9f441f1027eebd556fa30e4867 Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Mon, 25 Mar 2013 20:16:22 +0100 Subject: [PATCH 03/33] Preserve buffer contents for unsaved files when reloading --- spec/app/edit-session-spec.coffee | 4 ++++ src/app/edit-session.coffee | 3 +++ src/app/project.coffee | 8 ++++++++ src/app/text-buffer.coffee | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 3337d526b..061139528 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -2059,6 +2059,10 @@ describe "EditSession", -> editSession.setCursorScreenPosition([0, 1]) editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] + it "preserves the current state if the file was not saved yet", -> + editSession = project.buildEditSessionFromState('test', autoIndent: false) + editSession = EditSession.deserialize(editSession.serialize()) + expect(editSession.buffer.getText()).toBe('test') describe "when the 'grammars-loaded' event is triggered on the syntax global", -> it "reloads the edit session's grammar and re-tokenizes the buffer if it changes", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index e14baa16a..9b7b611b6 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -17,6 +17,8 @@ class EditSession @deserialize: (state) -> if fs.exists(state.buffer) session = project.buildEditSession(state.buffer) + else if state.unsavedState + session = project.buildEditSessionFromState(state.unsavedState) else console.warn "Could not build edit session for path '#{state.buffer}' because that file no longer exists" if state.buffer session = project.buildEditSession(null) @@ -92,6 +94,7 @@ class EditSession scrollTop: @getScrollTop() scrollLeft: @getScrollLeft() cursorScreenPosition: @getCursorScreenPosition().serialize() + unsavedState: @buffer.getText() if !@buffer.fileExists() copy: -> EditSession.deserialize(@serialize(), @project) diff --git a/src/app/project.coffee b/src/app/project.coffee index 53621f374..ff2805692 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -87,6 +87,9 @@ class Project buildEditSession: (filePath, editSessionOptions={}) -> @buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions) + buildEditSessionFromState: (state, editSessionOptions={}) -> + @buildEditSessionForBuffer(@bufferForState(state), editSessionOptions) + buildEditSessionForBuffer: (buffer, editSessionOptions) -> options = _.extend(@defaultEditSessionOptions(), editSessionOptions) options.project = this @@ -138,6 +141,11 @@ class Project else @buildBuffer() + bufferForState: (state) -> + buffer = @buildBuffer() + buffer.setText(state) if state + buffer + buildBuffer: (filePath) -> buffer = new Buffer(filePath, this) @buffers.push buffer diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index bd06299d2..c6cf06c79 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -445,7 +445,7 @@ class Buffer @trigger 'modified-status-changed', modifiedStatus fileExists: -> - @file.exists() + @file? && @file.exists() logLines: (start=0, end=@getLastRow())-> for row in [start..end] From cc87595e4eac26a9443ccf76ca2f6bcbf55943e6 Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Tue, 26 Mar 2013 14:46:45 +0100 Subject: [PATCH 04/33] Serialize TextBuffer inside EditSession serialize --- spec/app/edit-session-spec.coffee | 4 ++- spec/app/text-buffer-spec.coffee | 45 +++++++++++++++++++++++++++++++ src/app/edit-session.coffee | 10 +++---- src/app/project.coffee | 8 ------ src/app/text-buffer.coffee | 21 ++++++++++++--- 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 061139528..4fd1cbaf6 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -2060,7 +2060,9 @@ describe "EditSession", -> editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] it "preserves the current state if the file was not saved yet", -> - editSession = project.buildEditSessionFromState('test', autoIndent: false) + editSession.destroy() + editSession = project.buildEditSession(null, autoIndent: false) + editSession.buffer.setText('test') editSession = EditSession.deserialize(editSession.serialize()) expect(editSession.buffer.getText()).toBe('test') diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 0bf327d4c..e00ad2c16 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1229,3 +1229,48 @@ describe 'Buffer', -> expect(buffer.clipPosition([1, 0])).toEqual [0,9] expect(buffer.clipPosition([0,10])).toEqual [0,9] expect(buffer.clipPosition([10,Infinity])).toEqual [0,9] + + describe "when the buffer is serialized", -> + describe "when the contents of the buffer are saved on disk", -> + it "stores the file path", -> + data = buffer.serialize() + expect(data.path).toBe(buffer.getPath()) + expect(data.text).toBeFalsy() + describe "when the buffer has unsaved changes", -> + it "stores the file path and the changed buffer text", -> + buffer.setText("abc") + data = buffer.serialize() + expect(data.path).toBe(buffer.getPath()) + expect(data.text).toBe("abc") + describe "when the buffer has never been saved", -> + it "stores the changed buffer text", -> + buffer.release() + buffer = new Buffer() + buffer.setText("abc") + data = buffer.serialize() + expect(data.path).toBeFalsy() + expect(data.text).toBe("abc") + + describe "when a buffer is deserialized", -> + reloadBuffer = () -> + serialized = buffer.serialize() + buffer.release() + buffer = Buffer.deserialize(serialized) + + it "loads the contents of the file saved on disk when there are no unsaved changes", -> + path = buffer.getPath() + reloadBuffer() + expect(buffer.getPath()).toBe(path) + it "loads the stored changes if the file was modified", -> + path = buffer.getPath() + buffer.setText("abc") + reloadBuffer() + expect(buffer.getPath()).toBe(path) + expect(buffer.getText()).toBe("abc") + it "loads the stored changes if the file was never saved", -> + buffer.release() + buffer = new Buffer() + buffer.setText("abc") + reloadBuffer() + expect(buffer.getPath()).toBeFalsy() + expect(buffer.getText()).toBe("abc") diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 9b7b611b6..36884284a 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -15,11 +15,8 @@ class EditSession registerDeserializer(this) @deserialize: (state) -> - if fs.exists(state.buffer) - session = project.buildEditSession(state.buffer) - else if state.unsavedState - session = project.buildEditSessionFromState(state.unsavedState) - else + session = project.buildEditSessionForBuffer(Buffer.deserialize(state.buffer)) + if !session? console.warn "Could not build edit session for path '#{state.buffer}' because that file no longer exists" if state.buffer session = project.buildEditSession(null) session.setScrollTop(state.scrollTop) @@ -90,11 +87,10 @@ class EditSession serialize: -> deserializer: 'EditSession' - buffer: @buffer.getPath() + buffer: @buffer.serialize() scrollTop: @getScrollTop() scrollLeft: @getScrollLeft() cursorScreenPosition: @getCursorScreenPosition().serialize() - unsavedState: @buffer.getText() if !@buffer.fileExists() copy: -> EditSession.deserialize(@serialize(), @project) diff --git a/src/app/project.coffee b/src/app/project.coffee index ff2805692..53621f374 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -87,9 +87,6 @@ class Project buildEditSession: (filePath, editSessionOptions={}) -> @buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions) - buildEditSessionFromState: (state, editSessionOptions={}) -> - @buildEditSessionForBuffer(@bufferForState(state), editSessionOptions) - buildEditSessionForBuffer: (buffer, editSessionOptions) -> options = _.extend(@defaultEditSessionOptions(), editSessionOptions) options.project = this @@ -141,11 +138,6 @@ class Project else @buildBuffer() - bufferForState: (state) -> - buffer = @buildBuffer() - buffer.setText(state) if state - buffer - buildBuffer: (filePath) -> buffer = new Buffer(filePath, this) @buffers.push buffer diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index c6cf06c79..4e0443b7f 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -11,6 +11,7 @@ BufferMarker = require 'buffer-marker' module.exports = class Buffer @idCounter = 1 + registerDeserializer(this) stoppedChangingDelay: 300 stoppedChangingTimeout: null undoManager: null @@ -24,7 +25,13 @@ class Buffer invalidMarkers: null refcount: 0 - constructor: (path, @project) -> + @deserialize: (state) -> + if state && (state.path? || state.text?) + new Buffer(state.path, project, state.text) + else + new Buffer(null, project) + + constructor: (path, @project, initialText) -> @id = @constructor.idCounter++ @nextMarkerId = 1 @validMarkers = {} @@ -35,9 +42,12 @@ class Buffer if path throw "Path '#{path}' does not exist" unless fs.exists(path) @setPath(path) - @reload() + if initialText? + @setText(initialText) + else + @reload() else - @setText('') + @setText(initialText ? '') @undoManager = new UndoManager(this) @@ -56,6 +66,11 @@ class Buffer @destroy() if @refcount <= 0 this + serialize: -> + deserializer: 'TextBuffer' + path: @getPath() + text: @getText() if @isModified() + hasEditors: -> @refcount > 1 subscribeToFile: -> From 40975f15d3c65e80464fcb3bae3b74742377ec51 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 13:23:17 -0600 Subject: [PATCH 05/33] :lipstick: Follow whitespace conventions for specs --- spec/app/text-buffer-spec.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index e00ad2c16..2aea33ee5 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1236,12 +1236,14 @@ describe 'Buffer', -> data = buffer.serialize() expect(data.path).toBe(buffer.getPath()) expect(data.text).toBeFalsy() + describe "when the buffer has unsaved changes", -> it "stores the file path and the changed buffer text", -> buffer.setText("abc") data = buffer.serialize() expect(data.path).toBe(buffer.getPath()) expect(data.text).toBe("abc") + describe "when the buffer has never been saved", -> it "stores the changed buffer text", -> buffer.release() @@ -1261,12 +1263,14 @@ describe 'Buffer', -> path = buffer.getPath() reloadBuffer() expect(buffer.getPath()).toBe(path) + it "loads the stored changes if the file was modified", -> path = buffer.getPath() buffer.setText("abc") reloadBuffer() expect(buffer.getPath()).toBe(path) expect(buffer.getText()).toBe("abc") + it "loads the stored changes if the file was never saved", -> buffer.release() buffer = new Buffer() From 78211acafd6dc68a5feb8f21badc92c6bea93921 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 14:36:56 -0600 Subject: [PATCH 06/33] Use `project.bufferForPath` to build buffers in specs This reflects the way buffers should always be created in practice. It registers buffers on project, which will be important when testing that we always get the same buffer when deserializing a buffer for a path we've already opened. --- spec/app/text-buffer-spec.coffee | 39 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 2aea33ee5..6f05a9230 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -9,7 +9,7 @@ describe 'Buffer', -> beforeEach -> filePath = require.resolve('fixtures/sample.js') fileContents = fs.read(filePath) - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) afterEach -> buffer?.release() @@ -23,11 +23,11 @@ describe 'Buffer', -> describe "when a file exists for the path", -> it "loads the contents of that file", -> filePath = require.resolve 'fixtures/sample.txt' - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) expect(buffer.getText()).toBe fs.read(filePath) it "is not modified and has no undo history", -> - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) expect(buffer.isModified()).toBeFalsy() expect(buffer.undoManager.undoHistory.length).toBe 0 @@ -35,11 +35,11 @@ describe 'Buffer', -> it "throws an exception", -> filePath = "does-not-exist.txt" expect(fs.exists(filePath)).toBeFalsy() - expect(-> new Buffer(filePath)).toThrow() + expect(-> project.bufferForPath(filePath)).toThrow() describe "when no path is given", -> it "creates an empty buffer", -> - buffer = new Buffer + buffer = project.bufferForPath(null) expect(buffer .getText()).toBe "" describe "path-changed event", -> @@ -49,7 +49,7 @@ describe 'Buffer', -> path = fs.join(fs.resolveOnLoadPath("fixtures"), "atom-manipulate-me") newPath = "#{path}-i-moved" fs.write(path, "") - bufferToChange = new Buffer(path) + bufferToChange = project.bufferForPath(path) eventHandler = jasmine.createSpy('eventHandler') bufferToChange.on 'path-changed', eventHandler @@ -78,7 +78,7 @@ describe 'Buffer', -> path = "/tmp/tmp.txt" fs.write(path, "first") buffer.release() - buffer = new Buffer(path).retain() + buffer = project.bufferForPath(path).retain() afterEach -> buffer.release() @@ -150,7 +150,8 @@ describe 'Buffer', -> beforeEach -> path = "/tmp/atom-file-to-delete.txt" fs.write(path, 'delete me') - bufferToDelete = new Buffer(path) + bufferToDelete = project.bufferForPath(path) + path = bufferToDelete.getPath() # symlinks may have been converted expect(bufferToDelete.getPath()).toBe path expect(bufferToDelete.isModified()).toBeFalsy() @@ -207,7 +208,7 @@ describe 'Buffer', -> buffer.release() filePath = "/tmp/atom-tmp-file" fs.write(filePath, 'delete me') - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") buffer.on 'modified-status-changed', modifiedHandler @@ -220,7 +221,7 @@ describe 'Buffer', -> filePath = "/tmp/atom-tmp-file" fs.write(filePath, '') buffer.release() - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") buffer.on 'modified-status-changed', modifiedHandler @@ -244,7 +245,7 @@ describe 'Buffer', -> filePath = "/tmp/atom-tmp-file" fs.write(filePath, '') buffer.release() - buffer = new Buffer(filePath) + buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") buffer.on 'modified-status-changed', modifiedHandler @@ -265,12 +266,12 @@ describe 'Buffer', -> it "returns false for an empty buffer with no path", -> buffer.release() - buffer = new Buffer() + buffer = project.bufferForPath(null) expect(buffer.isModified()).toBeFalsy() it "returns true for a non-empty buffer with no path", -> buffer.release() - buffer = new Buffer() + buffer = project.bufferForPath(null) buffer.setText('a') expect(buffer.isModified()).toBeTruthy() buffer.setText('\n') @@ -420,7 +421,7 @@ describe 'Buffer', -> beforeEach -> filePath = '/tmp/temp.txt' fs.write(filePath, "") - saveBuffer = new Buffer filePath + saveBuffer = project.bufferForPath(filePath) saveBuffer.setText("blah") it "saves the contents of the buffer to the path", -> @@ -454,7 +455,7 @@ describe 'Buffer', -> describe "when the buffer has no path", -> it "throws an exception", -> - saveBuffer = new Buffer + saveBuffer = project.bufferForPath(null) saveBuffer.setText "hi" expect(-> saveBuffer.save()).toThrow() @@ -478,7 +479,7 @@ describe 'Buffer', -> filePath = '/tmp/temp.txt' fs.remove filePath if fs.exists(filePath) - saveAsBuffer = new Buffer().retain() + saveAsBuffer = project.bufferForPath(null).retain() eventHandler = jasmine.createSpy('eventHandler') saveAsBuffer.on 'path-changed', eventHandler @@ -493,7 +494,7 @@ describe 'Buffer', -> newPath = "/tmp/new.txt" fs.write(originalPath, "") - saveAsBuffer = new Buffer(originalPath).retain() + saveAsBuffer = project.bufferForPath(originalPath).retain() changeHandler = jasmine.createSpy('changeHandler') saveAsBuffer.on 'changed', changeHandler saveAsBuffer.saveAs(newPath) @@ -1247,7 +1248,7 @@ describe 'Buffer', -> describe "when the buffer has never been saved", -> it "stores the changed buffer text", -> buffer.release() - buffer = new Buffer() + buffer = project.bufferForPath(null) buffer.setText("abc") data = buffer.serialize() expect(data.path).toBeFalsy() @@ -1273,7 +1274,7 @@ describe 'Buffer', -> it "loads the stored changes if the file was never saved", -> buffer.release() - buffer = new Buffer() + buffer = project.bufferForPath(null) buffer.setText("abc") reloadBuffer() expect(buffer.getPath()).toBeFalsy() From e8216a8313b4686064473d9a01743b4c3209c659 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 14:41:05 -0600 Subject: [PATCH 07/33] Don't store @project reference inside TextBuffer. Use the global. --- src/app/project.coffee | 2 +- src/app/text-buffer.coffee | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/project.coffee b/src/app/project.coffee index 53621f374..2e4d718ac 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -139,7 +139,7 @@ class Project @buildBuffer() buildBuffer: (filePath) -> - buffer = new Buffer(filePath, this) + buffer = new Buffer(filePath) @buffers.push buffer @trigger 'buffer-created', buffer buffer diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 4e0443b7f..ab49c47e1 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -27,11 +27,11 @@ class Buffer @deserialize: (state) -> if state && (state.path? || state.text?) - new Buffer(state.path, project, state.text) + new Buffer(state.path, state.text) else - new Buffer(null, project) + new Buffer(null) - constructor: (path, @project, initialText) -> + constructor: (path, initialText) -> @id = @constructor.idCounter++ @nextMarkerId = 1 @validMarkers = {} @@ -55,7 +55,7 @@ class Buffer throw new Error("Destroying buffer twice with path '#{@getPath()}'") if @destroyed @file?.off() @destroyed = true - @project?.removeBuffer(this) + project?.removeBuffer(this) retain: -> @refcount++ From 9efc326ff3ce9d5f9c160f8c68f3474a73a28351 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 14:43:17 -0600 Subject: [PATCH 08/33] Remove spec that can be covered in text-buffer specs --- spec/app/edit-session-spec.coffee | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 4fd1cbaf6..3337d526b 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -2059,12 +2059,6 @@ describe "EditSession", -> editSession.setCursorScreenPosition([0, 1]) editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] - it "preserves the current state if the file was not saved yet", -> - editSession.destroy() - editSession = project.buildEditSession(null, autoIndent: false) - editSession.buffer.setText('test') - editSession = EditSession.deserialize(editSession.serialize()) - expect(editSession.buffer.getText()).toBe('test') describe "when the 'grammars-loaded' event is triggered on the syntax global", -> it "reloads the edit session's grammar and re-tokenizes the buffer if it changes", -> From f531d360606a7b4ba53f11e3d87dcc615fbbee9d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 14:54:45 -0600 Subject: [PATCH 09/33] Condense / cleanup TextBuffer serialization specs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typically it's fine to test serialization behaviorally. If we can deserialize the serialized state correctly, then we're generally happy. We don't need explicit tests on the serialized state… but I added a couple assertions to ensure we don't write text when we don't need to. It would have been more correct to just modify the saved file and verify we load the new state, but it's not worth the hassle. --- spec/app/text-buffer-spec.coffee | 70 +++++++++++++------------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 6f05a9230..7a23e9326 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1231,51 +1231,37 @@ describe 'Buffer', -> expect(buffer.clipPosition([0,10])).toEqual [0,9] expect(buffer.clipPosition([10,Infinity])).toEqual [0,9] - describe "when the buffer is serialized", -> - describe "when the contents of the buffer are saved on disk", -> - it "stores the file path", -> - data = buffer.serialize() - expect(data.path).toBe(buffer.getPath()) - expect(data.text).toBeFalsy() + describe "serialization", -> + serializedState = null - describe "when the buffer has unsaved changes", -> - it "stores the file path and the changed buffer text", -> - buffer.setText("abc") - data = buffer.serialize() - expect(data.path).toBe(buffer.getPath()) - expect(data.text).toBe("abc") - - describe "when the buffer has never been saved", -> - it "stores the changed buffer text", -> - buffer.release() - buffer = project.bufferForPath(null) - buffer.setText("abc") - data = buffer.serialize() - expect(data.path).toBeFalsy() - expect(data.text).toBe("abc") - - describe "when a buffer is deserialized", -> reloadBuffer = () -> - serialized = buffer.serialize() + serializedState = buffer.serialize() buffer.release() - buffer = Buffer.deserialize(serialized) + buffer = Buffer.deserialize(serializedState) - it "loads the contents of the file saved on disk when there are no unsaved changes", -> - path = buffer.getPath() - reloadBuffer() - expect(buffer.getPath()).toBe(path) + describe "when the serialized buffer had no unsaved changes", -> + it "loads the current contents of the file at the serialized path", -> + path = buffer.getPath() + text = buffer.getText() + reloadBuffer() + expect(serializedState.text).toBeUndefined() + expect(buffer.getPath()).toBe(path) + expect(buffer.getText()).toBe(text) - it "loads the stored changes if the file was modified", -> - path = buffer.getPath() - buffer.setText("abc") - reloadBuffer() - expect(buffer.getPath()).toBe(path) - expect(buffer.getText()).toBe("abc") + describe "when the serialized buffer had unsaved changes", -> + it "restores the previous unsaved state of the buffer", -> + path = buffer.getPath() + buffer.setText("abc") + reloadBuffer() + expect(serializedState.text).toBe "abc" + expect(buffer.getPath()).toBe(path) + expect(buffer.getText()).toBe("abc") - it "loads the stored changes if the file was never saved", -> - buffer.release() - buffer = project.bufferForPath(null) - buffer.setText("abc") - reloadBuffer() - expect(buffer.getPath()).toBeFalsy() - expect(buffer.getText()).toBe("abc") + describe "when the serialized buffer was unsaved and had no path", -> + it "restores the previous unsaved state of the buffer", -> + buffer.setPath(undefined) + buffer.setText("abc") + reloadBuffer() + expect(serializedState.path).toBeUndefined() + expect(buffer.getPath()).toBeUndefined() + expect(buffer.getText()).toBe("abc") From 3150785db227bfb507b7ef20b2c615a07a5f1d91 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 15:05:26 -0600 Subject: [PATCH 10/33] Ensure we never deserialize two instances of the same buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We might have two edit sessions pointing to the same buffer, for example if we have a split pane… So when we deserialize a buffer, we always need to check that we don't already have an instance of that buffer on the project. If we do, then we've already deserialized it once so we don't need to worry about the saved text. We still have a problem when deserializing previously unsaved buffers, because we can't use the path to identify them. --- spec/app/text-buffer-spec.coffee | 6 ++++++ src/app/project.coffee | 12 +++++------- src/app/text-buffer.coffee | 7 ++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 7a23e9326..cb5395933 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1265,3 +1265,9 @@ describe 'Buffer', -> expect(serializedState.path).toBeUndefined() expect(buffer.getPath()).toBeUndefined() expect(buffer.getText()).toBe("abc") + + it "never deserializes two separate instances of the same buffer", -> + serializedState = buffer.serialize() + buffer.release() + buffer = Buffer.deserialize(serializedState) + expect(Buffer.deserialize(serializedState)).toBe buffer diff --git a/src/app/project.coffee b/src/app/project.coffee index 2e4d718ac..81bf19c76 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -127,19 +127,17 @@ class Project else @on 'buffer-created', (buffer) -> callback(buffer) - bufferForPath: (filePath) -> + bufferForPath: (filePath, text) -> if filePath? filePath = @resolve(filePath) if filePath buffer = _.find @buffers, (buffer) -> buffer.getPath() == filePath - buffer or @buildBuffer(filePath) - else - + buffer or @buildBuffer(filePath, text) else - @buildBuffer() + @buildBuffer(null, text) - buildBuffer: (filePath) -> - buffer = new Buffer(filePath) + buildBuffer: (filePath, text) -> + buffer = new Buffer(filePath, text) @buffers.push buffer @trigger 'buffer-created', buffer buffer diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index ab49c47e1..3ebfda88e 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -25,11 +25,8 @@ class Buffer invalidMarkers: null refcount: 0 - @deserialize: (state) -> - if state && (state.path? || state.text?) - new Buffer(state.path, state.text) - else - new Buffer(null) + @deserialize: ({path, text}) -> + project.bufferForPath(path, text) constructor: (path, initialText) -> @id = @constructor.idCounter++ From dab8c5b53b9f8884748cb5a219d3a0a3dcba7b8a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 15:12:33 -0600 Subject: [PATCH 11/33] Assign cachedDiskContents when unsaved buffer is deserialized This allows the buffer to return to an "unmodified" state if the unsaved changes are reversed. --- spec/app/text-buffer-spec.coffee | 3 +++ src/app/text-buffer.coffee | 2 ++ 2 files changed, 5 insertions(+) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index cb5395933..72233ba16 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1251,11 +1251,14 @@ describe 'Buffer', -> describe "when the serialized buffer had unsaved changes", -> it "restores the previous unsaved state of the buffer", -> path = buffer.getPath() + previousText = buffer.getText() buffer.setText("abc") reloadBuffer() expect(serializedState.text).toBe "abc" expect(buffer.getPath()).toBe(path) expect(buffer.getText()).toBe("abc") + buffer.setText(previousText) + expect(buffer.isModified()).toBeFalsy() describe "when the serialized buffer was unsaved and had no path", -> it "restores the previous unsaved state of the buffer", -> diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 3ebfda88e..36f93724c 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -41,11 +41,13 @@ class Buffer @setPath(path) if initialText? @setText(initialText) + @updateCachedDiskContents() else @reload() else @setText(initialText ? '') + @undoManager = new UndoManager(this) destroy: -> From 1bbc9f61e945b119e4da8ca081d57054f00faf28 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Apr 2013 15:15:20 -0600 Subject: [PATCH 12/33] Remove unsaved buffer prompt on reload now that we handle it correctly --- spec/app/window-spec.coffee | 16 ---------------- src/app/window.coffee | 10 +--------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 0615cdc91..52c095904 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -60,22 +60,6 @@ describe "Window", -> expect(window.close).not.toHaveBeenCalled() expect(atom.confirm).toHaveBeenCalled() - describe ".reload()", -> - beforeEach -> - spyOn($native, "reload") - - it "returns false when no buffers are modified", -> - window.reload() - expect($native.reload).toHaveBeenCalled() - - it "shows an alert when a modifed buffer exists", -> - rootView.open('sample.js') - rootView.getActiveView().insertText("hi") - spyOn(atom, "confirm") - window.reload() - expect($native.reload).not.toHaveBeenCalled() - expect(atom.confirm).toHaveBeenCalled() - describe "requireStylesheet(path)", -> it "synchronously loads css at the given path and installs a style tag for it in the head", -> cssPath = project.resolve('css.css') diff --git a/src/app/window.coffee b/src/app/window.coffee index 84a6764d9..78fc1bd42 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -147,15 +147,7 @@ window.applyStylesheet = (id, text, ttype = 'bundled') -> $("head").append "" window.reload = -> - if rootView?.getModifiedBuffers().length > 0 - atom.confirm( - "There are unsaved buffers, reload anyway?", - "You will lose all unsaved changes if you reload", - "Reload", (-> $native.reload()), - "Cancel" - ) - else - $native.reload() + $native.reload() window.onerror = -> atom.showDevTools() From a9c74762cc5421e87f84ca3260485c718be80fee Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Tue, 2 Apr 2013 14:52:39 -0700 Subject: [PATCH 13/33] Add `focusPreviousPane` to pane container --- spec/app/pane-container-spec.coffee | 12 ++++++++++++ src/app/pane-container.coffee | 11 +++++++++++ src/app/root-view.coffee | 2 ++ 3 files changed, 25 insertions(+) diff --git a/spec/app/pane-container-spec.coffee b/spec/app/pane-container-spec.coffee index 708beb081..3289ab5f5 100644 --- a/spec/app/pane-container-spec.coffee +++ b/spec/app/pane-container-spec.coffee @@ -39,6 +39,18 @@ describe "PaneContainer", -> container.focusNextPane() expect(pane1.activeItem).toMatchSelector ':focus' + describe ".focusPreviousPane()", -> + it "focuses the pane preceding the focused pane or the last pane if no pane has focus", -> + container.attachToDom() + container.focusPreviousPane() + expect(pane3.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane2.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane1.activeItem).toMatchSelector ':focus' + container.focusPreviousPane() + expect(pane3.activeItem).toMatchSelector ':focus' + describe ".getActivePane()", -> it "returns the most-recently focused pane", -> focusStealer = $$ -> @div tabindex: -1, "focus stealer" diff --git a/src/app/pane-container.coffee b/src/app/pane-container.coffee index 2118af2b0..6f59af0f4 100644 --- a/src/app/pane-container.coffee +++ b/src/app/pane-container.coffee @@ -32,6 +32,17 @@ class PaneContainer extends View else false + focusPreviousPane: -> + panes = @getPanes() + if panes.length > 1 + currentIndex = panes.indexOf(@getFocusedPane()) + previousIndex = currentIndex - 1 + previousIndex = panes.length - 1 if previousIndex < 0 + panes[previousIndex].focus() + true + else + false + makeNextPaneActive: -> panes = @getPanes() currentIndex = panes.indexOf(@getActivePane()) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 2c299c92c..fc1fdb4e1 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -53,6 +53,7 @@ class RootView extends View config.set("editor.fontSize", fontSize - 1) if fontSize > 1 @command 'window:focus-next-pane', => @focusNextPane() + @command 'window:focus-previous-pane', => @focusPreviousPane() @command 'window:save-all', => @saveAll() @command 'window:toggle-invisibles', => config.set("editor.showInvisibles", !config.get("editor.showInvisibles")) @@ -143,6 +144,7 @@ class RootView extends View getActiveView: -> @panes.getActiveView() + focusPreviousPane: -> @panes.focusPreviousPane() focusNextPane: -> @panes.focusNextPane() getFocusedPane: -> @panes.getFocusedPane() From 9a6b5986fe8db224f1bd8cc1d7e2f73712a69128 Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Tue, 2 Apr 2013 14:59:53 -0700 Subject: [PATCH 14/33] Add editor.selectLine --- src/app/editor.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 42effb3a7..a9583b713 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -122,6 +122,7 @@ class Editor extends View 'editor:select-to-beginning-of-line': @selectToBeginningOfLine 'editor:select-to-end-of-word': @selectToEndOfWord 'editor:select-to-beginning-of-word': @selectToBeginningOfWord + 'editor:select-line': @selectLine 'editor:transpose': @transpose 'editor:upper-case': @upperCase 'editor:lower-case': @lowerCase @@ -211,6 +212,7 @@ class Editor extends View selectToBeginningOfWord: -> @activeEditSession.selectToBeginningOfWord() selectToEndOfWord: -> @activeEditSession.selectToEndOfWord() selectWord: -> @activeEditSession.selectWord() + selectLine: -> @activeEditSession.selectLine() selectToScreenPosition: (position) -> @activeEditSession.selectToScreenPosition(position) transpose: -> @activeEditSession.transpose() upperCase: -> @activeEditSession.upperCase() From 5c93fd457467ff48eba09cbfe3e6ab15ea440183 Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Thu, 21 Mar 2013 16:16:56 +0100 Subject: [PATCH 15/33] Update markdown preview when markdown buffer is saved --- .../markdown-preview/lib/markdown-preview.coffee | 2 ++ .../spec/markdown-preview-spec.coffee | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/packages/markdown-preview/lib/markdown-preview.coffee b/src/packages/markdown-preview/lib/markdown-preview.coffee index 457984f1e..574001d40 100644 --- a/src/packages/markdown-preview/lib/markdown-preview.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview.coffee @@ -13,6 +13,8 @@ module.exports = console.warn("Can not render markdown for #{item.getUri()}") return + activePane.on 'core:save', => @show() + editSession = item if nextPane = activePane.getNextPane() if preview = nextPane.itemForUri("markdown-preview:#{editSession.getPath()}") diff --git a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee index 1bcf984ad..133bc7ad5 100644 --- a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee +++ b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee @@ -65,3 +65,15 @@ describe "MarkdownPreview package", -> expect(pane2.getItems()).toHaveLength 2 expect(pane2.activeItem).toBe preview expect(pane1).toMatchSelector(':has(:focus)') + + describe "when a buffer is modified and saved after a preview item has already been created", -> + it "updates the existing preview item", -> + rootView.getActiveView().trigger 'markdown-preview:show' + [pane1, pane2] = rootView.getPanes() + preview = pane2.activeItem + pane1.focus() + + preview.fetchRenderedMarkdown.reset() + pane1.saveActiveItem = () -> + pane1.trigger("core:save") + expect(preview.fetchRenderedMarkdown).toHaveBeenCalled() \ No newline at end of file From e03f2fd738586b12ce70e9eb73afdfb5600c8da9 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 25 Mar 2013 12:00:01 -0700 Subject: [PATCH 16/33] Markdown preview listens to `core:save` on activate --- src/packages/markdown-preview/lib/markdown-preview.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/packages/markdown-preview/lib/markdown-preview.coffee b/src/packages/markdown-preview/lib/markdown-preview.coffee index 574001d40..4f34f8929 100644 --- a/src/packages/markdown-preview/lib/markdown-preview.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview.coffee @@ -4,6 +4,7 @@ MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view' module.exports = activate: -> rootView.command 'markdown-preview:show', '.editor', => @show() + rootView.on 'core:save', ".pane", => @show() show: -> activePane = rootView.getActivePane() @@ -13,8 +14,6 @@ module.exports = console.warn("Can not render markdown for #{item.getUri()}") return - activePane.on 'core:save', => @show() - editSession = item if nextPane = activePane.getNextPane() if preview = nextPane.itemForUri("markdown-preview:#{editSession.getPath()}") From 5f2c4dad951b1e4ae3e45124c3103ecb2c2aa3f1 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 25 Mar 2013 13:29:12 -0700 Subject: [PATCH 17/33] Only show markdown preview if the edit session's grammar is GFM --- .../markdown-preview/lib/markdown-preview.coffee | 2 ++ .../spec/markdown-preview-spec.coffee | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/packages/markdown-preview/lib/markdown-preview.coffee b/src/packages/markdown-preview/lib/markdown-preview.coffee index 4f34f8929..2c0fe213e 100644 --- a/src/packages/markdown-preview/lib/markdown-preview.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview.coffee @@ -15,6 +15,8 @@ module.exports = return editSession = item + return unless editSession.getGrammar().scopeName == "source.gfm" + if nextPane = activePane.getNextPane() if preview = nextPane.itemForUri("markdown-preview:#{editSession.getPath()}") nextPane.showItem(preview) diff --git a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee index 133bc7ad5..478418f82 100644 --- a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee +++ b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee @@ -4,6 +4,7 @@ MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view' describe "MarkdownPreview package", -> beforeEach -> + window.loadPackage('gfm') project.setPath(project.resolve('markdown')) window.rootView = new RootView atom.activatePackage("markdown-preview", immediate: true) @@ -17,6 +18,14 @@ describe "MarkdownPreview package", -> beforeEach -> rootView.attachToDom() + describe "when the edit session does not use the GFM grammar", -> + it "does not show a markdown preview", -> + rootView.open() + expect(rootView.getPanes()).toHaveLength(1) + rootView.getActiveView().trigger 'markdown-preview:show' + expect(rootView.getPanes()).toHaveLength(1) + + describe "when a preview item has not been created for the edit session's uri", -> describe "when there is more than one pane", -> it "shows a markdown preview for the current buffer on the next pane", -> @@ -76,4 +85,4 @@ describe "MarkdownPreview package", -> preview.fetchRenderedMarkdown.reset() pane1.saveActiveItem = () -> pane1.trigger("core:save") - expect(preview.fetchRenderedMarkdown).toHaveBeenCalled() \ No newline at end of file + expect(preview.fetchRenderedMarkdown).toHaveBeenCalled() From 55d4625091328d2a8e148a786dd692f657b2e2fb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 25 Mar 2013 14:47:52 -0700 Subject: [PATCH 18/33] Only display markdown preview on save if preview already exists --- .../lib/markdown-preview.coffee | 7 ++++- .../spec/markdown-preview-spec.coffee | 28 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/packages/markdown-preview/lib/markdown-preview.coffee b/src/packages/markdown-preview/lib/markdown-preview.coffee index 2c0fe213e..fa21e2a47 100644 --- a/src/packages/markdown-preview/lib/markdown-preview.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview.coffee @@ -4,7 +4,7 @@ MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view' module.exports = activate: -> rootView.command 'markdown-preview:show', '.editor', => @show() - rootView.on 'core:save', ".pane", => @show() + rootView.on 'core:save', ".pane", => @show() if @previewExists() show: -> activePane = rootView.getActivePane() @@ -26,3 +26,8 @@ module.exports = else activePane.splitRight(new MarkdownPreviewView(editSession.buffer)) activePane.focus() + + previewExists: -> + nextPane = rootView.getActivePane().getNextPane() + item = rootView.getActivePane().activeItem + nextPane?.itemForUri("markdown-preview:#{item.getPath?()}") diff --git a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee index 478418f82..92eaa6703 100644 --- a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee +++ b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee @@ -55,6 +55,15 @@ describe "MarkdownPreview package", -> expect(preview.buffer).toBe rootView.getActivePaneItem().buffer expect(pane1).toMatchSelector(':has(:focus)') + describe "when a buffer is saved", -> + it "does not show the markdown preview", -> + [pane] = rootView.getPanes() + pane.focus() + + MarkdownPreviewView.prototype.fetchRenderedMarkdown.reset() + pane.trigger("core:save") + expect(MarkdownPreviewView.prototype.fetchRenderedMarkdown).not.toHaveBeenCalled() + describe "when a preview item has already been created for the edit session's uri", -> it "updates and shows the existing preview item if it isn't displayed", -> rootView.getActiveView().trigger 'markdown-preview:show' @@ -75,14 +84,13 @@ describe "MarkdownPreview package", -> expect(pane2.activeItem).toBe preview expect(pane1).toMatchSelector(':has(:focus)') - describe "when a buffer is modified and saved after a preview item has already been created", -> - it "updates the existing preview item", -> - rootView.getActiveView().trigger 'markdown-preview:show' - [pane1, pane2] = rootView.getPanes() - preview = pane2.activeItem - pane1.focus() + describe "when a buffer is saved", -> + it "updates the existing preview item", -> + rootView.getActiveView().trigger 'markdown-preview:show' + [pane1, pane2] = rootView.getPanes() + preview = pane2.activeItem + pane1.focus() - preview.fetchRenderedMarkdown.reset() - pane1.saveActiveItem = () -> - pane1.trigger("core:save") - expect(preview.fetchRenderedMarkdown).toHaveBeenCalled() + preview.fetchRenderedMarkdown.reset() + pane1.trigger("core:save") + expect(preview.fetchRenderedMarkdown).toHaveBeenCalled() From 2944b64795da85a59646d9795ddf44f9fd56fa76 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 25 Mar 2013 14:59:29 -0700 Subject: [PATCH 19/33] Show GitHub API error message when markdown preview fails --- .../lib/markdown-preview-view.coffee | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/packages/markdown-preview/lib/markdown-preview-view.coffee b/src/packages/markdown-preview/lib/markdown-preview-view.coffee index 5b88545ac..62a832e5c 100644 --- a/src/packages/markdown-preview/lib/markdown-preview-view.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview-view.coffee @@ -32,15 +32,20 @@ class MarkdownPreviewView extends ScrollView getPath: -> @buffer.getPath() - setErrorHtml: -> + setErrorHtml: (result)-> + try failureMessage = JSON.parse(result.responseText).message + @html $$$ -> @h2 'Previewing Markdown Failed' - @h3 'Possible Reasons' - @ul => - @li => - @span 'You aren\'t online or are unable to reach ' - @a 'github.com', href: 'https://github.com' - @span '.' + if failureMessage? + @h3 failureMessage + else + @h3 'Possible Reasons' + @ul => + @li => + @span 'You aren\'t online or are unable to reach ' + @a 'github.com', href: 'https://github.com' + @span '.' setLoading: -> @html($$$ -> @div class: 'markdown-spinner', 'Loading Markdown...') @@ -56,4 +61,4 @@ class MarkdownPreviewView extends ScrollView mode: 'markdown' text: @buffer.getText() success: (html) => @html(html) - error: => @setErrorHtml() + error: (result) => @setErrorHtml(result) From 606f446c27527216e41e5e78a8fbc99ef30f0172 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 25 Mar 2013 15:00:50 -0700 Subject: [PATCH 20/33] Log warning when trying to render non-markdown file --- .../markdown-preview/lib/markdown-preview.coffee | 11 +++++------ .../spec/markdown-preview-spec.coffee | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/packages/markdown-preview/lib/markdown-preview.coffee b/src/packages/markdown-preview/lib/markdown-preview.coffee index fa21e2a47..00ea933fc 100644 --- a/src/packages/markdown-preview/lib/markdown-preview.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview.coffee @@ -8,15 +8,14 @@ module.exports = show: -> activePane = rootView.getActivePane() - item = activePane.activeItem + editSession = activePane.activeItem - if not item instanceof EditSession - console.warn("Can not render markdown for #{item.getUri()}") + isEditSession = editSession instanceof EditSession + hasMarkdownGrammar = editSession.getGrammar().scopeName == "source.gfm" + if not isEditSession or not hasMarkdownGrammar + console.warn("Can not render markdown for '#{editSession.getUri() ? 'untitled'}'") return - editSession = item - return unless editSession.getGrammar().scopeName == "source.gfm" - if nextPane = activePane.getNextPane() if preview = nextPane.itemForUri("markdown-preview:#{editSession.getPath()}") nextPane.showItem(preview) diff --git a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee index 92eaa6703..44e28e706 100644 --- a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee +++ b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee @@ -20,11 +20,12 @@ describe "MarkdownPreview package", -> describe "when the edit session does not use the GFM grammar", -> it "does not show a markdown preview", -> + spyOn(console, 'warn') rootView.open() expect(rootView.getPanes()).toHaveLength(1) rootView.getActiveView().trigger 'markdown-preview:show' expect(rootView.getPanes()).toHaveLength(1) - + expect(console.warn).toHaveBeenCalled() describe "when a preview item has not been created for the edit session's uri", -> describe "when there is more than one pane", -> From f4264f00f8968fc068244f6fb38a81e9b20737b7 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 2 Apr 2013 17:09:08 -0700 Subject: [PATCH 21/33] Modernize markdown preview spec --- src/packages/markdown-preview/spec/markdown-preview-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee index 44e28e706..2ea4ffd32 100644 --- a/src/packages/markdown-preview/spec/markdown-preview-spec.coffee +++ b/src/packages/markdown-preview/spec/markdown-preview-spec.coffee @@ -4,7 +4,7 @@ MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view' describe "MarkdownPreview package", -> beforeEach -> - window.loadPackage('gfm') + atom.activatePackage('gfm') project.setPath(project.resolve('markdown')) window.rootView = new RootView atom.activatePackage("markdown-preview", immediate: true) From 326910eeed40b231a789fe5aa6cd18df49213968 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 Apr 2013 17:25:15 -0700 Subject: [PATCH 22/33] Don't output curl progress bar during ci build --- script/cibuild | 2 +- script/update-cefode | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/script/cibuild b/script/cibuild index e3e58ec23..b0d8fbb30 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,4 +2,4 @@ set -ex rm -rf ~/.atom -rake test +CI_BUILD=true rake test diff --git a/script/update-cefode b/script/update-cefode index a715242c6..29e6a8074 100755 --- a/script/update-cefode +++ b/script/update-cefode @@ -30,7 +30,12 @@ CURRENT_VERSION=`cat cef/version 2>&1` if [[ $LATEST_VERSION != $CURRENT_VERSION ]]; then echo "Downloading/extracting cefode2 u${LATEST_VERSION}..." - curl --progress-bar "${DISTURL}/cef_binary_latest.zip" > "${TEMP_DIR}/cef.zip" + if [ -z "$CI_BUILD" ]; then + CURL_ARGS="--progress-bar" + else + CURL_ARGS="-fsS" + fi + curl $CURL_ARGS "${DISTURL}/cef_binary_latest.zip" > "${TEMP_DIR}/cef.zip" unzip -q "${TEMP_DIR}/cef.zip" -d "${TEMP_DIR}" [ -e "${TARGET}" ] && rm -rf "${TARGET}" mv "${TEMP_DIR}/${CEF_BASENAME}" "${TARGET}" @@ -45,4 +50,3 @@ echo "Downloading/extracting symbols for cefode2 u${LATEST_VERSION}..." curl --progress-bar "${DISTURL}/cef_binary_latest_symbols.zip" > "${TEMP_DIR}/symbols.zip" unzip -q "${TEMP_DIR}/symbols.zip" -d "${TEMP_DIR}" mv "${TEMP_DIR}/${CEF_SYMBOLS_BASENAME}"/* "${TARGET}/Release" - From ba028f6358b6eca49f58ee9af942d75f9cee1171 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 Apr 2013 17:37:21 -0700 Subject: [PATCH 23/33] Support ~/.atom/user.less --- src/app/atom.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 70c05a952..6294b8961 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -109,9 +109,10 @@ _.extend atom, @loadedThemes.push Theme.load(name) loadUserStylesheet: -> - userStylesheetPath = fs.join(config.configDirPath, 'user.css') + userStylesheetPath = fs.resolve(fs.join(config.configDirPath, 'user'), ['css', 'less']) if fs.isFile(userStylesheetPath) - applyStylesheet(userStylesheetPath, fs.read(userStylesheetPath), 'userTheme') + userStyleesheetContents = loadStylesheet(userStylesheetPath) + applyStylesheet(userStylesheetPath, userStyleesheetContents, 'userTheme') getAtomThemeStylesheets: -> themeNames = config.get("core.themes") ? ['atom-dark-ui', 'atom-dark-syntax'] From ec93dc38b7dea14635d6dd5c48c91765956b20e8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 10:21:56 -0600 Subject: [PATCH 24/33] Version serialized state of EditSession Since buffers are now serialized directly, previous versions of the EditSession state which used the buffer's path as the `buffer` key are no longer valid. --- src/app/edit-session.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 36884284a..c1bb8022d 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -14,6 +14,8 @@ module.exports = class EditSession registerDeserializer(this) + @version: 1 + @deserialize: (state) -> session = project.buildEditSessionForBuffer(Buffer.deserialize(state.buffer)) if !session? @@ -87,6 +89,7 @@ class EditSession serialize: -> deserializer: 'EditSession' + version: @constructor.version buffer: @buffer.serialize() scrollTop: @getScrollTop() scrollLeft: @getScrollLeft() From 11f140ac5aab107fa26ba382996232d452f6169b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 10:27:57 -0600 Subject: [PATCH 25/33] Don't save/load window state to/from disk when pathToOpen is undefined This fixes a bug where `meta-n` was not opening a new buffer in the opened window if window state was previously saved for an `undefined` path. --- src/app/atom.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 6294b8961..05eeea60d 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -233,10 +233,12 @@ _.extend atom, null getSavedWindowState: -> - localStorage[window.location.params.pathToOpen] + if pathToOpen = window.location.params.pathToOpen + localStorage[pathToOpen] saveWindowState: -> - localStorage[@getPathToOpen()] = JSON.stringify(@getWindowState()) + if pathToOpen = @getPathToOpen() + localStorage[pathToOpen] = JSON.stringify(@getWindowState()) update: -> @sendMessageToBrowserProcess('update') From 68a02fe0094fb4c92cdb9269d54d36db9d260edb Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 11:03:45 -0600 Subject: [PATCH 26/33] Use `backwardsScanInRange` instead of passing `true` --- src/packages/bracket-matcher/lib/bracket-matcher.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/packages/bracket-matcher/lib/bracket-matcher.coffee b/src/packages/bracket-matcher/lib/bracket-matcher.coffee index 11398aad2..e5cc0c16c 100644 --- a/src/packages/bracket-matcher/lib/bracket-matcher.coffee +++ b/src/packages/bracket-matcher/lib/bracket-matcher.coffee @@ -116,14 +116,13 @@ module.exports = regex = new RegExp("[#{_.escapeRegExp(startPair + endPair)}]", 'g') startPairPosition = null unpairedCount = 0 - scanner = (match, range, {stop}) => + buffer.backwardsScanInRange regex, scanRange, (match, range, {stop}) => if match[0] is endPair unpairedCount++ else if match[0] is startPair unpairedCount-- startPairPosition = range.start stop() if unpairedCount < 0 - buffer.scanInRange(regex, scanRange, scanner, true) startPairPosition updateMatch: (editor) -> From 59a5a5bc8f00f657b236f1c6c08069da611cdb0b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 11:09:26 -0600 Subject: [PATCH 27/33] Always pass a hash to TextBuffer.scanInRange iterators This makes it easy to only assign variables for the information you need in the iterator. Before, we always forced you to take a match and a range as the first two arguments even if you weren't using them. --- spec/app/text-buffer-spec.coffee | 24 ++++++++-------- src/app/cursor.coffee | 28 +++++++++---------- src/app/edit-session.coffee | 2 +- src/app/text-buffer.coffee | 2 +- .../autocomplete/lib/autocomplete-view.coffee | 2 +- .../lib/bracket-matcher.coffee | 4 +-- .../lib/commands/regex-address.coffee | 4 +-- .../lib/commands/select-all-matches.coffee | 6 ++-- .../lib/commands/substitution.coffee | 6 ++-- src/packages/whitespace/lib/whitespace.coffee | 2 +- 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 72233ba16..dbf75502d 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -546,7 +546,7 @@ describe 'Buffer', -> describe "when given a regex with a ignore case flag", -> it "does a case-insensitive search", -> matches = [] - buffer.scanInRange /cuRRent/i, [[0,0], [12,0]], (match, range) -> + buffer.scanInRange /cuRRent/i, [[0,0], [12,0]], ({match, range}) -> matches.push(match) expect(matches.length).toBe 1 @@ -554,7 +554,7 @@ describe 'Buffer', -> it "calls the iterator with the first match for the given regex in the given range", -> matches = [] ranges = [] - buffer.scanInRange /cu(rr)ent/, [[4,0], [6,44]], (match, range) -> + buffer.scanInRange /cu(rr)ent/, [[4,0], [6,44]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -569,7 +569,7 @@ describe 'Buffer', -> it "calls the iterator with each match for the given regex in the given range", -> matches = [] ranges = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -593,7 +593,7 @@ describe 'Buffer', -> it "calls the iterator with the truncated match", -> matches = [] ranges = [] - buffer.scanInRange /cu(r*)/g, [[4,0], [6,9]], (match, range) -> + buffer.scanInRange /cu(r*)/g, [[4,0], [6,9]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -612,7 +612,7 @@ describe 'Buffer', -> it "calls the iterator with the truncated match", -> matches = [] ranges = [] - buffer.scanInRange /cu(r*)e/g, [[4,0], [6,9]], (match, range) -> + buffer.scanInRange /cu(r*)e/g, [[4,0], [6,9]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -626,7 +626,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'replace' control function with a replacement string", -> it "replaces each occurrence of the regex match with the string", -> ranges = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, replace}) -> ranges.push(range) replace("foo") @@ -638,7 +638,7 @@ describe 'Buffer', -> expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);' it "allows the match to be replaced with the empty string", -> - buffer.scanInRange /current/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.scanInRange /current/g, [[4,0], [6,59]], ({replace}) -> replace("") expect(buffer.lineForRow(5)).toBe ' = items.shift();' @@ -647,7 +647,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'stop' control function", -> it "stops the traversal", -> ranges = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { stop }) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, stop}) -> ranges.push(range) stop() if ranges.length == 2 @@ -658,7 +658,7 @@ describe 'Buffer', -> it "calls the iterator with the last match for the given regex in the given range", -> matches = [] ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/, [[4,0], [6,44]], (match, range) -> + buffer.backwardsScanInRange /cu(rr)ent/, [[4,0], [6,44]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -673,7 +673,7 @@ describe 'Buffer', -> it "calls the iterator with each match for the given regex in the given range, starting with the last match", -> matches = [] ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -695,7 +695,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'replace' control function with a replacement string", -> it "replaces each occurrence of the regex match with the string", -> ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, replace}) -> ranges.push(range) replace("foo") unless range.start.isEqual([6,6]) @@ -709,7 +709,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'stop' control function", -> it "stops the traversal", -> ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { stop }) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, stop}) -> ranges.push(range) stop() if ranges.length == 2 diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 5708d4bf7..f12a78c65 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -133,20 +133,20 @@ class Cursor moveToFirstCharacterOfLine: -> position = @getBufferPosition() - range = @getCurrentLineBufferRange() + scanRange = @getCurrentLineBufferRange() newPosition = null - @editSession.scanInRange /^\s*/, range, (match, matchRange) => - newPosition = matchRange.end + @editSession.scanInRange /^\s*/, scanRange, ({range}) => + newPosition = range.end return unless newPosition newPosition = [position.row, 0] if newPosition.isEqual(position) @setBufferPosition(newPosition) skipLeadingWhitespace: -> position = @getBufferPosition() - range = @getCurrentLineBufferRange() + scanRange = @getCurrentLineBufferRange() endOfLeadingWhitespace = null - @editSession.scanInRange /^[ \t]*/, range, (match, matchRange) => - endOfLeadingWhitespace = matchRange.end + @editSession.scanInRange /^[ \t]*/, scanRange, ({range}) => + endOfLeadingWhitespace = range.end @setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position) @@ -164,12 +164,12 @@ class Cursor allowPrevious = options.allowPrevious ? true currentBufferPosition = @getBufferPosition() previousNonBlankRow = @editSession.buffer.previousNonBlankRow(currentBufferPosition.row) - range = [[previousNonBlankRow, 0], currentBufferPosition] + scanRange = [[previousNonBlankRow, 0], currentBufferPosition] beginningOfWordPosition = null - @editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) => - if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious - beginningOfWordPosition = matchRange.start + @editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + if range.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious + beginningOfWordPosition = range.start if not beginningOfWordPosition?.isEqual(currentBufferPosition) stop() @@ -178,12 +178,12 @@ class Cursor getEndOfCurrentWordBufferPosition: (options = {}) -> allowNext = options.allowNext ? true currentBufferPosition = @getBufferPosition() - range = [currentBufferPosition, @editSession.getEofBufferPosition()] + scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()] endOfWordPosition = null - @editSession.scanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) => - if matchRange.start.isLessThanOrEqual(currentBufferPosition) or allowNext - endOfWordPosition = matchRange.end + @editSession.scanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + if range.start.isLessThanOrEqual(currentBufferPosition) or allowNext + endOfWordPosition = range.end if not endOfWordPosition?.isEqual(currentBufferPosition) stop() diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index c1bb8022d..64f6a2a6c 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -245,7 +245,7 @@ class EditSession normalizeTabsInBufferRange: (bufferRange) -> return unless @softTabs - @scanInRange /\t/, bufferRange, (match, range, {replace}) => replace(@getTabText()) + @scanInRange /\t/, bufferRange, ({replace}) => replace(@getTabText()) cutToEndOfLine: -> maintainPasteboard = false diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 36f93724c..803e009bf 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -404,7 +404,7 @@ class Buffer range = new Range(startPosition, endPosition) keepLooping = true replacementText = null - iterator(match, range, { stop, replace }) + iterator({match, range, stop, replace }) if replacementText? @change(range, replacementText) diff --git a/src/packages/autocomplete/lib/autocomplete-view.coffee b/src/packages/autocomplete/lib/autocomplete-view.coffee index 2123c442f..8da239fc2 100644 --- a/src/packages/autocomplete/lib/autocomplete-view.coffee +++ b/src/packages/autocomplete/lib/autocomplete-view.coffee @@ -142,7 +142,7 @@ class AutocompleteView extends SelectList lineRange = [[selectionRange.start.row, 0], [selectionRange.end.row, @editor.lineLengthForBufferRow(selectionRange.end.row)]] [prefix, suffix] = ["", ""] - @currentBuffer.scanInRange @wordRegex, lineRange, (match, range, {stop}) -> + @currentBuffer.scanInRange @wordRegex, lineRange, ({match, range, stop}) -> stop() if range.start.isGreaterThan(selectionRange.end) if range.intersectsWith(selectionRange) diff --git a/src/packages/bracket-matcher/lib/bracket-matcher.coffee b/src/packages/bracket-matcher/lib/bracket-matcher.coffee index e5cc0c16c..4d80300fa 100644 --- a/src/packages/bracket-matcher/lib/bracket-matcher.coffee +++ b/src/packages/bracket-matcher/lib/bracket-matcher.coffee @@ -102,7 +102,7 @@ module.exports = regex = new RegExp("[#{_.escapeRegExp(startPair + endPair)}]", 'g') endPairPosition = null unpairedCount = 0 - buffer.scanInRange regex, scanRange, (match, range, {stop}) => + buffer.scanInRange regex, scanRange, ({match, range, stop}) => if match[0] is startPair unpairedCount++ else if match[0] is endPair @@ -116,7 +116,7 @@ module.exports = regex = new RegExp("[#{_.escapeRegExp(startPair + endPair)}]", 'g') startPairPosition = null unpairedCount = 0 - buffer.backwardsScanInRange regex, scanRange, (match, range, {stop}) => + buffer.backwardsScanInRange regex, scanRange, ({match, range, stop}) => if match[0] is endPair unpairedCount++ else if match[0] is startPair diff --git a/src/packages/command-panel/lib/commands/regex-address.coffee b/src/packages/command-panel/lib/commands/regex-address.coffee index d2828a6be..9764d0cae 100644 --- a/src/packages/command-panel/lib/commands/regex-address.coffee +++ b/src/packages/command-panel/lib/commands/regex-address.coffee @@ -24,12 +24,12 @@ class RegexAddress extends Address rangeToReturn = null scanMethodName = if @isReversed then "backwardsScanInRange" else "scanInRange" - buffer[scanMethodName] @regex, rangeToSearch, (match, range) -> + buffer[scanMethodName] @regex, rangeToSearch, ({range}) -> rangeToReturn = range if not rangeToReturn rangeToSearch = if @isReversed then rangeAfter else rangeBefore - buffer[scanMethodName] @regex, rangeToSearch, (match, range) -> + buffer[scanMethodName] @regex, rangeToSearch, ({range}) -> rangeToReturn = range if not rangeToReturn diff --git a/src/packages/command-panel/lib/commands/select-all-matches.coffee b/src/packages/command-panel/lib/commands/select-all-matches.coffee index ad1b0bca9..dc0eaef35 100644 --- a/src/packages/command-panel/lib/commands/select-all-matches.coffee +++ b/src/packages/command-panel/lib/commands/select-all-matches.coffee @@ -12,12 +12,12 @@ class SelectAllMatches extends Command compile: (project, buffer, ranges) -> deferred = $.Deferred() operations = [] - for range in ranges - buffer.scanInRange @regex, range, (match, matchRange) -> + for scanRange in ranges + buffer.scanInRange @regex, scanRange, ({range}) -> operations.push(new Operation( project: project buffer: buffer - bufferRange: matchRange + bufferRange: range )) deferred.resolve(operations) deferred.promise() diff --git a/src/packages/command-panel/lib/commands/substitution.coffee b/src/packages/command-panel/lib/commands/substitution.coffee index 66a621bc2..71a229c32 100644 --- a/src/packages/command-panel/lib/commands/substitution.coffee +++ b/src/packages/command-panel/lib/commands/substitution.coffee @@ -15,12 +15,12 @@ class Substitution extends Command compile: (project, buffer, ranges) -> deferred = $.Deferred() operations = [] - for range in ranges - buffer.scanInRange @regex, range, (match, matchRange) => + for scanRange in ranges + buffer.scanInRange @regex, scanRange, ({range}) => operations.push(new Operation( project: project buffer: buffer - bufferRange: matchRange + bufferRange: range newText: @replacementText preserveSelection: true )) diff --git a/src/packages/whitespace/lib/whitespace.coffee b/src/packages/whitespace/lib/whitespace.coffee index 087bfabd3..f5c954ba5 100644 --- a/src/packages/whitespace/lib/whitespace.coffee +++ b/src/packages/whitespace/lib/whitespace.coffee @@ -8,7 +8,7 @@ module.exports = whitespaceBeforeSave: (buffer) -> buffer.on 'will-be-saved', -> buffer.transact -> - buffer.scan /[ \t]+$/g, (match, range, { replace }) -> replace('') + buffer.scan /[ \t]+$/g, ({replace}) -> replace('') if config.get('whitespace.ensureSingleTrailingNewline') if buffer.getLastLine() is '' From 5df78812ef2c5589b765c1da952a064fdee57d72 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 11:28:55 -0600 Subject: [PATCH 28/33] Rename EditSession.scanInRange to scanInBufferRange This is more consistent with other range-oriented methods on EditSession. At this layer, we need to be explicit about what kind of range we are talking about. --- src/app/cursor.coffee | 8 ++++---- src/app/edit-session.coffee | 6 +++--- src/app/editor.coffee | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index f12a78c65..8f1a21d67 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -135,7 +135,7 @@ class Cursor position = @getBufferPosition() scanRange = @getCurrentLineBufferRange() newPosition = null - @editSession.scanInRange /^\s*/, scanRange, ({range}) => + @editSession.scanInBufferRange /^\s*/, scanRange, ({range}) => newPosition = range.end return unless newPosition newPosition = [position.row, 0] if newPosition.isEqual(position) @@ -145,7 +145,7 @@ class Cursor position = @getBufferPosition() scanRange = @getCurrentLineBufferRange() endOfLeadingWhitespace = null - @editSession.scanInRange /^[ \t]*/, scanRange, ({range}) => + @editSession.scanInBufferRange /^[ \t]*/, scanRange, ({range}) => endOfLeadingWhitespace = range.end @setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position) @@ -167,7 +167,7 @@ class Cursor scanRange = [[previousNonBlankRow, 0], currentBufferPosition] beginningOfWordPosition = null - @editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + @editSession.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => if range.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious beginningOfWordPosition = range.start if not beginningOfWordPosition?.isEqual(currentBufferPosition) @@ -181,7 +181,7 @@ class Cursor scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()] endOfWordPosition = null - @editSession.scanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + @editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => if range.start.isLessThanOrEqual(currentBufferPosition) or allowNext endOfWordPosition = range.end if not endOfWordPosition?.isEqual(currentBufferPosition) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 64f6a2a6c..b420f7875 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -163,8 +163,8 @@ class EditSession bufferRangeForBufferRow: (row, options) -> @buffer.rangeForRow(row, options) lineForBufferRow: (row) -> @buffer.lineForRow(row) lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row) - scanInRange: (args...) -> @buffer.scanInRange(args...) - backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...) + scanInBufferRange: (args...) -> @buffer.scanInRange(args...) + backwardsScanInBufferRange: (args...) -> @buffer.backwardsScanInRange(args...) isModified: -> @buffer.isModified() hasEditors: -> @buffer.hasEditors() @@ -245,7 +245,7 @@ class EditSession normalizeTabsInBufferRange: (bufferRange) -> return unless @softTabs - @scanInRange /\t/, bufferRange, ({replace}) => replace(@getTabText()) + @scanInBufferRange /\t/, bufferRange, ({replace}) => replace(@getTabText()) cutToEndOfLine: -> maintainPasteboard = false diff --git a/src/app/editor.coffee b/src/app/editor.coffee index a9583b713..a3bed0f00 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -315,8 +315,8 @@ class Editor extends View lineForBufferRow: (row) -> @getBuffer().lineForRow(row) lineLengthForBufferRow: (row) -> @getBuffer().lineLengthForRow(row) rangeForBufferRow: (row) -> @getBuffer().rangeForRow(row) - scanInRange: (args...) -> @getBuffer().scanInRange(args...) - backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...) + scanInBufferRange: (args...) -> @getBuffer().scanInRange(args...) + backwardsScanInBufferRange: (args...) -> @getBuffer().backwardsScanInRange(args...) configure: -> @observeConfig 'editor.showLineNumbers', (showLineNumbers) => @gutter.setShowLineNumbers(showLineNumbers) From a99e4ef5a97a80f61e88f2fc9ee7a428b01e0d51 Mon Sep 17 00:00:00 2001 From: Jeremy McAnally Date: Wed, 3 Apr 2013 14:44:30 -0300 Subject: [PATCH 29/33] Making an edit to .github To make the docs build... --- .github | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github b/.github index fc652aa74..f9562bce3 100644 --- a/.github +++ b/.github @@ -1,2 +1,2 @@ [docs] - title = The Guide to Atom +title = The Guide to Atom From f03b6207de9180e005d46be057edf8a86b72ccb1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 12:01:01 -0600 Subject: [PATCH 30/33] Make all requires of 'fs-utils' assign to fsUtils var instead of fs --- benchmark/benchmark-suite.coffee | 1 - spec/app/atom-spec.coffee | 20 +-- spec/app/config-spec.coffee | 50 +++---- spec/app/directory-spec.coffee | 24 ++-- spec/app/editor-spec.coffee | 38 +++--- spec/app/file-spec.coffee | 34 ++--- spec/app/git-spec.coffee | 110 +++++++-------- spec/app/project-spec.coffee | 50 +++---- spec/app/root-view-spec.coffee | 6 +- spec/app/syntax-spec.coffee | 8 +- spec/app/text-buffer-spec.coffee | 64 ++++----- spec/app/text-mate-grammar-spec.coffee | 6 +- spec/app/text-mate-theme-spec.coffee | 4 +- spec/app/theme-spec.coffee | 4 +- spec/app/window-spec.coffee | 14 +- spec/jasmine-helper.coffee | 6 +- spec/spec-helper.coffee | 10 +- spec/spec-suite.coffee | 8 +- spec/stdlib/fs-utils-spec.coffee | 96 ++++++------- src/app/atom-theme.coffee | 12 +- src/app/atom.coffee | 22 +-- src/app/binding-set.coffee | 4 +- src/app/config.coffee | 42 +++--- src/app/edit-session.coffee | 10 +- src/app/editor.coffee | 6 +- src/app/git.coffee | 4 +- src/app/keymap.coffee | 8 +- src/app/package.coffee | 4 +- src/app/project.coffee | 12 +- src/app/repository-status-handler.coffee | 4 +- src/app/root-view.coffee | 3 +- src/app/syntax.coffee | 4 +- src/app/text-buffer.coffee | 4 +- src/app/text-mate-grammar.coffee | 8 +- src/app/text-mate-theme.coffee | 2 +- src/app/theme.coffee | 6 +- src/app/window.coffee | 26 ++-- .../lib/command-interpreter.coffee | 4 +- .../command-panel/lib/path-view.coffee | 4 +- .../command-panel/lib/preview-list.coffee | 2 +- .../fuzzy-finder/lib/fuzzy-finder-view.coffee | 22 +-- .../fuzzy-finder/lib/load-paths-task.coffee | 6 +- .../spec/fuzzy-finder-spec.coffee | 18 +-- .../lib/markdown-preview-view.coffee | 1 - .../lib/package-generator-view.coffee | 30 ++--- .../spec/package-generator-spec.coffee | 16 +-- .../snippets/lib/snippet-body-parser.coffee | 4 +- .../snippets/spec/snippets-spec.coffee | 1 - .../status-bar/spec/status-bar-spec.coffee | 32 ++--- .../symbols-view/lib/load-tags-handler.coffee | 10 +- .../symbols-view/lib/symbols-view.coffee | 12 +- .../symbols-view/lib/tag-generator.coffee | 4 +- .../symbols-view/lib/tag-reader.coffee | 4 +- .../spec/symbols-view-spec.coffee | 14 +- src/packages/tabs/lib/tab-view.coffee | 4 +- src/packages/tabs/spec/tabs-spec.coffee | 1 - src/packages/tree-view/lib/dialog.coffee | 6 +- src/packages/tree-view/lib/file-view.coffee | 14 +- src/packages/tree-view/lib/tree-view.coffee | 22 +-- .../tree-view/spec/tree-view-spec.coffee | 126 +++++++++--------- .../whitespace/spec/whitespace-spec.coffee | 9 +- src/stdlib/task.coffee | 2 +- 62 files changed, 548 insertions(+), 554 deletions(-) diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index 8f549b061..fd5fd0533 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -1,5 +1,4 @@ require 'benchmark-helper' -fs = require 'fs-utils' $ = require 'jquery' _ = require 'underscore' TokenizedBuffer = require 'tokenized-buffer' diff --git a/spec/app/atom-spec.coffee b/spec/app/atom-spec.coffee index df2ff94d0..1da757d0f 100644 --- a/spec/app/atom-spec.coffee +++ b/spec/app/atom-spec.coffee @@ -1,7 +1,7 @@ $ = require 'jquery' RootView = require 'root-view' {$$} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "the `atom` global", -> beforeEach -> @@ -129,9 +129,9 @@ describe "the `atom` global", -> describe "stylesheet loading", -> describe "when the metadata contains a 'stylesheets' manifest", -> it "loads stylesheets from the stylesheets directory as specified by the manifest", -> - one = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/1.css") - two = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/2.less") - three = fs.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/3.css") + one = fsUtils.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/1.css") + two = fsUtils.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/2.less") + three = fsUtils.resolveOnLoadPath("package-with-stylesheets-manifest/stylesheets/3.css") expect(stylesheetElementForId(one)).not.toExist() expect(stylesheetElementForId(two)).not.toExist() expect(stylesheetElementForId(three)).not.toExist() @@ -145,9 +145,9 @@ describe "the `atom` global", -> describe "when the metadata does not contain a 'stylesheets' manifest", -> it "loads all stylesheets from the stylesheets directory", -> - one = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/1.css") - two = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/2.less") - three = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/3.css") + one = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/1.css") + two = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/2.less") + three = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/3.css") expect(stylesheetElementForId(one)).not.toExist() expect(stylesheetElementForId(two)).not.toExist() expect(stylesheetElementForId(three)).not.toExist() @@ -215,9 +215,9 @@ describe "the `atom` global", -> it "removes the package's stylesheets", -> atom.activatePackage('package-with-stylesheets') atom.deactivatePackage('package-with-stylesheets') - one = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/1.css") - two = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/2.less") - three = fs.resolveOnLoadPath("package-with-stylesheets/stylesheets/3.css") + one = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/1.css") + two = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/2.less") + three = fsUtils.resolveOnLoadPath("package-with-stylesheets/stylesheets/3.css") expect(stylesheetElementForId(one)).not.toExist() expect(stylesheetElementForId(two)).not.toExist() expect(stylesheetElementForId(three)).not.toExist() diff --git a/spec/app/config-spec.coffee b/spec/app/config-spec.coffee index 2daa360cd..797923af1 100644 --- a/spec/app/config-spec.coffee +++ b/spec/app/config-spec.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "Config", -> describe ".get(keyPath) and .set(keyPath, value)", -> @@ -19,38 +19,38 @@ describe "Config", -> describe ".save()", -> beforeEach -> - spyOn(fs, 'write') + spyOn(fsUtils, 'write') jasmine.unspy config, 'save' describe "when ~/.atom/config.json exists", -> it "writes any non-default properties to ~/.atom/config.json", -> - config.configFilePath = fs.join(config.configDirPath, "config.json") + config.configFilePath = fsUtils.join(config.configDirPath, "config.json") config.set("a.b.c", 1) config.set("a.b.d", 2) config.set("x.y.z", 3) config.setDefaults("a.b", e: 4, f: 5) - fs.write.reset() + fsUtils.write.reset() config.save() - expect(fs.write.argsForCall[0][0]).toBe(fs.join(config.configDirPath, "config.json")) - writtenConfig = JSON.parse(fs.write.argsForCall[0][1]) + expect(fsUtils.write.argsForCall[0][0]).toBe(fsUtils.join(config.configDirPath, "config.json")) + writtenConfig = JSON.parse(fsUtils.write.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 = fs.join(config.configDirPath, "config.cson") + config.configFilePath = fsUtils.join(config.configDirPath, "config.cson") config.set("a.b.c", 1) config.set("a.b.d", 2) config.set("x.y.z", 3) config.setDefaults("a.b", e: 4, f: 5) - fs.write.reset() + fsUtils.write.reset() config.save() - expect(fs.write.argsForCall[0][0]).toBe(fs.join(config.configDirPath, "config.cson")) + expect(fsUtils.write.argsForCall[0][0]).toBe(fsUtils.join(config.configDirPath, "config.cson")) CoffeeScript = require 'coffee-script' - writtenConfig = CoffeeScript.eval(fs.write.argsForCall[0][1], bare: true) + writtenConfig = CoffeeScript.eval(fsUtils.write.argsForCall[0][1], bare: true) expect(writtenConfig).toEqual config.settings describe ".setDefaults(keyPath, defaults)", -> @@ -113,40 +113,40 @@ describe "Config", -> describe "initializeConfigDirectory()", -> beforeEach -> config.configDirPath = '/tmp/dot-atom-dir' - expect(fs.exists(config.configDirPath)).toBeFalsy() + expect(fsUtils.exists(config.configDirPath)).toBeFalsy() afterEach -> - fs.remove('/tmp/dot-atom-dir') if fs.exists('/tmp/dot-atom-dir') + fsUtils.remove('/tmp/dot-atom-dir') if fsUtils.exists('/tmp/dot-atom-dir') describe "when the configDirPath doesn't exist", -> it "copies the contents of dot-atom to ~/.atom", -> config.initializeConfigDirectory() - expect(fs.exists(config.configDirPath)).toBeTruthy() - expect(fs.exists(fs.join(config.configDirPath, 'packages'))).toBeTruthy() - expect(fs.exists(fs.join(config.configDirPath, 'snippets'))).toBeTruthy() - expect(fs.exists(fs.join(config.configDirPath, 'themes'))).toBeTruthy() - expect(fs.isFile(fs.join(config.configDirPath, 'config.cson'))).toBeTruthy() + 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() it "copies the bundles themes to ~/.atom", -> config.initializeConfigDirectory() - expect(fs.isFile(fs.join(config.configDirPath, 'themes/atom-dark-ui/package.cson'))).toBeTruthy() - expect(fs.isFile(fs.join(config.configDirPath, 'themes/atom-light-ui/package.cson'))).toBeTruthy() - expect(fs.isFile(fs.join(config.configDirPath, 'themes/atom-dark-syntax.css'))).toBeTruthy() - expect(fs.isFile(fs.join(config.configDirPath, 'themes/atom-light-syntax.css'))).toBeTruthy() + 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.css'))).toBeTruthy() + expect(fsUtils.isFile(fsUtils.join(config.configDirPath, 'themes/atom-light-syntax.css'))).toBeTruthy() describe "when the config file is not parseable", -> beforeEach -> config.configDirPath = '/tmp/dot-atom-dir' - config.configFilePath = fs.join(config.configDirPath, "config.cson") - expect(fs.exists(config.configDirPath)).toBeFalsy() + config.configFilePath = fsUtils.join(config.configDirPath, "config.cson") + expect(fsUtils.exists(config.configDirPath)).toBeFalsy() afterEach -> - fs.remove('/tmp/dot-atom-dir') if fs.exists('/tmp/dot-atom-dir') + fsUtils.remove('/tmp/dot-atom-dir') if fsUtils.exists('/tmp/dot-atom-dir') it "logs an error to the console and does not overwrite the config file", -> config.save.reset() spyOn(console, 'error') - fs.write(config.configFilePath, "{{{{{") + fsUtils.write(config.configFilePath, "{{{{{") config.loadUserConfig() config.set("hair", "blonde") # trigger a save expect(console.error).toHaveBeenCalled() diff --git a/spec/app/directory-spec.coffee b/spec/app/directory-spec.coffee index 4bbd8ea02..a56eee671 100644 --- a/spec/app/directory-spec.coffee +++ b/spec/app/directory-spec.coffee @@ -1,11 +1,11 @@ Directory = require 'directory' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "Directory", -> directory = null beforeEach -> - directory = new Directory(fs.resolveOnLoadPath('fixtures')) + directory = new Directory(fsUtils.resolveOnLoadPath('fixtures')) afterEach -> directory.off() @@ -14,11 +14,11 @@ describe "Directory", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fs.join(fs.resolveOnLoadPath('fixtures'), 'temporary') - fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath) + temporaryFilePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures'), 'temporary') + fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) afterEach -> - fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath) + fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) it "triggers 'contents-changed' event handlers", -> changeHandler = null @@ -26,13 +26,13 @@ describe "Directory", -> runs -> changeHandler = jasmine.createSpy('changeHandler') directory.on 'contents-changed', changeHandler - fs.write(temporaryFilePath, '') + fsUtils.write(temporaryFilePath, '') waitsFor "first change", -> changeHandler.callCount > 0 runs -> changeHandler.reset() - fs.remove(temporaryFilePath) + fsUtils.remove(temporaryFilePath) waitsFor "second change", -> changeHandler.callCount > 0 @@ -40,11 +40,11 @@ describe "Directory", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fs.join(directory.path, 'temporary') - fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath) + temporaryFilePath = fsUtils.join(directory.path, 'temporary') + fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) afterEach -> - fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath) + fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) it "no longer triggers events", -> changeHandler = null @@ -52,7 +52,7 @@ describe "Directory", -> runs -> changeHandler = jasmine.createSpy('changeHandler') directory.on 'contents-changed', changeHandler - fs.write(temporaryFilePath, '') + fsUtils.write(temporaryFilePath, '') waitsFor "change event", -> changeHandler.callCount > 0 @@ -61,7 +61,7 @@ describe "Directory", -> directory.off() waits 20 - runs -> fs.remove(temporaryFilePath) + runs -> fsUtils.remove(temporaryFilePath) waits 20 runs -> expect(changeHandler.callCount).toBe 0 diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index bbfa1ba99..4424d9d73 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -6,7 +6,7 @@ Project = require 'project' $ = require 'jquery' {$$} = require 'space-pen' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "Editor", -> [buffer, editor, editSession, cachedLineHeight, cachedCharWidth] = [] @@ -83,7 +83,7 @@ describe "Editor", -> describe "when the activeEditSession's file is modified on disk", -> it "triggers an alert", -> path = "/tmp/atom-changed-file.txt" - fs.write(path, "") + fsUtils.write(path, "") editSession = project.buildEditSession(path) editor.edit(editSession) editor.insertText("now the buffer is modified") @@ -93,7 +93,7 @@ describe "Editor", -> spyOn(atom, "confirm") - fs.write(path, "a file change") + fsUtils.write(path, "a file change") waitsFor "file to trigger contents-changed event", -> fileChangeHandler.callCount > 0 @@ -147,7 +147,7 @@ describe "Editor", -> it "triggers alert if edit session's buffer goes into conflict with changes on disk", -> path = "/tmp/atom-changed-file.txt" - fs.write(path, "") + fsUtils.write(path, "") tempEditSession = project.buildEditSession(path) editor.edit(tempEditSession) tempEditSession.insertText("a buffer change") @@ -156,7 +156,7 @@ describe "Editor", -> contentsConflictedHandler = jasmine.createSpy("contentsConflictedHandler") tempEditSession.on 'contents-conflicted', contentsConflictedHandler - fs.write(path, "a file change") + fsUtils.write(path, "a file change") waitsFor -> contentsConflictedHandler.callCount > 0 @@ -228,10 +228,10 @@ describe "Editor", -> path = null beforeEach -> path = "/tmp/something.txt" - fs.write(path, path) + fsUtils.write(path, path) afterEach -> - fs.remove(path) if fs.exists(path) + fsUtils.remove(path) if fsUtils.exists(path) it "emits event when buffer's path is changed", -> eventHandler = jasmine.createSpy('eventHandler') @@ -390,7 +390,7 @@ describe "Editor", -> editor.clearFontFamily() it "positions the cursor to the clicked row and column", -> - {top, left} = editor.pixelOffsetForScreenPosition([3, 30]) + {top, left} = editor.pixelOffsUtilsetForScreenPosition([3, 30]) editor.renderedLines.trigger mousedownEvent(pageX: left, pageY: top) expect(editor.getCursorScreenPosition()).toEqual [3, 30] @@ -786,7 +786,7 @@ describe "Editor", -> setEditorHeightInLines(editor, 4) describe "if autoscroll is true", -> - it "centers the viewport on the selection if its vertical center is currently offscreen", -> + it "centers the viewport on the selection if its vertical center is currently offsUtilscreen", -> editor.setSelectedBufferRange([[2, 0], [4, 0]], autoscroll: true) expect(editor.scrollTop()).toBe 0 @@ -1197,7 +1197,7 @@ describe "Editor", -> expect(editor.renderedLines.find('.line:last').text()).toBe buffer.lineForRow(7) describe "when scrolling more than the editors height", -> - it "removes lines that are offscreen and not in range of the overdraw and builds lines that become visible", -> + it "removes lines that are offsUtilscreen and not in range of the overdraw and builds lines that become visible", -> editor.scrollTop(editor.scrollView.prop('scrollHeight') - editor.scrollView.height()) expect(editor.renderedLines.find('.line').length).toBe 8 expect(editor.renderedLines.find('.line:first').text()).toBe buffer.lineForRow(5) @@ -2003,11 +2003,11 @@ describe "Editor", -> beforeEach -> path = project.resolve('git/working-dir/file.txt') - originalPathText = fs.read(path) + originalPathText = fsUtils.read(path) editor.edit(project.buildEditSession(path)) afterEach -> - fs.write(path, originalPathText) + fsUtils.write(path, originalPathText) it "restores the contents of the editor to the HEAD revision", -> editor.setText('') @@ -2103,11 +2103,11 @@ describe "Editor", -> [path] = [] beforeEach -> - path = fs.join(fs.absolute("/tmp"), "grammar-change.txt") - fs.write(path, "var i;") + path = fsUtils.join(fsUtils.absolute("/tmp"), "grammar-change.txt") + fsUtils.write(path, "var i;") afterEach -> - fs.remove(path) if fs.exists(path) + fsUtils.remove(path) if fsUtils.exists(path) it "updates all the rendered lines when the grammar changes", -> editor.edit(project.buildEditSession(path)) @@ -2451,12 +2451,12 @@ describe "Editor", -> it "saves the state of the rendered lines, the display buffer, and the buffer to a file of the user's choosing", -> saveDialogCallback = null spyOn(atom, 'showSaveDialog').andCallFake (callback) -> saveDialogCallback = callback - spyOn(fs, 'write') + spyOn(fsUtils, 'write') editor.trigger 'editor:save-debug-snapshot' expect(atom.showSaveDialog).toHaveBeenCalled() saveDialogCallback('/tmp/state') - expect(fs.write).toHaveBeenCalled() - expect(fs.write.argsForCall[0][0]).toBe '/tmp/state' - expect(typeof fs.write.argsForCall[0][1]).toBe 'string' + expect(fsUtils.write).toHaveBeenCalled() + expect(fsUtils.write.argsForCall[0][0]).toBe '/tmp/state' + expect(typeof fsUtils.write.argsForCall[0][1]).toBe 'string' diff --git a/spec/app/file-spec.coffee b/spec/app/file-spec.coffee index 21f57833f..9cbd613c0 100644 --- a/spec/app/file-spec.coffee +++ b/spec/app/file-spec.coffee @@ -1,33 +1,33 @@ File = require 'file' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe 'File', -> [path, file] = [] beforeEach -> - path = fs.join(fs.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test - fs.remove(path) if fs.exists(path) - fs.write(path, "this is old!") + path = 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 + fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.write(path, "this is old!") file = new File(path) file.read() afterEach -> file.off() - fs.remove(path) if fs.exists(path) + fsUtils.remove(path) if fsUtils.exists(path) describe "when the contents of the file change", -> it "triggers 'contents-changed' event handlers", -> changeHandler = null changeHandler = jasmine.createSpy('changeHandler') file.on 'contents-changed', changeHandler - fs.write(file.getPath(), "this is new!") + fsUtils.write(file.getPath(), "this is new!") waitsFor "change event", -> changeHandler.callCount > 0 runs -> changeHandler.reset() - fs.write(file.getPath(), "this is newer!") + fsUtils.write(file.getPath(), "this is newer!") waitsFor "second change event", -> changeHandler.callCount > 0 @@ -37,7 +37,7 @@ describe 'File', -> removeHandler = null removeHandler = jasmine.createSpy('removeHandler') file.on 'removed', removeHandler - fs.remove(file.getPath()) + fsUtils.remove(file.getPath()) waitsFor "remove event", -> removeHandler.callCount > 0 @@ -46,11 +46,11 @@ describe 'File', -> newPath = null beforeEach -> - newPath = fs.join(fs.directory(path), "atom-file-was-moved-test.txt") + newPath = fsUtils.join(fsUtils.directory(path), "atom-file-was-moved-test.txt") afterEach -> - if fs.exists(newPath) - fs.remove(newPath) + if fsUtils.exists(newPath) + fsUtils.remove(newPath) waitsFor "remove event", (done) -> file.on 'removed', done it "it updates its path", -> @@ -58,7 +58,7 @@ describe 'File', -> moveHandler = jasmine.createSpy('moveHandler') file.on 'moved', moveHandler - fs.move(path, newPath) + fsUtils.move(path, newPath) waitsFor "move event", -> moveHandler.callCount > 0 @@ -74,14 +74,14 @@ describe 'File', -> changeHandler = jasmine.createSpy('changeHandler') file.on 'contents-changed', changeHandler - fs.move(path, newPath) + fsUtils.move(path, newPath) waitsFor "move event", -> moveHandler.callCount > 0 runs -> expect(changeHandler).not.toHaveBeenCalled() - fs.write(file.getPath(), "this is new!") + fsUtils.write(file.getPath(), "this is new!") waitsFor "change event", -> changeHandler.callCount > 0 @@ -98,12 +98,12 @@ describe 'File', -> expect(changeHandler).not.toHaveBeenCalled() - fs.remove(path) + fsUtils.remove(path) expect(changeHandler).not.toHaveBeenCalled() waits 20 runs -> - fs.write(path, "HE HAS RISEN!") + fsUtils.write(path, "HE HAS RISEN!") expect(changeHandler).not.toHaveBeenCalled() waitsFor "resurrection change event", -> @@ -111,7 +111,7 @@ describe 'File', -> runs -> expect(removeHandler).not.toHaveBeenCalled() - fs.write(path, "Hallelujah!") + fsUtils.write(path, "Hallelujah!") changeHandler.reset() waitsFor "post-resurrection change event", -> diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 921d88cc5..ade848136 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -1,12 +1,12 @@ Git = require 'git' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Task = require 'task' describe "Git", -> repo = null beforeEach -> - fs.remove('/tmp/.git') if fs.isDirectory('/tmp/.git') + fsUtils.remove('/tmp/.git') if fsUtils.isDirectory('/tmp/.git') afterEach -> repo.destroy() if repo?.repo? @@ -21,55 +21,55 @@ describe "Git", -> describe ".getPath()", -> it "returns the repository path for a .git directory path", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git/HEAD')) - expect(repo.getPath()).toBe fs.resolveOnLoadPath('fixtures/git/master.git') + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/master.git/HEAD')) + expect(repo.getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/git/master.git') it "returns the repository path for a repository path", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git')) - expect(repo.getPath()).toBe fs.resolveOnLoadPath('fixtures/git/master.git') + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/master.git')) + expect(repo.getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/git/master.git') describe ".getHead()", -> it "returns a branch name for a non-empty repository", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/master.git')) expect(repo.getHead()).toBe 'refs/heads/master' describe ".getShortHead()", -> it "returns a branch name for a non-empty repository", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/master.git')) expect(repo.getShortHead()).toBe 'master' describe ".isPathIgnored(path)", -> it "returns true for an ignored path", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/ignore.git')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/ignore.git')) expect(repo.isPathIgnored('a.txt')).toBeTruthy() it "returns false for a non-ignored path", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/ignore.git')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/ignore.git')) expect(repo.isPathIgnored('b.txt')).toBeFalsy() describe ".isPathModified(path)", -> [repo, path, newPath, originalPathText] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) - path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - newPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') - originalPathText = fs.read(path) + 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) afterEach -> - fs.write(path, originalPathText) - fs.remove(newPath) if fs.exists(newPath) + fsUtils.write(path, 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() it "returns true if the path is modified", -> - fs.write(path, "change") + fsUtils.write(path, "change") expect(repo.isPathModified(path)).toBeTruthy() it "returns true if the path is deleted", -> - fs.remove(path) + fsUtils.remove(path) expect(repo.isPathModified(path)).toBeTruthy() it "returns false if the path is new", -> @@ -79,13 +79,13 @@ describe "Git", -> [path, newPath] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) - path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - newPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'new-path.txt') - fs.write(newPath, "i'm new here") + 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') + fsUtils.write(newPath, "i'm new here") afterEach -> - fs.remove(newPath) if fs.exists(newPath) + fsUtils.remove(newPath) if fsUtils.exists(newPath) describe "when the path is unstaged", -> it "returns true if the path is new", -> @@ -98,37 +98,37 @@ describe "Git", -> [path1, path2, originalPath1Text, originalPath2Text] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) - path1 = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - originalPath1Text = fs.read(path1) - path2 = fs.resolveOnLoadPath('fixtures/git/working-dir/other.txt') - originalPath2Text = fs.read(path2) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) + path1 = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + originalPath1Text = fsUtils.read(path1) + path2 = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/other.txt') + originalPath2Text = fsUtils.read(path2) afterEach -> - fs.write(path1, originalPath1Text) - fs.write(path2, originalPath2Text) + fsUtils.write(path1, originalPath1Text) + fsUtils.write(path2, originalPath2Text) it "no longer reports a path as modified after checkout", -> expect(repo.isPathModified(path1)).toBeFalsy() - fs.write(path1, '') + fsUtils.write(path1, '') expect(repo.isPathModified(path1)).toBeTruthy() expect(repo.checkoutHead(path1)).toBeTruthy() expect(repo.isPathModified(path1)).toBeFalsy() it "restores the contents of the path to the original text", -> - fs.write(path1, '') + fsUtils.write(path1, '') expect(repo.checkoutHead(path1)).toBeTruthy() - expect(fs.read(path1)).toBe(originalPath1Text) + expect(fsUtils.read(path1)).toBe(originalPath1Text) it "only restores the path specified", -> - fs.write(path2, 'path 2 is edited') + fsUtils.write(path2, 'path 2 is edited') expect(repo.isPathModified(path2)).toBeTruthy() expect(repo.checkoutHead(path1)).toBeTruthy() - expect(fs.read(path2)).toBe('path 2 is edited') + expect(fsUtils.read(path2)).toBe('path 2 is edited') expect(repo.isPathModified(path2)).toBeTruthy() it "fires a status-changed event if the checkout completes successfully", -> - fs.write(path1, '') + fsUtils.write(path1, '') repo.getPathStatus(path1) statusHandler = jasmine.createSpy('statusHandler') repo.on 'status-changed', statusHandler @@ -141,7 +141,7 @@ describe "Git", -> describe ".destroy()", -> it "throws an exception when any method is called after it is called", -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/master.git/HEAD')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/master.git/HEAD')) repo.destroy() expect(-> repo.getHead()).toThrow() @@ -149,38 +149,38 @@ describe "Git", -> [path, originalPathText] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) - path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - originalPathText = fs.read(path) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) + path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + originalPathText = fsUtils.read(path) afterEach -> - fs.write(path, originalPathText) + fsUtils.write(path, originalPathText) it "returns the number of lines added and deleted", -> expect(repo.getDiffStats(path)).toEqual {added: 0, deleted: 0} - fs.write(path, "#{originalPathText} edited line") + fsUtils.write(path, "#{originalPathText} edited line") expect(repo.getDiffStats(path)).toEqual {added: 1, deleted: 1} describe ".getPathStatus(path)", -> [path, originalPathText] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) - path = fs.resolveOnLoadPath('fixtures/git/working-dir/file.txt') - originalPathText = fs.read(path) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) + path = fsUtils.resolveOnLoadPath('fixtures/git/working-dir/file.txt') + originalPathText = fsUtils.read(path) afterEach -> - fs.write(path, originalPathText) + fsUtils.write(path, originalPathText) it "trigger a status-changed event when the new status differs from the last cached one", -> statusHandler = jasmine.createSpy("statusHandler") repo.on 'status-changed', statusHandler - fs.write(path, '') + fsUtils.write(path, '') status = repo.getPathStatus(path) expect(statusHandler.callCount).toBe 1 expect(statusHandler.argsForCall[0][0..1]).toEqual [path, status] - fs.write(path, 'abc') + fsUtils.write(path, 'abc') status = repo.getPathStatus(path) expect(statusHandler.callCount).toBe 1 @@ -188,19 +188,19 @@ describe "Git", -> [newPath, modifiedPath, cleanPath, originalModifiedPathText] = [] beforeEach -> - repo = new Git(fs.resolveOnLoadPath('fixtures/git/working-dir')) + repo = new Git(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) modifiedPath = project.resolve('git/working-dir/file.txt') - originalModifiedPathText = fs.read(modifiedPath) + originalModifiedPathText = fsUtils.read(modifiedPath) newPath = project.resolve('git/working-dir/untracked.txt') cleanPath = project.resolve('git/working-dir/other.txt') - fs.write(newPath, '') + fsUtils.write(newPath, '') afterEach -> - fs.write(modifiedPath, originalModifiedPathText) - fs.remove(newPath) if fs.exists(newPath) + fsUtils.write(modifiedPath, originalModifiedPathText) + fsUtils.remove(newPath) if fsUtils.exists(newPath) it "returns status information for all new and modified files", -> - fs.write(modifiedPath, 'making this path modified') + fsUtils.write(modifiedPath, 'making this path modified') statusHandler = jasmine.createSpy('statusHandler') repo.on 'statuses-changed', statusHandler repo.refreshStatus() @@ -215,7 +215,7 @@ describe "Git", -> expect(repo.isStatusModified(statuses[modifiedPath])).toBeTruthy() it "only starts a single web worker at a time and schedules a restart if one is already running", => - fs.write(modifiedPath, 'making this path modified') + fsUtils.write(modifiedPath, 'making this path modified') statusHandler = jasmine.createSpy('statusHandler') repo.on 'statuses-changed', statusHandler diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index 48f483fc5..14e0af834 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -1,5 +1,5 @@ Project = require 'project' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' BufferedProcess = require 'buffered-process' @@ -29,12 +29,12 @@ describe "Project", -> editSession = project.buildEditSession() editSession.saveAs('/tmp/atom-test-save-sets-project-path') expect(project.getPath()).toBe '/tmp' - fs.remove('/tmp/atom-test-save-sets-project-path') + fsUtils.remove('/tmp/atom-test-save-sets-project-path') describe ".buildEditSession(path)", -> [absolutePath, newBufferHandler, newEditSessionHandler] = [] beforeEach -> - absolutePath = fs.resolveOnLoadPath('fixtures/dir/a') + absolutePath = fsUtils.resolveOnLoadPath('fixtures/dir/a') newBufferHandler = jasmine.createSpy('newBufferHandler') project.on 'buffer-created', newBufferHandler newEditSessionHandler = jasmine.createSpy('newEditSessionHandler') @@ -86,30 +86,30 @@ describe "Project", -> describe ".resolve(path)", -> it "returns an absolute path based on the project's root", -> - absolutePath = fs.resolveOnLoadPath('fixtures/dir/a') + absolutePath = fsUtils.resolveOnLoadPath('fixtures/dir/a') expect(project.resolve('a')).toBe absolutePath expect(project.resolve(absolutePath + '/../a')).toBe absolutePath expect(project.resolve('a/../a')).toBe absolutePath describe ".relativize(path)", -> it "returns an relative path based on the project's root", -> - absolutePath = fs.resolveOnLoadPath('fixtures/dir') - expect(project.relativize(fs.join(absolutePath, "b"))).toBe "b" - expect(project.relativize(fs.join(absolutePath, "b/file.coffee"))).toBe "b/file.coffee" - expect(project.relativize(fs.join(absolutePath, "file.coffee"))).toBe "file.coffee" + 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" describe ".setPath(path)", -> describe "when path is a file", -> it "sets its path to the files parent directory and updates the root directory", -> - project.setPath(fs.resolveOnLoadPath('fixtures/dir/a')) - expect(project.getPath()).toEqual fs.resolveOnLoadPath('fixtures/dir') - expect(project.getRootDirectory().path).toEqual fs.resolveOnLoadPath('fixtures/dir') + project.setPath(fsUtils.resolveOnLoadPath('fixtures/dir/a')) + expect(project.getPath()).toEqual fsUtils.resolveOnLoadPath('fixtures/dir') + expect(project.getRootDirectory().path).toEqual fsUtils.resolveOnLoadPath('fixtures/dir') describe "when path is a directory", -> it "sets its path to the directory and updates the root directory", -> - project.setPath(fs.resolveOnLoadPath('fixtures/dir/a-dir')) - expect(project.getPath()).toEqual fs.resolveOnLoadPath('fixtures/dir/a-dir') - expect(project.getRootDirectory().path).toEqual fs.resolveOnLoadPath('fixtures/dir/a-dir') + project.setPath(fsUtils.resolveOnLoadPath('fixtures/dir/a-dir')) + expect(project.getPath()).toEqual fsUtils.resolveOnLoadPath('fixtures/dir/a-dir') + expect(project.getRootDirectory().path).toEqual fsUtils.resolveOnLoadPath('fixtures/dir/a-dir') describe "when path is null", -> it "sets its path and root directory to null", -> @@ -127,7 +127,7 @@ describe "Project", -> expect(paths.length).toBeGreaterThan 0 it "ignores files that return true from atom.ignorePath(path)", -> - spyOn(project, 'isPathIgnored').andCallFake (path) -> fs.base(path).match /a$/ + spyOn(project, 'isPathIgnored').andCallFake (path) -> fsUtils.base(path).match /a$/ paths = null waitsForPromise -> @@ -140,7 +140,7 @@ describe "Project", -> describe "when config.core.hideGitIgnoredFiles is true", -> it "ignores files that are present in .gitignore if the project is a git repo", -> config.set "core.hideGitIgnoredFiles", true - project.setPath(fs.resolveOnLoadPath('fixtures/git/working-dir')) + project.setPath(fsUtils.resolveOnLoadPath('fixtures/git/working-dir')) paths = null waitsForPromise -> project.getFilePaths().done (foundPaths) -> paths = foundPaths @@ -152,11 +152,11 @@ describe "Project", -> ignoredFile = null beforeEach -> - ignoredFile = fs.join(fs.resolveOnLoadPath('fixtures/dir'), 'ignored.txt') - fs.write(ignoredFile, "") + ignoredFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored.txt') + fsUtils.write(ignoredFile, "") afterEach -> - fs.remove(ignoredFile) + fsUtils.remove(ignoredFile) it "ignores ignored.txt file", -> paths = null @@ -172,11 +172,11 @@ describe "Project", -> ignoredFile = null beforeEach -> - ignoredFile = fs.join(fs.resolveOnLoadPath('fixtures/dir'), 'ignored/ignored.txt') - fs.write(ignoredFile, "") + ignoredFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/dir'), 'ignored/ignored.txt') + fsUtils.write(ignoredFile, "") afterEach -> - fs.remove(ignoredFile) + fsUtils.remove(ignoredFile) it "ignores ignored folder", -> paths = null @@ -222,7 +222,7 @@ describe "Project", -> range: [[2, 6], [2, 11]] it "works on evil filenames", -> - project.setPath(fs.resolveOnLoadPath('fixtures/evil-files')) + project.setPath(fsUtils.resolveOnLoadPath('fixtures/evil-files')) paths = [] matches = [] waitsForPromise -> @@ -237,7 +237,7 @@ describe "Project", -> expect(paths[1]).toMatch /file with spaces.txt$/ expect(paths[2]).toMatch /goddam\nnewlines$/m expect(paths[3]).toMatch /quote".txt$/m - expect(fs.base(paths[4])).toBe "utfa\u0306.md" + expect(fsUtils.base(paths[4])).toBe "utfa\u0306.md" it "handles breaks in the search subprocess's output following the filename", -> spyOn(BufferedProcess.prototype, 'bufferStream') @@ -246,7 +246,7 @@ describe "Project", -> project.scan /a+/, iterator stdout = BufferedProcess.prototype.bufferStream.argsForCall[0][1] - stdout ":#{fs.resolveOnLoadPath('fixtures/dir/a')}\n" + stdout ":#{fsUtils.resolveOnLoadPath('fixtures/dir/a')}\n" stdout "1;0 3:aaa bbb\n2;3 2:cc aa cc\n" expect(iterator.argsForCall[0][0]).toEqual diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 4935dbd1b..8c28d4297 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -1,5 +1,5 @@ $ = require 'jquery' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Project = require 'project' RootView = require 'root-view' Buffer = require 'text-buffer' @@ -83,7 +83,7 @@ describe "RootView", -> expect(editor3.isFocused).toBeFalsy() expect(editor4.isFocused).toBeFalsy() - expect(rootView.title).toBe "#{fs.base(editor2.getPath())} - #{project.getPath()}" + expect(rootView.title).toBe "#{fsUtils.base(editor2.getPath())} - #{project.getPath()}" describe "where there are no open editors", -> it "constructs the view with no open editors", -> @@ -223,7 +223,7 @@ describe "RootView", -> it "creates an edit session for the given path as an item on a new pane, and focuses the pane", -> editSession = rootView.open('b') expect(rootView.getActivePane().activeItem).toBe editSession - expect(editSession.getPath()).toBe fs.resolveOnLoadPath('fixtures/dir/b') + expect(editSession.getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/dir/b') expect(rootView.getActivePane().focus).toHaveBeenCalled() describe "when the changeFocus option is false", -> diff --git a/spec/app/syntax-spec.coffee b/spec/app/syntax-spec.coffee index ad12bee71..6a07cd289 100644 --- a/spec/app/syntax-spec.coffee +++ b/spec/app/syntax-spec.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "the `syntax` global", -> beforeEach -> @@ -44,10 +44,10 @@ describe "the `syntax` global", -> it "doesn't read the file when the file contents are specified", -> filePath = require.resolve("fixtures/shebang") - filePathContents = fs.read(filePath) - spyOn(fs, 'read').andCallThrough() + filePathContents = fsUtils.read(filePath) + spyOn(fsUtils, 'read').andCallThrough() expect(syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby" - expect(fs.read).not.toHaveBeenCalled() + expect(fsUtils.read).not.toHaveBeenCalled() it "allows the default grammar to be overridden for a path", -> path = '/foo/bar/file.js' diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index dbf75502d..8181e2ab6 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -1,6 +1,6 @@ Project = require 'project' Buffer = require 'text-buffer' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' describe 'Buffer', -> @@ -8,7 +8,7 @@ describe 'Buffer', -> beforeEach -> filePath = require.resolve('fixtures/sample.js') - fileContents = fs.read(filePath) + fileContents = fsUtils.read(filePath) buffer = project.bufferForPath(filePath) afterEach -> @@ -24,7 +24,7 @@ describe 'Buffer', -> it "loads the contents of that file", -> filePath = require.resolve 'fixtures/sample.txt' buffer = project.bufferForPath(filePath) - expect(buffer.getText()).toBe fs.read(filePath) + expect(buffer.getText()).toBe fsUtils.read(filePath) it "is not modified and has no undo history", -> buffer = project.bufferForPath(filePath) @@ -34,7 +34,7 @@ describe 'Buffer', -> describe "when no file exists for the path", -> it "throws an exception", -> filePath = "does-not-exist.txt" - expect(fs.exists(filePath)).toBeFalsy() + expect(fsUtils.exists(filePath)).toBeFalsy() expect(-> project.bufferForPath(filePath)).toThrow() describe "when no path is given", -> @@ -46,25 +46,25 @@ describe 'Buffer', -> [path, newPath, bufferToChange, eventHandler] = [] beforeEach -> - path = fs.join(fs.resolveOnLoadPath("fixtures"), "atom-manipulate-me") + path = fsUtils.join(fsUtils.resolveOnLoadPath("fixtures"), "atom-manipulate-me") newPath = "#{path}-i-moved" - fs.write(path, "") + fsUtils.write(path, "") bufferToChange = project.bufferForPath(path) eventHandler = jasmine.createSpy('eventHandler') bufferToChange.on 'path-changed', eventHandler afterEach -> bufferToChange.destroy() - fs.remove(path) if fs.exists(path) - fs.remove(newPath) if fs.exists(newPath) + fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(newPath) if fsUtils.exists(newPath) it "triggers a `path-changed` event when path is changed", -> bufferToChange.saveAs(newPath) expect(eventHandler).toHaveBeenCalledWith(bufferToChange) it "triggers a `path-changed` event when the file is moved", -> - fs.remove(newPath) if fs.exists(newPath) - fs.move(path, newPath) + fsUtils.remove(newPath) if fsUtils.exists(newPath) + fsUtils.move(path, newPath) waitsFor "buffer path change", -> eventHandler.callCount > 0 @@ -76,14 +76,14 @@ describe 'Buffer', -> path = null beforeEach -> path = "/tmp/tmp.txt" - fs.write(path, "first") + fsUtils.write(path, "first") buffer.release() buffer = project.bufferForPath(path).retain() afterEach -> buffer.release() buffer = null - fs.remove(path) if fs.exists(path) + fsUtils.remove(path) if fsUtils.exists(path) it "does not trigger a change event when Atom modifies the file", -> buffer.insert([0,0], "HELLO!") @@ -99,7 +99,7 @@ describe 'Buffer', -> 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 - fs.write(path, "second") + fsUtils.write(path, "second") expect(changeHandler.callCount).toBe 0 waitsFor "file to trigger change event", -> @@ -119,7 +119,7 @@ describe 'Buffer', -> buffer.file.on 'contents-changed', fileChangeHandler buffer.insert([0, 0], "a change") - fs.write(path, "second") + fsUtils.write(path, "second") expect(fileChangeHandler.callCount).toBe 0 waitsFor "file to trigger 'contents-changed' event", -> @@ -134,7 +134,7 @@ describe 'Buffer', -> buffer.insert([0, 0], "a second change") handler = jasmine.createSpy('fileChange') - fs.write(path, "second") + fsUtils.write(path, "second") buffer.on 'contents-conflicted', handler expect(handler.callCount).toBe 0 @@ -149,7 +149,7 @@ describe 'Buffer', -> beforeEach -> path = "/tmp/atom-file-to-delete.txt" - fs.write(path, 'delete me') + fsUtils.write(path, 'delete me') bufferToDelete = project.bufferForPath(path) path = bufferToDelete.getPath() # symlinks may have been converted @@ -158,7 +158,7 @@ describe 'Buffer', -> removeHandler = jasmine.createSpy('removeHandler') bufferToDelete.file.on 'removed', removeHandler - fs.remove(path) + fsUtils.remove(path) waitsFor "file to be removed", -> removeHandler.callCount > 0 @@ -174,7 +174,7 @@ describe 'Buffer', -> expect(bufferToDelete.fileExists()).toBeTruthy() expect(bufferToDelete.isInConflict()).toBeFalsy() - fs.write(path, 'moo') + fsUtils.write(path, 'moo') changeHandler = jasmine.createSpy('changeHandler') bufferToDelete.on 'changed', changeHandler @@ -207,19 +207,19 @@ describe 'Buffer', -> it "reports the modified status changing to true after the underlying file is deleted", -> buffer.release() filePath = "/tmp/atom-tmp-file" - fs.write(filePath, 'delete me') + fsUtils.write(filePath, 'delete me') buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") buffer.on 'modified-status-changed', modifiedHandler - fs.remove(filePath) + fsUtils.remove(filePath) waitsFor "modified status to change", -> modifiedHandler.callCount runs -> expect(buffer.isModified()).toBe true it "reports the modified status changing to false after a modified buffer is saved", -> filePath = "/tmp/atom-tmp-file" - fs.write(filePath, '') + fsUtils.write(filePath, '') buffer.release() buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") @@ -243,7 +243,7 @@ describe 'Buffer', -> it "reports the modified status changing to false after a modified buffer is reloaded", -> filePath = "/tmp/atom-tmp-file" - fs.write(filePath, '') + fsUtils.write(filePath, '') buffer.release() buffer = project.bufferForPath(filePath) modifiedHandler = jasmine.createSpy("modifiedHandler") @@ -420,16 +420,16 @@ describe 'Buffer', -> beforeEach -> filePath = '/tmp/temp.txt' - fs.write(filePath, "") + fsUtils.write(filePath, "") saveBuffer = project.bufferForPath(filePath) saveBuffer.setText("blah") it "saves the contents of the buffer to the path", -> saveBuffer.setText 'Buffer contents!' saveBuffer.save() - expect(fs.read(filePath)).toEqual 'Buffer contents!' + expect(fsUtils.read(filePath)).toEqual 'Buffer contents!' - it "fires will-be-saved and saved events around the call to fs.write", -> + it "fires will-be-saved and saved events around the call to fsUtils.write", -> events = [] beforeSave1 = -> events.push('beforeSave1') beforeSave2 = -> events.push('beforeSave2') @@ -438,12 +438,12 @@ describe 'Buffer', -> saveBuffer.on 'will-be-saved', beforeSave1 saveBuffer.on 'will-be-saved', beforeSave2 - spyOn(fs, 'write').andCallFake -> events.push 'fs.write' + spyOn(fsUtils, 'write').andCallFake -> events.push 'fsUtils.write' saveBuffer.on 'saved', afterSave1 saveBuffer.on 'saved', afterSave2 saveBuffer.save() - expect(events).toEqual ['beforeSave1', 'beforeSave2', 'fs.write', 'afterSave1', 'afterSave2'] + expect(events).toEqual ['beforeSave1', 'beforeSave2', 'fsUtils.write', 'afterSave1', 'afterSave2'] it "fires will-reload and reloaded events when reloaded", -> events = [] @@ -477,7 +477,7 @@ describe 'Buffer', -> it "saves the contents of the buffer to the path", -> filePath = '/tmp/temp.txt' - fs.remove filePath if fs.exists(filePath) + fsUtils.remove filePath if fsUtils.exists(filePath) saveAsBuffer = project.bufferForPath(null).retain() eventHandler = jasmine.createSpy('eventHandler') @@ -485,14 +485,14 @@ describe 'Buffer', -> saveAsBuffer.setText 'Buffer contents!' saveAsBuffer.saveAs(filePath) - expect(fs.read(filePath)).toEqual 'Buffer contents!' + expect(fsUtils.read(filePath)).toEqual 'Buffer contents!' expect(eventHandler).toHaveBeenCalledWith(saveAsBuffer) it "stops listening to events on previous path and begins listening to events on new path", -> originalPath = "/tmp/original.txt" newPath = "/tmp/new.txt" - fs.write(originalPath, "") + fsUtils.write(originalPath, "") saveAsBuffer = project.bufferForPath(originalPath).retain() changeHandler = jasmine.createSpy('changeHandler') @@ -500,11 +500,11 @@ describe 'Buffer', -> saveAsBuffer.saveAs(newPath) expect(changeHandler).not.toHaveBeenCalled() - fs.write(originalPath, "should not trigger buffer event") + fsUtils.write(originalPath, "should not trigger buffer event") waits 20 runs -> expect(changeHandler).not.toHaveBeenCalled() - fs.write(newPath, "should trigger buffer event") + fsUtils.write(newPath, "should trigger buffer event") waitsFor -> changeHandler.callCount > 0 diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee index c23bfd6b8..27c88fef2 100644 --- a/spec/app/text-mate-grammar-spec.coffee +++ b/spec/app/text-mate-grammar-spec.coffee @@ -1,7 +1,7 @@ TextMateGrammar = require 'text-mate-grammar' TextMatePackage = require 'text-mate-package' plist = require 'plist' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' describe "TextMateGrammar", -> @@ -16,13 +16,13 @@ describe "TextMateGrammar", -> describe "@loadSync(path)", -> it "loads grammars from plists", -> - grammar = TextMateGrammar.loadSync(fs.resolveOnLoadPath('packages/text.tmbundle/Syntaxes/Plain text.plist')) + grammar = TextMateGrammar.loadSync(fsUtils.resolveOnLoadPath('packages/text.tmbundle/Syntaxes/Plain text.plist')) expect(grammar.scopeName).toBe "text.plain" {tokens} = grammar.tokenizeLine("this text is so plain. i love it.") expect(tokens[0]).toEqual value: "this text is so plain. i love it.", scopes: ["text.plain", "meta.paragraph.text"] it "loads grammars from cson files", -> - grammar = TextMateGrammar.loadSync(fs.resolveOnLoadPath('package-with-grammars/grammars/alot.cson')) + grammar = TextMateGrammar.loadSync(fsUtils.resolveOnLoadPath('package-with-grammars/grammars/alot.cson')) expect(grammar.scopeName).toBe "source.alot" {tokens} = grammar.tokenizeLine("this is alot of code") expect(tokens[1]).toEqual value: "alot", scopes: ["source.alot", "keyword.alot"] diff --git a/spec/app/text-mate-theme-spec.coffee b/spec/app/text-mate-theme-spec.coffee index 16588606c..0292c714b 100644 --- a/spec/app/text-mate-theme-spec.coffee +++ b/spec/app/text-mate-theme-spec.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' plist = require 'plist' TextMateTheme = require 'text-mate-theme' Theme = require 'theme' @@ -7,7 +7,7 @@ describe "TextMateTheme", -> [theme, themePath] = [] beforeEach -> - themePath = fs.resolveOnLoadPath(fs.join('fixtures', 'test.tmTheme')) + themePath = fsUtils.resolveOnLoadPath(fsUtils.join('fixtures', 'test.tmTheme')) theme = Theme.load(themePath) afterEach -> diff --git a/spec/app/theme-spec.coffee b/spec/app/theme-spec.coffee index 86d703b9d..b447a8cf1 100644 --- a/spec/app/theme-spec.coffee +++ b/spec/app/theme-spec.coffee @@ -1,5 +1,5 @@ $ = require 'jquery' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Theme = require 'theme' describe "@load(name)", -> @@ -15,7 +15,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 = fs.resolveOnLoadPath(fs.join('fixtures', 'test.tmTheme')) + themePath = fsUtils.resolveOnLoadPath(fsUtils.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 52c095904..c27a7a31e 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -1,5 +1,5 @@ $ = require 'jquery' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' {less} = require 'less' describe "Window", -> @@ -70,7 +70,7 @@ describe "Window", -> element = $('head style[id*="css.css"]') expect(element.attr('id')).toBe cssPath - expect(element.text()).toBe fs.read(cssPath) + expect(element.text()).toBe fsUtils.read(cssPath) # doesn't append twice requireStylesheet(cssPath) @@ -112,7 +112,7 @@ describe "Window", -> describe ".removeStylesheet(path)", -> it "removes styling applied by given stylesheet path", -> - cssPath = require.resolve(fs.join("fixtures", "css.css")) + cssPath = require.resolve(fsUtils.join("fixtures", "css.css")) expect($(document.body).css('font-weight')).not.toBe("bold") requireStylesheet(cssPath) @@ -159,14 +159,14 @@ describe "Window", -> commandPath = '/tmp/installed-atom-command/atom' afterEach -> - fs.remove(commandPath) if fs.exists(commandPath) + fsUtils.remove(commandPath) if fsUtils.exists(commandPath) describe "when the command path doesn't exist", -> it "copies atom.sh to the specified path", -> - expect(fs.exists(commandPath)).toBeFalsy() + expect(fsUtils.exists(commandPath)).toBeFalsy() window.installAtomCommand(commandPath) - expect(fs.exists(commandPath)).toBeTruthy() - expect(fs.read(commandPath).length).toBeGreaterThan 1 + expect(fsUtils.exists(commandPath)).toBeTruthy() + expect(fsUtils.read(commandPath).length).toBeGreaterThan 1 describe ".deserialize(state)", -> class Foo diff --git a/spec/jasmine-helper.coffee b/spec/jasmine-helper.coffee index fb6175ae0..86a8bb625 100644 --- a/spec/jasmine-helper.coffee +++ b/spec/jasmine-helper.coffee @@ -1,8 +1,8 @@ window.nakedLoad = (file) -> - fs = require 'fs-utils' + fsUtils = require 'fs-utils' file = require.resolve(file) - code = fs.read(file) - if fs.extension(file) is '.coffee' + code = fsUtils.read(file) + if fsUtils.extension(file) is '.coffee' require('coffee-script').eval(code, filename: file) else window.eval("#{code}\n//@ sourceURL=#{file}") diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 0475902a7..d4dcac2cb 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -12,11 +12,11 @@ Directory = require 'directory' File = require 'file' Editor = require 'editor' TokenizedBuffer = require 'tokenized-buffer' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' RootView = require 'root-view' Git = require 'git' requireStylesheet "jasmine" -fixturePackagesPath = fs.resolveOnLoadPath('fixtures/packages') +fixturePackagesPath = fsUtils.resolveOnLoadPath('fixtures/packages') config.packageDirPaths.unshift(fixturePackagesPath) keymap.loadBundledKeymaps() [bindingSetsToRestore, bindingSetsByFirstKeystrokeToRestore] = [] @@ -30,7 +30,7 @@ jasmine.getEnv().defaultTimeoutInterval = 5000 beforeEach -> jQuery.fx.off = true - window.project = new Project(fs.resolveOnLoadPath('fixtures')) + window.project = new Project(fsUtils.resolveOnLoadPath('fixtures')) window.git = Git.open(project.getPath()) window.project.on 'path-changed', -> window.git?.destroy() @@ -126,7 +126,7 @@ addCustomMatchers = (spec) -> toExistOnDisk: (expected) -> notText = this.isNot and " not" or "" @message = -> return "Expected path '" + @actual + "'" + notText + " to exist." - fs.exists(@actual) + fsUtils.exists(@actual) window.keyIdentifierForKey = (key) -> if key.length > 1 # named key @@ -241,5 +241,5 @@ $.fn.textInput = (data) -> event = jQuery.event.fix(event) $(this).trigger(event) -unless fs.md5ForPath(require.resolve('fixtures/sample.js')) == "dd38087d0d7e3e4802a6d3f9b9745f2b" +unless fsUtils.md5ForPath(require.resolve('fixtures/sample.js')) == "dd38087d0d7e3e4802a6d3f9b9745f2b" throw new Error("Sample.js is modified") diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index 0c7ebc37e..7fc7cdadd 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -1,15 +1,15 @@ require 'window' measure 'spec suite require time', -> - fs = require 'fs-utils' + fsUtils = require 'fs-utils' require 'spec-helper' # Run core specs - for path in fs.listTree(fs.resolveOnLoadPath("spec")) when /-spec\.coffee$/.test path + for path in fsUtils.listTree(fsUtils.resolveOnLoadPath("spec")) when /-spec\.coffee$/.test path require path # Run extension specs for packageDirPath in config.packageDirPaths - for packagePath in fs.list(packageDirPath) - for path in fs.listTree(fs.join(packagePath, "spec")) when /-spec\.coffee$/.test path + for packagePath in fsUtils.list(packageDirPath) + for path in fsUtils.listTree(fsUtils.join(packagePath, "spec")) when /-spec\.coffee$/.test path require path diff --git a/spec/stdlib/fs-utils-spec.coffee b/spec/stdlib/fs-utils-spec.coffee index 5317be474..8d2204a8b 100644 --- a/spec/stdlib/fs-utils-spec.coffee +++ b/spec/stdlib/fs-utils-spec.coffee @@ -1,95 +1,95 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' -describe "fs", -> +describe "fsUtils", -> describe ".read(path)", -> it "return contents of file", -> - expect(fs.read(require.resolve("fixtures/sample.txt"))).toBe "Some text.\n" + expect(fsUtils.read(require.resolve("fixtures/sample.txt"))).toBe "Some text.\n" it "does not through an exception when the path is a binary file", -> - expect(-> fs.read(require.resolve("fixtures/binary-file.png"))).not.toThrow() + expect(-> fsUtils.read(require.resolve("fixtures/binary-file.png"))).not.toThrow() describe ".isFile(path)", -> - fixturesDir = fs.resolveOnLoadPath('fixtures') + fixturesDir = fsUtils.resolveOnLoadPath('fixtures') it "returns true with a file path", -> - expect(fs.isFile(fs.join(fixturesDir, 'sample.js'))).toBe true + expect(fsUtils.isFile(fsUtils.join(fixturesDir, 'sample.js'))).toBe true it "returns false with a directory path", -> - expect(fs.isFile(fixturesDir)).toBe false + expect(fsUtils.isFile(fixturesDir)).toBe false it "returns false with a non-existent path", -> - expect(fs.isFile(fs.join(fixturesDir, 'non-existent'))).toBe false - expect(fs.isFile(null)).toBe false + expect(fsUtils.isFile(fsUtils.join(fixturesDir, 'non-existent'))).toBe false + expect(fsUtils.isFile(null)).toBe false describe ".directory(path)", -> describe "when called with a file path", -> it "returns the path to the directory", -> - expect(fs.directory(fs.resolveOnLoadPath('fixtures/dir/a'))).toBe fs.resolveOnLoadPath('fixtures/dir') + expect(fsUtils.directory(fsUtils.resolveOnLoadPath('fixtures/dir/a'))).toBe fsUtils.resolveOnLoadPath('fixtures/dir') describe "when called with a directory path", -> it "return the path it was given", -> - expect(fs.directory("/a/b/c")).toBe "/a/b" - expect(fs.directory("/a")).toBe "" - expect(fs.directory("a")).toBe "" - expect(fs.directory("/a/b/c++")).toBe "/a/b" + expect(fsUtils.directory("/a/b/c")).toBe "/a/b" + expect(fsUtils.directory("/a")).toBe "" + expect(fsUtils.directory("a")).toBe "" + expect(fsUtils.directory("/a/b/c++")).toBe "/a/b" describe ".base(path, ext)", -> describe "when called with an extension", -> it "return the base name without the extension when the path has the given extension", -> - expect(fs.base("/a/b/c.txt", '.txt')).toBe "c" - expect(fs.base("/a/b/c.txt", '.txt2')).toBe "c.txt" - expect(fs.base("/a/b/c.+", '.+')).toBe "c" + expect(fsUtils.base("/a/b/c.txt", '.txt')).toBe "c" + expect(fsUtils.base("/a/b/c.txt", '.txt2')).toBe "c.txt" + expect(fsUtils.base("/a/b/c.+", '.+')).toBe "c" describe ".exists(path)", -> it "returns true when path exsits", -> - expect(fs.exists(fs.resolveOnLoadPath('fixtures'))).toBe true + expect(fsUtils.exists(fsUtils.resolveOnLoadPath('fixtures'))).toBe true it "returns false when path doesn't exsit", -> - expect(fs.exists(fs.resolveOnLoadPath("fixtures") + "/-nope-does-not-exist")).toBe false - expect(fs.exists("")).toBe false - expect(fs.exists(null)).toBe false + expect(fsUtils.exists(fsUtils.resolveOnLoadPath("fixtures") + "/-nope-does-not-exist")).toBe false + expect(fsUtils.exists("")).toBe false + expect(fsUtils.exists(null)).toBe false describe ".join(paths...)", -> it "concatenates the given paths with the directory separator", -> - expect(fs.join('a')).toBe 'a' - expect(fs.join('a', 'b', 'c')).toBe 'a/b/c' - expect(fs.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d' - expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/' + 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(fs.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"] - expect(fs.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"] + expect(fsUtils.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"] + expect(fsUtils.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"] describe ".extension(path)", -> it "returns the extension of a file", -> - expect(fs.extension("a/b/corey.txt")).toBe '.txt' - expect(fs.extension("a/b/corey.txt.coffee")).toBe '.coffee' + expect(fsUtils.extension("a/b/corey.txt")).toBe '.txt' + expect(fsUtils.extension("a/b/corey.txt.coffee")).toBe '.coffee' it "returns an empty string for paths without an extension", -> - expect(fs.extension("a/b.not-extension/a-dir")).toBe '' + expect(fsUtils.extension("a/b.not-extension/a-dir")).toBe '' describe ".makeTree(path)", -> beforeEach -> - fs.remove("/tmp/a") if fs.exists("/tmp/a") + fsUtils.remove("/tmp/a") if fsUtils.exists("/tmp/a") it "creates all directories in path including any missing parent directories", -> - fs.makeTree("/tmp/a/b/c") - expect(fs.exists("/tmp/a/b/c")).toBeTruthy() + fsUtils.makeTree("/tmp/a/b/c") + expect(fsUtils.exists("/tmp/a/b/c")).toBeTruthy() describe ".traverseTreeSync(path, onFile, onDirectory)", -> fixturesDir = null beforeEach -> - fixturesDir = fs.resolveOnLoadPath('fixtures') + fixturesDir = fsUtils.resolveOnLoadPath('fixtures') it "calls fn for every path in the tree at the given path", -> paths = [] onPath = (path) -> paths.push(path) true - fs.traverseTreeSync fixturesDir, onPath, onPath - expect(paths).toEqual fs.listTree(fixturesDir) + fsUtils.traverseTreeSync fixturesDir, onPath, onPath + expect(paths).toEqual fsUtils.listTree(fixturesDir) it "does not recurse into a directory if it is pruned", -> paths = [] @@ -99,43 +99,43 @@ describe "fs", -> else paths.push(path) true - fs.traverseTreeSync fixturesDir, onPath, onPath + fsUtils.traverseTreeSync fixturesDir, onPath, onPath expect(paths.length).toBeGreaterThan 0 for path in paths expect(path).not.toMatch /\/dir\// it "returns entries if path is a symlink", -> - symlinkPath = fs.join(fixturesDir, 'symlink-to-dir') + symlinkPath = fsUtils.join(fixturesDir, 'symlink-to-dir') symlinkPaths = [] onSymlinkPath = (path) -> symlinkPaths.push(path.substring(symlinkPath.length + 1)) - regularPath = fs.join(fixturesDir, 'dir') + regularPath = fsUtils.join(fixturesDir, 'dir') paths = [] onPath = (path) -> paths.push(path.substring(regularPath.length + 1)) - fs.traverseTreeSync(symlinkPath, onSymlinkPath, onSymlinkPath) - fs.traverseTreeSync(regularPath, onPath, onPath) + fsUtils.traverseTreeSync(symlinkPath, onSymlinkPath, onSymlinkPath) + fsUtils.traverseTreeSync(regularPath, onPath, onPath) expect(symlinkPaths).toEqual(paths) describe ".md5ForPath(path)", -> it "returns the MD5 hash of the file at the given path", -> - expect(fs.md5ForPath(require.resolve('fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b' + expect(fsUtils.md5ForPath(require.resolve('fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b' describe ".list(path, extensions)", -> it "returns the absolute paths of entries within the given directory", -> - paths = fs.list(project.getPath()) + paths = fsUtils.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 an empty array for paths that aren't directories or don't exist", -> - expect(fs.list(project.resolve('sample.js'))).toEqual [] - expect(fs.list('/non/existent/directory')).toEqual [] + expect(fsUtils.list(project.resolve('sample.js'))).toEqual [] + expect(fsUtils.list('/non/existent/directory')).toEqual [] it "can filter the paths by an optional array of file extensions", -> - paths = fs.list(project.getPath(), ['.css', 'coffee']) + paths = fsUtils.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 @@ -145,7 +145,7 @@ describe "fs", -> it "calls the callback with the absolute paths of entries within the given directory", -> waitsFor (done) -> - fs.listAsync project.getPath(), (err, result) -> + fsUtils.listAsync project.getPath(), (err, result) -> paths = result done() runs -> @@ -155,7 +155,7 @@ describe "fs", -> it "can filter the paths by an optional array of file extensions", -> waitsFor (done) -> - fs.listAsync project.getPath(), ['css', '.coffee'], (err, result) -> + fsUtils.listAsync project.getPath(), ['css', '.coffee'], (err, result) -> paths = result done() runs -> diff --git a/src/app/atom-theme.coffee b/src/app/atom-theme.coffee index 3fab3f9e7..c679298a1 100644 --- a/src/app/atom-theme.coffee +++ b/src/app/atom-theme.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Theme = require 'theme' CSON = require 'cson' @@ -9,17 +9,17 @@ class AtomTheme extends Theme @stylesheets[stylesheetPath] = window.loadStylesheet(stylesheetPath) load: -> - if fs.extension(@path) in ['.css', '.less'] + if fsUtils.extension(@path) in ['.css', '.less'] @loadStylesheet(@path) else - metadataPath = fs.resolveExtension(fs.join(@path, 'package'), ['cson', 'json']) - if fs.isFile(metadataPath) + metadataPath = fsUtils.resolveExtension(fsUtils.join(@path, 'package'), ['cson', 'json']) + if fsUtils.isFile(metadataPath) stylesheetNames = CSON.readObject(metadataPath)?.stylesheets if stylesheetNames for name in stylesheetNames - filename = fs.resolveExtension(fs.join(@path, name), ['.css', '.less', '']) + filename = fsUtils.resolveExtension(fsUtils.join(@path, name), ['.css', '.less', '']) @loadStylesheet(filename) else - @loadStylesheet(stylesheetPath) for stylesheetPath in fs.list(@path, ['.css', '.less']) + @loadStylesheet(stylesheetPath) for stylesheetPath in fsUtils.list(@path, ['.css', '.less']) super diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 05eeea60d..cb8180113 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' Package = require 'package' TextMatePackage = require 'text-mate-package' @@ -74,9 +74,9 @@ _.extend atom, throw new Error("Could not resolve '#{id}' to a package path") resolvePackagePath: _.memoize (id) -> - return id if fs.isDirectory(id) - path = fs.resolve(config.packageDirPaths..., id) - path if fs.isDirectory(path) + return id if fsUtils.isDirectory(id) + path = fsUtils.resolve(config.packageDirPaths..., id) + path if fsUtils.isDirectory(path) getLoadedPackage: (id) -> if path = @resolvePackagePath(id) @@ -90,13 +90,13 @@ _.extend atom, isPackageDisabled: (id) -> if path = @resolvePackagePath(id) - _.include(config.get('core.disabledPackages') ? [], fs.base(path)) + _.include(config.get('core.disabledPackages') ? [], fsUtils.base(path)) getPackagePaths: -> packagePaths = [] for packageDirPath in config.packageDirPaths - for packagePath in fs.list(packageDirPath) - packagePaths.push(packagePath) if fs.isDirectory(packagePath) + for packagePath in fsUtils.list(packageDirPath) + packagePaths.push(packagePath) if fsUtils.isDirectory(packagePath) _.uniq(packagePaths) loadThemes: -> @@ -109,8 +109,8 @@ _.extend atom, @loadedThemes.push Theme.load(name) loadUserStylesheet: -> - userStylesheetPath = fs.resolve(fs.join(config.configDirPath, 'user'), ['css', 'less']) - if fs.isFile(userStylesheetPath) + userStylesheetPath = fsUtils.resolve(fsUtils.join(config.configDirPath, 'user'), ['css', 'less']) + if fsUtils.isFile(userStylesheetPath) userStyleesheetContents = loadStylesheet(userStylesheetPath) applyStylesheet(userStylesheetPath, userStyleesheetContents, 'userTheme') @@ -247,9 +247,9 @@ _.extend atom, @sendMessageToBrowserProcess('getUpdateStatus', [], callback) requireUserInitScript: -> - userInitScriptPath = fs.join(config.configDirPath, "user.coffee") + userInitScriptPath = fsUtils.join(config.configDirPath, "user.coffee") try - require userInitScriptPath if fs.isFile(userInitScriptPath) + require userInitScriptPath if fsUtils.isFile(userInitScriptPath) catch error console.error "Failed to load `#{userInitScriptPath}`", error.stack, error diff --git a/src/app/binding-set.coffee b/src/app/binding-set.coffee index 3bf87dab8..e9017d1f9 100644 --- a/src/app/binding-set.coffee +++ b/src/app/binding-set.coffee @@ -1,6 +1,6 @@ $ = require 'jquery' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Specificity = require 'specificity' PEG = require 'pegjs' @@ -17,7 +17,7 @@ class BindingSet name: null constructor: (@selector, commandsByKeystrokes, @index, @name) -> - BindingSet.parser ?= PEG.buildParser(fs.read(require.resolve 'keystroke-pattern.pegjs')) + BindingSet.parser ?= PEG.buildParser(fsUtils.read(require.resolve 'keystroke-pattern.pegjs')) @specificity = Specificity(@selector) @commandsByKeystrokes = @normalizeCommandsByKeystrokes(commandsByKeystrokes) diff --git a/src/app/config.coffee b/src/app/config.coffee index c8d36db6e..79cb4d35e 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -1,15 +1,15 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' EventEmitter = require 'event-emitter' CSON = require 'cson' -configDirPath = fs.absolute("~/.atom") -bundledPackagesDirPath = fs.join(resourcePath, "src/packages") -bundledThemesDirPath = fs.join(resourcePath, "themes") -vendoredPackagesDirPath = fs.join(resourcePath, "vendor/packages") -vendoredThemesDirPath = fs.join(resourcePath, "vendor/themes") -userThemesDirPath = fs.join(configDirPath, "themes") -userPackagesDirPath = fs.join(configDirPath, "packages") +configDirPath = fsUtils.absolute("~/.atom") +bundledPackagesDirPath = fsUtils.join(resourcePath, "src/packages") +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") module.exports = class Config @@ -26,34 +26,34 @@ class Config core: _.clone(require('root-view').configDefaults) editor: _.clone(require('editor').configDefaults) @settings = {} - @configFilePath = fs.resolve(configDirPath, 'config', ['json', 'cson']) - @configFilePath ?= fs.join(configDirPath, 'config.cson') + @configFilePath = fsUtils.resolve(configDirPath, 'config', ['json', 'cson']) + @configFilePath ?= fsUtils.join(configDirPath, 'config.cson') initializeConfigDirectory: -> - return if fs.exists(@configDirPath) + return if fsUtils.exists(@configDirPath) - fs.makeDirectory(@configDirPath) + fsUtils.makeDirectory(@configDirPath) - templateConfigDirPath = fs.resolve(window.resourcePath, 'dot-atom') + templateConfigDirPath = fsUtils.resolve(window.resourcePath, 'dot-atom') onConfigDirFile = (path) => relativePath = path.substring(templateConfigDirPath.length + 1) - configPath = fs.join(@configDirPath, relativePath) - fs.write(configPath, fs.read(path)) - fs.traverseTreeSync(templateConfigDirPath, onConfigDirFile, (path) -> true) + configPath = fsUtils.join(@configDirPath, relativePath) + fsUtils.write(configPath, fsUtils.read(path)) + fsUtils.traverseTreeSync(templateConfigDirPath, onConfigDirFile, (path) -> true) - configThemeDirPath = fs.join(@configDirPath, 'themes') + configThemeDirPath = fsUtils.join(@configDirPath, 'themes') onThemeDirFile = (path) -> relativePath = path.substring(bundledThemesDirPath.length + 1) - configPath = fs.join(configThemeDirPath, relativePath) - fs.write(configPath, fs.read(path)) - fs.traverseTreeSync(bundledThemesDirPath, onThemeDirFile, (path) -> true) + configPath = fsUtils.join(configThemeDirPath, relativePath) + fsUtils.write(configPath, fsUtils.read(path)) + fsUtils.traverseTreeSync(bundledThemesDirPath, onThemeDirFile, (path) -> true) load: -> @initializeConfigDirectory() @loadUserConfig() loadUserConfig: -> - if fs.exists(@configFilePath) + if fsUtils.exists(@configFilePath) try userConfig = CSON.readObject(@configFilePath) _.extend(@settings, userConfig) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index b420f7875..3c3951533 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -8,7 +8,7 @@ EventEmitter = require 'event-emitter' Subscriber = require 'subscriber' Range = require 'range' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class EditSession @@ -45,7 +45,7 @@ class EditSession @buffer.retain() @subscribe @buffer, "path-changed", => - @project.setPath(fs.directory(@getPath())) unless @project.getPath()? + @project.setPath(fsUtils.directory(@getPath())) unless @project.getPath()? @trigger "title-changed" @trigger "path-changed" @subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted" @@ -64,14 +64,14 @@ class EditSession getTitle: -> if path = @getPath() - fs.base(path) + fsUtils.base(path) else 'untitled' getLongTitle: -> if path = @getPath() - fileName = fs.base(path) - directory = fs.base(fs.directory(path)) + fileName = fsUtils.base(path) + directory = fsUtils.base(fsUtils.directory(path)) "#{fileName} - #{directory}" else 'untitled' diff --git a/src/app/editor.coffee b/src/app/editor.coffee index a3bed0f00..c3c147d0e 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -6,7 +6,7 @@ Range = require 'range' EditSession = require 'edit-session' CursorView = require 'cursor-view' SelectionView = require 'selection-view' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' _ = require 'underscore' @@ -1098,7 +1098,7 @@ class Editor extends View range.detach() leftPixels - pixelOffsetForScreenPosition: (position) -> + pixelOffsUtilsetForScreenPosition: (position) -> {top, left} = @pixelPositionForScreenPosition(position) offset = @renderedLines.offset() {top: top + offset.top, left: left + offset.left} @@ -1181,7 +1181,7 @@ class Editor extends View saveDebugSnapshot: -> atom.showSaveDialog (path) => - fs.write(path, @getDebugSnapshot()) if path + fsUtils.write(path, @getDebugSnapshot()) if path getDebugSnapshot: -> [ diff --git a/src/app/git.coffee b/src/app/git.coffee index 21128dfbd..9bbe63117 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' Subscriber = require 'subscriber' EventEmitter = require 'event-emitter' RepositoryStatusTask = require 'repository-status-task' @@ -48,7 +48,7 @@ class Git refreshIndex: -> @getRepo().refreshIndex() getPath: -> - @path ?= fs.absolute(@getRepo().getPath()) + @path ?= fsUtils.absolute(@getRepo().getPath()) destroy: -> if @statusTask? diff --git a/src/app/keymap.coffee b/src/app/keymap.coffee index 23e585ee7..0cc615726 100644 --- a/src/app/keymap.coffee +++ b/src/app/keymap.coffee @@ -1,6 +1,6 @@ $ = require 'jquery' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' CSON = require 'cson' BindingSet = require 'binding-set' @@ -32,13 +32,13 @@ class Keymap $(document).command 'open-dev', => atom.openDev() loadBundledKeymaps: -> - @loadDirectory(fs.resolveOnLoadPath('keymaps')) + @loadDirectory(fsUtils.resolveOnLoadPath('keymaps')) loadUserKeymaps: -> - @loadDirectory(fs.join(config.configDirPath, 'keymaps')) + @loadDirectory(fsUtils.join(config.configDirPath, 'keymaps')) loadDirectory: (directoryPath) -> - @load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json']) + @load(filePath) for filePath in fsUtils.list(directoryPath, ['.cson', '.json']) load: (path) -> @add(path, CSON.readObject(path)) diff --git a/src/app/package.coffee b/src/app/package.coffee index c03e082d5..b3f3333e0 100644 --- a/src/app/package.coffee +++ b/src/app/package.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class Package @@ -20,4 +20,4 @@ class Package path: null constructor: (@path) -> - @name = fs.base(@path) + @name = fsUtils.base(@path) diff --git a/src/app/project.coffee b/src/app/project.coffee index 81bf19c76..68b36a4c6 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' $ = require 'jquery' Range = require 'range' @@ -41,7 +41,7 @@ class Project @rootDirectory?.off() if path? - directory = if fs.isDirectory(path) then path else fs.directory(path) + directory = if fsUtils.isDirectory(path) then path else fsUtils.directory(path) @rootDirectory = new Directory(directory) else @rootDirectory = null @@ -56,7 +56,7 @@ class Project paths = [] onFile = (path) => paths.push(path) unless @isPathIgnored(path) onDirectory = -> true - fs.traverseTreeSync(@getPath(), onFile, onDirectory) + fsUtils.traverseTreeSync(@getPath(), onFile, onDirectory) deferred.resolve(paths) deferred.promise() @@ -68,11 +68,11 @@ class Project @ignoreRepositoryPath(path) ignoreRepositoryPath: (path) -> - config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fs.join(@getPath(), path)) + config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fsUtils.join(@getPath(), path)) resolve: (filePath) -> - filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/' - fs.absolute filePath + filePath = fsUtils.join(@getPath(), filePath) unless filePath[0] == '/' + fsUtils.absolute filePath relativize: (fullPath) -> return fullPath unless fullPath.lastIndexOf(@getPath()) is 0 diff --git a/src/app/repository-status-handler.coffee b/src/app/repository-status-handler.coffee index 7816cf383..05f866a96 100644 --- a/src/app/repository-status-handler.coffee +++ b/src/app/repository-status-handler.coffee @@ -1,5 +1,5 @@ Git = require 'git-utils' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = loadStatuses: (path) -> @@ -8,7 +8,7 @@ module.exports = workingDirectoryPath = repo.getWorkingDirectory() statuses = {} for path, status of repo.getStatus() - statuses[fs.join(workingDirectoryPath, path)] = status + statuses[fsUtils.join(workingDirectoryPath, path)] = status upstream = repo.getAheadBehindCount() repo.release() else diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index fc1fdb4e1..0a7d3a2e9 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -1,6 +1,6 @@ $ = require 'jquery' {$$} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' _ = require 'underscore' {View} = require 'space-pen' @@ -174,4 +174,3 @@ class RootView extends View eachBuffer: (callback) -> project.eachBuffer(callback) - diff --git a/src/app/syntax.coffee b/src/app/syntax.coffee index 7ab711a14..75e954baf 100644 --- a/src/app/syntax.coffee +++ b/src/app/syntax.coffee @@ -2,7 +2,7 @@ _ = require 'underscore' jQuery = require 'jquery' Specificity = require 'specificity' {$$} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' EventEmitter = require 'event-emitter' NullGrammar = require 'null-grammar' nodePath = require 'path' @@ -71,7 +71,7 @@ class Syntax grammarByFirstLineRegex: (filePath, fileContents) -> try - fileContents ?= fs.read(filePath) + fileContents ?= fsUtils.read(filePath) catch e return diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 803e009bf..d403c44fd 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' File = require 'file' Point = require 'point' Range = require 'range' @@ -37,7 +37,7 @@ class Buffer @lineEndings = [] if path - throw "Path '#{path}' does not exist" unless fs.exists(path) + throw "Path '#{path}' does not exist" unless fsUtils.exists(path) @setPath(path) if initialText? @setText(initialText) diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index 03b35b6ca..774eac4f7 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' plist = require 'plist' Token = require 'token' CSON = require 'cson' @@ -8,17 +8,17 @@ CSON = require 'cson' module.exports = class TextMateGrammar @readFromPath: (path) -> - fs.readPlist(path) + fsUtils.readPlist(path) @load: (path, done) -> - fs.readObjectAsync path, (err, object) -> + fsUtils.readObjectAsync path, (err, object) -> if err done(err) else done(null, new TextMateGrammar(object)) @loadSync: (path) -> - new TextMateGrammar(fs.readObject(path)) + new TextMateGrammar(fsUtils.readObject(path)) name: null fileTypes: null diff --git a/src/app/text-mate-theme.coffee b/src/app/text-mate-theme.coffee index 2424bc2d3..3054b0633 100644 --- a/src/app/text-mate-theme.coffee +++ b/src/app/text-mate-theme.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' plist = require 'plist' Theme = require 'theme' diff --git a/src/app/theme.coffee b/src/app/theme.coffee index 6ca385d66..da038e391 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class Theme @@ -8,10 +8,10 @@ class Theme TextMateTheme = require 'text-mate-theme' AtomTheme = require 'atom-theme' - if fs.exists(name) + if fsUtils.exists(name) path = name else - path = fs.resolve(config.themeDirPaths..., name, ['', '.tmTheme', '.css', 'less']) + path = fsUtils.resolve(config.themeDirPaths..., name, ['', '.tmTheme', '.css', 'less']) throw new Error("No theme exists named '#{name}'") unless path diff --git a/src/app/window.coffee b/src/app/window.coffee index 78fc1bd42..f4950ed08 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' _ = require 'underscore' {less} = require 'less' @@ -32,14 +32,14 @@ window.setUpEnvironment = -> requireStylesheet 'notification' requireStylesheet 'markdown' - if nativeStylesheetPath = fs.resolveOnLoadPath(process.platform, ['css', 'less']) + if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less']) requireStylesheet(nativeStylesheetPath) # This method is only called when opening a real application window window.startup = -> - directory = _.find ['/opt/boxen', '/opt/github', '/usr/local'], (dir) -> fs.isDirectory(dir) + directory = _.find ['/opt/boxen', '/opt/github', '/usr/local'], (dir) -> fsUtils.isDirectory(dir) if directory - installAtomCommand(fs.join(directory, 'bin/atom')) + installAtomCommand(fsUtils.join(directory, 'bin/atom')) else console.warn "Failed to install `atom` binary" @@ -73,11 +73,11 @@ window.shutdown = -> window.git = null window.installAtomCommand = (commandPath) -> - return if fs.exists(commandPath) + return if fsUtils.exists(commandPath) - bundledCommandPath = fs.resolve(window.resourcePath, 'atom.sh') + bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh') if bundledCommandPath? - fs.write(commandPath, fs.read(bundledCommandPath)) + fsUtils.write(commandPath, fsUtils.read(bundledCommandPath)) spawn('chmod', ['u+x', commandPath]) window.handleWindowEvents = -> @@ -99,7 +99,7 @@ window.deserializeWindowState = -> window.project = deserialize(windowState.project) ? new Project(pathToOpen) window.rootView = deserialize(windowState.rootView) ? new RootView - if !windowState.rootView and (!pathToOpen or fs.isFile(pathToOpen)) + if !windowState.rootView and (!pathToOpen or fsUtils.isFile(pathToOpen)) rootView.open(pathToOpen) $(rootViewParentSelector).append(rootView) @@ -113,10 +113,10 @@ window.stylesheetElementForId = (id) -> $("head style[id='#{id}']") window.resolveStylesheet = (path) -> - if fs.extension(path).length > 0 - fs.resolveOnLoadPath(path) + if fsUtils.extension(path).length > 0 + fsUtils.resolveOnLoadPath(path) else - fs.resolveOnLoadPath(path, ['css', 'less']) + fsUtils.resolveOnLoadPath(path, ['css', 'less']) window.requireStylesheet = (path) -> if fullPath = window.resolveStylesheet(path) @@ -126,8 +126,8 @@ window.requireStylesheet = (path) -> throw new Error("Could not find a file at path '#{path}'") window.loadStylesheet = (path) -> - content = fs.read(path) - if fs.extension(path) == '.less' + content = fsUtils.read(path) + if fsUtils.extension(path) == '.less' (new less.Parser).parse content, (e, tree) -> throw new Error(e.message, path, e.line) if e content = tree.toCSS() diff --git a/src/packages/command-panel/lib/command-interpreter.coffee b/src/packages/command-panel/lib/command-interpreter.coffee index 07f53672e..8022fcb81 100644 --- a/src/packages/command-panel/lib/command-interpreter.coffee +++ b/src/packages/command-panel/lib/command-interpreter.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' PEG = require 'pegjs' module.exports = @@ -6,7 +6,7 @@ class CommandInterpreter constructor: (@project) -> eval: (string, activeEditSession) -> - @parser ?= PEG.buildParser(fs.read(require.resolve 'command-panel/lib/commands.pegjs')) + @parser ?= PEG.buildParser(fsUtils.read(require.resolve 'command-panel/lib/commands.pegjs')) compositeCommand = @parser.parse(string) @lastRelativeAddress = compositeCommand if compositeCommand.isRelativeAddress() compositeCommand.execute(@project, activeEditSession) diff --git a/src/packages/command-panel/lib/path-view.coffee b/src/packages/command-panel/lib/path-view.coffee index 9561d019b..814128c7e 100644 --- a/src/packages/command-panel/lib/path-view.coffee +++ b/src/packages/command-panel/lib/path-view.coffee @@ -1,5 +1,5 @@ {View} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' OperationView = require './operation-view' $ = require 'jquery' @@ -7,7 +7,7 @@ module.exports = class PathView extends View @content: ({path, previewList} = {}) -> classes = ['path'] - classes.push('readme') if fs.isReadmePath(path) + classes.push('readme') if fsUtils.isReadmePath(path) @li class: classes.join(' '), => @div outlet: 'pathDetails', class: 'path-details', => @span class: 'path-name', path diff --git a/src/packages/command-panel/lib/preview-list.coffee b/src/packages/command-panel/lib/preview-list.coffee index 7f70db89d..6be25229f 100644 --- a/src/packages/command-panel/lib/preview-list.coffee +++ b/src/packages/command-panel/lib/preview-list.coffee @@ -1,7 +1,7 @@ $ = require 'jquery' ScrollView = require 'scroll-view' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' PathView = require './path-view' OperationView = require './operation-view' diff --git a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee index 1c11229db..8bdfc5521 100644 --- a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee +++ b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee @@ -2,7 +2,7 @@ SelectList = require 'select-list' _ = require 'underscore' $ = require 'jquery' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' LoadPathsTask = require './load-paths-task' module.exports = @@ -45,22 +45,22 @@ class FuzzyFinderView extends SelectList else if git.isStatusModified(status) @div class: 'status modified' - ext = fs.extension(path) - if fs.isReadmePath(path) + ext = fsUtils.extension(path) + if fsUtils.isReadmePath(path) typeClass = 'readme-name' - else if fs.isCompressedExtension(ext) + else if fsUtils.isCompressedExtension(ext) typeClass = 'compressed-name' - else if fs.isImageExtension(ext) + else if fsUtils.isImageExtension(ext) typeClass = 'image-name' - else if fs.isPdfExtension(ext) + else if fsUtils.isPdfExtension(ext) typeClass = 'pdf-name' - else if fs.isBinaryExtension(ext) + else if fsUtils.isBinaryExtension(ext) typeClass = 'binary-name' else typeClass = 'text-name' - @span fs.base(path), class: "file label #{typeClass}" - if folder = project.relativize(fs.directory(path)) + @span fsUtils.base(path), class: "file label #{typeClass}" + if folder = project.relativize(fsUtils.directory(path)) @span " - #{folder}/", class: 'directory' openPath: (path) -> @@ -76,7 +76,7 @@ class FuzzyFinderView extends SelectList confirmed : (path) -> return unless path.length - if fs.isFile(path) + if fsUtils.isFile(path) @cancel() @openPath(path) else @@ -134,7 +134,7 @@ class FuzzyFinderView extends SelectList populateGitStatusPaths: -> paths = [] - paths.push(path) for path, status of git.statuses when fs.isFile(path) + paths.push(path) for path, status of git.statuses when fsUtils.isFile(path) @setArray(paths) diff --git a/src/packages/fuzzy-finder/lib/load-paths-task.coffee b/src/packages/fuzzy-finder/lib/load-paths-task.coffee index 12ef322f9..391b39255 100644 --- a/src/packages/fuzzy-finder/lib/load-paths-task.coffee +++ b/src/packages/fuzzy-finder/lib/load-paths-task.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class LoadPathsTask @@ -18,7 +18,7 @@ class LoadPathsTask path = path.substring(rootPath.length + 1) for segment in path.split('/') return true if _.contains(ignoredNames, segment) - ignoreGitIgnoredFiles and git?.isPathIgnored(fs.join(rootPath, path)) + ignoreGitIgnoredFiles and git?.isPathIgnored(fsUtils.join(rootPath, path)) onFile = (path) -> return if @aborted paths.push(path) unless isIgnored(path) @@ -27,7 +27,7 @@ class LoadPathsTask onDone = => @callback(paths) unless @aborted - fs.traverseTree(rootPath, onFile, onDirectory, onDone) + fsUtils.traverseTree(rootPath, onFile, onDirectory, onDone) abort: -> @aborted = true diff --git a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee index 3c9a5c6e4..0ea88f702 100644 --- a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee +++ b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee @@ -4,7 +4,7 @@ LoadPathsTask = require 'fuzzy-finder/lib/load-paths-task' _ = require 'underscore' $ = require 'jquery' {$$} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe 'FuzzyFinder', -> [finderView] = [] @@ -57,7 +57,7 @@ describe 'FuzzyFinder', -> runs -> expect(finderView.list.children('li').length).toBe paths.length for path in paths - expect(finderView.list.find("li:contains(#{fs.base(path)})")).toExist() + expect(finderView.list.find("li:contains(#{fsUtils.base(path)})")).toExist() expect(finderView.list.children().first()).toHaveClass 'selected' expect(finderView.find(".loading")).not.toBeVisible() @@ -218,16 +218,16 @@ describe 'FuzzyFinder', -> editor = rootView.getActiveView() originalText = editor.getText() originalPath = editor.getPath() - fs.write(originalPath, 'making a change for the better') + fsUtils.write(originalPath, 'making a change for the better') git.getPathStatus(originalPath) newPath = project.resolve('newsample.js') - fs.write(newPath, '') + fsUtils.write(newPath, '') git.getPathStatus(newPath) afterEach -> - fs.write(originalPath, originalText) - fs.remove(newPath) if fs.exists(newPath) + fsUtils.write(originalPath, originalText) + fsUtils.remove(newPath) if fsUtils.exists(newPath) it "displays all new and modified paths", -> expect(rootView.find('.fuzzy-finder')).not.toExist() @@ -468,11 +468,11 @@ describe 'FuzzyFinder', -> originalText = editor.getText() originalPath = editor.getPath() newPath = project.resolve('newsample.js') - fs.write(newPath, '') + fsUtils.write(newPath, '') afterEach -> - fs.write(originalPath, originalText) - fs.remove(newPath) if fs.exists(newPath) + fsUtils.write(originalPath, originalText) + fsUtils.remove(newPath) if fsUtils.exists(newPath) describe "when a modified file is shown in the list", -> it "displays the modified icon", -> diff --git a/src/packages/markdown-preview/lib/markdown-preview-view.coffee b/src/packages/markdown-preview/lib/markdown-preview-view.coffee index 62a832e5c..5a8de69de 100644 --- a/src/packages/markdown-preview/lib/markdown-preview-view.coffee +++ b/src/packages/markdown-preview/lib/markdown-preview-view.coffee @@ -1,4 +1,3 @@ -fs = require 'fs-utils' $ = require 'jquery' ScrollView = require 'scroll-view' {$$$} = require 'space-pen' diff --git a/src/packages/package-generator/lib/package-generator-view.coffee b/src/packages/package-generator/lib/package-generator-view.coffee index 63f07890f..eebbf88c2 100644 --- a/src/packages/package-generator/lib/package-generator-view.coffee +++ b/src/packages/package-generator/lib/package-generator-view.coffee @@ -2,7 +2,7 @@ Editor = require 'editor' $ = require 'jquery' _ = require 'underscore' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class PackageGeneratorView extends View @@ -24,7 +24,7 @@ class PackageGeneratorView extends View @previouslyFocusedElement = $(':focus') @message.text("Enter package path") placeholderName = "package-name" - @miniEditor.setText(fs.join(config.userPackagesDirPath, placeholderName)); + @miniEditor.setText(fsUtils.join(config.userPackagesDirPath, placeholderName)); pathLength = @miniEditor.getText().length @miniEditor.setSelectedBufferRange([[0, pathLength - placeholderName.length], [0, pathLength]]) @@ -44,11 +44,11 @@ class PackageGeneratorView extends View getPackagePath: -> packagePath = @miniEditor.getText() - packageName = _.dasherize(fs.base(packagePath)) - fs.join(fs.directory(packagePath), packageName) + packageName = _.dasherize(fsUtils.base(packagePath)) + fsUtils.join(fsUtils.directory(packagePath), packageName) validPackagePath: -> - if fs.exists(@getPackagePath()) + if fsUtils.exists(@getPackagePath()) @error.text("Path already exists at '#{@getPackagePath()}'") @error.show() false @@ -56,22 +56,22 @@ class PackageGeneratorView extends View true createPackageFiles: -> - templatePath = fs.resolveOnLoadPath(fs.join("package-generator", "template")) - packageName = fs.base(@getPackagePath()) + templatePath = fsUtils.resolveOnLoadPath(fsUtils.join("package-generator", "template")) + packageName = fsUtils.base(@getPackagePath()) - for path in fs.listTree(templatePath) + for path in fsUtils.listTree(templatePath) relativePath = path.replace(templatePath, "") relativePath = relativePath.replace(/^\//, '') relativePath = relativePath.replace(/\.template$/, '') relativePath = @replacePackageNamePlaceholders(relativePath, packageName) - sourcePath = fs.join(@getPackagePath(), relativePath) - if fs.isDirectory(path) - fs.makeTree(sourcePath) - if fs.isFile(path) - fs.makeTree(fs.directory(sourcePath)) - content = @replacePackageNamePlaceholders(fs.read(path), packageName) - fs.write(sourcePath, content) + sourcePath = fsUtils.join(@getPackagePath(), relativePath) + if fsUtils.isDirectory(path) + fsUtils.makeTree(sourcePath) + if fsUtils.isFile(path) + fsUtils.makeTree(fsUtils.directory(sourcePath)) + content = @replacePackageNamePlaceholders(fsUtils.read(path), packageName) + fsUtils.write(sourcePath, content) replacePackageNamePlaceholders: (string, packageName) -> placeholderRegex = /__(?:(package-name)|([pP]ackageName)|(package_name))__/g diff --git a/src/packages/package-generator/spec/package-generator-spec.coffee b/src/packages/package-generator/spec/package-generator-spec.coffee index 87d57bbdd..b237dc285 100644 --- a/src/packages/package-generator/spec/package-generator-spec.coffee +++ b/src/packages/package-generator/spec/package-generator-spec.coffee @@ -1,5 +1,5 @@ RootView = require 'root-view' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe 'Package Generator', -> [packageGenerator] = [] @@ -35,21 +35,21 @@ describe 'Package Generator', -> packageName = "sweet-package-dude" packagePath = "/tmp/atom-packages/#{packageName}" - fs.remove(packagePath) if fs.exists(packagePath) + fsUtils.remove(packagePath) if fsUtils.exists(packagePath) afterEach -> - fs.remove(packagePath) if fs.exists(packagePath) + fsUtils.remove(packagePath) if fsUtils.exists(packagePath) it "forces the package's name to be lowercase with dashes", -> packageName = "CamelCaseIsForTheBirds" - packagePath = fs.join(fs.directory(packagePath), packageName) + packagePath = fsUtils.join(fsUtils.directory(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(fs.join(fs.directory(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() + expect(fsUtils.join(fsUtils.directory(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() it "correctly lays out the package files and closes the package generator view", -> rootView.attachToDom() @@ -77,16 +77,16 @@ describe 'Package Generator', -> packageGeneratorView.miniEditor.setText(packagePath) packageGeneratorView.trigger "core:confirm" - lines = fs.read("#{packagePath}/package.cson").split("\n") + lines = fsUtils.read("#{packagePath}/package.cson").split("\n") expect(lines[0]).toBe "'main': 'lib\/#{packageName}'" - lines = fs.read("#{packagePath}/lib/#{packageName}.coffee").split("\n") + lines = fsUtils.read("#{packagePath}/lib/#{packageName}.coffee").split("\n") expect(lines[0]).toBe "SweetPackageDudeView = require 'sweet-package-dude/lib/sweet-package-dude-view'" expect(lines[3]).toBe " sweetPackageDudeView: null" it "displays an error when the package path already exists", -> rootView.attachToDom() - fs.makeTree(packagePath) + fsUtils.makeTree(packagePath) rootView.trigger("package-generator:generate") packageGeneratorView = rootView.find(".package-generator").view() diff --git a/src/packages/snippets/lib/snippet-body-parser.coffee b/src/packages/snippets/lib/snippet-body-parser.coffee index f4c3f99f7..15e6bb289 100644 --- a/src/packages/snippets/lib/snippet-body-parser.coffee +++ b/src/packages/snippets/lib/snippet-body-parser.coffee @@ -1,4 +1,4 @@ PEG = require 'pegjs' -fs = require 'fs-utils' -grammarSrc = fs.read(require.resolve('./snippet-body.pegjs')) +fsUtils = require 'fs-utils' +grammarSrc = fsUtils.read(require.resolve('./snippet-body.pegjs')) module.exports = PEG.buildParser(grammarSrc, trackLineAndColumn: true) diff --git a/src/packages/snippets/spec/snippets-spec.coffee b/src/packages/snippets/spec/snippets-spec.coffee index 2236757e7..de27a456a 100644 --- a/src/packages/snippets/spec/snippets-spec.coffee +++ b/src/packages/snippets/spec/snippets-spec.coffee @@ -3,7 +3,6 @@ RootView = require 'root-view' Buffer = require 'text-buffer' Editor = require 'editor' _ = require 'underscore' -fs = require 'fs-utils' Package = require 'package' describe "Snippets extension", -> diff --git a/src/packages/status-bar/spec/status-bar-spec.coffee b/src/packages/status-bar/spec/status-bar-spec.coffee index 497a4143d..d9bf04274 100644 --- a/src/packages/status-bar/spec/status-bar-spec.coffee +++ b/src/packages/status-bar/spec/status-bar-spec.coffee @@ -2,7 +2,7 @@ $ = require 'jquery' _ = require 'underscore' RootView = require 'root-view' StatusBar = require 'status-bar/lib/status-bar-view' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "StatusBar", -> [editor, statusBar, buffer] = [] @@ -57,7 +57,7 @@ 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" - fs.write(path, "") + fsUtils.write(path, "") rootView.open(path) expect(statusBar.bufferModified.text()).toBe '' editor.insertText("\n") @@ -107,12 +107,12 @@ describe "StatusBar", -> describe "git branch label", -> beforeEach -> - fs.remove('/tmp/.git') if fs.isDirectory('/tmp/.git') + fsUtils.remove('/tmp/.git') if fsUtils.isDirectory('/tmp/.git') rootView.attachToDom() it "displays the current branch for files in repositories", -> path = require.resolve('fixtures/git/master.git/HEAD') - project.setPath(fs.resolveOnLoadPath('fixtures/git/master.git')) + project.setPath(fsUtils.resolveOnLoadPath('fixtures/git/master.git')) rootView.open(path) expect(statusBar.branchArea).toBeVisible() expect(statusBar.branchLabel.text()).toBe 'master' @@ -128,22 +128,22 @@ describe "StatusBar", -> beforeEach -> path = require.resolve('fixtures/git/working-dir/file.txt') - newPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'new.txt') - fs.write(newPath, "I'm new here") - ignoredPath = fs.join(fs.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt') - fs.write(ignoredPath, 'ignored.txt') + newPath = fsUtils.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') + fsUtils.write(ignoredPath, 'ignored.txt') git.getPathStatus(path) git.getPathStatus(newPath) - originalPathText = fs.read(path) + originalPathText = fsUtils.read(path) rootView.attachToDom() afterEach -> - fs.write(path, originalPathText) - fs.remove(newPath) if fs.exists(newPath) - fs.remove(ignoredPath) if fs.exists(ignoredPath) + fsUtils.write(path, originalPathText) + fsUtils.remove(newPath) if fsUtils.exists(newPath) + fsUtils.remove(ignoredPath) if fsUtils.exists(ignoredPath) it "displays the modified icon for a changed file", -> - fs.write(path, "i've changed for the worse") + fsUtils.write(path, "i've changed for the worse") git.getPathStatus(path) rootView.open(path) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') @@ -161,16 +161,16 @@ describe "StatusBar", -> expect(statusBar.gitStatusIcon).toHaveClass('ignored-status-icon') it "updates when a status-changed event occurs", -> - fs.write(path, "i've changed for the worse") + fsUtils.write(path, "i've changed for the worse") git.getPathStatus(path) rootView.open(path) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') - fs.write(path, originalPathText) + fsUtils.write(path, originalPathText) git.getPathStatus(path) expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon') it "displays the diff stat for modified files", -> - fs.write(path, "i've changed for the worse") + fsUtils.write(path, "i've changed for the worse") git.getPathStatus(path) rootView.open(path) expect(statusBar.gitStatusIcon).toHaveText('+1,-1') diff --git a/src/packages/symbols-view/lib/load-tags-handler.coffee b/src/packages/symbols-view/lib/load-tags-handler.coffee index 860d037f5..c29957822 100644 --- a/src/packages/symbols-view/lib/load-tags-handler.coffee +++ b/src/packages/symbols-view/lib/load-tags-handler.coffee @@ -1,13 +1,13 @@ ctags = require 'ctags' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = getTagsFile: (path) -> - tagsFile = fs.join(path, "tags") - return tagsFile if fs.isFile(tagsFile) + tagsFile = fsUtils.join(path, "tags") + return tagsFile if fsUtils.isFile(tagsFile) - tagsFile = fs.join(path, "TAGS") - return tagsFile if fs.isFile(tagsFile) + tagsFile = fsUtils.join(path, "TAGS") + return tagsFile if fsUtils.isFile(tagsFile) loadTags: (path) -> tagsFile = @getTagsFile(path) diff --git a/src/packages/symbols-view/lib/symbols-view.coffee b/src/packages/symbols-view/lib/symbols-view.coffee index 816be9739..a6f617139 100644 --- a/src/packages/symbols-view/lib/symbols-view.coffee +++ b/src/packages/symbols-view/lib/symbols-view.coffee @@ -3,7 +3,7 @@ SelectList = require 'select-list' TagGenerator = require './tag-generator' TagReader = require './tag-reader' Point = require 'point' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' module.exports = @@ -30,7 +30,7 @@ class SymbolsView extends SelectList if position text = "Line #{position.row + 1}" else - text = fs.base(file) + text = fsUtils.base(file) @div text, class: 'right function-details' toggleFileSymbols: -> @@ -75,7 +75,7 @@ class SymbolsView extends SelectList setTimeout (=> @cancel()), 2000 confirmed : (tag) -> - if tag.file and not fs.isFile(project.resolve(tag.file)) + if tag.file and not fsUtils.isFile(project.resolve(tag.file)) @setError('Selected file does not exist') setTimeout((=> @setError()), 2000) else @@ -104,8 +104,8 @@ class SymbolsView extends SelectList pattern = $.trim(tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '')) # Remove leading /^ and trailing $/ return unless pattern file = project.resolve(tag.file) - return unless fs.isFile(file) - for line, index in fs.read(file).split('\n') + return unless fsUtils.isFile(file) + for line, index in fsUtils.read(file).split('\n') return new Point(index, 0) if pattern is $.trim(line) goToDeclaration: -> @@ -123,7 +123,7 @@ class SymbolsView extends SelectList continue unless position tags.push file: match.file - name: fs.base(match.file) + name: fsUtils.base(match.file) position: position @miniEditor.show() @setArray(tags) diff --git a/src/packages/symbols-view/lib/tag-generator.coffee b/src/packages/symbols-view/lib/tag-generator.coffee index 5960ed6a2..8a847ea25 100644 --- a/src/packages/symbols-view/lib/tag-generator.coffee +++ b/src/packages/symbols-view/lib/tag-generator.coffee @@ -1,7 +1,7 @@ Point = require 'point' $ = require 'jquery' BufferedProcess = require 'buffered-process' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class TagGenerator @@ -18,7 +18,7 @@ class TagGenerator generate: -> deferred = $.Deferred() tags = [] - command = fs.resolveOnLoadPath('ctags') + command = fsUtils.resolveOnLoadPath('ctags') args = ['--fields=+KS', '-nf', '-', @path] stdout = (lines) => for line in lines.split('\n') diff --git a/src/packages/symbols-view/lib/tag-reader.coffee b/src/packages/symbols-view/lib/tag-reader.coffee index dd7f069a7..d243535e8 100644 --- a/src/packages/symbols-view/lib/tag-reader.coffee +++ b/src/packages/symbols-view/lib/tag-reader.coffee @@ -1,4 +1,4 @@ -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' LoadTagsTask = require './load-tags-task' ctags = require 'ctags' @@ -7,7 +7,7 @@ module.exports = getTagsFile: (project) -> tagsFile = project.resolve("tags") or project.resolve("TAGS") - return tagsFile if fs.isFile(tagsFile) + return tagsFile if fsUtils.isFile(tagsFile) find: (editor) -> word = editor.getTextInRange(editor.getCursor().getCurrentWordBufferRange()) diff --git a/src/packages/symbols-view/spec/symbols-view-spec.coffee b/src/packages/symbols-view/spec/symbols-view-spec.coffee index 7401a4448..4762ba421 100644 --- a/src/packages/symbols-view/spec/symbols-view-spec.coffee +++ b/src/packages/symbols-view/spec/symbols-view-spec.coffee @@ -1,7 +1,7 @@ RootView = require 'root-view' SymbolsView = require 'symbols-view/lib/symbols-view' TagGenerator = require 'symbols-view/lib/tag-generator' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "SymbolsView", -> [symbolsView, setArraySpy] = [] @@ -162,11 +162,11 @@ describe "SymbolsView", -> beforeEach -> renamedPath = project.resolve("tagged-duplicate-renamed.js") - fs.remove(renamedPath) if fs.exists(renamedPath) - fs.move(project.resolve("tagged-duplicate.js"), renamedPath) + fsUtils.remove(renamedPath) if fsUtils.exists(renamedPath) + fsUtils.move(project.resolve("tagged-duplicate.js"), renamedPath) afterEach -> - fs.move(renamedPath, project.resolve("tagged-duplicate.js")) + fsUtils.move(renamedPath, project.resolve("tagged-duplicate.js")) it "doesn't display the tag", -> rootView.open("tagged.js") @@ -205,11 +205,11 @@ describe "SymbolsView", -> beforeEach -> renamedPath = project.resolve("tagged-renamed.js") - fs.remove(renamedPath) if fs.exists(renamedPath) - fs.move(project.resolve("tagged.js"), renamedPath) + fsUtils.remove(renamedPath) if fsUtils.exists(renamedPath) + fsUtils.move(project.resolve("tagged.js"), renamedPath) afterEach -> - fs.move(renamedPath, project.resolve("tagged.js")) + fsUtils.move(renamedPath, project.resolve("tagged.js")) it "doesn't open the editor", -> rootView.trigger "symbols-view:toggle-project-symbols" diff --git a/src/packages/tabs/lib/tab-view.coffee b/src/packages/tabs/lib/tab-view.coffee index 9e9594ef1..9c5faab90 100644 --- a/src/packages/tabs/lib/tab-view.coffee +++ b/src/packages/tabs/lib/tab-view.coffee @@ -1,6 +1,6 @@ $ = require 'jquery' {View} = require 'space-pen' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class TabView extends View @@ -46,7 +46,7 @@ class TabView extends View if fileNameText? duplicates = @editor.getEditSessions().filter (session) -> fileNameText is session.buffer.getBaseName() if duplicates.length > 1 - directory = fs.base(fs.directory(@editSession.getPath())) + directory = fsUtils.base(fsUtils.directory(@editSession.getPath())) fileNameText = "#{fileNameText} - #{directory}" if directory else fileNameText = 'untitled' diff --git a/src/packages/tabs/spec/tabs-spec.coffee b/src/packages/tabs/spec/tabs-spec.coffee index a366126d9..7eb59d232 100644 --- a/src/packages/tabs/spec/tabs-spec.coffee +++ b/src/packages/tabs/spec/tabs-spec.coffee @@ -4,7 +4,6 @@ RootView = require 'root-view' Pane = require 'pane' PaneContainer = require 'pane-container' TabBarView = require 'tabs/lib/tab-bar-view' -fs = require 'fs-utils' {View} = require 'space-pen' describe "Tabs package main", -> diff --git a/src/packages/tree-view/lib/dialog.coffee b/src/packages/tree-view/lib/dialog.coffee index 858db818a..d1d4787bd 100644 --- a/src/packages/tree-view/lib/dialog.coffee +++ b/src/packages/tree-view/lib/dialog.coffee @@ -1,6 +1,6 @@ {View} = require 'space-pen' Editor = require 'editor' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' module.exports = @@ -21,8 +21,8 @@ class Dialog extends View @miniEditor.setText(path) if select - extension = fs.extension(path) - baseName = fs.base(path) + extension = fsUtils.extension(path) + baseName = fsUtils.base(path) if baseName is extension selectionEnd = path.length else diff --git a/src/packages/tree-view/lib/file-view.coffee b/src/packages/tree-view/lib/file-view.coffee index 1ff73c910..1aea8286b 100644 --- a/src/packages/tree-view/lib/file-view.coffee +++ b/src/packages/tree-view/lib/file-view.coffee @@ -1,7 +1,7 @@ {View} = require 'space-pen' $ = require 'jquery' Git = require 'git' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class FileView extends View @@ -17,16 +17,16 @@ class FileView extends View if @file.symlink @fileName.addClass('symlink-icon') else - extension = fs.extension(@getPath()) - if fs.isReadmePath(@getPath()) + extension = fsUtils.extension(@getPath()) + if fsUtils.isReadmePath(@getPath()) @fileName.addClass('readme-icon') - else if fs.isCompressedExtension(extension) + else if fsUtils.isCompressedExtension(extension) @fileName.addClass('compressed-icon') - else if fs.isImageExtension(extension) + else if fsUtils.isImageExtension(extension) @fileName.addClass('image-icon') - else if fs.isPdfExtension(extension) + else if fsUtils.isPdfExtension(extension) @fileName.addClass('pdf-icon') - else if fs.isBinaryExtension(extension) + else if fsUtils.isBinaryExtension(extension) @fileName.addClass('binary-icon') else @fileName.addClass('text-icon') diff --git a/src/packages/tree-view/lib/tree-view.coffee b/src/packages/tree-view/lib/tree-view.coffee index c7e72221e..6e0aa25b2 100644 --- a/src/packages/tree-view/lib/tree-view.coffee +++ b/src/packages/tree-view/lib/tree-view.coffee @@ -4,7 +4,7 @@ Directory = require 'directory' DirectoryView = require './directory-view' FileView = require './file-view' Dialog = require './dialog' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' $ = require 'jquery' _ = require 'underscore' @@ -230,14 +230,14 @@ class TreeView extends ScrollView dialog.close() return - if fs.exists(newPath) + if fsUtils.exists(newPath) dialog.showError("Error: #{newPath} already exists. Try a different path.") return - directoryPath = fs.directory(newPath) + directoryPath = fsUtils.directory(newPath) try - fs.makeTree(directoryPath) unless fs.exists(directoryPath) - fs.move(oldPath, newPath) + fsUtils.makeTree(directoryPath) unless fsUtils.exists(directoryPath) + fsUtils.move(oldPath, newPath) dialog.close() catch e dialog.showError("Error: #{e.message} Try a different path.") @@ -254,13 +254,13 @@ class TreeView extends ScrollView "You are deleting #{entry.getPath()}", "Move to Trash", (=> $native.moveToTrash(entry.getPath())), "Cancel", null - "Delete", (=> fs.remove(entry.getPath())) + "Delete", (=> fsUtils.remove(entry.getPath())) ) add: -> selectedEntry = @selectedEntry() or @root selectedPath = selectedEntry.getPath() - directoryPath = if fs.isFile(selectedPath) then fs.directory(selectedPath) else selectedPath + directoryPath = if fsUtils.isFile(selectedPath) then fsUtils.directory(selectedPath) else selectedPath relativeDirectoryPath = project.relativize(directoryPath) relativeDirectoryPath += '/' if relativeDirectoryPath.length > 0 @@ -274,16 +274,16 @@ class TreeView extends ScrollView endsWithDirectorySeparator = /\/$/.test(relativePath) path = project.resolve(relativePath) try - if fs.exists(path) - pathType = if fs.isFile(path) then "file" else "directory" + if fsUtils.exists(path) + pathType = if fsUtils.isFile(path) then "file" else "directory" dialog.showError("Error: A #{pathType} already exists at path '#{path}'. Try a different path.") else if endsWithDirectorySeparator - fs.makeTree(path) + fsUtils.makeTree(path) dialog.cancel() @entryForPath(path).buildEntries() @selectEntryForPath(path) else - fs.write(path, "") + fsUtils.write(path, "") rootView.open(path) dialog.close() catch e diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index f5f01aace..d65c59fdb 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -4,7 +4,7 @@ _ = require 'underscore' TreeView = require 'tree-view/lib/tree-view' RootView = require 'root-view' Directory = require 'directory' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "TreeView", -> [treeView, sampleJs, sampleTxt] = [] @@ -259,20 +259,20 @@ describe "TreeView", -> sampleJs.trigger clickEvent(originalEvent: { detail: 1 }) expect(sampleJs).toHaveClass 'selected' - expect(rootView.getActiveView().getPath()).toBe fs.resolveOnLoadPath('fixtures/tree-view/tree-view.js') + expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js') expect(rootView.getActiveView().isFocused).toBeFalsy() sampleTxt.trigger clickEvent(originalEvent: { detail: 1 }) expect(sampleTxt).toHaveClass 'selected' expect(treeView.find('.selected').length).toBe 1 - expect(rootView.getActiveView().getPath()).toBe fs.resolveOnLoadPath('fixtures/tree-view/tree-view.txt') + expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.txt') expect(rootView.getActiveView().isFocused).toBeFalsy() describe "when a file is double-clicked", -> it "selects the file and opens it in the active editor on the first click, then changes focus to the active editor on the second", -> sampleJs.trigger clickEvent(originalEvent: { detail: 1 }) expect(sampleJs).toHaveClass 'selected' - expect(rootView.getActiveView().getPath()).toBe fs.resolveOnLoadPath('fixtures/tree-view/tree-view.js') + expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js') expect(rootView.getActiveView().isFocused).toBeFalsy() sampleJs.trigger clickEvent(originalEvent: { detail: 2 }) @@ -568,7 +568,7 @@ describe "TreeView", -> it "opens the file in the editor and focuses it", -> treeView.root.find('.file:contains(tree-view.js)').click() treeView.root.trigger 'tree-view:open-selected-entry' - expect(rootView.getActiveView().getPath()).toBe fs.resolveOnLoadPath('fixtures/tree-view/tree-view.js') + expect(rootView.getActiveView().getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/tree-view/tree-view.js') expect(rootView.getActiveView().isFocused).toBeTruthy() describe "when a directory is selected", -> @@ -593,14 +593,14 @@ describe "TreeView", -> beforeEach -> atom.deactivatePackage('tree-view') - rootDirPath = fs.join(fs.absolute("/tmp"), "atom-tests") - fs.remove(rootDirPath) if fs.exists(rootDirPath) + rootDirPath = fsUtils.join(fsUtils.absolute("/tmp"), "atom-tests") + fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath) - dirPath = fs.join(rootDirPath, "test-dir") - filePath = fs.join(dirPath, "test-file.txt") - fs.makeDirectory(rootDirPath) - fs.makeDirectory(dirPath) - fs.write(filePath, "doesn't matter") + dirPath = fsUtils.join(rootDirPath, "test-dir") + filePath = fsUtils.join(dirPath, "test-file.txt") + fsUtils.makeDirectory(rootDirPath) + fsUtils.makeDirectory(dirPath) + fsUtils.write(filePath, "doesn't matter") project.setPath(rootDirPath) @@ -612,7 +612,7 @@ describe "TreeView", -> fileView = treeView.find('.file:contains(test-file.txt)').view() afterEach -> - fs.remove(rootDirPath) if fs.exists(rootDirPath) + fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath) describe "tree-view:add", -> addDialog = null @@ -638,16 +638,16 @@ describe "TreeView", -> dirView.directory.trigger 'contents-changed' expect(directoryChangeHandler).toHaveBeenCalled() - expect(treeView.find('.selected').text()).toBe fs.base(filePath) + expect(treeView.find('.selected').text()).toBe fsUtils.base(filePath) 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 = fs.join(dirPath, "new-test-file.txt") - addDialog.miniEditor.insertText(fs.base(newPath)) + newPath = fsUtils.join(dirPath, "new-test-file.txt") + addDialog.miniEditor.insertText(fsUtils.base(newPath)) addDialog.trigger 'core:confirm' - expect(fs.exists(newPath)).toBeTruthy() - expect(fs.isFile(newPath)).toBeTruthy() + expect(fsUtils.exists(newPath)).toBeTruthy() + expect(fsUtils.isFile(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveView().getPath()).toBe newPath @@ -655,13 +655,13 @@ describe "TreeView", -> dirView.entries.find("> .file").length > 1 runs -> - expect(treeView.find('.selected').text()).toBe fs.base(newPath) + expect(treeView.find('.selected').text()).toBe fsUtils.base(newPath) describe "when a file already exists at that location", -> it "shows an error message and does not close the dialog", -> - newPath = fs.join(dirPath, "new-test-file.txt") - fs.write(newPath, '') - addDialog.miniEditor.insertText(fs.base(newPath)) + newPath = fsUtils.join(dirPath, "new-test-file.txt") + fsUtils.write(newPath, '') + addDialog.miniEditor.insertText(fsUtils.base(newPath)) addDialog.trigger 'core:confirm' expect(addDialog.prompt.text()).toContain 'Error' @@ -673,11 +673,11 @@ describe "TreeView", -> describe "when no file or directory exists at the given path", -> it "adds a directory and closes the dialog", -> treeView.attachToDom() - newPath = fs.join(dirPath, "new/dir") + newPath = fsUtils.join(dirPath, "new/dir") addDialog.miniEditor.insertText("new/dir/") addDialog.trigger 'core:confirm' - expect(fs.exists(newPath)).toBeTruthy() - expect(fs.isDirectory(newPath)).toBeTruthy() + expect(fsUtils.exists(newPath)).toBeTruthy() + expect(fsUtils.isDirectory(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveView().getPath()).not.toBe newPath expect(treeView.find(".tree-view")).toMatchSelector(':focus') @@ -686,11 +686,11 @@ describe "TreeView", -> it "selects the created directory", -> treeView.attachToDom() - newPath = fs.join(dirPath, "new2/") + newPath = fsUtils.join(dirPath, "new2/") addDialog.miniEditor.insertText("new2/") addDialog.trigger 'core:confirm' - expect(fs.exists(newPath)).toBeTruthy() - expect(fs.isDirectory(newPath)).toBeTruthy() + expect(fsUtils.exists(newPath)).toBeTruthy() + expect(fsUtils.isDirectory(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveView().getPath()).not.toBe newPath expect(treeView.find(".tree-view")).toMatchSelector(':focus') @@ -699,8 +699,8 @@ 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 = fs.join(dirPath, "new-dir") - fs.makeDirectory(newPath) + newPath = fsUtils.join(dirPath, "new-dir") + fsUtils.makeDirectory(newPath) addDialog.miniEditor.insertText("new-dir/") addDialog.trigger 'core:confirm' @@ -770,24 +770,24 @@ describe "TreeView", -> waits 50 # The move specs cause too many false positives because of their async nature, so wait a little bit before we cleanup it "opens a move dialog with the file's current path (excluding extension) populated", -> - extension = fs.extension(filePath) - fileNameWithoutExtension = fs.base(filePath, extension) + extension = fsUtils.extension(filePath) + fileNameWithoutExtension = fsUtils.base(filePath, extension) expect(moveDialog).toExist() expect(moveDialog.prompt.text()).toBe "Enter the new path for the file." expect(moveDialog.miniEditor.getText()).toBe(project.relativize(filePath)) - expect(moveDialog.miniEditor.getSelectedText()).toBe fs.base(fileNameWithoutExtension) + expect(moveDialog.miniEditor.getSelectedText()).toBe fsUtils.base(fileNameWithoutExtension) expect(moveDialog.miniEditor.isFocused).toBeTruthy() 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 = fs.join(rootDirPath, 'renamed-test-file.txt') + newPath = fsUtils.join(rootDirPath, 'renamed-test-file.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' - expect(fs.exists(newPath)).toBeTruthy() - expect(fs.exists(filePath)).toBeFalsy() + expect(fsUtils.exists(newPath)).toBeTruthy() + expect(fsUtils.exists(filePath)).toBeFalsy() expect(moveDialog.parent()).not.toExist() waitsFor "tree view to update", -> @@ -800,7 +800,7 @@ describe "TreeView", -> describe "when the directories along the new path don't exist", -> it "creates the target directory before moving the file", -> - newPath = fs.join(rootDirPath, 'new/directory', 'renamed-test-file.txt') + newPath = fsUtils.join(rootDirPath, 'new/directory', 'renamed-test-file.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' @@ -809,14 +809,14 @@ describe "TreeView", -> treeView.root.find('> .entries > .directory:contains(new)').length > 0 runs -> - expect(fs.exists(newPath)).toBeTruthy() - expect(fs.exists(filePath)).toBeFalsy() + expect(fsUtils.exists(newPath)).toBeTruthy() + expect(fsUtils.exists(filePath)).toBeFalsy() describe "when a file or directory already exists at the target path", -> it "shows an error message and does not close the dialog", -> runs -> - fs.write(fs.join(rootDirPath, 'target.txt'), '') - newPath = fs.join(rootDirPath, 'target.txt') + fsUtils.write(fsUtils.join(rootDirPath, 'target.txt'), '') + newPath = fsUtils.join(rootDirPath, 'target.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'core:confirm' @@ -844,8 +844,8 @@ describe "TreeView", -> [dotFilePath, dotFileView, moveDialog] = [] beforeEach -> - dotFilePath = fs.join(dirPath, ".dotfile") - fs.write(dotFilePath, "dot") + dotFilePath = fsUtils.join(dirPath, ".dotfile") + fsUtils.write(dotFilePath, "dot") dirView.collapse() dirView.expand() dotFileView = treeView.find('.file:contains(.dotfile)').view() @@ -875,22 +875,22 @@ describe "TreeView", -> temporaryFilePath = null beforeEach -> - temporaryFilePath = fs.join(fs.resolveOnLoadPath('fixtures/tree-view'), 'temporary') - if fs.exists(temporaryFilePath) - fs.remove(temporaryFilePath) + temporaryFilePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary') + if fsUtils.exists(temporaryFilePath) + fsUtils.remove(temporaryFilePath) waits(20) afterEach -> - fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath) + fsUtils.remove(temporaryFilePath) if fsUtils.exists(temporaryFilePath) describe "when a file is added or removed in an expanded directory", -> it "updates the directory view to display the directory's new contents", -> entriesCountBefore = null runs -> - expect(fs.exists(temporaryFilePath)).toBeFalsy() + expect(fsUtils.exists(temporaryFilePath)).toBeFalsy() entriesCountBefore = treeView.root.entries.find('.entry').length - fs.write temporaryFilePath, 'hi' + fsUtils.write temporaryFilePath, 'hi' waitsFor "directory view contens to refresh", -> treeView.root.entries.find('.entry').length == entriesCountBefore + 1 @@ -898,7 +898,7 @@ describe "TreeView", -> runs -> expect(treeView.root.entries.find('.entry').length).toBe entriesCountBefore + 1 expect(treeView.root.entries.find('.file:contains(temporary)')).toExist() - fs.remove(temporaryFilePath) + fsUtils.remove(temporaryFilePath) waitsFor "directory view contens to refresh", -> treeView.root.entries.find('.entry').length == entriesCountBefore @@ -907,12 +907,12 @@ describe "TreeView", -> [ignoreFile] = [] beforeEach -> - ignoreFile = fs.join(fs.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') - fs.write(ignoreFile, 'tree-view.js') + ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') + fsUtils.write(ignoreFile, 'tree-view.js') config.set "core.hideGitIgnoredFiles", false afterEach -> - fs.remove(ignoreFile) if fs.exists(ignoreFile) + fsUtils.remove(ignoreFile) if fsUtils.exists(ignoreFile) it "hides git-ignored files if the option is set, but otherwise shows them", -> expect(treeView.find('.file:contains(tree-view.js)').length).toBe 1 @@ -930,17 +930,17 @@ describe "TreeView", -> beforeEach -> config.set "core.hideGitIgnoredFiles", false - ignoreFile = fs.join(fs.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') - fs.write(ignoreFile, 'tree-view.js') + ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') + fsUtils.write(ignoreFile, 'tree-view.js') git.getPathStatus(ignoreFile) - newFile = fs.join(fs.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2') - fs.write(newFile, '') + newFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2') + fsUtils.write(newFile, '') git.getPathStatus(newFile) - modifiedFile = fs.join(fs.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1') - originalFileContent = fs.read(modifiedFile) - fs.write modifiedFile, 'ch ch changes' + modifiedFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1') + originalFileContent = fsUtils.read(modifiedFile) + fsUtils.write modifiedFile, 'ch ch changes' git.getPathStatus(modifiedFile) treeView.updateRoot() @@ -948,9 +948,9 @@ describe "TreeView", -> treeView.root.entries.find('.directory:contains(dir2)').view().expand() afterEach -> - fs.remove(ignoreFile) if fs.exists(ignoreFile) - fs.remove(newFile) if fs.exists(newFile) - fs.write modifiedFile, originalFileContent + fsUtils.remove(ignoreFile) if fsUtils.exists(ignoreFile) + fsUtils.remove(newFile) if fsUtils.exists(newFile) + fsUtils.write modifiedFile, originalFileContent describe "when a file is modified", -> it "adds a custom style", -> diff --git a/src/packages/whitespace/spec/whitespace-spec.coffee b/src/packages/whitespace/spec/whitespace-spec.coffee index 854cf3295..1a0e54f44 100644 --- a/src/packages/whitespace/spec/whitespace-spec.coffee +++ b/src/packages/whitespace/spec/whitespace-spec.coffee @@ -1,12 +1,12 @@ RootView = require 'root-view' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' describe "Whitespace", -> [editor, path] = [] beforeEach -> path = "/tmp/atom-whitespace.txt" - fs.write(path, "") + fsUtils.write(path, "") window.rootView = new RootView rootView.open(path) @@ -16,10 +16,10 @@ describe "Whitespace", -> editor = rootView.getActiveView() afterEach -> - fs.remove(path) if fs.exists(path) + fsUtils.remove(path) if fsUtils.exists(path) it "strips trailing whitespace before an editor saves a buffer", -> - spyOn(fs, 'write') + spyOn(fsUtils, 'write') config.set("whitespace.ensureSingleTrailingNewline", false) config.update() @@ -79,4 +79,3 @@ describe "Whitespace", -> editor.insertText "no trailing newline" editor.getBuffer().save() expect(editor.getText()).toBe "no trailing newline" - diff --git a/src/stdlib/task.coffee b/src/stdlib/task.coffee index 8216a4f15..091362d73 100644 --- a/src/stdlib/task.coffee +++ b/src/stdlib/task.coffee @@ -1,7 +1,7 @@ _ = require 'underscore' child_process = require 'child_process' EventEmitter = require 'event-emitter' -fs = require 'fs-utils' +fsUtils = require 'fs-utils' module.exports = class Task From 930cd9551b37cfdf5bdc0aee0b0076844c3cea51 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 12:01:23 -0600 Subject: [PATCH 31/33] :lipstick: add eof newlines --- spec/fixtures/packages/package-with-main/main-module.coffee | 2 +- src/packages/grammar-selector/lib/grammar-selector.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/packages/package-with-main/main-module.coffee b/spec/fixtures/packages/package-with-main/main-module.coffee index 46920ab78..825eb4055 100644 --- a/spec/fixtures/packages/package-with-main/main-module.coffee +++ b/spec/fixtures/packages/package-with-main/main-module.coffee @@ -1,2 +1,2 @@ module.exports = -activate: -> \ No newline at end of file +activate: -> diff --git a/src/packages/grammar-selector/lib/grammar-selector.coffee b/src/packages/grammar-selector/lib/grammar-selector.coffee index ca0aa828b..81f678a52 100644 --- a/src/packages/grammar-selector/lib/grammar-selector.coffee +++ b/src/packages/grammar-selector/lib/grammar-selector.coffee @@ -61,4 +61,4 @@ class GrammarSelector extends SelectList attach: -> super rootView.append(this) - @miniEditor.focus() \ No newline at end of file + @miniEditor.focus() From 5d22cff6ad7f076dc7be439feae7326dc81fd33b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 12:33:40 -0600 Subject: [PATCH 32/33] :speak_no_evil: --- .../packages/package-with-activation-events/index.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/fixtures/packages/package-with-activation-events/index.coffee b/spec/fixtures/packages/package-with-activation-events/index.coffee index 91f2230b1..44704fa79 100644 --- a/spec/fixtures/packages/package-with-activation-events/index.coffee +++ b/spec/fixtures/packages/package-with-activation-events/index.coffee @@ -10,5 +10,4 @@ module.exports = activate: -> @activateCallCount++ rootView.getActiveView()?.command 'activation-event', => - console.log "ACTIVATION EVENT" @activationEventCallCount++ From 40aa81e9c11063838b2ade2bf8f2ce676b560bc0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Apr 2013 12:34:56 -0600 Subject: [PATCH 33/33] Add required activate method to avoid logging during specs --- .../fixtures/packages/package-with-config-defaults/index.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/fixtures/packages/package-with-config-defaults/index.coffee b/spec/fixtures/packages/package-with-config-defaults/index.coffee index 5e0b1eed6..554c6c5eb 100644 --- a/spec/fixtures/packages/package-with-config-defaults/index.coffee +++ b/spec/fixtures/packages/package-with-config-defaults/index.coffee @@ -1,3 +1,5 @@ module.exports = configDefaults: numbers: { one: 1, two: 2 } + + activate: -> # no-op