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