rolldown 1.2.0 → 1.2.2

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 (44) hide show
  1. package/THIRD-PARTY-LICENSE +33 -0
  2. package/dist/cli.d.mts +1 -1
  3. package/dist/cli.mjs +9 -10
  4. package/dist/config.d.mts +1 -1
  5. package/dist/config.mjs +2 -2
  6. package/dist/experimental-default-runtime.mjs +116 -0
  7. package/dist/experimental-index.d.mts +10 -4
  8. package/dist/experimental-index.mjs +32 -16
  9. package/dist/experimental-runtime-base.mjs +95 -0
  10. package/dist/experimental-runtime.d.ts +177 -0
  11. package/dist/experimental-runtime.mjs +257 -0
  12. package/dist/filter-index.d.mts +1 -1
  13. package/dist/filter-index.mjs +1 -3
  14. package/dist/index.d.mts +3 -3
  15. package/dist/index.mjs +4 -4
  16. package/dist/parallel-plugin-worker.d.mts +1 -1
  17. package/dist/parallel-plugin-worker.mjs +3 -3
  18. package/dist/parallel-plugin.d.mts +1 -1
  19. package/dist/parse-ast-index.d.mts +1 -1
  20. package/dist/parse-ast-index.mjs +2 -2
  21. package/dist/plugins-index.d.mts +3 -3
  22. package/dist/plugins-index.mjs +2 -2
  23. package/dist/shared/{binding-Dbbi0RbO.d.mts → binding-CVtkJvyl.d.mts} +11 -0
  24. package/dist/shared/{binding-Dby9rwGk.mjs → binding-DwUQWZOo.mjs} +124 -50
  25. package/dist/shared/{bindingify-input-options-_ppP73I9.mjs → bindingify-input-options-BHixd47T.mjs} +448 -268
  26. package/dist/shared/{constructors-CSWbNgBZ.d.mts → constructors-ALilxAii.d.mts} +2 -2
  27. package/dist/shared/{constructors-CuGa75s-.mjs → constructors-COwFYQna.mjs} +10 -6
  28. package/dist/shared/{rolldown-build-CdF8HAHX.mjs → create-bundler-option-LuUKlAT7.mjs} +72 -179
  29. package/dist/shared/{define-config-B-IDOhDz.d.mts → define-config-DSMNXceb.d.mts} +85 -22
  30. package/dist/shared/{error-DFGNOCle.mjs → error-nLggAzpQ.mjs} +1 -1
  31. package/dist/shared/{load-config-C6UyiS41.mjs → load-config-cRWJAHTc.mjs} +2 -2
  32. package/dist/shared/{logs-ZGEh6uhb.mjs → logs-DmYCAKcW.mjs} +8 -1
  33. package/dist/shared/{misc-CoQm4NHO.mjs → misc-DOSKtd97.mjs} +9 -1
  34. package/dist/shared/{normalize-string-or-regex-SiXbePVH.mjs → normalize-string-or-regex-Cj-DgIV1.mjs} +2 -2
  35. package/dist/shared/{parse-BFj5G_7i.mjs → parse-C17W7W5g.mjs} +2 -2
  36. package/dist/shared/{prompt--dNycKSZ.mjs → prompt-CH6TK0bC.mjs} +2 -6
  37. package/dist/shared/{resolve-tsconfig-2TXRF_zr.mjs → resolve-tsconfig-CE3HNSOK.mjs} +2 -2
  38. package/dist/shared/rolldown-D23fYgSS.mjs +178 -0
  39. package/dist/shared/{transform-Cs2bUDRH.d.mts → transform-WmU_cI8e.d.mts} +1 -1
  40. package/dist/shared/{watch-WnrlHRS0.mjs → watch-DcgK_L55.mjs} +16 -13
  41. package/dist/utils-index.d.mts +3 -3
  42. package/dist/utils-index.mjs +6 -8
  43. package/package.json +32 -25
  44. package/dist/shared/rolldown-951h_1lf.mjs +0 -40
@@ -1,14 +1,16 @@
1
- import { n as __toESM, t as require_binding } from "./binding-Dby9rwGk.mjs";
2
- import { a as logInvalidLogPosition, c as logPluginError, n as error, r as logCycleLoading, t as augmentCodeLocation } from "./logs-ZGEh6uhb.mjs";
3
- import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-SiXbePVH.mjs";
4
- import { a as unreachable, o as unsupported, r as noop, t as arraify } from "./misc-CoQm4NHO.mjs";
5
- import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-DFGNOCle.mjs";
1
+ import { n as __toESM, t as require_binding } from "./binding-DwUQWZOo.mjs";
2
+ import { i as logFailedValidation, l as logPluginError, n as error, o as logInvalidLogPosition, r as logCycleLoading, t as augmentCodeLocation } from "./logs-DmYCAKcW.mjs";
3
+ import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-Cj-DgIV1.mjs";
4
+ import { i as noop, n as isPathFragment, o as unreachable, s as unsupported, t as arraify } from "./misc-DOSKtd97.mjs";
5
+ import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-nLggAzpQ.mjs";
6
6
  import { parseAst } from "../parse-ast-index.mjs";
7
+ import fs from "node:fs";
7
8
  import path from "node:path";
8
9
  import * as filter from "@rolldown/pluginutils";
9
10
  import fsp from "node:fs/promises";
11
+ import { fileURLToPath } from "node:url";
10
12
  //#region package.json
11
- var version = "1.2.0";
13
+ var version = "1.2.2";
12
14
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
13
15
  //#endregion
14
16
  //#region src/constants/version.ts
@@ -65,6 +67,26 @@ function normalizeHook(hook) {
65
67
  unreachable("Invalid hook type");
66
68
  }
67
69
  //#endregion
70
+ //#region src/utils/parallel-plugin.ts
71
+ /**
72
+ * Returns the `_parallel` marker of a parallel plugin, or `undefined` if the
73
+ * given plugin is not one.
74
+ *
75
+ * Detection is descriptor-based instead of using the `in` operator: only an
76
+ * own data property named `_parallel` with the expected shape counts. This
77
+ * avoids false positives from inherited or accessor `_parallel` properties on
78
+ * regular plugins, and guarantees that callers can safely read `fileUrl` and
79
+ * `options` from the returned value.
80
+ */
81
+ function getParallelPluginInfo(plugin) {
82
+ if (plugin === null || typeof plugin !== "object") return;
83
+ const descriptor = Object.getOwnPropertyDescriptor(plugin, "_parallel");
84
+ if (!descriptor || !("value" in descriptor)) return;
85
+ const parallel = descriptor.value;
86
+ if (parallel === null || typeof parallel !== "object" || typeof parallel.fileUrl !== "string") return;
87
+ return parallel;
88
+ }
89
+ //#endregion
68
90
  //#region src/plugin/minimal-plugin-context.ts
