/
index.js
73 lines (63 loc) · 1.83 KB
/
index.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
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
import { fileURLToPath } from "node:url";
import path from "node:path";
import fs from "node:fs/promises";
import webpack from "webpack";
import { DIST_DIR } from "../../../scripts/utils/index.mjs";
function runWebpack(config) {
return new Promise((resolve, reject) => {
webpack(config, (error, stats) => {
if (error) {
reject(error);
return;
}
if (stats.hasErrors()) {
const { errors } = stats.toJson();
const error = new Error(errors[0].message);
error.errors = errors;
reject(error);
return;
}
resolve(stats);
});
});
}
const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url));
/* `require` in `parser-typescript.js`, #12338 */
(async () => {
const esmFilesDirectory = path.join(DIST_DIR, "esm");
const files = [
(await fs.readdir(DIST_DIR))
.filter(
(name) =>
name.startsWith("parser-") ||
name === "standalone.js" ||
name === "doc.js"
)
.map((name) => ({ name, file: path.join(DIST_DIR, name) })),
(await fs.readdir(esmFilesDirectory)).map((name) => ({
displayName: `esm/${name}`,
name,
file: path.join(esmFilesDirectory, name),
})),
].flat();
for (const { displayName, name, file } of files) {
console.log(`${displayName || name}: `);
const stats = await runWebpack({
mode: "production",
entry: file,
output: {
path: TEMPORARY_DIRECTORY,
filename: `${name}.[contenthash:7].js`,
},
performance: { hints: false },
optimization: { minimize: false },
});
const result = stats.toJson();
const { warnings } = result;
if (warnings.length > 0) {
console.log(warnings);
throw new Error("Unexpected webpack warning.");
}
console.log(" Passed.");
}
})();