Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2026-06-25 08:59:19 +08:00
import assert from "node:assert";
import fs from "node:fs";
const packageJsonFile = new URL("../package.json", import.meta.url);
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile));
const argv = process.argv.slice(2);
/** @type {14 | 16 | 18} */
const nodeVersion = Number(argv[1]);
2026-06-25 08:59:19 +08:00
assert.ok(
argv[0] === "--node-version" && Number.isSafeInteger(nodeVersion),
"Expect `--node-version` argument.",
);
2026-06-25 08:59:19 +08:00
assert.ok(
nodeVersion === 14 || nodeVersion === 16 || nodeVersion === 18,
2026-06-25 08:59:19 +08:00
"Unexpected `--node-version`.",
);
2025-09-24 04:31:22 +02:00
/*
Script to get dependencies
2025-09-24 04:31:22 +02:00
```js
console.log(
Array.from(
fs
.readFileSync("./yarn.lock", "utf8")
.matchAll(/"(.*?)@npm:30\.0\.0-alpha\.3[",]/g),
(match) => match[1],
).sort(),
);
2025-09-24 04:31:22 +02:00
```
*/
const jestDependencies = [
"@jest/console",
"@jest/core",
"@jest/environment",
"@jest/expect",
"@jest/expect-utils",
"@jest/fake-timers",
"@jest/globals",
"@jest/reporters",
"@jest/schemas",
"@jest/source-map",
"@jest/test-result",
"@jest/test-sequencer",
"@jest/transform",
// "@jest/types",
"babel-jest",
"babel-plugin-jest-hoist",
"babel-preset-jest",
"diff-sequences",
"expect",
"jest",
"jest-changed-files",
"jest-circus",
"jest-cli",
"jest-config",
"jest-diff",
// "jest-docblock",
"jest-each",
"jest-environment-node",
"jest-get-type",
"jest-haste-map",
"jest-leak-detector",
"jest-matcher-utils",
"jest-message-util",
"jest-mock",
"jest-regex-util",
"jest-resolve",
"jest-resolve-dependencies",
"jest-runner",
"jest-runtime",
"jest-snapshot",
"jest-util",
"jest-validate",
"jest-watcher",
"jest-worker",
"pretty-format",
];
2026-06-25 08:59:19 +08:00
const jestVersion =
nodeVersion === 14
? // `jest@30.0.0-alpha.2` is the last version that supports Node.js v14
"30.0.0-alpha.2"
: nodeVersion === 16
? // `jest@30.0.0-alpha.7` is the last version that supports Node.js v16
"30.0.0-alpha.7"
: undefined;
2026-06-25 08:59:19 +08:00
const jestLightRunnerVersion =
nodeVersion === 14 || nodeVersion === 16
? "0.7.13"
: nodeVersion === 18
? "0.8.1"
: undefined;
2026-09-19 11:05:25 +08:00
const resolutions = { ...packageJson.resolutions };
const devDependencies = { ...packageJson.devDependencies };
if (jestVersion) {
2026-09-19 11:05:25 +08:00
Object.assign(
resolutions,
Object.fromEntries(jestDependencies.map((name) => [name, jestVersion])),
);
}
if (jestLightRunnerVersion) {
2026-09-19 11:05:25 +08:00
devDependencies["jest-light-runner"] = jestLightRunnerVersion;
if (nodeVersion === 18) {
Object.assign(resolutions, {
// Avoid different versions installed
"jest-snapshot": devDependencies.jest,
});
}
}
2026-06-25 08:59:19 +08:00
2026-09-19 11:05:25 +08:00
const content = JSON.stringify(
{ ...packageJson, resolutions, devDependencies },
undefined,
2,
);
2025-09-24 04:31:22 +02:00
fs.writeFileSync(packageJsonFile, content);