rolldown 0.15.0 → 0.15.1-commit.4e41a08

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 (54) hide show
  1. package/dist/cjs/cli.cjs +249 -183
  2. package/dist/cjs/experimental-index.cjs +2 -2
  3. package/dist/cjs/index.cjs +1 -1
  4. package/dist/cjs/parallel-plugin-worker.cjs +2 -2
  5. package/dist/esm/cli.mjs +343 -277
  6. package/dist/esm/experimental-index.mjs +1 -1
  7. package/dist/esm/index.mjs +1 -1
  8. package/dist/esm/parallel-plugin-worker.mjs +1 -1
  9. package/dist/shared/{chunk-BK2Ye-xa.cjs → chunk-BFvIen8E.cjs} +0 -11
  10. package/dist/shared/{consola_36c0034f-_8_dG1Nr.cjs → consola_36c0034f-B7L-radJ.cjs} +2 -2
  11. package/dist/shared/{consola_36c0034f-DWsVjwtA.mjs → consola_36c0034f-D9ce-831.mjs} +10 -10
  12. package/dist/shared/{prompt-RFvZMmjc.cjs → prompt-BiXtYIJ2.cjs} +3 -3
  13. package/dist/shared/{prompt-DGW8ZJmn.mjs → prompt-DlQ-08lk.mjs} +2 -2
  14. package/dist/shared/{src-DEPa5yhI.mjs → src-Do1JlyLc.mjs} +324 -232
  15. package/dist/shared/{src-COU7qQBJ.cjs → src-Dw217EaC.cjs} +313 -215
  16. package/dist/tsconfig.dts.tsbuildinfo +1 -0
  17. package/dist/types/api/build.d.ts +2 -0
  18. package/dist/types/api/watch/index.d.ts +2 -2
  19. package/dist/types/api/watch/watch-emitter.d.ts +31 -0
  20. package/dist/types/api/watch/watcher.d.ts +7 -27
  21. package/dist/types/binding.d.ts +114 -19
  22. package/dist/types/builtin-plugin/constructors.d.ts +1 -5
  23. package/dist/types/cli/arguments/index.d.ts +5 -3
  24. package/dist/types/cli/arguments/schema.d.ts +10 -397
  25. package/dist/types/cli/colors.d.ts +11 -1
  26. package/dist/types/cli/load-config.d.ts +3 -0
  27. package/dist/types/cli/logger.d.ts +5 -0
  28. package/dist/types/constants/plugin.d.ts +8 -1
  29. package/dist/types/index.d.ts +3 -3
  30. package/dist/types/log/logging.d.ts +6 -6
  31. package/dist/types/log/logs.d.ts +1 -0
  32. package/dist/types/options/input-options-schema.d.ts +3 -595
  33. package/dist/types/options/input-options.d.ts +26 -3
  34. package/dist/types/options/normalized-input-options.d.ts +1 -1
  35. package/dist/types/options/normalized-output-options.d.ts +21 -17
  36. package/dist/types/options/output-options-schema.d.ts +2 -146
  37. package/dist/types/options/output-options.d.ts +1 -0
  38. package/dist/types/plugin/minimal-plugin-context.d.ts +3 -3
  39. package/dist/types/plugin/plugin-context-data.d.ts +2 -1
  40. package/dist/types/plugin/plugin-context.d.ts +14 -10
  41. package/dist/types/plugin/transform-plugin-context.d.ts +7 -4
  42. package/dist/types/rollup.d.ts +4 -0
  43. package/dist/types/treeshake/module-side-effects.d.ts +14 -115
  44. package/dist/types/types/module-info.d.ts +1 -0
  45. package/dist/types/types/rolldown-output.d.ts +6 -0
  46. package/dist/types/utils/bindingify-input-options.d.ts +1 -1
  47. package/dist/types/utils/create-bundler-option.d.ts +11 -0
  48. package/dist/types/utils/error.d.ts +2 -1
  49. package/dist/types/utils/misc.d.ts +1 -1
  50. package/dist/types/utils/transform-sourcemap.d.ts +1 -1
  51. package/dist/types/utils/zod-ext.d.ts +6 -5
  52. package/package.json +15 -15
  53. package/dist/types/cli/utils.d.ts +0 -6
  54. package/dist/types/log/locate-character/index.d.ts +0 -13
@@ -1,4 +1,5 @@
1
- const require_chunk = require('./chunk-BK2Ye-xa.cjs');
1
+ const require_chunk = require('./chunk-BFvIen8E.cjs');
2
+ const node_buffer = require_chunk.__toESM(require("node:buffer"));
2
3
  const zod = require_chunk.__toESM(require("zod"));
3
4
  const node_path = require_chunk.__toESM(require("node:path"));
4
5
  const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
@@ -35,7 +36,11 @@ function bindingifySourcemap$1(map) {
35
36
  //#endregion
36
37
  //#region src/utils/error.ts
37
38
  function normalizeErrors(rawErrors) {
38
- const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), e, { stack: undefined }));
39
+ const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
40
+ kind: e.kind,
41
+ message: e.message,
42
+ stack: undefined
43
+ }));
39
44
  let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
