rolldown 0.14.0 → 0.15.0-commit.6d5a1b0

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.
Files changed (103) hide show
  1. package/dist/cjs/cli.cjs +960 -966
  2. package/dist/cjs/experimental-index.cjs +68 -26
  3. package/dist/cjs/index.cjs +6 -8
  4. package/dist/cjs/parallel-plugin-worker.cjs +20 -14
  5. package/dist/cjs/parallel-plugin.cjs +1 -3
  6. package/dist/esm/cli.mjs +914 -922
  7. package/dist/esm/experimental-index.mjs +44 -7
  8. package/dist/esm/index.mjs +2 -4
  9. package/dist/esm/parallel-plugin-worker.mjs +15 -10
  10. package/dist/esm/parallel-plugin.mjs +1 -3
  11. package/dist/shared/{chunk-JoMxl5V2.cjs → chunk-BFvIen8E.cjs} +13 -11
  12. package/dist/shared/{consola.36c0034f-HcmWcfPe.cjs → consola_36c0034f-B7L-radJ.cjs} +249 -295
  13. package/dist/shared/{consola.36c0034f-Xyw7SC_7.mjs → consola_36c0034f-D9ce-831.mjs} +221 -286
  14. package/dist/shared/{prompt-9Ij3R3TG.cjs → prompt-BiXtYIJ2.cjs} +157 -204
  15. package/dist/shared/{prompt-hoPhcrA-.mjs → prompt-DlQ-08lk.mjs} +125 -174
  16. package/dist/shared/src-CTTOsHx-.cjs +2985 -0
  17. package/dist/shared/src-DcKnw9Hv.mjs +2851 -0
  18. package/dist/tsconfig.dts.tsbuildinfo +1 -0
  19. package/dist/types/api/build.d.ts +16 -0
  20. package/dist/types/api/experimental.d.ts +7 -0
  21. package/dist/types/api/rolldown/index.d.ts +3 -0
  22. package/dist/types/api/rolldown/rolldown-build.d.ts +12 -0
  23. package/dist/types/api/watch/index.d.ts +3 -0
  24. package/dist/types/{watcher.d.ts → api/watch/watch-emitter.d.ts} +17 -17
  25. package/dist/types/api/watch/watcher.d.ts +13 -0
  26. package/dist/types/binding.d.ts +273 -49
  27. package/dist/types/builtin-plugin/alias-plugin.d.ts +10 -0
  28. package/dist/types/builtin-plugin/constructors.d.ts +16 -0
  29. package/dist/types/builtin-plugin/replace-plugin.d.ts +28 -0
  30. package/dist/types/{options/normalized-ecma-transform-plugin-config.d.ts → builtin-plugin/transform-plugin.d.ts} +2 -1
  31. package/dist/types/builtin-plugin/utils.d.ts +8 -0
  32. package/dist/types/cli/arguments/index.d.ts +5 -3
  33. package/dist/types/cli/arguments/normalize.d.ts +2 -6
  34. package/dist/types/cli/arguments/schema.d.ts +10 -309
  35. package/dist/types/cli/colors.d.ts +11 -1
  36. package/dist/types/cli/load-config.d.ts +3 -0
  37. package/dist/types/cli/logger.d.ts +5 -0
  38. package/dist/types/constants/plugin.d.ts +10 -1
  39. package/dist/types/experimental-index.d.ts +5 -2
  40. package/dist/types/index.d.ts +13 -10
  41. package/dist/types/log/logger.d.ts +2 -16
  42. package/dist/types/log/logging.d.ts +11 -8
  43. package/dist/types/log/logs.d.ts +3 -0
  44. package/dist/types/options/input-options-schema.d.ts +4 -0
  45. package/dist/types/options/input-options.d.ts +89 -430
  46. package/dist/types/options/normalized-input-options.d.ts +17 -11
  47. package/dist/types/options/normalized-output-options.d.ts +60 -21
  48. package/dist/types/options/output-options-schema.d.ts +3 -0
  49. package/dist/types/options/output-options.d.ts +73 -265
  50. package/dist/types/options/watch-options.d.ts +5 -0
  51. package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -11
  52. package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -5
  53. package/dist/types/plugin/bindingify-output-hooks.d.ts +13 -16
  54. package/dist/types/plugin/bindingify-plugin.d.ts +12 -3
  55. package/dist/types/plugin/bindingify-watch-hooks.d.ts +3 -5
  56. package/dist/types/plugin/hook-filter.d.ts +1 -1
  57. package/dist/types/plugin/index.d.ts +21 -18
  58. package/dist/types/plugin/minimal-plugin-context.d.ts +15 -0
  59. package/dist/types/plugin/plugin-context-data.d.ts +4 -4
  60. package/dist/types/plugin/plugin-context.d.ts +9 -4
  61. package/dist/types/plugin/plugin-driver.d.ts +4 -5
  62. package/dist/types/plugin/transform-plugin-context.d.ts +4 -3
  63. package/dist/types/rollup-types.d.ts +1 -1
  64. package/dist/types/rollup.d.ts +4 -0
  65. package/dist/types/treeshake/index.d.ts +0 -12
  66. package/dist/types/treeshake/module-side-effects.d.ts +14 -15
  67. package/dist/types/types/rolldown-output.d.ts +17 -2
  68. package/dist/types/types/utils.d.ts +1 -0
  69. package/dist/types/utils/bindingify-input-options.d.ts +7 -0
  70. package/dist/types/utils/bindingify-output-options.d.ts +3 -0
  71. package/dist/types/utils/create-bundler-option.d.ts +11 -0
  72. package/dist/types/utils/define-config.d.ts +3 -0
  73. package/dist/types/utils/error.d.ts +2 -0
  74. package/dist/types/utils/misc.d.ts +1 -0
  75. package/dist/types/utils/normalize-hook.d.ts +1 -1
  76. package/dist/types/utils/normalize-plugin-option.d.ts +8 -3
  77. package/dist/types/{options/utils.d.ts → utils/normalize-string-or-regex.d.ts} +1 -1
  78. package/dist/types/utils/transform-rendered-chunk.d.ts +4 -0
  79. package/dist/types/utils/transform-rendered-module.d.ts +3 -0
  80. package/dist/types/utils/transform-sourcemap.d.ts +2 -0
  81. package/dist/types/utils/transform-to-rollup-output.d.ts +1 -0
  82. package/dist/types/utils/zod-ext.d.ts +6 -5
  83. package/package.json +31 -23
  84. package/dist/shared/rolldown-binding.wasi.cjs +0 -187
  85. package/dist/shared/src_index-3pqhEViJ.cjs +0 -2785
  86. package/dist/shared/src_index-ywYMd4vB.mjs +0 -2786
  87. package/dist/shared/wasi-worker-browser.mjs +0 -39
  88. package/dist/shared/wasi-worker.mjs +0 -63
  89. package/dist/shared/watcher-worker.js +0 -1
  90. package/dist/types/cli/utils.d.ts +0 -6
  91. package/dist/types/constants/types.d.ts +0 -1
  92. package/dist/types/options/bindingify-input-options.d.ts +0 -4
  93. package/dist/types/options/bindingify-output-options.d.ts +0 -3
  94. package/dist/types/options/normalized-alias-plugin-config.d.ts +0 -8
  95. package/dist/types/options/watch-option.d.ts +0 -5
  96. package/dist/types/plugin/builtin-plugin.d.ts +0 -81
  97. package/dist/types/rolldown-build.d.ts +0 -10
  98. package/dist/types/rolldown.d.ts +0 -12
  99. package/dist/types/types/rendered-module.d.ts +0 -2
  100. package/dist/types/utils/normalize-input-options.d.ts +0 -3
  101. package/dist/types/utils/normalize-output-options.d.ts +0 -3
  102. package/dist/types/utils/normalize-tree-shake.d.ts +0 -3
  103. /package/dist/types/{utils/type-assert.d.ts → types/assert.d.ts} +0 -0
