Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove slash #14372

Merged
merged 3 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/gatsby-source-filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"pretty-bytes": "^4.0.2",
"progress": "^1.1.8",
"read-chunk": "^3.0.0",
"slash": "^1.0.0",
"valid-url": "^1.0.9",
"xstate": "^3.1.0"
},
Expand Down
12 changes: 11 additions & 1 deletion packages/gatsby-source-filesystem/src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getRemoteFileExtension, getRemoteFileName } = require(`../utils`)
const { getRemoteFileExtension, getRemoteFileName, slash } = require(`../utils`)

describe(`create remote file node`, () => {
it(`can correctly retrieve file name and extensions`, () => {
Expand All @@ -22,3 +22,13 @@ describe(`create remote file node`, () => {
})
})
})

describe(`slash path`, () => {
it(`can correctly slash path`, () => {
;[[`foo\\bar`, `foo/bar`], [`foo\\中文`, `foo/中文`]].forEach(
woodgear marked this conversation as resolved.
Show resolved Hide resolved
([path, expectRes]) => {
expect(slash(path)).toBe(expectRes)
}
)
})
})
superhawk610 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/src/create-file-node.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Athang663

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/gatsby-source-filesystem/src/create-file-node.js

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const slash = require(`slash`)
const { slash } = require(`./utils`)
const path = require(`path`)
const fs = require(`fs-extra`)
const mime = require(`mime`)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/src/create-file-path.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require(`path`)
const slash = require(`slash`)
const { slash } = require(`./utils`)

function findFileNode({ node, getNode }) {
// Find the file node.
Expand Down
19 changes: 19 additions & 0 deletions packages/gatsby-source-filesystem/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ export function getRemoteFileExtension(url) {
export function getRemoteFileName(url) {
return getParsedPath(url).name
}

/**
* slash
* --
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
*
*
* @param {String} path
* @return {String} slashed path
*/
export function slash(path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
superhawk610 marked this conversation as resolved.
Show resolved Hide resolved

if (isExtendedLengthPath) {
return path
}

return path.replace(/\\/g, `/`)
}