-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
swc.minify with sourcemap issue #10108
Comments
Maybe you can replace all |
Yes, that's what I did and it works. Though, as you can see on the CI there is one file that compiles with a different sourcemap "hash" when compiled with Windows or Linux. This one I can't fix. I'm not sure if the issue comes from Thanks for the answer. |
So when I say a different hash it is this part of the sourcemap which is different:
And after debugging the output.map, the issue for the So something in swc when generating these sourcemaps is using something like "newline" while it should explicitly be |
If the original file contains |
While you are cloning files, |
We did that and it did not work. Because these are "litteral" |
Can you reproduce it in playground or provide a minimal reproduction? |
Well playground would compile only on Linux I'd guess. Best repro is pulling that branch and running |
Solution was to use: let reader = await fs.readFile(file, "utf8");
await swc.minify(reader.replace(/(\r?\n|\r)/gm, "\n"), { // Here is the main fix
compress: true,
sourceMap: mode === "production",
}).then((output) => {
const minifiedTarget = path.join(dest, path.parse(target).name + ".min.js");
fs.outputFile(minifiedTarget, output.code);
console.log(`Minified (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(minifiedTarget));
if (mode === "production" && output.map) {
const mappedTarget = path.join(dest, path.parse(target).name + ".map");
const normalized = output.map.replace(/(?:\\[rn])+/g, "\\n"); // Still needed to keep this one
fs.outputFile(mappedTarget, normalized + "\n");
console.log(`Mapped (${chalk.gray("from")}, ${chalk.cyan("to")})`, chalk.gray(file), chalk.cyan(mappedTarget));
}
}); So, the fs.readFile on Windows will return a reader that has \r\n chars in it. I needed to convert these to \n so that the .map file generated be consistent between different OS. Maybe an option on SWC compiler to convert these string to normalized X newline string of your choice. |
Describe the bug
I am using swc.minify() API method to minify files.
Though, the sourcemap generated is different when used under Windows or under Linux.
Also, the .map files generates with
\r\n
newlines on Windows and\n
newlines on Linux.I needed to add code to rewrite the files with
\n
which is an ugly patch for now.But the main issue is that the .map files are generated with different output when minified under Windows vs Linux.
Input code
You can find the code used here: https://github.com/OrchardCMS/OrchardCore/blob/main/.scripts/assets-manager/min.mjs
Config
Playground link (or link to the minimal reproduction)
OrchardCMS/OrchardCore#17533
SWC Info output
No response
Expected behavior
Should output the same from Windows or Linux
Actual behavior
No response
Version
1.11.1
Additional context
No response
The text was updated successfully, but these errors were encountered: