rolldown 0.12.2-snapshot-3ea6797-20240810002921 → 0.12.2-snapshot-e65c643-20240811191124

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.
@@ -449,36 +449,12 @@ var require_binding = __commonJSMin((exports, module) => {
449
449
  module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
450
450
  module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
451
451
  module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
452
+ module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
452
453
  module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
453
454
  module.exports.registerPlugins = nativeBinding.registerPlugins;
454
455
  module.exports.transform = nativeBinding.transform;
455
456
  });
456
457
 
457
- //#endregion
458
- //#region src/utils/normalize-hook.ts
459
- function normalizeHook(hook) {
460
- if (typeof hook === "function") {
461
- return [hook, {}];
462
- }
463
- if (typeof hook === "object" && hook !== null) {
464
- const { handler: handler,...options } = hook;
465
- return [handler, options];
466
- }
467
- return [hook, {}];
468
- }
469
-
470
- //#endregion
471
- //#region src/utils/transform-sourcemap.ts
472
- function isEmptySourcemapFiled(array) {
473
- if (!array) {
474
- return true;
475
- }
476
- if (array.length === 0 || !array[0]) {
477
- return true;
478
- }
479
- return false;
480
- }
481
-
482
458
  //#endregion
483
459
  //#region src/utils/misc.ts
484
460
  function arraify(value) {
@@ -493,6 +469,12 @@ function unimplemented(info) {
493
469
  }
494
470
  throw new Error("unimplemented");
495
471
  }
472
+ function unreachable(info) {
473
+ if (info) {
474
+ throw new Error(`unreachable: ${info}`);
475
+ }
476
+ throw new Error("unreachable");
477
+ }
496
478
  function unsupported(info) {
497
479
  return () => {
498
480
  throw new Error(`UNSUPPORTED: ${info}`);
@@ -500,6 +482,38 @@ function unsupported(info) {
500
482
  }
501
483
  function noop(..._args) {}
502
484
 
485
+ //#endregion
486
+ //#region src/utils/normalize-hook.ts
487
+ function normalizeHook(hook) {
488
+ if (typeof hook === "function" || typeof hook === "string") {
489
+ return {
490
+ handler: hook,
491
+ options: {},
492
+ meta: {}
493
+ };
494
+ } else if (typeof hook === "object" && hook !== null) {
495
+ const { handler: handler, order: order,...options } = hook;
496
+ return {
497
+ handler,
498
+ options,
499
+ meta: {order}
500
+ };
501
+ }
502
+ unreachable("Invalid hook type");
503
+ }
504
+
505
+ //#endregion
506
+ //#region src/utils/transform-sourcemap.ts
507
+ function isEmptySourcemapFiled(array) {
508
+ if (!array) {
509
+ return true;
510
+ }
511
+ if (array.length === 0 || !array[0]) {
512
+ return true;
513
+ }
514
+ return false;
515
+ }
516
+
503
517
  //#endregion
504
518
  //#region src/utils/transform-module-info.ts
505
519
  function transformModuleInfo(info, option) {
@@ -801,47 +815,63 @@ class TransformPluginContext extends PluginContext {
801
815
 
802
816
  //#endregion
803
817
  //#region src/utils/transform-side-effects.ts
804
- var import_binding = __toESM(require_binding());
818
+ var import_binding$1 = __toESM(require_binding());
805
819
  function bindingifySideEffects(sideEffects) {
806
820
  switch (sideEffects) {
807
- case true: return import_binding.BindingHookSideEffects.True;
808
- case false: return import_binding.BindingHookSideEffects.False;
809
- case "no-treeshake": return import_binding.BindingHookSideEffects.NoTreeshake;
821
+ case true: return import_binding$1.BindingHookSideEffects.True;
822
+ case false: return import_binding$1.BindingHookSideEffects.False;
823
+ case "no-treeshake": return import_binding$1.BindingHookSideEffects.NoTreeshake;
810
824
  case null:
811
825
  case undefined: return undefined;
812
826
  default: throw new Error(`Unexpected side effects: ${sideEffects}`);
813
827
  }
814
828
  }
815
829
 
830
+ //#endregion
831
+ //#region src/plugin/bindingify-plugin-hook-meta.ts
832
+ var import_binding = __toESM(require_binding());
833
+ function bindingifyPluginHookMeta(options) {
834
+ return {order: bindingPluginOrder(options.order)};
835
+ }
836
+ function bindingPluginOrder(order) {
837
+ switch (order) {
838
+ case "post": return import_binding.BindingPluginOrder.Post;
839
+ case "pre": return import_binding.BindingPluginOrder.Pre;
840
+ case null:
841
+ case undefined: return undefined;
842
+ default: throw new Error(`Unknown plugin order: ${order}`);
843
+ }
844
+ }
845
+
816
846
  //#endregion
817
847
  //#region src/plugin/bindingify-build-hooks.ts
818
848
  function bindingifyBuildStart(plugin, options, pluginContextData) {
819
849
  const hook = plugin.buildStart;
820
850
  if (!hook) {
821
- return undefined;
851
+ return [undefined, undefined];
822
852
  }
823
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
824
- return async (ctx) => {
853
+ const { handler: handler, meta: meta } = normalizeHook(hook);
854
+ return [async (ctx) => {
825
855
  await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), options);
826
- };
856
+ }, bindingifyPluginHookMeta(meta),];
827
857
  }
828
858
  function bindingifyBuildEnd(plugin, options, pluginContextData) {
829
859
  const hook = plugin.buildEnd;
830
860
  if (!hook) {
831
- return undefined;
861
+ return [undefined, undefined];
832
862
  }
833
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
834
- return async (ctx, err) => {
863
+ const { handler: handler, meta: meta } = normalizeHook(hook);
864
+ return [async (ctx, err) => {
835
865
  await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), err ? new Error(err) : undefined);
836
- };
866
+ }, bindingifyPluginHookMeta(meta),];
837
867
  }
