rolldown 0.13.2 → 0.14.0

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