Skip to content

Commit ef9d8c8

Browse files
fix deterministic SER tooling client builds
1 parent 900986e commit ef9d8c8

6 files changed

Lines changed: 112 additions & 82 deletions

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Normalize text in the repository while preserving binary assets.
22
* text=auto
3+
.gitattributes text eol=lf
34

45
*.cs text eol=crlf
56
*.csproj text eol=crlf
@@ -14,6 +15,7 @@
1415
*.jsx text eol=lf
1516
*.css text eol=lf
1617
*.html text eol=lf
18+
*.svg text eol=lf
1719

1820
*.dll binary
1921
*.exe binary

Tooling/scripts/manifest.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import fs from "node:fs";
22

3+
export function normalizeManifestLineEndings(value) {
4+
if (typeof value === "string") return value.replace(/\r\n?/g, "\n");
5+
if (Array.isArray(value)) return value.map(normalizeManifestLineEndings);
6+
if (value && typeof value === "object") {
7+
return Object.fromEntries(
8+
Object.entries(value).map(([key, child]) => [key, normalizeManifestLineEndings(child)])
9+
);
10+
}
11+
return value;
12+
}
13+
314
export function readGeneratedManifest(manifestPath) {
415
const source = fs.readFileSync(manifestPath, "utf8");
516
const match = source.match(
@@ -8,7 +19,7 @@ export function readGeneratedManifest(manifestPath) {
819
if (!match) {
920
throw new Error(`Could not read SER_TRUTH_TABLE from ${manifestPath}`);
1021
}
11-
const manifest = JSON.parse(match[1]);
22+
const manifest = normalizeManifestLineEndings(JSON.parse(match[1]));
1223
if (!manifest.methods || !manifest.keywords || !manifest.flags) {
1324
throw new Error("The generated SER manifest is missing required sections.");
1425
}

Tooling/tests/manifest.test.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import { normalizeManifestLineEndings } from "../scripts/manifest.mjs";
4+
5+
test("normalizes generated manifest line endings recursively", () => {
6+
const manifest = {
7+
description: "first\r\nsecond",
8+
methods: [{ example: "one\rtwo\nthree" }],
9+
flags: { OnEvent: { description: "alpha\r\nbeta" } }
10+
};
11+
12+
assert.deepEqual(normalizeManifestLineEndings(manifest), {
13+
description: "first\nsecond",
14+
methods: [{ example: "one\ntwo\nthree" }],
15+
flags: { OnEvent: { description: "alpha\nbeta" } }
16+
});
17+
});

0 commit comments

Comments
 (0)