838
868
  function bindingifyResolveId(plugin, options, pluginContextData) {
839
869
  const hook = plugin.resolveId;
840
870
  if (!hook) {
841
- return undefined;
871
+ return [undefined, undefined];
842
872
  }
843
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
844
- return async (ctx, specifier, importer, extraOptions) => {
873
+ const { handler: handler, meta: meta } = normalizeHook(hook);
874
+ return [async (ctx, specifier, importer, extraOptions) => {
845
875
  const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined, {
846
876
  ...extraOptions,
847
877
  custom: typeof extraOptions.custom === "number" ? pluginContextData.getResolveCustom(extraOptions.custom) : undefined
@@ -864,15 +894,15 @@ function bindingifyResolveId(plugin, options, pluginContextData) {
864
894
  moduleSideEffects: ret.moduleSideEffects || null
865
895
  });
866
896
  return result;
867
- };
897
+ }, bindingifyPluginHookMeta(meta),];
868
898
  }
869
899
  function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
870
900
  const hook = plugin.resolveDynamicImport;
871
901
  if (!hook) {
872
- return undefined;
902
+ return [undefined, undefined];
873
903
  }
874
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
875
- return async (ctx, specifier, importer) => {
904
+ const { handler: handler, meta: meta } = normalizeHook(hook);
905
+ return [async (ctx, specifier, importer) => {
876
906
  const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined);
877
907
  if (ret == false || ret == null) {
878
908
  return;
@@ -892,16 +922,16 @@ function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
892
922
  moduleSideEffects: ret.moduleSideEffects || null
893
923
  });
894
924
  return result;
895
- };
925
+ }, bindingifyPluginHookMeta(meta),];
896
926
  }
897
927
  function bindingifyTransform(plugin, options, pluginContextData) {
898
928
  const hook = plugin.transform;
899
929
  if (!hook) {
900
- return undefined;
930
+ return [undefined, undefined];
901
931
  }
902
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
903
- return async (ctx, code, id, meta) => {
904
- const ret = await handler.call(new TransformPluginContext(options, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id, meta);
932
+ const { handler: handler, meta: meta } = normalizeHook(hook);
933
+ return [async (ctx, code, id, meta$1) => {
934
+ const ret = await handler.call(new TransformPluginContext(options, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id, meta$1);
905
935
  if (ret == null) {
906
936
  return undefined;
907
937
  }
@@ -918,15 +948,15 @@ function bindingifyTransform(plugin, options, pluginContextData) {
918
948
  sideEffects: bindingifySideEffects(ret.moduleSideEffects),
919
949
  moduleType: ret.moduleType
920
950
  };
921
- };
951
+ }, bindingifyPluginHookMeta(meta),];
922
952
  }
923
953
  function bindingifyLoad(plugin, options, pluginContextData) {
924
954
  const hook = plugin.load;
925
955
  if (!hook) {
926
- return undefined;
956
+ return [undefined, undefined];
927
957
  }
928
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
929
- return async (ctx, id) => {
958
+ const { handler: handler, meta: meta } = normalizeHook(hook);
959
+ return [async (ctx, id) => {
930
960
  const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), id);
931
961
  if (ret == null) {
932
962
  return;
@@ -955,17 +985,17 @@ function bindingifyLoad(plugin, options, pluginContextData) {
955
985
  moduleSideEffects: ret.moduleSideEffects || null
956
986
  });
957
987
  return result;
958
- };
988
+ }, bindingifyPluginHookMeta(meta),];
959
989
  }
960
990
  function bindingifyModuleParsed(plugin, options, pluginContextData) {
961
991
  const hook = plugin.moduleParsed;
962
992
  if (!hook) {
963
- return undefined;
993
+ return [undefined, undefined];
964
994
  }
965
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
966
- return async (ctx, moduleInfo) => {
995
+ const { handler: handler, meta: meta } = normalizeHook(hook);
996
+ return [async (ctx, moduleInfo) => {
967
997
  await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), transformModuleInfo(moduleInfo, pluginContextData.moduleOptionMap.get(moduleInfo.id)));
968
- };
998
+ }, bindingifyPluginHookMeta(meta),];
969
999
  }
970
1000
 
971
1001
  //#endregion
@@ -973,20 +1003,20 @@ function bindingifyModuleParsed(plugin, options, pluginContextData) {
973
1003
  function bindingifyRenderStart(plugin, options, outputOptions, pluginContextData) {
974
1004
  const hook = plugin.renderStart;
975
1005
  if (!hook) {
976
- return undefined;
1006
+ return [undefined, undefined];
977
1007
  }
978
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
979
- return async (ctx) => {
1008
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1009
+ return [async (ctx) => {
980
1010
  handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, options);
981
- };
1011
+ }, bindingifyPluginHookMeta(meta),];
982
1012
  }
983
1013
  function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData) {
984
1014
  const hook = plugin.renderChunk;
985
1015
  if (!hook) {
986
- return undefined;
1016
+ return [undefined, undefined];
987
1017
  }
988
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
989
- return async (ctx, code, chunk) => {
1018
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1019
+ return [async (ctx, code, chunk) => {
990
1020
  const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), code, chunk, outputOptions);
991
1021
  if (ret == null) {
992
1022
  return;
@@ -1001,123 +1031,157 @@ function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData
1001
1031
  code: ret.code,
1002
1032
  map: bindingifySourcemap(ret.map)
1003
1033
  };
1004
- };
1034
+ }, bindingifyPluginHookMeta(meta),];
1005
1035
  }
1006
1036
  function bindingifyAugmentChunkHash(plugin, options, pluginContextData) {
1007
1037
  const hook = plugin.augmentChunkHash;
1008
1038
  if (!hook) {
1009
- return undefined;
1039
+ return [undefined, undefined];
1010
1040
  }
1011
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1012
- return async (ctx, chunk) => {
1041
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1042
+ return [async (ctx, chunk) => {
1013
1043
  return await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1014
- };
1044
+ }, bindingifyPluginHookMeta(meta),];
1015
1045
  }
1016
1046
  function bindingifyRenderError(plugin, options, pluginContextData) {
1017
1047
  const hook = plugin.renderError;
1018
1048
  if (!hook) {
1019
- return undefined;
1049
+ return [undefined, undefined];
1020
1050
  }
1021
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1022
- return async (ctx, err) => {
1051
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1052
+ return [async (ctx, err) => {
1023
1053
  handler.call(new PluginContext(options, ctx, plugin, pluginContextData), new Error(err));
1024
- };
1054
+ }, bindingifyPluginHookMeta(meta),];
1025
1055
  }
