rolldown 0.15.0 → 0.15.1-commit.cc6f557
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/dist/cjs/cli.cjs +249 -183
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/esm/cli.mjs +343 -277
- package/dist/esm/experimental-index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{chunk-BK2Ye-xa.cjs → chunk-BFvIen8E.cjs} +0 -11
- package/dist/shared/{consola_36c0034f-_8_dG1Nr.cjs → consola_36c0034f-B7L-radJ.cjs} +2 -2
- package/dist/shared/{consola_36c0034f-DWsVjwtA.mjs → consola_36c0034f-D9ce-831.mjs} +10 -10
- package/dist/shared/{prompt-RFvZMmjc.cjs → prompt-BiXtYIJ2.cjs} +3 -3
- package/dist/shared/{prompt-DGW8ZJmn.mjs → prompt-DlQ-08lk.mjs} +2 -2
- package/dist/shared/{src-DEPa5yhI.mjs → src-C4XpZnTu.mjs} +332 -233
- package/dist/shared/{src-COU7qQBJ.cjs → src-DKykz7Lg.cjs} +321 -216
- package/dist/tsconfig.dts.tsbuildinfo +1 -0
- package/dist/types/api/build.d.ts +2 -0
- package/dist/types/api/watch/index.d.ts +2 -2
- package/dist/types/api/watch/watch-emitter.d.ts +31 -0
- package/dist/types/api/watch/watcher.d.ts +7 -27
- package/dist/types/binding.d.ts +114 -19
- package/dist/types/builtin-plugin/constructors.d.ts +1 -5
- package/dist/types/cli/arguments/index.d.ts +5 -3
- package/dist/types/cli/arguments/schema.d.ts +10 -397
- package/dist/types/cli/colors.d.ts +11 -1
- package/dist/types/cli/load-config.d.ts +3 -0
- package/dist/types/cli/logger.d.ts +5 -0
- package/dist/types/constants/plugin.d.ts +8 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/log/logging.d.ts +6 -6
- package/dist/types/log/logs.d.ts +2 -0
- package/dist/types/options/input-options-schema.d.ts +3 -595
- package/dist/types/options/input-options.d.ts +26 -3
- package/dist/types/options/normalized-input-options.d.ts +1 -1
- package/dist/types/options/normalized-output-options.d.ts +21 -17
- package/dist/types/options/output-options-schema.d.ts +2 -146
- package/dist/types/options/output-options.d.ts +1 -0
- package/dist/types/plugin/minimal-plugin-context.d.ts +3 -3
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/dist/types/plugin/plugin-context.d.ts +14 -10
- package/dist/types/plugin/transform-plugin-context.d.ts +7 -4
- package/dist/types/rollup.d.ts +4 -0
- package/dist/types/treeshake/module-side-effects.d.ts +14 -115
- package/dist/types/types/module-info.d.ts +1 -0
- package/dist/types/types/rolldown-output.d.ts +6 -0
- package/dist/types/utils/bindingify-input-options.d.ts +1 -1
- package/dist/types/utils/create-bundler-option.d.ts +11 -0
- package/dist/types/utils/error.d.ts +2 -1
- package/dist/types/utils/misc.d.ts +1 -1
- package/dist/types/utils/transform-sourcemap.d.ts +1 -1
- package/dist/types/utils/zod-ext.d.ts +6 -5
- package/package.json +16 -16
- package/dist/types/cli/utils.d.ts +0 -6
- package/dist/types/log/locate-character/index.d.ts +0 -13
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createRequire
|
|
2
|
-
import {
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import path, { default as path$1 } from "node:path";
|
|
4
5
|
import { Worker } from "node:worker_threads";
|
|
5
6
|
import { availableParallelism } from "node:os";
|
|
@@ -14,12 +15,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
14
15
|
var __commonJS = (cb, mod) => function() {
|
|
15
16
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
17
|
};
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all) __defProp(target, name, {
|
|
19
|
-
get: all[name],
|
|
20
|
-
enumerable: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
18
|
var __copyProps = (to, from, except, desc) => {
|
|
24
19
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
20
|
key = keys[i];
|
|
@@ -34,7 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
29
|
value: mod,
|
|
35
30
|
enumerable: true
|
|
36
31
|
}) : target, mod));
|
|
37
|
-
var __require = /* @__PURE__ */ createRequire
|
|
32
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
38
33
|
|
|
39
34
|
//#endregion
|
|
40
35
|
//#region src/utils/define-config.ts
|
|
@@ -68,7 +63,11 @@ function bindingifySourcemap$1(map) {
|
|
|
68
63
|
//#endregion
|
|
69
64
|
//#region src/utils/error.ts
|
|
70
65
|
function normalizeErrors(rawErrors) {
|
|
71
|
-
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(),
|
|
66
|
+
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
|
|
67
|
+
kind: e.kind,
|
|
68
|
+
message: e.message,
|
|
69
|
+
stack: undefined
|
|
70
|
+
}));
|
|
72
71
|
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
73
72
|
for (let i = 0; i < errors.length; i++) {
|
|
74
73
|
if (i >= 5) {
|
|
@@ -140,6 +139,19 @@ function transformChunkModules(modules) {
|
|
|
140
139
|
|
|
141
140
|
//#endregion
|
|
142
141
|
//#region src/utils/transform-to-rollup-output.ts
|
|
142
|
+
function transformToRollupSourceMap(map) {
|
|
143
|
+
const parsed = JSON.parse(map);
|
|
144
|
+
const obj = {
|
|
145
|
+
...parsed,
|
|
146
|
+
toString() {
|
|
147
|
+
return JSON.stringify(obj);
|
|
148
|
+
},
|
|
149
|
+
toUrl() {
|
|
150
|
+
return `data:application/json;charset=utf-8;base64,${Buffer$1.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
return obj;
|
|
154
|
+
}
|
|
143
155
|
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
144
156
|
const chunk = {
|
|
145
157
|
type: "chunk",
|
|
@@ -165,7 +177,7 @@ function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
|
165
177
|
return bindingChunk.moduleIds;
|
|
166
178
|
},
|
|
167
179
|
get map() {
|
|
168
|
-
return bindingChunk.map ?
|
|
180
|
+
return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
|
|
169
181
|
},
|
|
170
182
|
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
171
183
|
preliminaryFileName: bindingChunk.preliminaryFileName
|
|
@@ -188,10 +200,12 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
|
188
200
|
type: "asset",
|
|
189
201
|
fileName: bindingAsset.fileName,
|
|
190
202
|
originalFileName: bindingAsset.originalFileName || null,
|
|
203
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
191
204
|
get source() {
|
|
192
205
|
return transformAssetSource(bindingAsset.source);
|
|
193
206
|
},
|
|
194
|
-
name: bindingAsset.name ?? undefined
|
|
207
|
+
name: bindingAsset.name ?? undefined,
|
|
208
|
+
names: bindingAsset.names
|
|
195
209
|
};
|
|
196
210
|
const cache = {};
|
|
197
211
|
return new Proxy(asset, {
|
|
@@ -230,9 +244,9 @@ function collectChangedBundle(changed, bundle) {
|
|
|
230
244
|
const item = bundle[key];
|
|
231
245
|
if (item.type === "asset") assets.push({
|
|
232
246
|
filename: item.fileName,
|
|
233
|
-
|
|
247
|
+
originalFileNames: item.originalFileNames,
|
|
234
248
|
source: bindingAssetSource(item.source),
|
|
235
|
-
|
|
249
|
+
names: item.names
|
|
236
250
|
});
|
|
237
251
|
else chunks.push({
|
|
238
252
|
code: item.code,
|
|
@@ -261,7 +275,7 @@ else chunks.push({
|
|
|
261
275
|
//#endregion
|
|
262
276
|
//#region src/binding.js
|
|
263
277
|
var require_binding = __commonJS({ "src/binding.js"(exports, module) {
|
|
264
|
-
const { createRequire } = __require("node:module");
|
|
278
|
+
const { createRequire: createRequire$1 } = __require("node:module");
|
|
265
279
|
const { readFileSync } = __require("node:fs");
|
|
266
280
|
let nativeBinding = null;
|
|
267
281
|
const loadErrors = [];
|
|
@@ -549,7 +563,7 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
|
|
|
549
563
|
}
|
|
550
564
|
module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
|
|
551
565
|
module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
|
|
552
|
-
module.exports.
|
|
566
|
+
module.exports.BindingError = nativeBinding.BindingError;
|
|
553
567
|
module.exports.BindingLog = nativeBinding.BindingLog;
|
|
554
568
|
module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
|
|
555
569
|
module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
|
|
@@ -568,8 +582,10 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
|
|
|
568
582
|
module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
|
|
569
583
|
module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
|
|
570
584
|
module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
|
|
585
|
+
module.exports.HelperMode = nativeBinding.HelperMode;
|
|
571
586
|
module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
|
|
572
587
|
module.exports.registerPlugins = nativeBinding.registerPlugins;
|
|
588
|
+
module.exports.Severity = nativeBinding.Severity;
|
|
573
589
|
module.exports.transform = nativeBinding.transform;
|
|
574
590
|
} });
|
|
575
591
|
|
|
@@ -590,17 +606,15 @@ function unreachable(info) {
|
|
|
590
606
|
throw new Error("unreachable");
|
|
591
607
|
}
|
|
592
608
|
function unsupported(info) {
|
|
593
|
-
|
|
594
|
-
throw new Error(`UNSUPPORTED: ${info}`);
|
|
595
|
-
};
|
|
609
|
+
throw new Error(`UNSUPPORTED: ${info}`);
|
|
596
610
|
}
|
|
597
611
|
function noop(..._args) {}
|
|
598
612
|
|
|
599
613
|
//#endregion
|
|
600
614
|
//#region src/log/logging.ts
|
|
601
|
-
const LogLevelSchema = z
|
|
602
|
-
const LogLevelOptionSchema = LogLevelSchema.or(z
|
|
603
|
-
const LogLevelWithErrorSchema = LogLevelSchema.or(z
|
|
615
|
+
const LogLevelSchema = z.literal("info").or(z.literal("debug")).or(z.literal("warn"));
|
|
616
|
+
const LogLevelOptionSchema = LogLevelSchema.or(z.literal("silent"));
|
|
617
|
+
const LogLevelWithErrorSchema = LogLevelSchema.or(z.literal("error"));
|
|
604
618
|
const LOG_LEVEL_SILENT = "silent";
|
|
605
619
|
const LOG_LEVEL_ERROR = "error";
|
|
606
620
|
const LOG_LEVEL_WARN = "warn";
|
|
@@ -612,8 +626,8 @@ const logLevelPriority = {
|
|
|
612
626
|
[LOG_LEVEL_WARN]: 2,
|
|
613
627
|
[LOG_LEVEL_SILENT]: 3
|
|
614
628
|
};
|
|
615
|
-
const RollupLogSchema = z
|
|
616
|
-
const RollupLogWithStringSchema = RollupLogSchema.or(z
|
|
629
|
+
const RollupLogSchema = z.any();
|
|
630
|
+
const RollupLogWithStringSchema = RollupLogSchema.or(z.string());
|
|
617
631
|
|
|
618
632
|
//#endregion
|
|
619
633
|
//#region src/utils/code-frame.ts
|
|
@@ -707,7 +721,13 @@ function locate(source, search, options) {
|
|
|
707
721
|
|
|
708
722
|
//#endregion
|
|
709
723
|
//#region src/log/logs.ts
|
|
710
|
-
const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING";
|
|
724
|
+
const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", MINIFY_WARNING = "MINIFY_WARNING";
|
|
725
|
+
function logMinifyWarning() {
|
|
726
|
+
return {
|
|
727
|
+
code: MINIFY_WARNING,
|
|
728
|
+
message: "The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use."
|
|
729
|
+
};
|
|
730
|
+
}
|
|
711
731
|
function logInvalidLogPosition(pluginName) {
|
|
712
732
|
return {
|
|
713
733
|
code: INVALID_LOG_POSITION,
|
|
@@ -726,6 +746,12 @@ function logCycleLoading(pluginName, moduleId) {
|
|
|
726
746
|
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
727
747
|
};
|
|
728
748
|
}
|
|
749
|
+
function logMultiplyNotifyOption() {
|
|
750
|
+
return {
|
|
751
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
752
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
753
|
+
};
|
|
754
|
+
}
|
|
729
755
|
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
730
756
|
const code = error$1.code;
|
|
731
757
|
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
@@ -829,7 +855,8 @@ function getLogger(plugins, onLog, logLevel) {
|
|
|
829
855
|
rolldownVersion: VERSION,
|
|
830
856
|
watchMode: false
|
|
831
857
|
},
|
|
832
|
-
warn: getLogHandler$1(LOG_LEVEL_WARN)
|
|
858
|
+
warn: getLogHandler$1(LOG_LEVEL_WARN),
|
|
859
|
+
pluginName: plugin.name || "unknown"
|
|
833
860
|
}, level, log) === false) return;
|
|
834
861
|
}
|
|
835
862
|
}
|
|
@@ -881,9 +908,9 @@ function relativeId(id) {
|
|
|
881
908
|
|
|
882
909
|
//#endregion
|
|
883
910
|
//#region src/builtin-plugin/utils.ts
|
|
884
|
-
var import_binding$
|
|
911
|
+
var import_binding$6 = __toESM(require_binding());
|
|
885
912
|
function makeBuiltinPluginCallable(plugin) {
|
|
886
|
-
let callablePlugin = new import_binding$
|
|
913
|
+
let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
887
914
|
const wrappedPlugin = plugin;
|
|
888
915
|
for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
|
|
889
916
|
return callablePlugin[key](...args);
|
|
@@ -1052,7 +1079,8 @@ var PluginDriver = class {
|
|
|
1052
1079
|
rolldownVersion: VERSION,
|
|
1053
1080
|
watchMode: false
|
|
1054
1081
|
},
|
|
1055
|
-
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
|
|
1082
|
+
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
|
|
1083
|
+
pluginName: name
|
|
1056
1084
|
}, inputOptions);
|
|
1057
1085
|
if (result) inputOptions = result;
|
|
1058
1086
|
}
|
|
@@ -1116,7 +1144,7 @@ const ModuleSideEffectsRuleSchema = z.object({
|
|
|
1116
1144
|
}).refine((data) => {
|
|
1117
1145
|
return data.test !== undefined || data.external !== undefined;
|
|
1118
1146
|
}, "Either `test` or `external` should be set.");
|
|
1119
|
-
const ModuleSideEffectsOptionSchema = z.boolean().or(z.array(ModuleSideEffectsRuleSchema)).or(z.literal("no-external"));
|
|
1147
|
+
const ModuleSideEffectsOptionSchema = z.boolean().or(z.array(ModuleSideEffectsRuleSchema)).or(z.function().args(z.string(), z.boolean()).returns(z.boolean().optional())).or(z.literal("no-external"));
|
|
1120
1148
|
const TreeshakingOptionsSchema = z.object({
|
|
1121
1149
|
moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
|
|
1122
1150
|
annotations: z.boolean().optional()
|
|
@@ -1152,6 +1180,7 @@ function transformModuleInfo(info, option) {
|
|
|
1152
1180
|
dynamicImporters: info.dynamicImporters,
|
|
1153
1181
|
importedIds: info.importedIds,
|
|
1154
1182
|
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
1183
|
+
exports: info.exports,
|
|
1155
1184
|
isEntry: info.isEntry,
|
|
1156
1185
|
...option
|
|
1157
1186
|
};
|
|
@@ -1164,31 +1193,30 @@ var MinimalPluginContext = class {
|
|
|
1164
1193
|
warn;
|
|
1165
1194
|
debug;
|
|
1166
1195
|
meta;
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
const pluginName = plugin.name || "unknown";
|
|
1196
|
+
constructor(onLog, logLevel, pluginName) {
|
|
1197
|
+
this.pluginName = pluginName;
|
|
1170
1198
|
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1171
1199
|
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1172
1200
|
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
1173
|
-
this.error = (e) => {
|
|
1174
|
-
return error(logPluginError(normalizeLog(e), pluginName));
|
|
1175
|
-
};
|
|
1176
1201
|
this.meta = {
|
|
1177
1202
|
rollupVersion: "4.23.0",
|
|
1178
1203
|
rolldownVersion: VERSION,
|
|
1179
1204
|
watchMode: false
|
|
1180
1205
|
};
|
|
1181
1206
|
}
|
|
1207
|
+
error(e) {
|
|
1208
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1209
|
+
}
|
|
1182
1210
|
};
|
|
1183
1211
|
|
|
1184
1212
|
//#endregion
|
|
1185
1213
|
//#region src/utils/transform-side-effects.ts
|
|
1186
|
-
var import_binding$
|
|
1214
|
+
var import_binding$5 = __toESM(require_binding());
|
|
1187
1215
|
function bindingifySideEffects(sideEffects) {
|
|
1188
1216
|
switch (sideEffects) {
|
|
1189
|
-
case true: return import_binding$
|
|
1190
|
-
case false: return import_binding$
|
|
1191
|
-
case "no-treeshake": return import_binding$
|
|
1217
|
+
case true: return import_binding$5.BindingHookSideEffects.True;
|
|
1218
|
+
case false: return import_binding$5.BindingHookSideEffects.False;
|
|
1219
|
+
case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
|
|
1192
1220
|
case null:
|
|
1193
1221
|
case undefined: return undefined;
|
|
1194
1222
|
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
@@ -1198,84 +1226,92 @@ function bindingifySideEffects(sideEffects) {
|
|
|
1198
1226
|
//#endregion
|
|
1199
1227
|
//#region src/plugin/plugin-context.ts
|
|
1200
1228
|
var PluginContext = class extends MinimalPluginContext {
|
|
1201
|
-
load;
|
|
1202
|
-
resolve;
|
|
1203
|
-
emitFile;
|
|
1204
|
-
getFileName;
|
|
1205
|
-
getModuleInfo;
|
|
1206
|
-
getModuleIds;
|
|
1207
|
-
addWatchFile;
|
|
1208
|
-
/**
|
|
1209
|
-
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1210
|
-
*/
|
|
1211
|
-
parse;
|
|
1212
1229
|
constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
|
|
1213
|
-
super(onLog, logLevel, plugin);
|
|
1214
|
-
this.
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
const promise = new Promise((resolve, _) => {
|
|
1228
|
-
resolveFn = resolve;
|
|
1229
|
-
});
|
|
1230
|
-
data.loadModulePromiseMap.set(id, promise);
|
|
1231
|
-
try {
|
|
1232
|
-
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1233
|
-
} finally {
|
|
1234
|
-
data.loadModulePromiseMap.delete(id);
|
|
1235
|
-
}
|
|
1236
|
-
return promise;
|
|
1237
|
-
}
|
|
1238
|
-
await createLoadModulePromise();
|
|
1239
|
-
return data.getModuleInfo(id, context);
|
|
1240
|
-
};
|
|
1241
|
-
this.resolve = async (source, importer, options) => {
|
|
1242
|
-
let receipt = undefined;
|
|
1243
|
-
if (options != null) receipt = data.saveResolveOptions(options);
|
|
1244
|
-
const res = await context.resolve(source, importer, {
|
|
1245
|
-
custom: receipt,
|
|
1246
|
-
skipSelf: options?.skipSelf
|
|
1247
|
-
});
|
|
1248
|
-
if (receipt != null) data.removeSavedResolveOptions(receipt);
|
|
1249
|
-
if (res == null) return null;
|
|
1250
|
-
const info = data.getModuleOption(res.id) || {};
|
|
1251
|
-
return {
|
|
1252
|
-
...res,
|
|
1253
|
-
...info
|
|
1254
|
-
};
|
|
1230
|
+
super(onLog, logLevel, plugin.name);
|
|
1231
|
+
this.context = context;
|
|
1232
|
+
this.data = data;
|
|
1233
|
+
this.onLog = onLog;
|
|
1234
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1235
|
+
}
|
|
1236
|
+
async load(options) {
|
|
1237
|
+
const id = options.id;
|
|
1238
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
1239
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1240
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1241
|
+
const rawOptions = {
|
|
1242
|
+
meta: options.meta || {},
|
|
1243
|
+
moduleSideEffects: options.moduleSideEffects || null
|
|
1255
1244
|
};
|
|
1256
|
-
this.
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1245
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1246
|
+
async function createLoadModulePromise(context, data) {
|
|
1247
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
1248
|
+
if (loadPromise) return loadPromise;
|
|
1249
|
+
let resolveFn;
|
|
1250
|
+
const promise = new Promise((resolve, _) => {
|
|
1251
|
+
resolveFn = resolve;
|
|
1262
1252
|
});
|
|
1253
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
1254
|
+
try {
|
|
1255
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1256
|
+
} finally {
|
|
1257
|
+
data.loadModulePromiseMap.delete(id);
|
|
1258
|
+
}
|
|
1259
|
+
return promise;
|
|
1260
|
+
}
|
|
1261
|
+
await createLoadModulePromise(this.context, this.data);
|
|
1262
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1263
|
+
}
|
|
1264
|
+
async resolve(source, importer, options) {
|
|
1265
|
+
let receipt = undefined;
|
|
1266
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1267
|
+
const res = await this.context.resolve(source, importer, {
|
|
1268
|
+
custom: receipt,
|
|
1269
|
+
skipSelf: options?.skipSelf
|
|
1270
|
+
});
|
|
1271
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1272
|
+
if (res == null) return null;
|
|
1273
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1274
|
+
return {
|
|
1275
|
+
...res,
|
|
1276
|
+
...info
|
|
1263
1277
|
};
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
this.
|
|
1268
|
-
|
|
1278
|
+
}
|
|
1279
|
+
emitFile(file) {
|
|
1280
|
+
if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
|
|
1281
|
+
return this.context.emitFile({
|
|
1282
|
+
...file,
|
|
1283
|
+
originalFileName: file.originalFileName || undefined,
|
|
1284
|
+
source: bindingAssetSource(file.source)
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
getFileName(referenceId) {
|
|
1288
|
+
return this.context.getFileName(referenceId);
|
|
1289
|
+
}
|
|
1290
|
+
getModuleInfo(id) {
|
|
1291
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1292
|
+
}
|
|
1293
|
+
getModuleIds() {
|
|
1294
|
+
return this.data.getModuleIds(this.context);
|
|
1295
|
+
}
|
|
1296
|
+
addWatchFile(id) {
|
|
1297
|
+
this.context.addWatchFile(id);
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1301
|
+
*/
|
|
1302
|
+
parse(_input, _options) {
|
|
1303
|
+
unsupported("`PluginContext#parse` is not supported by rolldown.");
|
|
1269
1304
|
}
|
|
1270
1305
|
};
|
|
1271
1306
|
|
|
1272
1307
|
//#endregion
|
|
1273
1308
|
//#region src/plugin/transform-plugin-context.ts
|
|
1274
1309
|
var TransformPluginContext = class extends PluginContext {
|
|
1275
|
-
error;
|
|
1276
|
-
getCombinedSourcemap;
|
|
1277
1310
|
constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
1278
1311
|
super(context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
1312
|
+
this.inner = inner;
|
|
1313
|
+
this.moduleId = moduleId;
|
|
1314
|
+
this.moduleSource = moduleSource;
|
|
1279
1315
|
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
1280
1316
|
log = normalizeLog(log);
|
|
1281
1317
|
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
@@ -1286,27 +1322,29 @@ var TransformPluginContext = class extends PluginContext {
|
|
|
1286
1322
|
this.debug = getLogHandler$1(this.debug);
|
|
1287
1323
|
this.warn = getLogHandler$1(this.warn);
|
|
1288
1324
|
this.info = getLogHandler$1(this.info);
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1325
|
+
}
|
|
1326
|
+
error(e, pos) {
|
|
1327
|
+
if (typeof e === "string") e = { message: e };
|
|
1328
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1329
|
+
e.id = this.moduleId;
|
|
1330
|
+
e.hook = "transform";
|
|
1331
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1332
|
+
}
|
|
1333
|
+
getCombinedSourcemap() {
|
|
1334
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1297
1335
|
}
|
|
1298
1336
|
};
|
|
1299
1337
|
|
|
1300
1338
|
//#endregion
|
|
1301
1339
|
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1302
|
-
var import_binding$
|
|
1340
|
+
var import_binding$4 = __toESM(require_binding());
|
|
1303
1341
|
function bindingifyPluginHookMeta(options) {
|
|
1304
1342
|
return { order: bindingPluginOrder(options.order) };
|
|
1305
1343
|
}
|
|
1306
1344
|
function bindingPluginOrder(order) {
|
|
1307
1345
|
switch (order) {
|
|
1308
|
-
case "post": return import_binding$
|
|
1309
|
-
case "pre": return import_binding$
|
|
1346
|
+
case "post": return import_binding$4.BindingPluginOrder.Post;
|
|
1347
|
+
case "pre": return import_binding$4.BindingPluginOrder.Pre;
|
|
1310
1348
|
case null:
|
|
1311
1349
|
case undefined: return undefined;
|
|
1312
1350
|
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
@@ -1387,7 +1425,7 @@ function bindingifyBuildEnd(args) {
|
|
|
1387
1425
|
const { handler, meta } = normalizeHook(hook);
|
|
1388
1426
|
return {
|
|
1389
1427
|
plugin: async (ctx, err) => {
|
|
1390
|
-
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err
|
|
1428
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
|
|
1391
1429
|
},
|
|
1392
1430
|
meta: bindingifyPluginHookMeta(meta)
|
|
1393
1431
|
};
|
|
@@ -1526,7 +1564,9 @@ function bindingifyModuleParsed(args) {
|
|
|
1526
1564
|
//#endregion
|
|
1527
1565
|
//#region src/options/normalized-output-options.ts
|
|
1528
1566
|
function mapFunctionOption(option, name) {
|
|
1529
|
-
return typeof option === "undefined" ?
|
|
1567
|
+
return typeof option === "undefined" ? () => {
|
|
1568
|
+
unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
|
|
1569
|
+
} : option;
|
|
1530
1570
|
}
|
|
1531
1571
|
var NormalizedOutputOptionsImpl = class {
|
|
1532
1572
|
inner;
|
|
@@ -1614,6 +1654,9 @@ var NormalizedOutputOptionsImpl = class {
|
|
|
1614
1654
|
get comments() {
|
|
1615
1655
|
return this.inner.comments;
|
|
1616
1656
|
}
|
|
1657
|
+
get polyfillRequire() {
|
|
1658
|
+
return this.inner.polyfillRequire;
|
|
1659
|
+
}
|
|
1617
1660
|
};
|
|
1618
1661
|
|
|
1619
1662
|
//#endregion
|
|
@@ -1664,7 +1707,7 @@ function bindingifyRenderError(args) {
|
|
|
1664
1707
|
const { handler, meta } = normalizeHook(hook);
|
|
1665
1708
|
return {
|
|
1666
1709
|
plugin: async (ctx, err) => {
|
|
1667
|
-
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel),
|
|
1710
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
1668
1711
|
},
|
|
1669
1712
|
meta: bindingifyPluginHookMeta(meta)
|
|
1670
1713
|
};
|
|
@@ -1965,7 +2008,7 @@ function normalizedStringOrRegex(pattern) {
|
|
|
1965
2008
|
|
|
1966
2009
|
//#endregion
|
|
1967
2010
|
//#region src/utils/bindingify-input-options.ts
|
|
1968
|
-
var import_binding$
|
|
2011
|
+
var import_binding$3 = __toESM(require_binding());
|
|
1969
2012
|
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
|
|
1970
2013
|
const pluginContextData = new PluginContextData();
|
|
1971
2014
|
const plugins = rawPlugins.map((plugin) => {
|
|
@@ -1996,7 +2039,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
|
|
|
1996
2039
|
profilerNames: inputOptions?.profilerNames,
|
|
1997
2040
|
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1998
2041
|
watch: bindingifyWatch(inputOptions.watch),
|
|
1999
|
-
dropLabels: inputOptions.dropLabels
|
|
2042
|
+
dropLabels: inputOptions.dropLabels,
|
|
2043
|
+
keepNames: inputOptions.keepNames,
|
|
2044
|
+
checks: inputOptions.checks
|
|
2000
2045
|
};
|
|
2001
2046
|
}
|
|
2002
2047
|
function bindingifyExternal(external) {
|
|
@@ -2020,7 +2065,7 @@ function bindingifyResolve(resolve) {
|
|
|
2020
2065
|
return {
|
|
2021
2066
|
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
2022
2067
|
find: name,
|
|
2023
|
-
replacements:
|
|
2068
|
+
replacements: arraify(replacement)
|
|
2024
2069
|
})) : undefined,
|
|
2025
2070
|
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
2026
2071
|
target: name,
|
|
@@ -2054,10 +2099,10 @@ function bindingifyInject(inject) {
|
|
|
2054
2099
|
}
|
|
2055
2100
|
function bindingifyLogLevel(logLevel) {
|
|
2056
2101
|
switch (logLevel) {
|
|
2057
|
-
case "silent": return import_binding$
|
|
2058
|
-
case "debug": return import_binding$
|
|
2059
|
-
case "warn": return import_binding$
|
|
2060
|
-
case "info": return import_binding$
|
|
2102
|
+
case "silent": return import_binding$3.BindingLogLevel.Silent;
|
|
2103
|
+
case "debug": return import_binding$3.BindingLogLevel.Debug;
|
|
2104
|
+
case "warn": return import_binding$3.BindingLogLevel.Warn;
|
|
2105
|
+
case "info": return import_binding$3.BindingLogLevel.Info;
|
|
2061
2106
|
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2062
2107
|
}
|
|
2063
2108
|
}
|
|
@@ -2073,15 +2118,20 @@ function bindingifyInput(input) {
|
|
|
2073
2118
|
});
|
|
2074
2119
|
}
|
|
2075
2120
|
function bindingifyJsx(input) {
|
|
2121
|
+
if (input === false) return { type: "Disable" };
|
|
2076
2122
|
if (input) {
|
|
2077
|
-
|
|
2123
|
+
if (input.mode === "preserve") return { type: "Preserve" };
|
|
2124
|
+
const mode = input.mode ?? "automatic";
|
|
2078
2125
|
return {
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2126
|
+
type: "Enable",
|
|
2127
|
+
field0: {
|
|
2128
|
+
runtime: mode,
|
|
2129
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
|
|
2130
|
+
pragma: input.factory,
|
|
2131
|
+
pragmaFrag: input.fragment,
|
|
2132
|
+
development: input.development,
|
|
2133
|
+
refresh: input.refresh
|
|
2134
|
+
}
|
|
2085
2135
|
};
|
|
2086
2136
|
}
|
|
2087
2137
|
}
|
|
@@ -2092,10 +2142,6 @@ function bindingifyWatch(watch$1) {
|
|
|
2092
2142
|
include: normalizedStringOrRegex(watch$1.include),
|
|
2093
2143
|
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2094
2144
|
};
|
|
2095
|
-
if (watch$1.notify) value.notify = {
|
|
2096
|
-
pollInterval: watch$1.notify.pollInterval,
|
|
2097
|
-
compareContents: watch$1.notify.compareContents
|
|
2098
|
-
};
|
|
2099
2145
|
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
2100
2146
|
return value;
|
|
2101
2147
|
}
|
|
@@ -2150,7 +2196,8 @@ function bindingifyOutputOptions(outputOptions) {
|
|
|
2150
2196
|
minify: outputOptions.minify,
|
|
2151
2197
|
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
2152
2198
|
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
2153
|
-
advancedChunks: outputOptions.advancedChunks
|
|
2199
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
2200
|
+
polyfillRequire: outputOptions.polyfillRequire
|
|
2154
2201
|
};
|
|
2155
2202
|
}
|
|
2156
2203
|
function bindingifyAddon(configAddon) {
|
|
@@ -2319,10 +2366,7 @@ function createComposedPlugin(plugins) {
|
|
|
2319
2366
|
const createFixedPluginResolveFnMap = new Map();
|
|
2320
2367
|
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2321
2368
|
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2322
|
-
if (createFixedPluginResolveFn)
|
|
2323
|
-
...ctx,
|
|
2324
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
2325
|
-
};
|
|
2369
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2326
2370
|
return ctx;
|
|
2327
2371
|
}
|
|
2328
2372
|
if (batchedHooks.resolveId) {
|
|
@@ -2331,14 +2375,14 @@ function createComposedPlugin(plugins) {
|
|
|
2331
2375
|
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2332
2376
|
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2333
2377
|
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2334
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
2378
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2335
2379
|
return (source, importer, rawContextResolveOptions) => {
|
|
2336
2380
|
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2337
2381
|
if (contextResolveOptions.skipSelf) {
|
|
2338
2382
|
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2339
2383
|
contextResolveOptions.skipSelf = false;
|
|
2340
2384
|
}
|
|
2341
|
-
return
|
|
2385
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2342
2386
|
};
|
|
2343
2387
|
};
|
|
2344
2388
|
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
@@ -2396,12 +2440,10 @@ function createComposedPlugin(plugins) {
|
|
|
2396
2440
|
}
|
|
2397
2441
|
for (const [handler, plugin] of batchedHandlers) {
|
|
2398
2442
|
const { handler: handlerFn } = normalizeHook(handler);
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
}
|
|
2404
|
-
}, code, id, moduleType);
|
|
2443
|
+
this.getCombinedSourcemap = () => {
|
|
2444
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2445
|
+
};
|
|
2446
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2405
2447
|
if (!isNullish(result)) {
|
|
2406
2448
|
if (typeof result === "string") updateOutput(result);
|
|
2407
2449
|
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
@@ -2536,7 +2578,7 @@ else newPlugins.push(toBeComposed[0]);
|
|
|
2536
2578
|
|
|
2537
2579
|
//#endregion
|
|
2538
2580
|
//#region src/utils/initialize-parallel-plugins.ts
|
|
2539
|
-
var import_binding$
|
|
2581
|
+
var import_binding$2 = __toESM(require_binding());
|
|
2540
2582
|
async function initializeParallelPlugins(plugins) {
|
|
2541
2583
|
const pluginInfos = [];
|
|
2542
2584
|
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
@@ -2549,7 +2591,7 @@ async function initializeParallelPlugins(plugins) {
|
|
|
2549
2591
|
}
|
|
2550
2592
|
if (pluginInfos.length <= 0) return undefined;
|
|
2551
2593
|
const count = Math.min(availableParallelism(), 8);
|
|
2552
|
-
const parallelJsPluginRegistry = new import_binding$
|
|
2594
|
+
const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
|
|
2553
2595
|
const registryId = parallelJsPluginRegistry.id;
|
|
2554
2596
|
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2555
2597
|
const stopWorkers = async () => {
|
|
@@ -2565,14 +2607,14 @@ function initializeWorkers(registryId, count, pluginInfos) {
|
|
|
2565
2607
|
}
|
|
2566
2608
|
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
2567
2609
|
const urlString = import.meta.resolve("#parallel-plugin-worker");
|
|
2568
|
-
const workerData = {
|
|
2610
|
+
const workerData$1 = {
|
|
2569
2611
|
registryId,
|
|
2570
2612
|
pluginInfos,
|
|
2571
2613
|
threadNumber
|
|
2572
2614
|
};
|
|
2573
2615
|
let worker;
|
|
2574
2616
|
try {
|
|
2575
|
-
worker = new Worker(new URL(urlString), { workerData });
|
|
2617
|
+
worker = new Worker(new URL(urlString), { workerData: workerData$1 });
|
|
2576
2618
|
worker.unref();
|
|
2577
2619
|
await new Promise((resolve, reject) => {
|
|
2578
2620
|
worker.once("message", async (message) => {
|
|
@@ -2588,17 +2630,17 @@ else resolve();
|
|
|
2588
2630
|
}
|
|
2589
2631
|
|
|
2590
2632
|
//#endregion
|
|
2591
|
-
//#region src/utils/create-bundler.ts
|
|
2592
|
-
|
|
2593
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
2633
|
+
//#region src/utils/create-bundler-option.ts
|
|
2634
|
+
async function createBundlerOptions(inputOptions, outputOptions) {
|
|
2594
2635
|
const pluginDriver = new PluginDriver();
|
|
2595
2636
|
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
2596
2637
|
if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
|
|
2597
2638
|
const inputPlugins = await normalizePluginOption(inputOptions.plugins);
|
|
2598
2639
|
const outputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
2599
|
-
outputOptions = pluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
|
|
2600
2640
|
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
2601
2641
|
const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel);
|
|
2642
|
+
outputOptions = pluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
|
|
2643
|
+
if (outputOptions.minify === true) onLog(LOG_LEVEL_WARN, logMinifyWarning());
|
|
2602
2644
|
let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(await normalizePluginOption(outputOptions.plugins), ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
|
|
2603
2645
|
if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
|
|
2604
2646
|
const parallelPluginInitResult = await initializeParallelPlugins(plugins);
|
|
@@ -2606,7 +2648,13 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2606
2648
|
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
|
|
2607
2649
|
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
2608
2650
|
return {
|
|
2609
|
-
|
|
2651
|
+
bundlerOptions: {
|
|
2652
|
+
inputOptions: bindingInputOptions,
|
|
2653
|
+
outputOptions: bindingOutputOptions,
|
|
2654
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
2655
|
+
},
|
|
2656
|
+
inputOptions,
|
|
2657
|
+
onLog,
|
|
2610
2658
|
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
2611
2659
|
};
|
|
2612
2660
|
} catch (e) {
|
|
@@ -2615,6 +2663,22 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2615
2663
|
}
|
|
2616
2664
|
}
|
|
2617
2665
|
|
|
2666
|
+
//#endregion
|
|
2667
|
+
//#region src/utils/create-bundler.ts
|
|
2668
|
+
var import_binding$1 = __toESM(require_binding());
|
|
2669
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
2670
|
+
const option = await createBundlerOptions(inputOptions, outputOptions);
|
|
2671
|
+
try {
|
|
2672
|
+
return {
|
|
2673
|
+
bundler: new import_binding$1.Bundler(option.bundlerOptions),
|
|
2674
|
+
stopWorkers: option.stopWorkers
|
|
2675
|
+
};
|
|
2676
|
+
} catch (e) {
|
|
2677
|
+
await option.stopWorkers?.();
|
|
2678
|
+
throw e;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2618
2682
|
//#endregion
|
|
2619
2683
|
//#region src/api/rolldown/rolldown-build.ts
|
|
2620
2684
|
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
@@ -2657,98 +2721,129 @@ const rolldown = async (input) => {
|
|
|
2657
2721
|
return new RolldownBuild(input);
|
|
2658
2722
|
};
|
|
2659
2723
|
|
|
2724
|
+
//#endregion
|
|
2725
|
+
//#region src/api/watch/watch-emitter.ts
|
|
2726
|
+
var WatcherEmitter = class {
|
|
2727
|
+
listeners = new Map();
|
|
2728
|
+
timer;
|
|
2729
|
+
constructor() {
|
|
2730
|
+
this.timer = setInterval(
|
|
2731
|
+
() => {},
|
|
2732
|
+
1e9
|
|
2733
|
+
/* Low power usage */
|
|
2734
|
+
);
|
|
2735
|
+
}
|
|
2736
|
+
on(event, listener) {
|
|
2737
|
+
const listeners = this.listeners.get(event);
|
|
2738
|
+
if (listeners) listeners.push(listener);
|
|
2739
|
+
else this.listeners.set(event, [listener]);
|
|
2740
|
+
return this;
|
|
2741
|
+
}
|
|
2742
|
+
async onEvent(event) {
|
|
2743
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
2744
|
+
if (listeners) switch (event.eventKind()) {
|
|
2745
|
+
case "close":
|
|
2746
|
+
case "restart":
|
|
2747
|
+
for (const listener of listeners) await listener();
|
|
2748
|
+
break;
|
|
2749
|
+
case "event":
|
|
2750
|
+
for (const listener of listeners) {
|
|
2751
|
+
const code = event.bundleEventKind();
|
|
2752
|
+
switch (code) {
|
|
2753
|
+
case "BUNDLE_END":
|
|
2754
|
+
const { duration, output } = event.bundleEndData();
|
|
2755
|
+
await listener({
|
|
2756
|
+
code: "BUNDLE_END",
|
|
2757
|
+
duration,
|
|
2758
|
+
output: [output]
|
|
2759
|
+
});
|
|
2760
|
+
break;
|
|
2761
|
+
case "ERROR":
|
|
2762
|
+
const errors = event.errors();
|
|
2763
|
+
await listener({
|
|
2764
|
+
code: "ERROR",
|
|
2765
|
+
error: normalizeErrors(errors)
|
|
2766
|
+
});
|
|
2767
|
+
break;
|
|
2768
|
+
default:
|
|
2769
|
+
await listener({ code });
|
|
2770
|
+
break;
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
break;
|
|
2774
|
+
case "change":
|
|
2775
|
+
for (const listener of listeners) {
|
|
2776
|
+
const { path: path$2, kind } = event.watchChangeData();
|
|
2777
|
+
await listener(path$2, { event: kind });
|
|
2778
|
+
}
|
|
2779
|
+
break;
|
|
2780
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
async close() {
|
|
2784
|
+
clearInterval(this.timer);
|
|
2785
|
+
}
|
|
2786
|
+
};
|
|
2787
|
+
|
|
2660
2788
|
//#endregion
|
|
2661
2789
|
//#region src/api/watch/watcher.ts
|
|
2790
|
+
var import_binding = __toESM(require_binding());
|
|
2662
2791
|
var Watcher = class {
|
|
2663
2792
|
closed;
|
|
2664
|
-
controller;
|
|
2665
2793
|
inner;
|
|
2794
|
+
emitter;
|
|
2666
2795
|
stopWorkers;
|
|
2667
|
-
|
|
2668
|
-
constructor(inner, stopWorkers) {
|
|
2796
|
+
constructor(emitter, inner, stopWorkers) {
|
|
2669
2797
|
this.closed = false;
|
|
2670
|
-
this.controller = new AbortController();
|
|
2671
2798
|
this.inner = inner;
|
|
2799
|
+
this.emitter = emitter;
|
|
2800
|
+
const originClose = emitter.close.bind(emitter);
|
|
2801
|
+
emitter.close = async () => {
|
|
2802
|
+
await this.close();
|
|
2803
|
+
originClose();
|
|
2804
|
+
};
|
|
2672
2805
|
this.stopWorkers = stopWorkers;
|
|
2673
2806
|
}
|
|
2674
2807
|
async close() {
|
|
2808
|
+
if (this.closed) return;
|
|
2675
2809
|
this.closed = true;
|
|
2676
|
-
|
|
2810
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
2677
2811
|
await this.inner.close();
|
|
2678
|
-
this.controller.abort();
|
|
2679
2812
|
}
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
if (listeners) listeners.push(listener);
|
|
2683
|
-
else this.listeners.set(event, [listener]);
|
|
2684
|
-
return this;
|
|
2685
|
-
}
|
|
2686
|
-
watch() {
|
|
2687
|
-
const timer = setInterval(
|
|
2688
|
-
() => {},
|
|
2689
|
-
1e9
|
|
2690
|
-
/* Low power usage */
|
|
2691
|
-
);
|
|
2692
|
-
this.controller.signal.addEventListener("abort", () => {
|
|
2693
|
-
clearInterval(timer);
|
|
2694
|
-
});
|
|
2695
|
-
process.nextTick(() => this.inner.start(async (event) => {
|
|
2696
|
-
const listeners = this.listeners.get(event.eventKind());
|
|
2697
|
-
if (listeners) switch (event.eventKind()) {
|
|
2698
|
-
case "close":
|
|
2699
|
-
case "restart":
|
|
2700
|
-
for (const listener of listeners) await listener();
|
|
2701
|
-
break;
|
|
2702
|
-
case "event":
|
|
2703
|
-
for (const listener of listeners) {
|
|
2704
|
-
const code = event.bundleEventKind();
|
|
2705
|
-
switch (code) {
|
|
2706
|
-
case "BUNDLE_END":
|
|
2707
|
-
const { duration, output } = event.bundleEndData();
|
|
2708
|
-
await listener({
|
|
2709
|
-
code: "BUNDLE_END",
|
|
2710
|
-
duration,
|
|
2711
|
-
output: [output]
|
|
2712
|
-
});
|
|
2713
|
-
break;
|
|
2714
|
-
case "ERROR":
|
|
2715
|
-
const errors = event.errors();
|
|
2716
|
-
await listener({
|
|
2717
|
-
code: "ERROR",
|
|
2718
|
-
error: normalizeErrors(errors)
|
|
2719
|
-
});
|
|
2720
|
-
break;
|
|
2721
|
-
default:
|
|
2722
|
-
await listener({ code });
|
|
2723
|
-
break;
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
break;
|
|
2727
|
-
case "change":
|
|
2728
|
-
for (const listener of listeners) {
|
|
2729
|
-
const { path: path$2, kind } = event.watchChangeData();
|
|
2730
|
-
await listener(path$2, { event: kind });
|
|
2731
|
-
}
|
|
2732
|
-
break;
|
|
2733
|
-
default: throw new Error(`Unknown event: ${event}`);
|
|
2734
|
-
}
|
|
2735
|
-
}));
|
|
2813
|
+
start() {
|
|
2814
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
2736
2815
|
}
|
|
2737
2816
|
};
|
|
2817
|
+
async function createWatcher(emitter, input) {
|
|
2818
|
+
const options = Array.isArray(input) ? input : [input];
|
|
2819
|
+
const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
|
|
2820
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
2821
|
+
const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
2822
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
2823
|
+
watcher.start();
|
|
2824
|
+
}
|
|
2825
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
2826
|
+
let result;
|
|
2827
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
2828
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
2829
|
+
if (notifyOption) if (result) {
|
|
2830
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
2831
|
+
return result;
|
|
2832
|
+
} else result = notifyOption;
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2738
2835
|
|
|
2739
2836
|
//#endregion
|
|
2740
2837
|
//#region src/api/watch/index.ts
|
|
2741
|
-
const watch =
|
|
2742
|
-
const
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
watcher.watch();
|
|
2746
|
-
return watcher;
|
|
2838
|
+
const watch = (input) => {
|
|
2839
|
+
const emitter = new WatcherEmitter();
|
|
2840
|
+
createWatcher(emitter, input);
|
|
2841
|
+
return emitter;
|
|
2747
2842
|
};
|
|
2748
2843
|
|
|
2749
2844
|
//#endregion
|
|
2750
2845
|
//#region package.json
|
|
2751
|
-
var version = "0.15.
|
|
2846
|
+
var version = "0.15.1-commit.cc6f557";
|
|
2752
2847
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2753
2848
|
|
|
2754
2849
|
//#endregion
|
|
@@ -2756,10 +2851,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
|
|
|
2756
2851
|
async function build(options) {
|
|
2757
2852
|
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
2758
2853
|
else {
|
|
2759
|
-
const { output,...inputOptions } = options;
|
|
2854
|
+
const { output, write = true,...inputOptions } = options;
|
|
2760
2855
|
const build$1 = await rolldown(inputOptions);
|
|
2761
|
-
|
|
2762
|
-
|
|
2856
|
+
try {
|
|
2857
|
+
if (write) return await build$1.write(output);
|
|
2858
|
+
else return await build$1.generate(output);
|
|
2859
|
+
} finally {
|
|
2860
|
+
await build$1.close();
|
|
2861
|
+
}
|
|
2763
2862
|
}
|
|
2764
2863
|
}
|
|
2765
2864
|
|
|
@@ -2768,4 +2867,4 @@ else return build$1.generate(output);
|
|
|
2768
2867
|
const VERSION = version;
|
|
2769
2868
|
|
|
2770
2869
|
//#endregion
|
|
2771
|
-
export { BuiltinPlugin, LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, PluginContextData, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, VERSION,
|
|
2870
|
+
export { BuiltinPlugin, LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, PluginContextData, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, VERSION, __toESM, arraify, bindingifyPlugin, build, buildImportAnalysisPlugin, composeJsPlugins, createBundler, defineConfig, description, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, rolldown, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch };
|