rolldown 0.12.2 → 0.13.0-snapshot-514fd69-20240905003110

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 (67) hide show
  1. package/dist/cjs/cli.cjs +1552 -584
  2. package/dist/cjs/experimental-index.cjs +40 -0
  3. package/dist/cjs/index.cjs +5 -22
  4. package/dist/cjs/parallel-plugin-worker.cjs +7 -7
  5. package/dist/cjs/parallel-plugin.cjs +1 -1
  6. package/dist/esm/cli.mjs +1549 -583
  7. package/dist/esm/experimental-index.mjs +23 -0
  8. package/dist/esm/index.mjs +5 -17
  9. package/dist/esm/parallel-plugin-worker.mjs +6 -6
  10. package/dist/esm/parallel-plugin.mjs +1 -1
  11. package/dist/shared/{chunk-1xb6WR3y.cjs → chunk-gQ4GMlVi.cjs} +3 -2
  12. package/dist/shared/{consola.36c0034f-N8xiTrv3.cjs → consola.36c0034f-eps_ogJv.cjs} +188 -188
  13. package/dist/shared/{consola.36c0034f-jtHhMkSX.mjs → consola.36c0034f-m5cABVv4.mjs} +187 -187
  14. package/dist/shared/package-3VR4tEG7.mjs +9 -0
  15. package/dist/shared/package-OJCNSbf0.cjs +11 -0
  16. package/dist/shared/plugin-context-data-AMG1kfMv.mjs +1443 -0
  17. package/dist/shared/plugin-context-data-S1bXhfAf.cjs +1436 -0
  18. package/dist/shared/{prompt-pjyLzLci.mjs → prompt-9VjtYvi_.mjs} +182 -182
  19. package/dist/shared/{prompt-1K6oCkIU.cjs → prompt-Ah5G71p-.cjs} +183 -183
  20. package/dist/shared/rolldown-NGdGAW73.mjs +1069 -0
  21. package/dist/shared/rolldown-binding.wasi.cjs +70 -51
  22. package/dist/shared/rolldown-z62CIhEW.cjs +1085 -0
  23. package/dist/types/binding.d.ts +329 -14
  24. package/dist/types/cli/arguments/alias.d.ts +8 -0
  25. package/dist/types/cli/arguments/index.d.ts +13 -0
  26. package/dist/types/cli/arguments/normalize.d.ts +15 -0
  27. package/dist/types/cli/arguments/schema.d.ts +161 -0
  28. package/dist/types/cli/arguments/utils.d.ts +6 -0
  29. package/dist/types/cli/commands/bundle.d.ts +3 -1
  30. package/dist/types/cli/commands/help.d.ts +1 -0
  31. package/dist/types/cli/utils.d.ts +1 -1
  32. package/dist/types/constants/plugin-context.d.ts +7 -0
  33. package/dist/types/constants/plugin.d.ts +36 -0
  34. package/dist/types/experimental-index.d.ts +5 -0
  35. package/dist/types/index.d.ts +8 -8
  36. package/dist/types/options/input-options.d.ts +139 -27
  37. package/dist/types/options/normalized-alias-plugin-config.d.ts +10 -0
  38. package/dist/types/options/normalized-ecma-transform-plugin-config.d.ts +8 -0
  39. package/dist/types/options/normalized-output-options.d.ts +8 -3
  40. package/dist/types/options/output-options.d.ts +102 -11
  41. package/dist/types/options/utils.d.ts +2 -0
  42. package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -8
  43. package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -0
  44. package/dist/types/plugin/bindingify-output-hooks.d.ts +11 -7
  45. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +8 -0
  46. package/dist/types/plugin/bindingify-plugin.d.ts +2 -1
  47. package/dist/types/plugin/builtin-plugin.d.ts +75 -7
  48. package/dist/types/plugin/index.d.ts +68 -28
  49. package/dist/types/plugin/plugin-context-data.d.ts +6 -0
  50. package/dist/types/plugin/plugin-context.d.ts +18 -8
  51. package/dist/types/plugin/plugin-driver.d.ts +2 -2
  52. package/dist/types/rollup.d.ts +1 -0
  53. package/dist/types/types/rolldown-output.d.ts +1 -0
  54. package/dist/types/utils/compose-js-plugins.d.ts +2 -0
  55. package/dist/types/utils/misc.d.ts +1 -0
  56. package/dist/types/utils/normalize-hook.d.ts +7 -5
  57. package/dist/types/utils/plugin/index.d.ts +2 -0
  58. package/dist/types/utils/type-assert.d.ts +1 -0
  59. package/package.json +30 -22
  60. package/dist/shared/rolldown-SCF5NBN_.cjs +0 -49
  61. package/dist/shared/rolldown-kYz4BvAA.mjs +0 -48
  62. package/dist/shared/utils_index-_DFpKlu1.mjs +0 -1582
  63. package/dist/shared/utils_index-xb2NoRNm.cjs +0 -1557
  64. package/dist/types/cli/constants.d.ts +0 -1
  65. package/dist/types/utils/ensure-array.d.ts +0 -1
  66. package/dist/types/utils/index.d.ts +0 -9
  67. /package/dist/types/plugin/{transfrom-plugin-context.d.ts → transform-plugin-context.d.ts} +0 -0
