NO-JIRA Make rollup build reproducible across line endings

Normalize CRLF to LF in the rollup load hook so Windows checkouts
produce the same dist bundle and source maps as Linux/macOS.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julien HENRY
2026-05-18 12:52:49 +02:00
parent 9ddabeeb80
commit 305fabb1f1
3 changed files with 17 additions and 3 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -1
View File
@@ -16,9 +16,23 @@
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import { readFileSync } from "node:fs";
import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
// Ensures CRLF line endings from a Windows checkout don't leak into the
// bundle or the source map's sourcesContent, so the build is reproducible
// across operating systems. Uses `load` rather than `transform` so the
// normalized text is also what Rollup embeds in sourcesContent.
const normalizeLineEndings = {
name: "normalize-line-endings",
load(id) {
if (id.startsWith("\0") || id.includes("?")) return null;
const code = readFileSync(id, "utf8");
return code.includes("\r") ? code.replaceAll("\r\n", "\n") : null;
},
};
const config = {
input: [
"src/main/index.js",
@@ -30,7 +44,7 @@ const config = {
format: "es",
sourcemap: true,
},
plugins: [commonjs(), nodeResolve({ preferBuiltins: true })],
plugins: [normalizeLineEndings, commonjs(), nodeResolve({ preferBuiltins: true })],
};
export default config;