1026
1056
  function bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData) {
1027
1057
  const hook = plugin.generateBundle;
1028
1058
  if (!hook) {
1029
- return undefined;
1059
+ return [undefined, undefined];
1030
1060
  }
1031
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1032
- return async (ctx, bundle, isWrite) => {
1061
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1062
+ return [async (ctx, bundle, isWrite) => {
1033
1063
  await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle), isWrite);
1034
- };
1064
+ }, bindingifyPluginHookMeta(meta),];
1035
1065
  }
1036
1066
  function bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData) {
1037
1067
  const hook = plugin.writeBundle;
1038
1068
  if (!hook) {
1039
- return undefined;
1069
+ return [undefined, undefined];
1040
1070
  }
1041
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1042
- return async (ctx, bundle) => {
1071
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1072
+ return [async (ctx, bundle) => {
1043
1073
  await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle));
1044
- };
1074
+ }, bindingifyPluginHookMeta(meta),];
1045
1075
  }
1046
1076
  function bindingifyBanner(plugin, options, pluginContextData) {
1047
1077
  const hook = plugin.banner;
1048
1078
  if (!hook) {
1049
- return undefined;
1079
+ return [undefined, undefined];
1050
1080
  }
1051
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1052
- return async (ctx, chunk) => {
1081
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1082
+ return [async (ctx, chunk) => {
1053
1083
  if (typeof handler === "string") {
1054
1084
  return handler;
1055
1085
  }
1056
1086
  return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1057
- };
1087
+ }, bindingifyPluginHookMeta(meta),];
1058
1088
  }
1059
1089
  function bindingifyFooter(plugin, options, pluginContextData) {
1060
1090
  const hook = plugin.footer;
1061
1091
  if (!hook) {
1062
- return undefined;
1092
+ return [undefined, undefined];
1063
1093
  }
1064
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1065
- return async (ctx, chunk) => {
1094
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1095
+ return [async (ctx, chunk) => {
1066
1096
  if (typeof handler === "string") {
1067
1097
  return handler;
1068
1098
  }
1069
1099
  return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1070
- };
1100
+ }, bindingifyPluginHookMeta(meta),];
1071
1101
  }
1072
1102
  function bindingifyIntro(plugin, options, pluginContextData) {
1073
1103
  const hook = plugin.intro;
1074
1104
  if (!hook) {
1075
- return undefined;
1105
+ return [undefined, undefined];
1076
1106
  }
1077
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1078
- return async (ctx, chunk) => {
1107
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1108
+ return [async (ctx, chunk) => {
1079
1109
  if (typeof handler === "string") {
1080
1110
  return handler;
1081
1111
  }
1082
1112
  return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1083
- };
1113
+ }, bindingifyPluginHookMeta(meta),];
1084
1114
  }
1085
1115
  function bindingifyOutro(plugin, options, pluginContextData) {
1086
1116
  const hook = plugin.outro;
1087
1117
  if (!hook) {
1088
- return undefined;
1118
+ return [undefined, undefined];
1089
1119
  }
1090
- const [handler, _optionsIgnoredSofar] = normalizeHook(hook);
1091
- return async (ctx, chunk) => {
1120
+ const { handler: handler, meta: meta } = normalizeHook(hook);
1121
+ return [async (ctx, chunk) => {
1092
1122
  if (typeof handler === "string") {
1093
1123
  return handler;
1094
1124
  }
1095
1125
  return handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
1096
- };
1126
+ }, bindingifyPluginHookMeta(meta),];
1097
1127
  }
1098
1128
 
1099
1129
  //#endregion
1100
1130
  //#region src/plugin/bindingify-plugin.ts
