Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sourcemap takes into account special chars in output file #7574

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-cf-sourcemaps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

sourcemap takes into account special chars in output file
2 changes: 1 addition & 1 deletion packages/remix-dev/compiler/server/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this regex better than the 3-pass replace in #5809, but do we need to also escape the [ in the regex, as suggested in #3768 (comment)?

Suggested change
let escapedFilename = filename.replace(/([.[\]])/g, "\\$1");
let escapedFilename = filename.replace(/([.\[\]])/g, "\\$1");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's inside the existing group, so it's not needed.

let pattern = `(//# sourceMappingURL=)(.*)${escapedFilename}`;
let contents = Buffer.from(file.contents).toString("utf-8");
contents = contents.replace(new RegExp(pattern), `$1${filename}`);
Expand Down