rolldown 1.0.0-beta.22 → 1.0.0-beta.23

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 (35) hide show
  1. package/dist/cli.cjs +3 -3
  2. package/dist/cli.mjs +3 -3
  3. package/dist/config.cjs +3 -3
  4. package/dist/config.d.cts +2 -2
  5. package/dist/config.d.mts +2 -2
  6. package/dist/config.mjs +3 -3
  7. package/dist/experimental-index.cjs +2 -3
  8. package/dist/experimental-index.d.cts +3 -6
  9. package/dist/experimental-index.d.mts +3 -6
  10. package/dist/experimental-index.mjs +3 -3
  11. package/dist/filter-index.cjs +1 -1
  12. package/dist/filter-index.d.cts +2 -2
  13. package/dist/filter-index.d.mts +2 -2
  14. package/dist/filter-index.mjs +1 -1
  15. package/dist/index.cjs +2 -2
  16. package/dist/index.d.cts +3 -3
  17. package/dist/index.d.mts +3 -3
  18. package/dist/index.mjs +2 -2
  19. package/dist/parallel-plugin-worker.cjs +3 -3
  20. package/dist/parallel-plugin-worker.mjs +3 -3
  21. package/dist/parallel-plugin.d.cts +2 -2
  22. package/dist/parallel-plugin.d.mts +2 -2
  23. package/dist/parse-ast-index.d.cts +1 -1
  24. package/dist/parse-ast-index.d.mts +1 -1
  25. package/dist/shared/{binding-B8kHDLfO.d.mts → binding-CMKStSph.d.cts} +4 -14
  26. package/dist/shared/{binding-CbR_BHh9.d.cts → binding-DB58iXP8.d.mts} +4 -14
  27. package/dist/shared/{define-config-Czc3unFy.d.mts → define-config-BRkYSF9E.d.cts} +12 -22
  28. package/dist/shared/{define-config-DZVEpUTF.d.cts → define-config-CyRbZDRR.d.mts} +12 -22
  29. package/dist/shared/{load-config-gtAGhZYG.mjs → load-config-CTdjFUJH.mjs} +1 -1
  30. package/dist/shared/{load-config-DPnW1OC0.cjs → load-config-n-iiDvYj.cjs} +1 -1
  31. package/dist/shared/{misc-BN0nse6C.mjs → misc-CQeo-AFx.mjs} +1 -4
  32. package/dist/shared/{misc-BKp5iIef.cjs → misc-DksvspN4.cjs} +0 -9
  33. package/dist/shared/{src-9_Ra3A9D.cjs → src-D6QrbVqq.cjs} +327 -654
  34. package/dist/shared/{src-CJvC869N.mjs → src-DgdMNl-3.mjs} +427 -748
  35. package/package.json +16 -17
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-DDkG_k5U.cjs');
2
2
  const require_parse_ast_index = require('./parse-ast-index-DDMiEgyY.cjs');
3
- const require_misc = require('./misc-BKp5iIef.cjs');
3
+ const require_misc = require('./misc-DksvspN4.cjs');
4
4
  const node_path = require_chunk.__toESM(require("node:path"));
5
5
  const node_url = require_chunk.__toESM(require("node:url"));
6
6
  const ansis = require_chunk.__toESM(require("ansis"));
@@ -9,7 +9,7 @@ const node_os = require_chunk.__toESM(require("node:os"));
9
9
  const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
10
10
 
11
11
  //#region package.json
12
- var version = "1.0.0-beta.22";
12
+ var version = "1.0.0-beta.23";
13
13
  var description$1 = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
14
14
 
15
15
  //#endregion
