rolldown 0.15.0-commit.ddbe0a9 → 0.15.0-commit.f0c42f8

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.
@@ -580,9 +580,7 @@ function unreachable(info) {
580
580
  throw new Error("unreachable");
581
581
  }
582
582
  function unsupported(info) {
583
- return () => {
584
- throw new Error(`UNSUPPORTED: ${info}`);
585
- };
583
+ throw new Error(`UNSUPPORTED: ${info}`);
586
584
  }
587
585
  function noop(..._args) {}
588
586
 
@@ -825,7 +823,8 @@ function getLogger(plugins, onLog, logLevel) {
825
823
  rolldownVersion: VERSION,
826
824
  watchMode: false
827
825
  },
828
- warn: getLogHandler$1(LOG_LEVEL_WARN)
826
+ warn: getLogHandler$1(LOG_LEVEL_WARN),
827
+ pluginName: plugin.name || "unknown"
829
828
  }, level, log) === false) return;
830
829
  }
831
830
  }
@@ -1048,7 +1047,8 @@ var PluginDriver = class {
1048
1047
  rolldownVersion: VERSION,
1049
1048
  watchMode: false
1050
1049
  },
1051
- warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
1050
+ warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
1051
+ pluginName: name
1052
1052
  }, inputOptions);
1053
1053
  if (result) inputOptions = result;
1054
1054
  }
@@ -1148,6 +1148,7 @@ function transformModuleInfo(info, option) {
1148
1148
  dynamicImporters: info.dynamicImporters,
1149
1149
  importedIds: info.importedIds,
1150
1150
  dynamicallyImportedIds: info.dynamicallyImportedIds,
1151
+ exports: info.exports,
1151
1152
  isEntry: info.isEntry,
1152
1153
  ...option
1153
1154
  };