@@ -1,1557 +0,0 @@
1
- const { __commonJSMin, __toESM } = require("./chunk-1xb6WR3y.cjs");
2
- const { default: nodePath, default: path, default: path$1 } = __toESM(require("node:path"));
3
- const { z } = __toESM(require("zod"));
4
- const { Worker } = __toESM(require("node:worker_threads"));
5
- const { availableParallelism } = __toESM(require("node:os"));
6
- const { isRegExp } = __toESM(require("node:util/types"));
7
-
8
- //#region src/utils/async-flatten.ts
9
- async function asyncFlatten(array) {
10
- do {
11
- array = (await Promise.all(array)).flat(Infinity);
12
- } while (array.some((v) => v?.then));
13
- return array;
14
- }
15
-
16
- //#endregion
17
- //#region src/utils/asset-source.ts
18
- function transformAssetSource(bindingAssetSource$1) {
19
- return bindingAssetSource$1.inner;
20
- }
21
- function bindingAssetSource(source) {
22
- return {inner: source};
23
- }
24
-
25
- //#endregion
26
- //#region src/utils/transform-to-rollup-output.ts
27
- function transformToRollupOutputChunk(chunk) {
28
- return {
29
- type: 'chunk',
30
- get code() {
31
- return chunk.code;
32
- },
33
- set code(code) {
34
- chunk.code = code;
35
- },
36
- fileName: chunk.fileName,
37
- name: chunk.name,
38
- get modules() {
39
- return Object.fromEntries(Object.entries(chunk.modules).map(([key, _]) => [key, {}]));
40
- },
41
- get imports() {
42
- return chunk.imports;
43
- },
44
- set imports(imports) {
45
- chunk.imports = imports;
46
- },
47
- get dynamicImports() {
48
- return chunk.dynamicImports;
49
- },
50
- exports: chunk.exports,
51
- isEntry: chunk.isEntry,
52
- facadeModuleId: chunk.facadeModuleId || null,
53
- isDynamicEntry: chunk.isDynamicEntry,
54
- get moduleIds() {
55
- return chunk.moduleIds;
56
- },
57
- get map() {
58
- return chunk.map ? JSON.parse(chunk.map) : null;
59
- },
60
- set map(map) {
61
- chunk.map = JSON.stringify(map);
62
- },
63
- sourcemapFileName: chunk.sourcemapFileName || null,
64
- preliminaryFileName: chunk.preliminaryFileName
65
- };
66
- }
67
- function transformToRollupOutputAsset(asset) {
68
- return {
69
- type: 'asset',
70
- fileName: asset.fileName,
71
- get source() {
72
- return transformAssetSource(asset.source);
73
- },
74
- set source(source) {
75
- asset.source = bindingAssetSource(source);
76
- },
77
- name: asset.name ?? undefined
78
- };
79
- }
80
- function transformToRollupOutput(output) {
81
- const { chunks, assets } = output;
82
- const [firstChunk, ...restChunks] = chunks;
83
- return {output: [transformToRollupOutputChunk(firstChunk), ...restChunks.map(transformToRollupOutputChunk), ...assets.map(transformToRollupOutputAsset),]};
84
- }
85
- function transformToOutputBundle(output) {
86
- const bundle = Object.fromEntries(transformToRollupOutput(output).output.map((item) => [item.fileName, item]));
87
- return new Proxy(bundle, {deleteProperty(target, property) {
88
- if (typeof property === 'string') {
89
- output.delete(property);
90
- }
91
- return true;
92
- }});
93
- }
94
-
95
- //#endregion
96
- //#region src/utils/normalize-plugin-option.ts
97
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
98
-
99
- //#endregion
100
- //#region src/binding.js
101
- var require_binding = __commonJSMin((exports, module) => {
102
- const { readFileSync } = require('node:fs');
103
- let nativeBinding = null;
104
- const loadErrors = [];
105
- const isMusl = () => {
106
- let musl = false;
107
- if (process.platform === 'linux') {
108
- musl = isMuslFromFilesystem();
109
- if (musl === null) {
110
- musl = isMuslFromReport();
111
- }
112
- if (musl === null) {
113
- musl = isMuslFromChildProcess();
114
- }
115
- }
116
- return musl;
117
- };
118
- const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-');
119
- const isMuslFromFilesystem = () => {
120
- try {
121
- return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl');
122
- } catch {
123
- return null;
124
- }
125
- };
126
- const isMuslFromReport = () => {
127
- const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null;
128
- if (!report) {
129
- return null;
130
- }
131
- if (report.header && report.header.glibcVersionRuntime) {
132
- return false;
133
- }
134
- if (Array.isArray(report.sharedObjects)) {
135
- if (report.sharedObjects.some(isFileMusl)) {
136
- return true;
137
- }
138
- }
139
- return false;
140
- };
141
- const isMuslFromChildProcess = () => {
142
- try {
143
- return require('node:child_process').execSync('ldd --version', {encoding: 'utf8'}).includes('musl');
144
- } catch (e) {
145
- return false;
146
- }
147
- };
148
- function requireNative() {
149
- if (process.platform === 'android') {
150
- if (process.arch === 'arm64') {
151
- try {
152
- return require('./rolldown-binding.android-arm64.node');
153
- } catch (e) {
154
- loadErrors.push(e);
155
- }
156
- try {
157
- return require('@rolldown/binding-android-arm64');
158
- } catch (e) {
159
- loadErrors.push(e);
160
- }
161
- } else if (process.arch === 'arm') {
162
- try {
163
- return require('./rolldown-binding.android-arm-eabi.node');
164
- } catch (e) {
165
- loadErrors.push(e);
166
- }
167
- try {
168
- return require('@rolldown/binding-android-arm-eabi');
169
- } catch (e) {
170
- loadErrors.push(e);
171
- }
172
- } else {
173
- loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
174
- }
175
- } else if (process.platform === 'win32') {
176
- if (process.arch === 'x64') {
177
- try {
178
- return require('./rolldown-binding.win32-x64-msvc.node');
179
- } catch (e) {
180
- loadErrors.push(e);
181
- }
182
- try {
183
- return require('@rolldown/binding-win32-x64-msvc');
184
- } catch (e) {
185
- loadErrors.push(e);
186
- }
187
- } else if (process.arch === 'ia32') {
188
- try {
189
- return require('./rolldown-binding.win32-ia32-msvc.node');
190
- } catch (e) {
191
- loadErrors.push(e);
192
- }
193
- try {
194
- return require('@rolldown/binding-win32-ia32-msvc');
195
- } catch (e) {
196
- loadErrors.push(e);
197
- }
198
- } else if (process.arch === 'arm64') {
199
- try {
200
- return require('./rolldown-binding.win32-arm64-msvc.node');
201
- } catch (e) {
202
- loadErrors.push(e);
203
- }
204
- try {
205
- return require('@rolldown/binding-win32-arm64-msvc');
206
- } catch (e) {
207
- loadErrors.push(e);
208
- }
209
- } else {
210
- loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
211
- }
212
- } else if (process.platform === 'darwin') {
213
- try {
214
- return require('./rolldown-binding.darwin-universal.node');
215
- } catch (e) {
216
- loadErrors.push(e);
217
- }
218
- try {
219
- return require('@rolldown/binding-darwin-universal');
220
- } catch (e) {
221
- loadErrors.push(e);
222
- }
223
- if (process.arch === 'x64') {
224
- try {
225
- return require('./rolldown-binding.darwin-x64.node');
226
- } catch (e) {
227
- loadErrors.push(e);
228
- }
229
- try {
230
- return require('@rolldown/binding-darwin-x64');
231
- } catch (e) {
232
- loadErrors.push(e);
233
- }
234
- } else if (process.arch === 'arm64') {
235
- try {
236
- return require('./rolldown-binding.darwin-arm64.node');
237
- } catch (e) {
238
- loadErrors.push(e);
239
- }
240
- try {
241
- return require('@rolldown/binding-darwin-arm64');
242
- } catch (e) {
243
- loadErrors.push(e);
244
- }
245
- } else {
246
- loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
247
- }
248
- } else if (process.platform === 'freebsd') {
249
- if (process.arch === 'x64') {
250
- try {
251
- return require('./rolldown-binding.freebsd-x64.node');
252
- } catch (e) {
253
- loadErrors.push(e);
254
- }
255
- try {
256
- return require('@rolldown/binding-freebsd-x64');
257
- } catch (e) {
258
- loadErrors.push(e);
259
- }
260
- } else if (process.arch === 'arm64') {
261
- try {
262
- return require('./rolldown-binding.freebsd-arm64.node');
263
- } catch (e) {
264
- loadErrors.push(e);
265
- }
266
- try {
267
- return require('@rolldown/binding-freebsd-arm64');
268
- } catch (e) {
269
- loadErrors.push(e);
270
- }
271
- } else {
272
- loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
273
- }
274
- } else if (process.platform === 'linux') {
275
- if (process.arch === 'x64') {
276
- if (isMusl()) {
277
- try {
278
- return require('./rolldown-binding.linux-x64-musl.node');
279
- } catch (e) {
280
- loadErrors.push(e);
281
- }
282
- try {
283
- return require('@rolldown/binding-linux-x64-musl');
284
- } catch (e) {
285
- loadErrors.push(e);
286
- }
287
- } else {
288
- try {
289
- return require('./rolldown-binding.linux-x64-gnu.node');
290
- } catch (e) {
291
- loadErrors.push(e);
292
- }
293
- try {
294
- return require('@rolldown/binding-linux-x64-gnu');
295
- } catch (e) {
296
- loadErrors.push(e);
297
- }
298
- }
299
- } else if (process.arch === 'arm64') {
300
- if (isMusl()) {
301
- try {
302
- return require('./rolldown-binding.linux-arm64-musl.node');
303
- } catch (e) {
304
- loadErrors.push(e);
305
- }
306
- try {
307
- return require('@rolldown/binding-linux-arm64-musl');
308
- } catch (e) {
309
- loadErrors.push(e);
310
- }
311
- } else {
312
- try {
313
- return require('./rolldown-binding.linux-arm64-gnu.node');
314
- } catch (e) {
315
- loadErrors.push(e);
316
- }
317
- try {
318
- return require('@rolldown/binding-linux-arm64-gnu');
319
- } catch (e) {
320
- loadErrors.push(e);
321
- }
322
- }
323
- } else if (process.arch === 'arm') {
324
- if (isMusl()) {
325
- try {
326
- return require('./rolldown-binding.linux-arm-musleabihf.node');
327
- } catch (e) {
328
- loadErrors.push(e);
329
- }
330
- try {
331
- return require('@rolldown/binding-linux-arm-musleabihf');
332
- } catch (e) {
333
- loadErrors.push(e);
334
- }
335
- } else {
336
- try {
337
- return require('./rolldown-binding.linux-arm-gnueabihf.node');
338
- } catch (e) {
339
- loadErrors.push(e);
340
- }
341
- try {
342
- return require('@rolldown/binding-linux-arm-gnueabihf');
343
- } catch (e) {
344
- loadErrors.push(e);
345
- }
346
- }
347
- } else if (process.arch === 'riscv64') {
348
- if (isMusl()) {
349
- try {
350
- return require('./rolldown-binding.linux-riscv64-musl.node');
351
- } catch (e) {
352
- loadErrors.push(e);
353
- }
354
- try {
355
- return require('@rolldown/binding-linux-riscv64-musl');
356
- } catch (e) {
357
- loadErrors.push(e);
358
- }
359
- } else {
360
- try {
361
- return require('./rolldown-binding.linux-riscv64-gnu.node');
362
- } catch (e) {
363
- loadErrors.push(e);
364
- }
365
- try {
366
- return require('@rolldown/binding-linux-riscv64-gnu');
367
- } catch (e) {
368
- loadErrors.push(e);
369
- }
370
- }
371
- } else if (process.arch === 'ppc64') {
372
- try {
373
- return require('./rolldown-binding.linux-ppc64-gnu.node');
374
- } catch (e) {
375
- loadErrors.push(e);
376
- }
377
- try {
378
- return require('@rolldown/binding-linux-ppc64-gnu');
379
- } catch (e) {
380
- loadErrors.push(e);
381
- }
382
- } else if (process.arch === 's390x') {
383
- try {
384
- return require('./rolldown-binding.linux-s390x-gnu.node');
385
- } catch (e) {
386
- loadErrors.push(e);
387
- }
388
- try {
389
- return require('@rolldown/binding-linux-s390x-gnu');
390
- } catch (e) {
391
- loadErrors.push(e);
392
- }
393
- } else {
394
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
395
- }
396
- } else {
397
- loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
398
- }
399
- }
400
- nativeBinding = requireNative();
401
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
402
- try {
403
- nativeBinding = require('./rolldown-binding.wasi.cjs');
404
- } catch (err) {
405
- if (process.env.NAPI_RS_FORCE_WASI) {
406
- loadErrors.push(err);
407
- }
408
- }
409
- if (!nativeBinding) {
410
- try {
411
- nativeBinding = require('@rolldown/binding-wasm32-wasi');
412
- } catch (err) {
413
- if (process.env.NAPI_RS_FORCE_WASI) {
414
- loadErrors.push(err);
415
- }
416
- }
417
- }
418
- }
419
- if (!nativeBinding) {
420
- if (loadErrors.length > 0) {
421
- throw new Error('Failed to load native binding', {cause: loadErrors});
422
- }
423
- throw new Error(`Failed to load native binding`);
424
- }
425
- module.exports.BindingLog = nativeBinding.BindingLog;
426
- module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
427
- module.exports.BindingOutputAsset = nativeBinding.BindingOutputAsset;
428
- module.exports.BindingOutputChunk = nativeBinding.BindingOutputChunk;
429
- module.exports.BindingOutputs = nativeBinding.BindingOutputs;
430
- module.exports.BindingPluginContext = nativeBinding.BindingPluginContext;
431
- module.exports.BindingTransformPluginContext = nativeBinding.BindingTransformPluginContext;
432
- module.exports.Bundler = nativeBinding.Bundler;
433
- module.exports.FinalBindingOutputs = nativeBinding.FinalBindingOutputs;
434
- module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
435
- module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
436
- module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
437
- module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
438
- module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
439
- module.exports.registerPlugins = nativeBinding.registerPlugins;
440
- module.exports.transform = nativeBinding.transform;
441
- });
442
-
443
- //#endregion
444
- //#region src/utils/normalize-hook.ts
445
- function normalizeHook(hook) {
446
- if (typeof hook === 'function') {
447
- return [hook, {}];
448
- }
449
- const { handler,...options } = hook;
450
- return [handler, options];
451
- }
452
-
453
- //#endregion
454
- //#region src/utils/transform-sourcemap.ts
455
- function isEmptySourcemapFiled(array) {
456
- if (!array) {
457
- return true;
458
- }
459
- if (array.length === 0 || !array[0]) {
460
- return true;
461
- }
462
- return false;
463
- }
464
-
465
- //#endregion
466
- //#region src/utils/misc.ts
467
- function arraify(value) {
468
- return Array.isArray(value) ? value : [value];
469
- }
470
- function unimplemented(info) {
471
- if (info) {
472
- throw new Error(`unimplemented: ${info}`);
473
- }
474
- throw new Error('unimplemented');
475
- }
476
- function unsupported(info) {
477
- return () => {
478
- throw new Error(`UNSUPPORTED: ${info}`);
479
- };
480
- }
481
- function noop(..._args) {}
482
-
483
- //#endregion
484
- //#region src/utils/transform-module-info.ts
485
- function transformModuleInfo(info, option) {
486
- return {
487
- get ast() {
488
- return unsupported('ModuleInfo#ast');
489
- },
490
- get code() {
491
- return info.code;
492
- },
493
- id: info.id,
494
- importers: info.importers,
495
- dynamicImporters: info.dynamicImporters,
496
- importedIds: info.importedIds,
497
- dynamicallyImportedIds: info.dynamicallyImportedIds,
498
- isEntry: info.isEntry,
499
- ...option
500
- };
501
- }
502
-
503
- //#endregion
504
- //#region src/types/sourcemap.ts
505
- function bindingifySourcemap$1(map) {
506
- if (map == null) return;
507
- return {inner: typeof map === 'string' ? map : {
508
- file: map.file ?? undefined,
509
- mappings: map.mappings,
510
- sourceRoot: map.sourceRoot,
511
- sources: map.sources?.map((s) => s ?? undefined),
512
- sourcesContent: map.sourcesContent?.map((s) => s ?? undefined),
513
- names: map.names
514
- }};
515
- }
516
-
517
- //#endregion
518
- //#region src/log/logging.ts
519
- const LogLevelSchema = z.literal('info').or(z.literal('debug')).or(z.literal('warn'));
520
- const LogLevelWithErrorSchema = LogLevelSchema.or(z.literal('error'));
521
- const LogLevelOptionSchema = LogLevelSchema.or(z.literal('silent'));
522
- const LOG_LEVEL_SILENT = 'silent';
523
- const LOG_LEVEL_ERROR = 'error';
524
- const LOG_LEVEL_WARN = 'warn';
525
- const LOG_LEVEL_INFO = 'info';
526
- const LOG_LEVEL_DEBUG = 'debug';
527
- const logLevelPriority = {
528
- [LOG_LEVEL_DEBUG]: 0,
529
- [LOG_LEVEL_INFO]: 1,
530
- [LOG_LEVEL_WARN]: 2,
531
- [LOG_LEVEL_SILENT]: 3
532
- };
533
- const RollupLogSchema = z.any();
534
- const RollupLogWithStringSchema = RollupLogSchema.or(z.string());
535
-
536
- //#endregion
537
- //#region src/utils/code-frame.ts
538
- function spaces(index) {
539
- let result = '';
540
- while (index--) result += ' ';
541
- return result;
542
- }
543
- function tabsToSpaces(value) {
544
- return value.replace(/^\t+/, (match) => match.split(' ').join(' '));
545
- }
546
- const LINE_TRUNCATE_LENGTH = 120;
547
- const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
548
- const ELLIPSIS = '...';
549
- function getCodeFrame(source, line, column) {
550
- let lines = source.split('\n');
551
- if (line > lines.length) return '';
552
- const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
553
- const frameStart = Math.max(0, line - 3);
554
- let frameEnd = Math.min(line + 2, lines.length);
555
- lines = lines.slice(frameStart, frameEnd);
556
- while (!/\S/.test(lines[lines.length - 1])) {
557
- lines.pop();
558
- frameEnd -= 1;
559
- }
560
- const digits = String(frameEnd).length;
561
- return lines.map((sourceLine, index) => {
562
- const isErrorLine = frameStart + index + 1 === line;
563
- let lineNumber = String(index + frameStart + 1);
564
- while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
565
- let displayedLine = tabsToSpaces(sourceLine);
566
- if (displayedLine.length > maxLineLength) {
567
- displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
568
- }
569
- if (isErrorLine) {
570
- const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + '^';
571
- return `${lineNumber}: ${displayedLine}\n${indicator}`;
572
- }
573
- return `${lineNumber}: ${displayedLine}`;
574
- }).join('\n');
575
- }
576
-
577
- //#endregion
578
- //#region ../../node_modules/.pnpm/locate-character@3.0.0/node_modules/locate-character/src/index.js
579
- function rangeContains(range, index) {
580
- return range.start <= index && index < range.end;
581
- }
582
- function getLocator(source, options = {}) {
583
- const { offsetLine = 0, offsetColumn = 0 } = options;
584
- let start = 0;
585
- const ranges = source.split('\n').map((line, i$1) => {
586
- const end = start + line.length + 1;
587
- const range = {
588
- start,
589
- end,
590
- line: i$1
591
- };
592
- start = end;
593
- return range;
594
- });
595
- let i = 0;
596
- function locator(search, index) {
597
- if (typeof search === 'string') {
598
- search = source.indexOf(search, index ?? 0);
599
- }
600
- if (search === -1) return undefined;
601
- let range = ranges[i];
602
- const d = search >= range.end ? 1 : -1;
603
- while (range) {
604
- if (rangeContains(range, search)) {
605
- return {
606
- line: offsetLine + range.line,
607
- column: offsetColumn + search - range.start,
608
- character: search
609
- };
610
- }
611
- i += d;
612
- range = ranges[i];
613
- }
614
- }
615
- return locator;
616
- }
617
- function locate(source, search, options) {
618
- return getLocator(source, options)(search, options && options.startIndex);
619
- }
620
-
621
- //#endregion
622
- //#region src/log/logs.ts
623
- const INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', PLUGIN_ERROR = 'PLUGIN_ERROR';
624
- function logInvalidLogPosition(pluginName) {
625
- return {
626
- code: INVALID_LOG_POSITION,
627
- 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.`
628
- };
629
- }
630
- function logPluginError(error$1, plugin, { hook, id } = {}) {
631
- const code = error$1.code;
632
- if (!error$1.pluginCode && code != null && (typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
633
- error$1.pluginCode = code;
634
- }
635
- error$1.code = PLUGIN_ERROR;
636
- error$1.plugin = plugin;
637
- if (hook) {
638
- error$1.hook = hook;
639
- }
640
- if (id) {
641
- error$1.id = id;
642
- }
643
- return error$1;
644
- }
645
- function error(base) {
646
- if (!(base instanceof Error)) {
647
- base = Object.assign(new Error(base.message), base);
648
- Object.defineProperty(base, 'name', {
649
- value: 'RollupError',
650
- writable: true
651
- });
652
- }
653
- throw base;
654
- }
655
- function augmentCodeLocation(properties, pos, source, id) {
656
- if (typeof pos === 'object') {
657
- const { line, column } = pos;
658
- properties.loc = {
659
- column,
660
- file: id,
661
- line
662
- };
663
- } else {
664
- properties.pos = pos;
665
- const location = locate(source, pos, {offsetLine: 1});
666
- if (!location) {
667
- return;
668
- }
669
- const { line, column } = location;
670
- properties.loc = {
671
- column,
672
- file: id,
673
- line
674
- };
675
- }
676
- if (properties.frame === undefined) {
677
- const { line, column } = properties.loc;
678
- properties.frame = getCodeFrame(source, line, column);
679
- }
680
- }
681
-
682
- //#endregion
683
- //#region src/log/logHandler.ts
684
- const normalizeLog = (log) => typeof log === 'string' ? {message: log} : typeof log === 'function' ? normalizeLog(log()) : log;
685
- function getLogHandler(level, code, logger, pluginName, logLevel) {
686
- if (logLevelPriority[level] < logLevelPriority[logLevel]) {
687
- return noop;
688
- }
689
- return (log, pos) => {
690
- if (pos != null) {
691
- logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
692
- }
693
- log = normalizeLog(log);
694
- if (log.code && !log.pluginCode) {
695
- log.pluginCode = log.code;
696
- }
697
- log.code = code;
698
- log.plugin = pluginName;
699
- logger(level, log);
700
- };
701
- }
702
-
703
- //#endregion
704
- //#region src/plugin/plugin-context.ts
705
- class PluginContext {
706
- debug;
707
- info;
708
- warn;
709
- error;
710
- resolve;
711
- emitFile;
712
- getFileName;
713
- getModuleInfo;
714
- getModuleIds;
715
- parse;
716
- constructor(options, context, plugin, data) {
717
- const onLog = options.onLog;
718
- const pluginName = plugin.name || 'unknown';
719
- const logLevel = options.logLevel;
720
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', onLog, pluginName, logLevel);
721
- this.warn = getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', onLog, pluginName, logLevel);
722
- this.info = getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', onLog, pluginName, logLevel);
723
- this.error = (e) => {
724
- return error(logPluginError(normalizeLog(e), pluginName));
725
- };
726
- this.resolve = context.resolve.bind(context);
727
- this.emitFile = (file) => {
728
- if (file.type !== 'asset') {
729
- return unimplemented('PluginContext.emitFile: only asset type is supported');
730
- }
731
- return context.emitFile({
732
- ...file,
733
- source: bindingAssetSource(file.source)
734
- });
735
- };
736
- this.getFileName = context.getFileName.bind(context);
737
- this.getModuleInfo = (id) => data.getModuleInfo(id, context);
738
- this.getModuleIds = () => data.getModuleIds(context);
739
- this.parse = unsupported('`PluginContext#parse` is not supported by rolldown.');
740
- }
741
- }
742
-
743
- //#endregion
744
- //#region src/plugin/transfrom-plugin-context.ts
745
- class TransformPluginContext extends PluginContext {
746
- error;
747
- constructor(options, context, plugin, data, inner, moduleId, moduleSource) {
748
- super(options, context, plugin, data);
749
- const getLogHandler$1 = (handler) => (log, pos) => {
750
- log = normalizeLog(log);
751
- if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
752
- log.id = moduleId;
753
- log.hook = 'transform';
754
- handler(log);
755
- };
756
- this.debug = getLogHandler$1(this.debug);
757
- this.warn = getLogHandler$1(this.warn);
758
- this.info = getLogHandler$1(this.info);
759
- this.error = (error$1, pos) => {
760
- if (typeof error$1 === 'string') error$1 = {message: error$1};
761
- if (pos) augmentCodeLocation(error$1, pos, moduleSource, moduleId);
762
- error$1.id = moduleId;
763
- error$1.hook = 'transform';
764
- return this.error(error$1);
765
- };
766
- }
767
- }
768
-
769
- //#endregion
770
- //#region src/utils/transform-side-effects.ts
771
- var import_binding$4 = __toESM(require_binding());
772
- function bindingifySideEffects(sideEffects) {
773
- switch (sideEffects) {
774
- case true: return import_binding$4.BindingHookSideEffects.True;
775
- case false: return import_binding$4.BindingHookSideEffects.False;
776
- case 'no-treeshake': return import_binding$4.BindingHookSideEffects.NoTreeshake;
777
- case null:
778
- case undefined: return undefined;
779
- default: throw new Error(`Unexpected side effects: ${sideEffects}`);
780
- }
781
- }
782
-
783
- //#endregion
784
- //#region src/plugin/bindingify-build-hooks.ts
785
- function bindingifyBuildStart(plugin, options, pluginContextData) {
786
- const hook = plugin.buildStart;
787
- if (!hook) {
788
- return undefined;
789
- }
790
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
791
- return async (ctx) => {
792
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), options);
793
- };
794
- }
795
- function bindingifyBuildEnd(plugin, options, pluginContextData) {
796
- const hook = plugin.buildEnd;
797
- if (!hook) {
798
- return undefined;
799
- }
800
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
801
- return async (ctx, err) => {
802
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), err ? new Error(err) : undefined);
803
- };
804
- }
805
- function bindingifyResolveId(plugin, options, pluginContextData) {
806
- const hook = plugin.resolveId;
807
- if (!hook) {
808
- return undefined;
809
- }
810
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
811
- return async (ctx, specifier, importer, extraOptions) => {
812
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined, extraOptions);
813
- if (ret == false || ret == null) {
814
- return;
815
- }
816
- if (typeof ret === 'string') {
817
- return {id: ret};
818
- }
819
- const result = {
820
- id: ret.id,
821
- external: ret.external
822
- };
823
- if (ret.moduleSideEffects !== null) {
824
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
825
- }
826
- pluginContextData.updateModuleOption(ret.id, {
827
- meta: ret.meta || {},
828
- moduleSideEffects: ret.moduleSideEffects || null
829
- });
830
- return result;
831
- };
832
- }
833
- function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
834
- const hook = plugin.resolveDynamicImport;
835
- if (!hook) {
836
- return undefined;
837
- }
838
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
839
- return async (ctx, specifier, importer) => {
840
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined);
841
- if (ret == false || ret == null) {
842
- return;
843
- }
844
- if (typeof ret === 'string') {
845
- return {id: ret};
846
- }
847
- const result = {
848
- id: ret.id,
849
- external: ret.external
850
- };
851
- if (ret.moduleSideEffects !== null) {
852
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
853
- }
854
- pluginContextData.updateModuleOption(ret.id, {
855
- meta: ret.meta || {},
856
- moduleSideEffects: ret.moduleSideEffects || null
857
- });
858
- return result;
859
- };
860
- }
861
- function bindingifyTransform(plugin, options, pluginContextData) {
862
- const hook = plugin.transform;
863
- if (!hook) {
864
- return undefined;
865
- }
866
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
867
- return async (ctx, code, id) => {
868
- const ret = await handler.call(new TransformPluginContext(options, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id);
869
- if (ret == null) {
870
- return undefined;
871
- }
872
- if (typeof ret === 'string') {
873
- return {code: ret};
874
- }
875
- pluginContextData.updateModuleOption(id, {
876
- meta: ret.meta || {},
877
- moduleSideEffects: ret.moduleSideEffects || null
878
- });
879
- return {
880
- code: ret.code,
881
- map: bindingifySourcemap$1(ret.map),
882
- sideEffects: bindingifySideEffects(ret.moduleSideEffects)
883
- };
884
- };
885
- }
886
- function bindingifyLoad(plugin, options, pluginContextData) {
887
- const hook = plugin.load;
888
- if (!hook) {
889
- return undefined;
890
- }
891
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
892
- return async (ctx, id) => {
893
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), id);
894
- if (ret == null) {
895
- return;
896
- }
897
- if (typeof ret === 'string') {
898
- return {code: ret};
899
- }
900
- if (!ret.map) {
901
- return {code: ret.code};
902
- }
903
- let map = typeof ret.map === 'object' ? ret.map : (JSON.parse(ret.map));
904
- if (!isEmptySourcemapFiled(map.sources)) {
905
- const directory = path$1.dirname(id) || '.';
906
- const sourceRoot = map.sourceRoot || '.';
907
- map.sources = map.sources.map((source) => path$1.resolve(directory, sourceRoot, source));
908
- }
909
- const result = {
910
- code: ret.code,
911
- map: bindingifySourcemap$1(map)
912
- };
913
- if (ret.moduleSideEffects !== null) {
914
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
915
- }
916
- pluginContextData.updateModuleOption(id, {
917
- meta: ret.meta || {},
918
- moduleSideEffects: ret.moduleSideEffects || null
919
- });
920
- return result;
921
- };
922
- }
923
- function bindingifyModuleParsed(plugin, options, pluginContextData) {
924
- const hook = plugin.moduleParsed;
925
- if (!hook) {
926
- return undefined;
927
- }
928
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
929
- return async (ctx, moduleInfo) => {
930
- await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), transformModuleInfo(moduleInfo, pluginContextData.moduleOptionMap.get(moduleInfo.id)));
931
- };
932
- }
933
-
934
- //#endregion
935
- //#region src/plugin/bindingify-output-hooks.ts
936
- function bindingifyRenderStart(plugin, options, outputOptions, pluginContextData) {
937
- const hook = plugin.renderStart;
938
- if (!hook) {
939
- return undefined;
940
- }
941
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
942
- return async (ctx) => {
943
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, options);
944
- };
945
- }
946
- function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData) {
947
- const hook = plugin.renderChunk;
948
- if (!hook) {
949
- return undefined;
950
- }
951
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
952
- return async (ctx, code, chunk) => {
953
- const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), code, chunk, outputOptions);
954
- if (ret == null) {
955
- return;
956
- }
957
- if (typeof ret === 'string') {
958
- return {code: ret};
959
- }
960
- if (!ret.map) {
961
- return {code: ret.code};
962
- }
963
- return {
964
- code: ret.code,
965
- map: bindingifySourcemap$1(ret.map)
966
- };
967
- };
968
- }
969
- function bindingifyAugmentChunkHash(plugin, options, pluginContextData) {
970
- const hook = plugin.augmentChunkHash;
971
- if (!hook) {
972
- return undefined;
973
- }
974
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
975
- return async (ctx, chunk) => {
976
- return await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
977
- };
978
- }
979
- function bindingifyRenderError(plugin, options, pluginContextData) {
980
- const hook = plugin.renderError;
981
- if (!hook) {
982
- return undefined;
983
- }
984
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
985
- return async (ctx, err) => {
986
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), new Error(err));
987
- };
988
- }
989
- function bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData) {
990
- const hook = plugin.generateBundle;
991
- if (!hook) {
992
- return undefined;
993
- }
994
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
995
- return async (ctx, bundle, isWrite) => {
996
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle), isWrite);
997
- };
998
- }
999
- function bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData) {
1000
- const hook = plugin.writeBundle;
1001
- if (!hook) {
1002
- return undefined;
1003
- }
1004
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1005
- return async (ctx, bundle) => {
1006
- handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle));
1007
- };
1008
- }
1009
- function bindingifyBanner(plugin, options, pluginContextData) {
1010
- const hook = plugin.banner;
1011
- if (!hook) {
1012
- return undefined;
1013
- }
1014
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1015
- return async (ctx, chunk) => {
1016
- return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1017
- };
1018
- }
1019
-
1020
- //#endregion
1021
- //#region src/plugin/plugin-context-data.ts
1022
- class PluginContextData {
1023
- modules = new Map();
1024
- moduleIds = null;
1025
- moduleOptionMap = new Map();
1026
- updateModuleOption(id, option) {
1027
- const existing = this.moduleOptionMap.get(id);
1028
- if (existing) {
1029
- Object.assign(existing, option);
1030
- if (option.meta != null) {
1031
- Object.assign(existing.meta, option.meta);
1032
- }
1033
- } else {
1034
- this.moduleOptionMap.set(id, option);
1035
- }
1036
- }
1037
- getModuleInfo(id, context) {
1038
- if (this.modules.has(id)) {
1039
- return this.modules.get(id) ?? null;
1040
- }
1041
- const bindingInfo = context.getModuleInfo(id);
1042
- if (bindingInfo) {
1043
- const info = transformModuleInfo(bindingInfo, this.moduleOptionMap.get(id));
1044
- this.modules.set(id, info);
1045
- return info;
1046
- }
1047
- return null;
1048
- }
1049
- getModuleIds(context) {
1050
- if (this.moduleIds) {
1051
- return this.moduleIds.values();
1052
- }
1053
- const moduleIds = context.getModuleIds();
1054
- if (moduleIds) {
1055
- this.moduleIds = moduleIds;
1056
- return moduleIds.values();
1057
- }
1058
- return [].values();
1059
- }
1060
- }
1061
-
1062
- //#endregion
1063
- //#region src/plugin/bindingify-plugin.ts
1064
- function bindingifyPlugin(plugin, options, outputOptions) {
1065
- const pluginContextData = new PluginContextData();
1066
- return {
1067
- name: plugin.name ?? 'unknown',
1068
- buildStart: bindingifyBuildStart(plugin, options, pluginContextData),
1069
- resolveId: bindingifyResolveId(plugin, options, pluginContextData),
1070
- resolveDynamicImport: bindingifyResolveDynamicImport(plugin, options, pluginContextData),
1071
- buildEnd: bindingifyBuildEnd(plugin, options, pluginContextData),
1072
- transform: bindingifyTransform(plugin, options, pluginContextData),
1073
- moduleParsed: bindingifyModuleParsed(plugin, options, pluginContextData),
1074
- load: bindingifyLoad(plugin, options, pluginContextData),
1075
- renderChunk: bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData),
1076
- augmentChunkHash: bindingifyAugmentChunkHash(plugin, options, pluginContextData),
1077
- renderStart: bindingifyRenderStart(plugin, options, outputOptions, pluginContextData),
1078
- renderError: bindingifyRenderError(plugin, options, pluginContextData),
1079
- generateBundle: bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData),
1080
- writeBundle: bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData),
1081
- banner: bindingifyBanner(plugin, options, pluginContextData)
1082
- };
1083
- }
1084
-
1085
- //#endregion
1086
- //#region src/plugin/builtin-plugin.ts
1087
- var import_binding$3 = __toESM(require_binding());
1088
- class BuiltinPlugin {
1089
- constructor(name, options) {
1090
- this.name = name;
1091
- this.options = options;
1092
- this.name = name;
1093
- this.options = options;
1094
- }
1095
- }
1096
- class BuiltinWasmPlugin extends BuiltinPlugin {
1097
- constructor(options) {
1098
- super(import_binding$3.BindingBuiltinPluginName.WasmPlugin, options);
1099
- }
1100
- }
1101
- class BuiltinGlobImportPlugin extends BuiltinPlugin {
1102
- constructor(options) {
1103
- super(import_binding$3.BindingBuiltinPluginName.GlobImportPlugin, options);
1104
- }
1105
- }
1106
- function bindingifyBuiltInPlugin(plugin) {
1107
- return {
1108
- name: plugin.name,
1109
- options: plugin.options
1110
- };
1111
- }
1112
-
1113
- //#endregion
1114
- //#region src/options/bindingify-input-options.ts
1115
- var import_binding$2 = __toESM(require_binding());
1116
- function bindingifyInputOptions(options, outputOptions) {
1117
- return {
1118
- input: bindingifyInput(options.input),
1119
- plugins: options.plugins.map((plugin) => {
1120
- if ('_parallel'in plugin) {
1121
- return undefined;
1122
- }
1123
- if (plugin instanceof BuiltinPlugin) {
1124
- return bindingifyBuiltInPlugin(plugin);
1125
- }
1126
- return bindingifyPlugin(plugin, options, outputOptions);
1127
- }),
1128
- cwd: options.cwd ?? process.cwd(),
1129
- external: options.external ? (function bindingifyExternal() {
1130
- const external = options.external;
1131
- if (typeof external === 'function') {
1132
- return (id, importer, isResolved) => {
1133
- if (id.startsWith('\0')) return false;
1134
- return external(id, importer, isResolved) ?? false;
1135
- };
1136
- }
1137
- const externalArr = arraify(external);
1138
- return (id, _importer, _isResolved) => {
1139
- return externalArr.some((pat) => {
1140
- if (pat instanceof RegExp) {
1141
- return pat.test(id);
1142
- }
1143
- return id === pat;
1144
- });
1145
- };
1146
- })() : undefined,
1147
- resolve: options.resolve ? (function bindingifyResolve() {
1148
- const { alias,...rest } = options.resolve;
1149
- return {
1150
- alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
1151
- find: name,
1152
- replacements: [replacement]
1153
- })) : undefined,
1154
- ...rest
1155
- };
1156
- })() : undefined,
1157
- platform: options.platform,
1158
- shimMissingExports: options.shimMissingExports,
1159
- logLevel: bindingifyLogLevel(options.logLevel),
1160
- onLog: (level, log) => {
1161
- options.onLog(level, {
1162
- code: log.code,
1163
- message: log.message
1164
- });
1165
- },
1166
- treeshake: options.treeshake,
1167
- moduleTypes: options.moduleTypes
1168
- };
1169
- }
1170
- function bindingifyLogLevel(logLevel) {
1171
- switch (logLevel) {
1172
- case 'silent': return import_binding$2.BindingLogLevel.Silent;
1173
- case 'warn': return import_binding$2.BindingLogLevel.Warn;
1174
- case 'info': return import_binding$2.BindingLogLevel.Info;
1175
- case 'debug': return import_binding$2.BindingLogLevel.Debug;
1176
- default: throw new Error(`Unexpected log level: ${logLevel}`);
1177
- }
1178
- }
1179
- function bindingifyInput(input) {
1180
- if (Array.isArray(input)) {
1181
- return input.map((src) => {
1182
- const name = nodePath.parse(src).name;
1183
- return {
1184
- name,
1185
- import: src
1186
- };
1187
- });
1188
- } else {
1189
- return Object.entries(input).map((value) => {
1190
- return {
1191
- name: value[0],
1192
- import: value[1]
1193
- };
1194
- });
1195
- }
1196
- }
1197
-
1198
- //#endregion
1199
- //#region src/utils/initialize-parallel-plugins.ts
1200
- var import_binding$1 = __toESM(require_binding());
1201
- async function initializeParallelPlugins(plugins) {
1202
- const pluginInfos = [];
1203
- for (const [index, plugin] of plugins.entries()) {
1204
- if ('_parallel'in plugin) {
1205
- const { fileUrl, options } = plugin._parallel;
1206
- pluginInfos.push({
1207
- index,
1208
- fileUrl,
1209
- options
1210
- });
1211
- }
1212
- }
1213
- if (pluginInfos.length <= 0) {
1214
- return undefined;
1215
- }
1216
- const count = Math.min(availableParallelism(), 8);
1217
- const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
1218
- const registryId = parallelJsPluginRegistry.id;
1219
- const workers = await initializeWorkers(registryId, count, pluginInfos);
1220
- const stopWorkers = async () => {
1221
- await Promise.all(workers.map((worker) => worker.terminate()));
1222
- };
1223
- return {
1224
- registry: parallelJsPluginRegistry,
1225
- stopWorkers
1226
- };
1227
- }
1228
- function initializeWorkers(registryId, count, pluginInfos) {
1229
- return Promise.all(Array.from({length: count}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
1230
- }
1231
- async function initializeWorker(registryId, pluginInfos, threadNumber) {
1232
- const urlString = undefined('#parallel-plugin-worker');
1233
- const workerData = {
1234
- registryId,
1235
- pluginInfos,
1236
- threadNumber
1237
- };
1238
- let worker;
1239
- try {
1240
- worker = new Worker(new URL(urlString), {workerData});
1241
- worker.unref();
1242
- await new Promise((resolve, reject) => {
1243
- worker.once('message', async (message) => {
1244
- if (message.type === 'error') {
1245
- reject(message.error);
1246
- } else {
1247
- resolve();
1248
- }
1249
- });
1250
- });
1251
- return worker;
1252
- } catch (e) {
1253
- worker?.terminate();
1254
- throw e;
1255
- }
1256
- }
1257
-
1258
- //#endregion
1259
- //#region src/log/logger.ts
1260
- function getLogger(plugins, onLog, logLevel) {
1261
- const minimalPriority = logLevelPriority[logLevel];
1262
- const logger = (level, log, skipped = new Set()) => {
1263
- const logPriority = logLevelPriority[level];
1264
- if (logPriority < minimalPriority) {
1265
- return;
1266
- }
1267
- for (const plugin of plugins) {
1268
- if (skipped.has(plugin)) continue;
1269
- const { onLog: pluginOnLog } = plugin;
1270
- if (pluginOnLog) {
1271
- const getLogHandler$1 = (level$1) => {
1272
- if (logLevelPriority[level$1] < minimalPriority) {
1273
- return () => {};
1274
- }
1275
- return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
1276
- };
1277
- const handler = 'handler'in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
1278
- if (handler.call({
1279
- debug: getLogHandler$1(LOG_LEVEL_DEBUG),
1280
- error: (log$1) => error(normalizeLog(log$1)),
1281
- info: getLogHandler$1(LOG_LEVEL_INFO),
1282
- warn: getLogHandler$1(LOG_LEVEL_WARN)
1283
- }, level, log) === false) {
1284
- return;
1285
- }
1286
- }
1287
- }
1288
- onLog(level, log);
1289
- };
1290
- return logger;
1291
- }
1292
- const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
1293
- const { onwarn, onLog } = config;
1294
- const defaultOnLog = getDefaultOnLog(printLog, onwarn);
1295
- if (onLog) {
1296
- const minimalPriority = logLevelPriority[logLevel];
1297
- return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
1298
- if (level$1 === LOG_LEVEL_ERROR) {
1299
- return error(normalizeLog(handledLog));
1300
- }
1301
- if (logLevelPriority[level$1] >= minimalPriority) {
1302
- defaultOnLog(level$1, normalizeLog(handledLog));
1303
- }
1304
- });
1305
- }
1306
- return defaultOnLog;
1307
- };
1308
- const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
1309
- if (level === LOG_LEVEL_WARN) {
1310
- onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
1311
- } else {
1312
- printLog(level, log);
1313
- }
1314
- } : printLog;
1315
- const addLogToString = (log) => {
1316
- Object.defineProperty(log, 'toString', {
1317
- value: () => getExtendedLogMessage(log),
1318
- writable: true
1319
- });
1320
- return log;
1321
- };
1322
- const defaultPrintLog = (level, log) => {
1323
- const message = getExtendedLogMessage(log);
1324
- switch (level) {
1325
- case LOG_LEVEL_WARN: {
1326
- return console.warn(message);
1327
- }
1328
- case LOG_LEVEL_DEBUG: {
1329
- return console.debug(message);
1330
- }
1331
- default: {
1332
- return console.info(message);
1333
- }
1334
- }
1335
- };
1336
- const getExtendedLogMessage = (log) => {
1337
- let prefix = '';
1338
- if (log.plugin) {
1339
- prefix += `(${log.plugin} plugin) `;
1340
- }
1341
- if (log.loc) {
1342
- prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
1343
- }
1344
- return prefix + log.message;
1345
- };
1346
- function relativeId(id) {
1347
- if (!path.isAbsolute(id)) return id;
1348
- return path.relative(path.resolve(), id);
1349
- }
1350
-
1351
- //#endregion
1352
- //#region src/plugin/plugin-driver.ts
1353
- class PluginDriver {
1354
- async callOptionsHook(inputOptions) {
1355
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
1356
- const plugins = getObjectPlugins(inputOptions.plugins ?? []);
1357
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
1358
- for (const plugin of plugins) {
1359
- const name = plugin.name || 'unknown';
1360
- const options = plugin.options;
1361
- if (options) {
1362
- const [handler, _optionsIgnoredSofar] = normalizeHook(options);
1363
- const result = await handler.call({
1364
- debug: getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
1365
- error: (e) => error(logPluginError(normalizeLog(e), name, {hook: 'onLog'})),
1366
- info: getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
1367
- warn: getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel)
1368
- }, inputOptions);
1369
- if (result) {
1370
- inputOptions = result;
1371
- }
1372
- }
1373
- }
1374
- return inputOptions;
1375
- }
1376
- callOutputOptionsHook(inputOptions, outputOptions) {
1377
- const plugins = getObjectPlugins(inputOptions.plugins);
1378
- for (const plugin of plugins) {
1379
- const options = plugin.outputOptions;
1380
- if (options) {
1381
- const [handler, _optionsIgnoredSofar] = normalizeHook(options);
1382
- const result = handler.call(null, outputOptions);
1383
- if (result) {
1384
- outputOptions = result;
1385
- }
1386
- }
1387
- }
1388
- return outputOptions;
1389
- }
1390
- }
1391
- function getObjectPlugins(plugins) {
1392
- return plugins.filter((plugin) => {
1393
- if ('_parallel'in plugin) {
1394
- return undefined;
1395
- }
1396
- if (plugin instanceof BuiltinPlugin) {
1397
- return undefined;
1398
- }
1399
- return plugin;
1400
- });
1401
- }
1402
-
1403
- //#endregion
1404
- //#region src/utils/normalize-tree-shake.ts
1405
- function normalizeTreeshakeOptions(config) {
1406
- if (config === false) {
1407
- return undefined;
1408
- }
1409
- if (config === true || config === undefined) {
1410
- return {moduleSideEffects: 'true'};
1411
- }
1412
- let normalizedConfig = {moduleSideEffects: ''};
1413
- if (config.moduleSideEffects === undefined) {
1414
- normalizedConfig.moduleSideEffects = 'true';
1415
- } else if (isRegExp(config.moduleSideEffects)) {
1416
- normalizedConfig.moduleSideEffects = config.moduleSideEffects.source;
1417
- } else {
1418
- normalizedConfig.moduleSideEffects = config.moduleSideEffects.toString();
1419
- }
1420
- return normalizedConfig;
1421
- }
1422
-
1423
- //#endregion
1424
- //#region src/utils/normalize-input-options.ts
1425
- async function normalizeInputOptions(config) {
1426
- const { input,...rest } = config;
1427
- const plugins = await normalizePluginOption(config.plugins);
1428
- const treeshake = normalizeTreeshakeOptions(config.treeshake);
1429
- const logLevel = config.logLevel || LOG_LEVEL_INFO;
1430
- const onLog = getLogger(getObjectPlugins(plugins), getOnLog(config, logLevel), logLevel);
1431
- return {
1432
- ...rest,
1433
- input: input ? (typeof input === 'string' ? [input] : input) : [],
1434
- plugins,
1435
- logLevel,
1436
- onLog,
1437
- treeshake
1438
- };
1439
- }
1440
-
1441
- //#endregion
1442
- //#region src/utils/normalize-output-options.ts
1443
- function normalizeOutputOptions(opts) {
1444
- const { dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, entryFileNames, chunkFileNames, assetFileNames, name } = opts;
1445
- return {
1446
- dir: dir,
1447
- format: getFormat(format),
1448
- exports: exports ?? 'auto',
1449
- sourcemap: sourcemap ?? false,
1450
- sourcemapIgnoreList: typeof sourcemapIgnoreList === 'function' ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, sourcemapPath) => relativeSourcePath.includes('node_modules'),
1451
- sourcemapPathTransform,
1452
- banner: getAddon(opts, 'banner'),
1453
- footer: getAddon(opts, 'footer'),
1454
- entryFileNames: entryFileNames ?? '[name].js',
1455
- chunkFileNames: chunkFileNames ?? '[name]-[hash].js',
1456
- assetFileNames: assetFileNames ?? 'assets/[name]-[hash][extname]',
1457
- plugins: [],
1458
- minify: opts.minify,
1459
- name
1460
- };
1461
- }
1462
- function getFormat(format) {
1463
- switch (format) {
1464
- case undefined:
1465
- case 'es':
1466
- case 'esm':
1467
- case 'module': {
1468
- return 'es';
1469
- }
1470
- case 'cjs':
1471
- case 'commonjs': {
1472
- return 'cjs';
1473
- }
1474
- case 'iife': {
1475
- return 'iife';
1476
- }
1477
- default: unimplemented(`output.format: ${format}`);
1478
- }
1479
- }
1480
- const getAddon = (config, name) => {
1481
- return async (chunk) => {
1482
- const configAddon = config[name];
1483
- if (typeof configAddon === 'function') {
1484
- return configAddon(chunk);
1485
- }
1486
- return configAddon || '';
1487
- };
1488
- };
1489
-
1490
- //#endregion
1491
- //#region src/options/bindingify-output-options.ts
1492
- function bindingifyOutputOptions(outputOptions) {
1493
- const { dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, name, entryFileNames, chunkFileNames, assetFileNames, banner, footer } = outputOptions;
1494
- return {
1495
- dir,
1496
- format: (function() {
1497
- switch (format) {
1498
- case 'es': return 'es';
1499
- case 'cjs': return 'cjs';
1500
- case 'iife': return 'iife';
1501
- }
1502
- })(),
1503
- exports,
1504
- sourcemap: bindingifySourcemap(sourcemap),
1505
- sourcemapIgnoreList,
1506
- sourcemapPathTransform,
1507
- banner,
1508
- footer,
1509
- name,
1510
- entryFileNames,
1511
- chunkFileNames,
1512
- assetFileNames,
1513
- plugins: [],
1514
- minify: outputOptions.minify
1515
- };
1516
- }
1517
- function bindingifySourcemap(sourcemap) {
1518
- switch (sourcemap) {
1519
- case true: return 'file';
1520
- case 'inline': return 'inline';
1521
- case false:
1522
- case undefined:
1523
- case 'hidden': return 'hidden';
1524
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
1525
- }
1526
- }
1527
-
1528
- //#endregion
1529
- //#region src/utils/create-bundler.ts
1530
- var import_binding = __toESM(require_binding());
1531
- async function createBundler(inputOptions, outputOptions) {
1532
- const pluginDriver = new PluginDriver();
1533
- inputOptions = await pluginDriver.callOptionsHook(inputOptions);
1534
- const normalizedInputOptions = await normalizeInputOptions(inputOptions);
1535
- const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
1536
- try {
1537
- outputOptions = pluginDriver.callOutputOptionsHook(normalizedInputOptions, outputOptions);
1538
- const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
1539
- const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
1540
- return {
1541
- bundler: new import_binding.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
1542
- stopWorkers: parallelPluginInitResult?.stopWorkers
1543
- };
1544
- } catch (e) {
1545
- await parallelPluginInitResult?.stopWorkers();
1546
- throw e;
1547
- }
1548
- }
1549
-
1550
- //#endregion
1551
- exports.BuiltinGlobImportPlugin = BuiltinGlobImportPlugin;
1552
- exports.BuiltinWasmPlugin = BuiltinWasmPlugin;
1553
- exports.arraify = arraify;
1554
- exports.bindingifyPlugin = bindingifyPlugin;
1555
- exports.createBundler = createBundler;
1556
- exports.require_binding = require_binding;
1557
- exports.transformToRollupOutput = transformToRollupOutput;