@@ -52,8 +52,8 @@ function reporterPlugin(config) {
52
52
  function manifestPlugin(config) {
53
53
  return new BuiltinPlugin("builtin:manifest", config);
54
54
  }
55
- function wasmHelperPlugin() {
56
- return new BuiltinPlugin("builtin:wasm-helper");
55
+ function wasmHelperPlugin(config) {
56
+ return new BuiltinPlugin("builtin:wasm-helper", config);
57
57
  }
58
58
  function wasmFallbackPlugin() {
59
59
  const builtinPlugin = new BuiltinPlugin("builtin:wasm-fallback");
@@ -2255,41 +2255,9 @@ function getJsonSchema() {
2255
2255
  return toJsonSchema(CliOptionsSchema, { errorMode: "ignore" });
2256
2256
  }
2257
2257
 
2258
- //#endregion
2259
- //#region src/constants/plugin-context.ts
2260
- /**
2261
- * If Composed plugins call `this.resolve` with `skipSelf: true`, the composed plugins will be skipped as a whole.
2262
- * To prevent that, we use this symbol to store the actual caller of `this.resolve` with `skipSelf: true`. And we
2263
- * will modify the skipSelf option to `false` and use this symbol to skip the caller itself in the composed plugins
2264
- * internally.
2265
- */
2266
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
2267
-
2268
- //#endregion
2269
- //#region src/options/normalized-input-options.ts
2270
- var NormalizedInputOptionsImpl = class {
2271
- inner;
2272
- constructor(inner, onLog) {
2273
- this.onLog = onLog;
2274
- this.inner = inner;
2275
- }
2276
- get shimMissingExports() {
2277
- return this.inner.shimMissingExports;
2278
- }
2279
- get input() {
2280
- return this.inner.input;
2281
- }
2282
- get cwd() {
2283
- return this.inner.cwd ?? void 0;
2284
- }
2285
- get platform() {
2286
- return this.inner.platform;
2287
- }
2288
- };
2289
-
2290
2258
  //#endregion
2291
2259
  //#region src/types/sourcemap.ts
2292
- function bindingifySourcemap(map) {
2260
+ function bindingifySourcemap$1(map) {
2293
2261
  if (map == null) return;
2294
2262
  return { inner: typeof map === "string" ? map : {
2295
2263
  file: map.file ?? void 0,
@@ -2405,8 +2373,8 @@ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
2405
2373
  //#endregion
2406
2374
  //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
2407
2375
  function u$1(o, n, a) {
2408
- let t$1 = (r) => o(r, ...n);
2409
- return a === void 0 ? t$1 : Object.assign(t$1, {
2376
+ let t = (r) => o(r, ...n);
2377
+ return a === void 0 ? t : Object.assign(t, {
2410
2378
  lazy: a,
2411
2379
  lazyArgs: n
2412
2380
  });
@@ -2426,18 +2394,12 @@ function u(r, n, o) {
2426
2394
  function d(...r) {
2427
2395
  return u(i, r);
2428
2396
  }
2429
- var i = (r, t$1) => {
2397
+ var i = (r, t) => {
2430
2398
  let a = [[], []];
2431
- for (let [o, e] of r.entries()) t$1(e, o, r) ? a[0].push(e) : a[1].push(e);
2399
+ for (let [o, e] of r.entries()) t(e, o, r) ? a[0].push(e) : a[1].push(e);
2432
2400
  return a;
2433
2401
  };
2434
2402
 
2435
- //#endregion
2436
- //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
2437
- function t(...n) {
2438
- return u(Object.keys, n);
2439
- }
2440
-
2441
2403
  //#endregion
2442
2404
  //#region src/plugin/bindingify-hook-filter.ts
2443
2405
  function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
@@ -2742,7 +2704,7 @@ function bindingifyBuildStart(args$1) {
2742
2704
  const { handler, meta } = normalizeHook(hook);
2743
2705
  return {
2744
2706
  plugin: async (ctx, opts) => {
2745
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedInputOptionsImpl(opts, args$1.onLog));
2707
+ await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getInputOptions(opts));
2746
2708
  },
2747
2709
  meta: bindingifyPluginHookMeta(meta)
2748
2710
  };
@@ -2765,12 +2727,10 @@ function bindingifyResolveId(args$1) {
2765
2727
  return {
2766
2728
  plugin: async (ctx, specifier, importer, extraOptions) => {
2767
2729
  const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
2768
- const newExtraOptions = {
2730
+ const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0, {
2769
2731
  ...extraOptions,
2770
- custom: contextResolveOptions?.custom,
2771
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
2772
- };
2773
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0, newExtraOptions);
2732
+ custom: contextResolveOptions?.custom
2733
+ });
2774
2734
  if (ret == null) return;
2775
2735
  if (ret === false) return {
2776
2736
  id: specifier,
@@ -2841,7 +2801,7 @@ function bindingifyTransform(args$1) {
2841
2801
  });
2842
2802
  return {
2843
2803
  code: ret.code,
2844
- map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, ret.map)),
2804
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
2845
2805
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
2846
2806
  moduleType: ret.moduleType
2847
2807
  };
@@ -2867,7 +2827,7 @@ function bindingifyLoad(args$1) {
2867
2827
  let map = preProcessSourceMap(ret, id);
2868
2828
  return {
2869
2829
  code: ret.code,
2870
- map: bindingifySourcemap(map),
2830
+ map: bindingifySourcemap$1(map),
2871
2831
  moduleType: ret.moduleType,
2872
2832
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
2873
2833
  };
@@ -2898,25 +2858,6 @@ function bindingifyModuleParsed(args$1) {
2898
2858
  };
2899
2859
  }
2900
2860
 
2901
- //#endregion
2902
- //#region src/types/chunking-context.ts
2903
- var ChunkingContext = class {
2904
- constructor(context) {
2905
- this.context = context;
2906
- }
2907
- getModuleInfo(moduleId) {
2908
- const bindingInfo = this.context.getModuleInfo(moduleId);
2909
- if (bindingInfo) {
2910
- const info = transformModuleInfo(bindingInfo, {
2911
- moduleSideEffects: null,
2912
- meta: {}
2913
- });
2914
- return info;
2915
- }
2916
- return null;
2917
- }
2918
- };
2919
-
2920
2861
  //#endregion
2921
2862
  //#region src/utils/transform-rendered-module.ts
2922
2863
  function transformToRenderedModule(bindingRenderedModule) {
@@ -2982,219 +2923,6 @@ function transformChunkModules(modules) {
2982
2923
  return result;
2983
2924
  }
2984
2925
 
2985
- //#endregion
2986
- //#region src/utils/bindingify-output-options.ts
2987
- function bindingifyOutputOptions(outputOptions) {
2988
- const { dir, format, exports: exports$1, hashCharacters, sourcemap, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks } = outputOptions;
2989
- const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
2990
- return {
2991
- dir,
2992
- file: file == null ? void 0 : file,
2993
- format: bindingifyFormat(format),
2994
- exports: exports$1,
2995
- hashCharacters,
2996
- sourcemap: bindingifySourcemap$1(sourcemap),
2997
- sourcemapDebugIds,
2998
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
2999
- sourcemapPathTransform,
3000
- banner: bindingifyAddon(banner),
3001
- footer: bindingifyAddon(footer),
3002
- intro: bindingifyAddon(intro),
3003
- outro: bindingifyAddon(outro),
3004
- extend: outputOptions.extend,
3005
- globals,
3006
- esModule,
3007
- name,
3008
- assetFileNames: bindingifyAssetFilenames(assetFileNames),
3009
- entryFileNames,
3010
- chunkFileNames,
3011
- cssEntryFileNames,
3012
- cssChunkFileNames,
3013
- plugins: [],
3014
- minify: outputOptions.minify,
3015
- externalLiveBindings: outputOptions.externalLiveBindings,
3016
- inlineDynamicImports: outputOptions.inlineDynamicImports,
3017
- advancedChunks,
3018
- polyfillRequire: outputOptions.polyfillRequire,
3019
- sanitizeFileName,
3020
- preserveModules,
3021
- virtualDirname,
3022
- legalComments,
3023
- preserveModulesRoot
3024
- };
3025
- }
3026
- function bindingifyAddon(configAddon) {
3027
- return async (chunk) => {
3028
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3029
- return configAddon || "";
3030
- };
3031
- }
3032
- function bindingifyFormat(format) {
3033
- switch (format) {
3034
- case void 0:
3035
- case "es":
3036
- case "esm":
3037
- case "module": return "es";
3038
- case "cjs":
3039
- case "commonjs": return "cjs";
3040
- case "iife": return "iife";
3041
- case "umd": return "umd";
3042
- default: require_misc.unimplemented(`output.format: ${format}`);
3043
- }
3044
- }
3045
- function bindingifySourcemap$1(sourcemap) {
3046
- switch (sourcemap) {
3047
- case true: return "file";
3048
- case "inline": return "inline";
3049
- case false:
3050
- case void 0: return void 0;
3051
- case "hidden": return "hidden";
3052
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3053
- }
3054
- }
3055
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3056
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3057
- }
3058
- function bindingifyAssetFilenames(assetFileNames) {
3059
- if (typeof assetFileNames === "function") return (asset) => {
3060
- return assetFileNames({
3061
- names: asset.names,
3062
- originalFileNames: asset.originalFileNames,
3063
- source: transformAssetSource(asset.source),
3064
- type: "asset"
3065
- });
3066
- };
3067
- return assetFileNames;
3068
- }
3069
- function bindingifyAdvancedChunks(advancedChunks, manualChunks) {
3070
- if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
3071
- else if (manualChunks != null) advancedChunks = { groups: [{ name(moduleId, ctx) {
3072
- return manualChunks(moduleId, { getModuleInfo: (id) => ctx.getModuleInfo(id) });
3073
- } }] };
3074
- if (advancedChunks == null) return void 0;
3075
- const { groups,...restAdvancedChunks } = advancedChunks;
3076
- return {
3077
- ...restAdvancedChunks,
3078
- groups: groups?.map((group) => {
3079
- const { name,...restGroup } = group;
3080
- return {
3081
- ...restGroup,
3082
- name: typeof name === "function" ? (id, ctx) => name(id, new ChunkingContext(ctx)) : name
3083
- };
3084
- })
3085
- };
3086
- }
3087
-
3088
- //#endregion
3089
- //#region src/options/normalized-output-options.ts
3090
- var NormalizedOutputOptionsImpl = class {
3091
- constructor(inner, outputOptions, normalizedOutputPlugins) {
3092
- this.inner = inner;
3093
- this.outputOptions = outputOptions;
3094
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3095
- }
3096
- get dir() {
3097
- return this.inner.dir ?? void 0;
3098
- }
3099
- get entryFileNames() {
3100
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3101
- }
3102
- get chunkFileNames() {
3103
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3104
- }
3105
- get assetFileNames() {
3106
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3107
- }
3108
- get format() {
3109
- return this.inner.format;
3110
- }
3111
- get exports() {
3112
- return this.inner.exports;
3113
- }
3114
- get sourcemap() {
3115
- return this.inner.sourcemap;
3116
- }
3117
- get cssEntryFileNames() {
3118
- return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3119
- }
3120
- get cssChunkFileNames() {
3121
- return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3122
- }
3123
- get shimMissingExports() {
3124
- return this.inner.shimMissingExports;
3125
- }
3126
- get name() {
3127
- return this.inner.name ?? void 0;
3128
- }
3129
- get file() {
3130
- return this.inner.file ?? void 0;
3131
- }
3132
- get inlineDynamicImports() {
3133
- return this.inner.inlineDynamicImports;
3134
- }
3135
- get externalLiveBindings() {
3136
- return this.inner.externalLiveBindings;
3137
- }
3138
- get banner() {
3139
- return normalizeAddon(this.outputOptions.banner);
3140
- }
3141
- get footer() {
3142
- return normalizeAddon(this.outputOptions.footer);
3143
- }
3144
- get intro() {
3145
- return normalizeAddon(this.outputOptions.intro);
3146
- }
3147
- get outro() {
3148
- return normalizeAddon(this.outputOptions.outro);
3149
- }
3150
- get esModule() {
3151
- return this.inner.esModule;
3152
- }
3153
- get extend() {
3154
- return this.inner.extend;
3155
- }
3156
- get globals() {
3157
- return this.inner.globals || this.outputOptions.globals;
3158
- }
3159
- get hashCharacters() {
3160
- return this.inner.hashCharacters;
3161
- }
3162
- get sourcemapDebugIds() {
3163
- return this.inner.sourcemapDebugIds;
3164
- }
3165
- get sourcemapIgnoreList() {
3166
- return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3167
- }
3168
- get sourcemapPathTransform() {
3169
- return this.outputOptions.sourcemapPathTransform;
3170
- }
3171
- get minify() {
3172
- return this.inner.minify;
3173
- }
3174
- get legalComments() {
3175
- return this.inner.legalComments;
3176
- }
3177
- get polyfillRequire() {
3178
- return this.inner.polyfillRequire;
3179
- }
3180
- get plugins() {
3181
- return this.normalizedOutputPlugins;
3182
- }
3183
- get preserveModules() {
3184
- return this.inner.preserveModules;
3185
- }
3186
- get preserveModulesRoot() {
3187
- return this.inner.preserveModulesRoot;
3188
- }
3189
- get virtualDirname() {
3190
- return this.inner.virtualDirname;
3191
- }
3192
- };
3193
- function normalizeAddon(value) {
3194
- if (typeof value === "function") return value;
3195
- return () => value || "";
3196
- }
3197
-
3198
2926
  //#endregion
3199
2927
  //#region src/utils/transform-to-rollup-output.ts
3200
2928
  function transformToRollupSourceMap(map) {
@@ -3340,7 +3068,7 @@ function collectChangedBundle(changed, bundle) {
3340
3068
  facadeModuleId: item.facadeModuleId || void 0,
3341
3069
  isDynamicEntry: item.isDynamicEntry,
3342
3070
  moduleIds: item.moduleIds,
3343
- map: bindingifySourcemap(item.map),
3071
+ map: bindingifySourcemap$1(item.map),
3344
3072
  sourcemapFilename: item.sourcemapFileName || void 0,
3345
3073
  preliminaryFilename: item.preliminaryFileName
3346
3074
  });
@@ -3360,7 +3088,7 @@ function bindingifyRenderStart(args$1) {
3360
3088
  const { handler, meta } = normalizeHook(hook);
3361
3089
  return {
3362
3090
  plugin: async (ctx, opts) => {
3363
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), new NormalizedInputOptionsImpl(opts, args$1.onLog));
3091
+ handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getInputOptions(opts));
3364
3092
  },
3365
3093
  meta: bindingifyPluginHookMeta(meta)
3366
3094
  };
@@ -3372,13 +3100,13 @@ function bindingifyRenderChunk(args$1) {
3372
3100
  return {
3373
3101
  plugin: async (ctx, code, chunk, opts, meta$1) => {
3374
3102
  if (args$1.pluginContextData.getRenderChunkMeta() == null) args$1.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
3375
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), args$1.pluginContextData.getRenderChunkMeta());
3103
+ const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), code, transformRenderedChunk(chunk), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getRenderChunkMeta());
3376
3104
  if (ret == null) return;
3377
3105
  if (typeof ret === "string") return { code: ret };
3378
3106
  if (!ret.map) return { code: ret.code };
3379
3107
  return {
3380
3108
  code: ret.code,
3381
- map: bindingifySourcemap(ret.map)
3109
+ map: bindingifySourcemap$1(ret.map)
3382
3110
  };
3383
3111
  },
3384
3112
  meta: bindingifyPluginHookMeta(meta),
@@ -3419,7 +3147,7 @@ function bindingifyGenerateBundle(args$1) {
3419
3147
  };
3420
3148
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3421
3149
  const output = transformToOutputBundle(context, bundle, changed);
3422
- await handler.call(context, new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output, isWrite);
3150
+ await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
3423
3151
  return collectChangedBundle(changed, output);
3424
3152
  },
3425
3153
  meta: bindingifyPluginHookMeta(meta)
@@ -3437,7 +3165,7 @@ function bindingifyWriteBundle(args$1) {
3437
3165
  };
3438
3166
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3439
3167
  const output = transformToOutputBundle(context, bundle, changed);
3440
- await handler.call(context, new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output);
3168
+ await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
3441
3169
  return collectChangedBundle(changed, output);
3442
3170
  },
3443
3171
  meta: bindingifyPluginHookMeta(meta)
@@ -3671,44 +3399,298 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
3671
3399
  closeWatcherMeta,
3672
3400
  hookUsage
3673
3401
  };
3674
- return wrapHandlers(result);
3402
+ return wrapHandlers(result);
3403
+ }
3404
+ function wrapHandlers(plugin) {
3405
+ for (const hookName of [
3406
+ "buildStart",
3407
+ "resolveId",
3408
+ "resolveDynamicImport",
3409
+ "buildEnd",
3410
+ "transform",
3411
+ "moduleParsed",
3412
+ "load",
3413
+ "renderChunk",
3414
+ "augmentChunkHash",
3415
+ "renderStart",
3416
+ "renderError",
3417
+ "generateBundle",
3418
+ "writeBundle",
3419
+ "closeBundle",
3420
+ "banner",
3421
+ "footer",
3422
+ "intro",
3423
+ "outro",
3424
+ "watchChange",
3425
+ "closeWatcher"
3426
+ ]) {
3427
+ const handler = plugin[hookName];
3428
+ if (handler) plugin[hookName] = async (...args$1) => {
3429
+ try {
3430
+ return await handler(...args$1);
3431
+ } catch (e) {
3432
+ return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e, plugin.name, {
3433
+ hook: hookName,
3434
+ id: hookName === "transform" ? args$1[2] : void 0
3435
+ }));
3436
+ }
3437
+ };
3438
+ }
3439
+ return plugin;
3440
+ }
3441
+
3442
+ //#endregion
3443
+ //#region src/options/normalized-input-options.ts
3444
+ var NormalizedInputOptionsImpl = class {
3445
+ inner;
3446
+ constructor(inner, onLog) {
3447
+ this.onLog = onLog;
3448
+ this.inner = inner;
3449
+ }
3450
+ get shimMissingExports() {
3451
+ return this.inner.shimMissingExports;
3452
+ }
3453
+ get input() {
3454
+ return this.inner.input;
3455
+ }
3456
+ get cwd() {
3457
+ return this.inner.cwd ?? void 0;
3458
+ }
3459
+ get platform() {
3460
+ return this.inner.platform;
3461
+ }
3462
+ };
3463
+
3464
+ //#endregion
3465
+ //#region src/types/chunking-context.ts
3466
+ var ChunkingContextImpl = class {
3467
+ constructor(context) {
3468
+ this.context = context;
3469
+ }
3470
+ getModuleInfo(moduleId) {
3471
+ const bindingInfo = this.context.getModuleInfo(moduleId);
3472
+ if (bindingInfo) {
3473
+ const info = transformModuleInfo(bindingInfo, {
3474
+ moduleSideEffects: null,
3475
+ meta: {}
3476
+ });
3477
+ return info;
3478
+ }
3479
+ return null;
3480
+ }
3481
+ };
3482
+
3483
+ //#endregion
3484
+ //#region src/utils/bindingify-output-options.ts
3485
+ function bindingifyOutputOptions(outputOptions) {
3486
+ const { dir, format, exports: exports$1, hashCharacters, sourcemap, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks } = outputOptions;
3487
+ const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
3488
+ return {
3489
+ dir,
3490
+ file: file == null ? void 0 : file,
3491
+ format: bindingifyFormat(format),
3492
+ exports: exports$1,
3493
+ hashCharacters,
3494
+ sourcemap: bindingifySourcemap(sourcemap),
3495
+ sourcemapDebugIds,
3496
+ sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
3497
+ sourcemapPathTransform,
3498
+ banner: bindingifyAddon(banner),
3499
+ footer: bindingifyAddon(footer),
3500
+ intro: bindingifyAddon(intro),
3501
+ outro: bindingifyAddon(outro),
3502
+ extend: outputOptions.extend,
3503
+ globals,
3504
+ esModule,
3505
+ name,
3506
+ assetFileNames: bindingifyAssetFilenames(assetFileNames),
3507
+ entryFileNames,
3508
+ chunkFileNames,
3509
+ cssEntryFileNames,
3510
+ cssChunkFileNames,
3511
+ plugins: [],
3512
+ minify: outputOptions.minify,
3513
+ externalLiveBindings: outputOptions.externalLiveBindings,
3514
+ inlineDynamicImports: outputOptions.inlineDynamicImports,
3515
+ advancedChunks,
3516
+ polyfillRequire: outputOptions.polyfillRequire,
3517
+ sanitizeFileName,
3518
+ preserveModules,
3519
+ virtualDirname,
3520
+ legalComments,
3521
+ preserveModulesRoot
3522
+ };
3523
+ }
3524
+ function bindingifyAddon(configAddon) {
3525
+ return async (chunk) => {
3526
+ if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3527
+ return configAddon || "";
3528
+ };
3529
+ }
3530
+ function bindingifyFormat(format) {
3531
+ switch (format) {
3532
+ case void 0:
3533
+ case "es":
3534
+ case "esm":
3535
+ case "module": return "es";
3536
+ case "cjs":
3537
+ case "commonjs": return "cjs";
3538
+ case "iife": return "iife";
3539
+ case "umd": return "umd";
3540
+ default: require_misc.unimplemented(`output.format: ${format}`);
3541
+ }
3542
+ }
3543
+ function bindingifySourcemap(sourcemap) {
3544
+ switch (sourcemap) {
3545
+ case true: return "file";
3546
+ case "inline": return "inline";
3547
+ case false:
3548
+ case void 0: return void 0;
3549
+ case "hidden": return "hidden";
3550
+ default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3551
+ }
3552
+ }
3553
+ function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3554
+ return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3555
+ }
3556
+ function bindingifyAssetFilenames(assetFileNames) {
3557
+ if (typeof assetFileNames === "function") return (asset) => {
3558
+ return assetFileNames({
3559
+ names: asset.names,
3560
+ originalFileNames: asset.originalFileNames,
3561
+ source: transformAssetSource(asset.source),
3562
+ type: "asset"
3563
+ });
3564
+ };
3565
+ return assetFileNames;
3566
+ }
3567
+ function bindingifyAdvancedChunks(advancedChunks, manualChunks) {
3568
+ if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
3569
+ else if (manualChunks != null) advancedChunks = { groups: [{ name(moduleId, ctx) {
3570
+ return manualChunks(moduleId, { getModuleInfo: (id) => ctx.getModuleInfo(id) });
3571
+ } }] };
3572
+ if (advancedChunks == null) return void 0;
3573
+ const { groups,...restAdvancedChunks } = advancedChunks;
3574
+ return {
3575
+ ...restAdvancedChunks,
3576
+ groups: groups?.map((group) => {
3577
+ const { name,...restGroup } = group;
3578
+ return {
3579
+ ...restGroup,
3580
+ name: typeof name === "function" ? (id, ctx) => name(id, new ChunkingContextImpl(ctx)) : name
3581
+ };
3582
+ })
3583
+ };
3675
3584
  }