40
45
  for (let i = 0; i < errors.length; i++) {
41
46
  if (i >= 5) {
@@ -107,6 +112,19 @@ function transformChunkModules(modules) {
107
112
 
108
113
  //#endregion
109
114
  //#region src/utils/transform-to-rollup-output.ts
115
+ function transformToRollupSourceMap(map) {
116
+ const parsed = JSON.parse(map);
117
+ const obj = {
118
+ ...parsed,
119
+ toString() {
120
+ return JSON.stringify(obj);
121
+ },
122
+ toUrl() {
123
+ return `data:application/json;charset=utf-8;base64,${node_buffer.Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
124
+ }
125
+ };
126
+ return obj;
127
+ }
110
128
  function transformToRollupOutputChunk(bindingChunk, changed) {
111
129
  const chunk = {
112
130
  type: "chunk",
@@ -132,7 +150,7 @@ function transformToRollupOutputChunk(bindingChunk, changed) {
132
150
  return bindingChunk.moduleIds;
133
151
  },
134
152
  get map() {
135
- return bindingChunk.map ? JSON.parse(bindingChunk.map) : null;
153
+ return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
136
154
  },
137
155
  sourcemapFileName: bindingChunk.sourcemapFileName || null,
138
156
  preliminaryFileName: bindingChunk.preliminaryFileName
@@ -155,10 +173,12 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
155
173
  type: "asset",
156
174
  fileName: bindingAsset.fileName,
157
175
  originalFileName: bindingAsset.originalFileName || null,
176
+ originalFileNames: bindingAsset.originalFileNames,
158
177
  get source() {
159
178
  return transformAssetSource(bindingAsset.source);
160
179
  },
161
- name: bindingAsset.name ?? undefined
180
+ name: bindingAsset.name ?? undefined,
181
+ names: bindingAsset.names
162
182
  };
163
183
  const cache = {};
164
184
  return new Proxy(asset, {
@@ -197,9 +217,9 @@ function collectChangedBundle(changed, bundle) {
197
217
  const item = bundle[key];
198
218
  if (item.type === "asset") assets.push({
199
219
  filename: item.fileName,
200
- originalFileName: item.originalFileName || undefined,
220
+ originalFileNames: item.originalFileNames,
201
221
  source: bindingAssetSource(item.source),
202
- name: item.name
222
+ names: item.names
203
223
  });
204
224
  else chunks.push({
205
225
  code: item.code,
@@ -517,7 +537,7 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
517
537
  }
518
538
  module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
519
539
  module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
520
- module.exports.BindingHookError = nativeBinding.BindingHookError;
540
+ module.exports.BindingError = nativeBinding.BindingError;
521
541
  module.exports.BindingLog = nativeBinding.BindingLog;
522
542
  module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
523
543
  module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
@@ -536,8 +556,10 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
536
556
  module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
537
557
  module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
538
558
  module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
559
+ module.exports.HelperMode = nativeBinding.HelperMode;
539
560
  module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
540
561
  module.exports.registerPlugins = nativeBinding.registerPlugins;
562
+ module.exports.Severity = nativeBinding.Severity;
541
563
  module.exports.transform = nativeBinding.transform;
542
564
  } });
543
565
 
@@ -558,9 +580,7 @@ function unreachable(info) {
558
580
  throw new Error("unreachable");
559
581
  }
560
582
  function unsupported(info) {
561
- return () => {
562
- throw new Error(`UNSUPPORTED: ${info}`);
563
- };
583
+ throw new Error(`UNSUPPORTED: ${info}`);
564
584
  }
565
585
  function noop(..._args) {}
566
586
 
@@ -675,7 +695,7 @@ function locate(source, search, options) {
675
695
 
676
696
  //#endregion
677
697
  //#region src/log/logs.ts
678
- const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING";
698
+ const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION";
679
699
  function logInvalidLogPosition(pluginName) {
680
700
  return {
681
701
  code: INVALID_LOG_POSITION,
@@ -694,6 +714,12 @@ function logCycleLoading(pluginName, moduleId) {
694
714
  message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
695
715
  };
696
716
  }
717
+ function logMultiplyNotifyOption() {
718
+ return {
719
+ code: MULTIPLY_NOTIFY_OPTION,
720
+ message: `Found multiply notify option at watch options, using first one to start notify watcher.`
721
+ };
722
+ }
697
723
  function logPluginError(error$1, plugin, { hook, id } = {}) {
698
724
  const code = error$1.code;
699
725
  if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
@@ -797,7 +823,8 @@ function getLogger(plugins, onLog, logLevel) {
797
823
  rolldownVersion: VERSION,
798
824
  watchMode: false
799
825
  },
800
- warn: getLogHandler$1(LOG_LEVEL_WARN)
826
+ warn: getLogHandler$1(LOG_LEVEL_WARN),
827
+ pluginName: plugin.name || "unknown"
801
828
  }, level, log) === false) return;
802
829
  }
803
830
  }
@@ -849,9 +876,9 @@ function relativeId(id) {
849
876
 
850
877
  //#endregion
851
878
  //#region src/builtin-plugin/utils.ts
852
- var import_binding$5 = require_chunk.__toESM(require_binding());
879
+ var import_binding$6 = require_chunk.__toESM(require_binding());
853
880
  function makeBuiltinPluginCallable(plugin) {
854
- let callablePlugin = new import_binding$5.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
881
+ let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
855
882
  const wrappedPlugin = plugin;
856
883
  for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
857
884
  return callablePlugin[key](...args);
@@ -1020,7 +1047,8 @@ var PluginDriver = class {
1020
1047
  rolldownVersion: VERSION,
1021
1048
  watchMode: false
1022
1049
  },
1023
- warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
1050
+ warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
1051
+ pluginName: name
1024
1052
  }, inputOptions);
1025
1053
  if (result) inputOptions = result;
1026
1054
  }
@@ -1084,7 +1112,7 @@ const ModuleSideEffectsRuleSchema = zod.z.object({
1084
1112
  }).refine((data) => {
1085
1113
  return data.test !== undefined || data.external !== undefined;
1086
1114
  }, "Either `test` or `external` should be set.");
1087
- const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.literal("no-external"));
1115
+ const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.function().args(zod.z.string(), zod.z.boolean()).returns(zod.z.boolean().optional())).or(zod.z.literal("no-external"));
1088
1116
  const TreeshakingOptionsSchema = zod.z.object({
1089
1117
  moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
1090
1118
  annotations: zod.z.boolean().optional()
@@ -1120,6 +1148,7 @@ function transformModuleInfo(info, option) {
1120
1148
  dynamicImporters: info.dynamicImporters,
1121
1149
  importedIds: info.importedIds,
1122
1150
  dynamicallyImportedIds: info.dynamicallyImportedIds,
1151
+ exports: info.exports,
1123
1152
  isEntry: info.isEntry,
1124
1153
  ...option
1125
1154
  };
@@ -1132,31 +1161,30 @@ var MinimalPluginContext = class {
1132
1161
  warn;
1133
1162
  debug;
1134
1163
  meta;
1135
- error;
1136
- constructor(onLog, logLevel, plugin) {
1137
- const pluginName = plugin.name || "unknown";
1164
+ constructor(onLog, logLevel, pluginName) {
1165
+ this.pluginName = pluginName;
1138
1166
  this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
1139
1167
  this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
1140
1168
  this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
1141
- this.error = (e) => {
1142
- return error(logPluginError(normalizeLog(e), pluginName));
1143
- };
1144
1169
  this.meta = {
1145
1170
  rollupVersion: "4.23.0",
1146
1171
  rolldownVersion: VERSION,
1147
1172
  watchMode: false
1148
1173
  };
1149
1174
  }
1175
+ error(e) {
1176
+ return error(logPluginError(normalizeLog(e), this.pluginName));
1177
+ }
1150
1178
  };
1151
1179
 
1152
1180
  //#endregion
1153
1181
  //#region src/utils/transform-side-effects.ts
1154
- var import_binding$4 = require_chunk.__toESM(require_binding());
1182
+ var import_binding$5 = require_chunk.__toESM(require_binding());
1155
1183
  function bindingifySideEffects(sideEffects) {
1156
1184
  switch (sideEffects) {
1157
- case true: return import_binding$4.BindingHookSideEffects.True;
1158
- case false: return import_binding$4.BindingHookSideEffects.False;
1159
- case "no-treeshake": return import_binding$4.BindingHookSideEffects.NoTreeshake;
1185
+ case true: return import_binding$5.BindingHookSideEffects.True;
1186
+ case false: return import_binding$5.BindingHookSideEffects.False;
1187
+ case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
1160
1188
  case null:
1161
1189
  case undefined: return undefined;
1162
1190
  default: throw new Error(`Unexpected side effects: ${sideEffects}`);
@@ -1166,84 +1194,92 @@ function bindingifySideEffects(sideEffects) {
1166
1194
  //#endregion
1167
1195
  //#region src/plugin/plugin-context.ts
1168
1196
  var PluginContext = class extends MinimalPluginContext {
1169
- load;
1170
- resolve;
1171
- emitFile;
1172
- getFileName;
1173
- getModuleInfo;
1174
- getModuleIds;
1175
- addWatchFile;
1176
- /**
1177
- * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
1178
- */
1179
- parse;
1180
1197
  constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
1181
- super(onLog, logLevel, plugin);
1182
- this.load = async ({ id,...options }) => {
1183
- if (id === currentLoadingModule) onLog(LOG_LEVEL_WARN, logCycleLoading(plugin.name, currentLoadingModule));
1184
- const moduleInfo = data.getModuleInfo(id, context);
1185
- if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
1186
- const rawOptions = {
1187
- meta: options.meta || {},
1188
- moduleSideEffects: options.moduleSideEffects || null
1189
- };
1190
- data.updateModuleOption(id, rawOptions);
1191
- async function createLoadModulePromise() {
1192
- const loadPromise = data.loadModulePromiseMap.get(id);
1193
- if (loadPromise) return loadPromise;
1194
- let resolveFn;
1195
- const promise = new Promise((resolve, _) => {
1196
- resolveFn = resolve;
1197
- });
1198
- data.loadModulePromiseMap.set(id, promise);
1199
- try {
1200
- await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
1201
- } finally {
1202
- data.loadModulePromiseMap.delete(id);
1203
- }
1204
- return promise;
1205
- }
1206
- await createLoadModulePromise();
1207
- return data.getModuleInfo(id, context);
1208
- };
1209
- this.resolve = async (source, importer, options) => {
1210
- let receipt = undefined;
1211
- if (options != null) receipt = data.saveResolveOptions(options);
1212
- const res = await context.resolve(source, importer, {
1213
- custom: receipt,
1214
- skipSelf: options?.skipSelf
1215
- });
1216
- if (receipt != null) data.removeSavedResolveOptions(receipt);
1217
- if (res == null) return null;
1218
- const info = data.getModuleOption(res.id) || {};
1219
- return {
1220
- ...res,
1221
- ...info
1222
- };
1198
+ super(onLog, logLevel, plugin.name);
1199
+ this.context = context;
1200
+ this.data = data;
1201
+ this.onLog = onLog;
1202
+ this.currentLoadingModule = currentLoadingModule;
1203
+ }
1204
+ async load(options) {
1205
+ const id = options.id;
1206
+ if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(super.pluginName, this.currentLoadingModule));
1207
+ const moduleInfo = this.data.getModuleInfo(id, this.context);
1208
+ if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
1209
+ const rawOptions = {
1210
+ meta: options.meta || {},
1211
+ moduleSideEffects: options.moduleSideEffects || null
1223
1212
  };
1224
- this.emitFile = (file) => {
1225
- if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
1226
- return context.emitFile({
1227
- ...file,
1228
- originalFileName: file.originalFileName || undefined,
1229
- source: bindingAssetSource(file.source)
1213
+ this.data.updateModuleOption(id, rawOptions);
1214
+ async function createLoadModulePromise(context, data) {
1215
+ const loadPromise = data.loadModulePromiseMap.get(id);
1216
+ if (loadPromise) return loadPromise;
1217
+ let resolveFn;
1218
+ const promise = new Promise((resolve, _) => {
1219
+ resolveFn = resolve;
1230
1220
  });
1221
+ data.loadModulePromiseMap.set(id, promise);
1222
+ try {
1223
+ await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
1224
+ } finally {
1225
+ data.loadModulePromiseMap.delete(id);
1226
+ }
1227
+ return promise;
1228
+ }
1229
+ await createLoadModulePromise(this.context, this.data);
1230
+ return this.data.getModuleInfo(id, this.context);
1231
+ }
1232
+ async resolve(source, importer, options) {
1233
+ let receipt = undefined;
1234
+ if (options != null) receipt = this.data.saveResolveOptions(options);
1235
+ const res = await this.context.resolve(source, importer, {
1236
+ custom: receipt,
1237
+ skipSelf: options?.skipSelf
1238
+ });
1239
+ if (receipt != null) this.data.removeSavedResolveOptions(receipt);
1240
+ if (res == null) return null;
1241
+ const info = this.data.getModuleOption(res.id) || {};
1242
+ return {
1243
+ ...res,
1244
+ ...info
1231
1245
  };
1232
- this.getFileName = context.getFileName.bind(context);
1233
- this.getModuleInfo = (id) => data.getModuleInfo(id, context);
1234
- this.getModuleIds = () => data.getModuleIds(context);
1235
- this.parse = unsupported("`PluginContext#parse` is not supported by rolldown.");
1236
- this.addWatchFile = context.addWatchFile.bind(context);
1246
+ }
1247
+ emitFile(file) {
1248
+ if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
1249
+ return this.context.emitFile({
1250
+ ...file,
1251
+ originalFileName: file.originalFileName || undefined,
1252
+ source: bindingAssetSource(file.source)
1253
+ });
1254
+ }
1255
+ getFileName(referenceId) {
1256
+ return this.context.getFileName(referenceId);
1257
+ }
1258
+ getModuleInfo(id) {
1259
+ return this.data.getModuleInfo(id, this.context);
1260
+ }
1261
+ getModuleIds() {
1262
+ return this.data.getModuleIds(this.context);
1263
+ }
1264
+ addWatchFile(id) {
1265
+ this.context.addWatchFile(id);
1266
+ }
1267
+ /**
1268
+ * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
1269
+ */
1270
+ parse(_input, _options) {
1271
+ unsupported("`PluginContext#parse` is not supported by rolldown.");
1237
1272
  }
1238
1273
  };
1239
1274
 
1240
1275
  //#endregion
1241
1276
  //#region src/plugin/transform-plugin-context.ts
1242
1277
  var TransformPluginContext = class extends PluginContext {
1243
- error;
1244
- getCombinedSourcemap;
1245
1278
  constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
1246
1279
  super(context, plugin, data, onLog, LogLevelOption, moduleId);
1280
+ this.inner = inner;
1281
+ this.moduleId = moduleId;
1282
+ this.moduleSource = moduleSource;
1247
1283
  const getLogHandler$1 = (handler) => (log, pos) => {
1248
1284
  log = normalizeLog(log);
1249
1285
  if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
@@ -1254,27 +1290,29 @@ var TransformPluginContext = class extends PluginContext {
1254
1290
  this.debug = getLogHandler$1(this.debug);
1255
1291
  this.warn = getLogHandler$1(this.warn);
1256
1292
  this.info = getLogHandler$1(this.info);
1257
- this.error = (e, pos) => {
1258
- if (typeof e === "string") e = { message: e };
1259
- if (pos) augmentCodeLocation(e, pos, moduleSource, moduleId);
1260
- e.id = moduleId;
1261
- e.hook = "transform";
1262
- return error(logPluginError(normalizeLog(e), plugin.name || "unknown"));
1263
- };
1264
- this.getCombinedSourcemap = () => JSON.parse(inner.getCombinedSourcemap());
1293
+ }
1294
+ error(e, pos) {
1295
+ if (typeof e === "string") e = { message: e };
1296
+ if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
1297
+ e.id = this.moduleId;
1298
+ e.hook = "transform";
1299
+ return error(logPluginError(normalizeLog(e), super.pluginName));
1300
+ }
1301
+ getCombinedSourcemap() {
1302
+ return JSON.parse(this.inner.getCombinedSourcemap());
1265
1303
  }
1266
1304
  };
1267
1305
 
1268
1306
  //#endregion
1269
1307
  //#region src/plugin/bindingify-plugin-hook-meta.ts
1270
- var import_binding$3 = require_chunk.__toESM(require_binding());
1308
+ var import_binding$4 = require_chunk.__toESM(require_binding());
1271
1309
  function bindingifyPluginHookMeta(options) {
1272
1310
  return { order: bindingPluginOrder(options.order) };
1273
1311
  }
1274
1312
  function bindingPluginOrder(order) {
1275
1313
  switch (order) {
1276
- case "post": return import_binding$3.BindingPluginOrder.Post;
1277
- case "pre": return import_binding$3.BindingPluginOrder.Pre;
1314
+ case "post": return import_binding$4.BindingPluginOrder.Post;
1315
+ case "pre": return import_binding$4.BindingPluginOrder.Pre;
1278
1316
  case null:
1279
1317
  case undefined: return undefined;
1280
1318
  default: throw new Error(`Unknown plugin order: ${order}`);
@@ -1355,7 +1393,7 @@ function bindingifyBuildEnd(args) {
1355
1393
  const { handler, meta } = normalizeHook(hook);
1356
1394
  return {
1357
1395
  plugin: async (ctx, err) => {
1358
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err.errors) : undefined);
1396
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
1359
1397
  },
1360
1398
  meta: bindingifyPluginHookMeta(meta)
1361
1399
  };
@@ -1494,7 +1532,9 @@ function bindingifyModuleParsed(args) {
1494
1532
  //#endregion
1495
1533
  //#region src/options/normalized-output-options.ts
1496
1534
  function mapFunctionOption(option, name) {
1497
- return typeof option === "undefined" ? unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`) : option;
1535
+ return typeof option === "undefined" ? () => {
1536
+ unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
1537
+ } : option;
1498
1538
  }
1499
1539
  var NormalizedOutputOptionsImpl = class {
1500
1540
  inner;
@@ -1582,6 +1622,9 @@ var NormalizedOutputOptionsImpl = class {
1582
1622
  get comments() {
1583
1623
  return this.inner.comments;
1584
1624
  }
1625
+ get polyfillRequire() {
1626
+ return this.inner.polyfillRequire;
1627
+ }
1585
1628
  };
1586
1629
 
1587
1630
  //#endregion
@@ -1632,7 +1675,7 @@ function bindingifyRenderError(args) {
1632
1675
  const { handler, meta } = normalizeHook(hook);
1633
1676
  return {
1634
1677
  plugin: async (ctx, err) => {
1635
- handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new Error(err));
1678
+ handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
1636
1679
  },
1637
1680
  meta: bindingifyPluginHookMeta(meta)
1638
1681
  };
@@ -1933,7 +1976,7 @@ function normalizedStringOrRegex(pattern) {
1933
1976
 
1934
1977
  //#endregion
1935
1978
  //#region src/utils/bindingify-input-options.ts
1936
- var import_binding$2 = require_chunk.__toESM(require_binding());
1979
+ var import_binding$3 = require_chunk.__toESM(require_binding());
1937
1980
  function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
1938
1981
  const pluginContextData = new PluginContextData();
1939
1982
  const plugins = rawPlugins.map((plugin) => {
@@ -1964,7 +2007,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
1964
2007
  profilerNames: inputOptions?.profilerNames,
1965
2008
  jsx: bindingifyJsx(inputOptions.jsx),
1966
2009
  watch: bindingifyWatch(inputOptions.watch),
1967
- dropLabels: inputOptions.dropLabels
2010
+ dropLabels: inputOptions.dropLabels,
2011
+ keepNames: inputOptions.keepNames,
2012
+ checks: inputOptions.checks
1968
2013
  };
1969
2014
  }
1970
2015
  function bindingifyExternal(external) {
@@ -1988,7 +2033,7 @@ function bindingifyResolve(resolve) {
1988
2033
  return {
1989
2034
  alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
1990
2035
  find: name,
1991
- replacements: [replacement]
2036
+ replacements: arraify(replacement)
1992
2037
  })) : undefined,
1993
2038
  extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
1994
2039
  target: name,
@@ -2022,10 +2067,10 @@ function bindingifyInject(inject) {
2022
2067
  }
2023
2068
  function bindingifyLogLevel(logLevel) {
2024
2069
  switch (logLevel) {
2025
- case "silent": return import_binding$2.BindingLogLevel.Silent;
2026
- case "debug": return import_binding$2.BindingLogLevel.Debug;
2027
- case "warn": return import_binding$2.BindingLogLevel.Warn;
2028
- case "info": return import_binding$2.BindingLogLevel.Info;
2070
+ case "silent": return import_binding$3.BindingLogLevel.Silent;
2071
+ case "debug": return import_binding$3.BindingLogLevel.Debug;
2072
+ case "warn": return import_binding$3.BindingLogLevel.Warn;
2073
+ case "info": return import_binding$3.BindingLogLevel.Info;
2029
2074
  default: throw new Error(`Unexpected log level: ${logLevel}`);
2030
2075
  }
2031
2076
  }
@@ -2041,15 +2086,20 @@ function bindingifyInput(input) {
2041
2086
  });
2042
2087
  }
2043
2088
  function bindingifyJsx(input) {
2089
+ if (input === false) return { type: "Disable" };
2044
2090
  if (input) {
2045
- const mode = input.mode ?? "classic";
2091
+ if (input.mode === "preserve") return { type: "Preserve" };
2092
+ const mode = input.mode ?? "automatic";
2046
2093
  return {
2047
- runtime: mode,
2048
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
2049
- pragma: input.factory,
2050
- pragmaFrag: input.fragment,
2051
- development: input.development,
2052
- refresh: input.refresh
2094
+ type: "Enable",
2095
+ field0: {
2096
+ runtime: mode,
2097
+ importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
2098
+ pragma: input.factory,
2099
+ pragmaFrag: input.fragment,
2100
+ development: input.development,
2101
+ refresh: input.refresh
2102
+ }
2053
2103
  };
2054
2104
  }
2055
2105
  }
@@ -2060,10 +2110,6 @@ function bindingifyWatch(watch$1) {
2060
2110
  include: normalizedStringOrRegex(watch$1.include),
2061
2111
  exclude: normalizedStringOrRegex(watch$1.exclude)
2062
2112
  };
2063
- if (watch$1.notify) value.notify = {
2064
- pollInterval: watch$1.notify.pollInterval,
2065
- compareContents: watch$1.notify.compareContents
2066
- };
2067
2113
  if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
2068
2114
  return value;
2069
2115
  }
@@ -2118,7 +2164,8 @@ function bindingifyOutputOptions(outputOptions) {
2118
2164
  minify: outputOptions.minify,
2119
2165
  externalLiveBindings: outputOptions.externalLiveBindings,
2120
2166
  inlineDynamicImports: outputOptions.inlineDynamicImports,
2121
- advancedChunks: outputOptions.advancedChunks
2167
+ advancedChunks: outputOptions.advancedChunks,
2168
+ polyfillRequire: outputOptions.polyfillRequire
2122
2169
  };
2123
2170
  }
2124
2171
  function bindingifyAddon(configAddon) {
@@ -2287,10 +2334,7 @@ function createComposedPlugin(plugins) {
2287
2334
  const createFixedPluginResolveFnMap = new Map();
2288
2335
  function applyFixedPluginResolveFn(ctx, plugin) {
2289
2336
  const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
2290
- if (createFixedPluginResolveFn) return {
2291
- ...ctx,
2292
- resolve: createFixedPluginResolveFn(ctx)
2293
- };
2337
+ if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
2294
2338
  return ctx;
2295
2339
  }
2296
2340
  if (batchedHooks.resolveId) {
@@ -2299,14 +2343,14 @@ function createComposedPlugin(plugins) {
2299
2343
  for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2300
2344
  const [_handler, plugin] = batchedHandlers[handlerIdx];
2301
2345
  const handlerSymbol = handlerSymbols[handlerIdx];
2302
- const createFixedPluginResolveFn = (ctx) => {
2346
+ const createFixedPluginResolveFn = (ctx, resolve) => {
2303
2347
  return (source, importer, rawContextResolveOptions) => {
2304
2348
  const contextResolveOptions = rawContextResolveOptions ?? {};
2305
2349
  if (contextResolveOptions.skipSelf) {
2306
2350
  contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
2307
2351
  contextResolveOptions.skipSelf = false;
2308
2352
  }
2309
- return ctx.resolve(source, importer, contextResolveOptions);
2353
+ return resolve(source, importer, contextResolveOptions);
2310
2354
  };
2311
2355
  };
2312
2356
  createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
@@ -2364,12 +2408,10 @@ function createComposedPlugin(plugins) {
2364
2408
  }
2365
2409
  for (const [handler, plugin] of batchedHandlers) {
2366
2410
  const { handler: handlerFn } = normalizeHook(handler);
2367
- const result = await handlerFn.call({
2368
- ...applyFixedPluginResolveFn(this, plugin),
2369
- getCombinedSourcemap() {
2370
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
2371
- }
2372
- }, code, id, moduleType);
2411
+ this.getCombinedSourcemap = () => {
2412
+ throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
2413
+ };
2414
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
2373
2415
  if (!isNullish(result)) {
2374
2416
  if (typeof result === "string") updateOutput(result);
2375
2417
  else if (result.code) updateOutput(result.code, result.moduleSideEffects);
@@ -2504,7 +2546,7 @@ else newPlugins.push(toBeComposed[0]);
2504
2546
 
2505
2547
  //#endregion
2506
2548
  //#region src/utils/initialize-parallel-plugins.ts
2507
- var import_binding$1 = require_chunk.__toESM(require_binding());
2549
+ var import_binding$2 = require_chunk.__toESM(require_binding());
2508
2550
  async function initializeParallelPlugins(plugins) {
2509
2551
  const pluginInfos = [];
2510
2552
  for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
@@ -2517,7 +2559,7 @@ async function initializeParallelPlugins(plugins) {
2517
2559
  }
2518
2560
  if (pluginInfos.length <= 0) return undefined;
2519
2561
  const count = Math.min((0, node_os.availableParallelism)(), 8);
2520
- const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
2562
+ const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
2521
2563
  const registryId = parallelJsPluginRegistry.id;
2522
2564
  const workers = await initializeWorkers(registryId, count, pluginInfos);
2523
2565
  const stopWorkers = async () => {
@@ -2556,9 +2598,8 @@ else resolve();
2556
2598
  }
2557
2599
 
2558
2600
  //#endregion
2559
- //#region src/utils/create-bundler.ts
2560
- var import_binding = require_chunk.__toESM(require_binding());
2561
- async function createBundler(inputOptions, outputOptions) {
2601
+ //#region src/utils/create-bundler-option.ts
2602
+ async function createBundlerOptions(inputOptions, outputOptions) {
2562
2603
  const pluginDriver = new PluginDriver();
2563
2604
  inputOptions = await pluginDriver.callOptionsHook(inputOptions);
2564
2605
  if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
@@ -2574,7 +2615,13 @@ async function createBundler(inputOptions, outputOptions) {
2574
2615
  const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
2575
2616
  const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
2576
2617
  return {
2577
- bundler: new import_binding.Bundler(bindingInputOptions, bindingOutputOptions, parallelPluginInitResult?.registry),
2618
+ bundlerOptions: {
2619
+ inputOptions: bindingInputOptions,
2620
+ outputOptions: bindingOutputOptions,
2621
+ parallelPluginsRegistry: parallelPluginInitResult?.registry
2622
+ },
2623
+ inputOptions,
2624
+ onLog,
2578
2625
  stopWorkers: parallelPluginInitResult?.stopWorkers
2579
2626
  };
2580
2627
  } catch (e) {
@@ -2583,6 +2630,22 @@ async function createBundler(inputOptions, outputOptions) {
2583
2630
  }
2584
2631
  }
2585
2632
 
2633
+ //#endregion
2634
+ //#region src/utils/create-bundler.ts
2635
+ var import_binding$1 = require_chunk.__toESM(require_binding());
2636
+ async function createBundler(inputOptions, outputOptions) {
2637
+ const option = await createBundlerOptions(inputOptions, outputOptions);
2638
+ try {
2639
+ return {
2640
+ bundler: new import_binding$1.Bundler(option.bundlerOptions),
2641
+ stopWorkers: option.stopWorkers
2642
+ };
2643
+ } catch (e) {
2644
+ await option.stopWorkers?.();
2645
+ throw e;
2646
+ }
2647
+ }
2648
+
2586
2649
  //#endregion
2587
2650
  //#region src/api/rolldown/rolldown-build.ts
2588
2651
  Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
@@ -2625,98 +2688,129 @@ const rolldown = async (input) => {
2625
2688
  return new RolldownBuild(input);
2626
2689
  };
2627
2690
 
2691
+ //#endregion
2692
+ //#region src/api/watch/watch-emitter.ts
2693
+ var WatcherEmitter = class {
2694
+ listeners = new Map();
2695
+ timer;
2696
+ constructor() {
2697
+ this.timer = setInterval(
2698
+ () => {},
2699
+ 1e9
2700
+ /* Low power usage */
2701
+ );
2702
+ }
2703
+ on(event, listener) {
2704
+ const listeners = this.listeners.get(event);
2705
+ if (listeners) listeners.push(listener);
2706
+ else this.listeners.set(event, [listener]);
2707
+ return this;
2708
+ }
2709
+ async onEvent(event) {
2710
+ const listeners = this.listeners.get(event.eventKind());
2711
+ if (listeners) switch (event.eventKind()) {
2712
+ case "close":
2713
+ case "restart":
2714
+ for (const listener of listeners) await listener();
2715
+ break;
2716
+ case "event":
2717
+ for (const listener of listeners) {
2718
+ const code = event.bundleEventKind();
2719
+ switch (code) {
2720
+ case "BUNDLE_END":
2721
+ const { duration, output } = event.bundleEndData();
2722
+ await listener({
2723
+ code: "BUNDLE_END",
2724
+ duration,
2725
+ output: [output]
2726
+ });
2727
+ break;
2728
+ case "ERROR":
2729
+ const errors = event.errors();
2730
+ await listener({
2731
+ code: "ERROR",
2732
+ error: normalizeErrors(errors)
2733
+ });
2734
+ break;
2735
+ default:
2736
+ await listener({ code });
2737
+ break;
2738
+ }
2739
+ }
2740
+ break;
2741
+ case "change":
2742
+ for (const listener of listeners) {
2743
+ const { path: path$2, kind } = event.watchChangeData();
2744
+ await listener(path$2, { event: kind });
2745
+ }
2746
+ break;
2747
+ default: throw new Error(`Unknown event: ${event}`);
2748
+ }
2749
+ }
2750
+ async close() {
2751
+ clearInterval(this.timer);
2752
+ }
2753
+ };
2754
+
2628
2755
  //#endregion
2629
2756
  //#region src/api/watch/watcher.ts
2757
+ var import_binding = require_chunk.__toESM(require_binding());
2630
2758
  var Watcher = class {
2631
2759
  closed;
2632
- controller;
2633
2760
  inner;
2761
+ emitter;
2634
2762
  stopWorkers;
2635
- listeners = new Map();
2636
- constructor(inner, stopWorkers) {
2763
+ constructor(emitter, inner, stopWorkers) {
2637
2764
  this.closed = false;
2638
- this.controller = new AbortController();
2639
2765
  this.inner = inner;
2766
+ this.emitter = emitter;
2767
+ const originClose = emitter.close.bind(emitter);
2768
+ emitter.close = async () => {
2769
+ await this.close();
2770
+ originClose();
2771
+ };
2640
2772
  this.stopWorkers = stopWorkers;
2641
2773
  }
2642
2774
  async close() {
2775
+ if (this.closed) return;
2643
2776
  this.closed = true;
2644
- await this.stopWorkers?.();
2777
+ for (const stop of this.stopWorkers) await stop?.();
2645
2778
  await this.inner.close();
2646
- this.controller.abort();
2647
2779
  }
2648
- on(event, listener) {
2649
- const listeners = this.listeners.get(event);
2650
- if (listeners) listeners.push(listener);
2651
- else this.listeners.set(event, [listener]);
2652
- return this;
2653
- }
2654
- watch() {
2655
- const timer = setInterval(
2656
- () => {},
2657
- 1e9
2658
- /* Low power usage */
2659
- );
2660
- this.controller.signal.addEventListener("abort", () => {
2661
- clearInterval(timer);
2662
- });
2663
- process.nextTick(() => this.inner.start(async (event) => {
2664
- const listeners = this.listeners.get(event.eventKind());
2665
- if (listeners) switch (event.eventKind()) {
2666
- case "close":
2667
- case "restart":
2668
- for (const listener of listeners) await listener();
2669
- break;
2670
- case "event":
2671
- for (const listener of listeners) {
2672
- const code = event.bundleEventKind();
2673
- switch (code) {
2674
- case "BUNDLE_END":
2675
- const { duration, output } = event.bundleEndData();
2676
- await listener({
2677
- code: "BUNDLE_END",
2678
- duration,
2679
- output: [output]
2680
- });
2681
- break;
2682
- case "ERROR":
2683
- const errors = event.errors();
2684
- await listener({
2685
- code: "ERROR",
2686
- error: normalizeErrors(errors)
2687
- });
2688
- break;
2689
- default:
2690
- await listener({ code });
2691
- break;
2692
- }
2693
- }
2694
- break;
2695
- case "change":
2696
- for (const listener of listeners) {
2697
- const { path: path$2, kind } = event.watchChangeData();
2698
- await listener(path$2, { event: kind });
2699
- }
2700
- break;
2701
- default: throw new Error(`Unknown event: ${event}`);
2702
- }
2703
- }));
2780
+ start() {
2781
+ process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
2704
2782
  }
2705
2783
  };
2784
+ async function createWatcher(emitter, input) {
2785
+ const options = Array.isArray(input) ? input : [input];
2786
+ const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
2787
+ const notifyOptions = getValidNotifyOption(bundlerOptions);
2788
+ const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
2789
+ const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
2790
+ watcher.start();
2791
+ }
2792
+ function getValidNotifyOption(bundlerOptions) {
2793
+ let result;
2794
+ for (const option of bundlerOptions) if (option.inputOptions.watch) {
2795
+ const notifyOption = option.inputOptions.watch.notify;
2796
+ if (notifyOption) if (result) {
2797
+ option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
2798
+ return result;
2799
+ } else result = notifyOption;
2800
+ }
2801
+ }
2706
2802
 
2707
2803
  //#endregion
2708
2804
  //#region src/api/watch/index.ts
2709
- const watch = async (input) => {
2710
- const { bundler, stopWorkers } = await createBundler(input, input.output || {});
2711
- const bindingWatcher = await bundler.watch();
2712
- const watcher = new Watcher(bindingWatcher, stopWorkers);
2713
- watcher.watch();
2714
- return watcher;
2805
+ const watch = (input) => {
2806
+ const emitter = new WatcherEmitter();
2807
+ createWatcher(emitter, input);
2808
+ return emitter;
2715
2809
  };
2716
2810
 
2717
2811
  //#endregion
2718
2812
  //#region package.json
2719
- var version = "0.15.0";
2813
+ var version = "0.15.1-commit.4e41a08";
2720
2814
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2721
2815
 
2722
2816
  //#endregion
@@ -2724,10 +2818,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
2724
2818
  async function build(options) {
2725
2819
  if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
2726
2820
  else {
2727
- const { output,...inputOptions } = options;
2821
+ const { output, write = true,...inputOptions } = options;
2728
2822
  const build$1 = await rolldown(inputOptions);
2729
- if (options.write) return build$1.write(output);
2730
- else return build$1.generate(output);
2823
+ try {
2824
+ if (write) return await build$1.write(output);
2825
+ else return await build$1.generate(output);
2826
+ } finally {
2827
+ await build$1.close();
2828
+ }
2731
2829
  }
2732
2830
  }
2733
2831