fix(build): preserve native generated-file line endings
Treat CRLF and LF as equivalent when checking committed text artifacts so Windows package lifecycles do not report false drift. When real generated content changes, retain the existing artifact's line-ending convention and cover both check and update behavior with a focused regression test.
This commit is contained in:
1 parent
5970a71824
commit
00a3078148
2 files changed
+38
-2
No files matched your search
@@ -6,6 +6,13 @@ const isMissing = (cause) =>
|
||||
"code" in cause &&
|
||||
cause.code === "ENOENT";
|
||||
|
||||
const normalizeLineEndings = (value) => value.replaceAll("\r\n", "\n");
|
||||
|
||||
const preserveLineEndings = (source, existing) =>
|
||||
existing?.includes("\r\n") === true
|
||||
? normalizeLineEndings(source).replaceAll("\n", "\r\n")
|
||||
: source;
|
||||
|
||||
/** Compare or update one generated text artifact with actionable diagnostics. */
|
||||
export const ensureGeneratedFile = async ({
|
||||
path,
|
||||
@@ -19,11 +26,15 @@ export const ensureGeneratedFile = async ({
|
||||
} catch (cause) {
|
||||
if (!isMissing(cause)) throw cause;
|
||||
}
|
||||
if (existing === source) return { changed: false };
|
||||
if (
|
||||
existing !== undefined &&
|
||||
normalizeLineEndings(existing) === normalizeLineEndings(source)
|
||||
)
|
||||
return { changed: false };
|
||||
if (check)
|
||||
throw new Error(
|
||||
`${path} is missing or stale. Run \`${generateCommand}\` and commit the result.`,
|
||||
);
|
||||
await writeFile(path, source, "utf8");
|
||||
await writeFile(path, preserveLineEndings(source, existing), "utf8");
|
||||
return { changed: true };
|
||||
};
|
||||
Reference in new issue
Block a user