69
91
  var MinimalPluginContextImpl = class {
70
92
  pluginName;
@@ -214,7 +236,7 @@ function bindingAssetSource(source) {
214
236
  return { inner: source };
215
237
  }
216
238
  //#endregion
217
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
239
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
218
240
  function __decorate(decorators, target, key, desc) {
219
241
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
220
242
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1087,6 +1109,20 @@ function containsImporterId(expr) {
1087
1109
  function assertNoImporterId(filterExprs, hookName) {
1088
1110
  if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
1089
1111
  }
1112
+ function containsStringId(expr) {
1113
+ switch (expr.kind) {
1114
+ case "and":
1115
+ case "or": return expr.args.some(containsStringId);
1116
+ case "not":
1117
+ case "include":
1118
+ case "exclude": return containsStringId(expr.expr);
1119
+ case "id": return typeof expr.pattern === "string";
1120
+ default: return false;
1121
+ }
1122
+ }
1123
+ function assertNoStringId(filterExprs, hookName) {
1124
+ if (filterExprs?.some(containsStringId)) throw new Error(`A string \`id\` filter is not supported for the \`${hookName}\` hook, because its \`id\` is the import specifier rather than a resolved path. Use a RegExp instead.`);
1125
+ }
1090
1126
  function bindingifyFilterExprImpl(expr, list) {
1091
1127
  switch (expr.kind) {
1092
1128
  case "and": {
@@ -1160,8 +1196,11 @@ function bindingifyFilterExprImpl(expr, list) {
1160
1196
  }
1161
1197
  function bindingifyResolveIdFilter(filterOption) {
1162
1198
  if (!filterOption) return;
1163
- if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
1164
- return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
1199
+ const filterExprs = Array.isArray(filterOption) ? filterOption : filterOption.id ? generalHookFilterMatcherToFilterExprs(filterOption.id, "id") : void 0;
1200
+ assertNoStringId(filterExprs, "resolveId");
1201
+ if (!filterExprs) return;
1202
+ const value = filterExprs.map(bindingifyFilterExpr);
1203
+ return value.length > 0 ? { value } : void 0;
1165
1204
  }
1166
1205
  function bindingifyLoadFilter(filterOption) {
1167
1206
  if (!filterOption) return;
@@ -1201,6 +1240,14 @@ function bindingPluginOrder(order) {
1201
1240
  default: throw new Error(`Unknown plugin order: ${order}`);
1202
1241
  }
1203
1242
  }
1243
+ function bindingifyHook(hook, build) {
1244
+ if (!hook) return {};
1245
+ const normalized = normalizeHook(hook);
1246
+ return {
1247
+ ...build(normalized),
1248
+ meta: bindingifyPluginHookMeta(normalized.meta)
1249
+ };
1250
+ }
1204
1251
  //#endregion
1205
1252
  //#region src/plugin/fs.ts
1206
1253
  const fsModule = {
@@ -1284,17 +1331,23 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
1284
1331
  };
1285
1332
  }
1286
1333
  emitFile = (file) => {
1287
- if (file.type === "prebuilt-chunk") return this.context.emitPrebuiltChunk({
1288
- fileName: file.fileName,
1289
- name: file.name,
1290
- code: file.code,
1291
- exports: file.exports,
1292
- map: bindingifySourcemap(file.map),
1293
- sourcemapFileName: file.sourcemapFileName,
1294
- facadeModuleId: file.facadeModuleId,
1295
- isEntry: file.isEntry,
1296
- isDynamicEntry: file.isDynamicEntry
1297
- });
1334
+ if (file.type === "prebuilt-chunk") {
1335
+ if (typeof file.code !== "string") return error(logFailedValidation(`Emitted prebuilt chunks need to have a valid string code, received "${file.code}".`));
1336
+ if (typeof file.fileName !== "string" || isPathFragment(file.fileName)) return error(logFailedValidation(`The "fileName" property of emitted prebuilt chunks must be strings that are neither absolute nor relative paths, received "${file.fileName}".`));
1337
+ return this.context.emitPrebuiltChunk({
1338
+ fileName: file.fileName,
1339
+ name: file.name,
1340
+ code: file.code,
1341
+ exports: file.exports,
1342
+ map: bindingifySourcemap(file.map),
1343
+ sourcemapFileName: file.sourcemapFileName,
1344
+ facadeModuleId: file.facadeModuleId,
1345
+ isEntry: file.isEntry,
1346
+ isDynamicEntry: file.isDynamicEntry
1347
+ });
1348
+ }
1349
+ const validatedName = file.fileName || file.name;
1350
+ if (typeof validatedName === "string" && isPathFragment(validatedName)) return error(logFailedValidation(`The "fileName" or "name" properties of emitted chunks and assets must be strings that are neither absolute nor relative paths, received "${validatedName}".`));
1298
1351
  if (file.type === "chunk") return this.context.emitChunk({
1299
1352
  preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
1300
1353
  ...file
@@ -1330,6 +1383,9 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
1330
1383
  return parseAst(input, options);
1331
1384
  }
1332
1385
  };
1386
+ function createPluginContext(args, ctx) {
1387
+ return new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1388
+ }
1333
1389
  //#endregion
1334
1390
  //#region src/plugin/load-plugin-context.ts
1335
1391
  var LoadPluginContextImpl = class extends PluginContextImpl {
@@ -1383,36 +1439,19 @@ var TransformPluginContextImpl = class extends PluginContextImpl {
1383
1439
  };
1384
1440
  //#endregion
1385
1441
  //#region src/plugin/bindingify-build-hooks.ts
1386
- function createPluginContext(args, ctx) {
1387
- return new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1388
- }
1389
1442
  function bindingifyBuildStart(args) {
1390
- const hook = args.plugin.buildStart;
1391
- if (!hook) return {};
1392
- const { handler, meta } = normalizeHook(hook);
1393
- return {
1394
- plugin: async (ctx, opts) => {
1395
- await handler.call(createPluginContext(args, ctx), args.pluginContextData.getInputOptions(opts));
1396
- },
1397
- meta: bindingifyPluginHookMeta(meta)
1398
- };
1443
+ return bindingifyHook(args.plugin.buildStart, ({ handler }) => ({ plugin: async (ctx, opts) => {
1444
+ await handler.call(createPluginContext(args, ctx), args.pluginContextData.getInputOptions(opts));
1445
+ } }));
1399
1446
  }
1400
1447
  function bindingifyBuildEnd(args) {
1401
- const hook = args.plugin.buildEnd;
1402
- if (!hook) return {};
1403
- const { handler, meta } = normalizeHook(hook);
1404
- return {
1405
- plugin: async (ctx, err) => {
1406
- await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1407
- },
1408
- meta: bindingifyPluginHookMeta(meta)
1409
- };
1448
+ return bindingifyHook(args.plugin.buildEnd, ({ handler }) => ({ plugin: async (ctx, err) => {
1449
+ await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1450
+ } }));
1410
1451
  }
1411
1452
  function bindingifyResolveId(args) {
1412
1453
  const hook = args.plugin.resolveId;
1413
- if (!hook) return {};
1414
- const { handler, meta, options } = normalizeHook(hook);
1415
- return {
1454
+ return bindingifyHook(hook, ({ handler, options }) => ({
1416
1455
  plugin: async (ctx, specifier, importer, extraOptions) => {
1417
1456
  const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
1418
1457
  const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0, {
@@ -1442,44 +1481,34 @@ function bindingifyResolveId(args) {
1442
1481
  packageJsonPath: ret.packageJsonPath
1443
1482
  };
1444
1483
  },
1445
- meta: bindingifyPluginHookMeta(meta),
1446
1484
  filter: bindingifyResolveIdFilter(options.filter)
1447
- };
1485
+ }));
1448
1486
  }
1449
1487
  function bindingifyResolveDynamicImport(args) {
1450
- const hook = args.plugin.resolveDynamicImport;
1451
- if (!hook) return {};
1452
- const { handler, meta } = normalizeHook(hook);
1453
- return {
1454
- plugin: async (ctx, specifier, importer) => {
1455
- const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0);
1456
- if (ret == null) return;
1457
- if (ret === false) return {
1458
- id: specifier,
1459
- external: true
1460
- };
1461
- if (typeof ret === "string") return { id: ret };
1462
- const result = {
1463
- id: ret.id,
1464
- external: ret.external,
1465
- packageJsonPath: ret.packageJsonPath
1466
- };
1467
- if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
1468
- args.pluginContextData.updateModuleOption(ret.id, {
1469
- meta: ret.meta || {},
1470
- moduleSideEffects: ret.moduleSideEffects || null,
1471
- invalidate: false
1472
- });
1473
- return result;
1474
- },
1475
- meta: bindingifyPluginHookMeta(meta)
1476
- };
1488
+ return bindingifyHook(args.plugin.resolveDynamicImport, ({ handler }) => ({ plugin: async (ctx, specifier, importer) => {
1489
+ const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0);
1490
+ if (ret == null) return;
1491
+ if (ret === false) return {
1492
+ id: specifier,
1493
+ external: true
1494
+ };
1495
+ if (typeof ret === "string") return { id: ret };
1496
+ const result = {
1497
+ id: ret.id,
1498
+ external: ret.external,
1499
+ packageJsonPath: ret.packageJsonPath
1500
+ };
1501
+ if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
1502
+ args.pluginContextData.updateModuleOption(ret.id, {
1503
+ meta: ret.meta || {},
1504
+ moduleSideEffects: ret.moduleSideEffects || null,
1505
+ invalidate: false
1506
+ });
1507
+ return result;
1508
+ } }));
1477
1509
  }
1478
1510
  function bindingifyTransform(args) {
1479
- const hook = args.plugin.transform;
1480
- if (!hook) return {};
1481
- const { handler, meta, options } = normalizeHook(hook);
1482
- return {
1511
+ return bindingifyHook(args.plugin.transform, ({ handler, options }) => ({
1483
1512
  plugin: async (ctx, code, id, meta) => {
1484
1513
  let magicStringInstance, astInstance;
1485
1514
  Object.defineProperties(meta, {
@@ -1495,10 +1524,7 @@ function bindingifyTransform(args) {
1495
1524
  case "js":
1496
1525
  case "jsx":
1497
1526
  case "ts":
1498
- case "tsx":
1499
- lang = meta.moduleType;
1500
- break;
1501
- default: break;
1527
+ case "tsx": lang = meta.moduleType;
1502
1528
  }
1503
1529
  astInstance = parseAst(code, {
1504
1530
  astType: meta.moduleType.includes("ts") ? "ts" : "js",
@@ -1534,15 +1560,11 @@ function bindingifyTransform(args) {
1534
1560
  moduleType: ret.moduleType
1535
1561
  };
1536
1562
  },
1537
- meta: bindingifyPluginHookMeta(meta),
1538
1563
  filter: bindingifyTransformFilter(options.filter)
1539
- };
1564
+ }));
1540
1565
  }
1541
1566
  function bindingifyLoad(args) {
1542
- const hook = args.plugin.load;
1543
- if (!hook) return {};
1544
- const { handler, meta, options } = normalizeHook(hook);
1545
- return {
1567
+ return bindingifyHook(args.plugin.load, ({ handler, options }) => ({
1546
1568
  plugin: async (ctx, id) => {
1547
1569
  const ret = await handler.call(new LoadPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, args.onLog, args.logLevel, args.watchMode), id);
1548
1570
  if (ret == null) return;
@@ -1560,9 +1582,8 @@ function bindingifyLoad(args) {
1560
1582
  moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
1561
1583
  };
1562
1584
  },
1563
- meta: bindingifyPluginHookMeta(meta),
1564
1585
  filter: bindingifyLoadFilter(options.filter)
1565
- };
1586
+ }));
1566
1587
  }
1567
1588
  function preProcessSourceMap(ret, id) {
1568
1589
  if (!ret.map) return;
@@ -1575,34 +1596,19 @@ function preProcessSourceMap(ret, id) {
1575
1596
  return map;
1576
1597
  }
1577
1598
  function bindingifyModuleParsed(args) {
1578
- const hook = args.plugin.moduleParsed;
1579
- if (!hook) return {};
1580
- const { handler, meta } = normalizeHook(hook);
1581
- return {
1582
- plugin: async (ctx, moduleInfo) => {
1583
- await handler.call(createPluginContext(args, ctx), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
1584
- },
1585
- meta: bindingifyPluginHookMeta(meta)
1586
- };
1599
+ return bindingifyHook(args.plugin.moduleParsed, ({ handler }) => ({ plugin: async (ctx, moduleInfo) => {
1600
+ await handler.call(createPluginContext(args, ctx), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
1601
+ } }));
1587
1602
  }
1588
1603
  //#endregion
1589
1604
  //#region src/plugin/bindingify-output-hooks.ts
1590
1605
  function bindingifyRenderStart(args) {
1591
- const hook = args.plugin.renderStart;
1592
- if (!hook) return {};
1593
- const { handler, meta } = normalizeHook(hook);
1594
- return {
1595
- plugin: async (ctx, opts) => {
1596
- handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
1597
- },
1598
- meta: bindingifyPluginHookMeta(meta)
1599
- };
1606
+ return bindingifyHook(args.plugin.renderStart, ({ handler }) => ({ plugin: async (ctx, opts) => {
1607
+ await handler.call(createPluginContext(args, ctx), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
1608
+ } }));
1600
1609
  }
1601
1610
  function bindingifyRenderChunk(args) {
1602
- const hook = args.plugin.renderChunk;
1603
- if (!hook) return {};
1604
- const { handler, meta, options } = normalizeHook(hook);
1605
- return {
1611
+ return bindingifyHook(args.plugin.renderChunk, ({ handler, options }) => ({
1606
1612
  plugin: async (ctx, code, chunk, opts, meta) => {
1607
1613
  if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
1608
1614
  const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
@@ -1615,7 +1621,7 @@ function bindingifyRenderChunk(args) {
1615
1621
  },
1616
1622
  configurable: true
1617
1623
  });
1618
- const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
1624
+ const ret = await handler.call(createPluginContext(args, ctx), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
1619
1625
  if (ret == null) return;
1620
1626
  if (ret instanceof RolldownMagicString) {
1621
1627
  const normalizedCode = ret.toString();
@@ -1666,150 +1672,81 @@ function bindingifyRenderChunk(args) {
1666
1672
  map: bindingifySourcemap(ret.map)
1667
1673
  };
1668
1674
  },
1669
- meta: bindingifyPluginHookMeta(meta),
1670
1675
  filter: bindingifyRenderChunkFilter(options.filter)
1671
- };
1676
+ }));
1672
1677
  }
1673
1678
  function bindingifyAugmentChunkHash(args) {
1674
- const hook = args.plugin.augmentChunkHash;
1675
- if (!hook) return {};
1676
- const { handler, meta } = normalizeHook(hook);
1677
- return {
1678
- plugin: async (ctx, chunk) => {
1679
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1680
- },
1681
- meta: bindingifyPluginHookMeta(meta)
1682
- };
1679
+ return bindingifyHook(args.plugin.augmentChunkHash, ({ handler }) => ({ plugin: async (ctx, chunk) => {
1680
+ return handler.call(createPluginContext(args, ctx), transformRenderedChunk(chunk));
1681
+ } }));
1682
+ }
1683
+ function bindingifyResolveFileUrl(args) {
1684
+ return bindingifyHook(args.plugin.resolveFileUrl, ({ handler }) => ({ plugin: async (ctx, resolveFileUrlArgs) => {
1685
+ return handler.call(createPluginContext(args, ctx), resolveFileUrlArgs);
1686
+ } }));
1683
1687
  }
1684
1688
  function bindingifyRenderError(args) {
1685
- const hook = args.plugin.renderError;
1686
- if (!hook) return {};
1687
- const { handler, meta } = normalizeHook(hook);
1689
+ return bindingifyHook(args.plugin.renderError, ({ handler }) => ({ plugin: async (ctx, err) => {
1690
+ await handler.call(createPluginContext(args, ctx), aggregateBindingErrorsIntoJsError(err));
1691
+ } }));
1692
+ }
1693
+ function createOutputBundle(args, ctx, bundle) {
1694
+ const changed = {
1695
+ updated: /* @__PURE__ */ new Set(),
1696
+ deleted: /* @__PURE__ */ new Set()
1697
+ };
1698
+ const context = createPluginContext(args, ctx);
1688
1699
  return {
1689
- plugin: async (ctx, err) => {
1690
- handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
1691
- },
1692
- meta: bindingifyPluginHookMeta(meta)
1700
+ changed,
1701
+ context,
1702
+ output: transformToOutputBundle(context, unwrapBindingResult(bundle), changed)
1693
1703
  };
1694
1704
  }
1695
1705
  function bindingifyGenerateBundle(args) {
1696
- const hook = args.plugin.generateBundle;
1697
- if (!hook) return {};
1698
- const { handler, meta } = normalizeHook(hook);
1699
- return {
1700
- plugin: async (ctx, bundle, isWrite, opts) => {
1701
- const changed = {
1702
- updated: /* @__PURE__ */ new Set(),
1703
- deleted: /* @__PURE__ */ new Set()
1704
- };
1705
- const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1706
- const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1707
- await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
1708
- return collectChangedBundle(changed, output);
1709
- },
1710
- meta: bindingifyPluginHookMeta(meta)
1711
- };
1706
+ return bindingifyHook(args.plugin.generateBundle, ({ handler }) => ({ plugin: async (ctx, bundle, isWrite, opts) => {
1707
+ const { changed, context, output } = createOutputBundle(args, ctx, bundle);
1708
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
1709
+ return collectChangedBundle(changed, output);
1710
+ } }));
1712
1711
  }
1713
1712
  function bindingifyWriteBundle(args) {
1714
- const hook = args.plugin.writeBundle;
1715
- if (!hook) return {};
1716
- const { handler, meta } = normalizeHook(hook);
1717
- return {
1718
- plugin: async (ctx, bundle, opts) => {
1719
- const changed = {
1720
- updated: /* @__PURE__ */ new Set(),
1721
- deleted: /* @__PURE__ */ new Set()
1722
- };
1723
- const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1724
- const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1725
- await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
1726
- return collectChangedBundle(changed, output);
1727
- },
1728
- meta: bindingifyPluginHookMeta(meta)
1729
- };
1713
+ return bindingifyHook(args.plugin.writeBundle, ({ handler }) => ({ plugin: async (ctx, bundle, opts) => {
1714
+ const { changed, context, output } = createOutputBundle(args, ctx, bundle);
1715
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
1716
+ return collectChangedBundle(changed, output);
1717
+ } }));
1730
1718
  }
1731
1719
  function bindingifyCloseBundle(args) {
1732
- const hook = args.plugin.closeBundle;
1733
- if (!hook) return {};
1734
- const { handler, meta } = normalizeHook(hook);
1735
- return {
1736
- plugin: async (ctx, err) => {
1737
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1738
- },
1739
- meta: bindingifyPluginHookMeta(meta)
1740
- };
1741
- }
1742
- function bindingifyBanner(args) {
1743
- const hook = args.plugin.banner;
1744
- if (!hook) return {};
1745
- const { handler, meta } = normalizeHook(hook);
1746
- return {
1747
- plugin: async (ctx, chunk) => {
1748
- if (typeof handler === "string") return handler;
1749
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1750
- },
1751
- meta: bindingifyPluginHookMeta(meta)
1752
- };
1753
- }
1754
- function bindingifyFooter(args) {
1755
- const hook = args.plugin.footer;
1756
- if (!hook) return {};
1757
- const { handler, meta } = normalizeHook(hook);
1758
- return {
1759
- plugin: async (ctx, chunk) => {
1760
- if (typeof handler === "string") return handler;
1761
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1762
- },
1763
- meta: bindingifyPluginHookMeta(meta)
1764
- };
1720
+ return bindingifyHook(args.plugin.closeBundle, ({ handler }) => ({ plugin: async (ctx, err) => {
1721
+ await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1722
+ } }));
1765
1723
  }
1766
- function bindingifyIntro(args) {
1767
- const hook = args.plugin.intro;
1768
- if (!hook) return {};
1769
- const { handler, meta } = normalizeHook(hook);
1770
- return {
1771
- plugin: async (ctx, chunk) => {
1772
- if (typeof handler === "string") return handler;
1773
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1774
- },
1775
- meta: bindingifyPluginHookMeta(meta)
1776
- };
1777
- }
1778
- function bindingifyOutro(args) {
1779
- const hook = args.plugin.outro;
1780
- if (!hook) return {};
1781
- const { handler, meta } = normalizeHook(hook);
1782
- return {
1783
- plugin: async (ctx, chunk) => {
1784
- if (typeof handler === "string") return handler;
1785
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1786
- },
1787
- meta: bindingifyPluginHookMeta(meta)
1788
- };
1724
+ function bindingifyAddonHook(args, name) {
1725
+ return bindingifyHook(args.plugin[name], ({ handler }) => ({ plugin: async (ctx, chunk) => {
1726
+ if (typeof handler === "string") return handler;
1727
+ return handler.call(createPluginContext(args, ctx), transformRenderedChunk(chunk));
1728
+ } }));
1789
1729
  }
1790
1730
  //#endregion
1791
1731
  //#region src/plugin/bindingify-watch-hooks.ts
1732
+ function bindingifyHotUpdate(args) {
1733
+ return bindingifyHook(args.plugin.hotUpdate, ({ handler }) => ({ plugin: async (ctx, hookArgs) => {
1734
+ return await handler.call(createPluginContext(args, ctx), {
1735
+ type: hookArgs.kind,
1736
+ file: hookArgs.file,
1737
+ modules: hookArgs.modules
1738
+ }) ?? void 0;
1739
+ } }));
1740
+ }
1792
1741
  function bindingifyWatchChange(args) {
1793
- const hook = args.plugin.watchChange;
1794
- if (!hook) return {};
1795
- const { handler, meta } = normalizeHook(hook);
1796
- return {
1797
- plugin: async (ctx, id, event) => {
1798
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
1799
- },
1800
- meta: bindingifyPluginHookMeta(meta)
1801
- };
1742
+ return bindingifyHook(args.plugin.watchChange, ({ handler }) => ({ plugin: async (ctx, id, event) => {
1743
+ await handler.call(createPluginContext(args, ctx), id, { event });
1744
+ } }));
1802
1745
  }
1803
1746
  function bindingifyCloseWatcher(args) {
1804
- const hook = args.plugin.closeWatcher;
1805
- if (!hook) return {};
1806
- const { handler, meta } = normalizeHook(hook);
1807
- return {
1808
- plugin: async (ctx) => {
1809
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
1810
- },
1811
- meta: bindingifyPluginHookMeta(meta)
1812
- };
1747
+ return bindingifyHook(args.plugin.closeWatcher, ({ handler }) => ({ plugin: async (ctx) => {
1748
+ await handler.call(createPluginContext(args, ctx));
1749
+ } }));
1813
1750
  }
1814
1751
  //#endregion
1815
1752
  //#region src/plugin/generated/hook-usage.ts
@@ -1845,11 +1782,226 @@ function extractHookUsage(plugin) {
1845
1782
  if (plugin.footer) hookUsage.union(262144);
1846
1783
  if (plugin.intro) hookUsage.union(524288);
1847
1784
  if (plugin.outro) hookUsage.union(1048576);
1785
+ if (plugin.resolveFileUrl) hookUsage.union(2097152);
1786
+ if (plugin.hotUpdate) hookUsage.union(4194304);
1848
1787
  return hookUsage;
1849
1788
  }
1850
1789
  //#endregion
1790
+ //#region src/utils/plugin-timings.ts
1791
+ /**
1792
+ * Measure what plugin hooks cost, from inside the JavaScript callback.
1793
+ *
1794
+ * Internal to Rolldown. Nothing here is on a public entry point, and the measurement is not
1795
+ * offered as an API — the only consumer is the core, which pulls it while the build closes.
1796
+ *
1797
+ * The bundler core can only bracket *dispatch* and *completion*. For a hook it invokes
1798
+ * concurrently those two points are separated mostly by the queue the call waited in on
1799
+ * JavaScript's single thread, and the queue is deepest behind whichever callback is doing
1800
+ * the most work — so the hook blocking the thread dilutes its own credit while cheap hooks
1801
+ * collect credit for waiting. Ranking from those numbers reliably puts the *cheapest* hook
1802
+ * first.
1803
+ *
1804
+ * The missing quantity is when the callback began running, and that is known here. Starting
1805
+ * the clock inside the callback removes the dispatch queue by construction.
1806
+ *
1807
+ * ## `maxInFlight` decides whether a total means anything
1808
+ *
1809
+ * Entry-to-exit spans may be summed only if they never overlap. A synchronous callback
1810
+ * cannot overlap: it holds the thread until it returns. An `async` one can — it may suspend
1811
+ * at an `await` and let another call of the same hook begin, and then both spans cover the
1812
+ * same wall clock and the sum counts it twice.
1813
+ *
1814
+ * Overlap also changes what the span is measuring. A hook that awaits the bundler (say
1815
+ * `this.resolve`) spends most of its span waiting for Rust, so the number describes the
1816
+ * bundler rather than the plugin. Observed on a real build: one `resolveId` accumulated
1817
+ * ~47,000s of span inside a 44s module-loading window.
1818
+ *
1819
+ * So overlap is measured rather than assumed, per hook: `overlapMs` is the wall time
1820
+ * double counted in `ms` because two or more calls were in flight together. A hook is
1821
+ * reported with a number when that is a negligible share of its span, and named without one
1822
+ * when it is not.
1823
+ *
1824
+ * The test is deliberately a tolerance rather than "did this ever happen". A peak in-flight
1825
+ * count of 2 can mean one incidental overlap in twenty thousand calls, and discarding a
1826
+ * twelve-second measurement over that both throws away good data and makes the report
1827
+ * depend on scheduling luck — the same hook would appear in one run and vanish in the next.
1828
+ *
1829
+ * This keeps the rule the core followed — never present a number that cannot be defended —
1830
+ * while narrowing "cannot measure" from a property of the *call site* to a property of the
1831
+ * *callback*, which is where it actually lives. A hook dispatched concurrently but whose
1832
+ * body barely overlaps is measured to within the tolerance.
1833
+ *
1834
+ * A measured row is still wall time for that callback rather than CPU: a hook that awaits
1835
+ * I/O without overlapping another call of itself is charged for the wait. Excluding the
1836
+ * dispatch queue is what this buys; it does not distinguish running from awaiting.
1837
+ */
1838
+ /**
1839
+ * How much of a hook's span may be double counted before its total stops being reportable,
1840
+ * as a fraction of that span.
1841
+ */
1842
+ const OVERLAP_TOLERANCE = .01;
1843
+ /**
1844
+ * One recorder per build, keyed on the object that identifies it.
1845
+ *
1846
+ * Counters cannot be module-global. A plugin is free to run a nested `rolldown()` build of
1847
+ * its own, which finishes first; shared counters would let it flush the outer build's
1848
+ * half-accumulated totals and report a window belonging to neither.
1849
+ */
1850
+ const recorders = /* @__PURE__ */ new WeakMap();
1851
+ /** The recorder for one build, created on first use. */
1852
+ function pluginTimingsRecorderFor(key) {
1853
+ let recorder = recorders.get(key);
1854
+ if (recorder === void 0) {
1855
+ recorder = {
1856
+ costs: /* @__PURE__ */ new Map(),
1857
+ busyMs: 0,
1858
+ inFlight: 0,
1859
+ busyStart: 0
1860
+ };
1861
+ recorders.set(key, recorder);
1862
+ }
1863
+ return recorder;
1864
+ }
1865
+ function costFor(recorder, owner, hookName) {
1866
+ let byHook = recorder.costs.get(owner.key);
1867
+ if (byHook === void 0) {
1868
+ byHook = /* @__PURE__ */ new Map();
1869
+ recorder.costs.set(owner.key, byHook);
1870
+ }
1871
+ let cost = byHook.get(hookName);
1872
+ if (cost === void 0) {
1873
+ cost = {
1874
+ owner: owner.name,
1875
+ kind: owner.kind,
1876
+ hookName,
1877
+ calls: 0,
1878
+ ms: 0,
1879
+ inFlight: 0,
1880
+ maxInFlight: 0,
1881
+ overlapMs: 0,
1882
+ lastChange: 0
1883
+ };
1884
+ byHook.set(hookName, cost);
1885
+ }
1886
+ return cost;
1887
+ }
1888
+ /**
1889
+ * Fold the interval since the last in-flight change into `overlapMs`, then move the mark.
1890
+ * Call immediately before every increment and decrement of `cost.inFlight`.
1891
+ */
1892
+ function markInFlightChange(cost, at) {
1893
+ if (cost.inFlight > 1) cost.overlapMs += (cost.inFlight - 1) * (at - cost.lastChange);
1894
+ cost.lastChange = at;
1895
+ }
1896
+ /**
1897
+ * Close out one call. A module-level function rather than a closure per invocation: hooks
1898
+ * run hundreds of thousands of times in a large build, and the synchronous path would
1899
+ * otherwise allocate one closure per call only to invoke it immediately.
1900
+ */
1901
+ function settle(recorder, cost, started) {
1902
+ const ended = performance.now();
1903
+ markInFlightChange(cost, ended);
1904
+ cost.inFlight -= 1;
1905
+ cost.ms += ended - started;
1906
+ recorder.inFlight -= 1;
1907
+ if (recorder.inFlight === 0) recorder.busyMs += ended - recorder.busyStart;
1908
+ }
1909
+ /**
1910
+ * Wrap one callback so its execution time is recorded.
1911
+ *
1912
+ * Returns the callback untouched when there is no recorder, so a build that is not
1913
+ * measuring pays nothing beyond one branch at setup.
1914
+ */
1915
+ function measureHookCost(recorder, owner, hookName, handler) {
1916
+ if (recorder === void 0) return handler;
1917
+ const cost = costFor(recorder, owner, hookName);
1918
+ return function(...args) {
1919
+ const started = performance.now();
1920
+ markInFlightChange(cost, started);
1921
+ cost.calls += 1;
1922
+ cost.inFlight += 1;
1923
+ if (cost.inFlight > cost.maxInFlight) cost.maxInFlight = cost.inFlight;
1924
+ if (recorder.inFlight === 0) recorder.busyStart = started;
1925
+ recorder.inFlight += 1;
1926
+ let result;
1927
+ try {
1928
+ result = handler.apply(this, args);
1929
+ } catch (error) {
1930
+ settle(recorder, cost, started);
1931
+ throw error;
1932
+ }
1933
+ if (typeof result?.then === "function") return result.then((value) => {
1934
+ settle(recorder, cost, started);
1935
+ return value;
1936
+ }, (error) => {
1937
+ settle(recorder, cost, started);
1938
+ throw error;
1939
+ });
1940
+ settle(recorder, cost, started);
1941
+ return result;
1942
+ };
1943
+ }
1944
+ /**
1945
+ * The owner shown for user callbacks the core invokes directly rather than through a
1946
+ * plugin. One shared identity: they are all configured on the same options object.
1947
+ */
1948
+ const OUTPUT_OPTIONS_OWNER = {
1949
+ key: Symbol("output options"),
1950
+ name: "output options",
1951
+ kind: "outputOption"
1952
+ };
1953
+ /** As {@link OUTPUT_OPTIONS_OWNER}, for callbacks configured on the input options. */
1954
+ const INPUT_OPTIONS_OWNER = {
1955
+ key: Symbol("input options"),
1956
+ name: "input options",
1957
+ kind: "inputOption"
1958
+ };
1959
+ /**
1960
+ * Wrap `value` when the user supplied a function, and leave every other form alone.
1961
+ *
1962
+ * Most option callbacks are declared as `string | RegExp | Function | ...`, so this keeps
1963
+ * the one cast the wrapping needs in a single place.
1964
+ */
1965
+ function measureIfFunction(recorder, owner, hookName, value) {
1966
+ if (typeof value !== "function") return value;
1967
+ return measureHookCost(recorder, owner, hookName, value);
1968
+ }
1969
+ /**
1970
+ * What the build's callbacks have cost so far, leaving the recorder in place.
1971
+ *
1972
+ * Ungated on purpose: whether a build is worth reporting on is decided from the clocks Rust
1973
+ * holds, so the question is not this side's to ask.
1974
+ *
1975
+ * Rust calls this while the build is closing, so what it gets includes `closeBundle`.
1976
+ */
1977
+ function summarizePluginTimings(key) {
1978
+ const recorder = recorders.get(key);
1979
+ if (recorder === void 0) return {
1980
+ busyMs: 0,
1981
+ rows: []
1982
+ };
1983
+ const rows = [];
1984
+ for (const byHook of recorder.costs.values()) for (const cost of byHook.values()) {
1985
+ if (cost.calls === 0) continue;
1986
+ rows.push({
1987
+ owner: cost.owner,
1988
+ kind: cost.kind,
1989
+ hook: cost.hookName,
1990
+ calls: cost.calls,
1991
+ ms: cost.ms,
1992
+ maxInFlight: cost.maxInFlight,
1993
+ overlapMs: cost.overlapMs,
1994
+ rankable: cost.overlapMs <= cost.ms * OVERLAP_TOLERANCE
1995
+ });
1996
+ }
1997
+ return {
1998
+ busyMs: recorder.busyMs,
1999
+ rows
2000
+ };
2001
+ }
2002
+ //#endregion
1851
2003
  //#region src/plugin/bindingify-plugin.ts
1852
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
2004
+ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings) {
1853
2005
  const args = {
1854
2006
  plugin,
1855
2007
  options,
@@ -1869,19 +2021,21 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
1869
2021
  const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1870
2022
  const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
1871
2023
  const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
2024
+ const { plugin: resolveFileUrl, meta: resolveFileUrlMeta } = bindingifyResolveFileUrl(args);
1872
2025
  const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1873
2026
  const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1874
2027
  const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1875
2028
  const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1876
2029
  const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1877
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1878
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1879
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1880
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
2030
+ const { plugin: banner, meta: bannerMeta } = bindingifyAddonHook(args, "banner");
2031
+ const { plugin: footer, meta: footerMeta } = bindingifyAddonHook(args, "footer");
2032
+ const { plugin: intro, meta: introMeta } = bindingifyAddonHook(args, "intro");
2033
+ const { plugin: outro, meta: outroMeta } = bindingifyAddonHook(args, "outro");
1881
2034
  const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
2035
+ const { plugin: hotUpdate, meta: hotUpdateMeta } = bindingifyHotUpdate(args);
1882
2036
  const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1883
2037
  let hookUsage = extractHookUsage(plugin).inner();
1884
- return wrapHandlers({
2038
+ const result = {
1885
2039
  name: plugin.name,
1886
2040
  buildStart,
1887
2041
  buildStartMeta,
@@ -1905,6 +2059,8 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
1905
2059
  renderChunkFilter,
1906
2060
  augmentChunkHash,
1907
2061
  augmentChunkHashMeta,
2062
+ resolveFileUrl,
2063
+ resolveFileUrlMeta,
1908
2064
  renderStart,
1909
2065
  renderStartMeta,
1910
2066
  renderError,
@@ -1925,12 +2081,19 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
1925
2081
  outroMeta,
1926
2082
  watchChange,
1927
2083
  watchChangeMeta,
2084
+ hotUpdate,
2085
+ hotUpdateMeta,
1928
2086
  closeWatcher,
1929
2087
  closeWatcherMeta,
1930
2088
  hookUsage
1931
- });
2089
+ };
2090
+ return wrapHandlers(result, {
2091
+ key: plugin,
2092
+ name: result.name,
2093
+ kind: "plugin"
2094
+ }, timings);
1932
2095
  }
1933
- function wrapHandlers(plugin) {
2096
+ function wrapHandlers(plugin, owner, timings) {
1934
2097
  for (const hookName of [
1935
2098
  "buildStart",
1936
2099
  "resolveId",
@@ -1941,6 +2104,7 @@ function wrapHandlers(plugin) {
1941
2104
  "load",
1942
2105
  "renderChunk",
1943
2106
  "augmentChunkHash",
2107
+ "resolveFileUrl",
1944
2108
  "renderStart",
1945
2109
  "renderError",
1946
2110
  "generateBundle",
@@ -1951,9 +2115,11 @@ function wrapHandlers(plugin) {
1951
2115
  "intro",
1952
2116
  "outro",
1953
2117
  "watchChange",
2118
+ "hotUpdate",
1954
2119
  "closeWatcher"
1955
2120
  ]) {
1956
- const handler = plugin[hookName];
2121
+ const raw = plugin[hookName];
2122
+ const handler = raw && measureHookCost(timings, owner, hookName, raw);
1957
2123
  if (handler) plugin[hookName] = async (...args) => {
1958
2124
  try {
1959
2125
  return await handler(...args);
@@ -1995,28 +2161,36 @@ function normalizeTransformOptions(inputOptions) {
1995
2161
  };
1996
2162
  }
1997
2163
  //#endregion
2164
+ //#region src/utils/default-dev-runtime.ts
2165
+ function getDefaultDevRuntime(host = "localhost", port = 3e3) {
2166
+ const runtimeEntry = fs.readFileSync(fileURLToPath(import.meta.resolve("#runtime")), "utf8");
2167
+ const runtimeHelperImportEnd = runtimeEntry.indexOf("\n");
2168
+ if (!runtimeEntry.startsWith("import ") || runtimeHelperImportEnd === -1) throw new Error("Expected the standalone runtime to start with a helper import");
2169
+ return `${runtimeEntry.slice(runtimeHelperImportEnd + 1)}\n${fs.readFileSync(fileURLToPath(import.meta.resolve("#default-runtime")), "utf8").replaceAll("$ADDR", `${host}:${port}`)}`;
2170
+ }
2171
+ //#endregion
1998
2172
  //#region src/utils/bindingify-input-options.ts
1999
- function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
2173
+ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings) {
2000
2174
  const plugins = rawPlugins.map((plugin) => {
2001
- if ("_parallel" in plugin) return;
2175
+ if (getParallelPluginInfo(plugin)) return;
2002
2176
  if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
2003
2177
  case "builtin:vite-manifest": return bindingifyManifestPlugin(plugin, pluginContextData);
2004
2178
  default: return bindingifyBuiltInPlugin(plugin);
2005
2179
  }
2006
- return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
2180
+ return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings);
2007
2181
  });
2008
2182
  const normalizedTransform = normalizeTransformOptions(inputOptions);
2009
2183
  return {
2010
2184
  input: bindingifyInput(inputOptions.input),
2011
2185
  plugins,
2012
2186
  cwd: inputOptions.cwd ?? process.cwd(),
2013
- external: bindingifyExternal(inputOptions.external),
2187
+ external: bindingifyExternal(inputOptions.external, timings),
2014
2188
  resolve: bindingifyResolve(inputOptions.resolve),
2015
2189
  platform: inputOptions.platform,
2016
2190
  shimMissingExports: inputOptions.shimMissingExports,
2017
2191
  logLevel: bindingifyLogLevel(logLevel),
2018
2192
  onLog,
2019
- treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
2193
+ treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake, timings),
2020
2194
  moduleTypes: inputOptions.moduleTypes,
2021
2195
  define: normalizedTransform.define,
2022
2196
  inject: bindingifyInject(normalizedTransform.inject),
@@ -2027,6 +2201,7 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginC
2027
2201
  dropLabels: normalizedTransform.dropLabels,
2028
2202
  keepNames: outputOptions.keepNames,
2029
2203
  checks: inputOptions.checks,
2204
+ pluginTimings: timings ? () => summarizePluginTimings(inputOptions) : void 0,
2030
2205
  deferSyncScanData: () => {
2031
2206
  let ret = [];
2032
2207
  pluginContextData.moduleOptionMap.forEach((value, key) => {
@@ -2048,8 +2223,16 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginC
2048
2223
  }
2049
2224
  function bindingifyDevMode(devMode) {
2050
2225
  if (devMode) {
2051
- if (typeof devMode === "boolean") return devMode ? {} : void 0;
2052
- return devMode;
2226
+ if (typeof devMode === "boolean") return devMode ? {
2227
+ implement: getDefaultDevRuntime(),
2228
+ skipCommonRuntimeInjection: true
2229
+ } : void 0;
2230
+ const usesDefaultRuntime = devMode.implement == null;
2231
+ return {
2232
+ ...devMode,
2233
+ implement: devMode.implement ?? getDefaultDevRuntime(devMode.host, devMode.port),
2234
+ skipCommonRuntimeInjection: usesDefaultRuntime ? true : devMode.skipCommonRuntimeInjection
2235
+ };
2053
2236
  }
2054
2237
  }
2055
2238
  function bindingifyAttachDebugInfo(attachDebugInfo) {
@@ -2060,12 +2243,15 @@ function bindingifyAttachDebugInfo(attachDebugInfo) {
2060
2243
  case "none": return import_binding.BindingAttachDebugInfo.None;
2061
2244
  }
2062
2245
  }
2063
- function bindingifyExternal(external) {
2246
+ function bindingifyExternal(external, timings) {
2064
2247
  if (external) {
2065
- if (typeof external === "function") return (id, importer, isResolved) => {
2066
- if (id.startsWith("\0")) return false;
2067
- return external(id, importer, isResolved) ?? false;
2068
- };
2248
+ if (typeof external === "function") {
2249
+ const measured = measureHookCost(timings, INPUT_OPTIONS_OWNER, "external", external);
2250
+ return (id, importer, isResolved) => {
2251
+ if (id.startsWith("\0")) return false;
2252
+ return measured(id, importer, isResolved) ?? false;
2253
+ };
2254
+ }
2069
2255
  return arraify(external);
2070
2256
  }
2071
2257
  }
@@ -2176,7 +2362,7 @@ function bindingifyWatch(watch) {
2176
2362
  };
2177
2363
  }
2178
2364
  }
2179
- function bindingifyTreeshakeOptions(config) {
2365
+ function bindingifyTreeshakeOptions(config, timings) {
2180
2366
  if (config === false) return;
2181
2367
  if (config === true || config === void 0) return { moduleSideEffects: true };
2182
2368
  let normalizedConfig = {
@@ -2191,19 +2377,13 @@ function bindingifyTreeshakeOptions(config) {
2191
2377
  case "always":
2192
2378
  normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
2193
2379
  break;
2194
- case false:
2195
- normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
2196
- break;
2197
- default:
2380
+ case false: normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
2198
2381
  }
2199
2382
  switch (config.propertyWriteSideEffects) {
2200
2383
  case "always":
2201
2384
  normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
2202
2385
  break;
2203
- case false:
2204
- normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
2205
- break;
2206
- default:
2386
+ case false: normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
2207
2387
  }
2208
2388
  if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
2209
2389
  else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
@@ -2213,7 +2393,7 @@ function bindingifyTreeshakeOptions(config) {
2213
2393
  external: false,
2214
2394
  sideEffects: true
2215
2395
  }];
2216
- else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
2396
+ else normalizedConfig.moduleSideEffects = measureIfFunction(timings, INPUT_OPTIONS_OWNER, "treeshake.moduleSideEffects", config.moduleSideEffects);
2217
2397
  return normalizedConfig;
2218
2398
  }
2219
2399
  function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
@@ -2235,4 +2415,4 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
2235
2415
  };
2236
2416
  }
2237
2417
  //#endregion
2238
- export { version as S, LOG_LEVEL_INFO as _, transformModuleInfo as a, VERSION as b, __decorate as c, PlainObjectLike as d, MinimalPluginContextImpl as f, LOG_LEVEL_ERROR as g, LOG_LEVEL_DEBUG as h, PluginContextData as i, transformAssetSource as l, normalizeLog as m, bindingifyPlugin as n, transformToRollupOutput as o, normalizeHook as p, RolldownMagicString as r, transformRenderedChunk as s, bindingifyInputOptions as t, lazyProp as u, LOG_LEVEL_WARN as v, description as x, logLevelPriority as y };
2418
+ export { LOG_LEVEL_WARN as C, version as D, description as E, LOG_LEVEL_INFO as S, VERSION as T, getParallelPluginInfo as _, measureIfFunction as a, LOG_LEVEL_DEBUG as b, PluginContextData as c, transformRenderedChunk as d, __decorate as f, MinimalPluginContextImpl as g, PlainObjectLike as h, measureHookCost as i, transformModuleInfo as l, lazyProp as m, bindingifyPlugin as n, pluginTimingsRecorderFor as o, transformAssetSource as p, OUTPUT_OPTIONS_OWNER as r, RolldownMagicString as s, bindingifyInputOptions as t, transformToRollupOutput as u, normalizeHook as v, logLevelPriority as w, LOG_LEVEL_ERROR as x, normalizeLog as y };