Skip to content

Commit 749738c

Browse files
committed
feat: replace all invalid Windows file path chars when creating node manifest files
1 parent bb4e2a3 commit 749738c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/gatsby/src/utils/node-manifest.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,26 @@ export async function processNodeManifest(
249249
)
250250

251251
/**
252-
* Commas are considered special characters on Windows and are not valid in file paths with the exception of
253-
* the hard disk partition name at the beginning of a file path (i.e. C:).
252+
* Windows has a handful of special/reserved characters that are not valid in a file path
253+
* @reference https://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os
254+
*
255+
* 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:).
254256
*
255257
* During local development, node manifests can be written to disk but are generally unused as they are only used
256-
* for Content Sync which runs in Gatsby cloud. Gatsby cloud is a Linux environment in which colons are valid in
257-
* filepaths. To avoid errors on Windows, we replace all ":" instances in the filepath (with the exception of the
258+
* for Content Sync which runs in Gatsby Cloud. Gatsby cloud is a Linux environment in which these special chars are valid in
259+
* filepaths. To avoid errors on Windows, we replace all instances of the special chars in the filepath (with the exception of the
258260
* hard disk partition name) with "-" to ensure that local Windows development setups do not break when attempting
259261
* to write one of these manifests to disk.
260262
*/
261263
if (process.platform === `win32`) {
262-
manifestFilePath = manifestFilePath.replace(/(?<!^[A-Za-z]):/g, `-`)
264+
manifestFilePath = manifestFilePath.replace(
265+
/((?<!^[A-Za-z])):|\/|\*|\?|"|<|>|\|/g,
266+
`-`
267+
)
263268
}
264269

270+
console.log(`manifest file path: ${manifestFilePath}`)
271+
265272
const manifestFileDir = path.dirname(manifestFilePath)
266273

267274
await fs.ensureDir(manifestFileDir)

0 commit comments

Comments
 (0)