rolldown 1.0.0-beta.21 → 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 (39) hide show
  1. package/dist/cli.cjs +4 -4
  2. package/dist/cli.mjs +4 -4
  3. package/dist/config.cjs +4 -4
  4. package/dist/config.d.cts +2 -2
  5. package/dist/config.d.mts +2 -2
  6. package/dist/config.mjs +4 -4
  7. package/dist/experimental-index.cjs +3 -4
  8. package/dist/experimental-index.d.cts +3 -6
  9. package/dist/experimental-index.d.mts +3 -6
  10. package/dist/experimental-index.mjs +4 -4
  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 +3 -3
  16. package/dist/index.d.cts +3 -3
  17. package/dist/index.d.mts +3 -3
  18. package/dist/index.mjs +3 -3
  19. package/dist/parallel-plugin-worker.cjs +4 -4
  20. package/dist/parallel-plugin-worker.mjs +4 -4
  21. package/dist/parallel-plugin.d.cts +2 -2
  22. package/dist/parallel-plugin.d.mts +2 -2
  23. package/dist/parse-ast-index.cjs +1 -1
  24. package/dist/parse-ast-index.d.cts +1 -1
  25. package/dist/parse-ast-index.d.mts +1 -1
  26. package/dist/parse-ast-index.mjs +1 -1
  27. package/dist/shared/{binding--Ro_HG7S.d.mts → binding-CMKStSph.d.cts} +5 -1
  28. package/dist/shared/{binding-DBnJxycu.d.cts → binding-DB58iXP8.d.mts} +5 -1
  29. package/dist/shared/{define-config-LuFmoc43.d.cts → define-config-BRkYSF9E.d.cts} +30 -30
  30. package/dist/shared/{define-config-WLh0sQOM.d.mts → define-config-CyRbZDRR.d.mts} +30 -30
  31. package/dist/shared/{load-config-DUa6Uqtc.mjs → load-config-CTdjFUJH.mjs} +1 -1
  32. package/dist/shared/{load-config-juy1xxPU.cjs → load-config-n-iiDvYj.cjs} +1 -1
  33. package/dist/shared/{misc-BN0nse6C.mjs → misc-CQeo-AFx.mjs} +1 -4
  34. package/dist/shared/{misc-BKp5iIef.cjs → misc-DksvspN4.cjs} +0 -9
  35. package/dist/shared/{parse-ast-index-CVVmsBjK.cjs → parse-ast-index-DDMiEgyY.cjs} +1 -1
  36. package/dist/shared/{parse-ast-index-DW8kbzjr.mjs → parse-ast-index-DmWy-n6o.mjs} +1 -1
  37. package/dist/shared/{src-ajsKFM6g.cjs → src-D6QrbVqq.cjs} +327 -614
  38. package/dist/shared/{src-LzfUVOSn.mjs → src-DgdMNl-3.mjs} +328 -609
  39. package/package.json +15 -16
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-DDkG_k5U.cjs');
2
- const require_parse_ast_index = require('./parse-ast-index-CVVmsBjK.cjs');
3
- const require_misc = require('./misc-BKp5iIef.cjs');
2
+ const require_parse_ast_index = require('./parse-ast-index-DDMiEgyY.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.21";
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");
@@ -1989,7 +1989,8 @@ const ResolveOptionsSchema = strictObject({
1989
1989
  const TreeshakingOptionsSchema = union([boolean(), looseObject({
1990
1990
  annotations: optional(boolean()),
1991
1991
  manualPureFunctions: optional(array(string())),
1992
- unknownGlobalSideEffects: optional(boolean())
1992
+ unknownGlobalSideEffects: optional(boolean()),
1993
+ commonjs: optional(boolean())
1993
1994
  })]);
1994
1995
  const OnLogSchema = pipe(function_(), args(tuple([
1995
1996
  LogLevelSchema,
@@ -2254,41 +2255,9 @@ function getJsonSchema() {
2254
2255
  return toJsonSchema(CliOptionsSchema, { errorMode: "ignore" });
2255
2256
  }
2256
2257
 
2257
- //#endregion
2258
- //#region src/constants/plugin-context.ts
2259
- /**
2260
- * If Composed plugins call `this.resolve` with `skipSelf: true`, the composed plugins will be skipped as a whole.
2261
- * To prevent that, we use this symbol to store the actual caller of `this.resolve` with `skipSelf: true`. And we
2262
- * will modify the skipSelf option to `false` and use this symbol to skip the caller itself in the composed plugins
2263
- * internally.
2264
- */
2265
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
2266
-
2267
- //#endregion
2268
- //#region src/options/normalized-input-options.ts
2269
- var NormalizedInputOptionsImpl = class {
2270
- inner;
2271
- constructor(inner, onLog) {
2272
- this.onLog = onLog;
2273
- this.inner = inner;
2274
- }
2275
- get shimMissingExports() {
2276
- return this.inner.shimMissingExports;
2277
- }
2278
- get input() {
2279
- return this.inner.input;
2280
- }
2281
- get cwd() {
2282
- return this.inner.cwd ?? void 0;
2283
- }
2284
- get platform() {
2285
- return this.inner.platform;
2286
- }
2287
- };
2288
-
2289
2258
  //#endregion
2290
2259
  //#region src/types/sourcemap.ts
2291
- function bindingifySourcemap(map) {
2260
+ function bindingifySourcemap$1(map) {
2292
2261
  if (map == null) return;
2293
2262
  return { inner: typeof map === "string" ? map : {
2294
2263
  file: map.file ?? void 0,
@@ -2404,8 +2373,8 @@ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
2404
2373
  //#endregion
2405
2374
  //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
2406
2375
  function u$1(o, n, a) {
2407
- let t$1 = (r) => o(r, ...n);
2408
- 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, {
2409
2378
  lazy: a,
2410
2379
  lazyArgs: n
2411
2380
  });
@@ -2425,18 +2394,12 @@ function u(r, n, o) {
2425
2394
  function d(...r) {
2426
2395
  return u(i, r);
2427
2396
  }
2428
- var i = (r, t$1) => {
2397
+ var i = (r, t) => {
2429
2398
  let a = [[], []];
2430
- 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);
2431
2400
  return a;
2432
2401
  };
2433
2402
 
2434
- //#endregion
2435
- //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
2436
- function t(...n) {
2437
- return u(Object.keys, n);
2438
- }
2439
-
2440
2403
  //#endregion
2441
2404
  //#region src/plugin/bindingify-hook-filter.ts
2442
2405
  function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
@@ -2648,9 +2611,14 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
2648
2611
  async resolve(source, importer, options) {
2649
2612
  let receipt = void 0;
2650
2613
  if (options != null) receipt = this.data.saveResolveOptions(options);
2614
+ const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
2615
+ if (key.startsWith("vite:")) (acc ??= {})[key] = value;
2616
+ return acc;
2617
+ }, void 0);
2651
2618
  const res = await this.context.resolve(source, importer, {
2652
2619
  custom: receipt,
2653
- skipSelf: options?.skipSelf
2620
+ skipSelf: options?.skipSelf,
2621
+ vitePluginCustom
2654
2622
  });
2655
2623
  if (receipt != null) this.data.removeSavedResolveOptions(receipt);
2656
2624
  if (res == null) return null;
@@ -2736,7 +2704,7 @@ function bindingifyBuildStart(args$1) {
2736
2704
  const { handler, meta } = normalizeHook(hook);
2737
2705
  return {
2738
2706
  plugin: async (ctx, opts) => {
2739
- 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));
2740
2708
  },
2741
2709
  meta: bindingifyPluginHookMeta(meta)
2742
2710
  };
@@ -2759,12 +2727,10 @@ function bindingifyResolveId(args$1) {
2759
2727
  return {
2760
2728
  plugin: async (ctx, specifier, importer, extraOptions) => {
2761
2729
  const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
2762
- 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, {
2763
2731
  ...extraOptions,
2764
- custom: contextResolveOptions?.custom,
2765
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
2766
- };
2767
- 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
+ });
2768
2734
  if (ret == null) return;
2769
2735
  if (ret === false) return {
2770
2736
  id: specifier,
@@ -2835,7 +2801,7 @@ function bindingifyTransform(args$1) {
2835
2801
  });
2836
2802
  return {
2837
2803
  code: ret.code,
2838
- map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, ret.map)),
2804
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
2839
2805
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
2840
2806
  moduleType: ret.moduleType
2841
2807
  };
@@ -2861,7 +2827,7 @@ function bindingifyLoad(args$1) {
2861
2827
  let map = preProcessSourceMap(ret, id);
2862
2828
  return {
2863
2829
  code: ret.code,
2864
- map: bindingifySourcemap(map),
2830
+ map: bindingifySourcemap$1(map),
2865
2831
  moduleType: ret.moduleType,
2866
2832
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
2867
2833
  };
@@ -2957,205 +2923,6 @@ function transformChunkModules(modules) {
2957
2923
  return result;
2958
2924
  }
2959
2925
 
2960
- //#endregion
2961
- //#region src/utils/bindingify-output-options.ts
2962
- function bindingifyOutputOptions(outputOptions) {
2963
- 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;
2964
- let { advancedChunks } = outputOptions;
2965
- if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
2966
- else if (manualChunks != null) advancedChunks = { groups: [{ name(id) {
2967
- return manualChunks(id, {});
2968
- } }] };
2969
- return {
2970
- dir,
2971
- file: file == null ? void 0 : file,
2972
- format: bindingifyFormat(format),
2973
- exports: exports$1,
2974
- hashCharacters,
2975
- sourcemap: bindingifySourcemap$1(sourcemap),
2976
- sourcemapDebugIds,
2977
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
2978
- sourcemapPathTransform,
2979
- banner: bindingifyAddon(banner),
2980
- footer: bindingifyAddon(footer),
2981
- intro: bindingifyAddon(intro),
2982
- outro: bindingifyAddon(outro),
2983
- extend: outputOptions.extend,
2984
- globals,
2985
- esModule,
2986
- name,
2987
- assetFileNames: bindingifyAssetFilenames(assetFileNames),
2988
- entryFileNames,
2989
- chunkFileNames,
2990
- cssEntryFileNames,
2991
- cssChunkFileNames,
2992
- plugins: [],
2993
- minify: outputOptions.minify,
2994
- externalLiveBindings: outputOptions.externalLiveBindings,
2995
- inlineDynamicImports: outputOptions.inlineDynamicImports,
2996
- advancedChunks,
2997
- polyfillRequire: outputOptions.polyfillRequire,
2998
- sanitizeFileName,
2999
- preserveModules,
3000
- virtualDirname,
3001
- legalComments,
3002
- preserveModulesRoot
3003
- };
3004
- }
3005
- function bindingifyAddon(configAddon) {
3006
- return async (chunk) => {
3007
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3008
- return configAddon || "";
3009
- };
3010
- }
3011
- function bindingifyFormat(format) {
3012
- switch (format) {
3013
- case void 0:
3014
- case "es":
3015
- case "esm":
3016
- case "module": return "es";
3017
- case "cjs":
3018
- case "commonjs": return "cjs";
3019
- case "iife": return "iife";
3020
- case "umd": return "umd";
3021
- default: require_misc.unimplemented(`output.format: ${format}`);
3022
- }
3023
- }
3024
- function bindingifySourcemap$1(sourcemap) {
3025
- switch (sourcemap) {
3026
- case true: return "file";
3027
- case "inline": return "inline";
3028
- case false:
3029
- case void 0: return void 0;
3030
- case "hidden": return "hidden";
3031
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3032
- }
3033
- }
3034
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3035
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3036
- }
3037
- function bindingifyAssetFilenames(assetFileNames) {
3038
- if (typeof assetFileNames === "function") return (asset) => {
3039
- return assetFileNames({
3040
- names: asset.names,
3041
- originalFileNames: asset.originalFileNames,
3042
- source: transformAssetSource(asset.source),
3043
- type: "asset"
3044
- });
3045
- };
3046
- return assetFileNames;
3047
- }
3048
-
3049
- //#endregion
3050
- //#region src/options/normalized-output-options.ts
3051
- var NormalizedOutputOptionsImpl = class {
3052
- constructor(inner, outputOptions, normalizedOutputPlugins) {
3053
- this.inner = inner;
3054
- this.outputOptions = outputOptions;
3055
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3056
- }
3057
- get dir() {
3058
- return this.inner.dir ?? void 0;
3059
- }
3060
- get entryFileNames() {
3061
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3062
- }
3063
- get chunkFileNames() {
3064
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3065
- }
3066
- get assetFileNames() {
3067
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3068
- }
3069
- get format() {
3070
- return this.inner.format;
3071
- }
3072
- get exports() {
3073
- return this.inner.exports;
3074
- }
3075
- get sourcemap() {
3076
- return this.inner.sourcemap;
3077
- }
3078
- get cssEntryFileNames() {
3079
- return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3080
- }
3081
- get cssChunkFileNames() {
3082
- return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3083
- }
3084
- get shimMissingExports() {
3085
- return this.inner.shimMissingExports;
3086
- }
3087
- get name() {
3088
- return this.inner.name ?? void 0;
3089
- }
3090
- get file() {
3091
- return this.inner.file ?? void 0;
3092
- }
3093
- get inlineDynamicImports() {
3094
- return this.inner.inlineDynamicImports;
3095
- }
3096
- get externalLiveBindings() {
3097
- return this.inner.externalLiveBindings;
3098
- }
3099
- get banner() {
3100
- return normalizeAddon(this.outputOptions.banner);
3101
- }
3102
- get footer() {
3103
- return normalizeAddon(this.outputOptions.footer);
3104
- }
3105
- get intro() {
3106
- return normalizeAddon(this.outputOptions.intro);
3107
- }
3108
- get outro() {
3109
- return normalizeAddon(this.outputOptions.outro);
3110
- }
3111
- get esModule() {
3112
- return this.inner.esModule;
3113
- }
3114
- get extend() {
3115
- return this.inner.extend;
3116
- }
3117
- get globals() {
3118
- return this.inner.globals || this.outputOptions.globals;
3119
- }
3120
- get hashCharacters() {
3121
- return this.inner.hashCharacters;
3122
- }
3123
- get sourcemapDebugIds() {
3124
- return this.inner.sourcemapDebugIds;
3125
- }
3126
- get sourcemapIgnoreList() {
3127
- return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3128
- }
3129
- get sourcemapPathTransform() {
3130
- return this.outputOptions.sourcemapPathTransform;
3131
- }
3132
- get minify() {
3133
- return this.inner.minify;
3134
- }
3135
- get legalComments() {
3136
- return this.inner.legalComments;
3137
- }
3138
- get polyfillRequire() {
3139
- return this.inner.polyfillRequire;
3140
- }
3141
- get plugins() {
3142
- return this.normalizedOutputPlugins;
3143
- }
3144
- get preserveModules() {
3145
- return this.inner.preserveModules;
3146
- }
3147
- get preserveModulesRoot() {
3148
- return this.inner.preserveModulesRoot;
3149
- }
3150
- get virtualDirname() {
3151
- return this.inner.virtualDirname;
3152
- }
3153
- };
3154
- function normalizeAddon(value) {
3155
- if (typeof value === "function") return value;
3156
- return () => value || "";
3157
- }
3158
-
3159
2926
  //#endregion
3160
2927
  //#region src/utils/transform-to-rollup-output.ts
3161
2928
  function transformToRollupSourceMap(map) {
@@ -3301,7 +3068,7 @@ function collectChangedBundle(changed, bundle) {
3301
3068
  facadeModuleId: item.facadeModuleId || void 0,
3302
3069
  isDynamicEntry: item.isDynamicEntry,
3303
3070
  moduleIds: item.moduleIds,
3304
- map: bindingifySourcemap(item.map),
3071
+ map: bindingifySourcemap$1(item.map),
3305
3072
  sourcemapFilename: item.sourcemapFileName || void 0,
3306
3073
  preliminaryFilename: item.preliminaryFileName
3307
3074
  });
@@ -3321,7 +3088,7 @@ function bindingifyRenderStart(args$1) {
3321
3088
  const { handler, meta } = normalizeHook(hook);
3322
3089
  return {
3323
3090
  plugin: async (ctx, opts) => {
3324
- 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));
3325
3092
  },
3326
3093
  meta: bindingifyPluginHookMeta(meta)
3327
3094
  };
@@ -3333,13 +3100,13 @@ function bindingifyRenderChunk(args$1) {
3333
3100
  return {
3334
3101
  plugin: async (ctx, code, chunk, opts, meta$1) => {
3335
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)])) });
3336
- 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());
3337
3104
  if (ret == null) return;
3338
3105
  if (typeof ret === "string") return { code: ret };
3339
3106
  if (!ret.map) return { code: ret.code };
3340
3107
  return {
3341
3108
  code: ret.code,
3342
- map: bindingifySourcemap(ret.map)
3109
+ map: bindingifySourcemap$1(ret.map)
3343
3110
  };
3344
3111
  },
3345
3112
  meta: bindingifyPluginHookMeta(meta),
@@ -3380,7 +3147,7 @@ function bindingifyGenerateBundle(args$1) {
3380
3147
  };
3381
3148
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3382
3149
  const output = transformToOutputBundle(context, bundle, changed);
3383
- 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);
3384
3151
  return collectChangedBundle(changed, output);
3385
3152
  },
3386
3153
  meta: bindingifyPluginHookMeta(meta)
@@ -3398,7 +3165,7 @@ function bindingifyWriteBundle(args$1) {
3398
3165
  };
3399
3166
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3400
3167
  const output = transformToOutputBundle(context, bundle, changed);
3401
- 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);
3402
3169
  return collectChangedBundle(changed, output);
