rolldown 0.14.0 → 0.15.0-snapshot-b2570e7-20241204003545

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