-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
152 lines (137 loc) · 3.7 KB
/
build.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const { build, transform } = require("esbuild");
const path = require("path");
const rimraf = require("rimraf");
const fs = require("fs");
const defaultExternals = Object.keys(require("./package.json").dependencies)
.concat(Object.keys(require("./package.json").devDependencies))
.concat(Object.keys(require("./package.json").optionalDependencies));
if (defaultExternals.includes("es-module-lexer")) {
defaultExternals.splice(defaultExternals.indexOf("es-module-lexer"), 1);
}
const indexExternals = [...defaultExternals];
const decoratorsExternals = [...defaultExternals];
async function run() {
console.log("Starting...");
rimraf.sync("./index.js");
rimraf.sync("./index.mjs");
rimraf.sync("./decorators.js");
rimraf.sync("./decorators.mjs");
rimraf.sync("./*.map");
rimraf.sync("./*.d.ts");
const index = path.join(__dirname, "index.ts");
const dec = path.join(__dirname, "index.ts");
await build({
platform: "node",
entryPoints: [index],
minify: false,
minifySyntax: true,
outfile: "index.js",
format: "cjs",
bundle: true,
sourcemap: "both",
external: indexExternals,
});
console.log("Built index.js");
await build({
platform: "node",
entryPoints: [index],
outfile: "index.mjs",
minify: false,
minifySyntax: true,
format: "esm",
bundle: true,
external: indexExternals,
outExtension: {
".js": ".mjs",
},
sourcemap: "both",
});
console.log("Built index.mjs");
await build({
platform: "node",
entryPoints: [dec],
outfile: "decorators.js",
minify: false,
bundle: true,
minifySyntax: true,
external: decoratorsExternals,
format: "cjs",
sourcemap: "both",
});
console.log("Built decorators.js");
await build({
platform: "node",
bundle: true,
entryPoints: [dec],
outfile: "decorators.mjs",
external: decoratorsExternals,
minify: false,
minifySyntax: true,
format: "esm",
outExtension: {
".js": ".mjs",
},
sourcemap: "both",
});
console.log("Built decorators.mjs");
console.log("Built decky lib!");
// process.env.DECKY_VERBOSE = false;
process.env.DECKY_TIMINGS = "true";
require("rimraf").sync("./examples/**.js");
require("rimraf").sync("./examples/**.json");
const { load } = require("./index.js");
console.log("Building example decorators...");
const plugin = await load();
for (let entryPoint of [
"./examples/JSONSchema.ts",
"./examples/Person-GraphQL.ts",
"./examples/debugOnlyExample.ts",
]) {
let test = entryPoint.replace(".ts", ".js");
await build({
platform: "node",
entryPoints: [entryPoint],
outfile: test,
minify: false,
minifySyntax: true,
format: "cjs",
sourcemap: "both",
plugins: [plugin],
});
let snapshot = entryPoint.replace(".ts", ".orig.js");
await build({
platform: "node",
entryPoints: [entryPoint.replace(".ts", ".orig.ts")],
outfile: snapshot,
minify: false,
minifySyntax: true,
format: "cjs",
sourcemap: "both",
plugins: [],
});
const testCode = (
await transform(await fs.promises.readFile(test, "utf8"), {
minify: true,
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: true,
})
).code;
const snapshotCode = (
await transform(await fs.promises.readFile(snapshot, "utf8"), {
minify: true,
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: true,
})
).code;
console.assert(
testCode === snapshotCode,
"expected snapshot to match test for",
entryPoint,
"but received",
{ testCode, snapshotCode }
);
}
}
run();