forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry-node16.js
31 lines (26 loc) · 986 Bytes
/
try-node16.js
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
import cp from "child_process";
import fs from "fs";
import path from "path";
import url from "url";
const tsconfigs = process.argv.slice(2);
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
for (const tsconfigPath of tsconfigs) {
const tsconfigString = fs.readFileSync(tsconfigPath, "utf-8");
const tsconfig = JSON.parse(tsconfigString);
if (tsconfig.compilerOptions.module === "node16") {
continue;
}
const newTsconfig = JSON.parse(tsconfigString);
newTsconfig.compilerOptions.module = "node16";
fs.writeFileSync(tsconfigPath, JSON.stringify(newTsconfig, undefined, 4) + "\n", "utf-8");
try {
cp.execFileSync(
path.join(__dirname, "node_modules/.bin/tsc"),
["-p", tsconfigPath, "--noEmit"],
{ stdio: "ignore" },
);
} catch {
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, undefined, 4) + "\n", "utf-8");
console.log(tsconfigPath);
}
}