-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Unify filepaths to always use posix path separator (#81)
* feat: Unify filepaths to always use posix path separator * Remove usage of fromEntries to support older node versions * Satisfy the code coverage gods * Switch eslint to ecma 2018 parser * Add full coverage to the pathUtils * Add integration test on unifying pathnames between windows and posix
- Loading branch information
1 parent
ef3be21
commit 6c8e959
Showing
14 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
coverage/ | ||
.vscode | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
__tests__/integration/fixtures/windows-paths-in-record/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
rules: { | ||
"no-console": "warn" | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
__tests__/integration/fixtures/windows-paths-in-record/.esplint.rec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"recordVersion": 1, | ||
"configHash": "773a8b36f5d74ada1b0144c983a6d725c71c9413", | ||
"files": { | ||
"src\\main.js": { | ||
"no-console": 1 | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
__tests__/integration/fixtures/windows-paths-in-record/.esplintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
surfaceArea: ["."], | ||
rules: ["no-console"] | ||
}; |
1 change: 1 addition & 0 deletions
1
__tests__/integration/fixtures/windows-paths-in-record/src/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("this does nothing"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { toPosixPath, toSystemPath, toWinPath } = require("../lib/pathUtils"); | ||
const helpers = require("../lib/helpers"); | ||
|
||
describe("toPosixPath", function() { | ||
it("should convert windows to posix paths", () => { | ||
expect(toPosixPath("\\windows\\path")).toEqual("/windows/path"); | ||
}); | ||
it("should not alter posix paths", () => { | ||
expect(toPosixPath("/posix/path")).toEqual("/posix/path"); | ||
}); | ||
}); | ||
|
||
describe("toWinPath", function() { | ||
it("should convert posix to windows path", () => { | ||
expect(toWinPath("/posix/path")).toEqual("\\posix\\path"); | ||
}); | ||
it("not alter windows path", () => { | ||
expect(toWinPath("\\windows\\path")).toEqual("\\windows\\path"); | ||
}); | ||
}); | ||
|
||
describe("toSystemPath", () => { | ||
it("should convert posix to windows on windows", () => { | ||
jest.spyOn(helpers, "isPosix").mockImplementation(() => false); | ||
expect(toSystemPath("/posix/path")).toEqual("\\posix\\path"); | ||
}); | ||
it("should convert windows to posix on posix", () => { | ||
jest.spyOn(helpers, "isPosix").mockImplementation(() => true); | ||
expect(toSystemPath("\\windows\\path")).toEqual("/windows/path"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require("path"); | ||
|
||
function isPosix() { | ||
return path.sep === path.posix.sep; | ||
} | ||
|
||
module.exports = { | ||
isPosix | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const path = require("path"); | ||
const helpers = require("./helpers"); | ||
|
||
function toPosixPath(filePath) { | ||
return filePath.split(path.win32.sep).join(path.posix.sep); | ||
} | ||
|
||
function toWinPath(filePath) { | ||
return filePath.split(path.posix.sep).join(path.win32.sep); | ||
} | ||
|
||
function toSystemPath(filePath) { | ||
if (helpers.isPosix()) { | ||
return toPosixPath(filePath); | ||
} else { | ||
return toWinPath(filePath); | ||
} | ||
} | ||
|
||
module.exports = { | ||
toPosixPath, | ||
toWinPath, | ||
toSystemPath | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters