@rollipop/rolldown 0.0.0 → 1.0.0-rc.10

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 (50) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +11 -1
  3. package/bin/cli.mjs +2 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/cli.mjs +1191 -0
  6. package/dist/config.d.mts +14 -0
  7. package/dist/config.mjs +4 -0
  8. package/dist/experimental-index.d.mts +316 -0
  9. package/dist/experimental-index.mjs +350 -0
  10. package/dist/experimental-runtime-types.d.ts +98 -0
  11. package/dist/filter-index.d.mts +196 -0
  12. package/dist/filter-index.mjs +386 -0
  13. package/dist/get-log-filter.d.mts +3 -0
  14. package/dist/get-log-filter.mjs +68 -0
  15. package/dist/index.d.mts +4 -0
  16. package/dist/index.mjs +50 -0
  17. package/dist/parallel-plugin-worker.d.mts +1 -0
  18. package/dist/parallel-plugin-worker.mjs +28 -0
  19. package/dist/parallel-plugin.d.mts +13 -0
  20. package/dist/parallel-plugin.mjs +6 -0
  21. package/dist/parse-ast-index.d.mts +32 -0
  22. package/dist/parse-ast-index.mjs +60 -0
  23. package/dist/plugins-index.d.mts +33 -0
  24. package/dist/plugins-index.mjs +40 -0
  25. package/dist/shared/binding-D_jQsHun.mjs +583 -0
  26. package/dist/shared/binding-hSQGgsUz.d.mts +1877 -0
  27. package/dist/shared/bindingify-input-options-DfXGy4QO.mjs +2193 -0
  28. package/dist/shared/constructors-B-HbV10G.mjs +68 -0
  29. package/dist/shared/constructors-DMl58KN5.d.mts +37 -0
  30. package/dist/shared/define-config-BSxBeCq6.d.mts +3810 -0
  31. package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
  32. package/dist/shared/error-D5tMcn3l.mjs +85 -0
  33. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  34. package/dist/shared/load-config-CNjYgiQv.mjs +120 -0
  35. package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
  36. package/dist/shared/logs-D80CXhvg.mjs +180 -0
  37. package/dist/shared/misc-DJYbNKZX.mjs +21 -0
  38. package/dist/shared/normalize-string-or-regex-B8PEhdn1.mjs +66 -0
  39. package/dist/shared/parse-iQx2ihYn.mjs +74 -0
  40. package/dist/shared/prompt-BYQIwEjg.mjs +845 -0
  41. package/dist/shared/resolve-tsconfig-CxoM-bno.mjs +113 -0
  42. package/dist/shared/rolldown-C0o3hS3w.mjs +40 -0
  43. package/dist/shared/rolldown-build-80GULIOI.mjs +3326 -0
  44. package/dist/shared/transform-DY2pi3Qm.d.mts +149 -0
  45. package/dist/shared/watch-C2am0Ahc.mjs +374 -0
  46. package/dist/utils-index.d.mts +376 -0
  47. package/dist/utils-index.mjs +2414 -0
  48. package/package.json +130 -2
  49. package/.editorconfig +0 -10
  50. package/.gitattributes +0 -4