3403
3170
  },
3404
3171
  meta: bindingifyPluginHookMeta(meta)
@@ -3673,32 +3440,293 @@ function wrapHandlers(plugin) {
3673
3440
  }
3674
3441
 
3675
3442
  //#endregion
3676
- //#region src/plugin/plugin-context-data.ts
3677
- var PluginContextData = class {
3678
- moduleOptionMap = /* @__PURE__ */ new Map();
3679
- resolveOptionsMap = /* @__PURE__ */ new Map();
3680
- loadModulePromiseMap = /* @__PURE__ */ new Map();
3681
- loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
3682
- renderedChunkMeta = null;
3683
- updateModuleOption(id, option) {
3684
- const existing = this.moduleOptionMap.get(id);
3685
- if (existing) {
3686
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3687
- if (option.meta != null) Object.assign(existing.meta, option.meta);
3688
- if (option.invalidate != null) existing.invalidate = option.invalidate;
3689
- } else {
3690
- this.moduleOptionMap.set(id, option);
3691
- return option;
3692
- }
3693
- return existing;
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;
3694
3449
  }
3695
- getModuleOption(id) {
3696
- const option = this.moduleOptionMap.get(id);
3697
- if (!option) {
3698
- const raw = {
3699
- moduleSideEffects: null,
3700
- meta: {}
3701
- };
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
+ };
3584
+ }
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;
3593
+ }
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 || "";
3694
+ }
3695
+
3696
+ //#endregion
3697
+ //#region src/plugin/plugin-context-data.ts
3698
+ var PluginContextData = class {
3699
+ moduleOptionMap = /* @__PURE__ */ new Map();
3700
+ resolveOptionsMap = /* @__PURE__ */ new Map();
3701
+ loadModulePromiseMap = /* @__PURE__ */ new Map();
3702
+ loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
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
+ }
3711
+ updateModuleOption(id, option) {
3712
+ const existing = this.moduleOptionMap.get(id);
3713
+ if (existing) {
3714
+ if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3715
+ if (option.meta != null) Object.assign(existing.meta, option.meta);
3716
+ if (option.invalidate != null) existing.invalidate = option.invalidate;
3717
+ } else {
3718
+ this.moduleOptionMap.set(id, option);
3719
+ return option;
3720
+ }
3721
+ return existing;
3722
+ }
3723
+ getModuleOption(id) {
3724
+ const option = this.moduleOptionMap.get(id);
3725
+ if (!option) {
3726
+ const raw = {
3727
+ moduleSideEffects: null,
3728
+ meta: {}
3729
+ };
3702
3730
  this.moduleOptionMap.set(id, raw);
3703
3731
  return raw;
3704
3732
  }
@@ -3750,6 +3778,14 @@ var PluginContextData = class {
3750
3778
  getRenderChunkMeta() {
3751
3779
  return this.renderedChunkMeta;
3752
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
+ }
3753
3789
  markModuleLoaded(id, _success) {
3754
3790
  const resolve = this.loadModulePromiseResolveFnMap.get(id);
3755
3791
  if (resolve) resolve();
@@ -3775,7 +3811,7 @@ function isReadonlyArray(input) {
3775
3811
  //#endregion
3776
3812
  //#region src/utils/bindingify-input-options.ts
3777
3813
  function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3778
- const pluginContextData = new PluginContextData();
3814
+ const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
3779
3815
  const plugins = rawPlugins.map((plugin) => {
3780
3816
  if ("_parallel" in plugin) return void 0;
3781
3817
  if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
@@ -3950,7 +3986,8 @@ function bindingifyTreeshakeOptions(config) {
3950
3986
  moduleSideEffects: true,
3951
3987
  annotations: config.annotations,
3952
3988
  manualPureFunctions: config.manualPureFunctions,
3953
- unknownGlobalSideEffects: config.unknownGlobalSideEffects
3989
+ unknownGlobalSideEffects: config.unknownGlobalSideEffects,
3990
+ commonjs: config.commonjs
3954
3991
  };
3955
3992
  if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
3956
3993
  else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
@@ -3982,323 +4019,6 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
3982
4019
  };
3983
4020
  }
3984
4021
 
3985
- //#endregion
3986
- //#region src/utils/plugin/index.ts
3987
- const isPluginHookName = function() {
3988
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
3989
- return function isPluginHookName$1(hookName) {
3990
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
3991
- };
3992
- }();
3993
-
3994
- //#endregion
3995
- //#region src/utils/compose-js-plugins.ts
3996
- const unsupportedHookName = [
3997
- "augmentChunkHash",
3998
- "generateBundle",
3999
- "moduleParsed",
4000
- "onLog",
4001
- "options",
4002
- "outputOptions",
4003
- "renderError",
4004
- "renderStart",
4005
- "resolveDynamicImport",
4006
- "writeBundle"
4007
- ];
4008
- const unsupportedHooks = new Set(unsupportedHookName);
4009
- function isUnsupportedHooks(hookName) {
4010
- return unsupportedHooks.has(hookName);
4011
- }
4012
- function createComposedPlugin(plugins) {
4013
- const names = [];
4014
- const batchedHooks = {};
4015
- plugins.forEach((plugin, index) => {
4016
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
4017
- names.push(pluginName);
4018
- t(plugin).forEach((pluginProp) => {
4019
- if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
4020
- if (!isPluginHookName(pluginProp)) return;
4021
- switch (pluginProp) {
4022
- case "buildStart": {
4023
- const handlers = batchedHooks.buildStart ?? [];
4024
- batchedHooks.buildStart = handlers;
4025
- if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
4026
- break;
4027
- }
4028
- case "load": {
4029
- const handlers = batchedHooks.load ?? [];
4030
- batchedHooks.load = handlers;
4031
- if (plugin.load) handlers.push([plugin.load, plugin]);
4032
- break;
4033
- }
4034
- case "transform": {
4035
- const handlers = batchedHooks.transform ?? [];
4036
- batchedHooks.transform = handlers;
4037
- if (plugin.transform) handlers.push([plugin.transform, plugin]);
4038
- break;
4039
- }
4040
- case "resolveId": {
4041
- const handlers = batchedHooks.resolveId ?? [];
4042
- batchedHooks.resolveId = handlers;
4043
- if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
4044
- break;
4045
- }
4046
- case "buildEnd": {
4047
- const handlers = batchedHooks.buildEnd ?? [];
4048
- batchedHooks.buildEnd = handlers;
4049
- if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
4050
- break;
4051
- }
4052
- case "renderChunk": {
4053
- const handlers = batchedHooks.renderChunk ?? [];
4054
- batchedHooks.renderChunk = handlers;
4055
- if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
4056
- break;
4057
- }
4058
- case "banner":
4059
- case "footer":
4060
- case "intro":
4061
- case "outro": {
4062
- const hook = plugin[pluginProp];
4063
- if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
4064
- break;
4065
- }
4066
- case "closeBundle": {
4067
- const handlers = batchedHooks.closeBundle ?? [];
4068
- batchedHooks.closeBundle = handlers;
4069
- if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
4070
- break;
4071
- }
4072
- case "watchChange": {
4073
- const handlers = batchedHooks.watchChange ?? [];
4074
- batchedHooks.watchChange = handlers;
4075
- if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
4076
- break;
4077
- }
4078
- case "closeWatcher": {
4079
- const handlers = batchedHooks.closeWatcher ?? [];
4080
- batchedHooks.closeWatcher = handlers;
4081
- if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
4082
- break;
4083
- }
4084
- default: {}
4085
- }
4086
- });
4087
- });
4088
- const composed = { name: `Composed(${names.join(", ")})` };
4089
- const createFixedPluginResolveFnMap = /* @__PURE__ */ new Map();
4090
- function applyFixedPluginResolveFn(ctx, plugin) {
4091
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
4092
- if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
4093
- return ctx;
4094
- }
4095
- if (batchedHooks.resolveId) {
4096
- const batchedHandlers = batchedHooks.resolveId;
4097
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
4098
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4099
- const [_handler, plugin] = batchedHandlers[handlerIdx];
4100
- const handlerSymbol = handlerSymbols[handlerIdx];
4101
- const createFixedPluginResolveFn = (ctx, resolve) => {
4102
- return (source, importer, rawContextResolveOptions) => {
4103
- const contextResolveOptions = rawContextResolveOptions ?? {};
4104
- if (contextResolveOptions.skipSelf) {
4105
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
4106
- contextResolveOptions.skipSelf = false;
4107
- }
4108
- return resolve(source, importer, contextResolveOptions);
4109
- };
4110
- };
4111
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
4112
- }
4113
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
4114
- const hookResolveIdOptions = rawHookResolveIdOptions;
4115
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
4116
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4117
- const [handler, plugin] = batchedHandlers[handlerIdx];
4118
- const handlerSymbol = handlerSymbols[handlerIdx];
4119
- if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
4120
- const { handler: handlerFn } = normalizeHook(handler);
4121
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
4122
- if (!require_misc.isNullish(result)) return result;
4123
- }
4124
- };
4125
- }
4126
- t(batchedHooks).forEach((hookName) => {
4127
- switch (hookName) {
4128
- case "resolveId": break;
4129
- case "buildStart": {
4130
- if (batchedHooks.buildStart) {
4131
- const batchedHandlers = batchedHooks.buildStart;
4132
- composed.buildStart = async function(options) {
4133
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4134
- const { handler: handlerFn } = normalizeHook(handler);
4135
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
4136
- }));
4137
- };
4138
- }
4139
- break;
4140
- }
4141
- case "load": {
4142
- if (batchedHooks.load) {
4143
- const batchedHandlers = batchedHooks.load;
4144
- composed.load = async function(id) {
4145
- for (const [handler, plugin] of batchedHandlers) {
4146
- const { handler: handlerFn } = normalizeHook(handler);
4147
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
4148
- if (!require_misc.isNullish(result)) return result;
4149
- }
4150
- };
4151
- }
4152
- break;
4153
- }
4154
- case "transform": {
4155
- if (batchedHooks.transform) {
4156
- const batchedHandlers = batchedHooks.transform;
4157
- composed.transform = async function(initialCode, id, moduleType) {
4158
- let code = initialCode;
4159
- let moduleSideEffects = void 0;
4160
- function updateOutput(newCode, newModuleSideEffects) {
4161
- code = newCode;
4162
- moduleSideEffects = newModuleSideEffects ?? void 0;
4163
- }
4164
- for (const [handler, plugin] of batchedHandlers) {
4165
- const { handler: handlerFn } = normalizeHook(handler);
4166
- this.getCombinedSourcemap = () => {
4167
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
4168
- };
4169
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
4170
- if (!require_misc.isNullish(result)) {
4171
- if (typeof result === "string") updateOutput(result);
4172
- else if (result.code) updateOutput(result.code, result.moduleSideEffects);
4173
- }
4174
- }
4175
- return {
4176
- code,
4177
- moduleSideEffects
4178
- };
4179
- };
4180
- }
4181
- break;
4182
- }
4183
- case "buildEnd": {
4184
- if (batchedHooks.buildEnd) {
4185
- const batchedHandlers = batchedHooks.buildEnd;
4186
- composed.buildEnd = async function(err) {
4187
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4188
- const { handler: handlerFn } = normalizeHook(handler);
4189
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
4190
- }));
4191
- };
4192
- }
4193
- break;
4194
- }
4195
- case "renderChunk": {
4196
- if (batchedHooks.renderChunk) {
4197
- const batchedHandlers = batchedHooks.renderChunk;
4198
- composed.renderChunk = async function(code, chunk, options, meta) {
4199
- for (const [handler, plugin] of batchedHandlers) {
4200
- const { handler: handlerFn } = normalizeHook(handler);
4201
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options, meta);
4202
- if (!require_misc.isNullish(result)) return result;
4203
- }
4204
- };
4205
- }
4206
- break;
4207
- }
4208
- case "banner":
4209
- case "footer":
4210
- case "intro":
4211
- case "outro": {
4212
- const hooks = batchedHooks[hookName];
4213
- if (hooks?.length) composed[hookName] = async function(chunk) {
4214
- const ret = [];
4215
- for (const [hook, plugin] of hooks) {
4216
- const { handler } = normalizeHook(hook);
4217
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
4218
- }
4219
- return ret.join("\n");
4220
- };
4221
- break;
4222
- }
4223
- case "closeBundle": {
4224
- if (batchedHooks.closeBundle) {
4225
- const batchedHandlers = batchedHooks.closeBundle;
4226
- composed.closeBundle = async function() {
4227
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4228
- const { handler: handlerFn } = normalizeHook(handler);
4229
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4230
- }));
4231
- };
4232
- }
4233
- break;
4234
- }
4235
- case "watchChange": {
4236
- if (batchedHooks.watchChange) {
4237
- const batchedHandlers = batchedHooks.watchChange;
4238
- composed.watchChange = async function(id, event) {
4239
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4240
- const { handler: handlerFn } = normalizeHook(handler);
4241
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
4242
- }));
4243
- };
4244
- }
4245
- break;
4246
- }
4247
- case "closeWatcher": {
4248
- if (batchedHooks.closeWatcher) {
4249
- const batchedHandlers = batchedHooks.closeWatcher;
4250
- composed.closeWatcher = async function() {
4251
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4252
- const { handler: handlerFn } = normalizeHook(handler);
4253
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4254
- }));
4255
- };
4256
- }
4257
- break;
4258
- }
4259
- default: {}
4260
- }
4261
- });
4262
- return composed;
4263
- }
4264
- function isComposablePlugin(plugin) {
4265
- if (plugin instanceof BuiltinPlugin) return false;
4266
- if ("_parallel" in plugin) return false;
4267
- const hasNotComposablePattern = t(plugin).some((hookName) => {
4268
- if (!isPluginHookName(hookName)) return false;
4269
- const OK_TO_COMPOSE = false;
4270
- if (isUnsupportedHooks(hookName)) return true;
4271
- if (plugin[hookName]) {
4272
- const { meta } = normalizeHook(plugin[hookName]);
4273
- if (meta.order === "pre" || meta.order === "post") return true;
4274
- }
4275
- return OK_TO_COMPOSE;
4276
- });
4277
- if (hasNotComposablePattern) return false;
4278
- return true;
4279
- }
4280
- function composeJsPlugins(plugins) {
4281
- const newPlugins = [];
4282
- const toBeComposed = [];
4283
- plugins.forEach((plugin) => {
4284
- if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
4285
- else {
4286
- if (toBeComposed.length > 0) {
4287
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4288
- else newPlugins.push(toBeComposed[0]);
4289
- toBeComposed.length = 0;
4290
- }
4291
- newPlugins.push(plugin);
4292
- }
4293
- });
4294
- if (toBeComposed.length > 0) {
4295
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4296
- else newPlugins.push(toBeComposed[0]);
4297
- toBeComposed.length = 0;
4298
- }
4299
- return newPlugins;
4300
- }
4301
-
4302
4022
  //#endregion
4303
4023
  //#region src/utils/initialize-parallel-plugins.ts
4304
4024
  async function initializeParallelPlugins(plugins) {
@@ -4375,7 +4095,6 @@ async function createBundlerOptions(inputOptions, outputOptions, watchMode, isCl
4375
4095
  ...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX),
4376
4096
  ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)
4377
4097
  ];
4378
- if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
4379
4098
  const parallelPluginInitResult = await initializeParallelPlugins(plugins);
4380
4099
  try {
4381
4100
  const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
@@ -4693,12 +4412,6 @@ Object.defineProperty(exports, 'buildImportAnalysisPlugin', {
4693
4412
  return buildImportAnalysisPlugin;
4694
4413
  }
4695
4414
  });
4696
- Object.defineProperty(exports, 'composeJsPlugins', {
4697
- enumerable: true,
4698
- get: function () {
4699
- return composeJsPlugins;
4700
- }
4701
- });
4702
4415
  Object.defineProperty(exports, 'createBundlerImpl', {
4703
4416
  enumerable: true,
4704
4417
  get: function () {