@@ -1160,21 +1161,20 @@ var MinimalPluginContext = class {
1160
1161
  warn;
1161
1162
  debug;
1162
1163
  meta;
1163
- error;
1164
- constructor(onLog, logLevel, plugin) {
1165
- const pluginName = plugin.name || "unknown";
1164
+ constructor(onLog, logLevel, pluginName) {
1165
+ this.pluginName = pluginName;
1166
1166
  this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
1167
1167
  this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
1168
1168
  this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
1169
- this.error = (e) => {
1170
- return error(logPluginError(normalizeLog(e), pluginName));
1171
- };
1172
1169
  this.meta = {
1173
1170
  rollupVersion: "4.23.0",
1174
1171
  rolldownVersion: VERSION,
1175
1172
  watchMode: false
1176
1173
  };
1177
1174
  }
1175
+ error(e) {
1176
+ return error(logPluginError(normalizeLog(e), this.pluginName));
1177
+ }
1178
1178
  };
1179
1179
 
1180
1180
  //#endregion
@@ -1194,84 +1194,92 @@ function bindingifySideEffects(sideEffects) {
1194
1194
  //#endregion
1195
1195
  //#region src/plugin/plugin-context.ts
1196
1196
  var PluginContext = class extends MinimalPluginContext {
1197
- load;
1198
- resolve;
1199
- emitFile;
1200
- getFileName;
1201
- getModuleInfo;
1202
- getModuleIds;
1203
- addWatchFile;
1204
- /**
1205
- * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
1206
- */
1207
- parse;
1208
1197
  constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
1209
- super(onLog, logLevel, plugin);
1210
- this.load = async ({ id,...options }) => {
1211
- if (id === currentLoadingModule) onLog(LOG_LEVEL_WARN, logCycleLoading(plugin.name, currentLoadingModule));
1212
- const moduleInfo = data.getModuleInfo(id, context);
1213
- if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
1214
- const rawOptions = {
1215
- meta: options.meta || {},
1216
- moduleSideEffects: options.moduleSideEffects || null
1217
- };
1218
- data.updateModuleOption(id, rawOptions);
1219
- async function createLoadModulePromise() {
1220
- const loadPromise = data.loadModulePromiseMap.get(id);
1221
- if (loadPromise) return loadPromise;
1222
- let resolveFn;
1223
- const promise = new Promise((resolve, _) => {
1224
- resolveFn = resolve;
1225
- });
1226
- data.loadModulePromiseMap.set(id, promise);
1227
- try {
1228
- await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
1229
- } finally {
1230
- data.loadModulePromiseMap.delete(id);
1231
- }
1232
- return promise;
1233
- }
1234
- await createLoadModulePromise();
1235
- return data.getModuleInfo(id, context);
1236
- };
1237
- this.resolve = async (source, importer, options) => {
1238
- let receipt = undefined;
1239
- if (options != null) receipt = data.saveResolveOptions(options);
1240
- const res = await context.resolve(source, importer, {
1241
- custom: receipt,
1242
- skipSelf: options?.skipSelf
1243
- });
1244
- if (receipt != null) data.removeSavedResolveOptions(receipt);
1245
- if (res == null) return null;
1246
- const info = data.getModuleOption(res.id) || {};
1247
- return {
1248
- ...res,
1249
- ...info
1250
- };
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
1251
1212
  };
1252
- this.emitFile = (file) => {
1253
- if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
1254
- return context.emitFile({
1255
- ...file,
1256
- originalFileName: file.originalFileName || undefined,
1257
- 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;
1258
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
1259
1245
  };
1260
- this.getFileName = context.getFileName.bind(context);
1261
- this.getModuleInfo = (id) => data.getModuleInfo(id, context);
1262
- this.getModuleIds = () => data.getModuleIds(context);
1263
- this.parse = unsupported("`PluginContext#parse` is not supported by rolldown.");
1264
- 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.");
1265
1272
  }
1266
1273
  };
1267
1274
 
1268
1275
  //#endregion
1269
1276
  //#region src/plugin/transform-plugin-context.ts
1270
1277
  var TransformPluginContext = class extends PluginContext {
1271
- error;
1272
- getCombinedSourcemap;
1273
1278
  constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
1274
1279
  super(context, plugin, data, onLog, LogLevelOption, moduleId);
1280
+ this.inner = inner;
1281
+ this.moduleId = moduleId;
1282
+ this.moduleSource = moduleSource;
1275
1283
  const getLogHandler$1 = (handler) => (log, pos) => {
1276
1284
  log = normalizeLog(log);
1277
1285
  if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
@@ -1282,14 +1290,16 @@ var TransformPluginContext = class extends PluginContext {
1282
1290
  this.debug = getLogHandler$1(this.debug);
1283
1291
  this.warn = getLogHandler$1(this.warn);
1284
1292
  this.info = getLogHandler$1(this.info);
1285
- this.error = (e, pos) => {
1286
- if (typeof e === "string") e = { message: e };
1287
- if (pos) augmentCodeLocation(e, pos, moduleSource, moduleId);
1288
- e.id = moduleId;
1289
- e.hook = "transform";
1290
- return error(logPluginError(normalizeLog(e), plugin.name || "unknown"));
1291
- };
1292
- 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());
1293
1303
  }
1294
1304
  };
1295
1305
 
@@ -1522,7 +1532,9 @@ function bindingifyModuleParsed(args) {
1522
1532
  //#endregion
1523
1533
  //#region src/options/normalized-output-options.ts
1524
1534
  function mapFunctionOption(option, name) {
1525
- 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;
1526
1538
  }
1527
1539
  var NormalizedOutputOptionsImpl = class {
1528
1540
  inner;
@@ -2317,10 +2329,7 @@ function createComposedPlugin(plugins) {
2317
2329
  const createFixedPluginResolveFnMap = new Map();
2318
2330
  function applyFixedPluginResolveFn(ctx, plugin) {
2319
2331
  const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
2320
- if (createFixedPluginResolveFn) return {
2321
- ...ctx,
2322
- resolve: createFixedPluginResolveFn(ctx)
2323
- };
2332
+ if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
2324
2333
  return ctx;
2325
2334
  }
2326
2335
  if (batchedHooks.resolveId) {
@@ -2329,14 +2338,14 @@ function createComposedPlugin(plugins) {
2329
2338
  for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2330
2339
  const [_handler, plugin] = batchedHandlers[handlerIdx];
2331
2340
  const handlerSymbol = handlerSymbols[handlerIdx];
2332
- const createFixedPluginResolveFn = (ctx) => {
2341
+ const createFixedPluginResolveFn = (ctx, resolve) => {
2333
2342
  return (source, importer, rawContextResolveOptions) => {
2334
2343
  const contextResolveOptions = rawContextResolveOptions ?? {};
2335
2344
  if (contextResolveOptions.skipSelf) {
2336
2345
  contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
2337
2346
  contextResolveOptions.skipSelf = false;
2338
2347
  }
2339
- return ctx.resolve(source, importer, contextResolveOptions);
2348
+ return resolve(source, importer, contextResolveOptions);
2340
2349
  };
2341
2350
  };
2342
2351
  createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
@@ -2394,12 +2403,10 @@ function createComposedPlugin(plugins) {
2394
2403
  }
2395
2404
  for (const [handler, plugin] of batchedHandlers) {
2396
2405
  const { handler: handlerFn } = normalizeHook(handler);
2397
- const result = await handlerFn.call({
2398
- ...applyFixedPluginResolveFn(this, plugin),
2399
- getCombinedSourcemap() {
2400
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
2401
- }
2402
- }, code, id, moduleType);
2406
+ this.getCombinedSourcemap = () => {
2407
+ throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
2408
+ };
2409
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
2403
2410
  if (!isNullish(result)) {
2404
2411
  if (typeof result === "string") updateOutput(result);
2405
2412
  else if (result.code) updateOutput(result.code, result.moduleSideEffects);
@@ -2798,7 +2805,7 @@ const watch = (input) => {
2798
2805
 
2799
2806
  //#endregion
2800
2807
  //#region package.json
2801
- var version = "0.15.0-commit.ddbe0a9";
2808
+ var version = "0.15.0-commit.f0c42f8";
2802
2809
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2803
2810
 
2804
2811
  //#endregion