3676
- function wrapHandlers(plugin) {
3677
- for (const hookName of [
3678
- "buildStart",
3679
- "resolveId",
3680
- "resolveDynamicImport",
3681
- "buildEnd",
3682
- "transform",
3683
- "moduleParsed",
3684
- "load",
3685
- "renderChunk",
3686
- "augmentChunkHash",
3687
- "renderStart",
3688
- "renderError",
3689
- "generateBundle",
3690
- "writeBundle",
3691
- "closeBundle",
3692
- "banner",
3693
- "footer",
3694
- "intro",
3695
- "outro",
3696
- "watchChange",
3697
- "closeWatcher"
3698
- ]) {
3699
- const handler = plugin[hookName];
3700
- if (handler) plugin[hookName] = async (...args$1) => {
3701
- try {
3702
- return await handler(...args$1);
3703
- } catch (e) {
3704
- return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e, plugin.name, {
3705
- hook: hookName,
3706
- id: hookName === "transform" ? args$1[2] : void 0
3707
- }));
3708
- }
3709
- };
3585
+
3586
+ //#endregion
3587
+ //#region src/options/normalized-output-options.ts
3588
+ var NormalizedOutputOptionsImpl = class {
3589
+ constructor(inner, outputOptions, normalizedOutputPlugins) {
3590
+ this.inner = inner;
3591
+ this.outputOptions = outputOptions;
3592
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
3710
3593
  }
3711
- return plugin;
3594
+ get dir() {
3595
+ return this.inner.dir ?? void 0;
3596
+ }
3597
+ get entryFileNames() {
3598
+ return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3599
+ }
3600
+ get chunkFileNames() {
3601
+ return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3602
+ }
3603
+ get assetFileNames() {
3604
+ return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3605
+ }
3606
+ get format() {
3607
+ return this.inner.format;
3608
+ }
3609
+ get exports() {
3610
+ return this.inner.exports;
3611
+ }
3612
+ get sourcemap() {
3613
+ return this.inner.sourcemap;
3614
+ }
3615
+ get cssEntryFileNames() {
3616
+ return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3617
+ }
3618
+ get cssChunkFileNames() {
3619
+ return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3620
+ }
3621
+ get shimMissingExports() {
3622
+ return this.inner.shimMissingExports;
3623
+ }
3624
+ get name() {
3625
+ return this.inner.name ?? void 0;
3626
+ }
3627
+ get file() {
3628
+ return this.inner.file ?? void 0;
3629
+ }
3630
+ get inlineDynamicImports() {
3631
+ return this.inner.inlineDynamicImports;
3632
+ }
3633
+ get externalLiveBindings() {
3634
+ return this.inner.externalLiveBindings;
3635
+ }
3636
+ get banner() {
3637
+ return normalizeAddon(this.outputOptions.banner);
3638
+ }
3639
+ get footer() {
3640
+ return normalizeAddon(this.outputOptions.footer);
3641
+ }
3642
+ get intro() {
3643
+ return normalizeAddon(this.outputOptions.intro);
3644
+ }
3645
+ get outro() {
3646
+ return normalizeAddon(this.outputOptions.outro);
3647
+ }
3648
+ get esModule() {
3649
+ return this.inner.esModule;
3650
+ }
3651
+ get extend() {
3652
+ return this.inner.extend;
3653
+ }
3654
+ get globals() {
3655
+ return this.inner.globals || this.outputOptions.globals;
3656
+ }
3657
+ get hashCharacters() {
3658
+ return this.inner.hashCharacters;
3659
+ }
3660
+ get sourcemapDebugIds() {
3661
+ return this.inner.sourcemapDebugIds;
3662
+ }
3663
+ get sourcemapIgnoreList() {
3664
+ return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3665
+ }
3666
+ get sourcemapPathTransform() {
3667
+ return this.outputOptions.sourcemapPathTransform;
3668
+ }
3669
+ get minify() {
3670
+ return this.inner.minify;
3671
+ }
3672
+ get legalComments() {
3673
+ return this.inner.legalComments;
3674
+ }
3675
+ get polyfillRequire() {
3676
+ return this.inner.polyfillRequire;
3677
+ }
3678
+ get plugins() {
3679
+ return this.normalizedOutputPlugins;
3680
+ }
3681
+ get preserveModules() {
3682
+ return this.inner.preserveModules;
3683
+ }
3684
+ get preserveModulesRoot() {
3685
+ return this.inner.preserveModulesRoot;
3686
+ }
3687
+ get virtualDirname() {
3688
+ return this.inner.virtualDirname;
3689
+ }
3690
+ };
3691
+ function normalizeAddon(value) {
3692
+ if (typeof value === "function") return value;
3693
+ return () => value || "";
3712
3694
  }