1101
1131
  function bindingifyPlugin(plugin, options, outputOptions, pluginContextData) {
1132
+ const [buildStart, buildStartMeta] = bindingifyBuildStart(plugin, options, pluginContextData);
1133
+ const [resolveId, resolveIdMeta] = bindingifyResolveId(plugin, options, pluginContextData);
1134
+ const [resolveDynamicImport, resolveDynamicImportMeta] = bindingifyResolveDynamicImport(plugin, options, pluginContextData);
1135
+ const [buildEnd, buildEndMeta] = bindingifyBuildEnd(plugin, options, pluginContextData);
1136
+ const [transform, transformMeta] = bindingifyTransform(plugin, options, pluginContextData);
1137
+ const [moduleParsed, moduleParsedMeta] = bindingifyModuleParsed(plugin, options, pluginContextData);
1138
+ const [load, loadMeta] = bindingifyLoad(plugin, options, pluginContextData);
1139
+ const [renderChunk, renderChunkMeta] = bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData);
1140
+ const [augmentChunkHash, augmentChunkHashMeta] = bindingifyAugmentChunkHash(plugin, options, pluginContextData);
1141
+ const [renderStart, renderStartMeta] = bindingifyRenderStart(plugin, options, outputOptions, pluginContextData);
1142
+ const [renderError, renderErrorMeta] = bindingifyRenderError(plugin, options, pluginContextData);
1143
+ const [generateBundle, generateBundleMeta] = bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData);
1144
+ const [writeBundle, writeBundleMeta] = bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData);
1145
+ const [banner, bannerMeta] = bindingifyBanner(plugin, options, pluginContextData);
1146
+ const [footer, footerMeta] = bindingifyFooter(plugin, options, pluginContextData);
1147
+ const [intro, introMeta] = bindingifyIntro(plugin, options, pluginContextData);
1148
+ const [outro, outroMeta] = bindingifyOutro(plugin, options, pluginContextData);
1102
1149
  return {
1103
1150
  name: plugin.name ?? "unknown",
1104
- buildStart: bindingifyBuildStart(plugin, options, pluginContextData),
1105
- resolveId: bindingifyResolveId(plugin, options, pluginContextData),
1106
- resolveDynamicImport: bindingifyResolveDynamicImport(plugin, options, pluginContextData),
1107
- buildEnd: bindingifyBuildEnd(plugin, options, pluginContextData),
1108
- transform: bindingifyTransform(plugin, options, pluginContextData),
1109
- moduleParsed: bindingifyModuleParsed(plugin, options, pluginContextData),
1110
- load: bindingifyLoad(plugin, options, pluginContextData),
1111
- renderChunk: bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData),
1112
- augmentChunkHash: bindingifyAugmentChunkHash(plugin, options, pluginContextData),
1113
- renderStart: bindingifyRenderStart(plugin, options, outputOptions, pluginContextData),
1114
- renderError: bindingifyRenderError(plugin, options, pluginContextData),
1115
- generateBundle: bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextData),
1116
- writeBundle: bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData),
1117
- banner: bindingifyBanner(plugin, options, pluginContextData),
1118
- footer: bindingifyFooter(plugin, options, pluginContextData),
1119
- intro: bindingifyIntro(plugin, options, pluginContextData),
1120
- outro: bindingifyOutro(plugin, options, pluginContextData)
1151
+ buildStart,
1152
+ buildStartMeta,
1153
+ resolveId,
1154
+ resolveIdMeta,
1155
+ resolveDynamicImport,
1156
+ resolveDynamicImportMeta,
1157
+ buildEnd,
1158
+ buildEndMeta,
1159
+ transform,
1160
+ transformMeta,
1161
+ moduleParsed,
1162
+ moduleParsedMeta,
1163
+ load,
1164
+ loadMeta,
1165
+ renderChunk,
1166
+ renderChunkMeta,
1167
+ augmentChunkHash,
1168
+ augmentChunkHashMeta,
1169
+ renderStart,
1170
+ renderStartMeta,
1171
+ renderError,
1172
+ renderErrorMeta,
1173
+ generateBundle,
1174
+ generateBundleMeta,
1175
+ writeBundle,
1176
+ writeBundleMeta,
1177
+ banner,
1178
+ bannerMeta,
1179
+ footer,
1180
+ footerMeta,
1181
+ intro,
1182
+ introMeta,
1183
+ outro,
1184
+ outroMeta
1121
1185
  };
1122
1186
  }