@@ -1,2785 +0,0 @@
1
- const { __commonJSMin, __toESM } = require("./chunk-JoMxl5V2.cjs");
2
- const { spawn } = __toESM(require("node:child_process"));
3
- const { default: path, default: path$1 } = __toESM(require("node:path"));
4
- const { z } = __toESM(require("zod"));
5
- const { Worker } = __toESM(require("node:worker_threads"));
6
- const { availableParallelism } = __toESM(require("node:os"));
7
- const { isRegExp } = __toESM(require("node:util/types"));
8
-
9
- //#region src/utils/define-config.ts
10
- function defineConfig(config) {
11
- return config;
12
- }
13
-
14
- //#endregion
15
- //#region src/utils/asset-source.ts
16
- function transformAssetSource(bindingAssetSource$1) {
17
- return bindingAssetSource$1.inner;
18
- }
19
- function bindingAssetSource(source) {
20
- return {inner: source};
21
- }
22
-
23
- //#endregion
24
- //#region src/types/sourcemap.ts
25
- function bindingifySourcemap$1(map) {
26
- if (map == null) return;
27
- return {inner: typeof map === "string" ? map : {
28
- file: map.file ?? undefined,
29
- mappings: map.mappings,
30
- sourceRoot: map.sourceRoot,
31
- sources: map.sources?.map((s) => s ?? undefined),
32
- sourcesContent: map.sourcesContent?.map((s) => s ?? undefined),
33
- names: map.names
34
- }};
35
- }
36
-
37
- //#endregion
38
- //#region src/utils/transform-to-rollup-output.ts
39
- function transformToRollupOutputChunk(bindingChunk, changed) {
40
- const chunk = {
41
- type: "chunk",
42
- get code() {
43
- return bindingChunk.code;
44
- },
45
- fileName: bindingChunk.fileName,
46
- name: bindingChunk.name,
47
- get modules() {
48
- return Object.fromEntries((Object.entries(bindingChunk.modules)).map(([key, _]) => [key, {}]));
49
- },
50
- get imports() {
51
- return bindingChunk.imports;
52
- },
53
- get dynamicImports() {
54
- return bindingChunk.dynamicImports;
55
- },
56
- exports: bindingChunk.exports,
57
- isEntry: bindingChunk.isEntry,
58
- facadeModuleId: bindingChunk.facadeModuleId || null,
59
- isDynamicEntry: bindingChunk.isDynamicEntry,
60
- get moduleIds() {
61
- return bindingChunk.moduleIds;
62
- },
63
- get map() {
64
- return bindingChunk.map ? JSON.parse(bindingChunk.map) : null;
65
- },
66
- sourcemapFileName: bindingChunk.sourcemapFileName || null,
67
- preliminaryFileName: bindingChunk.preliminaryFileName
68
- };
69
- const cache = {};
70
- return new Proxy(chunk, {
71
- get(target, p) {
72
- if (p in cache) {
73
- return cache[p];
74
- }
75
- return target[p];
76
- },
77
- set(target, p, newValue) {
78
- cache[p] = newValue;
79
- changed?.updated.add(bindingChunk.fileName);
80
- return true;
81
- }
82
- });
83
- }
84
- function transformToRollupOutputAsset(bindingAsset, changed) {
85
- const asset = {
86
- type: "asset",
87
- fileName: bindingAsset.fileName,
88
- originalFileName: bindingAsset.originalFileName || null,
89
- get source() {
90
- return transformAssetSource(bindingAsset.source);
91
- },
92
- name: bindingAsset.name ?? undefined
93
- };
94
- const cache = {};
95
- return new Proxy(asset, {
96
- get(target, p) {
97
- if (p in cache) {
98
- return cache[p];
99
- }
100
- return target[p];
101
- },
102
- set(target, p, newValue) {
103
- cache[p] = newValue;
104
- changed?.updated.add(bindingAsset.fileName);
105
- return true;
106
- }
107
- });
108
- }
109
- function transformToRollupOutput(output, changed) {
110
- const { chunks: chunks, assets: assets } = output;
111
- return {output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed)),]};
112
- }
113
- function transformToOutputBundle(output, changed) {
114
- const bundle = Object.fromEntries((transformToRollupOutput(output, changed)).output.map((item) => [item.fileName, item,]));
115
- return new Proxy(bundle, {deleteProperty(target, property) {
116
- if (typeof property === "string") {
117
- changed.deleted.add(property);
118
- }
119
- return true;
120
- }});
121
- }
122
- function collectChangedBundle(changed, bundle) {
123
- const assets = [];
124
- const chunks = [];
125
- for (const key in bundle) {
126
- if (changed.deleted.has(key) || !changed.updated.has(key)) {
127
- continue;
128
- }
129
- const item = bundle[key];
130
- if (item.type === "asset") {
131
- assets.push({
132
- filename: item.fileName,
133
- originalFileName: item.originalFileName || undefined,
134
- source: bindingAssetSource(item.source),
135
- name: item.name
136
- });
137
- } else {
138
- chunks.push({
139
- code: item.code,
140
- filename: item.fileName,
141
- name: item.name,
142
- isEntry: item.isEntry,
143
- exports: item.exports,
144
- modules: Object.fromEntries((Object.entries(item.modules)).map(([key$1, _]) => [key$1, {}])),
145
- imports: item.imports,
146
- dynamicImports: item.dynamicImports,
147
- facadeModuleId: item.facadeModuleId || undefined,
148
- isDynamicEntry: item.isDynamicEntry,
149
- moduleIds: item.moduleIds,
150
- map: bindingifySourcemap$1(item.map),
151
- sourcemapFilename: item.sourcemapFileName || undefined,
152
- preliminaryFilename: item.preliminaryFileName
153
- });
154
- }
155
- }
156
- return {
157
- assets,
158
- chunks,
159
- deleted: Array.from(changed.deleted)
160
- };
161
- }
162
-
163
- //#endregion
164
- //#region src/binding.js
165
- var require_binding = __commonJSMin((exports, module) => {
166
- const { createRequire: createRequire } = require("node:module");
167
- require = createRequire(__filename);
168
- const { readFileSync: readFileSync } = require("node:fs");
169
- let nativeBinding = null;
170
- const loadErrors = [];
171
- const isMusl = () => {
172
- let musl = false;
173
- if (process.platform === "linux") {
174
- musl = isMuslFromFilesystem();
175
- if (musl === null) {
176
- musl = isMuslFromReport();
177
- }
178
- if (musl === null) {
179
- musl = isMuslFromChildProcess();
180
- }
181
- }
182
- return musl;
183
- };
184
- const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
185
- const isMuslFromFilesystem = () => {
186
- try {
187
- return (readFileSync("/usr/bin/ldd", "utf-8")).includes("musl");
188
- } catch {
189
- return null;
190
- }
191
- };
192
- const isMuslFromReport = () => {
193
- const report = typeof process.report.getReport === "function" ? process.report.getReport() : null;
194
- if (!report) {
195
- return null;
196
- }
197
- if (report.header && report.header.glibcVersionRuntime) {
198
- return false;
199
- }
200
- if (Array.isArray(report.sharedObjects)) {
201
- if (report.sharedObjects.some(isFileMusl)) {
202
- return true;
203
- }
204
- }
205
- return false;
206
- };
207
- const isMuslFromChildProcess = () => {
208
- try {
209
- return ((require("node:child_process")).execSync("ldd --version", {encoding: "utf8"})).includes("musl");
210
- } catch (e) {
211
- return false;
212
- }
213
- };
214
- function requireNative() {
215
- if (process.platform === "android") {
216
- if (process.arch === "arm64") {
217
- try {
218
- return require("./rolldown-binding.android-arm64.node");
219
- } catch (e) {
220
- loadErrors.push(e);
221
- }
222
- try {
223
- return require("@rolldown/binding-android-arm64");
224
- } catch (e) {
225
- loadErrors.push(e);
226
- }
227
- } else if (process.arch === "arm") {
228
- try {
229
- return require("./rolldown-binding.android-arm-eabi.node");
230
- } catch (e) {
231
- loadErrors.push(e);
232
- }
233
- try {
234
- return require("@rolldown/binding-android-arm-eabi");
235
- } catch (e) {
236
- loadErrors.push(e);
237
- }
238
- } else {
239
- loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
240
- }
241
- } else if (process.platform === "win32") {
242
- if (process.arch === "x64") {
243
- try {
244
- return require("./rolldown-binding.win32-x64-msvc.node");
245
- } catch (e) {
246
- loadErrors.push(e);
247
- }
248
- try {
249
- return require("@rolldown/binding-win32-x64-msvc");
250
- } catch (e) {
251
- loadErrors.push(e);
252
- }
253
- } else if (process.arch === "ia32") {
254
- try {
255
- return require("./rolldown-binding.win32-ia32-msvc.node");
256
- } catch (e) {
257
- loadErrors.push(e);
258
- }
259
- try {
260
- return require("@rolldown/binding-win32-ia32-msvc");
261
- } catch (e) {
262
- loadErrors.push(e);
263
- }
264
- } else if (process.arch === "arm64") {
265
- try {
266
- return require("./rolldown-binding.win32-arm64-msvc.node");
267
- } catch (e) {
268
- loadErrors.push(e);
269
- }
270
- try {
271
- return require("@rolldown/binding-win32-arm64-msvc");
272
- } catch (e) {
273
- loadErrors.push(e);
274
- }
275
- } else {
276
- loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
277
- }
278
- } else if (process.platform === "darwin") {
279
- try {
280
- return require("./rolldown-binding.darwin-universal.node");
281
- } catch (e) {
282
- loadErrors.push(e);
283
- }
284
- try {
285
- return require("@rolldown/binding-darwin-universal");
286
- } catch (e) {
287
- loadErrors.push(e);
288
- }
289
- if (process.arch === "x64") {
290
- try {
291
- return require("./rolldown-binding.darwin-x64.node");
292
- } catch (e) {
293
- loadErrors.push(e);
294
- }
295
- try {
296
- return require("@rolldown/binding-darwin-x64");
297
- } catch (e) {
298
- loadErrors.push(e);
299
- }
300
- } else if (process.arch === "arm64") {
301
- try {
302
- return require("./rolldown-binding.darwin-arm64.node");
303
- } catch (e) {
304
- loadErrors.push(e);
305
- }
306
- try {
307
- return require("@rolldown/binding-darwin-arm64");
308
- } catch (e) {
309
- loadErrors.push(e);
310
- }
311
- } else {
312
- loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
313
- }
314
- } else if (process.platform === "freebsd") {
315
- if (process.arch === "x64") {
316
- try {
317
- return require("./rolldown-binding.freebsd-x64.node");
318
- } catch (e) {
319
- loadErrors.push(e);
320
- }
321
- try {
322
- return require("@rolldown/binding-freebsd-x64");
323
- } catch (e) {
324
- loadErrors.push(e);
325
- }
326
- } else if (process.arch === "arm64") {
327
- try {
328
- return require("./rolldown-binding.freebsd-arm64.node");
329
- } catch (e) {
330
- loadErrors.push(e);
331
- }
332
- try {
333
- return require("@rolldown/binding-freebsd-arm64");
334
- } catch (e) {
335
- loadErrors.push(e);
336
- }
337
- } else {
338
- loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
339
- }
340
- } else if (process.platform === "linux") {
341
- if (process.arch === "x64") {
342
- if (isMusl()) {
343
- try {
344
- return require("./rolldown-binding.linux-x64-musl.node");
345
- } catch (e) {
346
- loadErrors.push(e);
347
- }
348
- try {
349
- return require("@rolldown/binding-linux-x64-musl");
350
- } catch (e) {
351
- loadErrors.push(e);
352
- }
353
- } else {
354
- try {
355
- return require("./rolldown-binding.linux-x64-gnu.node");
356
- } catch (e) {
357
- loadErrors.push(e);
358
- }
359
- try {
360
- return require("@rolldown/binding-linux-x64-gnu");
361
- } catch (e) {
362
- loadErrors.push(e);
363
- }
364
- }
365
- } else if (process.arch === "arm64") {
366
- if (isMusl()) {
367
- try {
368
- return require("./rolldown-binding.linux-arm64-musl.node");
369
- } catch (e) {
370
- loadErrors.push(e);
371
- }
372
- try {
373
- return require("@rolldown/binding-linux-arm64-musl");
374
- } catch (e) {
375
- loadErrors.push(e);
376
- }
377
- } else {
378
- try {
379
- return require("./rolldown-binding.linux-arm64-gnu.node");
380
- } catch (e) {
381
- loadErrors.push(e);
382
- }
383
- try {
384
- return require("@rolldown/binding-linux-arm64-gnu");
385
- } catch (e) {
386
- loadErrors.push(e);
387
- }
388
- }
389
- } else if (process.arch === "arm") {
390
- if (isMusl()) {
391
- try {
392
- return require("./rolldown-binding.linux-arm-musleabihf.node");
393
- } catch (e) {
394
- loadErrors.push(e);
395
- }
396
- try {
397
- return require("@rolldown/binding-linux-arm-musleabihf");
398
- } catch (e) {
399
- loadErrors.push(e);
400
- }
401
- } else {
402
- try {
403
- return require("./rolldown-binding.linux-arm-gnueabihf.node");
404
- } catch (e) {
405
- loadErrors.push(e);
406
- }
407
- try {
408
- return require("@rolldown/binding-linux-arm-gnueabihf");
409
- } catch (e) {
410
- loadErrors.push(e);
411
- }
412
- }
413
- } else if (process.arch === "riscv64") {
414
- if (isMusl()) {
415
- try {
416
- return require("./rolldown-binding.linux-riscv64-musl.node");
417
- } catch (e) {
418
- loadErrors.push(e);
419
- }
420
- try {
421
- return require("@rolldown/binding-linux-riscv64-musl");
422
- } catch (e) {
423
- loadErrors.push(e);
424
- }
425
- } else {
426
- try {
427
- return require("./rolldown-binding.linux-riscv64-gnu.node");
428
- } catch (e) {
429
- loadErrors.push(e);
430
- }
431
- try {
432
- return require("@rolldown/binding-linux-riscv64-gnu");
433
- } catch (e) {
434
- loadErrors.push(e);
435
- }
436
- }
437
- } else if (process.arch === "ppc64") {
438
- try {
439
- return require("./rolldown-binding.linux-ppc64-gnu.node");
440
- } catch (e) {
441
- loadErrors.push(e);
442
- }
443
- try {
444
- return require("@rolldown/binding-linux-ppc64-gnu");
445
- } catch (e) {
446
- loadErrors.push(e);
447
- }
448
- } else if (process.arch === "s390x") {
449
- try {
450
- return require("./rolldown-binding.linux-s390x-gnu.node");
451
- } catch (e) {
452
- loadErrors.push(e);
453
- }
454
- try {
455
- return require("@rolldown/binding-linux-s390x-gnu");
456
- } catch (e) {
457
- loadErrors.push(e);
458
- }
459
- } else {
460
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
461
- }
462
- } else {
463
- loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
464
- }
465
- }
466
- nativeBinding = requireNative();
467
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
468
- try {
469
- nativeBinding = require("./rolldown-binding.wasi.cjs");
470
- } catch (err) {
471
- if (process.env.NAPI_RS_FORCE_WASI) {
472
- loadErrors.push(err);
473
- }
474
- }
475
- if (!nativeBinding) {
476
- try {
477
- nativeBinding = require("@rolldown/binding-wasm32-wasi");
478
- } catch (err) {
479
- if (process.env.NAPI_RS_FORCE_WASI) {
480
- loadErrors.push(err);
481
- }
482
- }
483
- }
484
- }
485
- if (!nativeBinding) {
486
- if (loadErrors.length > 0) {
487
- throw new Error("Failed to load native binding", {cause: loadErrors});
488
- }
489
- throw new Error(`Failed to load native binding`);
490
- }
491
- module.exports.BindingLog = nativeBinding.BindingLog;
492
- module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
493
- module.exports.BindingOutputAsset = nativeBinding.BindingOutputAsset;
494
- module.exports.BindingOutputChunk = nativeBinding.BindingOutputChunk;
495
- module.exports.BindingOutputs = nativeBinding.BindingOutputs;
496
- module.exports.BindingPluginContext = nativeBinding.BindingPluginContext;
497
- module.exports.BindingTransformPluginContext = nativeBinding.BindingTransformPluginContext;
498
- module.exports.BindingWatcher = nativeBinding.BindingWatcher;
499
- module.exports.Bundler = nativeBinding.Bundler;
500
- module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
501
- module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
502
- module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
503
- module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
504
- module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
505
- module.exports.BindingWatcherEvent = nativeBinding.BindingWatcherEvent;
506
- module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
507
- module.exports.registerPlugins = nativeBinding.registerPlugins;
508
- module.exports.transform = nativeBinding.transform;
509
- });
510
-
511
- //#endregion
512
- //#region src/utils/misc.ts
513
- function arraify(value) {
514
- return Array.isArray(value) ? value : [value];
515
- }
516
- function isNullish(value) {
517
- return value === null || value === undefined;
518
- }
519
- function unimplemented(info) {
520
- if (info) {
521
- throw new Error(`unimplemented: ${info}`);
522
- }
523
- throw new Error("unimplemented");
524
- }
525
- function unreachable(info) {
526
- if (info) {
527
- throw new Error(`unreachable: ${info}`);
528
- }
529
- throw new Error("unreachable");
530
- }
531
- function unsupported(info) {
532
- return () => {
533
- throw new Error(`UNSUPPORTED: ${info}`);
534
- };
535
- }
536
- function noop(..._args) {}
537
-
538
- //#endregion
539
- //#region src/utils/normalize-hook.ts
540
- function normalizeHook(hook) {
541
- if (typeof hook === "function" || typeof hook === "string") {
542
- return {
543
- handler: hook,
544
- options: {},
545
- meta: {}
546
- };
547
- } else if (typeof hook === "object" && hook !== null) {
548
- const { handler: handler, order: order,...options } = hook;
549
- return {
550
- handler,
551
- options,
552
- meta: {order}
553
- };
554
- }
555
- unreachable("Invalid hook type");
556
- }
557
-
558
- //#endregion
559
- //#region src/utils/transform-sourcemap.ts
560
- function isEmptySourcemapFiled(array) {
561
- if (!array) {
562
- return true;
563
- }
564
- if (array.length === 0 || !array[0]) {
565
- return true;
566
- }
567
- return false;
568
- }
569
-
570
- //#endregion
571
- //#region src/utils/transform-module-info.ts
572
- function transformModuleInfo(info, option) {
573
- return {
574
- get ast() {
575
- return unsupported("ModuleInfo#ast");
576
- },
577
- get code() {
578
- return info.code;
579
- },
580
- id: info.id,
581
- importers: info.importers,
582
- dynamicImporters: info.dynamicImporters,
583
- importedIds: info.importedIds,
584
- dynamicallyImportedIds: info.dynamicallyImportedIds,
585
- isEntry: info.isEntry,
586
- ...option
587
- };
588
- }
589
-
590
- //#endregion
591
- //#region src/log/logging.ts
592
- const LogLevelSchema = ((z.literal("info")).or(z.literal("debug"))).or(z.literal("warn"));
593
- const LogLevelWithErrorSchema = LogLevelSchema.or(z.literal("error"));
594
- const LogLevelOptionSchema = LogLevelSchema.or(z.literal("silent"));
595
- const LOG_LEVEL_SILENT = "silent";
596
- const LOG_LEVEL_ERROR = "error";
597
- const LOG_LEVEL_WARN = "warn";
598
- const LOG_LEVEL_INFO = "info";
599
- const LOG_LEVEL_DEBUG = "debug";
600
- const logLevelPriority = {
601
- [LOG_LEVEL_DEBUG]: 0,
602
- [LOG_LEVEL_INFO]: 1,
603
- [LOG_LEVEL_WARN]: 2,
604
- [LOG_LEVEL_SILENT]: 3
605
- };
606
- const RollupLogSchema = z.any();
607
- const RollupLogWithStringSchema = RollupLogSchema.or(z.string());
608
-
609
- //#endregion
610
- //#region src/utils/code-frame.ts
611
- function spaces(index) {
612
- let result = "";
613
- while (index--) result += " ";
614
- return result;
615
- }
616
- function tabsToSpaces(value) {
617
- return value.replace(/^\t+/, (match) => (match.split(" ")).join(" "));
618
- }
619
- const LINE_TRUNCATE_LENGTH = 120;
620
- const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
621
- const ELLIPSIS = "...";
622
- function getCodeFrame(source, line, column) {
623
- let lines = source.split("\n");
624
- if (line > lines.length) return "";
625
- const maxLineLength = Math.max((tabsToSpaces(lines[line - 1].slice(0, column))).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
626
- const frameStart = Math.max(0, line - 3);
627
- let frameEnd = Math.min(line + 2, lines.length);
628
- lines = lines.slice(frameStart, frameEnd);
629
- while (!/\S/.test(lines[lines.length - 1])) {
630
- lines.pop();
631
- frameEnd -= 1;
632
- }
633
- const digits = (String(frameEnd)).length;
634
- return (lines.map((sourceLine, index) => {
635
- const isErrorLine = frameStart + index + 1 === line;
636
- let lineNumber = String(index + frameStart + 1);
637
- while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
638
- let displayedLine = tabsToSpaces(sourceLine);
639
- if (displayedLine.length > maxLineLength) {
640
- displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
641
- }
642
- if (isErrorLine) {
643
- const indicator = spaces(digits + 2 + (tabsToSpaces(sourceLine.slice(0, column))).length) + "^";
644
- return `${lineNumber}: ${displayedLine}\n${indicator}`;
645
- }
646
- return `${lineNumber}: ${displayedLine}`;
647
- })).join("\n");
648
- }
649
-
650
- //#endregion
651
- //#region ../../node_modules/.pnpm/locate-character@3.0.0/node_modules/locate-character/src/index.js
652
- function rangeContains(range, index) {
653
- return range.start <= index && index < range.end;
654
- }
655
- function getLocator(source, options = {}) {
656
- const { offsetLine: offsetLine = 0, offsetColumn: offsetColumn = 0 } = options;
657
- let start = 0;
658
- const ranges = (source.split("\n")).map((line, i$1) => {
659
- const end = start + line.length + 1;
660
- const range = {
661
- start,
662
- end,
663
- line: i$1
664
- };
665
- start = end;
666
- return range;
667
- });
668
- let i = 0;
669
- function locator(search, index) {
670
- if (typeof search === "string") {
671
- search = source.indexOf(search, index ?? 0);
672
- }
673
- if (search === -1) return undefined;
674
- let range = ranges[i];
675
- const d = search >= range.end ? 1 : -1;
676
- while (range) {
677
- if (rangeContains(range, search)) {
678
- return {
679
- line: offsetLine + range.line,
680
- column: offsetColumn + search - range.start,
681
- character: search
682
- };
683
- }
684
- i += d;
685
- range = ranges[i];
686
- }
687
- }
688
- return locator;
689
- }
690
- function locate(source, search, options) {
691
- return getLocator(source, options)(search, options && options.startIndex);
692
- }
693
-
694
- //#endregion
695
- //#region src/log/logs.ts
696
- const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR";
697
- function logInvalidLogPosition(pluginName) {
698
- return {
699
- code: INVALID_LOG_POSITION,
700
- message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
701
- };
702
- }
703
- function logPluginError(error$1, plugin, { hook: hook, id: id } = {}) {
704
- const code = error$1.code;
705
- if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) {
706
- error$1.pluginCode = code;
707
- }
708
- error$1.code = PLUGIN_ERROR;
709
- error$1.plugin = plugin;
710
- if (hook) {
711
- error$1.hook = hook;
712
- }
713
- if (id) {
714
- error$1.id = id;
715
- }
716
- return error$1;
717
- }
718
- function error(base) {
719
- if (!(base instanceof Error)) {
720
- base = Object.assign(new Error(base.message), base);
721
- Object.defineProperty(base, "name", {
722
- value: "RollupError",
723
- writable: true
724
- });
725
- }
726
- throw base;
727
- }
728
- function augmentCodeLocation(properties, pos, source, id) {
729
- if (typeof pos === "object") {
730
- const { line: line, column: column } = pos;
731
- properties.loc = {
732
- column,
733
- file: id,
734
- line
735
- };
736
- } else {
737
- properties.pos = pos;
738
- const location = locate(source, pos, {offsetLine: 1});
739
- if (!location) {
740
- return;
741
- }
742
- const { line: line, column: column } = location;
743
- properties.loc = {
744
- column,
745
- file: id,
746
- line
747
- };
748
- }
749
- if (properties.frame === undefined) {
750
- const { line: line, column: column } = properties.loc;
751
- properties.frame = getCodeFrame(source, line, column);
752
- }
753
- }
754
-
755
- //#endregion
756
- //#region src/log/logHandler.ts
757
- const normalizeLog = (log) => typeof log === "string" ? {message: log} : typeof log === "function" ? normalizeLog(log()) : log;
758
- function getLogHandler(level, code, logger, pluginName, logLevel) {
759
- if (logLevelPriority[level] < logLevelPriority[logLevel]) {
760
- return noop;
761
- }
762
- return (log, pos) => {
763
- if (pos != null) {
764
- logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
765
- }
766
- log = normalizeLog(log);
767
- if (log.code && !log.pluginCode) {
768
- log.pluginCode = log.code;
769
- }
770
- log.code = code;
771
- log.plugin = pluginName;
772
- logger(level, log);
773
- };
774
- }
775
-
776
- //#endregion
777
- //#region src/options/utils.ts
778
- function normalizedStringOrRegex(pattern) {
779
- if (!pattern) {
780
- return undefined;
781
- }
782
- if (!Array.isArray(pattern)) {
783
- pattern = [pattern];
784
- }
785
- return pattern;
786
- }
787
-
788
- //#endregion
789
- //#region src/options/normalized-ecma-transform-plugin-config.ts
790
- function normalizeEcmaTransformPluginConfig(config) {
791
- if (!config) {
792
- return undefined;
793
- }
794
- let normalizedConfig = {
795
- jsxInject: config?.jsxInject,
796
- exclude: normalizedStringOrRegex(config.exclude),
797
- include: normalizedStringOrRegex(config.include),
798
- targets: config.targets
799
- };
800
- return normalizedConfig;
801
- }
802
-
803
- //#endregion
804
- //#region src/plugin/builtin-plugin.ts
805
- var import_binding$6 = __toESM(require_binding());
806
- class BuiltinPlugin {
807
- constructor(name, options) {
808
- this.name = name;
809
- this.options = options;
810
- this.name = name;
811
- this.options = options;
812
- }
813
- }
814
- class ModulePreloadPolyfillPlugin extends BuiltinPlugin {
815
- constructor(config) {
816
- super(import_binding$6.BindingBuiltinPluginName.ModulePreloadPolyfillPlugin, config);
817
- }
818
- }
819
- class DynamicImportVarsPlugin extends BuiltinPlugin {
820
- constructor() {
821
- super(import_binding$6.BindingBuiltinPluginName.DynamicImportVarsPlugin);
822
- }
823
- }
824
- class ImportGlobPlugin extends BuiltinPlugin {
825
- constructor(config) {
826
- super(import_binding$6.BindingBuiltinPluginName.ImportGlobPlugin, config);
827
- }
828
- }
829
- class ManifestPlugin extends BuiltinPlugin {
830
- constructor(config) {
831
- super(import_binding$6.BindingBuiltinPluginName.ManifestPlugin, config);
832
- }
833
- }
834
- class WasmHelperPlugin extends BuiltinPlugin {
835
- constructor() {
836
- super(import_binding$6.BindingBuiltinPluginName.WasmHelperPlugin);
837
- }
838
- }
839
- class WasmFallbackPlugin extends BuiltinPlugin {
840
- constructor() {
841
- super(import_binding$6.BindingBuiltinPluginName.WasmFallbackPlugin);
842
- }
843
- }
844
- class LoadFallbackPlugin extends BuiltinPlugin {
845
- constructor() {
846
- super(import_binding$6.BindingBuiltinPluginName.LoadFallbackPlugin);
847
- }
848
- }
849
- class AliasPlugin extends BuiltinPlugin {
850
- constructor(config) {
851
- super(import_binding$6.BindingBuiltinPluginName.AliasPlugin, config);
852
- }
853
- }
854
- class TransformPlugin extends BuiltinPlugin {
855
- constructor(config) {
856
- let normalizedConfig = normalizeEcmaTransformPluginConfig(config);
857
- super(import_binding$6.BindingBuiltinPluginName.TransformPlugin, normalizedConfig);
858
- }
859
- }
860
- class JsonPlugin extends BuiltinPlugin {
861
- constructor(config) {
862
- super(import_binding$6.BindingBuiltinPluginName.JsonPlugin, config);
863
- }
864
- }
865
- class BuildImportAnalysisPlugin extends BuiltinPlugin {
866
- constructor(config) {
867
- super(import_binding$6.BindingBuiltinPluginName.BuildImportAnalysisPlugin, config);
868
- }
869
- }
870
- class ReplacePlugin extends BuiltinPlugin {
871
- constructor(config) {
872
- super(import_binding$6.BindingBuiltinPluginName.ReplacePlugin, config);
873
- }
874
- }
875
- function modulePreloadPolyfillPlugin(config) {
876
- return new ModulePreloadPolyfillPlugin(config);
877
- }
878
- function dynamicImportVarsPlugin() {
879
- return new DynamicImportVarsPlugin();
880
- }
881
- function importGlobPlugin(config) {
882
- return new ImportGlobPlugin(config);
883
- }
884
- function manifestPlugin(config) {
885
- return new ManifestPlugin(config);
886
- }
887
- function wasmHelperPlugin() {
888
- return new WasmHelperPlugin();
889
- }
890
- function wasmFallbackPlugin() {
891
- return new WasmFallbackPlugin();
892
- }
893
- function transformPlugin(config) {
894
- return new TransformPlugin(config);
895
- }
896
- function loadFallbackPlugin() {
897
- return new LoadFallbackPlugin();
898
- }
899
- function aliasPlugin(config) {
900
- return new AliasPlugin(config);
901
- }
902
- function jsonPlugin(config) {
903
- return new JsonPlugin(config);
904
- }
905
- function buildImportAnalysisPlugin(config) {
906
- return new BuildImportAnalysisPlugin(config);
907
- }
908
- function replacePlugin(values = {}, options = {}) {
909
- return new ReplacePlugin({
910
- ...options,
911
- values
912
- });
913
- }
914
- function bindingifyBuiltInPlugin(plugin) {
915
- return {
916
- __name: plugin.name,
917
- options: plugin.options
918
- };
919
- }
920
-
921
- //#endregion
922
- //#region src/plugin/plugin-driver.ts
923
- class PluginDriver {
924
- async callOptionsHook(inputOptions) {
925
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
926
- const plugins = getSortedPlugins("options", getObjectPlugins(inputOptions.plugins ?? []));
927
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
928
- for (const plugin of plugins) {
929
- const name = plugin.name || "unknown";
930
- const options = plugin.options;
931
- if (options) {
932
- const { handler: handler } = normalizeHook(options);
933
- const result = await handler.call({
934
- debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
935
- error: (e) => error(logPluginError(normalizeLog(e), name, {hook: "onLog"})),
936
- info: getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", logger, name, logLevel),
937
- meta: {
938
- rollupVersion: "4.23.0",
939
- rolldownVersion: VERSION,
940
- watchMode: false
941
- },
942
- warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
943
- }, inputOptions);
944
- if (result) {
945
- inputOptions = result;
946
- }
947
- }
948
- }
949
- return inputOptions;
950
- }
951
- callOutputOptionsHook(inputOptions, outputOptions) {
952
- const plugins = getSortedPlugins("outputOptions", getObjectPlugins(inputOptions.plugins));
953
- for (const plugin of plugins) {
954
- const options = plugin.outputOptions;
955
- if (options) {
956
- const { handler: handler } = normalizeHook(options);
957
- const result = handler.call(null, outputOptions);
958
- if (result) {
959
- outputOptions = result;
960
- }
961
- }
962
- }
963
- return outputOptions;
964
- }
965
- }
966
- function getObjectPlugins(plugins) {
967
- return plugins.filter((plugin) => {
968
- if ("_parallel"in plugin) {
969
- return undefined;
970
- }
971
- if (plugin instanceof BuiltinPlugin) {
972
- return undefined;
973
- }
974
- return plugin;
975
- });
976
- }
977
- function getSortedPlugins(hookName, plugins) {
978
- const pre = [];
979
- const normal = [];
980
- const post = [];
981
- for (const plugin of plugins) {
982
- const hook = plugin[hookName];
983
- if (hook) {
984
- if (typeof hook === "object") {
985
- if (hook.order === "pre") {
986
- pre.push(plugin);
987
- continue;
988
- }
989
- if (hook.order === "post") {
990
- post.push(plugin);
991
- continue;
992
- }
993
- }
994
- normal.push(plugin);
995
- }
996
- }
997
- return [...pre, ...normal, ...post];
998
- }
999
-
1000
- //#endregion
1001
- //#region src/log/logger.ts
1002
- class MinimalPluginContext {
1003
- debug;
1004
- info;
1005
- meta;
1006
- warn;
1007
- error;
1008
- constructor(options, plugin) {
1009
- const onLog = options.onLog;
1010
- const pluginName = plugin.name || "unknown";
1011
- const logLevel = options.logLevel;
1012
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
1013
- this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
1014
- this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
1015
- this.error = (e) => {
1016
- return error(logPluginError(normalizeLog(e), pluginName));
1017
- };
1018
- this.meta = {
1019
- rollupVersion: "4.23.0",
1020
- rolldownVersion: VERSION,
1021
- watchMode: false
1022
- };
1023
- }
1024
- }
1025
- function getLogger(plugins, onLog, logLevel) {
1026
- const minimalPriority = logLevelPriority[logLevel];
1027
- const logger = (level, log, skipped = new Set()) => {
1028
- const logPriority = logLevelPriority[level];
1029
- if (logPriority < minimalPriority) {
1030
- return;
1031
- }
1032
- for (const plugin of getSortedPlugins("onLog", plugins)) {
1033
- if (skipped.has(plugin)) continue;
1034
- const { onLog: pluginOnLog } = plugin;
1035
- if (pluginOnLog) {
1036
- const getLogHandler$1 = (level$1) => {
1037
- if (logLevelPriority[level$1] < minimalPriority) {
1038
- return () => {};
1039
- }
1040
- return (log$1) => logger(level$1, normalizeLog(log$1), (new Set(skipped)).add(plugin));
1041
- };
1042
- const handler = "handler"in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
1043
- if (handler.call({
1044
- debug: getLogHandler$1(LOG_LEVEL_DEBUG),
1045
- error: (log$1) => error(normalizeLog(log$1)),
1046
- info: getLogHandler$1(LOG_LEVEL_INFO),
1047
- meta: {
1048
- rollupVersion: "4.23.0",
1049
- rolldownVersion: VERSION,
1050
- watchMode: false
1051
- },
1052
- warn: getLogHandler$1(LOG_LEVEL_WARN)
1053
- }, level, log) === false) {
1054
- return;
1055
- }
1056
- }
1057
- }
1058
- onLog(level, log);
1059
- };
1060
- return logger;
1061
- }
1062
- const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
1063
- const { onwarn: onwarn, onLog: onLog } = config;
1064
- const defaultOnLog = getDefaultOnLog(printLog, onwarn);
1065
- if (onLog) {
1066
- const minimalPriority = logLevelPriority[logLevel];
1067
- return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
1068
- if (level$1 === LOG_LEVEL_ERROR) {
1069
- return error(normalizeLog(handledLog));
1070
- }
1071
- if (logLevelPriority[level$1] >= minimalPriority) {
1072
- defaultOnLog(level$1, normalizeLog(handledLog));
1073
- }
1074
- });
1075
- }
1076
- return defaultOnLog;
1077
- };
1078
- const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
1079
- if (level === LOG_LEVEL_WARN) {
1080
- onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
1081
- } else {
1082
- printLog(level, log);
1083
- }
1084
- } : printLog;
1085
- const addLogToString = (log) => {
1086
- Object.defineProperty(log, "toString", {
1087
- value: () => getExtendedLogMessage(log),
1088
- writable: true
1089
- });
1090
- return log;
1091
- };
1092
- const defaultPrintLog = (level, log) => {
1093
- const message = getExtendedLogMessage(log);
1094
- switch (level) {
1095
- case LOG_LEVEL_WARN: {
1096
- return console.warn(message);
1097
- }
1098
- case LOG_LEVEL_DEBUG: {
1099
- return console.debug(message);
1100
- }
1101
- default: {
1102
- return console.info(message);
1103
- }
1104
- }
1105
- };
1106
- const getExtendedLogMessage = (log) => {
1107
- let prefix = "";
1108
- if (log.plugin) {
1109
- prefix += `(${log.plugin} plugin) `;
1110
- }
1111
- if (log.loc) {
1112
- prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
1113
- }
1114
- return prefix + log.message;
1115
- };
1116
- function relativeId(id) {
1117
- if (!path$1.isAbsolute(id)) return id;
1118
- return path$1.relative(path$1.resolve(), id);
1119
- }
1120
-
1121
- //#endregion
1122
- //#region src/plugin/plugin-context.ts
1123
- class PluginContext extends MinimalPluginContext {
1124
- resolve;
1125
- emitFile;
1126
- getFileName;
1127
- getModuleInfo;
1128
- getModuleIds;
1129
- addWatchFile;
1130
- parse;
1131
- constructor(options, context, plugin, data) {
1132
- super(options, plugin);
1133
- this.resolve = async (source, importer, options$1) => {
1134
- let receipt = undefined;
1135
- if (options$1 != null) {
1136
- receipt = data.saveResolveOptions(options$1);
1137
- }
1138
- const res = await context.resolve(source, importer, {
1139
- custom: receipt,
1140
- skipSelf: options$1?.skipSelf
1141
- });
1142
- if (receipt != null) {
1143
- data.removeSavedResolveOptions(receipt);
1144
- }
1145
- if (res == null) return null;
1146
- const info = data.getModuleOption(res.id) || {};
1147
- return {
1148
- ...res,
1149
- ...info
1150
- };
1151
- };
1152
- this.emitFile = (file) => {
1153
- if (file.type !== "asset") {
1154
- return unimplemented("PluginContext.emitFile: only asset type is supported");
1155
- }
1156
- return context.emitFile({
1157
- ...file,
1158
- originalFileName: file.originalFileName || undefined,
1159
- source: bindingAssetSource(file.source)
1160
- });
1161
- };
1162
- this.getFileName = context.getFileName.bind(context);
1163
- this.getModuleInfo = (id) => data.getModuleInfo(id, context);
1164
- this.getModuleIds = () => data.getModuleIds(context);
1165
- this.parse = unsupported("`PluginContext#parse` is not supported by rolldown.");
1166
- this.addWatchFile = context.addWatchFile.bind(context);
1167
- }
1168
- }
1169
-
1170
- //#endregion
1171
- //#region src/plugin/transform-plugin-context.ts
1172
- class TransformPluginContext extends PluginContext {
1173
- error;
1174
- constructor(options, context, plugin, data, inner, moduleId, moduleSource) {
1175
- super(options, context, plugin, data);
1176
- const getLogHandler$1 = (handler) => (log, pos) => {
1177
- log = normalizeLog(log);
1178
- if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
1179
- log.id = moduleId;
1180
- log.hook = "transform";
1181
- handler(log);
1182
- };
1183
- this.debug = getLogHandler$1(this.debug);
1184
- this.warn = getLogHandler$1(this.warn);
1185
- this.info = getLogHandler$1(this.info);
1186
- this.error = (e, pos) => {
1187
- if (typeof e === "string") e = {message: e};
1188
- if (pos) augmentCodeLocation(e, pos, moduleSource, moduleId);
1189
- e.id = moduleId;
1190
- e.hook = "transform";
1191
- return error(logPluginError(normalizeLog(e), plugin.name || "unknown"));
1192
- };
1193
- }
1194
- }
1195
-
1196
- //#endregion
1197
- //#region src/utils/transform-side-effects.ts
1198
- var import_binding$5 = __toESM(require_binding());
1199
- function bindingifySideEffects(sideEffects) {
1200
- switch (sideEffects) {
1201
- case true: return import_binding$5.BindingHookSideEffects.True;
1202
- case false: return import_binding$5.BindingHookSideEffects.False;
1203
- case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
1204
- case null:
1205
- case undefined: return undefined;
1206
- default: throw new Error(`Unexpected side effects: ${sideEffects}`);
1207
- }
1208
- }
1209
-
1210
- //#endregion
1211
- //#region src/plugin/bindingify-plugin-hook-meta.ts
1212
- var import_binding$4 = __toESM(require_binding());
1213
- function bindingifyPluginHookMeta(options) {
1214
- return {order: bindingPluginOrder(options.order)};
1215
- }
1216
- function bindingPluginOrder(order) {
1217
- switch (order) {
1218
- case "post": return import_binding$4.BindingPluginOrder.Post;
1219
- case "pre": return import_binding$4.BindingPluginOrder.Pre;
1220
- case null:
1221
- case undefined: return undefined;
1222
- default: throw new Error(`Unknown plugin order: ${order}`);
1223
- }
1224
- }
1225
-
1226
- //#endregion
1227
- //#region src/constants/plugin-context.ts
1228
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
1229
-
1230
- //#endregion
1231
- //#region src/plugin/bindingify-hook-filter.ts
1232
- function bindingifyStringFilter(matcher) {
1233
- if (typeof matcher === "string" || matcher instanceof RegExp) {
1234
- return {include: [matcher]};
1235
- }
1236
- if (Array.isArray(matcher)) {
1237
- return {include: matcher};
1238
- }
1239
- return {
1240
- include: matcher.include ? arraify(matcher.include) : undefined,
1241
- exclude: matcher.exclude ? arraify(matcher.exclude) : undefined
1242
- };
1243
- }
1244
- function bindingifyResolveIdFilter(filterOption) {
1245
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
1246
- }
1247
- function bindingifyLoadFilter(filterOption) {
1248
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
1249
- }
1250
- function bindingifyTransformFilter(filterOption) {
1251
- if (!filterOption) {
1252
- return undefined;
1253
- }
1254
- const { id: id, code: code, moduleType: moduleType } = filterOption;
1255
- let moduleTypeRet;
1256
- if (moduleType) {
1257
- if (Array.isArray(moduleType)) {
1258
- moduleTypeRet = moduleType;
1259
- } else {
1260
- moduleTypeRet = moduleType.include;
1261
- }
1262
- }
1263
- return {
1264
- id: id ? bindingifyStringFilter(id) : undefined,
1265
- code: code ? bindingifyStringFilter(code) : undefined,
1266
- moduleType: moduleTypeRet
1267
- };
1268
- }
1269
-
1270
- //#endregion
1271
- //#region src/plugin/bindingify-build-hooks.ts
1272
- function bindingifyBuildStart(plugin, options, pluginContextData) {
1273
- const hook = plugin.buildStart;
1274
- if (!hook) {
1275
- return {};
1276
- }
1277
- const { handler: handler, meta: meta } = normalizeHook(hook);
1278
- return {
1279
- plugin: async (ctx) => {
1280
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), options);
1281
- },
1282
- meta: bindingifyPluginHookMeta(meta)
1283
- };
1284
- }
1285
- function bindingifyBuildEnd(plugin, options, pluginContextData) {
1286
- const hook = plugin.buildEnd;
1287
- if (!hook) {
1288
- return {};
1289
- }
1290
- const { handler: handler, meta: meta } = normalizeHook(hook);
1291
- return {
1292
- plugin: async (ctx, err) => {
1293
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), err ? new Error(err) : undefined);
1294
- },
1295
- meta: bindingifyPluginHookMeta(meta)
1296
- };
1297
- }
1298
- function bindingifyResolveId(plugin, normalizedOptions, pluginContextData) {
1299
- const hook = plugin.resolveId;
1300
- if (!hook) {
1301
- return {};
1302
- }
1303
- const { handler: handler, meta: meta, options: options } = normalizeHook(hook);
1304
- return {
1305
- plugin: async (ctx, specifier, importer, extraOptions) => {
1306
- const contextResolveOptions = extraOptions.custom != null ? pluginContextData.getSavedResolveOptions(extraOptions.custom) : undefined;
1307
- const newExtraOptions = {
1308
- ...extraOptions,
1309
- custom: contextResolveOptions?.custom,
1310
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
1311
- };
1312
- const ret = await handler.call(new PluginContext(normalizedOptions, ctx, plugin, pluginContextData), specifier, importer ?? undefined, newExtraOptions);
1313
- if (ret == null) {
1314
- return;
1315
- }
1316
- if (ret === false) {
1317
- return {
1318
- id: specifier,
1319
- external: true
1320
- };
1321
- }
1322
- if (typeof ret === "string") {
1323
- return {id: ret};
1324
- }
1325
- const result = {
1326
- id: ret.id,
1327
- external: ret.external
1328
- };
1329
- if (ret.moduleSideEffects !== null) {
1330
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
1331
- }
1332
- pluginContextData.updateModuleOption(ret.id, {
1333
- meta: ret.meta || {},
1334
- moduleSideEffects: ret.moduleSideEffects || null
1335
- });
1336
- return result;
1337
- },
1338
- meta: bindingifyPluginHookMeta(meta),
1339
- filter: bindingifyResolveIdFilter(options.filter)
1340
- };
1341
- }
1342
- function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
1343
- const hook = plugin.resolveDynamicImport;
1344
- if (!hook) {
1345
- return {};
1346
- }
1347
- const { handler: handler, meta: meta } = normalizeHook(hook);
1348
- return {
1349
- plugin: async (ctx, specifier, importer) => {
1350
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined);
1351
- if (ret == null) {
1352
- return;
1353
- }
1354
- if (ret === false) {
1355
- return {
1356
- id: specifier,
1357
- external: true
1358
- };
1359
- }
1360
- if (typeof ret === "string") {
1361
- return {id: ret};
1362
- }
1363
- const result = {
1364
- id: ret.id,
1365
- external: ret.external
1366
- };
1367
- if (ret.moduleSideEffects !== null) {
1368
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
1369
- }
1370
- pluginContextData.updateModuleOption(ret.id, {
1371
- meta: ret.meta || {},
1372
- moduleSideEffects: ret.moduleSideEffects || null
1373
- });
1374
- return result;
1375
- },
1376
- meta: bindingifyPluginHookMeta(meta)
1377
- };
1378
- }
1379
- function bindingifyTransform(plugin, normalizedOptions, pluginContextData) {
1380
- const hook = plugin.transform;
1381
- if (!hook) {
1382
- return {};
1383
- }
1384
- const { handler: handler, meta: meta, options: options } = normalizeHook(hook);
1385
- return {
1386
- plugin: async (ctx, code, id, meta$1) => {
1387
- const ret = await handler.call(new TransformPluginContext(normalizedOptions, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id, meta$1);
1388
- if (ret == null) {
1389
- return undefined;
1390
- }
1391
- if (typeof ret === "string") {
1392
- return {code: ret};
1393
- }
1394
- pluginContextData.updateModuleOption(id, {
1395
- meta: ret.meta || {},
1396
- moduleSideEffects: ret.moduleSideEffects || null
1397
- });
1398
- return {
1399
- code: ret.code,
1400
- map: bindingifySourcemap$1(ret.map),
1401
- sideEffects: bindingifySideEffects(ret.moduleSideEffects),
1402
- moduleType: ret.moduleType
1403
- };
1404
- },
1405
- meta: bindingifyPluginHookMeta(meta),
1406
- filter: bindingifyTransformFilter(options.filter)
1407
- };
1408
- }
1409
- function bindingifyLoad(plugin, normalized_options, pluginContextData) {
1410
- const hook = plugin.load;
1411
- if (!hook) {
1412
- return {};
1413
- }
1414
- const { handler: handler, meta: meta, options: options } = normalizeHook(hook);
1415
- return {
1416
- plugin: async (ctx, id) => {
1417
- const ret = await handler.call(new PluginContext(normalized_options, ctx, plugin, pluginContextData), id);
1418
- if (ret == null) {
1419
- return;
1420
- }
1421
- if (typeof ret === "string") {
1422
- return {code: ret};
1423
- }
1424
- if (!ret.map) {
1425
- return {
1426
- code: ret.code,
1427
- moduleType: ret.moduleType
1428
- };
1429
- }
1430
- let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
1431
- if (!isEmptySourcemapFiled(map.sources)) {
1432
- const directory = path.dirname(id) || ".";
1433
- const sourceRoot = map.sourceRoot || ".";
1434
- map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
1435
- }
1436
- const result = {
1437
- code: ret.code,
1438
- map: bindingifySourcemap$1(map),
1439
- moduleType: ret.moduleType
1440
- };
1441
- if (ret.moduleSideEffects !== null) {
1442
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
1443
- }
1444
- pluginContextData.updateModuleOption(id, {
1445
- meta: ret.meta || {},
1446
- moduleSideEffects: ret.moduleSideEffects || null
1447
- });
1448
- return result;
1449
- },
1450
- meta: bindingifyPluginHookMeta(meta),
1451
- filter: bindingifyLoadFilter(options.filter)
1452
- };
1453
- }
1454
- function bindingifyModuleParsed(plugin, options, pluginContextData) {
1455
- const hook = plugin.moduleParsed;
1456
- if (!hook) {
1457
- return {};
1458
- }
1459
- const { handler: handler, meta: meta } = normalizeHook(hook);
1460
- return {
1461
- plugin: async (ctx, moduleInfo) => {
1462
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), transformModuleInfo(moduleInfo, pluginContextData.moduleOptionMap.get(moduleInfo.id)));
1463
- },
1464
- meta: bindingifyPluginHookMeta(meta)
1465
- };
1466
- }
1467
-
1468
- //#endregion
1469
- //#region src/plugin/bindingify-output-hooks.ts
1470
- function bindingifyRenderStart(plugin, options, outputOptions, pluginContextData) {
1471
- const hook = plugin.renderStart;
1472
- if (!hook) {
1473
- return {};
1474
- }
1475
- const { handler: handler, meta: meta } = normalizeHook(hook);
1476
- return {
1477
- plugin: async (ctx) => {
1478
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, options);
1479
- },
1480
- meta: bindingifyPluginHookMeta(meta)
1481
- };
1482
- }
1483
- function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData) {
1484
- const hook = plugin.renderChunk;
1485
- if (!hook) {
1486
- return {};
1487
- }
1488
- const { handler: handler, meta: meta } = normalizeHook(hook);
1489
- return {
1490
- plugin: async (ctx, code, chunk) => {
1491
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), code, chunk, outputOptions);
1492
- if (ret == null) {
1493
- return;
1494
- }
1495
- if (typeof ret === "string") {
1496
- return {code: ret};
1497
- }
1498
- if (!ret.map) {
1499
- return {code: ret.code};
1500
- }
1501
- return {
1502
- code: ret.code,
1503
- map: bindingifySourcemap$1(ret.map)
1504
- };
1505
- },
1506
- meta: bindingifyPluginHookMeta(meta)
1507
- };
1508
- }
1509
- function bindingifyAugmentChunkHash(plugin, options, pluginContextData) {
1510
- const hook = plugin.augmentChunkHash;
1511
- if (!hook) {
1512
- return {};
1513
- }
1514
- const { handler: handler, meta: meta } = normalizeHook(hook);
1515
- return {
1516
- plugin: async (ctx, chunk) => {
1517
- return await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1518
- },
1519
- meta: bindingifyPluginHookMeta(meta)
1520
- };
1521
- }
1522
- function bindingifyRenderError(plugin, options, pluginContextData) {
1523
- const hook = plugin.renderError;
1524
- if (!hook) {
1525
- return {};
1526
- }
1527
- const { handler: handler, meta: meta } = normalizeHook(hook);
1528
- return {
1529
- plugin: async (ctx, err) => {
1530
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), new Error(err));
1531
- },
1532
- meta: bindingifyPluginHookMeta(meta)
1533
- };
1534
- }
1535
- function bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData) {
1536
- const hook = plugin.generateBundle;
1537
- if (!hook) {
1538
- return {};
1539
- }
1540
- const { handler: handler, meta: meta } = normalizeHook(hook);
1541
- return {
1542
- plugin: async (ctx, bundle, isWrite) => {
1543
- const changed = {
1544
- updated: new Set(),
1545
- deleted: new Set()
1546
- };
1547
- const output = transformToOutputBundle(bundle, changed);
1548
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, output, isWrite);
1549
- return collectChangedBundle(changed, output);
1550
- },
1551
- meta: bindingifyPluginHookMeta(meta)
1552
- };
1553
- }
1554
- function bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData) {
1555
- const hook = plugin.writeBundle;
1556
- if (!hook) {
1557
- return {};
1558
- }
1559
- const { handler: handler, meta: meta } = normalizeHook(hook);
1560
- return {
1561
- plugin: async (ctx, bundle) => {
1562
- const changed = {
1563
- updated: new Set(),
1564
- deleted: new Set()
1565
- };
1566
- const output = transformToOutputBundle(bundle, changed);
1567
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, output);
1568
- return collectChangedBundle(changed, output);
1569
- },
1570
- meta: bindingifyPluginHookMeta(meta)
1571
- };
1572
- }
1573
- function bindingifyCloseBundle(plugin, options, pluginContextData) {
1574
- const hook = plugin.closeBundle;
1575
- if (!hook) {
1576
- return {};
1577
- }
1578
- const { handler: handler, meta: meta } = normalizeHook(hook);
1579
- return {
1580
- plugin: async (ctx) => {
1581
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData));
1582
- },
1583
- meta: bindingifyPluginHookMeta(meta)
1584
- };
1585
- }
1586
- function bindingifyBanner(plugin, options, pluginContextData) {
1587
- const hook = plugin.banner;
1588
- if (!hook) {
1589
- return {};
1590
- }
1591
- const { handler: handler, meta: meta } = normalizeHook(hook);
1592
- return {
1593
- plugin: async (ctx, chunk) => {
1594
- if (typeof handler === "string") {
1595
- return handler;
1596
- }
1597
- return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1598
- },
1599
- meta: bindingifyPluginHookMeta(meta)
1600
- };
1601
- }
1602
- function bindingifyFooter(plugin, options, pluginContextData) {
1603
- const hook = plugin.footer;
1604
- if (!hook) {
1605
- return {};
1606
- }
1607
- const { handler: handler, meta: meta } = normalizeHook(hook);
1608
- return {
1609
- plugin: async (ctx, chunk) => {
1610
- if (typeof handler === "string") {
1611
- return handler;
1612
- }
1613
- return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1614
- },
1615
- meta: bindingifyPluginHookMeta(meta)
1616
- };
1617
- }
1618
- function bindingifyIntro(plugin, options, pluginContextData) {
1619
- const hook = plugin.intro;
1620
- if (!hook) {
1621
- return {};
1622
- }
1623
- const { handler: handler, meta: meta } = normalizeHook(hook);
1624
- return {
1625
- plugin: async (ctx, chunk) => {
1626
- if (typeof handler === "string") {
1627
- return handler;
1628
- }
1629
- return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1630
- },
1631
- meta: bindingifyPluginHookMeta(meta)
1632
- };
1633
- }
1634
- function bindingifyOutro(plugin, options, pluginContextData) {
1635
- const hook = plugin.outro;
1636
- if (!hook) {
1637
- return {};
1638
- }
1639
- const { handler: handler, meta: meta } = normalizeHook(hook);
1640
- return {
1641
- plugin: async (ctx, chunk) => {
1642
- if (typeof handler === "string") {
1643
- return handler;
1644
- }
1645
- return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1646
- },
1647
- meta: bindingifyPluginHookMeta(meta)
1648
- };
1649
- }
1650
-
1651
- //#endregion
1652
- //#region src/plugin/bindingify-watch-hooks.ts
1653
- function bindingifyWatchChange(plugin, options, pluginContextData) {
1654
- const hook = plugin.watchChange;
1655
- if (!hook) {
1656
- return {};
1657
- }
1658
- const { handler: handler, meta: meta } = normalizeHook(hook);
1659
- return {
1660
- plugin: async (ctx, id, event) => {
1661
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), id, {event: event});
1662
- },
1663
- meta: bindingifyPluginHookMeta(meta)
1664
- };
1665
- }
1666
- function bindingifyCloseWatcher(plugin, options, pluginContextData) {
1667
- const hook = plugin.closeWatcher;
1668
- if (!hook) {
1669
- return {};
1670
- }
1671
- const { handler: handler, meta: meta } = normalizeHook(hook);
1672
- return {
1673
- plugin: async (ctx) => {
1674
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData));
1675
- },
1676
- meta: bindingifyPluginHookMeta(meta)
1677
- };
1678
- }
1679
-
1680
- //#endregion
1681
- //#region src/plugin/bindingify-plugin.ts
1682
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData) {
1683
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(plugin, options, pluginContextData);
1684
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(plugin, options, pluginContextData);
1685
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(plugin, options, pluginContextData);
1686
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(plugin, options, pluginContextData);
1687
- const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(plugin, options, pluginContextData);
1688
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(plugin, options, pluginContextData);
1689
- const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(plugin, options, pluginContextData);
1690
- const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData);
1691
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(plugin, options, pluginContextData);
1692
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(plugin, options, outputOptions, pluginContextData);
1693
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(plugin, options, pluginContextData);
1694
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData);
1695
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData);
1696
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(plugin, options, pluginContextData);
1697
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(plugin, options, pluginContextData);
1698
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(plugin, options, pluginContextData);
1699
- const { plugin: intro, meta: introMeta } = bindingifyIntro(plugin, options, pluginContextData);
1700
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(plugin, options, pluginContextData);
1701
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(plugin, options, pluginContextData);
1702
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(plugin, options, pluginContextData);
1703
- return {
1704
- name: plugin.name ?? "unknown",
1705
- buildStart,
1706
- buildStartMeta,
1707
- resolveId,
1708
- resolveIdMeta,
1709
- resolveIdFilter,
1710
- resolveDynamicImport,
1711
- resolveDynamicImportMeta,
1712
- buildEnd,
1713
- buildEndMeta,
1714
- transform,
1715
- transformMeta,
1716
- transformFilter,
1717
- moduleParsed,
1718
- moduleParsedMeta,
1719
- load,
1720
- loadMeta,
1721
- loadFilter,
1722
- renderChunk,
1723
- renderChunkMeta,
1724
- augmentChunkHash,
1725
- augmentChunkHashMeta,
1726
- renderStart,
1727
- renderStartMeta,
1728
- renderError,
1729
- renderErrorMeta,
1730
- generateBundle,
1731
- generateBundleMeta,
1732
- writeBundle,
1733
- writeBundleMeta,
1734
- closeBundle,
1735
- closeBundleMeta,
1736
- banner,
1737
- bannerMeta,
1738
- footer,
1739
- footerMeta,
1740
- intro,
1741
- introMeta,
1742
- outro,
1743
- outroMeta,
1744
- watchChange,
1745
- watchChangeMeta,
1746
- closeWatcher,
1747
- closeWatcherMeta
1748
- };
1749
- }
1750
-
1751
- //#endregion
1752
- //#region src/plugin/plugin-context-data.ts
1753
- class PluginContextData {
1754
- modules = new Map();
1755
- moduleIds = null;
1756
- moduleOptionMap = new Map();
1757
- resolveOptionsMap = new Map();
1758
- updateModuleOption(id, option) {
1759
- const existing = this.moduleOptionMap.get(id);
1760
- if (existing) {
1761
- Object.assign(existing, option);
1762
- if (option.meta != null) {
1763
- Object.assign(existing.meta, option.meta);
1764
- }
1765
- } else {
1766
- this.moduleOptionMap.set(id, option);
1767
- }
1768
- }
1769
- getModuleOption(id) {
1770
- return this.moduleOptionMap.get(id);
1771
- }
1772
- getModuleInfo(id, context) {
1773
- if (this.modules.has(id)) {
1774
- return this.modules.get(id) ?? null;
1775
- }
1776
- const bindingInfo = context.getModuleInfo(id);
1777
- if (bindingInfo) {
1778
- const info = transformModuleInfo(bindingInfo, this.moduleOptionMap.get(id));
1779
- this.modules.set(id, info);
1780
- return info;
1781
- }
1782
- return null;
1783
- }
1784
- getModuleIds(context) {
1785
- if (this.moduleIds) {
1786
- return this.moduleIds.values();
1787
- }
1788
- const moduleIds = context.getModuleIds();
1789
- if (moduleIds) {
1790
- this.moduleIds = moduleIds;
1791
- return moduleIds.values();
1792
- }
1793
- return [].values();
1794
- }
1795
- saveResolveOptions(options) {
1796
- const index = this.resolveOptionsMap.size;
1797
- this.resolveOptionsMap.set(index, options);
1798
- return index;
1799
- }
1800
- getSavedResolveOptions(receipt) {
1801
- return this.resolveOptionsMap.get(receipt);
1802
- }
1803
- removeSavedResolveOptions(receipt) {
1804
- this.resolveOptionsMap.delete(receipt);
1805
- }
1806
- }
1807
-
1808
- //#endregion
1809
- //#region src/options/bindingify-input-options.ts
1810
- var import_binding$3 = __toESM(require_binding());
1811
- function bindingifyInputOptions(options, outputOptions) {
1812
- const pluginContextData = new PluginContextData();
1813
- return {
1814
- input: bindingifyInput(options.input),
1815
- plugins: options.plugins.map((plugin) => {
1816
- if ("_parallel"in plugin) {
1817
- return undefined;
1818
- }
1819
- if (plugin instanceof BuiltinPlugin) {
1820
- return bindingifyBuiltInPlugin(plugin);
1821
- }
1822
- return bindingifyPlugin(plugin, options, outputOptions, pluginContextData);
1823
- }),
1824
- cwd: options.cwd ?? process.cwd(),
1825
- external: options.external ? function bindingifyExternal() {
1826
- const external = options.external;
1827
- if (typeof external === "function") {
1828
- return (id, importer, isResolved) => {
1829
- if (id.startsWith("\0")) return false;
1830
- return external(id, importer, isResolved) ?? false;
1831
- };
1832
- }
1833
- const externalArr = arraify(external);
1834
- return (id, _importer, _isResolved) => {
1835
- return externalArr.some((pat) => {
1836
- if (pat instanceof RegExp) {
1837
- return pat.test(id);
1838
- }
1839
- return id === pat;
1840
- });
1841
- };
1842
- }() : undefined,
1843
- resolve: options.resolve ? function bindingifyResolve() {
1844
- const { alias: alias, extensionAlias: extensionAlias,...rest } = options.resolve;
1845
- return {
1846
- alias: alias ? (Object.entries(alias)).map(([name, replacement]) => ({
1847
- find: name,
1848
- replacements: [replacement]
1849
- })) : undefined,
1850
- extensionAlias: extensionAlias ? (Object.entries(extensionAlias)).map(([name, value]) => ({
1851
- target: name,
1852
- replacements: value
1853
- })) : undefined,
1854
- ...rest
1855
- };
1856
- }() : undefined,
1857
- platform: options.platform,
1858
- shimMissingExports: options.shimMissingExports,
1859
- logLevel: bindingifyLogLevel(options.logLevel),
1860
- onLog: (level, log) => {
1861
- options.onLog(level, {
1862
- code: log.code,
1863
- message: log.message
1864
- });
1865
- },
1866
- treeshake: options.treeshake,
1867
- moduleTypes: options.moduleTypes,
1868
- define: options.define ? Object.entries(options.define) : undefined,
1869
- inject: options.inject ? (Object.entries(options.inject)).map(([alias, item]) => {
1870
- if (Array.isArray(item)) {
1871
- if (item[1] === "*") {
1872
- return {
1873
- tagNamespace: true,
1874
- alias,
1875
- from: item[0]
1876
- };
1877
- }
1878
- return {
1879
- tagNamed: true,
1880
- alias,
1881
- from: item[0],
1882
- imported: item[1]
1883
- };
1884
- } else {
1885
- return {
1886
- tagNamed: true,
1887
- imported: "default",
1888
- alias,
1889
- from: item
1890
- };
1891
- }
1892
- }) : undefined,
1893
- experimental: {
1894
- strictExecutionOrder: options.experimental?.strictExecutionOrder,
1895
- disableLiveBindings: options.experimental?.disableLiveBindings
1896
- },
1897
- profilerNames: options?.profilerNames,
1898
- jsx: bindingifyJsx(options.jsx),
1899
- watch: bindingifyWatch(options.watch)
1900
- };
1901
- }
1902
- function bindingifyLogLevel(logLevel) {
1903
- switch (logLevel) {
1904
- case "silent": return import_binding$3.BindingLogLevel.Silent;
1905
- case "warn": return import_binding$3.BindingLogLevel.Warn;
1906
- case "info": return import_binding$3.BindingLogLevel.Info;
1907
- case "debug": return import_binding$3.BindingLogLevel.Debug;
1908
- default: throw new Error(`Unexpected log level: ${logLevel}`);
1909
- }
1910
- }
1911
- function bindingifyInput(input) {
1912
- if (Array.isArray(input)) {
1913
- return input.map((src) => {
1914
- return {import: src};
1915
- });
1916
- } else {
1917
- return (Object.entries(input)).map((value) => {
1918
- return {
1919
- name: value[0],
1920
- import: value[1]
1921
- };
1922
- });
1923
- }
1924
- }
1925
- function bindingifyJsx(input) {
1926
- if (input) {
1927
- const mode = input.mode ?? "classic";
1928
- return {
1929
- runtime: mode,
1930
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
1931
- pragma: input.factory,
1932
- pragmaFrag: input.fragment,
1933
- development: input.development,
1934
- refresh: input.refresh
1935
- };
1936
- }
1937
- }
1938
- function bindingifyWatch(watch$1) {
1939
- if (watch$1) {
1940
- let value = {
1941
- skipWrite: watch$1.skipWrite,
1942
- include: normalizedStringOrRegex(watch$1.include),
1943
- exclude: normalizedStringOrRegex(watch$1.exclude)
1944
- };
1945
- if (watch$1.notify) {
1946
- value.notify = {
1947
- pollInterval: watch$1.notify.pollInterval,
1948
- compareContents: watch$1.notify.compareContents
1949
- };
1950
- }
1951
- if (watch$1.chokidar) {
1952
- unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
1953
- }
1954
- return value;
1955
- }
1956
- }
1957
-
1958
- //#endregion
1959
- //#region src/utils/initialize-parallel-plugins.ts
1960
- var import_binding$2 = __toESM(require_binding());
1961
- async function initializeParallelPlugins(plugins) {
1962
- const pluginInfos = [];
1963
- for (const [index, plugin] of plugins.entries()) {
1964
- if ("_parallel"in plugin) {
1965
- const { fileUrl: fileUrl, options: options } = plugin._parallel;
1966
- pluginInfos.push({
1967
- index,
1968
- fileUrl,
1969
- options
1970
- });
1971
- }
1972
- }
1973
- if (pluginInfos.length <= 0) {
1974
- return undefined;
1975
- }
1976
- const count = Math.min(availableParallelism(), 8);
1977
- const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
1978
- const registryId = parallelJsPluginRegistry.id;
1979
- const workers = await initializeWorkers(registryId, count, pluginInfos);
1980
- const stopWorkers = async () => {
1981
- await Promise.all(workers.map((worker) => worker.terminate()));
1982
- };
1983
- return {
1984
- registry: parallelJsPluginRegistry,
1985
- stopWorkers
1986
- };
1987
- }
1988
- function initializeWorkers(registryId, count, pluginInfos) {
1989
- return Promise.all(Array.from({length: count}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
1990
- }
1991
- async function initializeWorker(registryId, pluginInfos, threadNumber) {
1992
- const urlString = undefined("#parallel-plugin-worker");
1993
- const workerData = {
1994
- registryId,
1995
- pluginInfos,
1996
- threadNumber
1997
- };
1998
- let worker;
1999
- try {
2000
- worker = new Worker(new URL(urlString), {workerData});
2001
- worker.unref();
2002
- await new Promise((resolve, reject) => {
2003
- worker.once("message", async (message) => {
2004
- if (message.type === "error") {
2005
- reject(message.error);
2006
- } else {
2007
- resolve();
2008
- }
2009
- });
2010
- });
2011
- return worker;
2012
- } catch (e) {
2013
- worker?.terminate();
2014
- throw e;
2015
- }
2016
- }
2017
-
2018
- //#endregion
2019
- //#region src/utils/async-flatten.ts
2020
- async function asyncFlatten(array) {
2021
- do {
2022
- array = (await Promise.all(array)).flat(Infinity);
2023
- } while (array.some((v) => v?.then));
2024
- return array;
2025
- }
2026
-
2027
- //#endregion
2028
- //#region src/utils/normalize-plugin-option.ts
2029
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
2030
-
2031
- //#endregion
2032
- //#region src/utils/normalize-tree-shake.ts
2033
- function normalizeTreeshakeOptions(config) {
2034
- if (config === false) {
2035
- return undefined;
2036
- }
2037
- if (config === true || config === undefined) {
2038
- return {moduleSideEffects: "true"};
2039
- }
2040
- let normalizedConfig = {moduleSideEffects: ""};
2041
- if (config.moduleSideEffects === undefined) {
2042
- normalizedConfig.moduleSideEffects = "true";
2043
- } else if (isRegExp(config.moduleSideEffects)) {
2044
- normalizedConfig.moduleSideEffects = config.moduleSideEffects.source;
2045
- } else {
2046
- normalizedConfig.moduleSideEffects = config.moduleSideEffects.toString();
2047
- }
2048
- return normalizedConfig;
2049
- }
2050
-
2051
- //#endregion
2052
- //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-K26VP6CL.js
2053
- function u$1(t$1, n, a) {
2054
- let o = (r) => t$1(r, ...n);
2055
- return a === void 0 ? o : Object.assign(o, {
2056
- lazy: a,
2057
- lazyArgs: n
2058
- });
2059
- }
2060
-
2061
- //#endregion
2062
- //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-RAAYCPUM.js
2063
- function u(r, n, a) {
2064
- let o = r.length - n.length;
2065
- if (o === 0) return r(...n);
2066
- if (o === 1) return u$1(r, n, a);
2067
- throw new Error("Wrong number of arguments");
2068
- }
2069
-
2070
- //#endregion
2071
- //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-NMJS7ULY.js
2072
- function t(...n) {
2073
- return u(Object.keys, n);
2074
- }
2075
-
2076
- //#endregion
2077
- //#region src/constants/plugin.ts
2078
- const ENUMERATED_PLUGIN_HOOK_NAMES = ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "augmentChunkHash", "buildEnd", "onLog", "resolveDynamicImport", "generateBundle", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "footer", "banner", "intro", "outro", "closeBundle", "watchChange", "closeWatcher",];
2079
- const DEFINED_HOOK_NAMES = {
2080
- [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
2081
- [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
2082
- [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
2083
- [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
2084
- [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
2085
- [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
2086
- [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
2087
- [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
2088
- [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
2089
- [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
2090
- [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
2091
- [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
2092
- [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
2093
- [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
2094
- [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
2095
- [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
2096
- [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
2097
- [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
2098
- [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
2099
- [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
2100
- [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
2101
- [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
2102
- [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
2103
- };
2104
-
2105
- //#endregion
2106
- //#region src/utils/plugin/index.ts
2107
- const isPluginHookName = function() {
2108
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
2109
- return function isPluginHookName$1(hookName) {
2110
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
2111
- };
2112
- }();
2113
-
2114
- //#endregion
2115
- //#region src/utils/compose-js-plugins.ts
2116
- const unsupportedHookName = ["augmentChunkHash", "generateBundle", "moduleParsed", "onLog", "options", "outputOptions", "renderError", "renderStart", "resolveDynamicImport", "writeBundle",];
2117
- const unsupportedHooks = new Set(unsupportedHookName);
2118
- function isUnsupportedHooks(hookName) {
2119
- return unsupportedHooks.has(hookName);
2120
- }
2121
- function createComposedPlugin(plugins) {
2122
- const names = [];
2123
- const batchedHooks = {};
2124
- plugins.forEach((plugin, index) => {
2125
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
2126
- names.push(pluginName);
2127
- (t(plugin)).forEach((pluginProp) => {
2128
- if (isUnsupportedHooks(pluginProp)) {
2129
- throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
2130
- }
2131
- if (!isPluginHookName(pluginProp)) {
2132
- return;
2133
- }
2134
- switch (pluginProp) {
2135
- case "buildStart": {
2136
- const handlers = batchedHooks.buildStart ?? [];
2137
- batchedHooks.buildStart = handlers;
2138
- if (plugin.buildStart) {
2139
- handlers.push([plugin.buildStart, plugin]);
2140
- }
2141
- break;
2142
- }
2143
- case "load": {
2144
- const handlers = batchedHooks.load ?? [];
2145
- batchedHooks.load = handlers;
2146
- if (plugin.load) {
2147
- handlers.push([plugin.load, plugin]);
2148
- }
2149
- break;
2150
- }
2151
- case "transform": {
2152
- const handlers = batchedHooks.transform ?? [];
2153
- batchedHooks.transform = handlers;
2154
- if (plugin.transform) {
2155
- handlers.push([plugin.transform, plugin]);
2156
- }
2157
- break;
2158
- }
2159
- case "resolveId": {
2160
- const handlers = batchedHooks.resolveId ?? [];
2161
- batchedHooks.resolveId = handlers;
2162
- if (plugin.resolveId) {
2163
- handlers.push([plugin.resolveId, plugin]);
2164
- }
2165
- break;
2166
- }
2167
- case "buildEnd": {
2168
- const handlers = batchedHooks.buildEnd ?? [];
2169
- batchedHooks.buildEnd = handlers;
2170
- if (plugin.buildEnd) {
2171
- handlers.push([plugin.buildEnd, plugin]);
2172
- }
2173
- break;
2174
- }
2175
- case "renderChunk": {
2176
- const handlers = batchedHooks.renderChunk ?? [];
2177
- batchedHooks.renderChunk = handlers;
2178
- if (plugin.renderChunk) {
2179
- handlers.push([plugin.renderChunk, plugin]);
2180
- }
2181
- break;
2182
- }
2183
- case "banner":
2184
- case "footer":
2185
- case "intro":
2186
- case "outro": {
2187
- const hook = plugin[pluginProp];
2188
- if (hook) {
2189
- ;
2190
- (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
2191
- }
2192
- break;
2193
- }
2194
- case "closeBundle": {
2195
- const handlers = batchedHooks.closeBundle ?? [];
2196
- batchedHooks.closeBundle = handlers;
2197
- if (plugin.closeBundle) {
2198
- handlers.push([plugin.closeBundle, plugin]);
2199
- }
2200
- break;
2201
- }
2202
- case "watchChange": {
2203
- const handlers = batchedHooks.watchChange ?? [];
2204
- batchedHooks.watchChange = handlers;
2205
- if (plugin.watchChange) {
2206
- handlers.push([plugin.watchChange, plugin]);
2207
- }
2208
- break;
2209
- }
2210
- case "closeWatcher": {
2211
- const handlers = batchedHooks.closeWatcher ?? [];
2212
- batchedHooks.closeWatcher = handlers;
2213
- if (plugin.closeWatcher) {
2214
- handlers.push([plugin.closeWatcher, plugin]);
2215
- }
2216
- break;
2217
- }
2218
- default: {}
2219
- }
2220
- });
2221
- });
2222
- const composed = {name: `Composed(${names.join(", ")})`};
2223
- const createFixedPluginResolveFnMap = new Map();
2224
- function applyFixedPluginResolveFn(ctx, plugin) {
2225
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
2226
- if (createFixedPluginResolveFn) {
2227
- return {
2228
- ...ctx,
2229
- resolve: createFixedPluginResolveFn(ctx)
2230
- };
2231
- }
2232
- return ctx;
2233
- }
2234
- if (batchedHooks.resolveId) {
2235
- const batchedHandlers = batchedHooks.resolveId;
2236
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
2237
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2238
- const [_handler, plugin] = batchedHandlers[handlerIdx];
2239
- const handlerSymbol = handlerSymbols[handlerIdx];
2240
- const createFixedPluginResolveFn = (ctx) => {
2241
- return (source, importer, rawContextResolveOptions) => {
2242
- const contextResolveOptions = rawContextResolveOptions ?? {};
2243
- if (contextResolveOptions.skipSelf) {
2244
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
2245
- contextResolveOptions.skipSelf = false;
2246
- }
2247
- return ctx.resolve(source, importer, contextResolveOptions);
2248
- };
2249
- };
2250
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
2251
- }
2252
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
2253
- const hookResolveIdOptions = rawHookResolveIdOptions;
2254
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
2255
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2256
- const [handler, plugin] = batchedHandlers[handlerIdx];
2257
- const handlerSymbol = handlerSymbols[handlerIdx];
2258
- if (symbolForCallerThatSkipSelf === handlerSymbol) {
2259
- continue;
2260
- }
2261
- const { handler: handlerFn } = normalizeHook(handler);
2262
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
2263
- if (!isNullish(result)) {
2264
- return result;
2265
- }
2266
- }
2267
- };
2268
- }
2269
- (t(batchedHooks)).forEach((hookName) => {
2270
- switch (hookName) {
2271
- case "resolveId": {
2272
- break;
2273
- }
2274
- case "buildStart": {
2275
- if (batchedHooks.buildStart) {
2276
- const batchedHandlers = batchedHooks.buildStart;
2277
- composed.buildStart = async function(options) {
2278
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2279
- const { handler: handlerFn } = normalizeHook(handler);
2280
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
2281
- }));
2282
- };
2283
- }
2284
- break;
2285
- }
2286
- case "load": {
2287
- if (batchedHooks.load) {
2288
- const batchedHandlers = batchedHooks.load;
2289
- composed.load = async function(id) {
2290
- for (const [handler, plugin] of batchedHandlers) {
2291
- const { handler: handlerFn } = normalizeHook(handler);
2292
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
2293
- if (!isNullish(result)) {
2294
- return result;
2295
- }
2296
- }
2297
- };
2298
- }
2299
- break;
2300
- }
2301
- case "transform": {
2302
- if (batchedHooks.transform) {
2303
- const batchedHandlers = batchedHooks.transform;
2304
- composed.transform = async function(initialCode, id, moduleType) {
2305
- let code = initialCode;
2306
- let moduleSideEffects = undefined;
2307
- function updateOutput(newCode, newModuleSideEffects) {
2308
- code = newCode;
2309
- moduleSideEffects = newModuleSideEffects ?? undefined;
2310
- }
2311
- for (const [handler, plugin] of batchedHandlers) {
2312
- const { handler: handlerFn } = normalizeHook(handler);
2313
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
2314
- if (!isNullish(result)) {
2315
- if (typeof result === "string") {
2316
- updateOutput(result);
2317
- } else {
2318
- if (result.code) {
2319
- updateOutput(result.code, result.moduleSideEffects);
2320
- }
2321
- }
2322
- }
2323
- }
2324
- return {
2325
- code,
2326
- moduleSideEffects
2327
- };
2328
- };
2329
- }
2330
- break;
2331
- }
2332
- case "buildEnd": {
2333
- if (batchedHooks.buildEnd) {
2334
- const batchedHandlers = batchedHooks.buildEnd;
2335
- composed.buildEnd = async function(err) {
2336
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2337
- const { handler: handlerFn } = normalizeHook(handler);
2338
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
2339
- }));
2340
- };
2341
- }
2342
- break;
2343
- }
2344
- case "renderChunk": {
2345
- if (batchedHooks.renderChunk) {
2346
- const batchedHandlers = batchedHooks.renderChunk;
2347
- composed.renderChunk = async function(code, chunk, options) {
2348
- for (const [handler, plugin] of batchedHandlers) {
2349
- const { handler: handlerFn } = normalizeHook(handler);
2350
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
2351
- if (!isNullish(result)) {
2352
- return result;
2353
- }
2354
- }
2355
- };
2356
- }
2357
- break;
2358
- }
2359
- case "banner":
2360
- case "footer":
2361
- case "intro":
2362
- case "outro": {
2363
- const hooks = batchedHooks[hookName];
2364
- if (hooks?.length) {
2365
- composed[hookName] = async function(chunk) {
2366
- const ret = [];
2367
- for (const [hook, plugin] of hooks) {
2368
- {
2369
- const { handler: handler } = normalizeHook(hook);
2370
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
2371
- }
2372
- }
2373
- return ret.join("\n");
2374
- };
2375
- }
2376
- break;
2377
- }
2378
- case "closeBundle": {
2379
- if (batchedHooks.closeBundle) {
2380
- const batchedHandlers = batchedHooks.closeBundle;
2381
- composed.closeBundle = async function() {
2382
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2383
- const { handler: handlerFn } = normalizeHook(handler);
2384
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2385
- }));
2386
- };
2387
- }
2388
- break;
2389
- }
2390
- case "watchChange": {
2391
- if (batchedHooks.watchChange) {
2392
- const batchedHandlers = batchedHooks.watchChange;
2393
- composed.watchChange = async function(id, event) {
2394
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2395
- const { handler: handlerFn } = normalizeHook(handler);
2396
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
2397
- }));
2398
- };
2399
- }
2400
- break;
2401
- }
2402
- case "closeWatcher": {
2403
- if (batchedHooks.closeWatcher) {
2404
- const batchedHandlers = batchedHooks.closeWatcher;
2405
- composed.closeWatcher = async function() {
2406
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2407
- const { handler: handlerFn } = normalizeHook(handler);
2408
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2409
- }));
2410
- };
2411
- }
2412
- break;
2413
- }
2414
- default: {}
2415
- }
2416
- });
2417
- return composed;
2418
- }
2419
- function isComposablePlugin(plugin) {
2420
- if (plugin instanceof BuiltinPlugin) {
2421
- return false;
2422
- }
2423
- if ("_parallel"in plugin) {
2424
- return false;
2425
- }
2426
- const hasNotComposablePattern = (t(plugin)).some((hookName) => {
2427
- if (!isPluginHookName(hookName)) {
2428
- return false;
2429
- }
2430
- const OK_TO_COMPOSE = false;
2431
- if (isUnsupportedHooks(hookName)) {
2432
- return !OK_TO_COMPOSE;
2433
- }
2434
- if (plugin[hookName]) {
2435
- const { meta: meta } = normalizeHook(plugin[hookName]);
2436
- if (meta.order === "pre" || meta.order === "post") {
2437
- return !OK_TO_COMPOSE;
2438
- }
2439
- }
2440
- return OK_TO_COMPOSE;
2441
- });
2442
- if (hasNotComposablePattern) {
2443
- return false;
2444
- }
2445
- return true;
2446
- }
2447
- function composeJsPlugins(plugins) {
2448
- const newPlugins = [];
2449
- const toBeComposed = [];
2450
- plugins.forEach((plugin) => {
2451
- if (isComposablePlugin(plugin)) {
2452
- toBeComposed.push(plugin);
2453
- } else {
2454
- if (toBeComposed.length > 0) {
2455
- if (toBeComposed.length > 1) {
2456
- newPlugins.push(createComposedPlugin(toBeComposed));
2457
- } else {
2458
- newPlugins.push(toBeComposed[0]);
2459
- }
2460
- toBeComposed.length = 0;
2461
- }
2462
- newPlugins.push(plugin);
2463
- }
2464
- });
2465
- if (toBeComposed.length > 0) {
2466
- if (toBeComposed.length > 1) {
2467
- newPlugins.push(createComposedPlugin(toBeComposed));
2468
- } else {
2469
- newPlugins.push(toBeComposed[0]);
2470
- }
2471
- toBeComposed.length = 0;
2472
- }
2473
- return newPlugins;
2474
- }
2475
-
2476
- //#endregion
2477
- //#region src/utils/normalize-input-options.ts
2478
- async function normalizeInputOptions(config) {
2479
- const { input: input,...rest } = config;
2480
- let plugins = await normalizePluginOption(config.plugins);
2481
- if (rest.experimental?.enableComposingJsPlugins ?? false) {
2482
- plugins = composeJsPlugins(plugins);
2483
- }
2484
- const treeshake = normalizeTreeshakeOptions(config.treeshake);
2485
- const logLevel = config.logLevel || LOG_LEVEL_INFO;
2486
- const onLog = getLogger(getObjectPlugins(plugins), getOnLog(config, logLevel), logLevel);
2487
- return {
2488
- ...rest,
2489
- input: input ? typeof input === "string" ? [input] : input : [],
2490
- plugins,
2491
- logLevel,
2492
- onLog,
2493
- treeshake
2494
- };
2495
- }
2496
-
2497
- //#endregion
2498
- //#region src/utils/normalize-output-options.ts
2499
- function normalizeOutputOptions(opts) {
2500
- const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, globals: globals, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, name: name, esModule: esModule, file: file } = opts;
2501
- return {
2502
- dir: dir,
2503
- file,
2504
- format: getFormat(format),
2505
- exports: exports ?? "auto",
2506
- sourcemap: sourcemap ?? false,
2507
- sourcemapIgnoreList: typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules"),
2508
- sourcemapPathTransform,
2509
- banner: getAddon(opts, "banner"),
2510
- footer: getAddon(opts, "footer"),
2511
- intro: getAddon(opts, "intro"),
2512
- outro: getAddon(opts, "outro"),
2513
- esModule: esModule ?? "if-default-prop",
2514
- globals: globals ?? {},
2515
- entryFileNames: entryFileNames ?? "[name].js",
2516
- chunkFileNames: chunkFileNames ?? "[name]-[hash].js",
2517
- assetFileNames: assetFileNames ?? "assets/[name]-[hash][extname]",
2518
- plugins: [],
2519
- minify: opts.minify,
2520
- extend: opts.extend,
2521
- name,
2522
- externalLiveBindings: opts.externalLiveBindings ?? true,
2523
- inlineDynamicImports: opts.inlineDynamicImports ?? false,
2524
- advancedChunks: opts.advancedChunks
2525
- };
2526
- }
2527
- function getFormat(format) {
2528
- switch (format) {
2529
- case undefined:
2530
- case "es":
2531
- case "esm":
2532
- case "module": {
2533
- return "es";
2534
- }
2535
- case "cjs":
2536
- case "commonjs": {
2537
- return "cjs";
2538
- }
2539
- case "iife": {
2540
- return "iife";
2541
- }
2542
- case "umd": {
2543
- return "umd";
2544
- }
2545
- default: unimplemented(`output.format: ${format}`);
2546
- }
2547
- }
2548
- const getAddon = (config, name) => {
2549
- return async (chunk) => {
2550
- const configAddon = config[name];
2551
- if (typeof configAddon === "function") {
2552
- return configAddon(chunk);
2553
- }
2554
- return configAddon || "";
2555
- };
2556
- };
2557
-
2558
- //#endregion
2559
- //#region src/options/bindingify-output-options.ts
2560
- function bindingifyOutputOptions(outputOptions) {
2561
- const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, name: name, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, banner: banner, footer: footer, intro: intro, outro: outro, esModule: esModule, globals: globals, file: file } = outputOptions;
2562
- return {
2563
- dir,
2564
- file: file == null ? undefined : file,
2565
- format: function() {
2566
- switch (format) {
2567
- case "es": return "es";
2568
- case "cjs": return "cjs";
2569
- case "iife": return "iife";
2570
- case "umd": return "umd";
2571
- }
2572
- }(),
2573
- exports,
2574
- sourcemap: bindingifySourcemap(sourcemap),
2575
- sourcemapIgnoreList,
2576
- sourcemapPathTransform,
2577
- banner,
2578
- footer,
2579
- intro,
2580
- outro,
2581
- extend: outputOptions.extend,
2582
- globals,
2583
- esModule: bindingifyEsModule(esModule),
2584
- name,
2585
- entryFileNames,
2586
- chunkFileNames,
2587
- assetFileNames,
2588
- plugins: [],
2589
- minify: outputOptions.minify,
2590
- externalLiveBindings: outputOptions.externalLiveBindings,
2591
- inlineDynamicImports: outputOptions.inlineDynamicImports,
2592
- advancedChunks: outputOptions.advancedChunks
2593
- };
2594
- }
2595
- function bindingifySourcemap(sourcemap) {
2596
- switch (sourcemap) {
2597
- case true: return "file";
2598
- case "inline": return "inline";
2599
- case false:
2600
- case undefined: return undefined;
2601
- case "hidden": return "hidden";
2602
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
2603
- }
2604
- }
2605
- function bindingifyEsModule(esModule) {
2606
- switch (esModule) {
2607
- case true:
2608
- case false:
2609
- case "if-default-prop": return esModule;
2610
- default: throw new Error(`unknown esModule: ${esModule}`);
2611
- }
2612
- }
2613
-
2614
- //#endregion
2615
- //#region src/utils/create-bundler.ts
2616
- var import_binding$1 = __toESM(require_binding());
2617
- async function createBundler(inputOptions, outputOptions) {
2618
- const pluginDriver = new PluginDriver();
2619
- inputOptions = await pluginDriver.callOptionsHook(inputOptions);
2620
- const normalizedInputOptions = await normalizeInputOptions(inputOptions);
2621
- const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
2622
- try {
2623
- outputOptions = pluginDriver.callOutputOptionsHook(normalizedInputOptions, outputOptions);
2624
- const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
2625
- const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
2626
- return {
2627
- bundler: new import_binding$1.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
2628
- stopWorkers: parallelPluginInitResult?.stopWorkers
2629
- };
2630
- } catch (e) {
2631
- await parallelPluginInitResult?.stopWorkers();
2632
- throw e;
2633
- }
2634
- }
2635
-
2636
- //#endregion
2637
- //#region src/rolldown-build.ts
2638
- class RolldownBuild {
2639
- #inputOptions;
2640
- #bundler;
2641
- constructor(inputOptions) {
2642
- this.#inputOptions = inputOptions;
2643
- }
2644
- async #getBundlerWithStopWorker(outputOptions) {
2645
- if (this.#bundler) {
2646
- this.#bundler.stopWorkers?.();
2647
- }
2648
- return this.#bundler = await createBundler(this.#inputOptions, outputOptions);
2649
- }
2650
- async generate(outputOptions = {}) {
2651
- const { bundler: bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2652
- const output = await bundler.generate();
2653
- return transformToRollupOutput(output);
2654
- }
2655
- async write(outputOptions = {}) {
2656
- const { bundler: bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2657
- const output = await bundler.write();
2658
- return transformToRollupOutput(output);
2659
- }
2660
- async close() {
2661
- const { bundler: bundler, stopWorkers: stopWorkers } = await this.#getBundlerWithStopWorker({});
2662
- await stopWorkers?.();
2663
- await bundler.close();
2664
- }
2665
- }
2666
-
2667
- //#endregion
2668
- //#region src/watcher.ts
2669
- var import_binding = __toESM(require_binding());
2670
- class Watcher {
2671
- closed;
2672
- controller;
2673
- inner;
2674
- stopWorkers;
2675
- constructor(inner, stopWorkers) {
2676
- this.closed = false;
2677
- this.controller = new AbortController();
2678
- this.inner = inner;
2679
- this.stopWorkers = stopWorkers;
2680
- }
2681
- async close() {
2682
- this.closed = true;
2683
- await this.stopWorkers?.();
2684
- await this.inner.close();
2685
- this.controller.abort();
2686
- }
2687
- on(event, listener) {
2688
- switch (event) {
2689
- case "close":
2690
- this.inner.on(import_binding.BindingWatcherEvent.Close, async () => {
2691
- await listener();
2692
- });
2693
- break;
2694
- case "event":
2695
- this.inner.on(import_binding.BindingWatcherEvent.Event, async (data) => {
2696
- if (data.code === "BUNDLE_END") {
2697
- await listener({
2698
- code: "BUNDLE_END",
2699
- duration: Number(data.duration),
2700
- output: [data.output]
2701
- });
2702
- } else {
2703
- await listener(data);
2704
- }
2705
- });
2706
- break;
2707
- case "restart":
2708
- this.inner.on(import_binding.BindingWatcherEvent.ReStart, async () => {
2709
- await listener();
2710
- });
2711
- break;
2712
- case "change":
2713
- this.inner.on(import_binding.BindingWatcherEvent.Change, async (data) => {
2714
- await listener(data.id, {event: data.kind});
2715
- });
2716
- break;
2717
- default: throw new Error(`Unknown event: ${event}`);
2718
- }
2719
- return this;
2720
- }
2721
- watch() {
2722
- const watcherWorkerPath = require.resolve("rolldown/watcher-worker");
2723
- const child = spawn(process.argv[0], [watcherWorkerPath], {signal: this.controller.signal});
2724
- child.on("error", () => {});
2725
- }
2726
- }
2727
-
2728
- //#endregion
2729
- //#region src/rolldown.ts
2730
- const rolldown = async (input) => {
2731
- return new RolldownBuild(input);
2732
- };
2733
- const watch = async (input) => {
2734
- const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(input, input.output || {});
2735
- const bindingWatcher = await bundler.watch();
2736
- const watcher = new Watcher(bindingWatcher, stopWorkers);
2737
- watcher.watch();
2738
- return watcher;
2739
- };
2740
- const experimental_scan = async (input) => {
2741
- const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(input, {});
2742
- await bundler.scan();
2743
- await stopWorkers?.();
2744
- };
2745
-
2746
- //#endregion
2747
- //#region package.json
2748
- const version = "0.14.0";
2749
- const description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2750
-
2751
- //#endregion
2752
- //#region src/index.ts
2753
- const VERSION = version;
2754
-
2755
- //#endregion
2756
- exports.LogLevelOptionSchema = LogLevelOptionSchema;
2757
- exports.LogLevelSchema = LogLevelSchema;
2758
- exports.LogLevelWithErrorSchema = LogLevelWithErrorSchema;
2759
- exports.PluginContextData = PluginContextData;
2760
- exports.RollupLogSchema = RollupLogSchema;
2761
- exports.RollupLogWithStringSchema = RollupLogWithStringSchema;
2762
- exports.VERSION = VERSION;
2763
- exports.aliasPlugin = aliasPlugin;
2764
- exports.arraify = arraify;
2765
- exports.bindingifyPlugin = bindingifyPlugin;
2766
- exports.buildImportAnalysisPlugin = buildImportAnalysisPlugin;
2767
- exports.composeJsPlugins = composeJsPlugins;
2768
- exports.defineConfig = defineConfig;
2769
- exports.description = description;
2770
- exports.dynamicImportVarsPlugin = dynamicImportVarsPlugin;
2771
- exports.experimental_scan = experimental_scan;
2772
- exports.importGlobPlugin = importGlobPlugin;
2773
- exports.jsonPlugin = jsonPlugin;
2774
- exports.loadFallbackPlugin = loadFallbackPlugin;
2775
- exports.manifestPlugin = manifestPlugin;
2776
- exports.modulePreloadPolyfillPlugin = modulePreloadPolyfillPlugin;
2777
- exports.replacePlugin = replacePlugin;
2778
- exports.require_binding = require_binding;
2779
- exports.rolldown = rolldown;
2780
- exports.transformPlugin = transformPlugin;
2781
- exports.version = version;
2782
- exports.wasmFallbackPlugin = wasmFallbackPlugin;
2783
- exports.wasmHelperPlugin = wasmHelperPlugin;
2784
- exports.watch = watch;
2785
-