Skip to content

Commit

Permalink
fix(gatsby): normalize component path casing (gatsbyjs#12005)
Browse files Browse the repository at this point in the history
* fix(gatsby): verify page template file path casing

* oh, Windows, you are just silly

* chore: update yarn.lock

* add sanity check

* Update packages/gatsby/src/redux/actions.js

Co-Authored-By: pieh <[email protected]>

* Update packages/gatsby/src/redux/actions.js

Co-Authored-By: pieh <[email protected]>
  • Loading branch information
pieh authored and sidharthachatterjee committed Feb 25, 2019
1 parent 8460992 commit 3006163
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"string-similarity": "^1.2.0",
"style-loader": "^0.21.0",
"terser-webpack-plugin": "^1.2.2",
"true-case-path": "^1.0.3",
"type-of": "^2.0.1",
"url-loader": "^1.0.1",
"uuid": "^3.1.0",
Expand Down
42 changes: 39 additions & 3 deletions packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const { stripIndent } = require(`common-tags`)
const report = require(`gatsby-cli/lib/reporter`)
const path = require(`path`)
const fs = require(`fs`)
const truePath = require(`true-case-path`)
const url = require(`url`)
const kebabHash = require(`kebab-hash`)
const slash = require(`slash`)
const { hasNodeChanged, getNode } = require(`../db/nodes`)
const { trackInlineObjectsInRootNode } = require(`../db/node-tracking`)
const { store } = require(`./index`)
Expand Down Expand Up @@ -82,7 +84,8 @@ const pascalCase = _.flow(
_.camelCase,
_.upperFirst
)
const hasWarnedForPageComponent = new Set()
const hasWarnedForPageComponentInvalidContext = new Set()
const hasWarnedForPageComponentInvalidCasing = new Set()
const fileOkCache = {}

/**
Expand Down Expand Up @@ -177,9 +180,9 @@ ${reservedFields.map(f => ` * "${f}"`).join(`\n`)}
} else if (invalidFields.some(f => page.context[f] !== page[f])) {
report.panic(error)
} else {
if (!hasWarnedForPageComponent.has(page.component)) {
if (!hasWarnedForPageComponentInvalidContext.has(page.component)) {
report.warn(error)
hasWarnedForPageComponent.add(page.component)
hasWarnedForPageComponentInvalidContext.add(page.component)
}
}
}
Expand All @@ -195,6 +198,39 @@ ${reservedFields.map(f => ` * "${f}"`).join(`\n`)}
console.log(``)
console.log(page)
noPageOrComponent = true
} else if (page.component) {
// normalize component path
page.component = slash(page.component)
// check if path uses correct casing - incorrect casing will
// cause issues in query compiler and inconsistencies when
// developing on Mac or Windows and trying to deploy from
// linux CI/CD pipeline
const trueComponentPath = slash(truePath(page.component))
if (trueComponentPath !== page.component) {
if (!hasWarnedForPageComponentInvalidCasing.has(page.component)) {
const markers = page.component
.split(``)
.map((letter, index) => {
if (letter !== trueComponentPath[index]) {
return `^`
}
return ` `
})
.join(``)

report.warn(
stripIndent`
${name} created a page with a component path that doesn't match the casing of the actual file. This may work locally, but will break on systems which are case-sensitive, e.g. most CI/CD pipelines.
page.component: "${page.component}"
path in filesystem: "${trueComponentPath}"
${markers}
`
)
hasWarnedForPageComponentInvalidCasing.add(page.component)
}
page.component = trueComponentPath
}
}
}

Expand Down
60 changes: 37 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-jsx@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.2.0.tgz#0b85a3b4bc7cdf4cc4b8bf236335b907ca22e7c7"
integrity sha512-VyN4QANJkRW6lDBmENzRszvZf3/4AXaj9YR7GwrWeeN9tEBPuXbmDYVU9bYBN0D70zCWVwUy0HWq2553VCb6Hw==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-object-rest-spread@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.0.0.tgz#37d8fbcaf216bd658ea1aebbeb8b75e88ebc549b"
Expand Down Expand Up @@ -942,14 +949,21 @@
follow-redirects "^1.2.5"
is-buffer "^1.1.5"

"@emotion/[email protected]":
version "10.0.5"
resolved "https://registry.yarnpkg.com/@emotion/babel-preset-css-prop/-/babel-preset-css-prop-10.0.5.tgz#955485c6f621247ee35dc1e6bd8fef0ba1d3286f"
integrity sha512-Mf1651pWaqraE2jJdX1/+ArCBLhubxNoNrs0mfYOriIRxwnmjoKQLIEYTMNl/K7ZkIu2PNwvLKGv74fo3wYovA==
"@emotion/babel-plugin-jsx-pragmatic@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@emotion/babel-plugin-jsx-pragmatic/-/babel-plugin-jsx-pragmatic-0.1.0.tgz#fc980ee7f50f7b949ca76b4897e992739076b93d"
integrity sha512-qO0St0wzQ7adbDPl0GzbptNBVg0G773uX4o07sSEzMnlsE+sAZn6CtmDJU69efALHjGfsuOAKhL/zBBEy5JGcA==
dependencies:
"@babel/plugin-syntax-jsx" "^7.2.0"

"@emotion/babel-preset-css-prop@^10.0.5":
version "10.0.7"
resolved "https://registry.yarnpkg.com/@emotion/babel-preset-css-prop/-/babel-preset-css-prop-10.0.7.tgz#ddb57f69ee6a8131f8c9ac4dd68dbec54bd6a6aa"
integrity sha512-GfOJtSm9daEL0KfdWDusy2vTJvXQpO82mTLextuXnTsSFiTaOt7WNP7z3T1onLEHCsgRHTsgjnBHX2qr2oT+yw==
dependencies:
"@babel/plugin-transform-react-jsx" "^7.1.6"
babel-plugin-emotion "^10.0.5"
babel-plugin-jsx-pragmatic "^1.0.2"
"@emotion/babel-plugin-jsx-pragmatic" "^0.1.0"
babel-plugin-emotion "^10.0.7"
object-assign "^4.1.1"

"@emotion/[email protected]":
Expand All @@ -962,10 +976,10 @@
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.1.tgz#e93c13942592cf5ef01aa8297444dc192beee52f"
integrity sha512-Qv4LTqO11jepd5Qmlp3M1YEjBumoTHcHFdgPTQ+sFlIL5myi/7xu/POwP7IRu6odBdmLXdtIs1D6TuW6kbwbbg==

"@emotion/serialize@^0.11.3":
version "0.11.3"
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.3.tgz#c4af2d96e3ddb9a749b7b567daa7556bcae45af2"
integrity sha512-6Q+XH/7kMdHwtylwZvdkOVMydaGZ989axQ56NF7urTR7eiDMLGun//pFUy31ha6QR4C6JB+KJVhZ3AEAJm9Z1g==
"@emotion/serialize@^0.11.4":
version "0.11.4"
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.4.tgz#691e615184a23cd3b9ae9b1eaa79eb8798e52379"
integrity sha512-JKmn+Qnc8f6OZKSHmNq1RpO27raIi6Kj0uqBaSOUVMW6NI0M3wLpV4pK5hZO4I+1WuCC39hOBPgQ/GcgoHbDeg==
dependencies:
"@emotion/hash" "0.7.1"
"@emotion/memoize" "0.7.1"
Expand Down Expand Up @@ -3065,15 +3079,15 @@ babel-plugin-dynamic-import-node@^1.2.0:
dependencies:
babel-plugin-syntax-dynamic-import "^6.18.0"

babel-plugin-emotion@^10.0.5:
version "10.0.5"
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.5.tgz#05ec47cde94f984b0b2aebdd41f81876cf9cbb24"
integrity sha512-ezct2vKACg4juSV0/A/4QIDJu2+5Sjna/8rX/LXY8D0qG8YEP3fu8pe5FqZ9yFGa8WOJ1sivf3/QKM/5C8naIg==
babel-plugin-emotion@^10.0.7:
version "10.0.7"
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.7.tgz#3634ada6dee762140f27db07387feaec8d2cb619"
integrity sha512-5PdLJYme3tFN97M3tBbEUS/rJVkS9EMbo7rs7/7BAUEUVMWehm1kb5DEbp16Rs+UsI3rTXRan1iqpL022T8XxA==
dependencies:
"@babel/helper-module-imports" "^7.0.0"
"@emotion/hash" "0.7.1"
"@emotion/memoize" "0.7.1"
"@emotion/serialize" "^0.11.3"
"@emotion/serialize" "^0.11.4"
babel-plugin-macros "^2.0.0"
babel-plugin-syntax-jsx "^6.18.0"
convert-source-map "^1.5.0"
Expand Down Expand Up @@ -3110,13 +3124,6 @@ babel-plugin-jest-hoist@^24.0.0:
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-24.0.0.tgz#3adf030b6fd67e4311479a54b24077bdfc226ec9"
integrity sha512-ipefE7YWNyRNVaV/MonUb/I5nef53ZRFR74P9meMGmJxqt8s1BJmfhw11YeIMbcjXN4fxtWUaskZZe8yreXE1Q==

babel-plugin-jsx-pragmatic@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/babel-plugin-jsx-pragmatic/-/babel-plugin-jsx-pragmatic-1.0.2.tgz#41e2beb8642235f34b2a7ab12ca39e07201b8e59"
integrity sha1-QeK+uGQiNfNLKnqxLKOeByAbjlk=
dependencies:
babel-plugin-syntax-jsx "^6.0.0"

babel-plugin-lodash@^3.2.11:
version "3.3.4"
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
Expand Down Expand Up @@ -3209,7 +3216,7 @@ babel-plugin-syntax-function-bind@^6.8.0:
resolved "http://registry.npmjs.org/babel-plugin-syntax-function-bind/-/babel-plugin-syntax-function-bind-6.13.0.tgz#48c495f177bdf31a981e732f55adc0bdd2601f46"
integrity sha1-SMSV8Xe98xqYHnMvVa3AvdJgH0Y=

babel-plugin-syntax-jsx@^6.0.0, babel-plugin-syntax-jsx@^6.18.0, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
babel-plugin-syntax-jsx@^6.18.0, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
version "6.18.0"
resolved "http://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
integrity sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY=
Expand Down Expand Up @@ -18983,6 +18990,13 @@ trough@^1.0.0:
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.3.tgz#e29bd1614c6458d44869fc28b255ab7857ef7c24"
integrity sha512-fwkLWH+DimvA4YCy+/nvJd61nWQQ2liO/nF/RjkTpiOGi+zxZzVkhb1mvbHIIW4b/8nDsYI8uTmAlc0nNkRMOw==

"true-case-path@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-1.0.3.tgz#f813b5a8c86b40da59606722b144e3225799f47d"
integrity sha512-m6s2OdQe5wgpFMC+pAJ+q9djG82O2jcHPOI6RNg1yy9rCYR+WD6Nbpl32fDpfC56nirdRy+opFa/Vk7HYhqaew==
dependencies:
glob "^7.1.2"

tsickle@^0.27.2:
version "0.27.5"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.27.5.tgz#41e1a41a5acf971cbb2b0558a9590779234d591f"
Expand Down

0 comments on commit 3006163

Please sign in to comment.