@storm-software/esbuild 0.4.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build.cjs +15 -11
- package/dist/build.d.cts +3 -3
- package/dist/build.d.ts +3 -3
- package/dist/build.js +14 -10
- package/dist/{chunk-WCQVDF3K.js → chunk-3GQAWCBQ.js} +0 -1
- package/dist/chunk-4JLYXTKD.cjs +26 -0
- package/dist/chunk-5I2MGPRN.cjs +919 -0
- package/dist/{chunk-CMWXE5MF.js → chunk-7KR3YBS6.js} +5 -3
- package/dist/chunk-7MDMXJ5V.js +26 -0
- package/dist/{chunk-WGEGR3DF.cjs → chunk-BGYQAVKQ.cjs} +0 -1
- package/dist/{chunk-J34FQYKV.cjs → chunk-CGFDQ5AJ.cjs} +8 -5
- package/dist/{chunk-TTHABTDU.js → chunk-DAGDNKO5.js} +8 -6
- package/dist/{chunk-DFGHPRBD.cjs → chunk-EZGTDCYM.cjs} +6 -6
- package/dist/chunk-GGNOJ77I.js +0 -0
- package/dist/{chunk-YQBU3FSL.js → chunk-GWG4HOQ6.js} +4 -4
- package/dist/chunk-HQGUIF4U.js +537 -0
- package/dist/{chunk-X5TLV7MF.js → chunk-KE5DL2BG.js} +11 -6
- package/dist/{chunk-KJ7ZHAFS.js → chunk-KOK4WCHS.js} +52 -28
- package/dist/chunk-LVWQSCJM.cjs +26 -0
- package/dist/chunk-LYDEMC26.js +23 -0
- package/dist/chunk-MAMLS55E.js +582 -0
- package/dist/chunk-NVWDQVN6.js +21 -0
- package/dist/chunk-PQ6YIJ72.cjs +136 -0
- package/dist/{chunk-BF5W6GVP.cjs → chunk-RMB62XEL.cjs} +10 -8
- package/dist/chunk-S6M44SSZ.cjs +60 -0
- package/dist/chunk-SFZRYJZ2.cjs +1 -0
- package/dist/chunk-T5272PC2.js +60 -0
- package/dist/chunk-TP5EOMRD.cjs +21 -0
- package/dist/chunk-VBINBV4Z.cjs +537 -0
- package/dist/chunk-VLP3P6HF.js +919 -0
- package/dist/{chunk-KVBDKVBU.cjs → chunk-VZBOWHCM.cjs} +9 -7
- package/dist/chunk-WRBUO7H6.cjs +23 -0
- package/dist/chunk-WYMD6YG2.cjs +582 -0
- package/dist/{chunk-437F3SFI.js → chunk-YNQ45EAM.js} +7 -4
- package/dist/clean.cjs +9 -0
- package/dist/clean.d.cts +1194 -0
- package/dist/clean.d.ts +1194 -0
- package/dist/clean.js +9 -0
- package/dist/config.cjs +14 -4
- package/dist/config.d.cts +8 -13
- package/dist/config.d.ts +8 -13
- package/dist/config.js +15 -5
- package/dist/esbuild.cjs +1185 -0
- package/dist/index.cjs +21 -12
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +22 -13
- package/dist/types.cjs +1 -2
- package/dist/types.d.cts +84 -1177
- package/dist/types.d.ts +84 -1177
- package/dist/types.js +1 -2
- package/package.json +1 -222
- package/dist/build.cjs.map +0 -1
- package/dist/build.js.map +0 -1
- package/dist/chunk-263L44RM.cjs +0 -112
- package/dist/chunk-263L44RM.cjs.map +0 -1
- package/dist/chunk-437F3SFI.js.map +0 -1
- package/dist/chunk-BF5W6GVP.cjs.map +0 -1
- package/dist/chunk-CMEDJ4L4.js +0 -352
- package/dist/chunk-CMEDJ4L4.js.map +0 -1
- package/dist/chunk-CMWXE5MF.js.map +0 -1
- package/dist/chunk-D5PRB2E2.cjs +0 -40
- package/dist/chunk-D5PRB2E2.cjs.map +0 -1
- package/dist/chunk-DFGHPRBD.cjs.map +0 -1
- package/dist/chunk-DRRPNILS.js +0 -40
- package/dist/chunk-DRRPNILS.js.map +0 -1
- package/dist/chunk-J34FQYKV.cjs.map +0 -1
- package/dist/chunk-KJ7ZHAFS.js.map +0 -1
- package/dist/chunk-KVBDKVBU.cjs.map +0 -1
- package/dist/chunk-MUYXFAKB.cjs +0 -1
- package/dist/chunk-MUYXFAKB.cjs.map +0 -1
- package/dist/chunk-MVLEDP7K.cjs +0 -21
- package/dist/chunk-MVLEDP7K.cjs.map +0 -1
- package/dist/chunk-PBHOTQGA.cjs +0 -352
- package/dist/chunk-PBHOTQGA.cjs.map +0 -1
- package/dist/chunk-QNDLJ2W7.js +0 -1
- package/dist/chunk-QNDLJ2W7.js.map +0 -1
- package/dist/chunk-TTHABTDU.js.map +0 -1
- package/dist/chunk-WCQVDF3K.js.map +0 -1
- package/dist/chunk-WGEGR3DF.cjs.map +0 -1
- package/dist/chunk-X5TLV7MF.js.map +0 -1
- package/dist/chunk-YQBU3FSL.js.map +0 -1
- package/dist/config.cjs.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clean
|
|
3
|
+
} from "./chunk-NVWDQVN6.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_BUILD_OPTIONS,
|
|
6
|
+
DEFAULT_COMPILED_BANNER,
|
|
7
|
+
DEFAULT_TARGET,
|
|
8
|
+
addPackageDependencies,
|
|
9
|
+
addPackageJsonExport,
|
|
10
|
+
addWorkspacePackageJsonFields,
|
|
11
|
+
copyAssets,
|
|
12
|
+
getDefaultBuildPlugins,
|
|
13
|
+
getEntryPoints,
|
|
14
|
+
getEnv,
|
|
15
|
+
getOutputExtensionMap,
|
|
16
|
+
loadStormConfig
|
|
17
|
+
} from "./chunk-VLP3P6HF.js";
|
|
18
|
+
import {
|
|
19
|
+
depsCheckPlugin
|
|
20
|
+
} from "./chunk-7KR3YBS6.js";
|
|
21
|
+
import {
|
|
22
|
+
getStopwatch,
|
|
23
|
+
isVerbose,
|
|
24
|
+
writeDebug,
|
|
25
|
+
writeError,
|
|
26
|
+
writeFatal,
|
|
27
|
+
writeSuccess,
|
|
28
|
+
writeTrace,
|
|
29
|
+
writeWarning
|
|
30
|
+
} from "./chunk-HQGUIF4U.js";
|
|
31
|
+
import {
|
|
32
|
+
joinPaths
|
|
33
|
+
} from "./chunk-7MDMXJ5V.js";
|
|
34
|
+
import {
|
|
35
|
+
__name
|
|
36
|
+
} from "./chunk-3GQAWCBQ.js";
|
|
37
|
+
|
|
38
|
+
// src/build.ts
|
|
39
|
+
import { hfs } from "@humanfs/node";
|
|
40
|
+
import { createProjectGraphAsync, readProjectsConfigurationFromProjectGraph, writeJsonFile } from "@nx/devkit";
|
|
41
|
+
import { watch as createWatcher } from "chokidar";
|
|
42
|
+
import defu from "defu";
|
|
43
|
+
import { debounce, flatten } from "es-toolkit";
|
|
44
|
+
import { map } from "es-toolkit/compat";
|
|
45
|
+
import * as esbuild from "esbuild";
|
|
46
|
+
import { globbySync } from "globby";
|
|
47
|
+
import { findWorkspaceRoot } from "nx/src/utils/find-workspace-root";
|
|
48
|
+
|
|
49
|
+
// src/base/renderer-engine.ts
|
|
50
|
+
import path2 from "node:path";
|
|
51
|
+
import { SourceMapConsumer, SourceMapGenerator } from "source-map";
|
|
52
|
+
|
|
53
|
+
// src/utilities/output-file.ts
|
|
54
|
+
import fs from "node:fs";
|
|
55
|
+
import path from "node:path";
|
|
56
|
+
var outputFile = /* @__PURE__ */ __name(async (filepath, data, options) => {
|
|
57
|
+
await fs.promises.mkdir(path.dirname(filepath), {
|
|
58
|
+
recursive: true
|
|
59
|
+
});
|
|
60
|
+
await fs.promises.writeFile(filepath, data, options);
|
|
61
|
+
}, "outputFile");
|
|
62
|
+
|
|
63
|
+
// src/base/renderer-engine.ts
|
|
64
|
+
var parseSourceMap = /* @__PURE__ */ __name((map2) => {
|
|
65
|
+
return typeof map2 === "string" ? JSON.parse(map2) : map2;
|
|
66
|
+
}, "parseSourceMap");
|
|
67
|
+
var isJS = /* @__PURE__ */ __name((path3) => /\.(js|mjs|cjs)$/.test(path3), "isJS");
|
|
68
|
+
var isCSS = /* @__PURE__ */ __name((path3) => /\.css$/.test(path3), "isCSS");
|
|
69
|
+
var getSourcemapComment = /* @__PURE__ */ __name((inline, map2, filepath, isCssFile) => {
|
|
70
|
+
if (!map2) return "";
|
|
71
|
+
const prefix = isCssFile ? "/*" : "//";
|
|
72
|
+
const suffix = isCssFile ? " */" : "";
|
|
73
|
+
const url = inline ? `data:application/json;base64,${Buffer.from(typeof map2 === "string" ? map2 : JSON.stringify(map2)).toString("base64")}` : `${path2.basename(filepath)}.map`;
|
|
74
|
+
return `${prefix}# sourceMappingURL=${url}${suffix}`;
|
|
75
|
+
}, "getSourcemapComment");
|
|
76
|
+
var RendererEngine = class {
|
|
77
|
+
static {
|
|
78
|
+
__name(this, "RendererEngine");
|
|
79
|
+
}
|
|
80
|
+
#renderers;
|
|
81
|
+
#options;
|
|
82
|
+
constructor(renderers) {
|
|
83
|
+
this.#renderers = renderers;
|
|
84
|
+
}
|
|
85
|
+
setOptions(options) {
|
|
86
|
+
this.#options = options;
|
|
87
|
+
}
|
|
88
|
+
getOptions() {
|
|
89
|
+
if (!this.#options) {
|
|
90
|
+
throw new Error(`Renderer options is not set`);
|
|
91
|
+
}
|
|
92
|
+
return this.#options;
|
|
93
|
+
}
|
|
94
|
+
modifyEsbuildOptions(options) {
|
|
95
|
+
for (const renderer of this.#renderers) {
|
|
96
|
+
if (renderer.esbuildOptions) {
|
|
97
|
+
renderer.esbuildOptions.call(this.getOptions(), options);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async buildStarted() {
|
|
102
|
+
for (const renderer of this.#renderers) {
|
|
103
|
+
if (renderer.buildStart) {
|
|
104
|
+
await renderer.buildStart.call(this.getOptions());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async buildFinished({ outputFiles, metafile }) {
|
|
109
|
+
const files = outputFiles.filter((file) => !file.path.endsWith(".map")).map((file) => {
|
|
110
|
+
if (isJS(file.path) || isCSS(file.path)) {
|
|
111
|
+
let relativePath = path2.relative(this.getOptions().config.workspaceRoot, file.path);
|
|
112
|
+
if (!relativePath.startsWith("\\\\?\\")) {
|
|
113
|
+
relativePath = relativePath.replace(/\\/g, "/");
|
|
114
|
+
}
|
|
115
|
+
const meta = metafile?.outputs[relativePath];
|
|
116
|
+
return {
|
|
117
|
+
type: "chunk",
|
|
118
|
+
path: file.path,
|
|
119
|
+
code: file.text,
|
|
120
|
+
map: outputFiles.find((f) => f.path === `${file.path}.map`)?.text,
|
|
121
|
+
entryPoint: meta?.entryPoint,
|
|
122
|
+
exports: meta?.exports,
|
|
123
|
+
imports: meta?.imports
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
return {
|
|
127
|
+
type: "asset",
|
|
128
|
+
path: file.path,
|
|
129
|
+
contents: file.contents
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const writtenFiles = [];
|
|
134
|
+
await Promise.all(files.map(async (info) => {
|
|
135
|
+
for (const renderer of this.#renderers) {
|
|
136
|
+
if (info.type === "chunk" && renderer.renderChunk) {
|
|
137
|
+
const result = await renderer.renderChunk.call(this.getOptions(), info.code, info);
|
|
138
|
+
if (result) {
|
|
139
|
+
info.code = result.code;
|
|
140
|
+
if (result.map) {
|
|
141
|
+
const originalConsumer = await new SourceMapConsumer(parseSourceMap(info.map));
|
|
142
|
+
const newConsumer = await new SourceMapConsumer(parseSourceMap(result.map));
|
|
143
|
+
const generator = SourceMapGenerator.fromSourceMap(newConsumer);
|
|
144
|
+
generator.applySourceMap(originalConsumer, info.path);
|
|
145
|
+
info.map = generator.toJSON();
|
|
146
|
+
originalConsumer.destroy();
|
|
147
|
+
newConsumer.destroy();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const inlineSourceMap = this.#options.sourcemap === "inline";
|
|
153
|
+
const contents = info.type === "chunk" ? info.code + getSourcemapComment(inlineSourceMap, info.map, info.path, isCSS(info.path)) : info.contents;
|
|
154
|
+
await outputFile(info.path, contents, {
|
|
155
|
+
mode: info.type === "chunk" ? info.mode : void 0
|
|
156
|
+
});
|
|
157
|
+
writtenFiles.push({
|
|
158
|
+
get name() {
|
|
159
|
+
return path2.relative(process.cwd(), info.path);
|
|
160
|
+
},
|
|
161
|
+
get size() {
|
|
162
|
+
return contents.length;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
if (info.type === "chunk" && info.map && !inlineSourceMap) {
|
|
166
|
+
const map2 = typeof info.map === "string" ? JSON.parse(info.map) : info.map;
|
|
167
|
+
const outPath = `${info.path}.map`;
|
|
168
|
+
const contents2 = JSON.stringify(map2);
|
|
169
|
+
await outputFile(outPath, contents2);
|
|
170
|
+
writtenFiles.push({
|
|
171
|
+
get name() {
|
|
172
|
+
return path2.relative(process.cwd(), outPath);
|
|
173
|
+
},
|
|
174
|
+
get size() {
|
|
175
|
+
return contents2.length;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
for (const renderer of this.#renderers) {
|
|
181
|
+
if (renderer.buildEnd) {
|
|
182
|
+
await renderer.buildEnd.call(this.getOptions(), {
|
|
183
|
+
writtenFiles
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/renderers/shebang.ts
|
|
191
|
+
var shebangRenderer = {
|
|
192
|
+
name: "shebang",
|
|
193
|
+
renderChunk(_, __, info) {
|
|
194
|
+
if (info.type === "chunk" && /\.(cjs|js|mjs)$/.test(info.path) && info.code.startsWith("#!")) {
|
|
195
|
+
info.mode = 493;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/utilities/helpers.ts
|
|
201
|
+
function handleSync(fn) {
|
|
202
|
+
try {
|
|
203
|
+
return fn();
|
|
204
|
+
} catch (error_) {
|
|
205
|
+
return error_;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
__name(handleSync, "handleSync");
|
|
209
|
+
async function handleAsync(fn) {
|
|
210
|
+
try {
|
|
211
|
+
return await fn();
|
|
212
|
+
} catch (error_) {
|
|
213
|
+
return error_;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
__name(handleAsync, "handleAsync");
|
|
217
|
+
var handle = handleSync;
|
|
218
|
+
handle.async = handleAsync;
|
|
219
|
+
var skip = Symbol("skip");
|
|
220
|
+
function transduceSync(list, transformer) {
|
|
221
|
+
const transduced = [];
|
|
222
|
+
for (const [i, element_] of list.entries()) {
|
|
223
|
+
const transformed = transformer(element_, i);
|
|
224
|
+
if (transformed !== skip) {
|
|
225
|
+
transduced[transduced.length] = transformed;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return transduced;
|
|
229
|
+
}
|
|
230
|
+
__name(transduceSync, "transduceSync");
|
|
231
|
+
async function transduceAsync(list, transformer) {
|
|
232
|
+
const transduced = [];
|
|
233
|
+
await Promise.all(list.entries().map(async ([i, element_]) => {
|
|
234
|
+
const transformed = await transformer(element_, i);
|
|
235
|
+
if (transformed !== skip) {
|
|
236
|
+
transduced[transduced.length] = transformed;
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
return transduced;
|
|
240
|
+
}
|
|
241
|
+
__name(transduceAsync, "transduceAsync");
|
|
242
|
+
var Filter = /* @__PURE__ */ __name((filter) => (item) => {
|
|
243
|
+
return filter(item) ? item : skip;
|
|
244
|
+
}, "Filter");
|
|
245
|
+
var Mapper = /* @__PURE__ */ __name((mapper) => (item) => {
|
|
246
|
+
return mapper(item);
|
|
247
|
+
}, "Mapper");
|
|
248
|
+
var transduce = transduceSync;
|
|
249
|
+
transduce.async = transduceAsync;
|
|
250
|
+
function pipeSync(fn, ...fns) {
|
|
251
|
+
return (...args) => {
|
|
252
|
+
let result = fn(...args);
|
|
253
|
+
for (let i = 0; result !== skip && i < fns.length; ++i) {
|
|
254
|
+
result = fns[i]?.(result);
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
__name(pipeSync, "pipeSync");
|
|
260
|
+
function pipeAsync(fn, ...fns) {
|
|
261
|
+
return async (...args) => {
|
|
262
|
+
let result = await fn(...args);
|
|
263
|
+
for (let i = 0; result !== skip && i < fns.length; ++i) {
|
|
264
|
+
result = await fns[i]?.(result);
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
__name(pipeAsync, "pipeAsync");
|
|
270
|
+
var pipe = pipeSync;
|
|
271
|
+
pipe.async = pipeAsync;
|
|
272
|
+
|
|
273
|
+
// src/build.ts
|
|
274
|
+
var resolveOptions = /* @__PURE__ */ __name(async (userOptions) => {
|
|
275
|
+
const projectRoot = userOptions.projectRoot;
|
|
276
|
+
const workspaceRoot = findWorkspaceRoot(projectRoot);
|
|
277
|
+
if (!workspaceRoot) {
|
|
278
|
+
throw new Error("Cannot find Nx workspace root");
|
|
279
|
+
}
|
|
280
|
+
const config = await loadStormConfig(workspaceRoot.dir);
|
|
281
|
+
writeDebug(" \u2699\uFE0F Resolving build options", config);
|
|
282
|
+
const stopwatch = getStopwatch("Build options resolution");
|
|
283
|
+
const projectGraph = await createProjectGraphAsync({
|
|
284
|
+
exitOnError: true
|
|
285
|
+
});
|
|
286
|
+
const projectJsonPath = joinPaths(workspaceRoot.dir, projectRoot, "project.json");
|
|
287
|
+
if (!await hfs.isFile(projectJsonPath)) {
|
|
288
|
+
throw new Error("Cannot find project.json configuration");
|
|
289
|
+
}
|
|
290
|
+
const projectJson = await hfs.json(projectJsonPath);
|
|
291
|
+
const projectName = projectJson.name;
|
|
292
|
+
const projectConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
|
|
293
|
+
if (!projectConfigurations?.projects?.[projectName]) {
|
|
294
|
+
throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
|
|
295
|
+
}
|
|
296
|
+
const options = defu(userOptions, DEFAULT_BUILD_OPTIONS);
|
|
297
|
+
options.name ??= `${projectName}-${options.format}`;
|
|
298
|
+
options.target ??= DEFAULT_TARGET;
|
|
299
|
+
const packageJsonPath = joinPaths(workspaceRoot.dir, options.projectRoot, "package.json");
|
|
300
|
+
if (!await hfs.isFile(packageJsonPath)) {
|
|
301
|
+
throw new Error("Cannot find package.json configuration");
|
|
302
|
+
}
|
|
303
|
+
const packageJson = await hfs.json(packageJsonPath);
|
|
304
|
+
const outExtension = getOutputExtensionMap(options, packageJson.type);
|
|
305
|
+
const env = getEnv("esbuild", options);
|
|
306
|
+
const result = {
|
|
307
|
+
...options,
|
|
308
|
+
config,
|
|
309
|
+
mainFields: options.platform === "node" ? [
|
|
310
|
+
"module",
|
|
311
|
+
"main"
|
|
312
|
+
] : [
|
|
313
|
+
"browser",
|
|
314
|
+
"module",
|
|
315
|
+
"main"
|
|
316
|
+
],
|
|
317
|
+
resolveExtensions: [
|
|
318
|
+
".ts",
|
|
319
|
+
".js",
|
|
320
|
+
".node"
|
|
321
|
+
],
|
|
322
|
+
...userOptions,
|
|
323
|
+
tsconfig: joinPaths(projectRoot, userOptions.tsconfig ? userOptions.tsconfig.replace(projectRoot, "") : "tsconfig.json"),
|
|
324
|
+
format: options.format || "cjs",
|
|
325
|
+
entryPoints: await getEntryPoints(config, projectRoot, projectJson.sourceRoot, userOptions.entry || [
|
|
326
|
+
"./src/index.ts"
|
|
327
|
+
], userOptions.emitOnAll),
|
|
328
|
+
outdir: userOptions.outputPath || joinPaths("dist", projectRoot),
|
|
329
|
+
plugins: [],
|
|
330
|
+
name: userOptions.name || projectName,
|
|
331
|
+
projectConfigurations,
|
|
332
|
+
projectName,
|
|
333
|
+
projectGraph,
|
|
334
|
+
sourceRoot: userOptions.sourceRoot || projectJson.sourceRoot || joinPaths(projectRoot, "src"),
|
|
335
|
+
minify: userOptions.minify || !userOptions.debug,
|
|
336
|
+
verbose: userOptions.verbose || isVerbose() || userOptions.debug === true,
|
|
337
|
+
includeSrc: userOptions.includeSrc === true,
|
|
338
|
+
metafile: userOptions.metafile !== false,
|
|
339
|
+
generatePackageJson: userOptions.generatePackageJson !== false,
|
|
340
|
+
clean: userOptions.clean !== false,
|
|
341
|
+
emitOnAll: userOptions.emitOnAll === true,
|
|
342
|
+
assets: userOptions.assets ?? [],
|
|
343
|
+
injectShims: userOptions.injectShims !== true,
|
|
344
|
+
bundle: userOptions.bundle !== false,
|
|
345
|
+
keepNames: true,
|
|
346
|
+
watch: userOptions.watch === true,
|
|
347
|
+
outExtension,
|
|
348
|
+
footer: userOptions.footer,
|
|
349
|
+
banner: {
|
|
350
|
+
js: options.banner || DEFAULT_COMPILED_BANNER,
|
|
351
|
+
css: options.banner || DEFAULT_COMPILED_BANNER
|
|
352
|
+
},
|
|
353
|
+
splitting: options.format === "iife" ? false : typeof options.splitting === "boolean" ? options.splitting : options.format === "esm",
|
|
354
|
+
treeShaking: options.format === "esm",
|
|
355
|
+
env,
|
|
356
|
+
define: {
|
|
357
|
+
STORM_FORMAT: JSON.stringify(options.format || "cjs"),
|
|
358
|
+
...options.format === "cjs" && options.injectShims ? {
|
|
359
|
+
"import.meta.url": "importMetaUrl"
|
|
360
|
+
} : {},
|
|
361
|
+
...options.define,
|
|
362
|
+
...Object.keys(env || {}).reduce((res, key) => {
|
|
363
|
+
const value = JSON.stringify(env[key]);
|
|
364
|
+
return {
|
|
365
|
+
...res,
|
|
366
|
+
[`process.env.${key}`]: value,
|
|
367
|
+
[`import.meta.env.${key}`]: value
|
|
368
|
+
};
|
|
369
|
+
}, {})
|
|
370
|
+
},
|
|
371
|
+
inject: [
|
|
372
|
+
options.format === "cjs" && options.injectShims ? joinPaths(__dirname, "../assets/cjs_shims.js") : "",
|
|
373
|
+
options.format === "esm" && options.injectShims && options.platform === "node" ? joinPaths(__dirname, "../assets/esm_shims.js") : "",
|
|
374
|
+
...options.inject ?? []
|
|
375
|
+
].filter(Boolean)
|
|
376
|
+
};
|
|
377
|
+
result.plugins = userOptions.plugins ?? getDefaultBuildPlugins(userOptions, result);
|
|
378
|
+
stopwatch();
|
|
379
|
+
return result;
|
|
380
|
+
}, "resolveOptions");
|
|
381
|
+
async function generatePackageJson(context2) {
|
|
382
|
+
if (context2.options.generatePackageJson !== false && await hfs.isFile(joinPaths(context2.options.projectRoot, "package.json"))) {
|
|
383
|
+
writeDebug(" \u270D\uFE0F Writing package.json file", context2.options.config);
|
|
384
|
+
const stopwatch = getStopwatch("Write package.json file");
|
|
385
|
+
const packageJsonPath = joinPaths(context2.options.projectRoot, "project.json");
|
|
386
|
+
if (!await hfs.isFile(packageJsonPath)) {
|
|
387
|
+
throw new Error("Cannot find package.json configuration");
|
|
388
|
+
}
|
|
389
|
+
let packageJson = await hfs.json(joinPaths(context2.options.config.workspaceRoot, context2.options.projectRoot, "package.json"));
|
|
390
|
+
if (!packageJson) {
|
|
391
|
+
throw new Error("Cannot find package.json configuration file");
|
|
392
|
+
}
|
|
393
|
+
packageJson = await addPackageDependencies(context2.options.config.workspaceRoot, context2.options.projectRoot, context2.options.projectName, packageJson);
|
|
394
|
+
packageJson = await addWorkspacePackageJsonFields(context2.options.config, context2.options.projectRoot, context2.options.sourceRoot, context2.options.projectName, false, packageJson);
|
|
395
|
+
packageJson.exports ??= {};
|
|
396
|
+
packageJson.exports["./package.json"] ??= "./package.json";
|
|
397
|
+
packageJson.exports["."] ??= addPackageJsonExport("index", packageJson.type, context2.options.sourceRoot);
|
|
398
|
+
let entryPoints = [
|
|
399
|
+
{
|
|
400
|
+
in: "./src/index.ts",
|
|
401
|
+
out: "./src/index.ts"
|
|
402
|
+
}
|
|
403
|
+
];
|
|
404
|
+
if (context2.options.entryPoints) {
|
|
405
|
+
if (Array.isArray(context2.options.entryPoints)) {
|
|
406
|
+
entryPoints = context2.options.entryPoints.map((entryPoint) => typeof entryPoint === "string" ? {
|
|
407
|
+
in: entryPoint,
|
|
408
|
+
out: entryPoint
|
|
409
|
+
} : entryPoint);
|
|
410
|
+
}
|
|
411
|
+
for (const entryPoint of entryPoints) {
|
|
412
|
+
const split = entryPoint.out.split(".");
|
|
413
|
+
split.pop();
|
|
414
|
+
const entry = split.join(".").replaceAll("\\", "/");
|
|
415
|
+
packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, context2.options.sourceRoot);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
|
|
419
|
+
packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
|
|
420
|
+
packageJson.types = "./dist/index.d.ts";
|
|
421
|
+
packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
|
|
422
|
+
if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
|
|
423
|
+
ret[key.replace("/index", "")] = packageJson.exports[key];
|
|
424
|
+
}
|
|
425
|
+
return ret;
|
|
426
|
+
}, packageJson.exports);
|
|
427
|
+
await writeJsonFile(joinPaths(context2.options.outdir, "package.json"), packageJson);
|
|
428
|
+
stopwatch();
|
|
429
|
+
}
|
|
430
|
+
return context2;
|
|
431
|
+
}
|
|
432
|
+
__name(generatePackageJson, "generatePackageJson");
|
|
433
|
+
async function createOptions(options) {
|
|
434
|
+
return flatten(await Promise.all(map(options, (opt) => [
|
|
435
|
+
// we defer it so that we don't trigger glob immediately
|
|
436
|
+
() => resolveOptions(opt)
|
|
437
|
+
])));
|
|
438
|
+
}
|
|
439
|
+
__name(createOptions, "createOptions");
|
|
440
|
+
async function generateContext(getOptions) {
|
|
441
|
+
const options = await getOptions();
|
|
442
|
+
const rendererEngine = new RendererEngine([
|
|
443
|
+
shebangRenderer,
|
|
444
|
+
...options.renderers || []
|
|
445
|
+
]);
|
|
446
|
+
return {
|
|
447
|
+
options,
|
|
448
|
+
rendererEngine
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
__name(generateContext, "generateContext");
|
|
452
|
+
async function executeEsBuild(context2) {
|
|
453
|
+
writeDebug(` \u{1F680} Running ${context2.options.name} build`, context2.options.config);
|
|
454
|
+
const stopwatch = getStopwatch(`${context2.options.name} build`);
|
|
455
|
+
if (process.env.WATCH === "true") {
|
|
456
|
+
const ctx = await esbuild.context(context2.options);
|
|
457
|
+
watch(ctx, context2.options);
|
|
458
|
+
}
|
|
459
|
+
const result = await esbuild.build(context2.options);
|
|
460
|
+
if (result.metafile) {
|
|
461
|
+
const metafilePath = `${context2.options.outdir}/${context2.options.name}.meta.json`;
|
|
462
|
+
await hfs.write(metafilePath, JSON.stringify(result.metafile));
|
|
463
|
+
}
|
|
464
|
+
stopwatch();
|
|
465
|
+
return context2;
|
|
466
|
+
}
|
|
467
|
+
__name(executeEsBuild, "executeEsBuild");
|
|
468
|
+
async function copyBuildAssets(context2) {
|
|
469
|
+
if (context2.result?.errors.length === 0) {
|
|
470
|
+
writeDebug(` \u{1F4CB} Copying asset files to output directory: ${context2.options.outdir}`, context2.options.config);
|
|
471
|
+
const stopwatch = getStopwatch(`${context2.options.name} asset copy`);
|
|
472
|
+
await copyAssets(context2.options.config, context2.options.assets ?? [], context2.options.outdir, context2.options.projectRoot, context2.options.projectName, context2.options.sourceRoot, true, false);
|
|
473
|
+
stopwatch();
|
|
474
|
+
}
|
|
475
|
+
return context2;
|
|
476
|
+
}
|
|
477
|
+
__name(copyBuildAssets, "copyBuildAssets");
|
|
478
|
+
async function reportResults(context2) {
|
|
479
|
+
if (context2.result?.errors.length === 0) {
|
|
480
|
+
if (context2.result.warnings.length > 0) {
|
|
481
|
+
writeWarning(` \u{1F6A7} The following warnings occurred during the build: ${context2.result.warnings.map((warning) => warning.text).join("\n")}`, context2.options.config);
|
|
482
|
+
}
|
|
483
|
+
writeSuccess(` \u{1F4E6} The ${context2.options.name} build completed successfully`, context2.options.config);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
__name(reportResults, "reportResults");
|
|
487
|
+
async function dependencyCheck(options) {
|
|
488
|
+
if (process.env.DEV === "true") {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
if (process.env.CI && !process.env.BUILDKITE) {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
const buildPromise = esbuild.build({
|
|
495
|
+
entryPoints: globbySync("**/*.{j,t}s", {
|
|
496
|
+
// We don't check dependencies in ecosystem tests because tests are isolated from the build.
|
|
497
|
+
ignore: [
|
|
498
|
+
"./src/__tests__/**/*",
|
|
499
|
+
"./tests/e2e/**/*",
|
|
500
|
+
"./dist/**/*"
|
|
501
|
+
],
|
|
502
|
+
gitignore: true
|
|
503
|
+
}),
|
|
504
|
+
logLevel: "silent",
|
|
505
|
+
bundle: true,
|
|
506
|
+
write: false,
|
|
507
|
+
outdir: "out",
|
|
508
|
+
plugins: [
|
|
509
|
+
depsCheckPlugin(options.bundle)
|
|
510
|
+
]
|
|
511
|
+
});
|
|
512
|
+
await buildPromise.catch(() => {
|
|
513
|
+
});
|
|
514
|
+
return void 0;
|
|
515
|
+
}
|
|
516
|
+
__name(dependencyCheck, "dependencyCheck");
|
|
517
|
+
async function cleanOutputPath(context2) {
|
|
518
|
+
if (context2.options.clean !== false && context2.options.outdir) {
|
|
519
|
+
await clean(context2.options.name, context2.options.outdir, context2.options.config);
|
|
520
|
+
}
|
|
521
|
+
return context2;
|
|
522
|
+
}
|
|
523
|
+
__name(cleanOutputPath, "cleanOutputPath");
|
|
524
|
+
async function build2(options) {
|
|
525
|
+
writeDebug(` \u26A1 Executing Storm ESBuild pipeline`);
|
|
526
|
+
const stopwatch = getStopwatch("ESBuild pipeline");
|
|
527
|
+
try {
|
|
528
|
+
const opts = Array.isArray(options) ? options : [
|
|
529
|
+
options
|
|
530
|
+
];
|
|
531
|
+
if (opts.length === 0) {
|
|
532
|
+
throw new Error("No build options were provided");
|
|
533
|
+
}
|
|
534
|
+
void transduce.async(opts, dependencyCheck);
|
|
535
|
+
await transduce.async(await createOptions(opts), pipe.async(generateContext, cleanOutputPath, generatePackageJson, executeEsBuild, copyBuildAssets, reportResults));
|
|
536
|
+
writeSuccess(" \u{1F3C1} ESBuild pipeline build completed successfully");
|
|
537
|
+
} catch (error) {
|
|
538
|
+
writeFatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
|
|
539
|
+
throw error;
|
|
540
|
+
} finally {
|
|
541
|
+
stopwatch();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
__name(build2, "build");
|
|
545
|
+
var watch = /* @__PURE__ */ __name((context2, options) => {
|
|
546
|
+
if (!options.watch) {
|
|
547
|
+
return context2;
|
|
548
|
+
}
|
|
549
|
+
const config = {
|
|
550
|
+
ignoreInitial: true,
|
|
551
|
+
useFsEvents: true,
|
|
552
|
+
ignored: [
|
|
553
|
+
"./src/__tests__/**/*",
|
|
554
|
+
"./package.json"
|
|
555
|
+
]
|
|
556
|
+
};
|
|
557
|
+
const changeWatcher = createWatcher([
|
|
558
|
+
"./src/**/*"
|
|
559
|
+
], config);
|
|
560
|
+
const fastRebuild = debounce(async () => {
|
|
561
|
+
const timeBefore = Date.now();
|
|
562
|
+
const rebuildResult = await handle.async(() => {
|
|
563
|
+
return context2.rebuild();
|
|
564
|
+
});
|
|
565
|
+
if (rebuildResult instanceof Error) {
|
|
566
|
+
writeError(rebuildResult.message);
|
|
567
|
+
}
|
|
568
|
+
writeTrace(`${Date.now() - timeBefore}ms [${options.name ?? ""}]`);
|
|
569
|
+
}, 10);
|
|
570
|
+
changeWatcher.on("change", fastRebuild);
|
|
571
|
+
return void 0;
|
|
572
|
+
}, "watch");
|
|
573
|
+
|
|
574
|
+
export {
|
|
575
|
+
handle,
|
|
576
|
+
skip,
|
|
577
|
+
Filter,
|
|
578
|
+
Mapper,
|
|
579
|
+
transduce,
|
|
580
|
+
pipe,
|
|
581
|
+
build2 as build
|
|
582
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getStopwatch,
|
|
3
|
+
writeDebug
|
|
4
|
+
} from "./chunk-HQGUIF4U.js";
|
|
5
|
+
import {
|
|
6
|
+
__name
|
|
7
|
+
} from "./chunk-3GQAWCBQ.js";
|
|
8
|
+
|
|
9
|
+
// src/clean.ts
|
|
10
|
+
import { hfs } from "@humanfs/node";
|
|
11
|
+
async function clean(name = "ESBuild", directory, config) {
|
|
12
|
+
writeDebug(` \u{1F9F9} Cleaning ${name} output path: ${directory}`, config);
|
|
13
|
+
const stopwatch = getStopwatch(`${name} output clean`);
|
|
14
|
+
await hfs.deleteAll(directory);
|
|
15
|
+
stopwatch();
|
|
16
|
+
}
|
|
17
|
+
__name(clean, "clean");
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
clean
|
|
21
|
+
};
|