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 749738c
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,19 +249,26 @@ 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 one exception is the comma that is part of the hard disk partition name at the beginning of a file path (i.e. C:).
*
* 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,
`-`
)
}

console.log(`manifest file path: ${manifestFilePath}`)

const manifestFileDir = path.dirname(manifestFilePath)

await fs.ensureDir(manifestFileDir)
Expand Down

0 comments on commit 749738c

Please sign in to comment.