1123
1187
 
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { __toESM } = require("./chunk-whRFQvSK.cjs");
4
- const { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARN, PluginContextData, arraify, bindingifyPlugin, error, getLogHandler, isNullish, logLevelPriority, logPluginError, normalizeHook, normalizeLog, require_binding, transformToRollupOutput, unimplemented } = require("./plugin-context-data-I1aPS5hK.cjs");
4
+ const { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARN, PluginContextData, arraify, bindingifyPlugin, error, getLogHandler, isNullish, logLevelPriority, logPluginError, normalizeHook, normalizeLog, require_binding, transformToRollupOutput, unimplemented } = require("./plugin-context-data-DXDLCu7_.cjs");
5
5
  const { default: nodePath, default: path } = __toESM(require("node:path"));
6
6
  const { isRegExp, isRegExp: isRegExp$1 } = __toESM(require("node:util/types"));
7
7
  const { Worker } = __toESM(require("node:worker_threads"));
@@ -189,7 +189,31 @@ function bindingifyInputOptions(options, outputOptions) {
189
189
  },
190
190
  treeshake: options.treeshake,
191
191
  moduleTypes: options.moduleTypes,
192
- define: options.define ? Object.entries(options.define) : undefined
192
+ define: options.define ? Object.entries(options.define) : undefined,
193
+ inject: options.inject ? (Object.entries(options.inject)).map(([alias, item]) => {
194
+ if (Array.isArray(item)) {
195
+ if (item[1] === "*") {
196
+ return {
197
+ tagNamespace: true,
198
+ alias,
199
+ from: item[0]
200
+ };
201
+ }
202
+ return {
203
+ tagNamed: true,
204
+ alias,
205
+ from: item[0],
206
+ imported: item[1]
207
+ };
208
+ } else {
209
+ return {
210
+ tagNamed: true,
211
+ imported: "default",
212
+ alias,
213
+ from: item
214
+ };
215
+ }
216
+ }) : undefined
193
217
  };
194
218
  }