@@ -0,0 +1,2193 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-D_jQsHun.mjs";
2
+ import { a as logInvalidLogPosition, c as logPluginError, n as error, r as logCycleLoading, t as augmentCodeLocation } from "./logs-D80CXhvg.mjs";
3
+ import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-B8PEhdn1.mjs";
4
+ import { a as unreachable, o as unsupported, r as noop, t as arraify } from "./misc-DJYbNKZX.mjs";
5
+ import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-D5tMcn3l.mjs";
6
+ import { parseAst } from "../parse-ast-index.mjs";
7
+ import path from "node:path";
8
+ import * as filter from "@rollipop/rolldown-pluginutils";
9
+ import fsp from "node:fs/promises";
10
+ //#region package.json
11
+ var version = "1.0.0-rc.10";
12
+ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
13
+ //#endregion
14
+ //#region src/constants/version.ts
15
+ /**
16
+ * The version of Rolldown.
17
+ * @example `'1.0.0'`
18
+ *
19
+ * @category Plugin APIs
20
+ */
21
+ const VERSION = version;
22
+ //#endregion
23
+ //#region src/constants/index.ts
24
+ /**
25
+ * Runtime helper module ID
26
+ */
27
+ const RUNTIME_MODULE_ID = "\0rolldown/runtime.js";
28
+ //#endregion
29
+ //#region src/log/logging.ts
30
+ const LOG_LEVEL_SILENT = "silent";
31
+ const LOG_LEVEL_ERROR = "error";
32
+ const LOG_LEVEL_WARN = "warn";
33
+ const LOG_LEVEL_INFO = "info";
34
+ const LOG_LEVEL_DEBUG = "debug";
35
+ const logLevelPriority = {
36
+ [LOG_LEVEL_DEBUG]: 0,
37
+ [LOG_LEVEL_INFO]: 1,
38
+ [LOG_LEVEL_WARN]: 2,
39
+ [LOG_LEVEL_SILENT]: 3
40
+ };
41
+ //#endregion
42
+ //#region src/log/log-handler.ts
43
+ const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
44
+ function getLogHandler(level, code, logger, pluginName, logLevel) {
45
+ if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
46
+ return (log, pos) => {
47
+ if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
48
+ log = normalizeLog(log);
49
+ if (log.code && !log.pluginCode) log.pluginCode = log.code;
50
+ log.code = code;
51
+ log.plugin = pluginName;
52
+ logger(level, log);
53
+ };
54
+ }
55
+ //#endregion
56
+ //#region src/utils/normalize-hook.ts
57
+ function normalizeHook(hook) {
58
+ if (typeof hook === "function" || typeof hook === "string") return {
59
+ handler: hook,
60
+ options: {},
61
+ meta: {}
62
+ };
63
+ if (typeof hook === "object" && hook !== null) {
64
+ const { handler, order, ...options } = hook;
65
+ return {
66
+ handler,
67
+ options,
68
+ meta: { order }
69
+ };
70
+ }
71
+ unreachable("Invalid hook type");
72
+ }
73
+ //#endregion
74
+ //#region src/plugin/minimal-plugin-context.ts
75
+ var MinimalPluginContextImpl = class {
76
+ info;
77
+ warn;
78
+ debug;
79
+ meta;
80
+ constructor(onLog, logLevel, pluginName, watchMode, hookName) {
81
+ this.pluginName = pluginName;
82
+ this.hookName = hookName;
83
+ this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
84
+ this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
85
+ this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
86
+ this.meta = {
87
+ rollupVersion: "4.23.0",
88
+ rolldownVersion: VERSION,
89
+ watchMode
90
+ };
91
+ }
92
+ error(e) {
93
+ return error(logPluginError(normalizeLog(e), this.pluginName, { hook: this.hookName }));
94
+ }
95
+ };
96
+ //#endregion
97
+ //#region src/types/plain-object-like.ts
98
+ const LAZY_FIELDS_KEY = Symbol("__lazy_fields__");
99
+ /**
100
+ * Base class for classes that use `@lazyProp` decorated properties.
101
+ *
102
+ * **Design Pattern in Rolldown:**
103
+ * This is a common pattern in Rolldown due to its three-layer architecture:
104
+ * TypeScript API → NAPI Bindings → Rust Core
105
+ *
106
+ * **Why we use getters:**
107
+ * For performance - to lazily fetch data from Rust bindings only when needed,
108
+ * rather than eagerly fetching all data during object construction.
109
+ *
110
+ * **The problem:**
111
+ * Getters defined on class prototypes are non-enumerable by default, which breaks:
112
+ * - Object spread operators ({...obj})
113
+ * - Object.keys() and similar methods
114
+ * - Standard JavaScript object semantics
115
+ *
116
+ * **The solution:**
117
+ * This base class automatically converts `@lazyProp` decorated getters into
118
+ * own enumerable getters on each instance during construction.
119
+ *
120
+ * **Result:**
121
+ * Objects get both lazy-loading performance benefits AND plain JavaScript object behavior.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * class MyClass extends PlainObjectLike {
126
+ * @lazyProp
127
+ * get myProp() {
128
+ * return fetchFromRustBinding();
129
+ * }
130
+ * }
131
+ * ```
132
+ */
133
+ var PlainObjectLike = class {
134
+ constructor() {
135
+ setupLazyProperties(this);
136
+ }
137
+ };
138
+ /**
139
+ * Set up lazy properties as own getters on an instance.
140
+ * This is called automatically by the `PlainObjectLike` base class constructor.
141
+ *
142
+ * @param instance - The instance to set up lazy properties on
143
+ * @internal
144
+ */
145
+ function setupLazyProperties(instance) {
146
+ const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
147
+ if (!lazyFields) return;
148
+ for (const [propertyKey, originalGetter] of lazyFields.entries()) {
149
+ let cachedValue;
150
+ let hasValue = false;
151
+ Object.defineProperty(instance, propertyKey, {
152
+ get() {
153
+ if (!hasValue) {
154
+ cachedValue = originalGetter.call(this);
155
+ hasValue = true;
156
+ }
157
+ return cachedValue;
158
+ },
159
+ enumerable: true,
160
+ configurable: true
161
+ });
162
+ }
163
+ }
164
+ /**
165
+ * Get all lazy field names from a class instance.
166
+ *
167
+ * @param instance - Instance to inspect
168
+ * @returns Set of lazy property names
169
+ */
170
+ function getLazyFields(instance) {
171
+ const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
172
+ return lazyFields ? new Set(lazyFields.keys()) : /* @__PURE__ */ new Set();
173
+ }
174
+ //#endregion
175
+ //#region src/decorators/lazy.ts
176
+ /**
177
+ * Decorator that marks a getter as lazy-evaluated and cached.
178
+ *
179
+ * **What "lazy" means here:**
180
+ * 1. Data is lazily fetched from Rust bindings only when the property is accessed (not eagerly on construction)
181
+ * 2. Once fetched, the data is cached for subsequent accesses (performance optimization)
182
+ * 3. Despite being a getter, it behaves like a plain object property (enumerable, appears in Object.keys())
183
+ *
184
+ * **Important**: Properties decorated with `@lazyProp` are defined as own enumerable
185
+ * properties on each instance (not on the prototype). This ensures they:
186
+ * - Appear in Object.keys() and Object.getOwnPropertyNames()
187
+ * - Are included in object spreads ({...obj})
188
+ * - Are enumerable in for...in loops
189
+ *
190
+ * Classes using this decorator must extend `PlainObjectLike` base class.
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * class MyClass extends PlainObjectLike {
195
+ * @lazyProp
196
+ * get expensiveValue() {
197
+ * return someExpensiveComputation();
198
+ * }
199
+ * }
200
+ * ```
201
+ */
202
+ function lazyProp(target, propertyKey, descriptor) {
203
+ if (!target.constructor[LAZY_FIELDS_KEY]) target.constructor[LAZY_FIELDS_KEY] = /* @__PURE__ */ new Map();
204
+ const originalGetter = descriptor.get;
205
+ target.constructor[LAZY_FIELDS_KEY].set(propertyKey, originalGetter);
206
+ return {
207
+ enumerable: false,
208
+ configurable: true
209
+ };
210
+ }
211
+ //#endregion
212
+ //#region src/utils/asset-source.ts
213
+ function transformAssetSource(bindingAssetSource) {
214
+ return bindingAssetSource.inner;
215
+ }
216
+ function bindingAssetSource(source) {
217
+ return { inner: source };
218
+ }
219
+ //#endregion
220
+ //#region \0@oxc-project+runtime@0.121.0/helpers/decorate.js
221
+ function __decorate(decorators, target, key, desc) {
222
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
223
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
224
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
225
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
226
+ }
227
+ //#endregion
228
+ //#region src/types/output-asset-impl.ts
229
+ var OutputAssetImpl = class extends PlainObjectLike {
230
+ type = "asset";
231
+ constructor(bindingAsset) {
232
+ super();
233
+ this.bindingAsset = bindingAsset;
234
+ }
235
+ get fileName() {
236
+ return this.bindingAsset.getFileName();
237
+ }
238
+ get originalFileName() {
239
+ return this.bindingAsset.getOriginalFileName() || null;
240
+ }
241
+ get originalFileNames() {
242
+ return this.bindingAsset.getOriginalFileNames();
243
+ }
244
+ get name() {
245
+ return this.bindingAsset.getName() ?? void 0;
246
+ }
247
+ get names() {
248
+ return this.bindingAsset.getNames();
249
+ }
250
+ get source() {
251
+ return transformAssetSource(this.bindingAsset.getSource());
252
+ }
253
+ __rolldown_external_memory_handle__(keepDataAlive) {
254
+ if (keepDataAlive) this.#evaluateAllLazyFields();
255
+ return this.bindingAsset.dropInner();
256
+ }
257
+ #evaluateAllLazyFields() {
258
+ for (const field of getLazyFields(this)) this[field];
259
+ }
260
+ };
261
+ __decorate([lazyProp], OutputAssetImpl.prototype, "fileName", null);
262
+ __decorate([lazyProp], OutputAssetImpl.prototype, "originalFileName", null);
263
+ __decorate([lazyProp], OutputAssetImpl.prototype, "originalFileNames", null);
264
+ __decorate([lazyProp], OutputAssetImpl.prototype, "name", null);
265
+ __decorate([lazyProp], OutputAssetImpl.prototype, "names", null);
266
+ __decorate([lazyProp], OutputAssetImpl.prototype, "source", null);
267
+ //#endregion
268
+ //#region src/utils/transform-rendered-module.ts
269
+ function transformToRenderedModule(bindingRenderedModule) {
270
+ return {
271
+ get code() {
272
+ return bindingRenderedModule.code;
273
+ },
274
+ get renderedLength() {
275
+ return bindingRenderedModule.code?.length || 0;
276
+ },
277
+ get renderedExports() {
278
+ return bindingRenderedModule.renderedExports;
279
+ }
280
+ };
281
+ }
282
+ //#endregion
283
+ //#region src/utils/transform-rendered-chunk.ts
284
+ function transformRenderedChunk(chunk) {
285
+ let modules = null;
286
+ return {
287
+ type: "chunk",
288
+ get name() {
289
+ return chunk.name;
290
+ },
291
+ get isEntry() {
292
+ return chunk.isEntry;
293
+ },
294
+ get isDynamicEntry() {
295
+ return chunk.isDynamicEntry;
296
+ },
297
+ get facadeModuleId() {
298
+ return chunk.facadeModuleId;
299
+ },
300
+ get moduleIds() {
301
+ return chunk.moduleIds;
302
+ },
303
+ get exports() {
304
+ return chunk.exports;
305
+ },
306
+ get fileName() {
307
+ return chunk.fileName;
308
+ },
309
+ get imports() {
310
+ return chunk.imports;
311
+ },
312
+ get dynamicImports() {
313
+ return chunk.dynamicImports;
314
+ },
315
+ get modules() {
316
+ if (!modules) modules = transformChunkModules(chunk.modules);
317
+ return modules;
318
+ }
319
+ };
320
+ }
321
+ function transformChunkModules(modules) {
322
+ const result = {};
323
+ for (let i = 0; i < modules.values.length; i++) {
324
+ let key = modules.keys[i];
325
+ const mod = modules.values[i];
326
+ result[key] = transformToRenderedModule(mod);
327
+ }
328
+ return result;
329
+ }
330
+ //#endregion
331
+ //#region src/types/output-chunk-impl.ts
332
+ var OutputChunkImpl = class extends PlainObjectLike {
333
+ type = "chunk";
334
+ constructor(bindingChunk) {
335
+ super();
336
+ this.bindingChunk = bindingChunk;
337
+ }
338
+ get fileName() {
339
+ return this.bindingChunk.getFileName();
340
+ }
341
+ get name() {
342
+ return this.bindingChunk.getName();
343
+ }
344
+ get exports() {
345
+ return this.bindingChunk.getExports();
346
+ }
347
+ get isEntry() {
348
+ return this.bindingChunk.getIsEntry();
349
+ }
350
+ get facadeModuleId() {
351
+ return this.bindingChunk.getFacadeModuleId() || null;
352
+ }
353
+ get isDynamicEntry() {
354
+ return this.bindingChunk.getIsDynamicEntry();
355
+ }
356
+ get sourcemapFileName() {
357
+ return this.bindingChunk.getSourcemapFileName() || null;
358
+ }
359
+ get preliminaryFileName() {
360
+ return this.bindingChunk.getPreliminaryFileName();
361
+ }
362
+ get code() {
363
+ return this.bindingChunk.getCode();
364
+ }
365
+ get modules() {
366
+ return transformChunkModules(this.bindingChunk.getModules());
367
+ }
368
+ get imports() {
369
+ return this.bindingChunk.getImports();
370
+ }
371
+ get dynamicImports() {
372
+ return this.bindingChunk.getDynamicImports();
373
+ }
374
+ get moduleIds() {
375
+ return this.bindingChunk.getModuleIds();
376
+ }
377
+ get map() {
378
+ const mapString = this.bindingChunk.getMap();
379
+ return mapString ? transformToRollupSourceMap(mapString) : null;
380
+ }
381
+ __rolldown_external_memory_handle__(keepDataAlive) {
382
+ if (keepDataAlive) this.#evaluateAllLazyFields();
383
+ return this.bindingChunk.dropInner();
384
+ }
385
+ #evaluateAllLazyFields() {
386
+ for (const field of getLazyFields(this)) this[field];
387
+ }
388
+ };
389
+ __decorate([lazyProp], OutputChunkImpl.prototype, "fileName", null);
390
+ __decorate([lazyProp], OutputChunkImpl.prototype, "name", null);
391
+ __decorate([lazyProp], OutputChunkImpl.prototype, "exports", null);
392
+ __decorate([lazyProp], OutputChunkImpl.prototype, "isEntry", null);
393
+ __decorate([lazyProp], OutputChunkImpl.prototype, "facadeModuleId", null);
394
+ __decorate([lazyProp], OutputChunkImpl.prototype, "isDynamicEntry", null);
395
+ __decorate([lazyProp], OutputChunkImpl.prototype, "sourcemapFileName", null);
396
+ __decorate([lazyProp], OutputChunkImpl.prototype, "preliminaryFileName", null);
397
+ __decorate([lazyProp], OutputChunkImpl.prototype, "code", null);
398
+ __decorate([lazyProp], OutputChunkImpl.prototype, "modules", null);
399
+ __decorate([lazyProp], OutputChunkImpl.prototype, "imports", null);
400
+ __decorate([lazyProp], OutputChunkImpl.prototype, "dynamicImports", null);
401
+ __decorate([lazyProp], OutputChunkImpl.prototype, "moduleIds", null);
402
+ __decorate([lazyProp], OutputChunkImpl.prototype, "map", null);
403
+ //#endregion
404
+ //#region src/utils/transform-to-rollup-output.ts
405
+ function transformToRollupSourceMap(map) {
406
+ const obj = {
407
+ ...JSON.parse(map),
408
+ toString() {
409
+ return JSON.stringify(obj);
410
+ },
411
+ toUrl() {
412
+ return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
413
+ }
414
+ };
415
+ return obj;
416
+ }
417
+ function transformToRollupOutputChunk(bindingChunk) {
418
+ return new OutputChunkImpl(bindingChunk);
419
+ }
420
+ function transformToMutableRollupOutputChunk(bindingChunk, changed) {
421
+ const chunk = {
422
+ type: "chunk",
423
+ get code() {
424
+ return bindingChunk.getCode();
425
+ },
426
+ fileName: bindingChunk.getFileName(),
427
+ name: bindingChunk.getName(),
428
+ get modules() {
429
+ return transformChunkModules(bindingChunk.getModules());
430
+ },
431
+ get imports() {
432
+ return bindingChunk.getImports();
433
+ },
434
+ get dynamicImports() {
435
+ return bindingChunk.getDynamicImports();
436
+ },
437
+ exports: bindingChunk.getExports(),
438
+ isEntry: bindingChunk.getIsEntry(),
439
+ facadeModuleId: bindingChunk.getFacadeModuleId() || null,
440
+ isDynamicEntry: bindingChunk.getIsDynamicEntry(),
441
+ get moduleIds() {
442
+ return bindingChunk.getModuleIds();
443
+ },
444
+ get map() {
445
+ const map = bindingChunk.getMap();
446
+ return map ? transformToRollupSourceMap(map) : null;
447
+ },
448
+ sourcemapFileName: bindingChunk.getSourcemapFileName() || null,
449
+ preliminaryFileName: bindingChunk.getPreliminaryFileName()
450
+ };
451
+ const cache = {};
452
+ return new Proxy(chunk, {
453
+ get(target, p) {
454
+ if (p in cache) return cache[p];
455
+ const value = target[p];
456
+ cache[p] = value;
457
+ return value;
458
+ },
459
+ set(_target, p, newValue) {
460
+ cache[p] = newValue;
461
+ changed.updated.add(bindingChunk.getFileName());
462
+ return true;
463
+ },
464
+ has(target, p) {
465
+ if (p in cache) return true;
466
+ return p in target;
467
+ }
468
+ });
469
+ }
470
+ function transformToRollupOutputAsset(bindingAsset) {
471
+ return new OutputAssetImpl(bindingAsset);
472
+ }
473
+ function transformToMutableRollupOutputAsset(bindingAsset, changed) {
474
+ const asset = {
475
+ type: "asset",
476
+ fileName: bindingAsset.getFileName(),
477
+ originalFileName: bindingAsset.getOriginalFileName() || null,
478
+ originalFileNames: bindingAsset.getOriginalFileNames(),
479
+ get source() {
480
+ return transformAssetSource(bindingAsset.getSource());
481
+ },
482
+ name: bindingAsset.getName() ?? void 0,
483
+ names: bindingAsset.getNames()
484
+ };
485
+ const cache = {};
486
+ return new Proxy(asset, {
487
+ get(target, p) {
488
+ if (p in cache) return cache[p];
489
+ const value = target[p];
490
+ cache[p] = value;
491
+ return value;
492
+ },
493
+ set(_target, p, newValue) {
494
+ cache[p] = newValue;
495
+ changed.updated.add(bindingAsset.getFileName());
496
+ return true;
497
+ }
498
+ });
499
+ }
500
+ function transformToRollupOutput(output) {
501
+ const { chunks, assets } = output;
502
+ return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk)), ...assets.map((asset) => transformToRollupOutputAsset(asset))] };
503
+ }
504
+ function transformToMutableRollupOutput(output, changed) {
505
+ const { chunks, assets } = output;
506
+ return { output: [...chunks.map((chunk) => transformToMutableRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToMutableRollupOutputAsset(asset, changed))] };
507
+ }
508
+ function transformToOutputBundle(context, output, changed) {
509
+ const bundle = Object.fromEntries(transformToMutableRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
510
+ return new Proxy(bundle, {
511
+ set(_target, _p, _newValue, _receiver) {
512
+ const originalStackTraceLimit = Error.stackTraceLimit;
513
+ Error.stackTraceLimit = 2;
514
+ const message = "This plugin assigns to bundle variable. This is discouraged by Rollup and is not supported by Rolldown. This will be ignored. https://rollupjs.org/plugin-development/#generatebundle:~:text=DANGER,this.emitFile.";
515
+ const stack = new Error(message).stack ?? message;
516
+ Error.stackTraceLimit = originalStackTraceLimit;
517
+ context.warn({
518
+ message: stack,
519
+ code: "UNSUPPORTED_BUNDLE_ASSIGNMENT"
520
+ });
521
+ return true;
522
+ },
523
+ deleteProperty(target, property) {
524
+ if (typeof property === "string") changed.deleted.add(property);
525
+ return true;
526
+ }
527
+ });
528
+ }
529
+ function collectChangedBundle(changed, bundle) {
530
+ const changes = {};
531
+ for (const key in bundle) {
532
+ if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
533
+ const item = bundle[key];
534
+ if (item.type === "asset") changes[key] = {
535
+ filename: item.fileName,
536
+ originalFileNames: item.originalFileNames,
537
+ source: bindingAssetSource(item.source),
538
+ names: item.names
539
+ };
540
+ else changes[key] = {
541
+ code: item.code,
542
+ filename: item.fileName,
543
+ name: item.name,
544
+ isEntry: item.isEntry,
545
+ exports: item.exports,
546
+ modules: {},
547
+ imports: item.imports,
548
+ dynamicImports: item.dynamicImports,
549
+ facadeModuleId: item.facadeModuleId || void 0,
550
+ isDynamicEntry: item.isDynamicEntry,
551
+ moduleIds: item.moduleIds,
552
+ map: bindingifySourcemap(item.map),
553
+ sourcemapFilename: item.sourcemapFileName || void 0,
554
+ preliminaryFilename: item.preliminaryFileName
555
+ };
556
+ }
557
+ return {
558
+ changes,
559
+ deleted: changed.deleted
560
+ };
561
+ }
562
+ //#endregion
563
+ //#region src/binding-magic-string.ts
564
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
565
+ Object.defineProperty(import_binding.BindingMagicString.prototype, "isRolldownMagicString", {
566
+ value: true,
567
+ writable: false,
568
+ configurable: false
569
+ });
570
+ const nativeReplace = import_binding.BindingMagicString.prototype.replace;
571
+ const nativeReplaceAll = import_binding.BindingMagicString.prototype.replaceAll;
572
+ import_binding.BindingMagicString.prototype.replace = function(searchValue, replacement) {
573
+ if (typeof searchValue === "string") return nativeReplace.call(this, searchValue, replacement);
574
+ if (searchValue.global) searchValue.lastIndex = 0;
575
+ const lastMatchEnd = this.replaceRegex(searchValue, replacement);
576
+ if (searchValue.global) searchValue.lastIndex = 0;
577
+ else if (searchValue.sticky) searchValue.lastIndex = lastMatchEnd === -1 ? 0 : lastMatchEnd;
578
+ return this;
579
+ };
580
+ import_binding.BindingMagicString.prototype.replaceAll = function(searchValue, replacement) {
581
+ if (typeof searchValue === "string") return nativeReplaceAll.call(this, searchValue, replacement);
582
+ if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
583
+ searchValue.lastIndex = 0;
584
+ this.replaceRegex(searchValue, replacement);
585
+ searchValue.lastIndex = 0;
586
+ return this;
587
+ };
588
+ /**
589
+ * A native MagicString implementation powered by Rust.
590
+ *
591
+ * @experimental
592
+ */
593
+ const RolldownMagicString = import_binding.BindingMagicString;
594
+ //#endregion
595
+ //#region src/utils/transform-module-info.ts
596
+ function transformModuleInfo(info, option) {
597
+ return {
598
+ get ast() {
599
+ return unsupported("ModuleInfo#ast");
600
+ },
601
+ get code() {
602
+ return info.code;
603
+ },
604
+ id: info.id,
605
+ importers: info.importers,
606
+ dynamicImporters: info.dynamicImporters,
607
+ importedIds: info.importedIds,
608
+ dynamicallyImportedIds: info.dynamicallyImportedIds,
609
+ exports: info.exports,
610
+ isEntry: info.isEntry,
611
+ inputFormat: info.inputFormat,
612
+ ...option
613
+ };
614
+ }
615
+ //#endregion
616
+ //#region src/utils/transform-sourcemap.ts
617
+ function isEmptySourcemapFiled(array) {
618
+ if (!array) return true;
619
+ if (array.length === 0 || !array[0]) return true;
620
+ return false;
621
+ }
622
+ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
623
+ if (!rawMap) return;
624
+ let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
625
+ if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
626
+ if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
627
+ return map;
628
+ }
629
+ //#endregion
630
+ //#region ../../node_modules/.pnpm/remeda@2.33.6/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
631
+ function e(e, t, n) {
632
+ let r = (n) => e(n, ...t);
633
+ return n === void 0 ? r : Object.assign(r, {
634
+ lazy: n,
635
+ lazyArgs: t
636
+ });
637
+ }
638
+ //#endregion
639
+ //#region ../../node_modules/.pnpm/remeda@2.33.6/node_modules/remeda/dist/purry.js
640
+ function t$1(t, n, r) {
641
+ let i = t.length - n.length;
642
+ if (i === 0) return t(...n);
643
+ if (i === 1) return e(t, n, r);
644
+ throw Error(`Wrong number of arguments`);
645
+ }
646
+ //#endregion
647
+ //#region ../../node_modules/.pnpm/remeda@2.33.6/node_modules/remeda/dist/partition.js
648
+ function t(...t) {
649
+ return t$1(n, t);
650
+ }
651
+ const n = (e, t) => {
652
+ let n = [[], []];
653
+ for (let [r, i] of e.entries()) t(i, r, e) ? n[0].push(i) : n[1].push(i);
654
+ return n;
655
+ };
656
+ //#endregion
657
+ //#region src/plugin/bindingify-hook-filter.ts
658
+ function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
659
+ if (typeof matcher === "string" || matcher instanceof RegExp) return [filter.include(generateAtomMatcher(stringKind, matcher))];
660
+ if (Array.isArray(matcher)) return matcher.map((m) => filter.include(generateAtomMatcher(stringKind, m)));
661
+ let ret = [];
662
+ if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => filter.exclude(generateAtomMatcher(stringKind, m))));
663
+ if (matcher.include) ret.push(...arraify(matcher.include).map((m) => filter.include(generateAtomMatcher(stringKind, m))));
664
+ return ret;
665
+ }
666
+ function generateAtomMatcher(kind, matcher) {
667
+ return kind === "code" ? filter.code(matcher) : filter.id(matcher);
668
+ }
669
+ function transformFilterMatcherToFilterExprs(filterOption) {
670
+ if (!filterOption) return;
671
+ if (Array.isArray(filterOption)) return filterOption;
672
+ const { id, code, moduleType } = filterOption;
673
+ let ret = [];
674
+ let idIncludes = [];
675
+ let idExcludes = [];
676
+ let codeIncludes = [];
677
+ let codeExcludes = [];
678
+ if (id) [idIncludes, idExcludes] = t(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
679
+ if (code) [codeIncludes, codeExcludes] = t(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
680
+ ret.push(...idExcludes);
681
+ ret.push(...codeExcludes);
682
+ let andExprList = [];
683
+ if (moduleType) {
684
+ let moduleTypes = Array.isArray(moduleType) ? moduleType : moduleType.include ?? [];
685
+ andExprList.push(filter.or(...moduleTypes.map((m) => filter.moduleType(m))));
686
+ }
687
+ if (idIncludes.length) andExprList.push(filter.or(...idIncludes.map((item) => item.expr)));
688
+ if (codeIncludes.length) andExprList.push(filter.or(...codeIncludes.map((item) => item.expr)));
689
+ if (andExprList.length) ret.push(filter.include(filter.and(...andExprList)));
690
+ return ret;
691
+ }
692
+ function bindingifyGeneralHookFilter(stringKind, pattern) {
693
+ let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
694
+ let ret = [];
695
+ if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
696
+ return ret.length > 0 ? { value: ret } : void 0;
697
+ }
698
+ function bindingifyFilterExpr(expr) {
699
+ let list = [];
700
+ bindingifyFilterExprImpl(expr, list);
701
+ return list;
702
+ }
703
+ function containsImporterId(expr) {
704
+ switch (expr.kind) {
705
+ case "and":
706
+ case "or": return expr.args.some(containsImporterId);
707
+ case "not":
708
+ case "include":
709
+ case "exclude": return containsImporterId(expr.expr);
710
+ case "importerId": return true;
711
+ default: return false;
712
+ }
713
+ }
714
+ function assertNoImporterId(filterExprs, hookName) {
715
+ if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
716
+ }
717
+ function bindingifyFilterExprImpl(expr, list) {
718
+ switch (expr.kind) {
719
+ case "and": {
720
+ let args = expr.args;
721
+ for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
722
+ list.push({
723
+ kind: "And",
724
+ payload: args.length
725
+ });
726
+ break;
727
+ }
728
+ case "or": {
729
+ let args = expr.args;
730
+ for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
731
+ list.push({
732
+ kind: "Or",
733
+ payload: args.length
734
+ });
735
+ break;
736
+ }
737
+ case "not":
738
+ bindingifyFilterExprImpl(expr.expr, list);
739
+ list.push({ kind: "Not" });
740
+ break;
741
+ case "id":
742
+ list.push({
743
+ kind: "Id",
744
+ payload: expr.pattern
745
+ });
746
+ if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
747
+ break;
748
+ case "importerId":
749
+ list.push({
750
+ kind: "ImporterId",
751
+ payload: expr.pattern
752
+ });
753
+ if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
754
+ break;
755
+ case "moduleType":
756
+ list.push({
757
+ kind: "ModuleType",
758
+ payload: expr.pattern
759
+ });
760
+ break;
761
+ case "code":
762
+ list.push({
763
+ kind: "Code",
764
+ payload: expr.pattern
765
+ });
766
+ break;
767
+ case "include":
768
+ bindingifyFilterExprImpl(expr.expr, list);
769
+ list.push({ kind: "Include" });
770
+ break;
771
+ case "exclude":
772
+ bindingifyFilterExprImpl(expr.expr, list);
773
+ list.push({ kind: "Exclude" });
774
+ break;
775
+ case "query":
776
+ list.push({
777
+ kind: "QueryKey",
778
+ payload: expr.key
779
+ });
780
+ list.push({
781
+ kind: "QueryValue",
782
+ payload: expr.pattern
783
+ });
784
+ break;
785
+ default: throw new Error(`Unknown filter expression: ${expr}`);
786
+ }
787
+ }
788
+ function bindingifyResolveIdFilter(filterOption) {
789
+ if (!filterOption) return;
790
+ if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
791
+ return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
792
+ }
793
+ function bindingifyLoadFilter(filterOption) {
794
+ if (!filterOption) return;
795
+ if (Array.isArray(filterOption)) {
796
+ assertNoImporterId(filterOption, "load");
797
+ return { value: filterOption.map(bindingifyFilterExpr) };
798
+ }
799
+ return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
800
+ }
801
+ function bindingifyTransformFilter(filterOption) {
802
+ if (!filterOption) return;
803
+ let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
804
+ assertNoImporterId(filterExprs, "transform");
805
+ let ret = [];
806
+ if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
807
+ return { value: ret.length > 0 ? ret : void 0 };
808
+ }
809
+ function bindingifyRenderChunkFilter(filterOption) {
810
+ if (!filterOption) return;
811
+ if (Array.isArray(filterOption)) {
812
+ assertNoImporterId(filterOption, "renderChunk");
813
+ return { value: filterOption.map(bindingifyFilterExpr) };
814
+ }
815
+ return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
816
+ }
817
+ //#endregion
818
+ //#region src/plugin/bindingify-plugin-hook-meta.ts
819
+ function bindingifyPluginHookMeta(options) {
820
+ return { order: bindingPluginOrder(options.order) };
821
+ }
822
+ function bindingPluginOrder(order) {
823
+ switch (order) {
824
+ case "post": return import_binding.BindingPluginOrder.Post;
825
+ case "pre": return import_binding.BindingPluginOrder.Pre;
826
+ case null:
827
+ case void 0: return;
828
+ default: throw new Error(`Unknown plugin order: ${order}`);
829
+ }
830
+ }
831
+ //#endregion
832
+ //#region src/plugin/fs.ts
833
+ const fsModule = {
834
+ appendFile: fsp.appendFile,
835
+ copyFile: fsp.copyFile,
836
+ mkdir: fsp.mkdir,
837
+ mkdtemp: fsp.mkdtemp,
838
+ readdir: fsp.readdir,
839
+ readFile: fsp.readFile,
840
+ realpath: fsp.realpath,
841
+ rename: fsp.rename,
842
+ rmdir: fsp.rmdir,
843
+ stat: fsp.stat,
844
+ lstat: fsp.lstat,
845
+ unlink: fsp.unlink,
846
+ writeFile: fsp.writeFile
847
+ };
848
+ //#endregion
849
+ //#region src/plugin/plugin-context.ts
850
+ var PluginContextImpl = class extends MinimalPluginContextImpl {
851
+ fs = fsModule;
852
+ getModuleInfo;
853
+ constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
854
+ super(onLog, logLevel, plugin.name, watchMode);
855
+ this.outputOptions = outputOptions;
856
+ this.context = context;
857
+ this.data = data;
858
+ this.onLog = onLog;
859
+ this.currentLoadingModule = currentLoadingModule;
860
+ this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
861
+ }
862
+ async load(options) {
863
+ const id = options.id;
864
+ if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
865
+ const moduleInfo = this.data.getModuleInfo(id, this.context);
866
+ if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
867
+ const rawOptions = {
868
+ meta: options.meta || {},
869
+ moduleSideEffects: options.moduleSideEffects || null,
870
+ invalidate: false
871
+ };
872
+ this.data.updateModuleOption(id, rawOptions);
873
+ let loadPromise = this.data.loadModulePromiseMap.get(id);
874
+ if (!loadPromise) {
875
+ loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
876
+ this.data.loadModulePromiseMap.delete(id);
877
+ });
878
+ this.data.loadModulePromiseMap.set(id, loadPromise);
879
+ }
880
+ await loadPromise;
881
+ return this.data.getModuleInfo(id, this.context);
882
+ }
883
+ async resolve(source, importer, options) {
884
+ let receipt = void 0;
885
+ if (options != null) receipt = this.data.saveResolveOptions(options);
886
+ const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
887
+ if (key.startsWith("vite:")) (acc ??= {})[key] = value;
888
+ return acc;
889
+ }, void 0);
890
+ const res = await this.context.resolve(source, importer, {
891
+ importKind: options?.kind,
892
+ custom: receipt,
893
+ isEntry: options?.isEntry,
894
+ skipSelf: options?.skipSelf,
895
+ vitePluginCustom
896
+ });
897
+ if (receipt != null) this.data.removeSavedResolveOptions(receipt);
898
+ if (res == null) return null;
899
+ const info = this.data.getModuleOption(res.id) || {};
900
+ return {
901
+ ...res,
902
+ external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
903
+ ...info,
904
+ moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
905
+ packageJsonPath: res.packageJsonPath
906
+ };
907
+ }
908
+ emitFile = (file) => {
909
+ if (file.type === "prebuilt-chunk") return this.context.emitPrebuiltChunk({
910
+ fileName: file.fileName,
911
+ name: file.name,
912
+ code: file.code,
913
+ exports: file.exports,
914
+ map: bindingifySourcemap(file.map),
915
+ sourcemapFileName: file.sourcemapFileName,
916
+ facadeModuleId: file.facadeModuleId,
917
+ isEntry: file.isEntry,
918
+ isDynamicEntry: file.isDynamicEntry
919
+ });
920
+ if (file.type === "chunk") return this.context.emitChunk({
921
+ preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
922
+ ...file
923
+ });
924
+ const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
925
+ const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
926
+ return this.context.emitFile({
927
+ ...file,
928
+ originalFileName: file.originalFileName || void 0,
929
+ source: bindingAssetSource(file.source)
930
+ }, filename, fnSanitizedFileName);
931
+ };
932
+ getAssetFileNames(file) {
933
+ if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
934
+ type: "asset",
935
+ name: file.name,
936
+ names: file.name ? [file.name] : [],
937
+ originalFileName: file.originalFileName,
938
+ originalFileNames: file.originalFileName ? [file.originalFileName] : [],
939
+ source: file.source
940
+ });
941
+ }
942
+ getFileName(referenceId) {
943
+ return this.context.getFileName(referenceId);
944
+ }
945
+ getModuleIds() {
946
+ return this.data.getModuleIds(this.context);
947
+ }
948
+ addWatchFile(id) {
949
+ this.context.addWatchFile(id);
950
+ }
951
+ parse(input, options) {
952
+ return parseAst(input, options);
953
+ }
954
+ };
955
+ //#endregion
956
+ //#region src/plugin/load-plugin-context.ts
957
+ var LoadPluginContextImpl = class extends PluginContextImpl {
958
+ constructor(outputOptions, context, plugin, data, inner, moduleId, onLog, logLevelOption, watchMode) {
959
+ super(outputOptions, context, plugin, data, onLog, logLevelOption, watchMode, moduleId);
960
+ this.inner = inner;
961
+ }
962
+ addWatchFile(id) {
963
+ this.inner.addWatchFile(id);
964
+ }
965
+ };
966
+ //#endregion
967
+ //#region src/plugin/transform-plugin-context.ts
968
+ var TransformPluginContextImpl = class extends PluginContextImpl {
969
+ constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
970
+ super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
971
+ this.inner = inner;
972
+ this.moduleId = moduleId;
973
+ this.moduleSource = moduleSource;
974
+ const getLogHandler = (handler) => (log, pos) => {
975
+ log = normalizeLog(log);
976
+ if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
977
+ log.id = moduleId;
978
+ log.hook = "transform";
979
+ handler(log);
980
+ };
981
+ this.debug = getLogHandler(this.debug);
982
+ this.warn = getLogHandler(this.warn);
983
+ this.info = getLogHandler(this.info);
984
+ }
985
+ error(e, pos) {
986
+ if (typeof e === "string") e = { message: e };
987
+ if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
988
+ e.id = this.moduleId;
989
+ e.hook = "transform";
990
+ return error(logPluginError(normalizeLog(e), this.pluginName));
991
+ }
992
+ getCombinedSourcemap() {
993
+ return JSON.parse(this.inner.getCombinedSourcemap());
994
+ }
995
+ addWatchFile(id) {
996
+ this.inner.addWatchFile(id);
997
+ }
998
+ sendMagicString(s) {
999
+ this.inner.sendMagicString(s);
1000
+ }
1001
+ };
1002
+ //#endregion
1003
+ //#region src/plugin/bindingify-build-hooks.ts
1004
+ function createPluginContext(args, ctx) {
1005
+ return new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1006
+ }
1007
+ function bindingifyBuildStart(args) {
1008
+ const hook = args.plugin.buildStart;
1009
+ if (!hook) return {};
1010
+ const { handler, meta } = normalizeHook(hook);
1011
+ return {
1012
+ plugin: async (ctx, opts) => {
1013
+ await handler.call(createPluginContext(args, ctx), args.pluginContextData.getInputOptions(opts));
1014
+ },
1015
+ meta: bindingifyPluginHookMeta(meta)
1016
+ };
1017
+ }
1018
+ function bindingifyBuildEnd(args) {
1019
+ const hook = args.plugin.buildEnd;
1020
+ if (!hook) return {};
1021
+ const { handler, meta } = normalizeHook(hook);
1022
+ return {
1023
+ plugin: async (ctx, err) => {
1024
+ await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1025
+ },
1026
+ meta: bindingifyPluginHookMeta(meta)
1027
+ };
1028
+ }
1029
+ function bindingifyResolveId(args) {
1030
+ const hook = args.plugin.resolveId;
1031
+ if (!hook) return {};
1032
+ const { handler, meta, options } = normalizeHook(hook);
1033
+ return {
1034
+ plugin: async (ctx, specifier, importer, extraOptions) => {
1035
+ const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
1036
+ const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0, {
1037
+ ...extraOptions,
1038
+ custom: contextResolveOptions?.custom
1039
+ });
1040
+ if (ret == null) return;
1041
+ if (ret === false) return {
1042
+ id: specifier,
1043
+ external: true,
1044
+ normalizeExternalId: true
1045
+ };
1046
+ if (typeof ret === "string") return {
1047
+ id: ret,
1048
+ normalizeExternalId: false
1049
+ };
1050
+ let exist = args.pluginContextData.updateModuleOption(ret.id, {
1051
+ meta: ret.meta || {},
1052
+ moduleSideEffects: ret.moduleSideEffects ?? null,
1053
+ invalidate: false
1054
+ });
1055
+ return {
1056
+ id: ret.id,
1057
+ external: ret.external,
1058
+ normalizeExternalId: false,
1059
+ moduleSideEffects: exist.moduleSideEffects ?? void 0,
1060
+ packageJsonPath: ret.packageJsonPath
1061
+ };
1062
+ },
1063
+ meta: bindingifyPluginHookMeta(meta),
1064
+ filter: bindingifyResolveIdFilter(options.filter)
1065
+ };
1066
+ }
1067
+ function bindingifyResolveDynamicImport(args) {
1068
+ const hook = args.plugin.resolveDynamicImport;
1069
+ if (!hook) return {};
1070
+ const { handler, meta } = normalizeHook(hook);
1071
+ return {
1072
+ plugin: async (ctx, specifier, importer) => {
1073
+ const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0);
1074
+ if (ret == null) return;
1075
+ if (ret === false) return {
1076
+ id: specifier,
1077
+ external: true
1078
+ };
1079
+ if (typeof ret === "string") return { id: ret };
1080
+ const result = {
1081
+ id: ret.id,
1082
+ external: ret.external,
1083
+ packageJsonPath: ret.packageJsonPath
1084
+ };
1085
+ if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
1086
+ args.pluginContextData.updateModuleOption(ret.id, {
1087
+ meta: ret.meta || {},
1088
+ moduleSideEffects: ret.moduleSideEffects || null,
1089
+ invalidate: false
1090
+ });
1091
+ return result;
1092
+ },
1093
+ meta: bindingifyPluginHookMeta(meta)
1094
+ };
1095
+ }
1096
+ function bindingifyTransform(args) {
1097
+ const hook = args.plugin.transform;
1098
+ if (!hook) return {};
1099
+ const { handler, meta, options } = normalizeHook(hook);
1100
+ return {
1101
+ plugin: async (ctx, code, id, meta) => {
1102
+ let magicStringInstance, astInstance;
1103
+ Object.defineProperties(meta, {
1104
+ magicString: { get() {
1105
+ if (magicStringInstance) return magicStringInstance;
1106
+ magicStringInstance = new RolldownMagicString(code);
1107
+ return magicStringInstance;
1108
+ } },
1109
+ ast: { get() {
1110
+ if (astInstance) return astInstance;
1111
+ let lang = "js";
1112
+ switch (meta.moduleType) {
1113
+ case "js":
1114
+ case "jsx":
1115
+ case "ts":
1116
+ case "tsx":
1117
+ lang = meta.moduleType;
1118
+ break;
1119
+ default: break;
1120
+ }
1121
+ astInstance = parseAst(code, {
1122
+ astType: meta.moduleType.includes("ts") ? "ts" : "js",
1123
+ lang
1124
+ });
1125
+ return astInstance;
1126
+ } }
1127
+ });
1128
+ const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
1129
+ const ret = await handler.call(transformCtx, code, id, meta);
1130
+ if (ret == null) return;
1131
+ if (typeof ret === "string") return { code: ret };
1132
+ let moduleOption = args.pluginContextData.updateModuleOption(id, {
1133
+ meta: ret.meta ?? {},
1134
+ moduleSideEffects: ret.moduleSideEffects ?? null,
1135
+ invalidate: false
1136
+ });
1137
+ let normalizedCode = void 0;
1138
+ let map = ret.map;
1139
+ if (typeof ret.code === "string") normalizedCode = ret.code;
1140
+ else if (ret.code instanceof RolldownMagicString) {
1141
+ let magicString = ret.code;
1142
+ normalizedCode = magicString.toString();
1143
+ let fallbackSourcemap = ctx.sendMagicString(magicString);
1144
+ if (fallbackSourcemap != void 0) map = fallbackSourcemap;
1145
+ }
1146
+ return {
1147
+ code: normalizedCode,
1148
+ map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)),
1149
+ moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
1150
+ moduleType: ret.moduleType
1151
+ };
1152
+ },
1153
+ meta: bindingifyPluginHookMeta(meta),
1154
+ filter: bindingifyTransformFilter(options.filter)
1155
+ };
1156
+ }
1157
+ function bindingifyLoad(args) {
1158
+ const hook = args.plugin.load;
1159
+ if (!hook) return {};
1160
+ const { handler, meta, options } = normalizeHook(hook);
1161
+ return {
1162
+ plugin: async (ctx, id) => {
1163
+ const ret = await handler.call(new LoadPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, args.onLog, args.logLevel, args.watchMode), id);
1164
+ if (ret == null) return;
1165
+ if (typeof ret === "string") return { code: ret };
1166
+ let moduleOption = args.pluginContextData.updateModuleOption(id, {
1167
+ meta: ret.meta || {},
1168
+ moduleSideEffects: ret.moduleSideEffects ?? null,
1169
+ invalidate: false
1170
+ });
1171
+ let map = preProcessSourceMap(ret, id);
1172
+ return {
1173
+ code: ret.code,
1174
+ map: bindingifySourcemap(map),
1175
+ moduleType: ret.moduleType,
1176
+ moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
1177
+ };
1178
+ },
1179
+ meta: bindingifyPluginHookMeta(meta),
1180
+ filter: bindingifyLoadFilter(options.filter)
1181
+ };
1182
+ }
1183
+ function preProcessSourceMap(ret, id) {
1184
+ if (!ret.map) return;
1185
+ let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
1186
+ if (!isEmptySourcemapFiled(map.sources)) {
1187
+ const directory = path.dirname(id) || ".";
1188
+ const sourceRoot = map.sourceRoot || ".";
1189
+ map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
1190
+ }
1191
+ return map;
1192
+ }
1193
+ function bindingifyModuleParsed(args) {
1194
+ const hook = args.plugin.moduleParsed;
1195
+ if (!hook) return {};
1196
+ const { handler, meta } = normalizeHook(hook);
1197
+ return {
1198
+ plugin: async (ctx, moduleInfo) => {
1199
+ await handler.call(createPluginContext(args, ctx), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
1200
+ },
1201
+ meta: bindingifyPluginHookMeta(meta)
1202
+ };
1203
+ }
1204
+ //#endregion
1205
+ //#region src/plugin/bindingify-output-hooks.ts
1206
+ function bindingifyRenderStart(args) {
1207
+ const hook = args.plugin.renderStart;
1208
+ if (!hook) return {};
1209
+ const { handler, meta } = normalizeHook(hook);
1210
+ return {
1211
+ plugin: async (ctx, opts) => {
1212
+ handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
1213
+ },
1214
+ meta: bindingifyPluginHookMeta(meta)
1215
+ };
1216
+ }
1217
+ function bindingifyRenderChunk(args) {
1218
+ const hook = args.plugin.renderChunk;
1219
+ if (!hook) return {};
1220
+ const { handler, meta, options } = normalizeHook(hook);
1221
+ return {
1222
+ plugin: async (ctx, code, chunk, opts, meta) => {
1223
+ if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
1224
+ const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
1225
+ let magicStringInstance;
1226
+ if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
1227
+ get() {
1228
+ if (magicStringInstance) return magicStringInstance;
1229
+ magicStringInstance = new RolldownMagicString(code);
1230
+ return magicStringInstance;
1231
+ },
1232
+ configurable: true
1233
+ });
1234
+ const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
1235
+ if (ret == null) return;
1236
+ if (ret instanceof RolldownMagicString) {
1237
+ const normalizedCode = ret.toString();
1238
+ const generatedMap = ret.generateMap();
1239
+ return {
1240
+ code: normalizedCode,
1241
+ map: bindingifySourcemap({
1242
+ file: generatedMap.file,
1243
+ mappings: generatedMap.mappings,
1244
+ names: generatedMap.names,
1245
+ sources: generatedMap.sources,
1246
+ sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1247
+ })
1248
+ };
1249
+ }
1250
+ if (typeof ret === "string") return { code: ret };
1251
+ if (ret.code instanceof RolldownMagicString) {
1252
+ const magicString = ret.code;
1253
+ const normalizedCode = magicString.toString();
1254
+ if (ret.map === null) return { code: normalizedCode };
1255
+ if (ret.map === void 0) {
1256
+ const generatedMap = magicString.generateMap();
1257
+ return {
1258
+ code: normalizedCode,
1259
+ map: bindingifySourcemap({
1260
+ file: generatedMap.file,
1261
+ mappings: generatedMap.mappings,
1262
+ names: generatedMap.names,
1263
+ sources: generatedMap.sources,
1264
+ sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1265
+ })
1266
+ };
1267
+ }
1268
+ return {
1269
+ code: normalizedCode,
1270
+ map: bindingifySourcemap(ret.map)
1271
+ };
1272
+ }
1273
+ if (!ret.map) return { code: ret.code };
1274
+ return {
1275
+ code: ret.code,
1276
+ map: bindingifySourcemap(ret.map)
1277
+ };
1278
+ },
1279
+ meta: bindingifyPluginHookMeta(meta),
1280
+ filter: bindingifyRenderChunkFilter(options.filter)
1281
+ };
1282
+ }
1283
+ function bindingifyAugmentChunkHash(args) {
1284
+ const hook = args.plugin.augmentChunkHash;
1285
+ if (!hook) return {};
1286
+ const { handler, meta } = normalizeHook(hook);
1287
+ return {
1288
+ plugin: async (ctx, chunk) => {
1289
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1290
+ },
1291
+ meta: bindingifyPluginHookMeta(meta)
1292
+ };
1293
+ }
1294
+ function bindingifyRenderError(args) {
1295
+ const hook = args.plugin.renderError;
1296
+ if (!hook) return {};
1297
+ const { handler, meta } = normalizeHook(hook);
1298
+ return {
1299
+ plugin: async (ctx, err) => {
1300
+ handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
1301
+ },
1302
+ meta: bindingifyPluginHookMeta(meta)
1303
+ };
1304
+ }
1305
+ function bindingifyGenerateBundle(args) {
1306
+ const hook = args.plugin.generateBundle;
1307
+ if (!hook) return {};
1308
+ const { handler, meta } = normalizeHook(hook);
1309
+ return {
1310
+ plugin: async (ctx, bundle, isWrite, opts) => {
1311
+ const changed = {
1312
+ updated: /* @__PURE__ */ new Set(),
1313
+ deleted: /* @__PURE__ */ new Set()
1314
+ };
1315
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1316
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1317
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
1318
+ return collectChangedBundle(changed, output);
1319
+ },
1320
+ meta: bindingifyPluginHookMeta(meta)
1321
+ };
1322
+ }
1323
+ function bindingifyWriteBundle(args) {
1324
+ const hook = args.plugin.writeBundle;
1325
+ if (!hook) return {};
1326
+ const { handler, meta } = normalizeHook(hook);
1327
+ return {
1328
+ plugin: async (ctx, bundle, opts) => {
1329
+ const changed = {
1330
+ updated: /* @__PURE__ */ new Set(),
1331
+ deleted: /* @__PURE__ */ new Set()
1332
+ };
1333
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1334
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1335
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
1336
+ return collectChangedBundle(changed, output);
1337
+ },
1338
+ meta: bindingifyPluginHookMeta(meta)
1339
+ };
1340
+ }
1341
+ function bindingifyCloseBundle(args) {
1342
+ const hook = args.plugin.closeBundle;
1343
+ if (!hook) return {};
1344
+ const { handler, meta } = normalizeHook(hook);
1345
+ return {
1346
+ plugin: async (ctx, err) => {
1347
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1348
+ },
1349
+ meta: bindingifyPluginHookMeta(meta)
1350
+ };
1351
+ }
1352
+ function bindingifyBanner(args) {
1353
+ const hook = args.plugin.banner;
1354
+ if (!hook) return {};
1355
+ const { handler, meta } = normalizeHook(hook);
1356
+ return {
1357
+ plugin: async (ctx, chunk) => {
1358
+ if (typeof handler === "string") return handler;
1359
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1360
+ },
1361
+ meta: bindingifyPluginHookMeta(meta)
1362
+ };
1363
+ }
1364
+ function bindingifyFooter(args) {
1365
+ const hook = args.plugin.footer;
1366
+ if (!hook) return {};
1367
+ const { handler, meta } = normalizeHook(hook);
1368
+ return {
1369
+ plugin: async (ctx, chunk) => {
1370
+ if (typeof handler === "string") return handler;
1371
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1372
+ },
1373
+ meta: bindingifyPluginHookMeta(meta)
1374
+ };
1375
+ }
1376
+ function bindingifyIntro(args) {
1377
+ const hook = args.plugin.intro;
1378
+ if (!hook) return {};
1379
+ const { handler, meta } = normalizeHook(hook);
1380
+ return {
1381
+ plugin: async (ctx, chunk) => {
1382
+ if (typeof handler === "string") return handler;
1383
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1384
+ },
1385
+ meta: bindingifyPluginHookMeta(meta)
1386
+ };
1387
+ }
1388
+ function bindingifyOutro(args) {
1389
+ const hook = args.plugin.outro;
1390
+ if (!hook) return {};
1391
+ const { handler, meta } = normalizeHook(hook);
1392
+ return {
1393
+ plugin: async (ctx, chunk) => {
1394
+ if (typeof handler === "string") return handler;
1395
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1396
+ },
1397
+ meta: bindingifyPluginHookMeta(meta)
1398
+ };
1399
+ }
1400
+ //#endregion
1401
+ //#region src/plugin/bindingify-watch-hooks.ts
1402
+ function bindingifyWatchChange(args) {
1403
+ const hook = args.plugin.watchChange;
1404
+ if (!hook) return {};
1405
+ const { handler, meta } = normalizeHook(hook);
1406
+ return {
1407
+ plugin: async (ctx, id, event) => {
1408
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
1409
+ },
1410
+ meta: bindingifyPluginHookMeta(meta)
1411
+ };
1412
+ }
1413
+ function bindingifyCloseWatcher(args) {
1414
+ const hook = args.plugin.closeWatcher;
1415
+ if (!hook) return {};
1416
+ const { handler, meta } = normalizeHook(hook);
1417
+ return {
1418
+ plugin: async (ctx) => {
1419
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
1420
+ },
1421
+ meta: bindingifyPluginHookMeta(meta)
1422
+ };
1423
+ }
1424
+ //#endregion
1425
+ //#region src/plugin/generated/hook-usage.ts
1426
+ let HookUsageKind = /* @__PURE__ */ function(HookUsageKind) {
1427
+ HookUsageKind[HookUsageKind["buildStart"] = 1] = "buildStart";
1428
+ HookUsageKind[HookUsageKind["resolveId"] = 2] = "resolveId";
1429
+ HookUsageKind[HookUsageKind["resolveDynamicImport"] = 4] = "resolveDynamicImport";
1430
+ HookUsageKind[HookUsageKind["load"] = 8] = "load";
1431
+ HookUsageKind[HookUsageKind["transform"] = 16] = "transform";
1432
+ HookUsageKind[HookUsageKind["moduleParsed"] = 32] = "moduleParsed";
1433
+ HookUsageKind[HookUsageKind["buildEnd"] = 64] = "buildEnd";
1434
+ HookUsageKind[HookUsageKind["renderStart"] = 128] = "renderStart";
1435
+ HookUsageKind[HookUsageKind["renderError"] = 256] = "renderError";
1436
+ HookUsageKind[HookUsageKind["renderChunk"] = 512] = "renderChunk";
1437
+ HookUsageKind[HookUsageKind["augmentChunkHash"] = 1024] = "augmentChunkHash";
1438
+ HookUsageKind[HookUsageKind["generateBundle"] = 2048] = "generateBundle";
1439
+ HookUsageKind[HookUsageKind["writeBundle"] = 4096] = "writeBundle";
1440
+ HookUsageKind[HookUsageKind["closeBundle"] = 8192] = "closeBundle";
1441
+ HookUsageKind[HookUsageKind["watchChange"] = 16384] = "watchChange";
1442
+ HookUsageKind[HookUsageKind["closeWatcher"] = 32768] = "closeWatcher";
1443
+ HookUsageKind[HookUsageKind["transformAst"] = 65536] = "transformAst";
1444
+ HookUsageKind[HookUsageKind["banner"] = 131072] = "banner";
1445
+ HookUsageKind[HookUsageKind["footer"] = 262144] = "footer";
1446
+ HookUsageKind[HookUsageKind["intro"] = 524288] = "intro";
1447
+ HookUsageKind[HookUsageKind["outro"] = 1048576] = "outro";
1448
+ return HookUsageKind;
1449
+ }({});
1450
+ var HookUsage = class {
1451
+ bitflag = BigInt(0);
1452
+ constructor() {}
1453
+ union(kind) {
1454
+ this.bitflag |= BigInt(kind);
1455
+ }
1456
+ inner() {
1457
+ return Number(this.bitflag);
1458
+ }
1459
+ };
1460
+ function extractHookUsage(plugin) {
1461
+ let hookUsage = new HookUsage();
1462
+ if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
1463
+ if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
1464
+ if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
1465
+ if (plugin.load) hookUsage.union(HookUsageKind.load);
1466
+ if (plugin.transform) hookUsage.union(HookUsageKind.transform);
1467
+ if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
1468
+ if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
1469
+ if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
1470
+ if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
1471
+ if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
1472
+ if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
1473
+ if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
1474
+ if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
1475
+ if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
1476
+ if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
1477
+ if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
1478
+ if (plugin.banner) hookUsage.union(HookUsageKind.banner);
1479
+ if (plugin.footer) hookUsage.union(HookUsageKind.footer);
1480
+ if (plugin.intro) hookUsage.union(HookUsageKind.intro);
1481
+ if (plugin.outro) hookUsage.union(HookUsageKind.outro);
1482
+ return hookUsage;
1483
+ }
1484
+ //#endregion
1485
+ //#region src/plugin/bindingify-plugin.ts
1486
+ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
1487
+ const args = {
1488
+ plugin,
1489
+ options,
1490
+ outputOptions,
1491
+ pluginContextData,
1492
+ onLog,
1493
+ logLevel,
1494
+ watchMode,
1495
+ normalizedOutputPlugins
1496
+ };
1497
+ const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
1498
+ const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
1499
+ const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
1500
+ const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
1501
+ const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
1502
+ const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
1503
+ const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1504
+ const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
1505
+ const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
1506
+ const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1507
+ const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1508
+ const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1509
+ const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1510
+ const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1511
+ const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1512
+ const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1513
+ const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1514
+ const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
1515
+ const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
1516
+ const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1517
+ let hookUsage = extractHookUsage(plugin).inner();
1518
+ return wrapHandlers({
1519
+ name: plugin.name,
1520
+ buildStart,
1521
+ buildStartMeta,
1522
+ resolveId,
1523
+ resolveIdMeta,
1524
+ resolveIdFilter,
1525
+ resolveDynamicImport,
1526
+ resolveDynamicImportMeta,
1527
+ buildEnd,
1528
+ buildEndMeta,
1529
+ transform,
1530
+ transformMeta,
1531
+ transformFilter,
1532
+ moduleParsed,
1533
+ moduleParsedMeta,
1534
+ load,
1535
+ loadMeta,
1536
+ loadFilter,
1537
+ renderChunk,
1538
+ renderChunkMeta,
1539
+ renderChunkFilter,
1540
+ augmentChunkHash,
1541
+ augmentChunkHashMeta,
1542
+ renderStart,
1543
+ renderStartMeta,
1544
+ renderError,
1545
+ renderErrorMeta,
1546
+ generateBundle,
1547
+ generateBundleMeta,
1548
+ writeBundle,
1549
+ writeBundleMeta,
1550
+ closeBundle,
1551
+ closeBundleMeta,
1552
+ banner,
1553
+ bannerMeta,
1554
+ footer,
1555
+ footerMeta,
1556
+ intro,
1557
+ introMeta,
1558
+ outro,
1559
+ outroMeta,
1560
+ watchChange,
1561
+ watchChangeMeta,
1562
+ closeWatcher,
1563
+ closeWatcherMeta,
1564
+ hookUsage
1565
+ });
1566
+ }
1567
+ function wrapHandlers(plugin) {
1568
+ for (const hookName of [
1569
+ "buildStart",
1570
+ "resolveId",
1571
+ "resolveDynamicImport",
1572
+ "buildEnd",
1573
+ "transform",
1574
+ "moduleParsed",
1575
+ "load",
1576
+ "renderChunk",
1577
+ "augmentChunkHash",
1578
+ "renderStart",
1579
+ "renderError",
1580
+ "generateBundle",
1581
+ "writeBundle",
1582
+ "closeBundle",
1583
+ "banner",
1584
+ "footer",
1585
+ "intro",
1586
+ "outro",
1587
+ "watchChange",
1588
+ "closeWatcher"
1589
+ ]) {
1590
+ const handler = plugin[hookName];
1591
+ if (handler) plugin[hookName] = async (...args) => {
1592
+ try {
1593
+ return await handler(...args);
1594
+ } catch (e) {
1595
+ return error(logPluginError(e, plugin.name, {
1596
+ hook: hookName,
1597
+ id: hookName === "transform" ? args[2] : void 0
1598
+ }));
1599
+ }
1600
+ };
1601
+ }
1602
+ return plugin;
1603
+ }
1604
+ //#endregion
1605
+ //#region src/options/normalized-input-options.ts
1606
+ var NormalizedInputOptionsImpl = class extends PlainObjectLike {
1607
+ inner;
1608
+ constructor(inner, onLog, inputPlugins) {
1609
+ super();
1610
+ this.onLog = onLog;
1611
+ this.inputPlugins = inputPlugins;
1612
+ this.inner = inner;
1613
+ }
1614
+ get shimMissingExports() {
1615
+ return this.inner.shimMissingExports;
1616
+ }
1617
+ get input() {
1618
+ return this.inner.input;
1619
+ }
1620
+ get cwd() {
1621
+ return this.inner.cwd;
1622
+ }
1623
+ get platform() {
1624
+ return this.inner.platform;
1625
+ }
1626
+ get context() {
1627
+ return this.inner.context;
1628
+ }
1629
+ get plugins() {
1630
+ return this.inputPlugins;
1631
+ }
1632
+ };
1633
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
1634
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
1635
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
1636
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
1637
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
1638
+ //#endregion
1639
+ //#region src/options/normalized-output-options.ts
1640
+ var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
1641
+ constructor(inner, outputOptions, normalizedOutputPlugins) {
1642
+ super();
1643
+ this.inner = inner;
1644
+ this.outputOptions = outputOptions;
1645
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
1646
+ }
1647
+ get dir() {
1648
+ return this.inner.dir ?? void 0;
1649
+ }
1650
+ get entryFileNames() {
1651
+ return this.inner.entryFilenames || this.outputOptions.entryFileNames;
1652
+ }
1653
+ get chunkFileNames() {
1654
+ return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
1655
+ }
1656
+ get assetFileNames() {
1657
+ return this.inner.assetFilenames || this.outputOptions.assetFileNames;
1658
+ }
1659
+ get format() {
1660
+ return this.inner.format;
1661
+ }
1662
+ get exports() {
1663
+ return this.inner.exports;
1664
+ }
1665
+ get sourcemap() {
1666
+ return this.inner.sourcemap;
1667
+ }
1668
+ get sourcemapBaseUrl() {
1669
+ return this.inner.sourcemapBaseUrl ?? void 0;
1670
+ }
1671
+ get shimMissingExports() {
1672
+ return this.inner.shimMissingExports;
1673
+ }
1674
+ get name() {
1675
+ return this.inner.name ?? void 0;
1676
+ }
1677
+ get file() {
1678
+ return this.inner.file ?? void 0;
1679
+ }
1680
+ get codeSplitting() {
1681
+ return this.inner.codeSplitting;
1682
+ }
1683
+ /**
1684
+ * @deprecated Use `codeSplitting` instead.
1685
+ */
1686
+ get inlineDynamicImports() {
1687
+ return !this.inner.codeSplitting;
1688
+ }
1689
+ get dynamicImportInCjs() {
1690
+ return this.inner.dynamicImportInCjs;
1691
+ }
1692
+ get externalLiveBindings() {
1693
+ return this.inner.externalLiveBindings;
1694
+ }
1695
+ get banner() {
1696
+ return normalizeAddon(this.outputOptions.banner);
1697
+ }
1698
+ get footer() {
1699
+ return normalizeAddon(this.outputOptions.footer);
1700
+ }
1701
+ get postBanner() {
1702
+ return normalizeAddon(this.outputOptions.postBanner);
1703
+ }
1704
+ get postFooter() {
1705
+ return normalizeAddon(this.outputOptions.postFooter);
1706
+ }
1707
+ get intro() {
1708
+ return normalizeAddon(this.outputOptions.intro);
1709
+ }
1710
+ get outro() {
1711
+ return normalizeAddon(this.outputOptions.outro);
1712
+ }
1713
+ get esModule() {
1714
+ return this.inner.esModule;
1715
+ }
1716
+ get extend() {
1717
+ return this.inner.extend;
1718
+ }
1719
+ get globals() {
1720
+ return this.inner.globals || this.outputOptions.globals;
1721
+ }
1722
+ get paths() {
1723
+ return this.outputOptions.paths;
1724
+ }
1725
+ get hashCharacters() {
1726
+ return this.inner.hashCharacters;
1727
+ }
1728
+ get sourcemapDebugIds() {
1729
+ return this.inner.sourcemapDebugIds;
1730
+ }
1731
+ get sourcemapExcludeSources() {
1732
+ return this.inner.sourcemapExcludeSources;
1733
+ }
1734
+ get sourcemapIgnoreList() {
1735
+ return this.outputOptions.sourcemapIgnoreList;
1736
+ }
1737
+ get sourcemapPathTransform() {
1738
+ return this.outputOptions.sourcemapPathTransform;
1739
+ }
1740
+ get minify() {
1741
+ let ret = this.inner.minify;
1742
+ if (typeof ret === "object" && ret !== null) {
1743
+ delete ret["codegen"];
1744
+ delete ret["module"];
1745
+ delete ret["sourcemap"];
1746
+ }
1747
+ return ret;
1748
+ }
1749
+ get legalComments() {
1750
+ return this.inner.legalComments;
1751
+ }
1752
+ get comments() {
1753
+ const c = this.inner.comments;
1754
+ return {
1755
+ legal: c.legal ?? true,
1756
+ annotation: c.annotation ?? true,
1757
+ jsdoc: c.jsdoc ?? true
1758
+ };
1759
+ }
1760
+ get polyfillRequire() {
1761
+ return this.inner.polyfillRequire;
1762
+ }
1763
+ get plugins() {
1764
+ return this.normalizedOutputPlugins;
1765
+ }
1766
+ get preserveModules() {
1767
+ return this.inner.preserveModules;
1768
+ }
1769
+ get preserveModulesRoot() {
1770
+ return this.inner.preserveModulesRoot;
1771
+ }
1772
+ get virtualDirname() {
1773
+ return this.inner.virtualDirname;
1774
+ }
1775
+ get topLevelVar() {
1776
+ return this.inner.topLevelVar ?? false;
1777
+ }
1778
+ get minifyInternalExports() {
1779
+ return this.inner.minifyInternalExports ?? false;
1780
+ }
1781
+ };
1782
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
1783
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
1784
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
1785
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
1786
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
1787
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
1788
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
1789
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
1790
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
1791
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
1792
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
1793
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "codeSplitting", null);
1794
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
1795
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dynamicImportInCjs", null);
1796
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
1797
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
1798
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
1799
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postBanner", null);
1800
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postFooter", null);
1801
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
1802
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
1803
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
1804
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
1805
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
1806
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
1807
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
1808
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
1809
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapExcludeSources", null);
1810
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
1811
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
1812
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
1813
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
1814
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "comments", null);
1815
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
1816
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
1817
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
1818
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
1819
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
1820
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
1821
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
1822
+ function normalizeAddon(value) {
1823
+ if (typeof value === "function") return value;
1824
+ return () => value || "";
1825
+ }
1826
+ //#endregion
1827
+ //#region src/plugin/plugin-context-data.ts
1828
+ var PluginContextData = class {
1829
+ moduleOptionMap = /* @__PURE__ */ new Map();
1830
+ resolveOptionsMap = /* @__PURE__ */ new Map();
1831
+ loadModulePromiseMap = /* @__PURE__ */ new Map();
1832
+ renderedChunkMeta = null;
1833
+ normalizedInputOptions = null;
1834
+ normalizedOutputOptions = null;
1835
+ constructor(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins) {
1836
+ this.onLog = onLog;
1837
+ this.outputOptions = outputOptions;
1838
+ this.normalizedInputPlugins = normalizedInputPlugins;
1839
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
1840
+ }
1841
+ updateModuleOption(id, option) {
1842
+ const existing = this.moduleOptionMap.get(id);
1843
+ if (existing) {
1844
+ if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
1845
+ if (option.meta != null) Object.assign(existing.meta, option.meta);
1846
+ if (option.invalidate != null) existing.invalidate = option.invalidate;
1847
+ } else {
1848
+ this.moduleOptionMap.set(id, option);
1849
+ return option;
1850
+ }
1851
+ return existing;
1852
+ }
1853
+ getModuleOption(id) {
1854
+ const option = this.moduleOptionMap.get(id);
1855
+ if (!option) {
1856
+ const raw = {
1857
+ moduleSideEffects: null,
1858
+ meta: {}
1859
+ };
1860
+ this.moduleOptionMap.set(id, raw);
1861
+ return raw;
1862
+ }
1863
+ return option;
1864
+ }
1865
+ getModuleInfo(id, context) {
1866
+ const bindingInfo = context.getModuleInfo(id);
1867
+ if (bindingInfo) {
1868
+ const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
1869
+ return this.proxyModuleInfo(id, info);
1870
+ }
1871
+ return null;
1872
+ }
1873
+ proxyModuleInfo(id, info) {
1874
+ let moduleSideEffects = info.moduleSideEffects;
1875
+ Object.defineProperty(info, "moduleSideEffects", {
1876
+ get() {
1877
+ return moduleSideEffects;
1878
+ },
1879
+ set: (v) => {
1880
+ this.updateModuleOption(id, {
1881
+ moduleSideEffects: v,
1882
+ meta: info.meta,
1883
+ invalidate: true
1884
+ });
1885
+ moduleSideEffects = v;
1886
+ }
1887
+ });
1888
+ return info;
1889
+ }
1890
+ getModuleIds(context) {
1891
+ return context.getModuleIds().values();
1892
+ }
1893
+ saveResolveOptions(options) {
1894
+ const index = this.resolveOptionsMap.size;
1895
+ this.resolveOptionsMap.set(index, options);
1896
+ return index;
1897
+ }
1898
+ getSavedResolveOptions(receipt) {
1899
+ return this.resolveOptionsMap.get(receipt);
1900
+ }
1901
+ removeSavedResolveOptions(receipt) {
1902
+ this.resolveOptionsMap.delete(receipt);
1903
+ }
1904
+ setRenderChunkMeta(meta) {
1905
+ this.renderedChunkMeta = meta;
1906
+ }
1907
+ getRenderChunkMeta() {
1908
+ return this.renderedChunkMeta;
1909
+ }
1910
+ getInputOptions(opts) {
1911
+ this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog, this.normalizedInputPlugins);
1912
+ return this.normalizedInputOptions;
1913
+ }
1914
+ getOutputOptions(opts) {
1915
+ this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
1916
+ return this.normalizedOutputOptions;
1917
+ }
1918
+ clear() {
1919
+ this.renderedChunkMeta = null;
1920
+ this.loadModulePromiseMap.clear();
1921
+ }
1922
+ };
1923
+ //#endregion
1924
+ //#region src/utils/normalize-transform-options.ts
1925
+ /**
1926
+ * Normalizes transform options by extracting `define`, `inject`, and `dropLabels` separately from OXC transform options.
1927
+ *
1928
+ * Prioritizes values from `transform.define`, `transform.inject`, and `transform.dropLabels` over deprecated top-level options.
1929
+ */
1930
+ function normalizeTransformOptions(inputOptions) {
1931
+ const transform = inputOptions.transform;
1932
+ const define = transform?.define ? Object.entries(transform.define) : void 0;
1933
+ const inject = transform?.inject;
1934
+ const dropLabels = transform?.dropLabels;
1935
+ let oxcTransformOptions;
1936
+ if (transform) {
1937
+ const { define: _define, inject: _inject, dropLabels: _dropLabels, ...rest } = transform;
1938
+ if (Object.keys(rest).length > 0) {
1939
+ if (rest.jsx === false) rest.jsx = "disable";
1940
+ oxcTransformOptions = rest;
1941
+ }
1942
+ }
1943
+ return {
1944
+ define,
1945
+ inject,
1946
+ dropLabels,
1947
+ oxcTransformOptions
1948
+ };
1949
+ }
1950
+ //#endregion
1951
+ //#region src/utils/bindingify-input-options.ts
1952
+ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedInputPlugins, normalizedOutputPlugins, onLog, logLevel, watchMode) {
1953
+ const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins);
1954
+ const plugins = rawPlugins.map((plugin) => {
1955
+ if ("_parallel" in plugin) return;
1956
+ if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
1957
+ case "builtin:vite-manifest": return bindingifyManifestPlugin(plugin, pluginContextData);
1958
+ default: return bindingifyBuiltInPlugin(plugin);
1959
+ }
1960
+ return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
1961
+ });
1962
+ const normalizedTransform = normalizeTransformOptions(inputOptions);
1963
+ return {
1964
+ input: bindingifyInput(inputOptions.input),
1965
+ plugins,
1966
+ cwd: inputOptions.cwd ?? process.cwd(),
1967
+ external: bindingifyExternal(inputOptions.external),
1968
+ resolve: bindingifyResolve(inputOptions.resolve),
1969
+ platform: inputOptions.platform,
1970
+ shimMissingExports: inputOptions.shimMissingExports,
1971
+ logLevel: bindingifyLogLevel(logLevel),
1972
+ onLog: async (level, log) => onLog(level, log),
1973
+ treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
1974
+ moduleTypes: inputOptions.moduleTypes,
1975
+ define: normalizedTransform.define,
1976
+ inject: bindingifyInject(normalizedTransform.inject),
1977
+ experimental: bindingifyExperimental(inputOptions.experimental),
1978
+ profilerNames: outputOptions.generatedCode?.profilerNames,
1979
+ transform: normalizedTransform.oxcTransformOptions,
1980
+ watch: bindingifyWatch(inputOptions.watch),
1981
+ dropLabels: normalizedTransform.dropLabels,
1982
+ keepNames: outputOptions.keepNames,
1983
+ checks: inputOptions.checks,
1984
+ deferSyncScanData: () => {
1985
+ let ret = [];
1986
+ pluginContextData.moduleOptionMap.forEach((value, key) => {
1987
+ if (value.invalidate) ret.push({
1988
+ id: key,
1989
+ sideEffects: value.moduleSideEffects ?? void 0
1990
+ });
1991
+ });
1992
+ return ret;
1993
+ },
1994
+ makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
1995
+ devtools: inputOptions.devtools,
1996
+ invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
1997
+ preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
1998
+ optimization: inputOptions.optimization,
1999
+ context: inputOptions.context,
2000
+ tsconfig: inputOptions.resolve?.tsconfigFilename ?? inputOptions.tsconfig,
2001
+ id: inputOptions.id
2002
+ };
2003
+ }
2004
+ function bindingifyDevMode(devMode) {
2005
+ if (devMode) {
2006
+ if (typeof devMode === "boolean") return devMode ? {} : void 0;
2007
+ return devMode;
2008
+ }
2009
+ }
2010
+ function bindingifyAttachDebugInfo(attachDebugInfo) {
2011
+ switch (attachDebugInfo) {
2012
+ case void 0: return;
2013
+ case "full": return import_binding.BindingAttachDebugInfo.Full;
2014
+ case "simple": return import_binding.BindingAttachDebugInfo.Simple;
2015
+ case "none": return import_binding.BindingAttachDebugInfo.None;
2016
+ }
2017
+ }
2018
+ function bindingifyExternal(external) {
2019
+ if (external) {
2020
+ if (typeof external === "function") return (id, importer, isResolved) => {
2021
+ if (id.startsWith("\0")) return false;
2022
+ return external(id, importer, isResolved) ?? false;
2023
+ };
2024
+ return arraify(external);
2025
+ }
2026
+ }
2027
+ function bindingifyExperimental(experimental) {
2028
+ let chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
2029
+ if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
2030
+ case "exec-order":
2031
+ chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
2032
+ break;
2033
+ case "module-id":
2034
+ chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ModuleId;
2035
+ break;
2036
+ default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
2037
+ }
2038
+ return {
2039
+ viteMode: experimental?.viteMode,
2040
+ resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
2041
+ devMode: bindingifyDevMode(experimental?.devMode),
2042
+ attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
2043
+ chunkModulesOrder,
2044
+ chunkImportMap: experimental?.chunkImportMap,
2045
+ onDemandWrapping: experimental?.onDemandWrapping,
2046
+ incrementalBuild: experimental?.incrementalBuild,
2047
+ nativeMagicString: experimental?.nativeMagicString,
2048
+ chunkOptimization: experimental?.chunkOptimization,
2049
+ lazyBarrel: experimental?.lazyBarrel
2050
+ };
2051
+ }
2052
+ function bindingifyResolve(resolve) {
2053
+ const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
2054
+ if (resolve) {
2055
+ const { alias, extensionAlias, ...rest } = resolve;
2056
+ return {
2057
+ alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
2058
+ find: name,
2059
+ replacements: replacement === false ? [void 0] : arraify(replacement)
2060
+ })) : void 0,
2061
+ extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
2062
+ target: name,
2063
+ replacements: value
2064
+ })) : void 0,
2065
+ yarnPnp,
2066
+ ...rest
2067
+ };
2068
+ } else return { yarnPnp };
2069
+ }
2070
+ function bindingifyInject(inject) {
2071
+ if (inject) return Object.entries(inject).map(([alias, item]) => {
2072
+ if (Array.isArray(item)) {
2073
+ if (item[1] === "*") return {
2074
+ tagNamespace: true,
2075
+ alias,
2076
+ from: item[0]
2077
+ };
2078
+ return {
2079
+ tagNamed: true,
2080
+ alias,
2081
+ from: item[0],
2082
+ imported: item[1]
2083
+ };
2084
+ } else return {
2085
+ tagNamed: true,
2086
+ imported: "default",
2087
+ alias,
2088
+ from: item
2089
+ };
2090
+ });
2091
+ }
2092
+ function bindingifyLogLevel(logLevel) {
2093
+ switch (logLevel) {
2094
+ case "silent": return import_binding.BindingLogLevel.Silent;
2095
+ case "debug": return import_binding.BindingLogLevel.Debug;
2096
+ case "warn": return import_binding.BindingLogLevel.Warn;
2097
+ case "info": return import_binding.BindingLogLevel.Info;
2098
+ default: throw new Error(`Unexpected log level: ${logLevel}`);
2099
+ }
2100
+ }
2101
+ function bindingifyInput(input) {
2102
+ if (input === void 0) return [];
2103
+ if (typeof input === "string") return [{ import: input }];
2104
+ if (Array.isArray(input)) return input.map((src) => ({ import: src }));
2105
+ return Object.entries(input).map(([name, import_path]) => {
2106
+ return {
2107
+ name,
2108
+ import: import_path
2109
+ };
2110
+ });
2111
+ }
2112
+ function bindingifyWatch(watch) {
2113
+ if (watch) {
2114
+ if (watch.notify) console.warn("The \"watch.notify\" option is deprecated. Please use \"watch.watcher\" instead.");
2115
+ const watcher = {
2116
+ ...watch.notify,
2117
+ ...watch.watcher
2118
+ };
2119
+ return {
2120
+ buildDelay: watch.buildDelay,
2121
+ skipWrite: watch.skipWrite,
2122
+ usePolling: watcher.usePolling,
2123
+ pollInterval: watcher.pollInterval,
2124
+ compareContentsForPolling: watcher.compareContentsForPolling,
2125
+ useDebounce: watcher.useDebounce,
2126
+ debounceDelay: watcher.debounceDelay,
2127
+ debounceTickRate: watcher.debounceTickRate,
2128
+ include: normalizedStringOrRegex(watch.include),
2129
+ exclude: normalizedStringOrRegex(watch.exclude),
2130
+ onInvalidate: (...args) => watch.onInvalidate?.(...args)
2131
+ };
2132
+ }
2133
+ }
2134
+ function bindingifyTreeshakeOptions(config) {
2135
+ if (config === false) return;
2136
+ if (config === true || config === void 0) return { moduleSideEffects: true };
2137
+ let normalizedConfig = {
2138
+ moduleSideEffects: true,
2139
+ annotations: config.annotations,
2140
+ manualPureFunctions: config.manualPureFunctions,
2141
+ unknownGlobalSideEffects: config.unknownGlobalSideEffects,
2142
+ invalidImportSideEffects: config.invalidImportSideEffects,
2143
+ commonjs: config.commonjs
2144
+ };
2145
+ switch (config.propertyReadSideEffects) {
2146
+ case "always":
2147
+ normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
2148
+ break;
2149
+ case false:
2150
+ normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
2151
+ break;
2152
+ default:
2153
+ }
2154
+ switch (config.propertyWriteSideEffects) {
2155
+ case "always":
2156
+ normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
2157
+ break;
2158
+ case false:
2159
+ normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
2160
+ break;
2161
+ default:
2162
+ }
2163
+ if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
2164
+ else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
2165
+ external: true,
2166
+ sideEffects: false
2167
+ }, {
2168
+ external: false,
2169
+ sideEffects: true
2170
+ }];
2171
+ else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
2172
+ return normalizedConfig;
2173
+ }
2174
+ function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
2175
+ if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
2176
+ if (typeof makeAbsoluteExternalsRelative === "boolean") return {
2177
+ type: "Bool",
2178
+ field0: makeAbsoluteExternalsRelative
2179
+ };
2180
+ }
2181
+ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
2182
+ if (preserveEntrySignatures == void 0) return;
2183
+ else if (typeof preserveEntrySignatures === "string") return {
2184
+ type: "String",
2185
+ field0: preserveEntrySignatures
2186
+ };
2187
+ else return {
2188
+ type: "Bool",
2189
+ field0: preserveEntrySignatures
2190
+ };
2191
+ }
2192
+ //#endregion
2193
+ export { version as C, description as S, LOG_LEVEL_INFO as _, RolldownMagicString as a, RUNTIME_MODULE_ID as b, __decorate as c, PlainObjectLike as d, MinimalPluginContextImpl as f, LOG_LEVEL_ERROR as g, LOG_LEVEL_DEBUG as h, transformModuleInfo as i, transformAssetSource as l, normalizeLog as m, PluginContextData as n, transformToRollupOutput as o, normalizeHook as p, bindingifyPlugin as r, transformRenderedChunk as s, bindingifyInputOptions as t, lazyProp as u, LOG_LEVEL_WARN as v, VERSION as x, logLevelPriority as y };