rolldown 1.0.0-beta.50 → 1.0.0-beta.51

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 (38) hide show
  1. package/dist/cli-setup.mjs +1 -1
  2. package/dist/cli.mjs +11 -8
  3. package/dist/config.d.mts +3 -3
  4. package/dist/config.mjs +9 -6
  5. package/dist/experimental-index.d.mts +52 -15
  6. package/dist/experimental-index.mjs +24 -14
  7. package/dist/filter-index.d.mts +3 -3
  8. package/dist/filter-index.mjs +1 -1
  9. package/dist/index.d.mts +3 -3
  10. package/dist/index.mjs +40 -5
  11. package/dist/parallel-plugin-worker.mjs +5 -5
  12. package/dist/parallel-plugin.d.mts +3 -3
  13. package/dist/parse-ast-index.d.mts +1 -1
  14. package/dist/parse-ast-index.mjs +2 -2
  15. package/dist/plugins-index.d.mts +3 -3
  16. package/dist/plugins-index.mjs +4 -3
  17. package/dist/shared/{binding-DkT6owYZ.mjs → binding-JavE2bkj.mjs} +31 -28
  18. package/dist/shared/{binding-BTw1cXhU.d.mts → binding-lSvYApx7.d.mts} +161 -87
  19. package/dist/shared/bindingify-input-options-C8RwNEVu.mjs +1571 -0
  20. package/dist/shared/constructors-D1fHJKvO.mjs +65 -0
  21. package/dist/shared/constructors-DgFF472b.d.mts +31 -0
  22. package/dist/shared/{define-config-CrMIxA40.d.mts → define-config-CXCkQG1z.d.mts} +10 -49
  23. package/dist/shared/define-config-DfeZGBEt.mjs +7 -0
  24. package/dist/shared/{load-config-8K0EpQy3.mjs → load-config-WNwAzWN-.mjs} +1 -1
  25. package/dist/shared/normalize-string-or-regex-Bu88lzEx.mjs +630 -0
  26. package/dist/shared/{parse-ast-index-w6oTGOhH.mjs → parse-ast-index-DPVqqR9w.mjs} +3 -3
  27. package/dist/shared/rolldown-Do5qEfGl.mjs +10 -0
  28. package/dist/shared/rolldown-build-MAIadGaX.mjs +2123 -0
  29. package/dist/shared/utils-BJWI2OzT.d.mts +62 -0
  30. package/dist/shared/watch-CUl9f7JR.mjs +339 -0
  31. package/package.json +20 -20
  32. package/dist/shared/constructors-BGT3rFMD.d.mts +0 -32
  33. package/dist/shared/constructors-Xd4Pek8a.mjs +0 -68
  34. package/dist/shared/normalize-string-or-regex-vZ5EI4ro.mjs +0 -47
  35. package/dist/shared/src-CYkh2Ybc.mjs +0 -4606
  36. package/dist/shared/utils-BxvnUO-9.d.mts +0 -18
  37. /package/dist/shared/{misc-DpQNcSw4.mjs → misc-CxyvWjTr.mjs} +0 -0
  38. /package/dist/shared/{prompt-CFbT7ROl.mjs → prompt-pmGBC3ws.mjs} +0 -0
