From 749738cdac34747e4677fb4556ce0d6092545846 Mon Sep 17 00:00:00 2001 From: veryspry Date: Thu, 4 Nov 2021 13:44:43 -0500 Subject: [PATCH] feat: replace all invalid Windows file path chars when creating node manifest files --- packages/gatsby/src/utils/node-manifest.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/gatsby/src/utils/node-manifest.ts b/packages/gatsby/src/utils/node-manifest.ts index d21651a73c3f1..61ed87b5aba9b 100644 --- a/packages/gatsby/src/utils/node-manifest.ts +++ b/packages/gatsby/src/utils/node-manifest.ts @@ -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(/(?|\|/g, + `-` + ) } + console.log(`manifest file path: ${manifestFilePath}`) + const manifestFileDir = path.dirname(manifestFilePath) await fs.ensureDir(manifestFileDir)