@rollipop/rolldown 1.0.25 → 1.0.27
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.
- package/THIRD-PARTY-LICENSE +33 -0
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +17 -14
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +2 -2
- package/dist/experimental-default-runtime.mjs +116 -0
- package/dist/experimental-index.d.mts +10 -4
- package/dist/experimental-index.mjs +32 -16
- package/dist/experimental-runtime-base.mjs +95 -0
- package/dist/experimental-runtime.d.ts +177 -0
- package/dist/experimental-runtime.mjs +257 -0
- package/dist/filter-index.d.mts +1 -1
- package/dist/filter-index.mjs +1 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/parallel-plugin-worker.d.mts +1 -1
- package/dist/parallel-plugin-worker.mjs +3 -3
- package/dist/parallel-plugin.d.mts +1 -1
- package/dist/parse-ast-index.d.mts +1 -1
- package/dist/parse-ast-index.mjs +2 -2
- package/dist/plugins-index.d.mts +3 -3
- package/dist/plugins-index.mjs +2 -2
- package/dist/shared/binding-CuB3cgML.mjs +679 -0
- package/dist/shared/{binding-CyCKfYSu.d.mts → binding-We_IfeZk.d.mts} +11 -0
- package/dist/shared/{bindingify-input-options-CkSiXecU.mjs → bindingify-input-options-Cp0kpzhL.mjs} +453 -283
- package/dist/shared/{constructors-CEYV9FDo.mjs → constructors-CUnQrTUN.mjs} +10 -6
- package/dist/shared/{constructors-B1v9buY3.d.mts → constructors-dwVL6FXl.d.mts} +2 -2
- package/dist/shared/{rolldown-build-Cy0C2jvD.mjs → create-bundler-option-CAx_5u9x.mjs} +72 -179
- package/dist/shared/{define-config-JSiTCvYA.d.mts → define-config-D7NdzfP7.d.mts} +86 -27
- package/dist/shared/{error-pMeQY3Ie.mjs → error-BdMRRSIe.mjs} +1 -1
- package/dist/shared/{load-config-BAsjK_il.mjs → load-config-Bh1CAJT7.mjs} +2 -2
- package/dist/shared/{logs-ZGEh6uhb.mjs → logs-DmYCAKcW.mjs} +8 -1
- package/dist/shared/{misc-CoQm4NHO.mjs → misc-DOSKtd97.mjs} +9 -1
- package/dist/shared/{normalize-string-or-regex-CSHtENP1.mjs → normalize-string-or-regex-Bp8lvaXp.mjs} +2 -2
- package/dist/shared/{parse-BEeauYyL.mjs → parse-Be-cJD0d.mjs} +2 -2
- package/dist/shared/{prompt--dNycKSZ.mjs → prompt-CH6TK0bC.mjs} +2 -6
- package/dist/shared/{resolve-tsconfig-upebNbwm.mjs → resolve-tsconfig-CzlObluk.mjs} +2 -2
- package/dist/shared/rolldown-BTyqb0Av.mjs +178 -0
- package/dist/shared/{transform-DJLP9UUk.d.mts → transform-CsZGbS4Q.d.mts} +1 -1
- package/dist/shared/{watch-BLrLOBAp.mjs → watch-BA13XFgy.mjs} +17 -14
- package/dist/utils-index.d.mts +3 -3
- package/dist/utils-index.mjs +16 -16
- package/package.json +26 -16
- package/dist/shared/binding-DnitnDvS.mjs +0 -594
- package/dist/shared/rolldown-DHWEkE2v.mjs +0 -40
package/dist/shared/{bindingify-input-options-CkSiXecU.mjs → bindingify-input-options-Cp0kpzhL.mjs}
RENAMED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { n as __toESM, t as require_binding } from "./binding-
|
|
2
|
-
import {
|
|
3
|
-
import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-
|
|
4
|
-
import {
|
|
5
|
-
import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./binding-CuB3cgML.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-Bp8lvaXp.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-BdMRRSIe.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.0.
|
|
13
|
+
var version = "1.0.27";
|
|
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.
|
|
239
|
+
//#region \0@oxc-project+runtime@0.143.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
|
-
|
|
1164
|
-
|
|
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")
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
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
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
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
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,45 +1596,24 @@ function preProcessSourceMap(ret, id) {
|
|
|
1575
1596
|
return map;
|
|
1576
1597
|
}
|
|
1577
1598
|
function bindingifyModuleParsed(args) {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
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
|
function bindingifyTransformCacheHit(args) {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
return {
|
|
1593
|
-
plugin: async (ctx, id) => {
|
|
1594
|
-
await handler.call(createPluginContext(args, ctx), id);
|
|
1595
|
-
},
|
|
1596
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1597
|
-
};
|
|
1604
|
+
return bindingifyHook(args.plugin.transformCacheHit, ({ handler }) => ({ plugin: async (ctx, id) => {
|
|
1605
|
+
await handler.call(createPluginContext(args, ctx), id);
|
|
1606
|
+
} }));
|
|
1598
1607
|
}
|
|
1599
1608
|
//#endregion
|
|
1600
1609
|
//#region src/plugin/bindingify-output-hooks.ts
|
|
1601
1610
|
function bindingifyRenderStart(args) {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
return {
|
|
1606
|
-
plugin: async (ctx, opts) => {
|
|
1607
|
-
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));
|
|
1608
|
-
},
|
|
1609
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1610
|
-
};
|
|
1611
|
+
return bindingifyHook(args.plugin.renderStart, ({ handler }) => ({ plugin: async (ctx, opts) => {
|
|
1612
|
+
await handler.call(createPluginContext(args, ctx), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
|
|
1613
|
+
} }));
|
|
1611
1614
|
}
|
|
1612
1615
|
function bindingifyRenderChunk(args) {
|
|
1613
|
-
|
|
1614
|
-
if (!hook) return {};
|
|
1615
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
1616
|
-
return {
|
|
1616
|
+
return bindingifyHook(args.plugin.renderChunk, ({ handler, options }) => ({
|
|
1617
1617
|
plugin: async (ctx, code, chunk, opts, meta) => {
|
|
1618
1618
|
if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
|
|
1619
1619
|
const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
|
|
@@ -1626,7 +1626,7 @@ function bindingifyRenderChunk(args) {
|
|
|
1626
1626
|
},
|
|
1627
1627
|
configurable: true
|
|
1628
1628
|
});
|
|
1629
|
-
const ret = await handler.call(
|
|
1629
|
+
const ret = await handler.call(createPluginContext(args, ctx), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
|
|
1630
1630
|
if (ret == null) return;
|
|
1631
1631
|
if (ret instanceof RolldownMagicString) {
|
|
1632
1632
|
const normalizedCode = ret.toString();
|
|
@@ -1677,150 +1677,81 @@ function bindingifyRenderChunk(args) {
|
|
|
1677
1677
|
map: bindingifySourcemap(ret.map)
|
|
1678
1678
|
};
|
|
1679
1679
|
},
|
|
1680
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
1681
1680
|
filter: bindingifyRenderChunkFilter(options.filter)
|
|
1682
|
-
};
|
|
1681
|
+
}));
|
|
1683
1682
|
}
|
|
1684
1683
|
function bindingifyAugmentChunkHash(args) {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
};
|
|
1684
|
+
return bindingifyHook(args.plugin.augmentChunkHash, ({ handler }) => ({ plugin: async (ctx, chunk) => {
|
|
1685
|
+
return handler.call(createPluginContext(args, ctx), transformRenderedChunk(chunk));
|
|
1686
|
+
} }));
|
|
1687
|
+
}
|
|
1688
|
+
function bindingifyResolveFileUrl(args) {
|
|
1689
|
+
return bindingifyHook(args.plugin.resolveFileUrl, ({ handler }) => ({ plugin: async (ctx, resolveFileUrlArgs) => {
|
|
1690
|
+
return handler.call(createPluginContext(args, ctx), resolveFileUrlArgs);
|
|
1691
|
+
} }));
|
|
1694
1692
|
}
|
|
1695
1693
|
function bindingifyRenderError(args) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1694
|
+
return bindingifyHook(args.plugin.renderError, ({ handler }) => ({ plugin: async (ctx, err) => {
|
|
1695
|
+
await handler.call(createPluginContext(args, ctx), aggregateBindingErrorsIntoJsError(err));
|
|
1696
|
+
} }));
|
|
1697
|
+
}
|
|
1698
|
+
function createOutputBundle(args, ctx, bundle) {
|
|
1699
|
+
const changed = {
|
|
1700
|
+
updated: /* @__PURE__ */ new Set(),
|
|
1701
|
+
deleted: /* @__PURE__ */ new Set()
|
|
1702
|
+
};
|
|
1703
|
+
const context = createPluginContext(args, ctx);
|
|
1699
1704
|
return {
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1705
|
+
changed,
|
|
1706
|
+
context,
|
|
1707
|
+
output: transformToOutputBundle(context, unwrapBindingResult(bundle), changed)
|
|
1704
1708
|
};
|
|
1705
1709
|
}
|
|
1706
1710
|
function bindingifyGenerateBundle(args) {
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
const changed = {
|
|
1713
|
-
updated: /* @__PURE__ */ new Set(),
|
|
1714
|
-
deleted: /* @__PURE__ */ new Set()
|
|
1715
|
-
};
|
|
1716
|
-
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1717
|
-
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1718
|
-
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
1719
|
-
return collectChangedBundle(changed, output);
|
|
1720
|
-
},
|
|
1721
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1722
|
-
};
|
|
1711
|
+
return bindingifyHook(args.plugin.generateBundle, ({ handler }) => ({ plugin: async (ctx, bundle, isWrite, opts) => {
|
|
1712
|
+
const { changed, context, output } = createOutputBundle(args, ctx, bundle);
|
|
1713
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
1714
|
+
return collectChangedBundle(changed, output);
|
|
1715
|
+
} }));
|
|
1723
1716
|
}
|
|
1724
1717
|
function bindingifyWriteBundle(args) {
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
const changed = {
|
|
1731
|
-
updated: /* @__PURE__ */ new Set(),
|
|
1732
|
-
deleted: /* @__PURE__ */ new Set()
|
|
1733
|
-
};
|
|
1734
|
-
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1735
|
-
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1736
|
-
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
|
|
1737
|
-
return collectChangedBundle(changed, output);
|
|
1738
|
-
},
|
|
1739
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1740
|
-
};
|
|
1718
|
+
return bindingifyHook(args.plugin.writeBundle, ({ handler }) => ({ plugin: async (ctx, bundle, opts) => {
|
|
1719
|
+
const { changed, context, output } = createOutputBundle(args, ctx, bundle);
|
|
1720
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
|
|
1721
|
+
return collectChangedBundle(changed, output);
|
|
1722
|
+
} }));
|
|
1741
1723
|
}
|
|
1742
1724
|
function bindingifyCloseBundle(args) {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
return {
|
|
1747
|
-
plugin: async (ctx, err) => {
|
|
1748
|
-
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1749
|
-
},
|
|
1750
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1751
|
-
};
|
|
1725
|
+
return bindingifyHook(args.plugin.closeBundle, ({ handler }) => ({ plugin: async (ctx, err) => {
|
|
1726
|
+
await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1727
|
+
} }));
|
|
1752
1728
|
}
|
|
1753
|
-
function
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
plugin: async (ctx, chunk) => {
|
|
1759
|
-
if (typeof handler === "string") return handler;
|
|
1760
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1761
|
-
},
|
|
1762
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1763
|
-
};
|
|
1764
|
-
}
|
|
1765
|
-
function bindingifyFooter(args) {
|
|
1766
|
-
const hook = args.plugin.footer;
|
|
1767
|
-
if (!hook) return {};
|
|
1768
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1769
|
-
return {
|
|
1770
|
-
plugin: async (ctx, chunk) => {
|
|
1771
|
-
if (typeof handler === "string") return handler;
|
|
1772
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1773
|
-
},
|
|
1774
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
function bindingifyIntro(args) {
|
|
1778
|
-
const hook = args.plugin.intro;
|
|
1779
|
-
if (!hook) return {};
|
|
1780
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1781
|
-
return {
|
|
1782
|
-
plugin: async (ctx, chunk) => {
|
|
1783
|
-
if (typeof handler === "string") return handler;
|
|
1784
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1785
|
-
},
|
|
1786
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
function bindingifyOutro(args) {
|
|
1790
|
-
const hook = args.plugin.outro;
|
|
1791
|
-
if (!hook) return {};
|
|
1792
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1793
|
-
return {
|
|
1794
|
-
plugin: async (ctx, chunk) => {
|
|
1795
|
-
if (typeof handler === "string") return handler;
|
|
1796
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1797
|
-
},
|
|
1798
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1799
|
-
};
|
|
1729
|
+
function bindingifyAddonHook(args, name) {
|
|
1730
|
+
return bindingifyHook(args.plugin[name], ({ handler }) => ({ plugin: async (ctx, chunk) => {
|
|
1731
|
+
if (typeof handler === "string") return handler;
|
|
1732
|
+
return handler.call(createPluginContext(args, ctx), transformRenderedChunk(chunk));
|
|
1733
|
+
} }));
|
|
1800
1734
|
}
|
|
1801
1735
|
//#endregion
|
|
1802
1736
|
//#region src/plugin/bindingify-watch-hooks.ts
|
|
1737
|
+
function bindingifyHotUpdate(args) {
|
|
1738
|
+
return bindingifyHook(args.plugin.hotUpdate, ({ handler }) => ({ plugin: async (ctx, hookArgs) => {
|
|
1739
|
+
return await handler.call(createPluginContext(args, ctx), {
|
|
1740
|
+
type: hookArgs.kind,
|
|
1741
|
+
file: hookArgs.file,
|
|
1742
|
+
modules: hookArgs.modules
|
|
1743
|
+
}) ?? void 0;
|
|
1744
|
+
} }));
|
|
1745
|
+
}
|
|
1803
1746
|
function bindingifyWatchChange(args) {
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
return {
|
|
1808
|
-
plugin: async (ctx, id, event) => {
|
|
1809
|
-
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
|
|
1810
|
-
},
|
|
1811
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1812
|
-
};
|
|
1747
|
+
return bindingifyHook(args.plugin.watchChange, ({ handler }) => ({ plugin: async (ctx, id, event) => {
|
|
1748
|
+
await handler.call(createPluginContext(args, ctx), id, { event });
|
|
1749
|
+
} }));
|
|
1813
1750
|
}
|
|
1814
1751
|
function bindingifyCloseWatcher(args) {
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
return {
|
|
1819
|
-
plugin: async (ctx) => {
|
|
1820
|
-
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
|
|
1821
|
-
},
|
|
1822
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1823
|
-
};
|
|
1752
|
+
return bindingifyHook(args.plugin.closeWatcher, ({ handler }) => ({ plugin: async (ctx) => {
|
|
1753
|
+
await handler.call(createPluginContext(args, ctx));
|
|
1754
|
+
} }));
|
|
1824
1755
|
}
|
|
1825
1756
|
//#endregion
|
|
1826
1757
|
//#region src/plugin/generated/hook-usage.ts
|
|
@@ -1856,12 +1787,227 @@ function extractHookUsage(plugin) {
|
|
|
1856
1787
|
if (plugin.footer) hookUsage.union(262144);
|
|
1857
1788
|
if (plugin.intro) hookUsage.union(524288);
|
|
1858
1789
|
if (plugin.outro) hookUsage.union(1048576);
|
|
1859
|
-
if (plugin.
|
|
1790
|
+
if (plugin.resolveFileUrl) hookUsage.union(2097152);
|
|
1791
|
+
if (plugin.hotUpdate) hookUsage.union(4194304);
|
|
1792
|
+
if (plugin.transformCacheHit) hookUsage.union(8388608);
|
|
1860
1793
|
return hookUsage;
|
|
1861
1794
|
}
|
|
1862
1795
|
//#endregion
|
|
1796
|
+
//#region src/utils/plugin-timings.ts
|
|
1797
|
+
/**
|
|
1798
|
+
* Measure what plugin hooks cost, from inside the JavaScript callback.
|
|
1799
|
+
*
|
|
1800
|
+
* Internal to Rolldown. Nothing here is on a public entry point, and the measurement is not
|
|
1801
|
+
* offered as an API — the only consumer is the core, which pulls it while the build closes.
|
|
1802
|
+
*
|
|
1803
|
+
* The bundler core can only bracket *dispatch* and *completion*. For a hook it invokes
|
|
1804
|
+
* concurrently those two points are separated mostly by the queue the call waited in on
|
|
1805
|
+
* JavaScript's single thread, and the queue is deepest behind whichever callback is doing
|
|
1806
|
+
* the most work — so the hook blocking the thread dilutes its own credit while cheap hooks
|
|
1807
|
+
* collect credit for waiting. Ranking from those numbers reliably puts the *cheapest* hook
|
|
1808
|
+
* first.
|
|
1809
|
+
*
|
|
1810
|
+
* The missing quantity is when the callback began running, and that is known here. Starting
|
|
1811
|
+
* the clock inside the callback removes the dispatch queue by construction.
|
|
1812
|
+
*
|
|
1813
|
+
* ## `maxInFlight` decides whether a total means anything
|
|
1814
|
+
*
|
|
1815
|
+
* Entry-to-exit spans may be summed only if they never overlap. A synchronous callback
|
|
1816
|
+
* cannot overlap: it holds the thread until it returns. An `async` one can — it may suspend
|
|
1817
|
+
* at an `await` and let another call of the same hook begin, and then both spans cover the
|
|
1818
|
+
* same wall clock and the sum counts it twice.
|
|
1819
|
+
*
|
|
1820
|
+
* Overlap also changes what the span is measuring. A hook that awaits the bundler (say
|
|
1821
|
+
* `this.resolve`) spends most of its span waiting for Rust, so the number describes the
|
|
1822
|
+
* bundler rather than the plugin. Observed on a real build: one `resolveId` accumulated
|
|
1823
|
+
* ~47,000s of span inside a 44s module-loading window.
|
|
1824
|
+
*
|
|
1825
|
+
* So overlap is measured rather than assumed, per hook: `overlapMs` is the wall time
|
|
1826
|
+
* double counted in `ms` because two or more calls were in flight together. A hook is
|
|
1827
|
+
* reported with a number when that is a negligible share of its span, and named without one
|
|
1828
|
+
* when it is not.
|
|
1829
|
+
*
|
|
1830
|
+
* The test is deliberately a tolerance rather than "did this ever happen". A peak in-flight
|
|
1831
|
+
* count of 2 can mean one incidental overlap in twenty thousand calls, and discarding a
|
|
1832
|
+
* twelve-second measurement over that both throws away good data and makes the report
|
|
1833
|
+
* depend on scheduling luck — the same hook would appear in one run and vanish in the next.
|
|
1834
|
+
*
|
|
1835
|
+
* This keeps the rule the core followed — never present a number that cannot be defended —
|
|
1836
|
+
* while narrowing "cannot measure" from a property of the *call site* to a property of the
|
|
1837
|
+
* *callback*, which is where it actually lives. A hook dispatched concurrently but whose
|
|
1838
|
+
* body barely overlaps is measured to within the tolerance.
|
|
1839
|
+
*
|
|
1840
|
+
* A measured row is still wall time for that callback rather than CPU: a hook that awaits
|
|
1841
|
+
* I/O without overlapping another call of itself is charged for the wait. Excluding the
|
|
1842
|
+
* dispatch queue is what this buys; it does not distinguish running from awaiting.
|
|
1843
|
+
*/
|
|
1844
|
+
/**
|
|
1845
|
+
* How much of a hook's span may be double counted before its total stops being reportable,
|
|
1846
|
+
* as a fraction of that span.
|
|
1847
|
+
*/
|
|
1848
|
+
const OVERLAP_TOLERANCE = .01;
|
|
1849
|
+
/**
|
|
1850
|
+
* One recorder per build, keyed on the object that identifies it.
|
|
1851
|
+
*
|
|
1852
|
+
* Counters cannot be module-global. A plugin is free to run a nested `rolldown()` build of
|
|
1853
|
+
* its own, which finishes first; shared counters would let it flush the outer build's
|
|
1854
|
+
* half-accumulated totals and report a window belonging to neither.
|
|
1855
|
+
*/
|
|
1856
|
+
const recorders = /* @__PURE__ */ new WeakMap();
|
|
1857
|
+
/** The recorder for one build, created on first use. */
|
|
1858
|
+
function pluginTimingsRecorderFor(key) {
|
|
1859
|
+
let recorder = recorders.get(key);
|
|
1860
|
+
if (recorder === void 0) {
|
|
1861
|
+
recorder = {
|
|
1862
|
+
costs: /* @__PURE__ */ new Map(),
|
|
1863
|
+
busyMs: 0,
|
|
1864
|
+
inFlight: 0,
|
|
1865
|
+
busyStart: 0
|
|
1866
|
+
};
|
|
1867
|
+
recorders.set(key, recorder);
|
|
1868
|
+
}
|
|
1869
|
+
return recorder;
|
|
1870
|
+
}
|
|
1871
|
+
function costFor(recorder, owner, hookName) {
|
|
1872
|
+
let byHook = recorder.costs.get(owner.key);
|
|
1873
|
+
if (byHook === void 0) {
|
|
1874
|
+
byHook = /* @__PURE__ */ new Map();
|
|
1875
|
+
recorder.costs.set(owner.key, byHook);
|
|
1876
|
+
}
|
|
1877
|
+
let cost = byHook.get(hookName);
|
|
1878
|
+
if (cost === void 0) {
|
|
1879
|
+
cost = {
|
|
1880
|
+
owner: owner.name,
|
|
1881
|
+
kind: owner.kind,
|
|
1882
|
+
hookName,
|
|
1883
|
+
calls: 0,
|
|
1884
|
+
ms: 0,
|
|
1885
|
+
inFlight: 0,
|
|
1886
|
+
maxInFlight: 0,
|
|
1887
|
+
overlapMs: 0,
|
|
1888
|
+
lastChange: 0
|
|
1889
|
+
};
|
|
1890
|
+
byHook.set(hookName, cost);
|
|
1891
|
+
}
|
|
1892
|
+
return cost;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Fold the interval since the last in-flight change into `overlapMs`, then move the mark.
|
|
1896
|
+
* Call immediately before every increment and decrement of `cost.inFlight`.
|
|
1897
|
+
*/
|
|
1898
|
+
function markInFlightChange(cost, at) {
|
|
1899
|
+
if (cost.inFlight > 1) cost.overlapMs += (cost.inFlight - 1) * (at - cost.lastChange);
|
|
1900
|
+
cost.lastChange = at;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Close out one call. A module-level function rather than a closure per invocation: hooks
|
|
1904
|
+
* run hundreds of thousands of times in a large build, and the synchronous path would
|
|
1905
|
+
* otherwise allocate one closure per call only to invoke it immediately.
|
|
1906
|
+
*/
|
|
1907
|
+
function settle(recorder, cost, started) {
|
|
1908
|
+
const ended = performance.now();
|
|
1909
|
+
markInFlightChange(cost, ended);
|
|
1910
|
+
cost.inFlight -= 1;
|
|
1911
|
+
cost.ms += ended - started;
|
|
1912
|
+
recorder.inFlight -= 1;
|
|
1913
|
+
if (recorder.inFlight === 0) recorder.busyMs += ended - recorder.busyStart;
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Wrap one callback so its execution time is recorded.
|
|
1917
|
+
*
|
|
1918
|
+
* Returns the callback untouched when there is no recorder, so a build that is not
|
|
1919
|
+
* measuring pays nothing beyond one branch at setup.
|
|
1920
|
+
*/
|
|
1921
|
+
function measureHookCost(recorder, owner, hookName, handler) {
|
|
1922
|
+
if (recorder === void 0) return handler;
|
|
1923
|
+
const cost = costFor(recorder, owner, hookName);
|
|
1924
|
+
return function(...args) {
|
|
1925
|
+
const started = performance.now();
|
|
1926
|
+
markInFlightChange(cost, started);
|
|
1927
|
+
cost.calls += 1;
|
|
1928
|
+
cost.inFlight += 1;
|
|
1929
|
+
if (cost.inFlight > cost.maxInFlight) cost.maxInFlight = cost.inFlight;
|
|
1930
|
+
if (recorder.inFlight === 0) recorder.busyStart = started;
|
|
1931
|
+
recorder.inFlight += 1;
|
|
1932
|
+
let result;
|
|
1933
|
+
try {
|
|
1934
|
+
result = handler.apply(this, args);
|
|
1935
|
+
} catch (error) {
|
|
1936
|
+
settle(recorder, cost, started);
|
|
1937
|
+
throw error;
|
|
1938
|
+
}
|
|
1939
|
+
if (typeof result?.then === "function") return result.then((value) => {
|
|
1940
|
+
settle(recorder, cost, started);
|
|
1941
|
+
return value;
|
|
1942
|
+
}, (error) => {
|
|
1943
|
+
settle(recorder, cost, started);
|
|
1944
|
+
throw error;
|
|
1945
|
+
});
|
|
1946
|
+
settle(recorder, cost, started);
|
|
1947
|
+
return result;
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* The owner shown for user callbacks the core invokes directly rather than through a
|
|
1952
|
+
* plugin. One shared identity: they are all configured on the same options object.
|
|
1953
|
+
*/
|
|
1954
|
+
const OUTPUT_OPTIONS_OWNER = {
|
|
1955
|
+
key: Symbol("output options"),
|
|
1956
|
+
name: "output options",
|
|
1957
|
+
kind: "outputOption"
|
|
1958
|
+
};
|
|
1959
|
+
/** As {@link OUTPUT_OPTIONS_OWNER}, for callbacks configured on the input options. */
|
|
1960
|
+
const INPUT_OPTIONS_OWNER = {
|
|
1961
|
+
key: Symbol("input options"),
|
|
1962
|
+
name: "input options",
|
|
1963
|
+
kind: "inputOption"
|
|
1964
|
+
};
|
|
1965
|
+
/**
|
|
1966
|
+
* Wrap `value` when the user supplied a function, and leave every other form alone.
|
|
1967
|
+
*
|
|
1968
|
+
* Most option callbacks are declared as `string | RegExp | Function | ...`, so this keeps
|
|
1969
|
+
* the one cast the wrapping needs in a single place.
|
|
1970
|
+
*/
|
|
1971
|
+
function measureIfFunction(recorder, owner, hookName, value) {
|
|
1972
|
+
if (typeof value !== "function") return value;
|
|
1973
|
+
return measureHookCost(recorder, owner, hookName, value);
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* What the build's callbacks have cost so far, leaving the recorder in place.
|
|
1977
|
+
*
|
|
1978
|
+
* Ungated on purpose: whether a build is worth reporting on is decided from the clocks Rust
|
|
1979
|
+
* holds, so the question is not this side's to ask.
|
|
1980
|
+
*
|
|
1981
|
+
* Rust calls this while the build is closing, so what it gets includes `closeBundle`.
|
|
1982
|
+
*/
|
|
1983
|
+
function summarizePluginTimings(key) {
|
|
1984
|
+
const recorder = recorders.get(key);
|
|
1985
|
+
if (recorder === void 0) return {
|
|
1986
|
+
busyMs: 0,
|
|
1987
|
+
rows: []
|
|
1988
|
+
};
|
|
1989
|
+
const rows = [];
|
|
1990
|
+
for (const byHook of recorder.costs.values()) for (const cost of byHook.values()) {
|
|
1991
|
+
if (cost.calls === 0) continue;
|
|
1992
|
+
rows.push({
|
|
1993
|
+
owner: cost.owner,
|
|
1994
|
+
kind: cost.kind,
|
|
1995
|
+
hook: cost.hookName,
|
|
1996
|
+
calls: cost.calls,
|
|
1997
|
+
ms: cost.ms,
|
|
1998
|
+
maxInFlight: cost.maxInFlight,
|
|
1999
|
+
overlapMs: cost.overlapMs,
|
|
2000
|
+
rankable: cost.overlapMs <= cost.ms * OVERLAP_TOLERANCE
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
return {
|
|
2004
|
+
busyMs: recorder.busyMs,
|
|
2005
|
+
rows
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
//#endregion
|
|
1863
2009
|
//#region src/plugin/bindingify-plugin.ts
|
|
1864
|
-
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
2010
|
+
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings) {
|
|
1865
2011
|
const args = {
|
|
1866
2012
|
plugin,
|
|
1867
2013
|
options,
|
|
@@ -1881,20 +2027,22 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
|
|
|
1881
2027
|
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
|
|
1882
2028
|
const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
|
|
1883
2029
|
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
2030
|
+
const { plugin: resolveFileUrl, meta: resolveFileUrlMeta } = bindingifyResolveFileUrl(args);
|
|
1884
2031
|
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
1885
2032
|
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
1886
2033
|
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
1887
2034
|
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
1888
2035
|
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
1889
|
-
const { plugin: banner, meta: bannerMeta } =
|
|
1890
|
-
const { plugin: footer, meta: footerMeta } =
|
|
1891
|
-
const { plugin: intro, meta: introMeta } =
|
|
1892
|
-
const { plugin: outro, meta: outroMeta } =
|
|
2036
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyAddonHook(args, "banner");
|
|
2037
|
+
const { plugin: footer, meta: footerMeta } = bindingifyAddonHook(args, "footer");
|
|
2038
|
+
const { plugin: intro, meta: introMeta } = bindingifyAddonHook(args, "intro");
|
|
2039
|
+
const { plugin: outro, meta: outroMeta } = bindingifyAddonHook(args, "outro");
|
|
1893
2040
|
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
2041
|
+
const { plugin: hotUpdate, meta: hotUpdateMeta } = bindingifyHotUpdate(args);
|
|
1894
2042
|
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
1895
2043
|
const { plugin: transformCacheHit, meta: transformCacheHitMeta } = bindingifyTransformCacheHit(args);
|
|
1896
2044
|
let hookUsage = extractHookUsage(plugin).inner();
|
|
1897
|
-
|
|
2045
|
+
const result = {
|
|
1898
2046
|
name: plugin.name,
|
|
1899
2047
|
buildStart,
|
|
1900
2048
|
buildStartMeta,
|
|
@@ -1918,6 +2066,8 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
|
|
|
1918
2066
|
renderChunkFilter,
|
|
1919
2067
|
augmentChunkHash,
|
|
1920
2068
|
augmentChunkHashMeta,
|
|
2069
|
+
resolveFileUrl,
|
|
2070
|
+
resolveFileUrlMeta,
|
|
1921
2071
|
renderStart,
|
|
1922
2072
|
renderStartMeta,
|
|
1923
2073
|
renderError,
|
|
@@ -1938,14 +2088,21 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
|
|
|
1938
2088
|
outroMeta,
|
|
1939
2089
|
watchChange,
|
|
1940
2090
|
watchChangeMeta,
|
|
2091
|
+
hotUpdate,
|
|
2092
|
+
hotUpdateMeta,
|
|
1941
2093
|
closeWatcher,
|
|
1942
2094
|
closeWatcherMeta,
|
|
1943
2095
|
transformCacheHit,
|
|
1944
2096
|
transformCacheHitMeta,
|
|
1945
2097
|
hookUsage
|
|
1946
|
-
}
|
|
2098
|
+
};
|
|
2099
|
+
return wrapHandlers(result, {
|
|
2100
|
+
key: plugin,
|
|
2101
|
+
name: result.name,
|
|
2102
|
+
kind: "plugin"
|
|
2103
|
+
}, timings);
|
|
1947
2104
|
}
|
|
1948
|
-
function wrapHandlers(plugin) {
|
|
2105
|
+
function wrapHandlers(plugin, owner, timings) {
|
|
1949
2106
|
for (const hookName of [
|
|
1950
2107
|
"buildStart",
|
|
1951
2108
|
"resolveId",
|
|
@@ -1956,6 +2113,7 @@ function wrapHandlers(plugin) {
|
|
|
1956
2113
|
"load",
|
|
1957
2114
|
"renderChunk",
|
|
1958
2115
|
"augmentChunkHash",
|
|
2116
|
+
"resolveFileUrl",
|
|
1959
2117
|
"renderStart",
|
|
1960
2118
|
"renderError",
|
|
1961
2119
|
"generateBundle",
|
|
@@ -1966,10 +2124,12 @@ function wrapHandlers(plugin) {
|
|
|
1966
2124
|
"intro",
|
|
1967
2125
|
"outro",
|
|
1968
2126
|
"watchChange",
|
|
2127
|
+
"hotUpdate",
|
|
1969
2128
|
"closeWatcher",
|
|
1970
2129
|
"transformCacheHit"
|
|
1971
2130
|
]) {
|
|
1972
|
-
const
|
|
2131
|
+
const raw = plugin[hookName];
|
|
2132
|
+
const handler = raw && measureHookCost(timings, owner, hookName, raw);
|
|
1973
2133
|
if (handler) plugin[hookName] = async (...args) => {
|
|
1974
2134
|
try {
|
|
1975
2135
|
return await handler(...args);
|
|
@@ -2030,28 +2190,36 @@ function normalizeJsxOptions(jsx) {
|
|
|
2030
2190
|
};
|
|
2031
2191
|
}
|
|
2032
2192
|
//#endregion
|
|
2193
|
+
//#region src/utils/default-dev-runtime.ts
|
|
2194
|
+
function getDefaultDevRuntime(host = "localhost", port = 3e3) {
|
|
2195
|
+
const runtimeEntry = fs.readFileSync(fileURLToPath(import.meta.resolve("@rollipop/rolldown/experimental/runtime")), "utf8");
|
|
2196
|
+
const runtimeHelperImportEnd = runtimeEntry.indexOf("\n");
|
|
2197
|
+
if (!runtimeEntry.startsWith("import ") || runtimeHelperImportEnd === -1) throw new Error("Expected the standalone runtime to start with a helper import");
|
|
2198
|
+
return `${runtimeEntry.slice(runtimeHelperImportEnd + 1)}\n${fs.readFileSync(fileURLToPath(import.meta.resolve("#default-runtime")), "utf8").replaceAll("$ADDR", `${host}:${port}`)}`;
|
|
2199
|
+
}
|
|
2200
|
+
//#endregion
|
|
2033
2201
|
//#region src/utils/bindingify-input-options.ts
|
|
2034
|
-
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
2202
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings) {
|
|
2035
2203
|
const plugins = rawPlugins.map((plugin) => {
|
|
2036
|
-
if (
|
|
2204
|
+
if (getParallelPluginInfo(plugin)) return;
|
|
2037
2205
|
if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
|
|
2038
2206
|
case "builtin:vite-manifest": return bindingifyManifestPlugin(plugin, pluginContextData);
|
|
2039
2207
|
default: return bindingifyBuiltInPlugin(plugin);
|
|
2040
2208
|
}
|
|
2041
|
-
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
|
|
2209
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode, timings);
|
|
2042
2210
|
});
|
|
2043
2211
|
const normalizedTransform = normalizeTransformOptions(inputOptions);
|
|
2044
2212
|
return {
|
|
2045
2213
|
input: bindingifyInput(inputOptions.input),
|
|
2046
2214
|
plugins,
|
|
2047
2215
|
cwd: inputOptions.cwd ?? process.cwd(),
|
|
2048
|
-
external: bindingifyExternal(inputOptions.external),
|
|
2216
|
+
external: bindingifyExternal(inputOptions.external, timings),
|
|
2049
2217
|
resolve: bindingifyResolve(inputOptions.resolve),
|
|
2050
2218
|
platform: inputOptions.platform,
|
|
2051
2219
|
shimMissingExports: inputOptions.shimMissingExports,
|
|
2052
2220
|
logLevel: bindingifyLogLevel(logLevel),
|
|
2053
2221
|
onLog,
|
|
2054
|
-
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
2222
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake, timings),
|
|
2055
2223
|
moduleTypes: inputOptions.moduleTypes,
|
|
2056
2224
|
define: normalizedTransform.define,
|
|
2057
2225
|
inject: bindingifyInject(normalizedTransform.inject),
|
|
@@ -2062,6 +2230,7 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginC
|
|
|
2062
2230
|
dropLabels: normalizedTransform.dropLabels,
|
|
2063
2231
|
keepNames: outputOptions.keepNames,
|
|
2064
2232
|
checks: inputOptions.checks,
|
|
2233
|
+
pluginTimings: timings ? () => summarizePluginTimings(inputOptions) : void 0,
|
|
2065
2234
|
deferSyncScanData: () => {
|
|
2066
2235
|
let ret = [];
|
|
2067
2236
|
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
@@ -2084,8 +2253,16 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginC
|
|
|
2084
2253
|
}
|
|
2085
2254
|
function bindingifyDevMode(devMode) {
|
|
2086
2255
|
if (devMode) {
|
|
2087
|
-
if (typeof devMode === "boolean") return devMode ? {
|
|
2088
|
-
|
|
2256
|
+
if (typeof devMode === "boolean") return devMode ? {
|
|
2257
|
+
implement: getDefaultDevRuntime(),
|
|
2258
|
+
skipCommonRuntimeInjection: true
|
|
2259
|
+
} : void 0;
|
|
2260
|
+
const usesDefaultRuntime = devMode.implement == null;
|
|
2261
|
+
return {
|
|
2262
|
+
...devMode,
|
|
2263
|
+
implement: devMode.implement ?? getDefaultDevRuntime(devMode.host, devMode.port),
|
|
2264
|
+
skipCommonRuntimeInjection: usesDefaultRuntime ? true : devMode.skipCommonRuntimeInjection
|
|
2265
|
+
};
|
|
2089
2266
|
}
|
|
2090
2267
|
}
|
|
2091
2268
|
function bindingifyAttachDebugInfo(attachDebugInfo) {
|
|
@@ -2096,12 +2273,15 @@ function bindingifyAttachDebugInfo(attachDebugInfo) {
|
|
|
2096
2273
|
case "none": return import_binding.BindingAttachDebugInfo.None;
|
|
2097
2274
|
}
|
|
2098
2275
|
}
|
|
2099
|
-
function bindingifyExternal(external) {
|
|
2276
|
+
function bindingifyExternal(external, timings) {
|
|
2100
2277
|
if (external) {
|
|
2101
|
-
if (typeof external === "function")
|
|
2102
|
-
|
|
2103
|
-
return
|
|
2104
|
-
|
|
2278
|
+
if (typeof external === "function") {
|
|
2279
|
+
const measured = measureHookCost(timings, INPUT_OPTIONS_OWNER, "external", external);
|
|
2280
|
+
return (id, importer, isResolved) => {
|
|
2281
|
+
if (id.startsWith("\0")) return false;
|
|
2282
|
+
return measured(id, importer, isResolved) ?? false;
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2105
2285
|
return arraify(external);
|
|
2106
2286
|
}
|
|
2107
2287
|
}
|
|
@@ -2192,11 +2372,7 @@ function bindingifyInput(input) {
|
|
|
2192
2372
|
}
|
|
2193
2373
|
function bindingifyWatch(watch) {
|
|
2194
2374
|
if (watch) {
|
|
2195
|
-
|
|
2196
|
-
const watcher = {
|
|
2197
|
-
...watch.notify,
|
|
2198
|
-
...watch.watcher
|
|
2199
|
-
};
|
|
2375
|
+
const watcher = watch.watcher ?? {};
|
|
2200
2376
|
return {
|
|
2201
2377
|
buildDelay: watch.buildDelay,
|
|
2202
2378
|
skipWrite: watch.skipWrite,
|
|
@@ -2212,7 +2388,7 @@ function bindingifyWatch(watch) {
|
|
|
2212
2388
|
};
|
|
2213
2389
|
}
|
|
2214
2390
|
}
|
|
2215
|
-
function bindingifyTreeshakeOptions(config) {
|
|
2391
|
+
function bindingifyTreeshakeOptions(config, timings) {
|
|
2216
2392
|
if (config === false) return;
|
|
2217
2393
|
if (config === true || config === void 0) return { moduleSideEffects: true };
|
|
2218
2394
|
let normalizedConfig = {
|
|
@@ -2227,19 +2403,13 @@ function bindingifyTreeshakeOptions(config) {
|
|
|
2227
2403
|
case "always":
|
|
2228
2404
|
normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
|
|
2229
2405
|
break;
|
|
2230
|
-
case false:
|
|
2231
|
-
normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
|
|
2232
|
-
break;
|
|
2233
|
-
default:
|
|
2406
|
+
case false: normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
|
|
2234
2407
|
}
|
|
2235
2408
|
switch (config.propertyWriteSideEffects) {
|
|
2236
2409
|
case "always":
|
|
2237
2410
|
normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
|
|
2238
2411
|
break;
|
|
2239
|
-
case false:
|
|
2240
|
-
normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
|
|
2241
|
-
break;
|
|
2242
|
-
default:
|
|
2412
|
+
case false: normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
|
|
2243
2413
|
}
|
|
2244
2414
|
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
2245
2415
|
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
@@ -2249,7 +2419,7 @@ function bindingifyTreeshakeOptions(config) {
|
|
|
2249
2419
|
external: false,
|
|
2250
2420
|
sideEffects: true
|
|
2251
2421
|
}];
|
|
2252
|
-
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
2422
|
+
else normalizedConfig.moduleSideEffects = measureIfFunction(timings, INPUT_OPTIONS_OWNER, "treeshake.moduleSideEffects", config.moduleSideEffects);
|
|
2253
2423
|
return normalizedConfig;
|
|
2254
2424
|
}
|
|
2255
2425
|
function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
|
|
@@ -2271,4 +2441,4 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
|
|
|
2271
2441
|
};
|
|
2272
2442
|
}
|
|
2273
2443
|
//#endregion
|
|
2274
|
-
export { version as
|
|
2444
|
+
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 };
|