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,5 +1,5 @@
1
- import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingHookSideEffects, BindingJsx, BindingLogLevel, BindingPluginOrder, BindingWatcher, ParallelJsPluginRegistry, augmentCodeLocation, error, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst, shutdownAsyncRuntime, startAsyncRuntime } from "./parse-ast-index-DW8kbzjr.mjs";
2
- import { arraify, isNullish, noop, unimplemented, unreachable, unsupported } from "./misc-BN0nse6C.mjs";
1
+ import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingHookSideEffects, BindingJsx, BindingLogLevel, BindingPluginOrder, BindingWatcher, ParallelJsPluginRegistry, augmentCodeLocation, error, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst, shutdownAsyncRuntime, startAsyncRuntime } from "./parse-ast-index-DmWy-n6o.mjs";
2
+ import { arraify, noop, unimplemented, unreachable, unsupported } from "./misc-CQeo-AFx.mjs";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import colors from "ansis";
@@ -8,7 +8,7 @@ import os from "node:os";
8
8
  import { Worker } from "node:worker_threads";
9
9
 
10
10
  //#region package.json
11
- var version = "1.0.0-beta.21";
11
+ var version = "1.0.0-beta.23";
12
12
  var description$1 = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
13
13
 
14
14
  //#endregion
@@ -51,8 +51,8 @@ function reporterPlugin(config) {
51
51
  function manifestPlugin(config) {
52
52
  return new BuiltinPlugin("builtin:manifest", config);
53
53
  }
54
- function wasmHelperPlugin() {
55
- return new BuiltinPlugin("builtin:wasm-helper");
54
+ function wasmHelperPlugin(config) {
55
+ return new BuiltinPlugin("builtin:wasm-helper", config);
56
56
  }
57
57
  function wasmFallbackPlugin() {
58
58
  const builtinPlugin = new BuiltinPlugin("builtin:wasm-fallback");
@@ -1988,7 +1988,8 @@ const ResolveOptionsSchema = strictObject({
1988
1988
  const TreeshakingOptionsSchema = union([boolean(), looseObject({
1989
1989
  annotations: optional(boolean()),
1990
1990
  manualPureFunctions: optional(array(string())),
1991
- unknownGlobalSideEffects: optional(boolean())
1991
+ unknownGlobalSideEffects: optional(boolean()),
1992
+ commonjs: optional(boolean())
1992
1993
  })]);
1993
1994
  const OnLogSchema = pipe(function_(), args(tuple([
1994
1995
  LogLevelSchema,
@@ -2253,41 +2254,9 @@ function getJsonSchema() {
2253
2254
  return toJsonSchema(CliOptionsSchema, { errorMode: "ignore" });
2254
2255
  }
2255
2256
 
2256
- //#endregion
2257
- //#region src/constants/plugin-context.ts
2258
- /**
2259
- * If Composed plugins call `this.resolve` with `skipSelf: true`, the composed plugins will be skipped as a whole.
2260
- * To prevent that, we use this symbol to store the actual caller of `this.resolve` with `skipSelf: true`. And we
2261
- * will modify the skipSelf option to `false` and use this symbol to skip the caller itself in the composed plugins
2262
- * internally.
2263
- */
2264
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
2265
-
2266
- //#endregion
2267
- //#region src/options/normalized-input-options.ts
2268
- var NormalizedInputOptionsImpl = class {
2269
- inner;
2270
- constructor(inner, onLog) {
2271
- this.onLog = onLog;
2272
- this.inner = inner;
2273
- }
2274
- get shimMissingExports() {
2275
- return this.inner.shimMissingExports;
2276
- }
2277
- get input() {
2278
- return this.inner.input;
2279
- }
2280
- get cwd() {
2281
- return this.inner.cwd ?? void 0;
2282
- }
2283
- get platform() {
2284
- return this.inner.platform;
2285
- }
2286
- };
2287
-
2288
2257
  //#endregion
2289
2258
  //#region src/types/sourcemap.ts
2290
- function bindingifySourcemap(map) {
2259
+ function bindingifySourcemap$1(map) {
2291
2260
  if (map == null) return;
2292
2261
  return { inner: typeof map === "string" ? map : {
2293
2262
  file: map.file ?? void 0,
@@ -2403,8 +2372,8 @@ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
2403
2372
  //#endregion
2404
2373
  //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
2405
2374
  function u$1(o, n, a) {
2406
- let t$1 = (r) => o(r, ...n);
2407
- return a === void 0 ? t$1 : Object.assign(t$1, {
2375
+ let t = (r) => o(r, ...n);
2376
+ return a === void 0 ? t : Object.assign(t, {
2408
2377
  lazy: a,
2409
2378
  lazyArgs: n
2410
2379
  });
@@ -2424,18 +2393,12 @@ function u(r, n, o) {
2424
2393
  function d(...r) {
2425
2394
  return u(i, r);
2426
2395
  }
2427
- var i = (r, t$1) => {
2396
+ var i = (r, t) => {
2428
2397
  let a = [[], []];
2429
- for (let [o, e] of r.entries()) t$1(e, o, r) ? a[0].push(e) : a[1].push(e);
2398
+ for (let [o, e] of r.entries()) t(e, o, r) ? a[0].push(e) : a[1].push(e);
2430
2399
  return a;
2431
2400
  };
2432
2401
 
2433
- //#endregion
2434
- //#region ../../node_modules/.pnpm/remeda@2.23.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
2435
- function t(...n) {
2436
- return u(Object.keys, n);
2437
- }
2438
-
2439
2402
  //#endregion
2440
2403
  //#region src/plugin/bindingify-hook-filter.ts
2441
2404
  function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
@@ -2647,9 +2610,14 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
2647
2610
  async resolve(source, importer, options) {
2648
2611
  let receipt = void 0;
2649
2612
  if (options != null) receipt = this.data.saveResolveOptions(options);
2613
+ const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
2614
+ if (key.startsWith("vite:")) (acc ??= {})[key] = value;
2615
+ return acc;
2616
+ }, void 0);
2650
2617
  const res = await this.context.resolve(source, importer, {
2651
2618
  custom: receipt,
2652
- skipSelf: options?.skipSelf
2619
+ skipSelf: options?.skipSelf,
2620
+ vitePluginCustom
2653
2621
  });
2654
2622
  if (receipt != null) this.data.removeSavedResolveOptions(receipt);
2655
2623
  if (res == null) return null;
@@ -2735,7 +2703,7 @@ function bindingifyBuildStart(args$1) {
2735
2703
  const { handler, meta } = normalizeHook(hook);
2736
2704
  return {
2737
2705
  plugin: async (ctx, opts) => {
2738
- 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));
2706
+ 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));
2739
2707
  },
2740
2708
  meta: bindingifyPluginHookMeta(meta)
2741
2709
  };
@@ -2758,12 +2726,10 @@ function bindingifyResolveId(args$1) {
2758
2726
  return {
2759
2727
  plugin: async (ctx, specifier, importer, extraOptions) => {
2760
2728
  const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
2761
- const newExtraOptions = {
2729
+ 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, {
2762
2730
  ...extraOptions,
2763
- custom: contextResolveOptions?.custom,
2764
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
2765
- };
2766
- 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);
2731
+ custom: contextResolveOptions?.custom
2732
+ });
2767
2733
  if (ret == null) return;
2768
2734
  if (ret === false) return {
2769
2735
  id: specifier,
@@ -2834,7 +2800,7 @@ function bindingifyTransform(args$1) {
2834
2800
  });
2835
2801
  return {
2836
2802
  code: ret.code,
2837
- map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, ret.map)),
2803
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
2838
2804
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
2839
2805
  moduleType: ret.moduleType
2840
2806
  };
@@ -2860,7 +2826,7 @@ function bindingifyLoad(args$1) {
2860
2826
  let map = preProcessSourceMap(ret, id);
2861
2827
  return {
2862
2828
  code: ret.code,
2863
- map: bindingifySourcemap(map),
2829
+ map: bindingifySourcemap$1(map),
2864
2830
  moduleType: ret.moduleType,
2865
2831
  sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
2866
2832
  };
@@ -2956,205 +2922,6 @@ function transformChunkModules(modules) {
2956
2922
  return result;
2957
2923
  }
2958
2924
 
2959
- //#endregion
2960
- //#region src/utils/bindingify-output-options.ts
2961
- function bindingifyOutputOptions(outputOptions) {
2962
- const { dir, format, exports, 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;
2963
- let { advancedChunks } = outputOptions;
2964
- if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
2965
- else if (manualChunks != null) advancedChunks = { groups: [{ name(id) {
2966
- return manualChunks(id, {});
2967
- } }] };
2968
- return {
2969
- dir,
2970
- file: file == null ? void 0 : file,
2971
- format: bindingifyFormat(format),
2972
- exports,
2973
- hashCharacters,
2974
- sourcemap: bindingifySourcemap$1(sourcemap),
2975
- sourcemapDebugIds,
2976
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
2977
- sourcemapPathTransform,
2978
- banner: bindingifyAddon(banner),
2979
- footer: bindingifyAddon(footer),
2980
- intro: bindingifyAddon(intro),
2981
- outro: bindingifyAddon(outro),
2982
- extend: outputOptions.extend,
2983
- globals,
2984
- esModule,
2985
- name,
2986
- assetFileNames: bindingifyAssetFilenames(assetFileNames),
2987
- entryFileNames,
2988
- chunkFileNames,
2989
- cssEntryFileNames,
2990
- cssChunkFileNames,
2991
- plugins: [],
2992
- minify: outputOptions.minify,
2993
- externalLiveBindings: outputOptions.externalLiveBindings,
2994
- inlineDynamicImports: outputOptions.inlineDynamicImports,
2995
- advancedChunks,
2996
- polyfillRequire: outputOptions.polyfillRequire,
2997
- sanitizeFileName,
2998
- preserveModules,
2999
- virtualDirname,
3000
- legalComments,
3001
- preserveModulesRoot
3002
- };
3003
- }
3004
- function bindingifyAddon(configAddon) {
3005
- return async (chunk) => {
3006
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3007
- return configAddon || "";
3008
- };
3009
- }
3010
- function bindingifyFormat(format) {
3011
- switch (format) {
3012
- case void 0:
3013
- case "es":
3014
- case "esm":
3015
- case "module": return "es";
3016
- case "cjs":
3017
- case "commonjs": return "cjs";
3018
- case "iife": return "iife";
3019
- case "umd": return "umd";
3020
- default: unimplemented(`output.format: ${format}`);
3021
- }
3022
- }
3023
- function bindingifySourcemap$1(sourcemap) {
3024
- switch (sourcemap) {
3025
- case true: return "file";
3026
- case "inline": return "inline";
3027
- case false:
3028
- case void 0: return void 0;
3029
- case "hidden": return "hidden";
3030
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3031
- }
3032
- }
3033
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3034
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3035
- }
3036
- function bindingifyAssetFilenames(assetFileNames) {
3037
- if (typeof assetFileNames === "function") return (asset) => {
3038
- return assetFileNames({
3039
- names: asset.names,
3040
- originalFileNames: asset.originalFileNames,
3041
- source: transformAssetSource(asset.source),
3042
- type: "asset"
3043
- });
3044
- };
3045
- return assetFileNames;
3046
- }
3047
-
3048
- //#endregion
3049
- //#region src/options/normalized-output-options.ts
3050
- var NormalizedOutputOptionsImpl = class {
3051
- constructor(inner, outputOptions, normalizedOutputPlugins) {
3052
- this.inner = inner;
3053
- this.outputOptions = outputOptions;
3054
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3055
- }
3056
- get dir() {
3057
- return this.inner.dir ?? void 0;
3058
- }
3059
- get entryFileNames() {
3060
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3061
- }
3062
- get chunkFileNames() {
3063
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3064
- }
3065
- get assetFileNames() {
3066
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3067
- }
3068
- get format() {
3069
- return this.inner.format;
3070
- }
3071
- get exports() {
3072
- return this.inner.exports;
3073
- }
3074
- get sourcemap() {
3075
- return this.inner.sourcemap;
3076
- }
3077
- get cssEntryFileNames() {
3078
- return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3079
- }
3080
- get cssChunkFileNames() {
3081
- return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3082
- }
3083
- get shimMissingExports() {
3084
- return this.inner.shimMissingExports;
3085
- }
3086
- get name() {
3087
- return this.inner.name ?? void 0;
3088
- }
3089
- get file() {
3090
- return this.inner.file ?? void 0;
3091
- }
3092
- get inlineDynamicImports() {
3093
- return this.inner.inlineDynamicImports;
3094
- }
3095
- get externalLiveBindings() {
3096
- return this.inner.externalLiveBindings;
3097
- }
3098
- get banner() {
3099
- return normalizeAddon(this.outputOptions.banner);
3100
- }
3101
- get footer() {
3102
- return normalizeAddon(this.outputOptions.footer);
3103
- }
3104
- get intro() {
3105
- return normalizeAddon(this.outputOptions.intro);
3106
- }
3107
- get outro() {
3108
- return normalizeAddon(this.outputOptions.outro);
3109
- }
3110
- get esModule() {
3111
- return this.inner.esModule;
3112
- }
3113
- get extend() {
3114
- return this.inner.extend;
3115
- }
3116
- get globals() {
3117
- return this.inner.globals || this.outputOptions.globals;
3118
- }
3119
- get hashCharacters() {
3120
- return this.inner.hashCharacters;
3121
- }
3122
- get sourcemapDebugIds() {
3123
- return this.inner.sourcemapDebugIds;
3124
- }
3125
- get sourcemapIgnoreList() {
3126
- return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3127
- }
3128
- get sourcemapPathTransform() {
3129
- return this.outputOptions.sourcemapPathTransform;
3130
- }
3131
- get minify() {
3132
- return this.inner.minify;
3133
- }
3134
- get legalComments() {
3135
- return this.inner.legalComments;
3136
- }
3137
- get polyfillRequire() {
3138
- return this.inner.polyfillRequire;
3139
- }
3140
- get plugins() {
3141
- return this.normalizedOutputPlugins;
3142
- }
3143
- get preserveModules() {
3144
- return this.inner.preserveModules;
3145
- }
3146
- get preserveModulesRoot() {
3147
- return this.inner.preserveModulesRoot;
3148
- }
3149
- get virtualDirname() {
3150
- return this.inner.virtualDirname;
3151
- }
3152
- };
3153
- function normalizeAddon(value) {
3154
- if (typeof value === "function") return value;
3155
- return () => value || "";
3156
- }
3157
-
3158
2925
  //#endregion
3159
2926
  //#region src/utils/transform-to-rollup-output.ts
3160
2927
  function transformToRollupSourceMap(map) {
@@ -3300,7 +3067,7 @@ function collectChangedBundle(changed, bundle) {
3300
3067
  facadeModuleId: item.facadeModuleId || void 0,
3301
3068
  isDynamicEntry: item.isDynamicEntry,
3302
3069
  moduleIds: item.moduleIds,
3303
- map: bindingifySourcemap(item.map),
3070
+ map: bindingifySourcemap$1(item.map),
3304
3071
  sourcemapFilename: item.sourcemapFileName || void 0,
3305
3072
  preliminaryFilename: item.preliminaryFileName
3306
3073
  });
@@ -3320,7 +3087,7 @@ function bindingifyRenderStart(args$1) {
3320
3087
  const { handler, meta } = normalizeHook(hook);
3321
3088
  return {
3322
3089
  plugin: async (ctx, opts) => {
3323
- 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));
3090
+ 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));
3324
3091
  },
3325
3092
  meta: bindingifyPluginHookMeta(meta)
3326
3093
  };
@@ -3332,13 +3099,13 @@ function bindingifyRenderChunk(args$1) {
3332
3099
  return {
3333
3100
  plugin: async (ctx, code, chunk, opts, meta$1) => {
3334
3101
  if (args$1.pluginContextData.getRenderChunkMeta() == null) args$1.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
3335
- 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());
3102
+ 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());
3336
3103
  if (ret == null) return;
3337
3104
  if (typeof ret === "string") return { code: ret };
3338
3105
  if (!ret.map) return { code: ret.code };
3339
3106
  return {
3340
3107
  code: ret.code,
3341
- map: bindingifySourcemap(ret.map)
3108
+ map: bindingifySourcemap$1(ret.map)
3342
3109
  };
3343
3110
  },
3344
3111
  meta: bindingifyPluginHookMeta(meta),
@@ -3379,7 +3146,7 @@ function bindingifyGenerateBundle(args$1) {
3379
3146
  };
3380
3147
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3381
3148
  const output = transformToOutputBundle(context, bundle, changed);
3382
- await handler.call(context, new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output, isWrite);
3149
+ await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
3383
3150
  return collectChangedBundle(changed, output);
3384
3151
  },
3385
3152
  meta: bindingifyPluginHookMeta(meta)
@@ -3397,7 +3164,7 @@ function bindingifyWriteBundle(args$1) {
3397
3164
  };
3398
3165
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3399
3166
  const output = transformToOutputBundle(context, bundle, changed);
3400
- await handler.call(context, new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output);
3167
+ await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
3401
3168
  return collectChangedBundle(changed, output);
3402
3169
  },
3403
3170
  meta: bindingifyPluginHookMeta(meta)
@@ -3672,32 +3439,293 @@ function wrapHandlers(plugin) {
3672
3439
  }
3673
3440
 
3674
3441
  //#endregion
3675
- //#region src/plugin/plugin-context-data.ts
3676
- var PluginContextData = class {
3677
- moduleOptionMap = /* @__PURE__ */ new Map();
3678
- resolveOptionsMap = /* @__PURE__ */ new Map();
3679
- loadModulePromiseMap = /* @__PURE__ */ new Map();
3680
- loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
3681
- renderedChunkMeta = null;
3682
- updateModuleOption(id, option) {
3683
- const existing = this.moduleOptionMap.get(id);
3684
- if (existing) {
3685
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3686
- if (option.meta != null) Object.assign(existing.meta, option.meta);
3687
- if (option.invalidate != null) existing.invalidate = option.invalidate;
3688
- } else {
3689
- this.moduleOptionMap.set(id, option);
3690
- return option;
3691
- }
3692
- return existing;
3442
+ //#region src/options/normalized-input-options.ts
3443
+ var NormalizedInputOptionsImpl = class {
3444
+ inner;
3445
+ constructor(inner, onLog) {
3446
+ this.onLog = onLog;
3447
+ this.inner = inner;
3693
3448
  }
3694
- getModuleOption(id) {
3695
- const option = this.moduleOptionMap.get(id);
3696
- if (!option) {
3697
- const raw = {
3698
- moduleSideEffects: null,
3699
- meta: {}
3700
- };
3449
+ get shimMissingExports() {
3450
+ return this.inner.shimMissingExports;
3451
+ }
3452
+ get input() {
3453
+ return this.inner.input;
3454
+ }
3455
+ get cwd() {
3456
+ return this.inner.cwd ?? void 0;
3457
+ }
3458
+ get platform() {
3459
+ return this.inner.platform;
3460
+ }
3461
+ };
3462
+
3463
+ //#endregion
3464
+ //#region src/types/chunking-context.ts
3465
+ var ChunkingContextImpl = class {
3466
+ constructor(context) {
3467
+ this.context = context;
3468
+ }
3469
+ getModuleInfo(moduleId) {
3470
+ const bindingInfo = this.context.getModuleInfo(moduleId);
3471
+ if (bindingInfo) {
3472
+ const info = transformModuleInfo(bindingInfo, {
3473
+ moduleSideEffects: null,
3474
+ meta: {}
3475
+ });
3476
+ return info;
3477
+ }
3478
+ return null;
3479
+ }
3480
+ };
3481
+
3482
+ //#endregion
3483
+ //#region src/utils/bindingify-output-options.ts
3484
+ function bindingifyOutputOptions(outputOptions) {
3485
+ const { dir, format, exports, 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;
3486
+ const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
3487
+ return {
3488
+ dir,
3489
+ file: file == null ? void 0 : file,
3490
+ format: bindingifyFormat(format),
3491
+ exports,
3492
+ hashCharacters,
3493
+ sourcemap: bindingifySourcemap(sourcemap),
3494
+ sourcemapDebugIds,
3495
+ sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
3496
+ sourcemapPathTransform,
3497
+ banner: bindingifyAddon(banner),
3498
+ footer: bindingifyAddon(footer),
3499
+ intro: bindingifyAddon(intro),
3500
+ outro: bindingifyAddon(outro),
3501
+ extend: outputOptions.extend,
3502
+ globals,
3503
+ esModule,
3504
+ name,
3505
+ assetFileNames: bindingifyAssetFilenames(assetFileNames),
3506
+ entryFileNames,
3507
+ chunkFileNames,
3508
+ cssEntryFileNames,
3509
+ cssChunkFileNames,
3510
+ plugins: [],
3511
+ minify: outputOptions.minify,
3512
+ externalLiveBindings: outputOptions.externalLiveBindings,
3513
+ inlineDynamicImports: outputOptions.inlineDynamicImports,
3514
+ advancedChunks,
3515
+ polyfillRequire: outputOptions.polyfillRequire,
3516
+ sanitizeFileName,
3517
+ preserveModules,
3518
+ virtualDirname,
3519
+ legalComments,
3520
+ preserveModulesRoot
3521
+ };
3522
+ }
3523
+ function bindingifyAddon(configAddon) {
3524
+ return async (chunk) => {
3525
+ if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3526
+ return configAddon || "";
3527
+ };
3528
+ }
3529
+ function bindingifyFormat(format) {
3530
+ switch (format) {
3531
+ case void 0:
3532
+ case "es":
3533
+ case "esm":
3534
+ case "module": return "es";
3535
+ case "cjs":
3536
+ case "commonjs": return "cjs";
3537
+ case "iife": return "iife";
3538
+ case "umd": return "umd";
3539
+ default: unimplemented(`output.format: ${format}`);
3540
+ }
3541
+ }
3542
+ function bindingifySourcemap(sourcemap) {
3543
+ switch (sourcemap) {
3544
+ case true: return "file";
3545
+ case "inline": return "inline";
3546
+ case false:
3547
+ case void 0: return void 0;
3548
+ case "hidden": return "hidden";
3549
+ default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3550
+ }
3551
+ }
3552
+ function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3553
+ return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3554
+ }
3555
+ function bindingifyAssetFilenames(assetFileNames) {
3556
+ if (typeof assetFileNames === "function") return (asset) => {
3557
+ return assetFileNames({
3558
+ names: asset.names,
3559
+ originalFileNames: asset.originalFileNames,
3560
+ source: transformAssetSource(asset.source),
3561
+ type: "asset"
3562
+ });
3563
+ };
3564
+ return assetFileNames;
3565
+ }
3566
+ function bindingifyAdvancedChunks(advancedChunks, manualChunks) {
3567
+ if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
3568
+ else if (manualChunks != null) advancedChunks = { groups: [{ name(moduleId, ctx) {
3569
+ return manualChunks(moduleId, { getModuleInfo: (id) => ctx.getModuleInfo(id) });
3570
+ } }] };
3571
+ if (advancedChunks == null) return void 0;
3572
+ const { groups,...restAdvancedChunks } = advancedChunks;
3573
+ return {
3574
+ ...restAdvancedChunks,
3575
+ groups: groups?.map((group) => {
3576
+ const { name,...restGroup } = group;
3577
+ return {
3578
+ ...restGroup,
3579
+ name: typeof name === "function" ? (id, ctx) => name(id, new ChunkingContextImpl(ctx)) : name
3580
+ };
3581
+ })
3582
+ };
3583
+ }
3584
+
3585
+ //#endregion
3586
+ //#region src/options/normalized-output-options.ts
3587
+ var NormalizedOutputOptionsImpl = class {
3588
+ constructor(inner, outputOptions, normalizedOutputPlugins) {
3589
+ this.inner = inner;
3590
+ this.outputOptions = outputOptions;
3591
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
3592
+ }
3593
+ get dir() {
3594
+ return this.inner.dir ?? void 0;
3595
+ }
3596
+ get entryFileNames() {
3597
+ return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3598
+ }
3599
+ get chunkFileNames() {
3600
+ return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3601
+ }
3602
+ get assetFileNames() {
3603
+ return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3604
+ }
3605
+ get format() {
3606
+ return this.inner.format;
3607
+ }
3608
+ get exports() {
3609
+ return this.inner.exports;
3610
+ }
3611
+ get sourcemap() {
3612
+ return this.inner.sourcemap;
3613
+ }
3614
+ get cssEntryFileNames() {
3615
+ return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3616
+ }
3617
+ get cssChunkFileNames() {
3618
+ return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3619
+ }
3620
+ get shimMissingExports() {
3621
+ return this.inner.shimMissingExports;
3622
+ }
3623
+ get name() {
3624
+ return this.inner.name ?? void 0;
3625
+ }
3626
+ get file() {
3627
+ return this.inner.file ?? void 0;
3628
+ }
3629
+ get inlineDynamicImports() {
3630
+ return this.inner.inlineDynamicImports;
3631
+ }
3632
+ get externalLiveBindings() {
3633
+ return this.inner.externalLiveBindings;
3634
+ }
3635
+ get banner() {
3636
+ return normalizeAddon(this.outputOptions.banner);
3637
+ }
3638
+ get footer() {
3639
+ return normalizeAddon(this.outputOptions.footer);
3640
+ }
3641
+ get intro() {
3642
+ return normalizeAddon(this.outputOptions.intro);
3643
+ }
3644
+ get outro() {
3645
+ return normalizeAddon(this.outputOptions.outro);
3646
+ }
3647
+ get esModule() {
3648
+ return this.inner.esModule;
3649
+ }
3650
+ get extend() {
3651
+ return this.inner.extend;
3652
+ }
3653
+ get globals() {
3654
+ return this.inner.globals || this.outputOptions.globals;
3655
+ }
3656
+ get hashCharacters() {
3657
+ return this.inner.hashCharacters;
3658
+ }
3659
+ get sourcemapDebugIds() {
3660
+ return this.inner.sourcemapDebugIds;
3661
+ }
3662
+ get sourcemapIgnoreList() {
3663
+ return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3664
+ }
3665
+ get sourcemapPathTransform() {
3666
+ return this.outputOptions.sourcemapPathTransform;
3667
+ }
3668
+ get minify() {
3669
+ return this.inner.minify;
3670
+ }
3671
+ get legalComments() {
3672
+ return this.inner.legalComments;
3673
+ }
3674
+ get polyfillRequire() {
3675
+ return this.inner.polyfillRequire;
3676
+ }
3677
+ get plugins() {
3678
+ return this.normalizedOutputPlugins;
3679
+ }
3680
+ get preserveModules() {
3681
+ return this.inner.preserveModules;
3682
+ }
3683
+ get preserveModulesRoot() {
3684
+ return this.inner.preserveModulesRoot;
3685
+ }
3686
+ get virtualDirname() {
3687
+ return this.inner.virtualDirname;
3688
+ }
3689
+ };
3690
+ function normalizeAddon(value) {
3691
+ if (typeof value === "function") return value;
3692
+ return () => value || "";
3693
+ }
3694
+
3695
+ //#endregion
3696
+ //#region src/plugin/plugin-context-data.ts
3697
+ var PluginContextData = class {
3698
+ moduleOptionMap = /* @__PURE__ */ new Map();
3699
+ resolveOptionsMap = /* @__PURE__ */ new Map();
3700
+ loadModulePromiseMap = /* @__PURE__ */ new Map();
3701
+ loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
3702
+ renderedChunkMeta = null;
3703
+ normalizedInputOptions = null;
3704
+ normalizedOutputOptions = null;
3705
+ constructor(onLog, outputOptions, normalizedOutputPlugins) {
3706
+ this.onLog = onLog;
3707
+ this.outputOptions = outputOptions;
3708
+ this.normalizedOutputPlugins = normalizedOutputPlugins;
3709
+ }
3710
+ updateModuleOption(id, option) {
3711
+ const existing = this.moduleOptionMap.get(id);
3712
+ if (existing) {
3713
+ if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3714
+ if (option.meta != null) Object.assign(existing.meta, option.meta);
3715
+ if (option.invalidate != null) existing.invalidate = option.invalidate;
3716
+ } else {
3717
+ this.moduleOptionMap.set(id, option);
3718
+ return option;
3719
+ }
3720
+ return existing;
3721
+ }
3722
+ getModuleOption(id) {
3723
+ const option = this.moduleOptionMap.get(id);
3724
+ if (!option) {
3725
+ const raw = {
3726
+ moduleSideEffects: null,
3727
+ meta: {}
3728
+ };
3701
3729
  this.moduleOptionMap.set(id, raw);
3702
3730
  return raw;
3703
3731
  }
@@ -3749,6 +3777,14 @@ var PluginContextData = class {
3749
3777
  getRenderChunkMeta() {
3750
3778
  return this.renderedChunkMeta;
3751
3779
  }
3780
+ getInputOptions(opts) {
3781
+ this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
3782
+ return this.normalizedInputOptions;
3783
+ }
3784
+ getOutputOptions(opts) {
3785
+ this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
3786
+ return this.normalizedOutputOptions;
3787
+ }
3752
3788
  markModuleLoaded(id, _success) {
3753
3789
  const resolve = this.loadModulePromiseResolveFnMap.get(id);
3754
3790
  if (resolve) resolve();
@@ -3774,7 +3810,7 @@ function isReadonlyArray(input) {
3774
3810
  //#endregion
3775
3811
  //#region src/utils/bindingify-input-options.ts
3776
3812
  function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3777
- const pluginContextData = new PluginContextData();
3813
+ const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
3778
3814
  const plugins = rawPlugins.map((plugin) => {
3779
3815
  if ("_parallel" in plugin) return void 0;
3780
3816
  if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
@@ -3949,7 +3985,8 @@ function bindingifyTreeshakeOptions(config) {
3949
3985
  moduleSideEffects: true,
3950
3986
  annotations: config.annotations,
3951
3987
  manualPureFunctions: config.manualPureFunctions,
3952
- unknownGlobalSideEffects: config.unknownGlobalSideEffects
3988
+ unknownGlobalSideEffects: config.unknownGlobalSideEffects,
3989
+ commonjs: config.commonjs
3953
3990
  };
3954
3991
  if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
3955
3992
  else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
@@ -3981,323 +4018,6 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
3981
4018
  };
3982
4019
  }
3983
4020
 
3984
- //#endregion
3985
- //#region src/utils/plugin/index.ts
3986
- const isPluginHookName = function() {
3987
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
3988
- return function isPluginHookName$1(hookName) {
3989
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
3990
- };
3991
- }();
3992
-
3993
- //#endregion
3994
- //#region src/utils/compose-js-plugins.ts
3995
- const unsupportedHookName = [
3996
- "augmentChunkHash",
3997
- "generateBundle",
3998
- "moduleParsed",
3999
- "onLog",
4000
- "options",
4001
- "outputOptions",
4002
- "renderError",
4003
- "renderStart",
4004
- "resolveDynamicImport",
4005
- "writeBundle"
4006
- ];
4007
- const unsupportedHooks = new Set(unsupportedHookName);
4008
- function isUnsupportedHooks(hookName) {
4009
- return unsupportedHooks.has(hookName);
4010
- }
4011
- function createComposedPlugin(plugins) {
4012
- const names = [];
4013
- const batchedHooks = {};
4014
- plugins.forEach((plugin, index) => {
4015
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
4016
- names.push(pluginName);
4017
- t(plugin).forEach((pluginProp) => {
4018
- if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
4019
- if (!isPluginHookName(pluginProp)) return;
4020
- switch (pluginProp) {
4021
- case "buildStart": {
4022
- const handlers = batchedHooks.buildStart ?? [];
4023
- batchedHooks.buildStart = handlers;
4024
- if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
4025
- break;
4026
- }
4027
- case "load": {
4028
- const handlers = batchedHooks.load ?? [];
4029
- batchedHooks.load = handlers;
4030
- if (plugin.load) handlers.push([plugin.load, plugin]);
4031
- break;
4032
- }
4033
- case "transform": {
4034
- const handlers = batchedHooks.transform ?? [];
4035
- batchedHooks.transform = handlers;
4036
- if (plugin.transform) handlers.push([plugin.transform, plugin]);
4037
- break;
4038
- }
4039
- case "resolveId": {
4040
- const handlers = batchedHooks.resolveId ?? [];
4041
- batchedHooks.resolveId = handlers;
4042
- if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
4043
- break;
4044
- }
4045
- case "buildEnd": {
4046
- const handlers = batchedHooks.buildEnd ?? [];
4047
- batchedHooks.buildEnd = handlers;
4048
- if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
4049
- break;
4050
- }
4051
- case "renderChunk": {
4052
- const handlers = batchedHooks.renderChunk ?? [];
4053
- batchedHooks.renderChunk = handlers;
4054
- if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
4055
- break;
4056
- }
4057
- case "banner":
4058
- case "footer":
4059
- case "intro":
4060
- case "outro": {
4061
- const hook = plugin[pluginProp];
4062
- if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
4063
- break;
4064
- }
4065
- case "closeBundle": {
4066
- const handlers = batchedHooks.closeBundle ?? [];
4067
- batchedHooks.closeBundle = handlers;
4068
- if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
4069
- break;
4070
- }
4071
- case "watchChange": {
4072
- const handlers = batchedHooks.watchChange ?? [];
4073
- batchedHooks.watchChange = handlers;
4074
- if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
4075
- break;
4076
- }
4077
- case "closeWatcher": {
4078
- const handlers = batchedHooks.closeWatcher ?? [];
4079
- batchedHooks.closeWatcher = handlers;
4080
- if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
4081
- break;
4082
- }
4083
- default: {}
4084
- }
4085
- });
4086
- });
4087
- const composed = { name: `Composed(${names.join(", ")})` };
4088
- const createFixedPluginResolveFnMap = /* @__PURE__ */ new Map();
4089
- function applyFixedPluginResolveFn(ctx, plugin) {
4090
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
4091
- if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
4092
- return ctx;
4093
- }
4094
- if (batchedHooks.resolveId) {
4095
- const batchedHandlers = batchedHooks.resolveId;
4096
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
4097
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4098
- const [_handler, plugin] = batchedHandlers[handlerIdx];
4099
- const handlerSymbol = handlerSymbols[handlerIdx];
4100
- const createFixedPluginResolveFn = (ctx, resolve) => {
4101
- return (source, importer, rawContextResolveOptions) => {
4102
- const contextResolveOptions = rawContextResolveOptions ?? {};
4103
- if (contextResolveOptions.skipSelf) {
4104
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
4105
- contextResolveOptions.skipSelf = false;
4106
- }
4107
- return resolve(source, importer, contextResolveOptions);
4108
- };
4109
- };
4110
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
4111
- }
4112
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
4113
- const hookResolveIdOptions = rawHookResolveIdOptions;
4114
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
4115
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4116
- const [handler, plugin] = batchedHandlers[handlerIdx];
4117
- const handlerSymbol = handlerSymbols[handlerIdx];
4118
- if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
4119
- const { handler: handlerFn } = normalizeHook(handler);
4120
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
4121
- if (!isNullish(result)) return result;
4122
- }
4123
- };
4124
- }
4125
- t(batchedHooks).forEach((hookName) => {
4126
- switch (hookName) {
4127
- case "resolveId": break;
4128
- case "buildStart": {
4129
- if (batchedHooks.buildStart) {
4130
- const batchedHandlers = batchedHooks.buildStart;
4131
- composed.buildStart = async function(options) {
4132
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4133
- const { handler: handlerFn } = normalizeHook(handler);
4134
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
4135
- }));
4136
- };
4137
- }
4138
- break;
4139
- }
4140
- case "load": {
4141
- if (batchedHooks.load) {
4142
- const batchedHandlers = batchedHooks.load;
4143
- composed.load = async function(id) {
4144
- for (const [handler, plugin] of batchedHandlers) {
4145
- const { handler: handlerFn } = normalizeHook(handler);
4146
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
4147
- if (!isNullish(result)) return result;
4148
- }
4149
- };
4150
- }
4151
- break;
4152
- }
4153
- case "transform": {
4154
- if (batchedHooks.transform) {
4155
- const batchedHandlers = batchedHooks.transform;
4156
- composed.transform = async function(initialCode, id, moduleType) {
4157
- let code = initialCode;
4158
- let moduleSideEffects = void 0;
4159
- function updateOutput(newCode, newModuleSideEffects) {
4160
- code = newCode;
4161
- moduleSideEffects = newModuleSideEffects ?? void 0;
4162
- }
4163
- for (const [handler, plugin] of batchedHandlers) {
4164
- const { handler: handlerFn } = normalizeHook(handler);
4165
- this.getCombinedSourcemap = () => {
4166
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
4167
- };
4168
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
4169
- if (!isNullish(result)) {
4170
- if (typeof result === "string") updateOutput(result);
4171
- else if (result.code) updateOutput(result.code, result.moduleSideEffects);
4172
- }
4173
- }
4174
- return {
4175
- code,
4176
- moduleSideEffects
4177
- };
4178
- };
4179
- }
4180
- break;
4181
- }
4182
- case "buildEnd": {
4183
- if (batchedHooks.buildEnd) {
4184
- const batchedHandlers = batchedHooks.buildEnd;
4185
- composed.buildEnd = async function(err) {
4186
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4187
- const { handler: handlerFn } = normalizeHook(handler);
4188
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
4189
- }));
4190
- };
4191
- }
4192
- break;
4193
- }
4194
- case "renderChunk": {
4195
- if (batchedHooks.renderChunk) {
4196
- const batchedHandlers = batchedHooks.renderChunk;
4197
- composed.renderChunk = async function(code, chunk, options, meta) {
4198
- for (const [handler, plugin] of batchedHandlers) {
4199
- const { handler: handlerFn } = normalizeHook(handler);
4200
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options, meta);
4201
- if (!isNullish(result)) return result;
4202
- }
4203
- };
4204
- }
4205
- break;
4206
- }
4207
- case "banner":
4208
- case "footer":
4209
- case "intro":
4210
- case "outro": {
4211
- const hooks = batchedHooks[hookName];
4212
- if (hooks?.length) composed[hookName] = async function(chunk) {
4213
- const ret = [];
4214
- for (const [hook, plugin] of hooks) {
4215
- const { handler } = normalizeHook(hook);
4216
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
4217
- }
4218
- return ret.join("\n");
4219
- };
4220
- break;
4221
- }
4222
- case "closeBundle": {
4223
- if (batchedHooks.closeBundle) {
4224
- const batchedHandlers = batchedHooks.closeBundle;
4225
- composed.closeBundle = async function() {
4226
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4227
- const { handler: handlerFn } = normalizeHook(handler);
4228
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4229
- }));
4230
- };
4231
- }
4232
- break;
4233
- }
4234
- case "watchChange": {
4235
- if (batchedHooks.watchChange) {
4236
- const batchedHandlers = batchedHooks.watchChange;
4237
- composed.watchChange = async function(id, event) {
4238
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4239
- const { handler: handlerFn } = normalizeHook(handler);
4240
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
4241
- }));
4242
- };
4243
- }
4244
- break;
4245
- }
4246
- case "closeWatcher": {
4247
- if (batchedHooks.closeWatcher) {
4248
- const batchedHandlers = batchedHooks.closeWatcher;
4249
- composed.closeWatcher = async function() {
4250
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4251
- const { handler: handlerFn } = normalizeHook(handler);
4252
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4253
- }));
4254
- };
4255
- }
4256
- break;
4257
- }
4258
- default: {}
4259
- }
4260
- });
4261
- return composed;
4262
- }
4263
- function isComposablePlugin(plugin) {
4264
- if (plugin instanceof BuiltinPlugin) return false;
4265
- if ("_parallel" in plugin) return false;
4266
- const hasNotComposablePattern = t(plugin).some((hookName) => {
4267
- if (!isPluginHookName(hookName)) return false;
4268
- const OK_TO_COMPOSE = false;
4269
- if (isUnsupportedHooks(hookName)) return true;
4270
- if (plugin[hookName]) {
4271
- const { meta } = normalizeHook(plugin[hookName]);
4272
- if (meta.order === "pre" || meta.order === "post") return true;
4273
- }
4274
- return OK_TO_COMPOSE;
4275
- });
4276
- if (hasNotComposablePattern) return false;
4277
- return true;
4278
- }
4279
- function composeJsPlugins(plugins) {
4280
- const newPlugins = [];
4281
- const toBeComposed = [];
4282
- plugins.forEach((plugin) => {
4283
- if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
4284
- else {
4285
- if (toBeComposed.length > 0) {
4286
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4287
- else newPlugins.push(toBeComposed[0]);
4288
- toBeComposed.length = 0;
4289
- }
4290
- newPlugins.push(plugin);
4291
- }
4292
- });
4293
- if (toBeComposed.length > 0) {
4294
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4295
- else newPlugins.push(toBeComposed[0]);
4296
- toBeComposed.length = 0;
4297
- }
4298
- return newPlugins;
4299
- }
4300
-
4301
4021
  //#endregion
