Skip to content

Commit

Permalink
feat: replace all invalid Windows file path chars when creating node …
Browse files Browse the repository at this point in the history
…manifest files
  • Loading branch information
veryspry committed Nov 4, 2021
1 parent bb4e2a3 commit 57a733d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/gatsby/src/utils/node-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,24 @@ export async function processNodeManifest(
)

/**
* Commas are considered special characters on Windows and are not valid in file paths with the exception of
* the hard disk partition name at the beginning of a file path (i.e. C:).
* Windows has a handful of special/reserved characters that are not valid in a file path
* @reference https://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os
*
* The two exceptions to the list linked above are
* - the colon that is part of the hard disk partition name at the beginning of a file path (i.e. C:)
* - backslashes. We don't want to replace backslashes because those are used to delineate what the actual file path is
*
* During local development, node manifests can be written to disk but are generally unused as they are only used
* for Content Sync which runs in Gatsby cloud. Gatsby cloud is a Linux environment in which colons are valid in
* filepaths. To avoid errors on Windows, we replace all ":" instances in the filepath (with the exception of the
* for Content Sync which runs in Gatsby Cloud. Gatsby cloud is a Linux environment in which these special chars are valid in
* filepaths. To avoid errors on Windows, we replace all instances of the special chars in the filepath (with the exception of the
* hard disk partition name) with "-" to ensure that local Windows development setups do not break when attempting
* to write one of these manifests to disk.
*/
if (process.platform === `win32`) {
manifestFilePath = manifestFilePath.replace(/(?<!^[A-Za-z]):/g, `-`)
manifestFilePath = manifestFilePath.replace(
/((?<!^[A-Za-z])):|\/|\*|\?|"|<|>|\|/g,
`-`
)
}

const manifestFileDir = path.dirname(manifestFilePath)
Expand Down

0 comments on commit 57a733d

Please sign in to comment.