3713
3695
 
3714
3696
  //#endregion
@@ -3719,6 +3701,13 @@ var PluginContextData = class {
3719
3701
  loadModulePromiseMap = /* @__PURE__ */ new Map();
3720
3702
  loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
3721
3703
  renderedChunkMeta = null;
3704
+ normalizedInputOptions = null;
3705
+ normalizedOutputOptions = null;
3706
+ constructor(onLog, outputOptions, normalizedOutputPlugins) {
3707
+ this.onLog = onLog;
3708
+ this.outputOptions = outputOptions;
3709
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
3710
+ }
3722
3711
  updateModuleOption(id, option) {
3723
3712
  const existing = this.moduleOptionMap.get(id);
3724
3713
  if (existing) {
@@ -3789,6 +3778,14 @@ var PluginContextData = class {
3789
3778
  getRenderChunkMeta() {
3790
3779
  return this.renderedChunkMeta;
3791
3780
  }
3781
+ getInputOptions(opts) {
3782
+ this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
3783
+ return this.normalizedInputOptions;
3784
+ }
3785
+ getOutputOptions(opts) {
3786
+ this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
3787
+ return this.normalizedOutputOptions;
3788
+ }
3792
3789
  markModuleLoaded(id, _success) {
3793
3790
  const resolve = this.loadModulePromiseResolveFnMap.get(id);
3794
3791
  if (resolve) resolve();
@@ -3814,7 +3811,7 @@ function isReadonlyArray(input) {
3814
3811
  //#endregion
3815
3812
  //#region src/utils/bindingify-input-options.ts
3816
3813
  function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3817
- const pluginContextData = new PluginContextData();
3814
+ const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
3818
3815
  const plugins = rawPlugins.map((plugin) => {
3819
3816
  if ("_parallel" in plugin) return void 0;
3820
3817
  if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
@@ -4022,323 +4019,6 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
4022
4019
  };
4023
4020
  }
4024
4021
 
4025
- //#endregion
4026
- //#region src/utils/plugin/index.ts
4027
- const isPluginHookName = function() {
4028
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
4029
- return function isPluginHookName$1(hookName) {
4030
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
4031
- };
4032
- }();
4033
-
4034
- //#endregion
4035
- //#region src/utils/compose-js-plugins.ts
4036
- const unsupportedHookName = [
4037
- "augmentChunkHash",
4038
- "generateBundle",
4039
- "moduleParsed",
4040
- "onLog",
4041
- "options",
4042
- "outputOptions",
4043
- "renderError",
4044
- "renderStart",
4045
- "resolveDynamicImport",
4046
- "writeBundle"
4047
- ];
4048
- const unsupportedHooks = new Set(unsupportedHookName);
4049
- function isUnsupportedHooks(hookName) {
4050
- return unsupportedHooks.has(hookName);
4051
- }
4052
- function createComposedPlugin(plugins) {
4053
- const names = [];
4054
- const batchedHooks = {};
4055
- plugins.forEach((plugin, index) => {
4056
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
4057
- names.push(pluginName);
4058
- t(plugin).forEach((pluginProp) => {
4059
- if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
4060
- if (!isPluginHookName(pluginProp)) return;
4061
- switch (pluginProp) {
4062
- case "buildStart": {
4063
- const handlers = batchedHooks.buildStart ?? [];
4064
- batchedHooks.buildStart = handlers;
4065
- if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
4066
- break;
4067
- }
4068
- case "load": {
4069
- const handlers = batchedHooks.load ?? [];
4070
- batchedHooks.load = handlers;
4071
- if (plugin.load) handlers.push([plugin.load, plugin]);
4072
- break;
4073
- }
4074
- case "transform": {
4075
- const handlers = batchedHooks.transform ?? [];
4076
- batchedHooks.transform = handlers;
4077
- if (plugin.transform) handlers.push([plugin.transform, plugin]);
4078
- break;
4079
- }
4080
- case "resolveId": {
4081
- const handlers = batchedHooks.resolveId ?? [];
4082
- batchedHooks.resolveId = handlers;
4083
- if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
4084
- break;
4085
- }
4086
- case "buildEnd": {
4087
- const handlers = batchedHooks.buildEnd ?? [];
4088
- batchedHooks.buildEnd = handlers;
4089
- if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
4090
- break;
4091
- }
4092
- case "renderChunk": {
4093
- const handlers = batchedHooks.renderChunk ?? [];
4094
- batchedHooks.renderChunk = handlers;
4095
- if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
4096
- break;
4097
- }
4098
- case "banner":
4099
- case "footer":
4100
- case "intro":
4101
- case "outro": {
4102
- const hook = plugin[pluginProp];
4103
- if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
4104
- break;
4105
- }
4106
- case "closeBundle": {
4107
- const handlers = batchedHooks.closeBundle ?? [];
4108
- batchedHooks.closeBundle = handlers;
4109
- if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
4110
- break;
4111
- }
4112
- case "watchChange": {
4113
- const handlers = batchedHooks.watchChange ?? [];
4114
- batchedHooks.watchChange = handlers;
4115
- if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
4116
- break;
4117
- }
4118
- case "closeWatcher": {
4119
- const handlers = batchedHooks.closeWatcher ?? [];
4120
- batchedHooks.closeWatcher = handlers;
4121
- if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
4122
- break;
4123
- }
4124
- default: {}
4125
- }
4126
- });
4127
- });
4128
- const composed = { name: `Composed(${names.join(", ")})` };
4129
- const createFixedPluginResolveFnMap = /* @__PURE__ */ new Map();
4130
- function applyFixedPluginResolveFn(ctx, plugin) {
4131
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
4132
- if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
4133
- return ctx;
4134
- }
4135
- if (batchedHooks.resolveId) {
4136
- const batchedHandlers = batchedHooks.resolveId;
4137
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
4138
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4139
- const [_handler, plugin] = batchedHandlers[handlerIdx];
4140
- const handlerSymbol = handlerSymbols[handlerIdx];
4141
- const createFixedPluginResolveFn = (ctx, resolve) => {
4142
- return (source, importer, rawContextResolveOptions) => {
4143
- const contextResolveOptions = rawContextResolveOptions ?? {};
4144
- if (contextResolveOptions.skipSelf) {
4145
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
4146
- contextResolveOptions.skipSelf = false;
4147
- }
4148
- return resolve(source, importer, contextResolveOptions);
4149
- };
4150
- };
4151
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
4152
- }
4153
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
4154
- const hookResolveIdOptions = rawHookResolveIdOptions;
4155
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
4156
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4157
- const [handler, plugin] = batchedHandlers[handlerIdx];
4158
- const handlerSymbol = handlerSymbols[handlerIdx];
4159
- if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
4160
- const { handler: handlerFn } = normalizeHook(handler);
4161
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
4162
- if (!require_misc.isNullish(result)) return result;
4163
- }
4164
- };
4165
- }
4166
- t(batchedHooks).forEach((hookName) => {
4167
- switch (hookName) {
4168
- case "resolveId": break;
4169
- case "buildStart": {
4170
- if (batchedHooks.buildStart) {
4171
- const batchedHandlers = batchedHooks.buildStart;
4172
- composed.buildStart = async function(options) {
4173
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4174
- const { handler: handlerFn } = normalizeHook(handler);
4175
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
4176
- }));
4177
- };
4178
- }
4179
- break;
4180
- }
4181
- case "load": {
4182
- if (batchedHooks.load) {
4183
- const batchedHandlers = batchedHooks.load;
4184
- composed.load = async function(id) {
4185
- for (const [handler, plugin] of batchedHandlers) {
4186
- const { handler: handlerFn } = normalizeHook(handler);
4187
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
4188
- if (!require_misc.isNullish(result)) return result;
4189
- }
4190
- };
4191
- }
4192
- break;
4193
- }
4194
- case "transform": {
4195
- if (batchedHooks.transform) {
4196
- const batchedHandlers = batchedHooks.transform;
4197
- composed.transform = async function(initialCode, id, moduleType) {
4198
- let code = initialCode;
4199
- let moduleSideEffects = void 0;
4200
- function updateOutput(newCode, newModuleSideEffects) {
4201
- code = newCode;
4202
- moduleSideEffects = newModuleSideEffects ?? void 0;
4203
- }
4204
- for (const [handler, plugin] of batchedHandlers) {
4205
- const { handler: handlerFn } = normalizeHook(handler);
4206
- this.getCombinedSourcemap = () => {
4207
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
4208
- };
4209
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
4210
- if (!require_misc.isNullish(result)) {
4211
- if (typeof result === "string") updateOutput(result);
4212
- else if (result.code) updateOutput(result.code, result.moduleSideEffects);
4213
- }
4214
- }
4215
- return {
4216
- code,
4217
- moduleSideEffects
4218
- };
4219
- };
4220
- }
4221
- break;
4222
- }
4223
- case "buildEnd": {
4224
- if (batchedHooks.buildEnd) {
4225
- const batchedHandlers = batchedHooks.buildEnd;
4226
- composed.buildEnd = async function(err) {
4227
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4228
- const { handler: handlerFn } = normalizeHook(handler);
4229
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
4230
- }));
4231
- };
4232
- }
4233
- break;
4234
- }
4235
- case "renderChunk": {
4236
- if (batchedHooks.renderChunk) {
4237
- const batchedHandlers = batchedHooks.renderChunk;
4238
- composed.renderChunk = async function(code, chunk, options, meta) {
4239
- for (const [handler, plugin] of batchedHandlers) {
4240
- const { handler: handlerFn } = normalizeHook(handler);
4241
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options, meta);
4242
- if (!require_misc.isNullish(result)) return result;
4243
- }
4244
- };
4245
- }
4246
- break;
4247
- }
4248
- case "banner":
4249
- case "footer":
4250
- case "intro":
4251
- case "outro": {
4252
- const hooks = batchedHooks[hookName];
4253
- if (hooks?.length) composed[hookName] = async function(chunk) {
4254
- const ret = [];
4255
- for (const [hook, plugin] of hooks) {
4256
- const { handler } = normalizeHook(hook);
4257
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
4258
- }
4259
- return ret.join("\n");
4260
- };
4261
- break;
4262
- }
4263
- case "closeBundle": {
4264
- if (batchedHooks.closeBundle) {
4265
- const batchedHandlers = batchedHooks.closeBundle;
4266
- composed.closeBundle = async function() {
4267
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4268
- const { handler: handlerFn } = normalizeHook(handler);
4269
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4270
- }));
4271
- };
4272
- }
4273
- break;
4274
- }
4275
- case "watchChange": {
4276
- if (batchedHooks.watchChange) {
4277
- const batchedHandlers = batchedHooks.watchChange;
4278
- composed.watchChange = async function(id, event) {
4279
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4280
- const { handler: handlerFn } = normalizeHook(handler);
4281
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
4282
- }));
4283
- };
4284
- }
4285
- break;
4286
- }
4287
- case "closeWatcher": {
4288
- if (batchedHooks.closeWatcher) {
4289
- const batchedHandlers = batchedHooks.closeWatcher;
4290
- composed.closeWatcher = async function() {
4291
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4292
- const { handler: handlerFn } = normalizeHook(handler);
4293
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4294
- }));
4295
- };
4296
- }
4297
- break;
4298
- }
4299
- default: {}
4300
- }
4301
- });
4302
- return composed;
4303
- }
4304
- function isComposablePlugin(plugin) {
4305
- if (plugin instanceof BuiltinPlugin) return false;
4306
- if ("_parallel" in plugin) return false;
4307
- const hasNotComposablePattern = t(plugin).some((hookName) => {
4308
- if (!isPluginHookName(hookName)) return false;
4309
- const OK_TO_COMPOSE = false;
4310
- if (isUnsupportedHooks(hookName)) return true;
4311
- if (plugin[hookName]) {
4312
- const { meta } = normalizeHook(plugin[hookName]);
4313
- if (meta.order === "pre" || meta.order === "post") return true;
4314
- }
4315
- return OK_TO_COMPOSE;
4316
- });
4317
- if (hasNotComposablePattern) return false;
4318
- return true;
4319
- }
4320
- function composeJsPlugins(plugins) {
4321
- const newPlugins = [];
4322
- const toBeComposed = [];
4323
- plugins.forEach((plugin) => {
4324
- if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
4325
- else {
4326
- if (toBeComposed.length > 0) {
4327
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4328
- else newPlugins.push(toBeComposed[0]);
4329
- toBeComposed.length = 0;
4330
- }
4331
- newPlugins.push(plugin);
4332
- }
4333
- });
4334
- if (toBeComposed.length > 0) {
4335
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4336
- else newPlugins.push(toBeComposed[0]);
4337
- toBeComposed.length = 0;
4338
- }
4339
- return newPlugins;
4340
- }
4341
-
4342
4022
  //#endregion
4343
4023
  //#region src/utils/initialize-parallel-plugins.ts
4344
4024
  async function initializeParallelPlugins(plugins) {
@@ -4415,7 +4095,6 @@ async function createBundlerOptions(inputOptions, outputOptions, watchMode, isCl
4415
4095
  ...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX),
4416
4096
  ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)
4417
4097
  ];
4418
- if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
4419
4098
  const parallelPluginInitResult = await initializeParallelPlugins(plugins);
4420
4099
  try {
4421
4100
  const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
@@ -4733,12 +4412,6 @@ Object.defineProperty(exports, 'buildImportAnalysisPlugin', {
4733
4412
  return buildImportAnalysisPlugin;
4734
4413
  }
4735
4414
  });
4736
- Object.defineProperty(exports, 'composeJsPlugins', {
4737
- enumerable: true,
4738
- get: function () {
4739
- return composeJsPlugins;
4740
- }
4741
- });
4742
4415
  Object.defineProperty(exports, 'createBundlerImpl', {
4743
4416
  enumerable: true,
4744
4417
  get: function () {