4302
4022
  //#region src/utils/initialize-parallel-plugins.ts
4303
4023
  async function initializeParallelPlugins(plugins) {
@@ -4374,7 +4094,6 @@ async function createBundlerOptions(inputOptions, outputOptions, watchMode, isCl
4374
4094
  ...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX),
4375
4095
  ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)
4376
4096
  ];
4377
- if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
4378
4097
  const parallelPluginInitResult = await initializeParallelPlugins(plugins);
4379
4098
  try {
4380
4099
  const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
@@ -4644,4 +4363,4 @@ function defineConfig(config) {
4644
4363
  const VERSION = version;
4645
4364
 
4646
4365
  //#endregion
4647
- export { BuiltinPlugin, PluginContextData, PluginDriver, VERSION, assetPlugin, bindingifyPlugin, build, buildImportAnalysisPlugin, composeJsPlugins, createBundlerImpl, defineConfig, description$1 as description, dynamicImportVarsPlugin, getInputCliKeys, getJsonSchema, getOutputCliKeys, handleOutputErrors, importGlobPlugin, isolatedDeclarationPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, moduleFederationPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, reporterPlugin, rolldown, validateCliOptions, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch, webWorkerPostPlugin };
4366
+ export { BuiltinPlugin, PluginContextData, PluginDriver, VERSION, assetPlugin, bindingifyPlugin, build, buildImportAnalysisPlugin, createBundlerImpl, defineConfig, description$1 as description, dynamicImportVarsPlugin, getInputCliKeys, getJsonSchema, getOutputCliKeys, handleOutputErrors, importGlobPlugin, isolatedDeclarationPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, moduleFederationPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, reporterPlugin, rolldown, validateCliOptions, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch, webWorkerPostPlugin };