From 9929cf06437873793333ece28be6ca41c3dffe4b Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 19 Nov 2019 05:26:16 +0700 Subject: [PATCH] fix(gatsby): Handle special characters in windows paths (#19600) --- .../gatsby-core-utils/src/__tests__/path.js | 22 +++- packages/gatsby-core-utils/src/index.js | 1 + packages/gatsby-core-utils/src/path.js | 19 +++ packages/gatsby-page-utils/package.json | 4 +- .../gatsby-page-utils/src/watch-directory.js | 2 +- .../gatsby-plugin-mdx/loaders/mdx-loader.js | 2 +- .../gatsby-plugin-mdx/loaders/mdx-scopes.js | 2 +- packages/gatsby-plugin-mdx/package.json | 2 +- .../utils/create-fake-file-node.js | 2 +- packages/gatsby-plugin-offline/package.json | 2 +- .../gatsby-plugin-offline/src/gatsby-node.js | 2 +- packages/gatsby-remark-images/package.json | 2 +- packages/gatsby-remark-images/src/index.js | 2 +- .../src/__tests__/utils.js | 19 --- .../src/create-file-node.js | 3 +- .../src/create-file-path.js | 2 +- .../gatsby-source-filesystem/src/utils.js | 19 --- packages/gatsby/package.json | 2 +- packages/gatsby/src/bootstrap/index.js | 2 +- .../load-plugins/__tests__/load-plugins.js | 2 +- .../gatsby/src/bootstrap/load-plugins/load.js | 2 +- .../gatsby/src/bootstrap/requires-writer.js | 2 +- packages/gatsby/src/commands/develop.js | 2 +- .../__snapshots__/file-parser.js.snap | 124 ++++++++++++++++++ .../gatsby/src/query/__tests__/file-parser.js | 30 +++++ packages/gatsby/src/query/file-parser.js | 7 +- packages/gatsby/src/query/query-watcher.js | 2 +- packages/gatsby/src/redux/actions/public.js | 13 +- .../src/schema/__tests__/kitchen-sink.js | 2 +- .../src/schema/__tests__/queries-file.js | 2 +- .../src/schema/infer/__tests__/infer.js | 2 +- packages/gatsby/src/schema/infer/is-file.js | 2 +- packages/gatsby/src/utils/tracer/index.js | 2 +- yarn.lock | 5 + 34 files changed, 238 insertions(+), 72 deletions(-) diff --git a/packages/gatsby-core-utils/src/__tests__/path.js b/packages/gatsby-core-utils/src/__tests__/path.js index 0994f5f7b7048..41553142af056 100644 --- a/packages/gatsby-core-utils/src/__tests__/path.js +++ b/packages/gatsby-core-utils/src/__tests__/path.js @@ -1,4 +1,4 @@ -const { joinPath, isNodeInternalModulePath } = require(`../path`) +const { joinPath, isNodeInternalModulePath, slash } = require(`../path`) const os = require(`os`) describe(`paths`, () => { @@ -30,4 +30,24 @@ describe(`paths`, () => { expect(isNodeInternalModulePath(modulePath)).toBe(false) }) }) + + describe(`slash path`, () => { + it(`can correctly slash path`, () => { + ;[ + [`foo\\bar`, `foo/bar`], + [`foo/bar`, `foo/bar`], + [`foo\\中文`, `foo/中文`], + [`foo/中文`, `foo/中文`], + [`foo/жä`, `foo/жä`], + [`foo\\жä`, `foo/жä`], + ].forEach(([path, expectRes]) => { + expect(slash(path)).toBe(expectRes) + }) + }) + + it(`does not modify extended length paths`, () => { + const extended = `\\\\?\\some\\path` + expect(slash(extended)).toBe(extended) + }) + }) }) diff --git a/packages/gatsby-core-utils/src/index.js b/packages/gatsby-core-utils/src/index.js index 0433d4d4dd763..5be4ce26f1b1c 100644 --- a/packages/gatsby-core-utils/src/index.js +++ b/packages/gatsby-core-utils/src/index.js @@ -1,6 +1,7 @@ exports.createContentDigest = require(`./create-content-digest`) exports.joinPath = require(`./path`).joinPath exports.isNodeInternalModulePath = require(`./path`).isNodeInternalModulePath +exports.slash = require(`./path`).slash exports.cpuCoreCount = require(`./cpu-core-count`) exports.urlResolve = require(`./url`).resolve exports.isCI = require(`./ci`).isCI diff --git a/packages/gatsby-core-utils/src/path.js b/packages/gatsby-core-utils/src/path.js index 2e6751243add1..5de75e25c72ff 100644 --- a/packages/gatsby-core-utils/src/path.js +++ b/packages/gatsby-core-utils/src/path.js @@ -74,3 +74,22 @@ const nodePaths = [ */ export const isNodeInternalModulePath = fileName => nodePaths.some(regTest => regTest.test(fileName)) + +/** + * 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) + + if (isExtendedLengthPath) { + return path + } + + return path.replace(/\\/g, `/`) +} diff --git a/packages/gatsby-page-utils/package.json b/packages/gatsby-page-utils/package.json index 2a2aa8c8b8f33..1f8bc5bc3bcaa 100644 --- a/packages/gatsby-page-utils/package.json +++ b/packages/gatsby-page-utils/package.json @@ -24,10 +24,10 @@ "bluebird": "^3.7.1", "chokidar": "3.3.0", "fs-exists-cached": "^1.0.0", + "gatsby-core-utils": "^1.0.19", "glob": "^7.1.6", "lodash": "^4.17.15", - "micromatch": "^3.1.10", - "slash": "^3.0.0" + "micromatch": "^3.1.10" }, "devDependencies": { "@babel/cli": "^7.7.0", diff --git a/packages/gatsby-page-utils/src/watch-directory.js b/packages/gatsby-page-utils/src/watch-directory.js index 27a2b6a74a826..98678f2834ec3 100644 --- a/packages/gatsby-page-utils/src/watch-directory.js +++ b/packages/gatsby-page-utils/src/watch-directory.js @@ -1,6 +1,6 @@ const Promise = require(`bluebird`) const chokidar = require(`chokidar`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) module.exports = async (path, glob, onNewFile, onRemovedFile) => new Promise((resolve, reject) => { diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-loader.js b/packages/gatsby-plugin-mdx/loaders/mdx-loader.js index 0f098f9f17018..2baa2ddfa2668 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-loader.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-loader.js @@ -21,7 +21,7 @@ const genMdx = require(`../utils/gen-mdx`) const withDefaultOptions = require(`../utils/default-options`) const createMDXNode = require(`../utils/create-mdx-node`) const { createFileNode } = require(`../utils/create-fake-file-node`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const DEFAULT_OPTIONS = { footnotes: true, diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js b/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js index b002a5951a305..085e82940caa7 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js @@ -1,6 +1,6 @@ const fs = require(`fs`) const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const loaderUtils = require(`loader-utils`) const { MDX_SCOPES_LOCATION } = require(`../constants`) diff --git a/packages/gatsby-plugin-mdx/package.json b/packages/gatsby-plugin-mdx/package.json index e968cd21daf80..e1292b893fc22 100644 --- a/packages/gatsby-plugin-mdx/package.json +++ b/packages/gatsby-plugin-mdx/package.json @@ -33,6 +33,7 @@ "escape-string-regexp": "^1.0.5", "eval": "^0.1.4", "fs-extra": "^8.1.0", + "gatsby-core-utils": "^1.0.19", "gray-matter": "^4.0.2", "json5": "^2.1.1", "loader-utils": "^1.2.3", @@ -45,7 +46,6 @@ "remark": "^10.0.1", "remark-retext": "^3.1.3", "retext-english": "^3.0.4", - "slash": "^3.0.0", "static-site-generator-webpack-plugin": "^3.4.2", "style-to-object": "^0.3.0", "underscore.string": "^3.3.5", diff --git a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js index baa7e4ed902b0..5538b8b2cf789 100644 --- a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js +++ b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js @@ -1,4 +1,4 @@ -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const path = require(`path`) const fs = require(`fs`) const mime = require(`mime`) diff --git a/packages/gatsby-plugin-offline/package.json b/packages/gatsby-plugin-offline/package.json index f0154cdd07daa..3aeb663023d80 100644 --- a/packages/gatsby-plugin-offline/package.json +++ b/packages/gatsby-plugin-offline/package.json @@ -9,10 +9,10 @@ "dependencies": { "@babel/runtime": "^7.7.2", "cheerio": "^1.0.0-rc.3", + "gatsby-core-utils": "^1.0.19", "glob": "^7.1.6", "idb-keyval": "^3.2.0", "lodash": "^4.17.15", - "slash": "^3.0.0", "workbox-build": "^4.3.1" }, "devDependencies": { diff --git a/packages/gatsby-plugin-offline/src/gatsby-node.js b/packages/gatsby-plugin-offline/src/gatsby-node.js index 8ac43ecc085d9..daf8559768ffe 100644 --- a/packages/gatsby-plugin-offline/src/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/gatsby-node.js @@ -2,7 +2,7 @@ let fs = require(`fs`) let workboxBuild = require(`workbox-build`) const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const glob = require(`glob`) const _ = require(`lodash`) diff --git a/packages/gatsby-remark-images/package.json b/packages/gatsby-remark-images/package.json index a5bb75092b157..563f2776030e6 100644 --- a/packages/gatsby-remark-images/package.json +++ b/packages/gatsby-remark-images/package.json @@ -10,12 +10,12 @@ "@babel/runtime": "^7.7.2", "chalk": "^2.4.2", "cheerio": "^1.0.0-rc.3", + "gatsby-core-utils": "^1.0.19", "is-relative-url": "^3.0.0", "lodash": "^4.17.15", "mdast-util-definitions": "^1.2.5", "potrace": "^2.1.2", "query-string": "^6.8.3", - "slash": "^3.0.0", "unist-util-select": "^1.5.0", "unist-util-visit-parents": "^2.1.2" }, diff --git a/packages/gatsby-remark-images/src/index.js b/packages/gatsby-remark-images/src/index.js index 61e9521c9760e..022b171190b50 100644 --- a/packages/gatsby-remark-images/src/index.js +++ b/packages/gatsby-remark-images/src/index.js @@ -13,7 +13,7 @@ const _ = require(`lodash`) const { fluid, stats, traceSVG } = require(`gatsby-plugin-sharp`) const Promise = require(`bluebird`) const cheerio = require(`cheerio`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const chalk = require(`chalk`) // If the image is relative (not hosted elsewhere) diff --git a/packages/gatsby-source-filesystem/src/__tests__/utils.js b/packages/gatsby-source-filesystem/src/__tests__/utils.js index e679448b2490f..9742a28be1733 100644 --- a/packages/gatsby-source-filesystem/src/__tests__/utils.js +++ b/packages/gatsby-source-filesystem/src/__tests__/utils.js @@ -4,7 +4,6 @@ const { getRemoteFileExtension, getRemoteFileName, createProgress, - slash, } = require(`../utils`) const reporter = require(`gatsby-cli/lib/reporter`) const progress = require(`progress`) @@ -62,21 +61,3 @@ describe(`createProgress`, () => { expect(bar).toHaveProperty(`total`) }) }) - -describe(`slash path`, () => { - it(`can correctly slash path`, () => { - ;[ - [`foo\\bar`, `foo/bar`], - [`foo/bar`, `foo/bar`], - [`foo\\中文`, `foo/中文`], - [`foo/中文`, `foo/中文`], - ].forEach(([path, expectRes]) => { - expect(slash(path)).toBe(expectRes) - }) - }) - - it(`does not modify extended length paths`, () => { - const extended = `\\\\?\\some\\path` - expect(slash(extended)).toBe(extended) - }) -}) diff --git a/packages/gatsby-source-filesystem/src/create-file-node.js b/packages/gatsby-source-filesystem/src/create-file-node.js index d9eeef8f9cca3..b3b5f3f03b8ff 100644 --- a/packages/gatsby-source-filesystem/src/create-file-node.js +++ b/packages/gatsby-source-filesystem/src/create-file-node.js @@ -1,11 +1,10 @@ -const { slash } = require(`./utils`) const path = require(`path`) const fs = require(`fs-extra`) const mime = require(`mime`) const prettyBytes = require(`pretty-bytes`) const md5File = require(`bluebird`).promisify(require(`md5-file`)) -const { createContentDigest } = require(`gatsby-core-utils`) +const { createContentDigest, slash } = require(`gatsby-core-utils`) exports.createFileNode = async ( pathToFile, diff --git a/packages/gatsby-source-filesystem/src/create-file-path.js b/packages/gatsby-source-filesystem/src/create-file-path.js index 2d72d3a8e9682..82af14d2e5b14 100644 --- a/packages/gatsby-source-filesystem/src/create-file-path.js +++ b/packages/gatsby-source-filesystem/src/create-file-path.js @@ -1,5 +1,5 @@ const path = require(`path`) -const { slash } = require(`./utils`) +const { slash } = require(`gatsby-core-utils`) function findFileNode({ node, getNode }) { // Find the file node. diff --git a/packages/gatsby-source-filesystem/src/utils.js b/packages/gatsby-source-filesystem/src/utils.js index b2b86f0c677c8..2ba3f7e392cf8 100644 --- a/packages/gatsby-source-filesystem/src/utils.js +++ b/packages/gatsby-source-filesystem/src/utils.js @@ -68,25 +68,6 @@ export function createProgress(message, reporter) { } } -/** - * 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) - - if (isExtendedLengthPath) { - return path - } - - return path.replace(/\\/g, `/`) -} - /** * createFilePath * -- diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index d413bf2e0df71..09db65fda2425 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -121,7 +121,7 @@ "shallow-compare": "^1.2.2", "sift": "^5.1.0", "signal-exit": "^3.0.2", - "slash": "^3.0.0", + "slugify": "^1.3.6", "socket.io": "^2.3.0", "stack-trace": "^0.0.10", "string-similarity": "^1.2.2", diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index abcb0953eb239..1fc5bd4abcc21 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -1,7 +1,7 @@ /* @flow */ const _ = require(`lodash`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const fs = require(`fs-extra`) const md5File = require(`md5-file/promise`) const crypto = require(`crypto`) diff --git a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.js b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.js index 6d7ee95ced595..598eb580ab436 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.js +++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.js @@ -1,5 +1,5 @@ const loadPlugins = require(`../index`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) describe(`Load plugins`, () => { /** diff --git a/packages/gatsby/src/bootstrap/load-plugins/load.js b/packages/gatsby/src/bootstrap/load-plugins/load.js index ff4fa2ffa66e3..78ec99f3107ff 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/load.js +++ b/packages/gatsby/src/bootstrap/load-plugins/load.js @@ -1,5 +1,5 @@ const _ = require(`lodash`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const fs = require(`fs`) const path = require(`path`) const crypto = require(`crypto`) diff --git a/packages/gatsby/src/bootstrap/requires-writer.js b/packages/gatsby/src/bootstrap/requires-writer.js index 92932994f4f53..039baad602745 100644 --- a/packages/gatsby/src/bootstrap/requires-writer.js +++ b/packages/gatsby/src/bootstrap/requires-writer.js @@ -2,7 +2,7 @@ const _ = require(`lodash`) const path = require(`path`) const fs = require(`fs-extra`) const crypto = require(`crypto`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const { store, emitter } = require(`../redux/`) const reporter = require(`gatsby-cli/lib/reporter`) const { match } = require(`@reach/router/lib/utils`) diff --git a/packages/gatsby/src/commands/develop.js b/packages/gatsby/src/commands/develop.js index 76c619dfb9e33..20871e5e0c916 100644 --- a/packages/gatsby/src/commands/develop.js +++ b/packages/gatsby/src/commands/develop.js @@ -32,7 +32,7 @@ const withResolverContext = require(`../schema/context`) const sourceNodes = require(`../utils/source-nodes`) const websocketManager = require(`../utils/websocket-manager`) const getSslCert = require(`../utils/get-ssl-cert`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const { initTracer } = require(`../utils/tracer`) const apiRunnerNode = require(`../utils/api-runner-node`) const db = require(`../db`) diff --git a/packages/gatsby/src/query/__tests__/__snapshots__/file-parser.js.snap b/packages/gatsby/src/query/__tests__/__snapshots__/file-parser.js.snap index 0e8c40940f872..0175ac0532cd2 100644 --- a/packages/gatsby/src/query/__tests__/__snapshots__/file-parser.js.snap +++ b/packages/gatsby/src/query/__tests__/__snapshots__/file-parser.js.snap @@ -1433,6 +1433,130 @@ query { ], "kind": "Document", }, + "ж-ä-!@#$%^&*()_-=+:;'\\"?,~\`.js" => Object { + "definitions": Array [ + Object { + "directives": Array [], + "hash": 1646962495, + "isHook": true, + "isStaticQuery": true, + "kind": "OperationDefinition", + "loc": Object { + "end": 13, + "start": 0, + }, + "name": Object { + "kind": "Name", + "value": "zhADollarpercentandJs1646962495", + }, + "operation": "query", + "selectionSet": Object { + "kind": "SelectionSet", + "loc": Object { + "end": 13, + "start": 6, + }, + "selections": Array [ + Object { + "alias": undefined, + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "loc": Object { + "end": 11, + "start": 8, + }, + "name": Object { + "kind": "Name", + "loc": Object { + "end": 11, + "start": 8, + }, + "value": "foo", + }, + "selectionSet": undefined, + }, + ], + }, + "templateLoc": SourceLocation { + "end": Position { + "column": 51, + "line": 3, + }, + "filename": true, + "start": Position { + "column": 38, + "line": 3, + }, + }, + "text": "query { foo }", + "variableDefinitions": Array [], + }, + ], + "kind": "Document", + }, + "static-ж-ä-!@#$%^&*()_-=+:;'\\"?,~\`.js" => Object { + "definitions": Array [ + Object { + "directives": Array [], + "hash": 1646962495, + "isHook": false, + "isStaticQuery": true, + "kind": "OperationDefinition", + "loc": Object { + "end": 13, + "start": 0, + }, + "name": Object { + "kind": "Name", + "value": "staticZhADollarpercentandJs1646962495", + }, + "operation": "query", + "selectionSet": Object { + "kind": "SelectionSet", + "loc": Object { + "end": 13, + "start": 6, + }, + "selections": Array [ + Object { + "alias": undefined, + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "loc": Object { + "end": 11, + "start": 8, + }, + "name": Object { + "kind": "Name", + "loc": Object { + "end": 11, + "start": 8, + }, + "value": "foo", + }, + "selectionSet": undefined, + }, + ], + }, + "templateLoc": SourceLocation { + "end": Position { + "column": 32, + "line": 4, + }, + "filename": true, + "start": Position { + "column": 19, + "line": 4, + }, + }, + "text": "query { foo }", + "variableDefinitions": Array [], + }, + ], + "kind": "Document", + }, } `; diff --git a/packages/gatsby/src/query/__tests__/file-parser.js b/packages/gatsby/src/query/__tests__/file-parser.js index 68c5e776cad81..fec286db3ce15 100644 --- a/packages/gatsby/src/query/__tests__/file-parser.js +++ b/packages/gatsby/src/query/__tests__/file-parser.js @@ -12,6 +12,8 @@ const fs = require(`fs-extra`) const FileParser = require(`../file-parser`).default +const specialChars = `ж-ä-!@#$%^&*()_-=+:;'"?,~\`` + describe(`File parser`, () => { const MOCK_FILE_INFO = { "no-query.js": `import React from "react"`, @@ -182,6 +184,18 @@ export default () => { const data = useStaticQuery(strangeQueryName); return
{data.pizza}
; }`, + [`${specialChars}.js`]: `import { graphql, useStaticQuery } from 'gatsby' +export default () => { + const data = useStaticQuery(graphql\`query { foo }\`); + return
{data.doo}
; +}`, + [`static-${specialChars}.js`]: `import { graphql } from 'gatsby' + export default () => ( +
{data.doo}
} + /> +)`, } const parser = new FileParser() @@ -200,4 +214,20 @@ export default () => { expect(results).toMatchSnapshot() expect(reporter.warn).toMatchSnapshot() }) + + it(`generates spec-compliant query names out of path`, async () => { + const ast = await parser.parseFile(`${specialChars}.js`, jest.fn()) + const nameNode = ast.definitions[0].name + expect(nameNode).toEqual({ + kind: `Name`, + value: `zhADollarpercentandJs1646962495`, + }) + + const ast2 = await parser.parseFile(`static-${specialChars}.js`, jest.fn()) + const nameNode2 = ast2.definitions[0].name + expect(nameNode2).toEqual({ + kind: `Name`, + value: `staticZhADollarpercentandJs1646962495`, + }) + }) }) diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index 8b6f035a6fb8d..1bcd5dbbc61a2 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -2,6 +2,7 @@ const fs = require(`fs-extra`) const crypto = require(`crypto`) const _ = require(`lodash`) +const slugify = require(`slugify`) // Traverse is a es6 module... import traverse from "@babel/traverse" @@ -26,8 +27,12 @@ import { locInGraphQlToLocInFile } from "./error-parser" */ const generateQueryName = ({ def, hash, file }) => { if (!def.name || !def.name.value) { + const slugified = slugify(file, { + replacement: ` `, + lower: false, + }) def.name = { - value: `${_.camelCase(file)}${hash}`, + value: `${_.camelCase(slugified)}${hash}`, kind: `Name`, } } diff --git a/packages/gatsby/src/query/query-watcher.js b/packages/gatsby/src/query/query-watcher.js index 43882c565c7f1..e500bbcc2b9f7 100644 --- a/packages/gatsby/src/query/query-watcher.js +++ b/packages/gatsby/src/query/query-watcher.js @@ -12,7 +12,7 @@ const _ = require(`lodash`) const chokidar = require(`chokidar`) const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const { store, emitter } = require(`../redux/`) const { boundActionCreators } = require(`../redux/actions`) diff --git a/packages/gatsby/src/redux/actions/public.js b/packages/gatsby/src/redux/actions/public.js index 4d90c97d250aa..246234ffc84e1 100644 --- a/packages/gatsby/src/redux/actions/public.js +++ b/packages/gatsby/src/redux/actions/public.js @@ -9,7 +9,7 @@ const path = require(`path`) const fs = require(`fs`) const { trueCasePathSync } = require(`true-case-path`) const url = require(`url`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const { hasNodeChanged, getNode } = require(`../../db/nodes`) const sanitizeNode = require(`../../db/sanitize-node`) const { store } = require(`..`) @@ -24,8 +24,11 @@ const { getNonGatsbyCodeFrame } = require(`../../utils/stack-trace-utils`) const actions = {} const isWindows = platform() === `win32` -function getRelevantFilePathSegments(filePath) { - return filePath.split(`/`).filter(s => s !== ``) +const ensureWindowsDriveIsUppercase = filePath => { + const segments = filePath.split(`:`).filter(s => s !== ``) + return segments.length > 0 + ? segments.shift().toUpperCase() + `:` + segments.join(`:`) + : filePath } const findChildren = initialChildren => { @@ -291,9 +294,7 @@ ${reservedFields.map(f => ` * "${f}"`).join(`\n`)} } if (isWindows) { - const segments = getRelevantFilePathSegments(page.component) - page.component = - segments.shift().toUpperCase() + `/` + segments.join(`/`) + page.component = ensureWindowsDriveIsUppercase(page.component) } if (trueComponentPath !== page.component) { diff --git a/packages/gatsby/src/schema/__tests__/kitchen-sink.js b/packages/gatsby/src/schema/__tests__/kitchen-sink.js index 793f3dbe3e445..42cbf47cac364 100644 --- a/packages/gatsby/src/schema/__tests__/kitchen-sink.js +++ b/packages/gatsby/src/schema/__tests__/kitchen-sink.js @@ -14,7 +14,7 @@ const { actions } = require(`../../redux/actions`) const { build } = require(`../index`) const fs = require(`fs-extra`) const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const withResolverContext = require(`../context`) require(`../../db/__tests__/fixtures/ensure-loki`)() diff --git a/packages/gatsby/src/schema/__tests__/queries-file.js b/packages/gatsby/src/schema/__tests__/queries-file.js index e049df37d1147..53a7474d01048 100644 --- a/packages/gatsby/src/schema/__tests__/queries-file.js +++ b/packages/gatsby/src/schema/__tests__/queries-file.js @@ -5,7 +5,7 @@ const { build } = require(`..`) const withResolverContext = require(`../context`) require(`../../db/__tests__/fixtures/ensure-loki`)() const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const basePath = slash(__dirname) const filePath = p => slash(path.join(basePath, p)) diff --git a/packages/gatsby/src/schema/infer/__tests__/infer.js b/packages/gatsby/src/schema/infer/__tests__/infer.js index 8eca8a8bd84a4..a21fdb0de05f3 100644 --- a/packages/gatsby/src/schema/infer/__tests__/infer.js +++ b/packages/gatsby/src/schema/infer/__tests__/infer.js @@ -3,7 +3,7 @@ const { graphql } = require(`graphql`) const nodeStore = require(`../../../db/nodes`) const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const { store } = require(`../../../redux`) const { actions } = require(`../../../redux/actions`) const { buildSchema } = require(`../../schema`) diff --git a/packages/gatsby/src/schema/infer/is-file.js b/packages/gatsby/src/schema/infer/is-file.js index eb2e671a11600..9ed698f838253 100644 --- a/packages/gatsby/src/schema/infer/is-file.js +++ b/packages/gatsby/src/schema/infer/is-file.js @@ -1,5 +1,5 @@ const path = require(`path`) -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const mime = require(`mime`) const isRelative = require(`is-relative`) const isRelativeUrl = require(`is-relative-url`) diff --git a/packages/gatsby/src/utils/tracer/index.js b/packages/gatsby/src/utils/tracer/index.js index 33cb4ca067fbf..b469d2a191e59 100644 --- a/packages/gatsby/src/utils/tracer/index.js +++ b/packages/gatsby/src/utils/tracer/index.js @@ -1,4 +1,4 @@ -const slash = require(`slash`) +const { slash } = require(`gatsby-core-utils`) const path = require(`path`) const opentracing = require(`opentracing`) diff --git a/yarn.lock b/yarn.lock index 4db3de2fe6a4c..0a0be0f60de44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19407,6 +19407,11 @@ slide@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" +slugify@^1.3.6: + version "1.3.6" + resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.3.6.tgz#ba5fd6159b570fe4811d02ea9b1f4906677638c3" + integrity sha512-wA9XS475ZmGNlEnYYLPReSfuz/c3VQsEMoU43mi6OnKMCdbnFXd4/Yg7J0lBv8jkPolacMpOrWEaoYxuE1+hoQ== + smart-buffer@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.0.1.tgz#07ea1ca8d4db24eb4cac86537d7d18995221ace3"