rolldown 1.0.0-beta.6-commit.0fdc9f2 → 1.0.0-beta.60

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