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