195
219
  function bindingifyLogLevel(logLevel) {
@@ -384,7 +408,7 @@ class PluginDriver {
384
408
  const name = plugin.name || "unknown";
385
409
  const options = plugin.options;
386
410
  if (options) {
387
- const [handler, _optionsIgnoredSofar] = normalizeHook(options);
411
+ const { handler: handler } = normalizeHook(options);
388
412
  const result = await handler.call({
389
413
  debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
390
414
  error: (e) => error(logPluginError(normalizeLog(e), name, {hook: "onLog"})),
@@ -403,7 +427,7 @@ class PluginDriver {
403
427
  for (const plugin of plugins) {
404
428
  const options = plugin.outputOptions;
405
429
  if (options) {
406
- const [handler, _optionsIgnoredSofar] = normalizeHook(options);
430
+ const { handler: handler } = normalizeHook(options);
407
431
  const result = handler.call(null, outputOptions);
408
432
  if (result) {
409
433
  outputOptions = result;
@@ -459,7 +483,7 @@ function normalizeTreeshakeOptions(config) {
459
483
  }
460
484
 
461
485
  //#endregion
462
- //#region ../../node_modules/.pnpm/remeda@2.10.0/node_modules/remeda/dist/chunk-K26VP6CL.js
486
+ //#region ../../node_modules/.pnpm/remeda@2.10.1/node_modules/remeda/dist/chunk-K26VP6CL.js
463
487
  function u$1(t$1, n, a) {
464
488
  let o = (r) => t$1(r, ...n);
465
489
  return a === void 0 ? o : Object.assign(o, {
@@ -469,7 +493,7 @@ function u$1(t$1, n, a) {
469
493
  }
470
494
 
471
495
  //#endregion
472
- //#region ../../node_modules/.pnpm/remeda@2.10.0/node_modules/remeda/dist/chunk-RAAYCPUM.js
496
+ //#region ../../node_modules/.pnpm/remeda@2.10.1/node_modules/remeda/dist/chunk-RAAYCPUM.js
473
497
  function u(r, n, a) {
474
498
  let o = r.length - n.length;
475
499
  if (o === 0) return r(...n);
@@ -478,7 +502,7 @@ function u(r, n, a) {
478
502
  }
479
503
 
480
504
  //#endregion
481
- //#region ../../node_modules/.pnpm/remeda@2.10.0/node_modules/remeda/dist/chunk-NMJS7ULY.js
505
+ //#region ../../node_modules/.pnpm/remeda@2.10.1/node_modules/remeda/dist/chunk-NMJS7ULY.js
482
506
  function t(...n) {
483
507
  return u(Object.keys, n);
484
508
  }
@@ -555,7 +579,7 @@ function createComposedPlugin(plugins) {
555
579
  const batchedHandlers = batchedHooks.buildStart;
556
580
  composed.buildStart = async function(options) {
557
581
  await Promise.all(batchedHandlers.map((handler) => {
558
- const [handlerFn, _handlerOptions] = normalizeHook(handler);
582
+ const { handler: handlerFn } = normalizeHook(handler);
559
583
  return handlerFn.call(this, options);
560
584
  }));
561
585
  };
@@ -567,7 +591,7 @@ function createComposedPlugin(plugins) {
567
591
  const batchedHandlers = batchedHooks.load;
568
592
  composed.load = async function(id) {
569
593
  for (const handler of batchedHandlers) {
570
- const [handlerFn, _handlerOptions] = normalizeHook(handler);
594
+ const { handler: handlerFn } = normalizeHook(handler);
571
595
  const result = await handlerFn.call(this, id);
572
596
  if (!isNullish(result)) {
573
597
  return result;
@@ -588,7 +612,7 @@ function createComposedPlugin(plugins) {
588
612
  moduleSideEffects = newModuleSideEffects ?? undefined;
589
613
  }
590
614
  for (const handler of batchedHandlers) {
591
- const [handlerFn, _handlerOptions] = normalizeHook(handler);
615
+ const { handler: handlerFn } = normalizeHook(handler);
592
616
  const result = await handlerFn.call(this, code, id, moduleType);
593
617
  if (!isNullish(result)) {
594
618
  if (typeof result === "string") {
@@ -613,7 +637,7 @@ function createComposedPlugin(plugins) {
613
637
  const batchedHandlers = batchedHooks.buildEnd;
614
638
  composed.buildEnd = async function(err) {
615
639
  await Promise.all(batchedHandlers.map((handler) => {
616
- const [handlerFn, _handlerOptions] = normalizeHook(handler);
640
+ const { handler: handlerFn } = normalizeHook(handler);
617
641
  return handlerFn.call(this, err);
618
642
  }));
619
643
  };
@@ -625,7 +649,7 @@ function createComposedPlugin(plugins) {
625
649
  const batchedHandlers = batchedHooks.renderChunk;
626
650
  composed.renderChunk = async function(code, chunk, options) {
627
651
  for (const handler of batchedHandlers) {
628
- const [handlerFn, _handlerOptions] = normalizeHook(handler);
652
+ const { handler: handlerFn } = normalizeHook(handler);
629
653
  const result = await handlerFn.call(this, code, chunk, options);
630
654
  if (!isNullish(result)) {
631
655
  return result;
@@ -647,7 +671,24 @@ function isComposablePlugin(plugin) {
647
671
  if ("_parallel"in plugin) {
648
672
  return false;
649
673
  }
650
- if ((t(plugin)).some((hookName) => isUnsupportedHooks(hookName))) {
674
+ const hasNotComposablePattern = (t(plugin)).some((hookName) => {
675
+ const OK_TO_COMPOSE = false;
676
+ switch (hookName) {
677
+ case "name":
678
+ case "api": return OK_TO_COMPOSE;
679
+ }
680
+ if (isUnsupportedHooks(hookName)) {
681
+ return !OK_TO_COMPOSE;
682
+ }
683
+ if (plugin[hookName]) {
684
+ const { meta: meta } = normalizeHook(plugin[hookName]);
685
+ if (meta.order === "pre" || meta.order === "post") {
686
+ return !OK_TO_COMPOSE;
687
+ }
688
+ }
689
+ return OK_TO_COMPOSE;
690
+ });
691
+ if (hasNotComposablePattern) {
651
692
  return false;
652
693
  }
653
694
  return true;