-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgenerate-baseline.mjs
More file actions
81 lines (66 loc) · 2.35 KB
/
generate-baseline.mjs
File metadata and controls
81 lines (66 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import shell from "shelljs";
import deepmerge from "deepmerge";
import fs from "node:fs/promises";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { objectSort } from "./dump-utils.mjs";
import { ignoredModules } from "./report/src/ignored-modules.js";
shell.set("-e");
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
if (!shell.env.FNM_DIR) {
console.error(
"You must have FNM installed to continue. Refer to README.md for instructions."
);
process.exit(1);
}
// shelljs doesn't read from .bashrc or .zshrc which normally inject FNM_DIR
// into your PATH variable, so a lookup is needed.
// Trailing space is intentional, for DX
const fnm = `${shell.env.FNM_DIR}/fnm `;
// Node
const nodeVersions = [20, 22, 24];
for (const version of nodeVersions) {
shell.echo(`Generate node v${version} apis...`);
shell.exec(fnm + `exec --using=${version} node node/dump.mjs`);
shell.echo("=== Done ====================================\n\n");
}
shell.echo("Generating baseline.json");
// Create a merged baseline that will be used in the report
// as well as when generating bun and deno
const node20 = JSON.parse(shell.cat("data/node-20.json"));
const node22 = JSON.parse(shell.cat("data/node-22.json"));
const node24 = JSON.parse(shell.cat("data/node-24.json"));
// Sort the baseline by key name
const baseline = objectSort(deepmerge.all([node20, node22, node24]));
for (const module of ignoredModules) {
delete baseline[module];
}
// We remove everything that starts with an underscore since they're internal APIs
// that we are not targeting at the moment.
function removeUnderscoreProperties(obj) {
if (typeof obj !== "object" || obj === null) {
return obj;
}
for (const key of Object.keys(obj)) {
if (key.startsWith("_")) {
delete obj[key];
} else if (typeof obj[key] === "object" && obj[key] !== null) {
removeUnderscoreProperties(obj[key]);
}
}
return obj;
}
for (const mod of Object.keys(baseline)) {
if (mod.startsWith("_")) {
delete baseline[mod];
continue;
}
removeUnderscoreProperties(baseline[mod]);
}
// Retain a copy of the baseline in the `node` folder for bun and deno
await fs.writeFile(
path.join(__dirname, "data", "baseline.json"),
JSON.stringify(baseline, null, 2)
);
shell.echo("=== Done ====================================\n\n");