@@ -0,0 +1,1571 @@
1
+ import { t as require_binding } from "./binding-JavE2bkj.mjs";
2
+ import { c as logPluginError, n as error, r as logCycleLoading, t as augmentCodeLocation } from "./logs-CSQ_UMWp.mjs";
3
+ import { a as unreachable, i as unimplemented, o as unsupported, t as arraify } from "./misc-CxyvWjTr.mjs";
4
+ import { b as normalizeLog, d as __decorate, f as bindingAssetSource, g as MinimalPluginContextImpl, h as PlainObjectLike, i as bindingifyViteHtmlPlugin, l as bindingifySourcemap, m as lazyProp, n as BuiltinPlugin, o as collectChangedBundle, r as bindingifyBuiltInPlugin, s as transformToOutputBundle, t as normalizedStringOrRegex, u as transformRenderedChunk, w as LOG_LEVEL_WARN } from "./normalize-string-or-regex-Bu88lzEx.mjs";
5
+ import { t as parseAst } from "./parse-ast-index-DPVqqR9w.mjs";
6
+ import path from "node:path";
7
+ import * as filter from "@rolldown/pluginutils";
8
+ import fsp from "node:fs/promises";
9
+
10
+ //#region src/utils/normalize-hook.ts
11
+ function normalizeHook(hook) {
12
+ if (typeof hook === "function" || typeof hook === "string") return {
13
+ handler: hook,
14
+ options: {},
15
+ meta: {}
16
+ };
17
+ if (typeof hook === "object" && hook !== null) {
18
+ const { handler, order, ...options } = hook;
19
+ return {
20
+ handler,
21
+ options,
22
+ meta: { order }
23
+ };
24
+ }
25
+ unreachable("Invalid hook type");
26
+ }
27
+
28
+ //#endregion
29
+ //#region src/utils/error.ts
30
+ function unwrapBindingResult(container) {
31
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
32
+ return container;
33
+ }
34
+ function normalizeBindingResult(container) {
35
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
36
+ return container;
37
+ }
38
+ function normalizeBindingError(e$1) {
39
+ return e$1.type === "JsError" ? e$1.field0 : Object.assign(/* @__PURE__ */ new Error(), {
40
+ kind: e$1.field0.kind,
41
+ message: e$1.field0.message,
42
+ stack: void 0
43
+ });
44
+ }
45
+ function aggregateBindingErrorsIntoJsError(rawErrors) {
46
+ const errors = rawErrors.map(normalizeBindingError);
47
+ let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
48
+ for (let i = 0; i < errors.length; i++) {
49
+ summary += "\n";
50
+ if (i >= 5) {
51
+ summary += "...";
52
+ break;
53
+ }
54
+ summary += getErrorMessage(errors[i]);
55
+ }
56
+ const wrapper = new Error(summary);
57
+ Object.defineProperty(wrapper, "errors", {
58
+ configurable: true,
59
+ enumerable: true,
60
+ get: () => errors,
61
+ set: (value) => Object.defineProperty(wrapper, "errors", {
62
+ configurable: true,
63
+ enumerable: true,
64
+ value
65
+ })
66
+ });
67
+ return wrapper;
68
+ }
69
+ function getErrorMessage(e$1) {
70
+ if (Object.hasOwn(e$1, "kind")) return e$1.message;
71
+ let s = "";
72
+ if (e$1.plugin) s += `[plugin ${e$1.plugin}]`;
73
+ const id = e$1.id ?? e$1.loc?.file;
74
+ if (id) {
75
+ s += " " + id;
76
+ if (e$1.loc) s += `:${e$1.loc.line}:${e$1.loc.column}`;
77
+ }
78
+ if (s) s += "\n";
79
+ const message = `${e$1.name ?? "Error"}: ${e$1.message}`;
80
+ s += message;
81
+ if (e$1.frame) s = joinNewLine(s, e$1.frame);
82
+ if (e$1.stack) s = joinNewLine(s, e$1.stack.replace(message, ""));
83
+ if (e$1.cause) {
84
+ s = joinNewLine(s, "Caused by:");
85
+ s = joinNewLine(s, getErrorMessage(e$1.cause).split("\n").map((line) => " " + line).join("\n"));
86
+ }
87
+ return s;
88
+ }
89
+ function joinNewLine(s1, s2) {
90
+ return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
91
+ }
92
+
93
+ //#endregion
94
+ //#region src/utils/transform-module-info.ts
95
+ function transformModuleInfo(info, option) {
96
+ return {
97
+ get ast() {
98
+ return unsupported("ModuleInfo#ast");
99
+ },
100
+ get code() {
101
+ return info.code;
102
+ },
103
+ id: info.id,
104
+ importers: info.importers,
105
+ dynamicImporters: info.dynamicImporters,
106
+ importedIds: info.importedIds,
107
+ dynamicallyImportedIds: info.dynamicallyImportedIds,
108
+ exports: info.exports,
109
+ isEntry: info.isEntry,
110
+ ...option
111
+ };
112
+ }
113
+
114
+ //#endregion
115
+ //#region src/utils/transform-sourcemap.ts
116
+ function isEmptySourcemapFiled(array) {
117
+ if (!array) return true;
118
+ if (array.length === 0 || !array[0]) return true;
119
+ return false;
120
+ }
121
+ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
122
+ if (!rawMap) return;
123
+ let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
124
+ if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
125
+ if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
126
+ return map;
127
+ }
128
+
129
+ //#endregion
130
+ //#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/lazyDataLastImpl-BDhrIOwR.js
131
+ function e(e$1, t$2, n$1) {
132
+ let r = (n$2) => e$1(n$2, ...t$2);
133
+ return n$1 === void 0 ? r : Object.assign(r, {
134
+ lazy: n$1,
135
+ lazyArgs: t$2
136
+ });
137
+ }
138
+
139
+ //#endregion
140
+ //#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/purry-DH9cw9sy.js
141
+ function t(t$2, n$1, r) {
142
+ let i = t$2.length - n$1.length;
143
+ if (i === 0) return t$2(...n$1);
144
+ if (i === 1) return e(t$2, n$1, r);
145
+ throw Error(`Wrong number of arguments`);
146
+ }
147
+
148
+ //#endregion
149
+ //#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/partition-DAu403JQ.js
150
+ function t$1(...t$2) {
151
+ return t(n, t$2);
152
+ }
153
+ const n = (e$1, t$2) => {
154
+ let n$1 = [[], []];
155
+ for (let [r, i] of e$1.entries()) t$2(i, r, e$1) ? n$1[0].push(i) : n$1[1].push(i);
156
+ return n$1;
157
+ };
158
+
159
+ //#endregion
160
+ //#region src/plugin/bindingify-hook-filter.ts
161
+ function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
162
+ if (typeof matcher === "string" || matcher instanceof RegExp) return [filter.include(generateAtomMatcher(stringKind, matcher))];
163
+ if (Array.isArray(matcher)) return matcher.map((m) => filter.include(generateAtomMatcher(stringKind, m)));
164
+ let ret = [];
165
+ if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => filter.exclude(generateAtomMatcher(stringKind, m))));
166
+ if (matcher.include) ret.push(...arraify(matcher.include).map((m) => filter.include(generateAtomMatcher(stringKind, m))));
167
+ return ret;
168
+ }
169
+ function generateAtomMatcher(kind, matcher) {
170
+ return kind === "code" ? filter.code(matcher) : filter.id(matcher);
171
+ }
172
+ function transformFilterMatcherToFilterExprs(filterOption) {
173
+ if (!filterOption) return;
174
+ if (Array.isArray(filterOption)) return filterOption;
175
+ const { id, code, moduleType } = filterOption;
176
+ let ret = [];
177
+ let idIncludes = [];
178
+ let idExcludes = [];
179
+ let codeIncludes = [];
180
+ let codeExcludes = [];
181
+ if (id) [idIncludes, idExcludes] = t$1(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
182
+ if (code) [codeIncludes, codeExcludes] = t$1(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
183
+ ret.push(...idExcludes);
184
+ ret.push(...codeExcludes);
185
+ let andExprList = [];
186
+ if (moduleType) {
187
+ let moduleTypes = Array.isArray(moduleType) ? moduleType : moduleType.include ?? [];
188
+ andExprList.push(filter.or(...moduleTypes.map((m) => filter.moduleType(m))));
189
+ }
190
+ if (idIncludes.length) andExprList.push(filter.or(...idIncludes.map((item) => item.expr)));
191
+ if (codeIncludes.length) andExprList.push(filter.or(...codeIncludes.map((item) => item.expr)));
192
+ if (andExprList.length) ret.push(filter.include(filter.and(...andExprList)));
193
+ return ret;
194
+ }
195
+ function bindingifyGeneralHookFilter(stringKind, pattern) {
196
+ let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
197
+ let ret = [];
198
+ if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
199
+ return ret.length > 0 ? { value: ret } : void 0;
200
+ }
201
+ function bindingifyFilterExpr(expr) {
202
+ let list = [];
203
+ bindingifyFilterExprImpl(expr, list);
204
+ return list;
205
+ }
206
+ function bindingifyFilterExprImpl(expr, list) {
207
+ switch (expr.kind) {
208
+ case "and": {
209
+ let args = expr.args;
210
+ for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
211
+ list.push({
212
+ kind: "And",
213
+ payload: args.length
214
+ });
215
+ break;
216
+ }
217
+ case "or": {
218
+ let args = expr.args;
219
+ for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
220
+ list.push({
221
+ kind: "Or",
222
+ payload: args.length
223
+ });
224
+ break;
225
+ }
226
+ case "not":
227
+ bindingifyFilterExprImpl(expr.expr, list);
228
+ list.push({ kind: "Not" });
229
+ break;
230
+ case "id":
231
+ list.push({
232
+ kind: "Id",
233
+ payload: expr.pattern
234
+ });
235
+ if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
236
+ break;
237
+ case "moduleType":
238
+ list.push({
239
+ kind: "ModuleType",
240
+ payload: expr.pattern
241
+ });
242
+ break;
243
+ case "code":
244
+ list.push({
245
+ kind: "Code",
246
+ payload: expr.pattern
247
+ });
248
+ break;
249
+ case "include":
250
+ bindingifyFilterExprImpl(expr.expr, list);
251
+ list.push({ kind: "Include" });
252
+ break;
253
+ case "exclude":
254
+ bindingifyFilterExprImpl(expr.expr, list);
255
+ list.push({ kind: "Exclude" });
256
+ break;
257
+ case "query":
258
+ list.push({
259
+ kind: "QueryKey",
260
+ payload: expr.key
261
+ });
262
+ list.push({
263
+ kind: "QueryValue",
264
+ payload: expr.pattern
265
+ });
266
+ break;
267
+ default: throw new Error(`Unknown filter expression: ${expr}`);
268
+ }
269
+ }
270
+ function bindingifyResolveIdFilter(filterOption) {
271
+ if (!filterOption) return;
272
+ if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
273
+ return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
274
+ }
275
+ function bindingifyLoadFilter(filterOption) {
276
+ if (!filterOption) return;
277
+ if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
278
+ return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
279
+ }
280
+ function bindingifyTransformFilter(filterOption) {
281
+ if (!filterOption) return;
282
+ let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
283
+ let ret = [];
284
+ if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
285
+ return { value: ret.length > 0 ? ret : void 0 };
286
+ }
287
+ function bindingifyRenderChunkFilter(filterOption) {
288
+ if (!filterOption) return;
289
+ if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
290
+ return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
291
+ }
292
+
293
+ //#endregion
294
+ //#region src/plugin/bindingify-plugin-hook-meta.ts
295
+ var import_binding$2 = require_binding();
296
+ function bindingifyPluginHookMeta(options) {
297
+ return { order: bindingPluginOrder(options.order) };
298
+ }
299
+ function bindingPluginOrder(order) {
300
+ switch (order) {
301
+ case "post": return import_binding$2.BindingPluginOrder.Post;
302
+ case "pre": return import_binding$2.BindingPluginOrder.Pre;
303
+ case null:
304
+ case void 0: return;
305
+ default: throw new Error(`Unknown plugin order: ${order}`);
306
+ }
307
+ }
308
+
309
+ //#endregion
310
+ //#region src/plugin/fs.ts
311
+ const fsModule = {
312
+ appendFile: fsp.appendFile,
313
+ copyFile: fsp.copyFile,
314
+ mkdir: fsp.mkdir,
315
+ mkdtemp: fsp.mkdtemp,
316
+ readdir: fsp.readdir,
317
+ readFile: fsp.readFile,
318
+ realpath: fsp.realpath,
319
+ rename: fsp.rename,
320
+ rmdir: fsp.rmdir,
321
+ stat: fsp.stat,
322
+ lstat: fsp.lstat,
323
+ unlink: fsp.unlink,
324
+ writeFile: fsp.writeFile
325
+ };
326
+
327
+ //#endregion
328
+ //#region src/plugin/plugin-context.ts
329
+ var PluginContextImpl = class extends MinimalPluginContextImpl {
330
+ fs = fsModule;
331
+ getModuleInfo;
332
+ constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
333
+ super(onLog, logLevel, plugin.name, watchMode);
334
+ this.outputOptions = outputOptions;
335
+ this.context = context;
336
+ this.data = data;
337
+ this.onLog = onLog;
338
+ this.currentLoadingModule = currentLoadingModule;
339
+ this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
340
+ }
341
+ async load(options) {
342
+ const id = options.id;
343
+ if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
344
+ const moduleInfo = this.data.getModuleInfo(id, this.context);
345
+ if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
346
+ const rawOptions = {
347
+ meta: options.meta || {},
348
+ moduleSideEffects: options.moduleSideEffects || null,
349
+ invalidate: false
350
+ };
351
+ this.data.updateModuleOption(id, rawOptions);
352
+ let loadPromise = this.data.loadModulePromiseMap.get(id);
353
+ if (!loadPromise) {
354
+ loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
355
+ this.data.loadModulePromiseMap.delete(id);
356
+ });
357
+ this.data.loadModulePromiseMap.set(id, loadPromise);
358
+ }
359
+ await loadPromise;
360
+ return this.data.getModuleInfo(id, this.context);
361
+ }
362
+ async resolve(source, importer, options) {
363
+ let receipt = void 0;
364
+ if (options != null) receipt = this.data.saveResolveOptions(options);
365
+ const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
366
+ if (key.startsWith("vite:")) (acc ??= {})[key] = value;
367
+ return acc;
368
+ }, void 0);
369
+ const res = await this.context.resolve(source, importer, {
370
+ custom: receipt,
371
+ isEntry: options?.isEntry,
372
+ skipSelf: options?.skipSelf,
373
+ vitePluginCustom
374
+ });
375
+ if (receipt != null) this.data.removeSavedResolveOptions(receipt);
376
+ if (res == null) return null;
377
+ const info = this.data.getModuleOption(res.id) || {};
378
+ return {
379
+ ...res,
380
+ external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
381
+ ...info,
382
+ moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
383
+ packageJsonPath: res.packageJsonPath
384
+ };
385
+ }
386
+ emitFile = (file) => {
387
+ if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
388
+ if (file.type === "chunk") return this.context.emitChunk({
389
+ preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
390
+ ...file
391
+ });
392
+ const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
393
+ const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
394
+ return this.context.emitFile({
395
+ ...file,
396
+ originalFileName: file.originalFileName || void 0,
397
+ source: bindingAssetSource(file.source)
398
+ }, filename, fnSanitizedFileName);
399
+ };
400
+ getAssetFileNames(file) {
401
+ if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
402
+ type: "asset",
403
+ name: file.name,
404
+ names: file.name ? [file.name] : [],
405
+ originalFileName: file.originalFileName,
406
+ originalFileNames: file.originalFileName ? [file.originalFileName] : [],
407
+ source: file.source
408
+ });
409
+ }
410
+ getFileName(referenceId) {
411
+ return this.context.getFileName(referenceId);
412
+ }
413
+ getModuleIds() {
414
+ return this.data.getModuleIds(this.context);
415
+ }
416
+ addWatchFile(id) {
417
+ this.context.addWatchFile(id);
418
+ }
419
+ parse(input, options) {
420
+ return parseAst(input, options);
421
+ }
422
+ };
423
+
424
+ //#endregion
425
+ //#region src/plugin/transform-plugin-context.ts
426
+ var TransformPluginContextImpl = class extends PluginContextImpl {
427
+ constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
428
+ super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
429
+ this.inner = inner;
430
+ this.moduleId = moduleId;
431
+ this.moduleSource = moduleSource;
432
+ const getLogHandler = (handler) => (log, pos) => {
433
+ log = normalizeLog(log);
434
+ if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
435
+ log.id = moduleId;
436
+ log.hook = "transform";
437
+ handler(log);
438
+ };
439
+ this.debug = getLogHandler(this.debug);
440
+ this.warn = getLogHandler(this.warn);
441
+ this.info = getLogHandler(this.info);
442
+ }
443
+ error(e$1, pos) {
444
+ if (typeof e$1 === "string") e$1 = { message: e$1 };
445
+ if (pos) augmentCodeLocation(e$1, pos, this.moduleSource, this.moduleId);
446
+ e$1.id = this.moduleId;
447
+ e$1.hook = "transform";
448
+ return error(logPluginError(normalizeLog(e$1), this.pluginName));
449
+ }
450
+ getCombinedSourcemap() {
451
+ return JSON.parse(this.inner.getCombinedSourcemap());
452
+ }
453
+ addWatchFile(id) {
454
+ this.inner.addWatchFile(id);
455
+ }
456
+ sendMagicString(s) {
457
+ this.inner.sendMagicString(s);
458
+ }
459
+ };
460
+
461
+ //#endregion
462
+ //#region src/plugin/bindingify-build-hooks.ts
463
+ var import_binding$1 = require_binding();
464
+ function bindingifyBuildStart(args) {
465
+ const hook = args.plugin.buildStart;
466
+ if (!hook) return {};
467
+ const { handler, meta } = normalizeHook(hook);
468
+ return {
469
+ plugin: async (ctx, opts) => {
470
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getInputOptions(opts));
471
+ },
472
+ meta: bindingifyPluginHookMeta(meta)
473
+ };
474
+ }
475
+ function bindingifyBuildEnd(args) {
476
+ const hook = args.plugin.buildEnd;
477
+ if (!hook) return {};
478
+ const { handler, meta } = normalizeHook(hook);
479
+ return {
480
+ plugin: async (ctx, err) => {
481
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
482
+ },
483
+ meta: bindingifyPluginHookMeta(meta)
484
+ };
485
+ }
486
+ function bindingifyResolveId(args) {
487
+ const hook = args.plugin.resolveId;
488
+ if (!hook) return {};
489
+ const { handler, meta, options } = normalizeHook(hook);
490
+ return {
491
+ plugin: async (ctx, specifier, importer, extraOptions) => {
492
+ const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
493
+ const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), specifier, importer ?? void 0, {
494
+ ...extraOptions,
495
+ custom: contextResolveOptions?.custom
496
+ });
497
+ if (ret == null) return;
498
+ if (ret === false) return {
499
+ id: specifier,
500
+ external: true,
501
+ normalizeExternalId: true
502
+ };
503
+ if (typeof ret === "string") return {
504
+ id: ret,
505
+ normalizeExternalId: false
506
+ };
507
+ let exist = args.pluginContextData.updateModuleOption(ret.id, {
508
+ meta: ret.meta || {},
509
+ moduleSideEffects: ret.moduleSideEffects ?? null,
510
+ invalidate: false
511
+ });
512
+ return {
513
+ id: ret.id,
514
+ external: ret.external,
515
+ normalizeExternalId: false,
516
+ moduleSideEffects: exist.moduleSideEffects ?? void 0,
517
+ packageJsonPath: ret.packageJsonPath
518
+ };
519
+ },
520
+ meta: bindingifyPluginHookMeta(meta),
521
+ filter: bindingifyResolveIdFilter(options.filter)
522
+ };
523
+ }
524
+ function bindingifyResolveDynamicImport(args) {
525
+ const hook = args.plugin.resolveDynamicImport;
526
+ if (!hook) return {};
527
+ const { handler, meta } = normalizeHook(hook);
528
+ return {
529
+ plugin: async (ctx, specifier, importer) => {
530
+ const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), specifier, importer ?? void 0);
531
+ if (ret == null) return;
532
+ if (ret === false) return {
533
+ id: specifier,
534
+ external: true
535
+ };
536
+ if (typeof ret === "string") return { id: ret };
537
+ const result = {
538
+ id: ret.id,
539
+ external: ret.external,
540
+ packageJsonPath: ret.packageJsonPath
541
+ };
542
+ if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
543
+ args.pluginContextData.updateModuleOption(ret.id, {
544
+ meta: ret.meta || {},
545
+ moduleSideEffects: ret.moduleSideEffects || null,
546
+ invalidate: false
547
+ });
548
+ return result;
549
+ },
550
+ meta: bindingifyPluginHookMeta(meta)
551
+ };
552
+ }
553
+ function bindingifyTransform(args) {
554
+ const hook = args.plugin.transform;
555
+ if (!hook) return {};
556
+ const { handler, meta, options } = normalizeHook(hook);
557
+ return {
558
+ plugin: async (ctx, code, id, meta$1) => {
559
+ let magicStringInstance, astInstance;
560
+ Object.defineProperties(meta$1, {
561
+ magicString: { get() {
562
+ if (magicStringInstance) return magicStringInstance;
563
+ magicStringInstance = new import_binding$1.BindingMagicString(code);
564
+ return magicStringInstance;
565
+ } },
566
+ ast: { get() {
567
+ if (astInstance) return astInstance;
568
+ let lang = "js";
569
+ switch (meta$1.moduleType) {
570
+ case "js":
571
+ case "jsx":
572
+ case "ts":
573
+ case "tsx":
574
+ lang = meta$1.moduleType;
575
+ break;
576
+ default: break;
577
+ }
578
+ astInstance = parseAst(code, {
579
+ astType: meta$1.moduleType.includes("ts") ? "ts" : "js",
580
+ lang
581
+ });
582
+ return astInstance;
583
+ } }
584
+ });
585
+ const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
586
+ const ret = await handler.call(transformCtx, code, id, meta$1);
587
+ if (ret == null) return;
588
+ if (typeof ret === "string") return { code: ret };
589
+ let moduleOption = args.pluginContextData.updateModuleOption(id, {
590
+ meta: ret.meta ?? {},
591
+ moduleSideEffects: ret.moduleSideEffects ?? null,
592
+ invalidate: false
593
+ });
594
+ let normalizedCode = void 0;
595
+ let map = ret.map;
596
+ if (typeof ret.code === "string") normalizedCode = ret.code;
597
+ else if (ret.code instanceof import_binding$1.BindingMagicString) {
598
+ let magicString = ret.code;
599
+ normalizedCode = magicString.toString();
600
+ let fallbackSourcemap = ctx.sendMagicString(magicString);
601
+ if (fallbackSourcemap != void 0) map = fallbackSourcemap;
602
+ }
603
+ return {
604
+ code: normalizedCode,
605
+ map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)),
606
+ moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
607
+ moduleType: ret.moduleType
608
+ };
609
+ },
610
+ meta: bindingifyPluginHookMeta(meta),
611
+ filter: bindingifyTransformFilter(options.filter)
612
+ };
613
+ }
614
+ function bindingifyLoad(args) {
615
+ const hook = args.plugin.load;
616
+ if (!hook) return {};
617
+ const { handler, meta, options } = normalizeHook(hook);
618
+ return {
619
+ plugin: async (ctx, id) => {
620
+ const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode, id), id);
621
+ if (ret == null) return;
622
+ if (typeof ret === "string") return { code: ret };
623
+ let moduleOption = args.pluginContextData.updateModuleOption(id, {
624
+ meta: ret.meta || {},
625
+ moduleSideEffects: ret.moduleSideEffects ?? null,
626
+ invalidate: false
627
+ });
628
+ let map = preProcessSourceMap(ret, id);
629
+ return {
630
+ code: ret.code,
631
+ map: bindingifySourcemap(map),
632
+ moduleType: ret.moduleType,
633
+ moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
634
+ };
635
+ },
636
+ meta: bindingifyPluginHookMeta(meta),
637
+ filter: bindingifyLoadFilter(options.filter)
638
+ };
639
+ }
640
+ function preProcessSourceMap(ret, id) {
641
+ if (!ret.map) return;
642
+ let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
643
+ if (!isEmptySourcemapFiled(map.sources)) {
644
+ const directory = path.dirname(id) || ".";
645
+ const sourceRoot = map.sourceRoot || ".";
646
+ map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
647
+ }
648
+ return map;
649
+ }
650
+ function bindingifyModuleParsed(args) {
651
+ const hook = args.plugin.moduleParsed;
652
+ if (!hook) return {};
653
+ const { handler, meta } = normalizeHook(hook);
654
+ return {
655
+ plugin: async (ctx, moduleInfo) => {
656
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
657
+ },
658
+ meta: bindingifyPluginHookMeta(meta)
659
+ };
660
+ }
661
+
662
+ //#endregion
663
+ //#region src/plugin/bindingify-output-hooks.ts
664
+ function bindingifyRenderStart(args) {
665
+ const hook = args.plugin.renderStart;
666
+ if (!hook) return {};
667
+ const { handler, meta } = normalizeHook(hook);
668
+ return {
669
+ plugin: async (ctx, opts) => {
670
+ 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));
671
+ },
672
+ meta: bindingifyPluginHookMeta(meta)
673
+ };
674
+ }
675
+ function bindingifyRenderChunk(args) {
676
+ const hook = args.plugin.renderChunk;
677
+ if (!hook) return {};
678
+ const { handler, meta, options } = normalizeHook(hook);
679
+ return {
680
+ plugin: async (ctx, code, chunk, opts, meta$1) => {
681
+ if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
682
+ 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), args.pluginContextData.getRenderChunkMeta());
683
+ if (ret == null) return;
684
+ if (typeof ret === "string") return { code: ret };
685
+ if (!ret.map) return { code: ret.code };
686
+ return {
687
+ code: ret.code,
688
+ map: bindingifySourcemap(ret.map)
689
+ };
690
+ },
691
+ meta: bindingifyPluginHookMeta(meta),
692
+ filter: bindingifyRenderChunkFilter(options.filter)
693
+ };
694
+ }
695
+ function bindingifyAugmentChunkHash(args) {
696
+ const hook = args.plugin.augmentChunkHash;
697
+ if (!hook) return {};
698
+ const { handler, meta } = normalizeHook(hook);
699
+ return {
700
+ plugin: async (ctx, chunk) => {
701
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
702
+ },
703
+ meta: bindingifyPluginHookMeta(meta)
704
+ };
705
+ }
706
+ function bindingifyRenderError(args) {
707
+ const hook = args.plugin.renderError;
708
+ if (!hook) return {};
709
+ const { handler, meta } = normalizeHook(hook);
710
+ return {
711
+ plugin: async (ctx, err) => {
712
+ handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
713
+ },
714
+ meta: bindingifyPluginHookMeta(meta)
715
+ };
716
+ }
717
+ function bindingifyGenerateBundle(args) {
718
+ const hook = args.plugin.generateBundle;
719
+ if (!hook) return {};
720
+ const { handler, meta } = normalizeHook(hook);
721
+ return {
722
+ plugin: async (ctx, bundle, isWrite, opts) => {
723
+ const changed = {
724
+ updated: /* @__PURE__ */ new Set(),
725
+ deleted: /* @__PURE__ */ new Set()
726
+ };
727
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
728
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
729
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
730
+ return collectChangedBundle(changed, output);
731
+ },
732
+ meta: bindingifyPluginHookMeta(meta)
733
+ };
734
+ }
735
+ function bindingifyWriteBundle(args) {
736
+ const hook = args.plugin.writeBundle;
737
+ if (!hook) return {};
738
+ const { handler, meta } = normalizeHook(hook);
739
+ return {
740
+ plugin: async (ctx, bundle, opts) => {
741
+ const changed = {
742
+ updated: /* @__PURE__ */ new Set(),
743
+ deleted: /* @__PURE__ */ new Set()
744
+ };
745
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
746
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
747
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
748
+ return collectChangedBundle(changed, output);
749
+ },
750
+ meta: bindingifyPluginHookMeta(meta)
751
+ };
752
+ }
753
+ function bindingifyCloseBundle(args) {
754
+ const hook = args.plugin.closeBundle;
755
+ if (!hook) return {};
756
+ const { handler, meta } = normalizeHook(hook);
757
+ return {
758
+ plugin: async (ctx) => {
759
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
760
+ },
761
+ meta: bindingifyPluginHookMeta(meta)
762
+ };
763
+ }
764
+ function bindingifyBanner(args) {
765
+ const hook = args.plugin.banner;
766
+ if (!hook) return {};
767
+ const { handler, meta } = normalizeHook(hook);
768
+ return {
769
+ plugin: async (ctx, chunk) => {
770
+ if (typeof handler === "string") return handler;
771
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
772
+ },
773
+ meta: bindingifyPluginHookMeta(meta)
774
+ };
775
+ }
776
+ function bindingifyFooter(args) {
777
+ const hook = args.plugin.footer;
778
+ if (!hook) return {};
779
+ const { handler, meta } = normalizeHook(hook);
780
+ return {
781
+ plugin: async (ctx, chunk) => {
782
+ if (typeof handler === "string") return handler;
783
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
784
+ },
785
+ meta: bindingifyPluginHookMeta(meta)
786
+ };
787
+ }
788
+ function bindingifyIntro(args) {
789
+ const hook = args.plugin.intro;
790
+ if (!hook) return {};
791
+ const { handler, meta } = normalizeHook(hook);
792
+ return {
793
+ plugin: async (ctx, chunk) => {
794
+ if (typeof handler === "string") return handler;
795
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
796
+ },
797
+ meta: bindingifyPluginHookMeta(meta)
798
+ };
799
+ }
800
+ function bindingifyOutro(args) {
801
+ const hook = args.plugin.outro;
802
+ if (!hook) return {};
803
+ const { handler, meta } = normalizeHook(hook);
804
+ return {
805
+ plugin: async (ctx, chunk) => {
806
+ if (typeof handler === "string") return handler;
807
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
808
+ },
809
+ meta: bindingifyPluginHookMeta(meta)
810
+ };
811
+ }
812
+
813
+ //#endregion
814
+ //#region src/plugin/bindingify-watch-hooks.ts
815
+ function bindingifyWatchChange(args) {
816
+ const hook = args.plugin.watchChange;
817
+ if (!hook) return {};
818
+ const { handler, meta } = normalizeHook(hook);
819
+ return {
820
+ plugin: async (ctx, id, event) => {
821
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
822
+ },
823
+ meta: bindingifyPluginHookMeta(meta)
824
+ };
825
+ }
826
+ function bindingifyCloseWatcher(args) {
827
+ const hook = args.plugin.closeWatcher;
828
+ if (!hook) return {};
829
+ const { handler, meta } = normalizeHook(hook);
830
+ return {
831
+ plugin: async (ctx) => {
832
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
833
+ },
834
+ meta: bindingifyPluginHookMeta(meta)
835
+ };
836
+ }
837
+
838
+ //#endregion
839
+ //#region src/plugin/generated/hook-usage.ts
840
+ let HookUsageKind = /* @__PURE__ */ function(HookUsageKind$1) {
841
+ HookUsageKind$1[HookUsageKind$1["buildStart"] = 1] = "buildStart";
842
+ HookUsageKind$1[HookUsageKind$1["resolveId"] = 2] = "resolveId";
843
+ HookUsageKind$1[HookUsageKind$1["resolveDynamicImport"] = 4] = "resolveDynamicImport";
844
+ HookUsageKind$1[HookUsageKind$1["load"] = 8] = "load";
845
+ HookUsageKind$1[HookUsageKind$1["transform"] = 16] = "transform";
846
+ HookUsageKind$1[HookUsageKind$1["moduleParsed"] = 32] = "moduleParsed";
847
+ HookUsageKind$1[HookUsageKind$1["buildEnd"] = 64] = "buildEnd";
848
+ HookUsageKind$1[HookUsageKind$1["renderStart"] = 128] = "renderStart";
849
+ HookUsageKind$1[HookUsageKind$1["renderError"] = 256] = "renderError";
850
+ HookUsageKind$1[HookUsageKind$1["renderChunk"] = 512] = "renderChunk";
851
+ HookUsageKind$1[HookUsageKind$1["augmentChunkHash"] = 1024] = "augmentChunkHash";
852
+ HookUsageKind$1[HookUsageKind$1["generateBundle"] = 2048] = "generateBundle";
853
+ HookUsageKind$1[HookUsageKind$1["writeBundle"] = 4096] = "writeBundle";
854
+ HookUsageKind$1[HookUsageKind$1["closeBundle"] = 8192] = "closeBundle";
855
+ HookUsageKind$1[HookUsageKind$1["watchChange"] = 16384] = "watchChange";
856
+ HookUsageKind$1[HookUsageKind$1["closeWatcher"] = 32768] = "closeWatcher";
857
+ HookUsageKind$1[HookUsageKind$1["transformAst"] = 65536] = "transformAst";
858
+ HookUsageKind$1[HookUsageKind$1["banner"] = 131072] = "banner";
859
+ HookUsageKind$1[HookUsageKind$1["footer"] = 262144] = "footer";
860
+ HookUsageKind$1[HookUsageKind$1["intro"] = 524288] = "intro";
861
+ HookUsageKind$1[HookUsageKind$1["outro"] = 1048576] = "outro";
862
+ return HookUsageKind$1;
863
+ }({});
864
+ var HookUsage = class {
865
+ bitflag = BigInt(0);
866
+ constructor() {}
867
+ union(kind) {
868
+ this.bitflag |= BigInt(kind);
869
+ }
870
+ inner() {
871
+ return Number(this.bitflag);
872
+ }
873
+ };
874
+ function extractHookUsage(plugin) {
875
+ let hookUsage = new HookUsage();
876
+ if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
877
+ if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
878
+ if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
879
+ if (plugin.load) hookUsage.union(HookUsageKind.load);
880
+ if (plugin.transform) hookUsage.union(HookUsageKind.transform);
881
+ if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
882
+ if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
883
+ if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
884
+ if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
885
+ if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
886
+ if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
887
+ if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
888
+ if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
889
+ if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
890
+ if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
891
+ if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
892
+ if (plugin.banner) hookUsage.union(HookUsageKind.banner);
893
+ if (plugin.footer) hookUsage.union(HookUsageKind.footer);
894
+ if (plugin.intro) hookUsage.union(HookUsageKind.intro);
895
+ if (plugin.outro) hookUsage.union(HookUsageKind.outro);
896
+ return hookUsage;
897
+ }
898
+
899
+ //#endregion
900
+ //#region src/plugin/bindingify-plugin.ts
901
+ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
902
+ const args = {
903
+ plugin,
904
+ options,
905
+ outputOptions,
906
+ pluginContextData,
907
+ onLog,
908
+ logLevel,
909
+ watchMode,
910
+ normalizedOutputPlugins
911
+ };
912
+ const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
913
+ const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
914
+ const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
915
+ const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
916
+ const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
917
+ const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
918
+ const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
919
+ const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
920
+ const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
921
+ const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
922
+ const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
923
+ const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
924
+ const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
925
+ const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
926
+ const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
927
+ const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
928
+ const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
929
+ const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
930
+ const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
931
+ const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
932
+ let hookUsage = extractHookUsage(plugin).inner();
933
+ return wrapHandlers({
934
+ name: plugin.name,
935
+ buildStart,
936
+ buildStartMeta,
937
+ resolveId,
938
+ resolveIdMeta,
939
+ resolveIdFilter,
940
+ resolveDynamicImport,
941
+ resolveDynamicImportMeta,
942
+ buildEnd,
943
+ buildEndMeta,
944
+ transform,
945
+ transformMeta,
946
+ transformFilter,
947
+ moduleParsed,
948
+ moduleParsedMeta,
949
+ load,
950
+ loadMeta,
951
+ loadFilter,
952
+ renderChunk,
953
+ renderChunkMeta,
954
+ renderChunkFilter,
955
+ augmentChunkHash,
956
+ augmentChunkHashMeta,
957
+ renderStart,
958
+ renderStartMeta,
959
+ renderError,
960
+ renderErrorMeta,
961
+ generateBundle,
962
+ generateBundleMeta,
963
+ writeBundle,
964
+ writeBundleMeta,
965
+ closeBundle,
966
+ closeBundleMeta,
967
+ banner,
968
+ bannerMeta,
969
+ footer,
970
+ footerMeta,
971
+ intro,
972
+ introMeta,
973
+ outro,
974
+ outroMeta,
975
+ watchChange,
976
+ watchChangeMeta,
977
+ closeWatcher,
978
+ closeWatcherMeta,
979
+ hookUsage
980
+ });
981
+ }
982
+ function wrapHandlers(plugin) {
983
+ for (const hookName of [
984
+ "buildStart",
985
+ "resolveId",
986
+ "resolveDynamicImport",
987
+ "buildEnd",
988
+ "transform",
989
+ "moduleParsed",
990
+ "load",
991
+ "renderChunk",
992
+ "augmentChunkHash",
993
+ "renderStart",
994
+ "renderError",
995
+ "generateBundle",
996
+ "writeBundle",
997
+ "closeBundle",
998
+ "banner",
999
+ "footer",
1000
+ "intro",
1001
+ "outro",
1002
+ "watchChange",
1003
+ "closeWatcher"
1004
+ ]) {
1005
+ const handler = plugin[hookName];
1006
+ if (handler) plugin[hookName] = async (...args) => {
1007
+ try {
1008
+ return await handler(...args);
1009
+ } catch (e$1) {
1010
+ return error(logPluginError(e$1, plugin.name, {
1011
+ hook: hookName,
1012
+ id: hookName === "transform" ? args[2] : void 0
1013
+ }));
1014
+ }
1015
+ };
1016
+ }
1017
+ return plugin;
1018
+ }
1019
+
1020
+ //#endregion
1021
+ //#region src/options/normalized-input-options.ts
1022
+ var NormalizedInputOptionsImpl = class extends PlainObjectLike {
1023
+ inner;
1024
+ constructor(inner, onLog) {
1025
+ super();
1026
+ this.onLog = onLog;
1027
+ this.inner = inner;
1028
+ }
1029
+ get shimMissingExports() {
1030
+ return this.inner.shimMissingExports;
1031
+ }
1032
+ get input() {
1033
+ return this.inner.input;
1034
+ }
1035
+ get cwd() {
1036
+ return this.inner.cwd ?? void 0;
1037
+ }
1038
+ get platform() {
1039
+ return this.inner.platform;
1040
+ }
1041
+ get context() {
1042
+ return this.inner.context;
1043
+ }
1044
+ };
1045
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
1046
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
1047
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
1048
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
1049
+ __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
1050
+
1051
+ //#endregion
1052
+ //#region src/options/normalized-output-options.ts
1053
+ var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
1054
+ constructor(inner, outputOptions, normalizedOutputPlugins) {
1055
+ super();
1056
+ this.inner = inner;
1057
+ this.outputOptions = outputOptions;
1058
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
1059
+ }
1060
+ get dir() {
1061
+ return this.inner.dir ?? void 0;
1062
+ }
1063
+ get entryFileNames() {
1064
+ return this.inner.entryFilenames || this.outputOptions.entryFileNames;
1065
+ }
1066
+ get chunkFileNames() {
1067
+ return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
1068
+ }
1069
+ get assetFileNames() {
1070
+ return this.inner.assetFilenames || this.outputOptions.assetFileNames;
1071
+ }
1072
+ get format() {
1073
+ return this.inner.format;
1074
+ }
1075
+ get exports() {
1076
+ return this.inner.exports;
1077
+ }
1078
+ get sourcemap() {
1079
+ return this.inner.sourcemap;
1080
+ }
1081
+ get sourcemapBaseUrl() {
1082
+ return this.inner.sourcemapBaseUrl ?? void 0;
1083
+ }
1084
+ get cssEntryFileNames() {
1085
+ return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
1086
+ }
1087
+ get cssChunkFileNames() {
1088
+ return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
1089
+ }
1090
+ get shimMissingExports() {
1091
+ return this.inner.shimMissingExports;
1092
+ }
1093
+ get name() {
1094
+ return this.inner.name ?? void 0;
1095
+ }
1096
+ get file() {
1097
+ return this.inner.file ?? void 0;
1098
+ }
1099
+ get inlineDynamicImports() {
1100
+ return this.inner.inlineDynamicImports;
1101
+ }
1102
+ get externalLiveBindings() {
1103
+ return this.inner.externalLiveBindings;
1104
+ }
1105
+ get banner() {
1106
+ return normalizeAddon(this.outputOptions.banner);
1107
+ }
1108
+ get footer() {
1109
+ return normalizeAddon(this.outputOptions.footer);
1110
+ }
1111
+ get intro() {
1112
+ return normalizeAddon(this.outputOptions.intro);
1113
+ }
1114
+ get outro() {
1115
+ return normalizeAddon(this.outputOptions.outro);
1116
+ }
1117
+ get esModule() {
1118
+ return this.inner.esModule;
1119
+ }
1120
+ get extend() {
1121
+ return this.inner.extend;
1122
+ }
1123
+ get globals() {
1124
+ return this.inner.globals || this.outputOptions.globals;
1125
+ }
1126
+ get paths() {
1127
+ return this.outputOptions.paths;
1128
+ }
1129
+ get hashCharacters() {
1130
+ return this.inner.hashCharacters;
1131
+ }
1132
+ get sourcemapDebugIds() {
1133
+ return this.inner.sourcemapDebugIds;
1134
+ }
1135
+ get sourcemapIgnoreList() {
1136
+ return this.outputOptions.sourcemapIgnoreList;
1137
+ }
1138
+ get sourcemapPathTransform() {
1139
+ return this.outputOptions.sourcemapPathTransform;
1140
+ }
1141
+ get minify() {
1142
+ let ret = this.inner.minify;
1143
+ if (typeof ret === "object" && ret !== null) {
1144
+ delete ret["codegen"];
1145
+ delete ret["module"];
1146
+ delete ret["sourcemap"];
1147
+ }
1148
+ return ret;
1149
+ }
1150
+ get legalComments() {
1151
+ return this.inner.legalComments;
1152
+ }
1153
+ get polyfillRequire() {
1154
+ return this.inner.polyfillRequire;
1155
+ }
1156
+ get plugins() {
1157
+ return this.normalizedOutputPlugins;
1158
+ }
1159
+ get preserveModules() {
1160
+ return this.inner.preserveModules;
1161
+ }
1162
+ get preserveModulesRoot() {
1163
+ return this.inner.preserveModulesRoot;
1164
+ }
1165
+ get virtualDirname() {
1166
+ return this.inner.virtualDirname;
1167
+ }
1168
+ get topLevelVar() {
1169
+ return this.inner.topLevelVar ?? false;
1170
+ }
1171
+ get minifyInternalExports() {
1172
+ return this.inner.minifyInternalExports ?? false;
1173
+ }
1174
+ };
1175
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
1176
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
1177
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
1178
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
1179
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
1180
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
1181
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
1182
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
1183
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "cssEntryFileNames", null);
1184
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "cssChunkFileNames", null);
1185
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
1186
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
1187
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
1188
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
1189
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
1190
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
1191
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
1192
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
1193
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
1194
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
1195
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
1196
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
1197
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
1198
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
1199
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
1200
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
1201
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
1202
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
1203
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
1204
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
1205
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
1206
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
1207
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
1208
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
1209
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
1210
+ __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
1211
+ function normalizeAddon(value) {
1212
+ if (typeof value === "function") return value;
1213
+ return () => value || "";
1214
+ }
1215
+
1216
+ //#endregion
1217
+ //#region src/plugin/plugin-context-data.ts
1218
+ var PluginContextData = class {
1219
+ moduleOptionMap = /* @__PURE__ */ new Map();
1220
+ resolveOptionsMap = /* @__PURE__ */ new Map();
1221
+ loadModulePromiseMap = /* @__PURE__ */ new Map();
1222
+ renderedChunkMeta = null;
1223
+ normalizedInputOptions = null;
1224
+ normalizedOutputOptions = null;
1225
+ constructor(onLog, outputOptions, normalizedOutputPlugins) {
1226
+ this.onLog = onLog;
1227
+ this.outputOptions = outputOptions;
1228
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
1229
+ }
1230
+ updateModuleOption(id, option) {
1231
+ const existing = this.moduleOptionMap.get(id);
1232
+ if (existing) {
1233
+ if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
1234
+ if (option.meta != null) Object.assign(existing.meta, option.meta);
1235
+ if (option.invalidate != null) existing.invalidate = option.invalidate;
1236
+ } else {
1237
+ this.moduleOptionMap.set(id, option);
1238
+ return option;
1239
+ }
1240
+ return existing;
1241
+ }
1242
+ getModuleOption(id) {
1243
+ const option = this.moduleOptionMap.get(id);
1244
+ if (!option) {
1245
+ const raw = {
1246
+ moduleSideEffects: null,
1247
+ meta: {}
1248
+ };
1249
+ this.moduleOptionMap.set(id, raw);
1250
+ return raw;
1251
+ }
1252
+ return option;
1253
+ }
1254
+ getModuleInfo(id, context) {
1255
+ const bindingInfo = context.getModuleInfo(id);
1256
+ if (bindingInfo) {
1257
+ const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
1258
+ return this.proxyModuleInfo(id, info);
1259
+ }
1260
+ return null;
1261
+ }
1262
+ proxyModuleInfo(id, info) {
1263
+ let moduleSideEffects = info.moduleSideEffects;
1264
+ Object.defineProperty(info, "moduleSideEffects", {
1265
+ get() {
1266
+ return moduleSideEffects;
1267
+ },
1268
+ set: (v) => {
1269
+ this.updateModuleOption(id, {
1270
+ moduleSideEffects: v,
1271
+ meta: info.meta,
1272
+ invalidate: true
1273
+ });
1274
+ moduleSideEffects = v;
1275
+ }
1276
+ });
1277
+ return info;
1278
+ }
1279
+ getModuleIds(context) {
1280
+ return context.getModuleIds().values();
1281
+ }
1282
+ saveResolveOptions(options) {
1283
+ const index = this.resolveOptionsMap.size;
1284
+ this.resolveOptionsMap.set(index, options);
1285
+ return index;
1286
+ }
1287
+ getSavedResolveOptions(receipt) {
1288
+ return this.resolveOptionsMap.get(receipt);
1289
+ }
1290
+ removeSavedResolveOptions(receipt) {
1291
+ this.resolveOptionsMap.delete(receipt);
1292
+ }
1293
+ setRenderChunkMeta(meta) {
1294
+ this.renderedChunkMeta = meta;
1295
+ }
1296
+ getRenderChunkMeta() {
1297
+ return this.renderedChunkMeta;
1298
+ }
1299
+ getInputOptions(opts) {
1300
+ this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
1301
+ return this.normalizedInputOptions;
1302
+ }
1303
+ getOutputOptions(opts) {
1304
+ this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
1305
+ return this.normalizedOutputOptions;
1306
+ }
1307
+ clear() {
1308
+ this.renderedChunkMeta = null;
1309
+ this.loadModulePromiseMap.clear();
1310
+ }
1311
+ };
1312
+
1313
+ //#endregion
1314
+ //#region src/utils/normalize-transform-options.ts
1315
+ /**
1316
+ * Normalizes transform options by extracting `define`, `inject`, and `dropLabels` separately from OXC transform options.
1317
+ *
1318
+ * Prioritizes values from `transform.define`, `transform.inject`, and `transform.dropLabels` over deprecated top-level options.
1319
+ */
1320
+ function normalizeTransformOptions(inputOptions) {
1321
+ const transform = inputOptions.transform;
1322
+ const define = transform?.define ? Object.entries(transform.define) : void 0;
1323
+ const inject = transform?.inject;
1324
+ const dropLabels = transform?.dropLabels;
1325
+ let oxcTransformOptions;
1326
+ if (transform) {
1327
+ const { define: _define, inject: _inject, dropLabels: _dropLabels, ...rest } = transform;
1328
+ if (Object.keys(rest).length > 0) {
1329
+ if (rest.jsx === false) rest.jsx = "disable";
1330
+ oxcTransformOptions = rest;
1331
+ }
1332
+ }
1333
+ return {
1334
+ define,
1335
+ inject,
1336
+ dropLabels,
1337
+ oxcTransformOptions
1338
+ };
1339
+ }
1340
+
1341
+ //#endregion
1342
+ //#region src/utils/bindingify-input-options.ts
1343
+ var import_binding = require_binding();
1344
+ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
1345
+ const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
1346
+ const plugins = rawPlugins.map((plugin) => {
1347
+ if ("_parallel" in plugin) return;
1348
+ if (plugin instanceof BuiltinPlugin) {
1349
+ if (plugin.name === "builtin:vite-html") return bindingifyViteHtmlPlugin(plugin, onLog, logLevel, watchMode);
1350
+ return bindingifyBuiltInPlugin(plugin);
1351
+ }
1352
+ return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
1353
+ });
1354
+ const normalizedTransform = normalizeTransformOptions(inputOptions);
1355
+ return {
1356
+ input: bindingifyInput(inputOptions.input),
1357
+ plugins,
1358
+ cwd: inputOptions.cwd ?? process.cwd(),
1359
+ external: bindingifyExternal(inputOptions.external),
1360
+ resolve: bindingifyResolve(inputOptions.resolve),
1361
+ platform: inputOptions.platform,
1362
+ shimMissingExports: inputOptions.shimMissingExports,
1363
+ logLevel: bindingifyLogLevel(logLevel),
1364
+ onLog: async (level, log) => onLog(level, log),
1365
+ treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
1366
+ moduleTypes: inputOptions.moduleTypes,
1367
+ define: normalizedTransform.define,
1368
+ inject: bindingifyInject(normalizedTransform.inject),
1369
+ experimental: bindingifyExperimental(inputOptions.experimental),
1370
+ profilerNames: outputOptions.generatedCode?.profilerNames,
1371
+ transform: normalizedTransform.oxcTransformOptions,
1372
+ watch: bindingifyWatch(inputOptions.watch),
1373
+ dropLabels: normalizedTransform.dropLabels,
1374
+ keepNames: outputOptions.keepNames,
1375
+ checks: inputOptions.checks,
1376
+ deferSyncScanData: () => {
1377
+ let ret = [];
1378
+ pluginContextData.moduleOptionMap.forEach((value, key) => {
1379
+ if (value.invalidate) ret.push({
1380
+ id: key,
1381
+ sideEffects: value.moduleSideEffects ?? void 0
1382
+ });
1383
+ });
1384
+ return ret;
1385
+ },
1386
+ makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
1387
+ debug: inputOptions.debug,
1388
+ invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
1389
+ preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
1390
+ optimization: inputOptions.optimization,
1391
+ context: inputOptions.context,
1392
+ tsconfig: inputOptions.resolve?.tsconfigFilename ?? inputOptions.tsconfig
1393
+ };
1394
+ }
1395
+ function bindingifyHmr(hmr) {
1396
+ if (hmr) {
1397
+ if (typeof hmr === "boolean") return hmr ? {} : void 0;
1398
+ return hmr;
1399
+ }
1400
+ }
1401
+ function bindingifyAttachDebugInfo(attachDebugInfo) {
1402
+ switch (attachDebugInfo) {
1403
+ case void 0: return;
1404
+ case "full": return import_binding.BindingAttachDebugInfo.Full;
1405
+ case "simple": return import_binding.BindingAttachDebugInfo.Simple;
1406
+ case "none": return import_binding.BindingAttachDebugInfo.None;
1407
+ }
1408
+ }
1409
+ function bindingifyExternal(external) {
1410
+ if (external) {
1411
+ if (typeof external === "function") return (id, importer, isResolved) => {
1412
+ if (id.startsWith("\0")) return false;
1413
+ return external(id, importer, isResolved) ?? false;
1414
+ };
1415
+ return arraify(external);
1416
+ }
1417
+ }
1418
+ function bindingifyExperimental(experimental) {
1419
+ let chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
1420
+ if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
1421
+ case "exec-order":
1422
+ chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
1423
+ break;
1424
+ case "module-id":
1425
+ chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ModuleId;
1426
+ break;
1427
+ default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
1428
+ }
1429
+ return {
1430
+ strictExecutionOrder: experimental?.strictExecutionOrder,
1431
+ disableLiveBindings: experimental?.disableLiveBindings,
1432
+ viteMode: experimental?.viteMode,
1433
+ resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
1434
+ hmr: bindingifyHmr(experimental?.hmr),
1435
+ attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
1436
+ chunkModulesOrder,
1437
+ chunkImportMap: experimental?.chunkImportMap,
1438
+ onDemandWrapping: experimental?.onDemandWrapping,
1439
+ incrementalBuild: experimental?.incrementalBuild,
1440
+ nativeMagicString: experimental?.nativeMagicString
1441
+ };
1442
+ }
1443
+ function bindingifyResolve(resolve) {
1444
+ const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
1445
+ if (resolve) {
1446
+ const { alias, extensionAlias, ...rest } = resolve;
1447
+ return {
1448
+ alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
1449
+ find: name,
1450
+ replacements: replacement === false ? [void 0] : arraify(replacement)
1451
+ })) : void 0,
1452
+ extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
1453
+ target: name,
1454
+ replacements: value
1455
+ })) : void 0,
1456
+ yarnPnp,
1457
+ ...rest
1458
+ };
1459
+ } else return { yarnPnp };
1460
+ }
1461
+ function bindingifyInject(inject) {
1462
+ if (inject) return Object.entries(inject).map(([alias, item]) => {
1463
+ if (Array.isArray(item)) {
1464
+ if (item[1] === "*") return {
1465
+ tagNamespace: true,
1466
+ alias,
1467
+ from: item[0]
1468
+ };
1469
+ return {
1470
+ tagNamed: true,
1471
+ alias,
1472
+ from: item[0],
1473
+ imported: item[1]
1474
+ };
1475
+ } else return {
1476
+ tagNamed: true,
1477
+ imported: "default",
1478
+ alias,
1479
+ from: item
1480
+ };
1481
+ });
1482
+ }
1483
+ function bindingifyLogLevel(logLevel) {
1484
+ switch (logLevel) {
1485
+ case "silent": return import_binding.BindingLogLevel.Silent;
1486
+ case "debug": return import_binding.BindingLogLevel.Debug;
1487
+ case "warn": return import_binding.BindingLogLevel.Warn;
1488
+ case "info": return import_binding.BindingLogLevel.Info;
1489
+ default: throw new Error(`Unexpected log level: ${logLevel}`);
1490
+ }
1491
+ }
1492
+ function bindingifyInput(input) {
1493
+ if (input === void 0) return [];
1494
+ if (typeof input === "string") return [{ import: input }];
1495
+ if (Array.isArray(input)) return input.map((src) => ({ import: src }));
1496
+ return Object.entries(input).map(([name, import_path]) => {
1497
+ return {
1498
+ name,
1499
+ import: import_path
1500
+ };
1501
+ });
1502
+ }
1503
+ function bindingifyWatch(watch) {
1504
+ if (watch) return {
1505
+ buildDelay: watch.buildDelay,
1506
+ skipWrite: watch.skipWrite,
1507
+ include: normalizedStringOrRegex(watch.include),
1508
+ exclude: normalizedStringOrRegex(watch.exclude),
1509
+ onInvalidate: (...args) => watch.onInvalidate?.(...args)
1510
+ };
1511
+ }
1512
+ function bindingifyTreeshakeOptions(config) {
1513
+ if (config === false) return;
1514
+ if (config === true || config === void 0) return { moduleSideEffects: true };
1515
+ let normalizedConfig = {
1516
+ moduleSideEffects: true,
1517
+ annotations: config.annotations,
1518
+ manualPureFunctions: config.manualPureFunctions,
1519
+ unknownGlobalSideEffects: config.unknownGlobalSideEffects,
1520
+ commonjs: config.commonjs
1521
+ };
1522
+ switch (config.propertyReadSideEffects) {
1523
+ case "always":
1524
+ normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
1525
+ break;
1526
+ case false:
1527
+ normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
1528
+ break;
1529
+ default:
1530
+ }
1531
+ switch (config.propertyWriteSideEffects) {
1532
+ case "always":
1533
+ normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
1534
+ break;
1535
+ case false:
1536
+ normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
1537
+ break;
1538
+ default:
1539
+ }
1540
+ if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
1541
+ else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
1542
+ external: true,
1543
+ sideEffects: false
1544
+ }, {
1545
+ external: false,
1546
+ sideEffects: true
1547
+ }];
1548
+ else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
1549
+ return normalizedConfig;
1550
+ }
1551
+ function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
1552
+ if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
1553
+ if (typeof makeAbsoluteExternalsRelative === "boolean") return {
1554
+ type: "Bool",
1555
+ field0: makeAbsoluteExternalsRelative
1556
+ };
1557
+ }
1558
+ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
1559
+ if (preserveEntrySignatures == void 0) return;
1560
+ else if (typeof preserveEntrySignatures === "string") return {
1561
+ type: "String",
1562
+ field0: preserveEntrySignatures
1563
+ };
1564
+ else return {
1565
+ type: "Bool",
1566
+ field0: preserveEntrySignatures
1567
+ };
1568
+ }
1569
+
1570
+ //#endregion
1571
+ export { aggregateBindingErrorsIntoJsError as a, normalizeHook as c, transformModuleInfo as i, PluginContextData as n, normalizeBindingResult as o, bindingifyPlugin as r, unwrapBindingResult as s, bindingifyInputOptions as t };