From 9623b4e4156a8a14833867db701366d8bbfb70fb Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Mon, 2 Oct 2023 12:04:33 -0700 Subject: [PATCH] fix: sourcemap takes into account special chars in output file (#7574) --- .changeset/fix-cf-sourcemaps.md | 5 +++++ packages/remix-dev/compiler/server/write.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/fix-cf-sourcemaps.md diff --git a/.changeset/fix-cf-sourcemaps.md b/.changeset/fix-cf-sourcemaps.md new file mode 100644 index 00000000000..164eb7b5561 --- /dev/null +++ b/.changeset/fix-cf-sourcemaps.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +sourcemap takes into account special chars in output file diff --git a/packages/remix-dev/compiler/server/write.ts b/packages/remix-dev/compiler/server/write.ts index d5300452d1b..680b8e8b69f 100644 --- a/packages/remix-dev/compiler/server/write.ts +++ b/packages/remix-dev/compiler/server/write.ts @@ -14,7 +14,7 @@ export async function write( if ([".js", ".cjs", ".mjs"].some((ext) => file.path.endsWith(ext))) { // fix sourceMappingURL to be relative to current path instead of /build let filename = file.path.substring(file.path.lastIndexOf(path.sep) + 1); - let escapedFilename = filename.replace(/\./g, "\\."); + let escapedFilename = filename.replace(/([.[\]])/g, "\\$1"); let pattern = `(//# sourceMappingURL=)(.*)${escapedFilename}`; let contents = Buffer.from(file.contents).toString("utf-8"); contents = contents.replace(new RegExp(pattern), `$1${filename}`);