rolldown 0.15.0 → 0.15.1-commit.4e41a08
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-Do1JlyLc.mjs} +324 -232
- package/dist/shared/{src-COU7qQBJ.cjs → src-Dw217EaC.cjs} +313 -215
- 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 +1 -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 +15 -15
- 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,7 @@ 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";
|
|
711
725
|
function logInvalidLogPosition(pluginName) {
|
|
712
726
|
return {
|
|
713
727
|
code: INVALID_LOG_POSITION,
|
|
@@ -726,6 +740,12 @@ function logCycleLoading(pluginName, moduleId) {
|
|
|
726
740
|
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
727
741
|
};
|
|
728
742
|
}
|
|
743
|
+
function logMultiplyNotifyOption() {
|
|
744
|
+
return {
|
|
745
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
746
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
747
|
+
};
|
|
748
|
+
}
|
|
729
749
|
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
730
750
|
const code = error$1.code;
|
|
731
751
|
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
@@ -829,7 +849,8 @@ function getLogger(plugins, onLog, logLevel) {
|
|
|
829
849
|
rolldownVersion: VERSION,
|
|
830
850
|
watchMode: false
|
|
831
851
|
},
|
|
832
|
-
warn: getLogHandler$1(LOG_LEVEL_WARN)
|
|
852
|
+
warn: getLogHandler$1(LOG_LEVEL_WARN),
|
|
853
|
+
pluginName: plugin.name || "unknown"
|
|
833
854
|
}, level, log) === false) return;
|
|
834
855
|
}
|
|
835
856
|
}
|
|
@@ -881,9 +902,9 @@ function relativeId(id) {
|
|
|
881
902
|
|
|
882
903
|
//#endregion
|
|
883
904
|
//#region src/builtin-plugin/utils.ts
|
|
884
|
-
var import_binding$
|
|
905
|
+
var import_binding$6 = __toESM(require_binding());
|
|
885
906
|
function makeBuiltinPluginCallable(plugin) {
|
|
886
|
-
let callablePlugin = new import_binding$
|
|
907
|
+
let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
887
908
|
const wrappedPlugin = plugin;
|
|
888
909
|
for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
|
|
889
910
|
return callablePlugin[key](...args);
|
|
@@ -1052,7 +1073,8 @@ var PluginDriver = class {
|
|
|
1052
1073
|
rolldownVersion: VERSION,
|
|
1053
1074
|
watchMode: false
|
|
1054
1075
|
},
|
|
1055
|
-
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
|
|
1076
|
+
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
|
|
1077
|
+
pluginName: name
|
|
1056
1078
|
}, inputOptions);
|
|
1057
1079
|
if (result) inputOptions = result;
|
|
1058
1080
|
}
|
|
@@ -1116,7 +1138,7 @@ const ModuleSideEffectsRuleSchema = z.object({
|
|
|
1116
1138
|
}).refine((data) => {
|
|
1117
1139
|
return data.test !== undefined || data.external !== undefined;
|
|
1118
1140
|
}, "Either `test` or `external` should be set.");
|
|
1119
|
-
const ModuleSideEffectsOptionSchema = z.boolean().or(z.array(ModuleSideEffectsRuleSchema)).or(z.literal("no-external"));
|
|
1141
|
+
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
1142
|
const TreeshakingOptionsSchema = z.object({
|
|
1121
1143
|
moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
|
|
1122
1144
|
annotations: z.boolean().optional()
|
|
@@ -1152,6 +1174,7 @@ function transformModuleInfo(info, option) {
|
|
|
1152
1174
|
dynamicImporters: info.dynamicImporters,
|
|
1153
1175
|
importedIds: info.importedIds,
|
|
1154
1176
|
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
1177
|
+
exports: info.exports,
|
|
1155
1178
|
isEntry: info.isEntry,
|
|
1156
1179
|
...option
|
|
1157
1180
|
};
|
|
@@ -1164,31 +1187,30 @@ var MinimalPluginContext = class {
|
|
|
1164
1187
|
warn;
|
|
1165
1188
|
debug;
|
|
1166
1189
|
meta;
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
const pluginName = plugin.name || "unknown";
|
|
1190
|
+
constructor(onLog, logLevel, pluginName) {
|
|
1191
|
+
this.pluginName = pluginName;
|
|
1170
1192
|
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1171
1193
|
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1172
1194
|
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
1173
|
-
this.error = (e) => {
|
|
1174
|
-
return error(logPluginError(normalizeLog(e), pluginName));
|
|
1175
|
-
};
|
|
1176
1195
|
this.meta = {
|
|
1177
1196
|
rollupVersion: "4.23.0",
|
|
1178
1197
|
rolldownVersion: VERSION,
|
|
1179
1198
|
watchMode: false
|
|
1180
1199
|
};
|
|
1181
1200
|
}
|
|
1201
|
+
error(e) {
|
|
1202
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1203
|
+
}
|
|
1182
1204
|
};
|
|
1183
1205
|
|
|
1184
1206
|
//#endregion
|
|
1185
1207
|
//#region src/utils/transform-side-effects.ts
|
|
1186
|
-
var import_binding$
|
|
1208
|
+
var import_binding$5 = __toESM(require_binding());
|
|
1187
1209
|
function bindingifySideEffects(sideEffects) {
|
|
1188
1210
|
switch (sideEffects) {
|
|
1189
|
-
case true: return import_binding$
|
|
1190
|
-
case false: return import_binding$
|
|
1191
|
-
case "no-treeshake": return import_binding$
|
|
1211
|
+
case true: return import_binding$5.BindingHookSideEffects.True;
|
|
1212
|
+
case false: return import_binding$5.BindingHookSideEffects.False;
|
|
1213
|
+
case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
|
|
1192
1214
|
case null:
|
|
1193
1215
|
case undefined: return undefined;
|
|
1194
1216
|
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
@@ -1198,84 +1220,92 @@ function bindingifySideEffects(sideEffects) {
|
|
|
1198
1220
|
//#endregion
|
|
1199
1221
|
//#region src/plugin/plugin-context.ts
|
|
1200
1222
|
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
1223
|
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
|
-
};
|
|
1224
|
+
super(onLog, logLevel, plugin.name);
|
|
1225
|
+
this.context = context;
|
|
1226
|
+
this.data = data;
|
|
1227
|
+
this.onLog = onLog;
|
|
1228
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1229
|
+
}
|
|
1230
|
+
async load(options) {
|
|
1231
|
+
const id = options.id;
|
|
1232
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(super.pluginName, this.currentLoadingModule));
|
|
1233
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1234
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1235
|
+
const rawOptions = {
|
|
1236
|
+
meta: options.meta || {},
|
|
1237
|
+
moduleSideEffects: options.moduleSideEffects || null
|
|
1255
1238
|
};
|
|
1256
|
-
this.
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1239
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1240
|
+
async function createLoadModulePromise(context, data) {
|
|
1241
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
1242
|
+
if (loadPromise) return loadPromise;
|
|
1243
|
+
let resolveFn;
|
|
1244
|
+
const promise = new Promise((resolve, _) => {
|
|
1245
|
+
resolveFn = resolve;
|
|
1262
1246
|
});
|
|
1247
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
1248
|
+
try {
|
|
1249
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1250
|
+
} finally {
|
|
1251
|
+
data.loadModulePromiseMap.delete(id);
|
|
1252
|
+
}
|
|
1253
|
+
return promise;
|
|
1254
|
+
}
|
|
1255
|
+
await createLoadModulePromise(this.context, this.data);
|
|
1256
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1257
|
+
}
|
|
1258
|
+
async resolve(source, importer, options) {
|
|
1259
|
+
let receipt = undefined;
|
|
1260
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1261
|
+
const res = await this.context.resolve(source, importer, {
|
|
1262
|
+
custom: receipt,
|
|
1263
|
+
skipSelf: options?.skipSelf
|
|
1264
|
+
});
|
|
1265
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1266
|
+
if (res == null) return null;
|
|
1267
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1268
|
+
return {
|
|
1269
|
+
...res,
|
|
1270
|
+
...info
|
|
1263
1271
|
};
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
this.
|
|
1268
|
-
|
|
1272
|
+
}
|
|
1273
|
+
emitFile(file) {
|
|
1274
|
+
if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
|
|
1275
|
+
return this.context.emitFile({
|
|
1276
|
+
...file,
|
|
1277
|
+
originalFileName: file.originalFileName || undefined,
|
|
1278
|
+
source: bindingAssetSource(file.source)
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
getFileName(referenceId) {
|
|
1282
|
+
return this.context.getFileName(referenceId);
|
|
1283
|
+
}
|
|
1284
|
+
getModuleInfo(id) {
|
|
1285
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1286
|
+
}
|
|
1287
|
+
getModuleIds() {
|
|
1288
|
+
return this.data.getModuleIds(this.context);
|
|
1289
|
+
}
|
|
1290
|
+
addWatchFile(id) {
|
|
1291
|
+
this.context.addWatchFile(id);
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1295
|
+
*/
|
|
1296
|
+
parse(_input, _options) {
|
|
1297
|
+
unsupported("`PluginContext#parse` is not supported by rolldown.");
|
|
1269
1298
|
}
|
|
1270
1299
|
};
|
|
1271
1300
|
|
|
1272
1301
|
//#endregion
|
|
1273
1302
|
//#region src/plugin/transform-plugin-context.ts
|
|
1274
1303
|
var TransformPluginContext = class extends PluginContext {
|
|
1275
|
-
error;
|
|
1276
|
-
getCombinedSourcemap;
|
|
1277
1304
|
constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
1278
1305
|
super(context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
1306
|
+
this.inner = inner;
|
|
1307
|
+
this.moduleId = moduleId;
|
|
1308
|
+
this.moduleSource = moduleSource;
|
|
1279
1309
|
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
1280
1310
|
log = normalizeLog(log);
|
|
1281
1311
|
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
@@ -1286,27 +1316,29 @@ var TransformPluginContext = class extends PluginContext {
|
|
|
1286
1316
|
this.debug = getLogHandler$1(this.debug);
|
|
1287
1317
|
this.warn = getLogHandler$1(this.warn);
|
|
1288
1318
|
this.info = getLogHandler$1(this.info);
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1319
|
+
}
|
|
1320
|
+
error(e, pos) {
|
|
1321
|
+
if (typeof e === "string") e = { message: e };
|
|
1322
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1323
|
+
e.id = this.moduleId;
|
|
1324
|
+
e.hook = "transform";
|
|
1325
|
+
return error(logPluginError(normalizeLog(e), super.pluginName));
|
|
1326
|
+
}
|
|
1327
|
+
getCombinedSourcemap() {
|
|
1328
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1297
1329
|
}
|
|
1298
1330
|
};
|
|
1299
1331
|
|
|
1300
1332
|
//#endregion
|
|
1301
1333
|
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1302
|
-
var import_binding$
|
|
1334
|
+
var import_binding$4 = __toESM(require_binding());
|
|
1303
1335
|
function bindingifyPluginHookMeta(options) {
|
|
1304
1336
|
return { order: bindingPluginOrder(options.order) };
|
|
1305
1337
|
}
|
|
1306
1338
|
function bindingPluginOrder(order) {
|
|
1307
1339
|
switch (order) {
|
|
1308
|
-
case "post": return import_binding$
|
|
1309
|
-
case "pre": return import_binding$
|
|
1340
|
+
case "post": return import_binding$4.BindingPluginOrder.Post;
|
|
1341
|
+
case "pre": return import_binding$4.BindingPluginOrder.Pre;
|
|
1310
1342
|
case null:
|
|
1311
1343
|
case undefined: return undefined;
|
|
1312
1344
|
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
@@ -1387,7 +1419,7 @@ function bindingifyBuildEnd(args) {
|
|
|
1387
1419
|
const { handler, meta } = normalizeHook(hook);
|
|
1388
1420
|
return {
|
|
1389
1421
|
plugin: async (ctx, err) => {
|
|
1390
|
-
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err
|
|
1422
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
|
|
1391
1423
|
},
|
|
1392
1424
|
meta: bindingifyPluginHookMeta(meta)
|
|
1393
1425
|
};
|
|
@@ -1526,7 +1558,9 @@ function bindingifyModuleParsed(args) {
|
|
|
1526
1558
|
//#endregion
|
|
1527
1559
|
//#region src/options/normalized-output-options.ts
|
|
1528
1560
|
function mapFunctionOption(option, name) {
|
|
1529
|
-
return typeof option === "undefined" ?
|
|
1561
|
+
return typeof option === "undefined" ? () => {
|
|
1562
|
+
unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
|
|
1563
|
+
} : option;
|
|
1530
1564
|
}
|
|
1531
1565
|
var NormalizedOutputOptionsImpl = class {
|
|
1532
1566
|
inner;
|
|
@@ -1614,6 +1648,9 @@ var NormalizedOutputOptionsImpl = class {
|
|
|
1614
1648
|
get comments() {
|
|
1615
1649
|
return this.inner.comments;
|
|
1616
1650
|
}
|
|
1651
|
+
get polyfillRequire() {
|
|
1652
|
+
return this.inner.polyfillRequire;
|
|
1653
|
+
}
|
|
1617
1654
|
};
|
|
1618
1655
|
|
|
1619
1656
|
//#endregion
|
|
@@ -1664,7 +1701,7 @@ function bindingifyRenderError(args) {
|
|
|
1664
1701
|
const { handler, meta } = normalizeHook(hook);
|
|
1665
1702
|
return {
|
|
1666
1703
|
plugin: async (ctx, err) => {
|
|
1667
|
-
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel),
|
|
1704
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
1668
1705
|
},
|
|
1669
1706
|
meta: bindingifyPluginHookMeta(meta)
|
|
1670
1707
|
};
|
|
@@ -1965,7 +2002,7 @@ function normalizedStringOrRegex(pattern) {
|
|
|
1965
2002
|
|
|
1966
2003
|
//#endregion
|
|
1967
2004
|
//#region src/utils/bindingify-input-options.ts
|
|
1968
|
-
var import_binding$
|
|
2005
|
+
var import_binding$3 = __toESM(require_binding());
|
|
1969
2006
|
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
|
|
1970
2007
|
const pluginContextData = new PluginContextData();
|
|
1971
2008
|
const plugins = rawPlugins.map((plugin) => {
|
|
@@ -1996,7 +2033,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
|
|
|
1996
2033
|
profilerNames: inputOptions?.profilerNames,
|
|
1997
2034
|
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1998
2035
|
watch: bindingifyWatch(inputOptions.watch),
|
|
1999
|
-
dropLabels: inputOptions.dropLabels
|
|
2036
|
+
dropLabels: inputOptions.dropLabels,
|
|
2037
|
+
keepNames: inputOptions.keepNames,
|
|
2038
|
+
checks: inputOptions.checks
|
|
2000
2039
|
};
|
|
2001
2040
|
}
|
|
2002
2041
|
function bindingifyExternal(external) {
|
|
@@ -2020,7 +2059,7 @@ function bindingifyResolve(resolve) {
|
|
|
2020
2059
|
return {
|
|
2021
2060
|
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
2022
2061
|
find: name,
|
|
2023
|
-
replacements:
|
|
2062
|
+
replacements: arraify(replacement)
|
|
2024
2063
|
})) : undefined,
|
|
2025
2064
|
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
2026
2065
|
target: name,
|
|
@@ -2054,10 +2093,10 @@ function bindingifyInject(inject) {
|
|
|
2054
2093
|
}
|
|
2055
2094
|
function bindingifyLogLevel(logLevel) {
|
|
2056
2095
|
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$
|
|
2096
|
+
case "silent": return import_binding$3.BindingLogLevel.Silent;
|
|
2097
|
+
case "debug": return import_binding$3.BindingLogLevel.Debug;
|
|
2098
|
+
case "warn": return import_binding$3.BindingLogLevel.Warn;
|
|
2099
|
+
case "info": return import_binding$3.BindingLogLevel.Info;
|
|
2061
2100
|
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2062
2101
|
}
|
|
2063
2102
|
}
|
|
@@ -2073,15 +2112,20 @@ function bindingifyInput(input) {
|
|
|
2073
2112
|
});
|
|
2074
2113
|
}
|
|
2075
2114
|
function bindingifyJsx(input) {
|
|
2115
|
+
if (input === false) return { type: "Disable" };
|
|
2076
2116
|
if (input) {
|
|
2077
|
-
|
|
2117
|
+
if (input.mode === "preserve") return { type: "Preserve" };
|
|
2118
|
+
const mode = input.mode ?? "automatic";
|
|
2078
2119
|
return {
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2120
|
+
type: "Enable",
|
|
2121
|
+
field0: {
|
|
2122
|
+
runtime: mode,
|
|
2123
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
|
|
2124
|
+
pragma: input.factory,
|
|
2125
|
+
pragmaFrag: input.fragment,
|
|
2126
|
+
development: input.development,
|
|
2127
|
+
refresh: input.refresh
|
|
2128
|
+
}
|
|
2085
2129
|
};
|
|
2086
2130
|
}
|
|
2087
2131
|
}
|
|
@@ -2092,10 +2136,6 @@ function bindingifyWatch(watch$1) {
|
|
|
2092
2136
|
include: normalizedStringOrRegex(watch$1.include),
|
|
2093
2137
|
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2094
2138
|
};
|
|
2095
|
-
if (watch$1.notify) value.notify = {
|
|
2096
|
-
pollInterval: watch$1.notify.pollInterval,
|
|
2097
|
-
compareContents: watch$1.notify.compareContents
|
|
2098
|
-
};
|
|
2099
2139
|
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
2100
2140
|
return value;
|
|
2101
2141
|
}
|
|
@@ -2150,7 +2190,8 @@ function bindingifyOutputOptions(outputOptions) {
|
|
|
2150
2190
|
minify: outputOptions.minify,
|
|
2151
2191
|
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
2152
2192
|
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
2153
|
-
advancedChunks: outputOptions.advancedChunks
|
|
2193
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
2194
|
+
polyfillRequire: outputOptions.polyfillRequire
|
|
2154
2195
|
};
|
|
2155
2196
|
}
|
|
2156
2197
|
function bindingifyAddon(configAddon) {
|
|
@@ -2319,10 +2360,7 @@ function createComposedPlugin(plugins) {
|
|
|
2319
2360
|
const createFixedPluginResolveFnMap = new Map();
|
|
2320
2361
|
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2321
2362
|
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2322
|
-
if (createFixedPluginResolveFn)
|
|
2323
|
-
...ctx,
|
|
2324
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
2325
|
-
};
|
|
2363
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2326
2364
|
return ctx;
|
|
2327
2365
|
}
|
|
2328
2366
|
if (batchedHooks.resolveId) {
|
|
@@ -2331,14 +2369,14 @@ function createComposedPlugin(plugins) {
|
|
|
2331
2369
|
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2332
2370
|
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2333
2371
|
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2334
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
2372
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2335
2373
|
return (source, importer, rawContextResolveOptions) => {
|
|
2336
2374
|
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2337
2375
|
if (contextResolveOptions.skipSelf) {
|
|
2338
2376
|
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2339
2377
|
contextResolveOptions.skipSelf = false;
|
|
2340
2378
|
}
|
|
2341
|
-
return
|
|
2379
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2342
2380
|
};
|
|
2343
2381
|
};
|
|
2344
2382
|
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
@@ -2396,12 +2434,10 @@ function createComposedPlugin(plugins) {
|
|
|
2396
2434
|
}
|
|
2397
2435
|
for (const [handler, plugin] of batchedHandlers) {
|
|
2398
2436
|
const { handler: handlerFn } = normalizeHook(handler);
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
}
|
|
2404
|
-
}, code, id, moduleType);
|
|
2437
|
+
this.getCombinedSourcemap = () => {
|
|
2438
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2439
|
+
};
|
|
2440
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2405
2441
|
if (!isNullish(result)) {
|
|
2406
2442
|
if (typeof result === "string") updateOutput(result);
|
|
2407
2443
|
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
@@ -2536,7 +2572,7 @@ else newPlugins.push(toBeComposed[0]);
|
|
|
2536
2572
|
|
|
2537
2573
|
//#endregion
|
|
2538
2574
|
//#region src/utils/initialize-parallel-plugins.ts
|
|
2539
|
-
var import_binding$
|
|
2575
|
+
var import_binding$2 = __toESM(require_binding());
|
|
2540
2576
|
async function initializeParallelPlugins(plugins) {
|
|
2541
2577
|
const pluginInfos = [];
|
|
2542
2578
|
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
@@ -2549,7 +2585,7 @@ async function initializeParallelPlugins(plugins) {
|
|
|
2549
2585
|
}
|
|
2550
2586
|
if (pluginInfos.length <= 0) return undefined;
|
|
2551
2587
|
const count = Math.min(availableParallelism(), 8);
|
|
2552
|
-
const parallelJsPluginRegistry = new import_binding$
|
|
2588
|
+
const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
|
|
2553
2589
|
const registryId = parallelJsPluginRegistry.id;
|
|
2554
2590
|
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2555
2591
|
const stopWorkers = async () => {
|
|
@@ -2565,14 +2601,14 @@ function initializeWorkers(registryId, count, pluginInfos) {
|
|
|
2565
2601
|
}
|
|
2566
2602
|
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
2567
2603
|
const urlString = import.meta.resolve("#parallel-plugin-worker");
|
|
2568
|
-
const workerData = {
|
|
2604
|
+
const workerData$1 = {
|
|
2569
2605
|
registryId,
|
|
2570
2606
|
pluginInfos,
|
|
2571
2607
|
threadNumber
|
|
2572
2608
|
};
|
|
2573
2609
|
let worker;
|
|
2574
2610
|
try {
|
|
2575
|
-
worker = new Worker(new URL(urlString), { workerData });
|
|
2611
|
+
worker = new Worker(new URL(urlString), { workerData: workerData$1 });
|
|
2576
2612
|
worker.unref();
|
|
2577
2613
|
await new Promise((resolve, reject) => {
|
|
2578
2614
|
worker.once("message", async (message) => {
|
|
@@ -2588,9 +2624,8 @@ else resolve();
|
|
|
2588
2624
|
}
|
|
2589
2625
|
|
|
2590
2626
|
//#endregion
|
|
2591
|
-
//#region src/utils/create-bundler.ts
|
|
2592
|
-
|
|
2593
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
2627
|
+
//#region src/utils/create-bundler-option.ts
|
|
2628
|
+
async function createBundlerOptions(inputOptions, outputOptions) {
|
|
2594
2629
|
const pluginDriver = new PluginDriver();
|
|
2595
2630
|
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
2596
2631
|
if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
|
|
@@ -2606,7 +2641,13 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2606
2641
|
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
|
|
2607
2642
|
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
2608
2643
|
return {
|
|
2609
|
-
|
|
2644
|
+
bundlerOptions: {
|
|
2645
|
+
inputOptions: bindingInputOptions,
|
|
2646
|
+
outputOptions: bindingOutputOptions,
|
|
2647
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
2648
|
+
},
|
|
2649
|
+
inputOptions,
|
|
2650
|
+
onLog,
|
|
2610
2651
|
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
2611
2652
|
};
|
|
2612
2653
|
} catch (e) {
|
|
@@ -2615,6 +2656,22 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2615
2656
|
}
|
|
2616
2657
|
}
|
|
2617
2658
|
|
|
2659
|
+
//#endregion
|
|
2660
|
+
//#region src/utils/create-bundler.ts
|
|
2661
|
+
var import_binding$1 = __toESM(require_binding());
|
|
2662
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
2663
|
+
const option = await createBundlerOptions(inputOptions, outputOptions);
|
|
2664
|
+
try {
|
|
2665
|
+
return {
|
|
2666
|
+
bundler: new import_binding$1.Bundler(option.bundlerOptions),
|
|
2667
|
+
stopWorkers: option.stopWorkers
|
|
2668
|
+
};
|
|
2669
|
+
} catch (e) {
|
|
2670
|
+
await option.stopWorkers?.();
|
|
2671
|
+
throw e;
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2618
2675
|
//#endregion
|
|
2619
2676
|
//#region src/api/rolldown/rolldown-build.ts
|
|
2620
2677
|
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
@@ -2657,98 +2714,129 @@ const rolldown = async (input) => {
|
|
|
2657
2714
|
return new RolldownBuild(input);
|
|
2658
2715
|
};
|
|
2659
2716
|
|
|
2717
|
+
//#endregion
|
|
2718
|
+
//#region src/api/watch/watch-emitter.ts
|
|
2719
|
+
var WatcherEmitter = class {
|
|
2720
|
+
listeners = new Map();
|
|
2721
|
+
timer;
|
|
2722
|
+
constructor() {
|
|
2723
|
+
this.timer = setInterval(
|
|
2724
|
+
() => {},
|
|
2725
|
+
1e9
|
|
2726
|
+
/* Low power usage */
|
|
2727
|
+
);
|
|
2728
|
+
}
|
|
2729
|
+
on(event, listener) {
|
|
2730
|
+
const listeners = this.listeners.get(event);
|
|
2731
|
+
if (listeners) listeners.push(listener);
|
|
2732
|
+
else this.listeners.set(event, [listener]);
|
|
2733
|
+
return this;
|
|
2734
|
+
}
|
|
2735
|
+
async onEvent(event) {
|
|
2736
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
2737
|
+
if (listeners) switch (event.eventKind()) {
|
|
2738
|
+
case "close":
|
|
2739
|
+
case "restart":
|
|
2740
|
+
for (const listener of listeners) await listener();
|
|
2741
|
+
break;
|
|
2742
|
+
case "event":
|
|
2743
|
+
for (const listener of listeners) {
|
|
2744
|
+
const code = event.bundleEventKind();
|
|
2745
|
+
switch (code) {
|
|
2746
|
+
case "BUNDLE_END":
|
|
2747
|
+
const { duration, output } = event.bundleEndData();
|
|
2748
|
+
await listener({
|
|
2749
|
+
code: "BUNDLE_END",
|
|
2750
|
+
duration,
|
|
2751
|
+
output: [output]
|
|
2752
|
+
});
|
|
2753
|
+
break;
|
|
2754
|
+
case "ERROR":
|
|
2755
|
+
const errors = event.errors();
|
|
2756
|
+
await listener({
|
|
2757
|
+
code: "ERROR",
|
|
2758
|
+
error: normalizeErrors(errors)
|
|
2759
|
+
});
|
|
2760
|
+
break;
|
|
2761
|
+
default:
|
|
2762
|
+
await listener({ code });
|
|
2763
|
+
break;
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
break;
|
|
2767
|
+
case "change":
|
|
2768
|
+
for (const listener of listeners) {
|
|
2769
|
+
const { path: path$2, kind } = event.watchChangeData();
|
|
2770
|
+
await listener(path$2, { event: kind });
|
|
2771
|
+
}
|
|
2772
|
+
break;
|
|
2773
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
async close() {
|
|
2777
|
+
clearInterval(this.timer);
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2780
|
+
|
|
2660
2781
|
//#endregion
|
|
2661
2782
|
//#region src/api/watch/watcher.ts
|
|
2783
|
+
var import_binding = __toESM(require_binding());
|
|
2662
2784
|
var Watcher = class {
|
|
2663
2785
|
closed;
|
|
2664
|
-
controller;
|
|
2665
2786
|
inner;
|
|
2787
|
+
emitter;
|
|
2666
2788
|
stopWorkers;
|
|
2667
|
-
|
|
2668
|
-
constructor(inner, stopWorkers) {
|
|
2789
|
+
constructor(emitter, inner, stopWorkers) {
|
|
2669
2790
|
this.closed = false;
|
|
2670
|
-
this.controller = new AbortController();
|
|
2671
2791
|
this.inner = inner;
|
|
2792
|
+
this.emitter = emitter;
|
|
2793
|
+
const originClose = emitter.close.bind(emitter);
|
|
2794
|
+
emitter.close = async () => {
|
|
2795
|
+
await this.close();
|
|
2796
|
+
originClose();
|
|
2797
|
+
};
|
|
2672
2798
|
this.stopWorkers = stopWorkers;
|
|
2673
2799
|
}
|
|
2674
2800
|
async close() {
|
|
2801
|
+
if (this.closed) return;
|
|
2675
2802
|
this.closed = true;
|
|
2676
|
-
|
|
2803
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
2677
2804
|
await this.inner.close();
|
|
2678
|
-
this.controller.abort();
|
|
2679
2805
|
}
|
|
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
|
-
}));
|
|
2806
|
+
start() {
|
|
2807
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
2736
2808
|
}
|
|
2737
2809
|
};
|
|
2810
|
+
async function createWatcher(emitter, input) {
|
|
2811
|
+
const options = Array.isArray(input) ? input : [input];
|
|
2812
|
+
const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
|
|
2813
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
2814
|
+
const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
2815
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
2816
|
+
watcher.start();
|
|
2817
|
+
}
|
|
2818
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
2819
|
+
let result;
|
|
2820
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
2821
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
2822
|
+
if (notifyOption) if (result) {
|
|
2823
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
2824
|
+
return result;
|
|
2825
|
+
} else result = notifyOption;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2738
2828
|
|
|
2739
2829
|
//#endregion
|
|
2740
2830
|
//#region src/api/watch/index.ts
|
|
2741
|
-
const watch =
|
|
2742
|
-
const
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
watcher.watch();
|
|
2746
|
-
return watcher;
|
|
2831
|
+
const watch = (input) => {
|
|
2832
|
+
const emitter = new WatcherEmitter();
|
|
2833
|
+
createWatcher(emitter, input);
|
|
2834
|
+
return emitter;
|
|
2747
2835
|
};
|
|
2748
2836
|
|
|
2749
2837
|
//#endregion
|
|
2750
2838
|
//#region package.json
|
|
2751
|
-
var version = "0.15.
|
|
2839
|
+
var version = "0.15.1-commit.4e41a08";
|
|
2752
2840
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2753
2841
|
|
|
2754
2842
|
//#endregion
|
|
@@ -2756,10 +2844,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
|
|
|
2756
2844
|
async function build(options) {
|
|
2757
2845
|
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
2758
2846
|
else {
|
|
2759
|
-
const { output,...inputOptions } = options;
|
|
2847
|
+
const { output, write = true,...inputOptions } = options;
|
|
2760
2848
|
const build$1 = await rolldown(inputOptions);
|
|
2761
|
-
|
|
2762
|
-
|
|
2849
|
+
try {
|
|
2850
|
+
if (write) return await build$1.write(output);
|
|
2851
|
+
else return await build$1.generate(output);
|
|
2852
|
+
} finally {
|
|
2853
|
+
await build$1.close();
|
|
2854
|
+
}
|
|
2763
2855
|
}
|
|
2764
2856
|
}
|
|
2765
2857
|
|
|
@@ -2768,4 +2860,4 @@ else return build$1.generate(output);
|
|
|
2768
2860
|
const VERSION = version;
|
|
2769
2861
|
|
|
2770
2862
|
//#endregion
|
|
2771
|
-
export { BuiltinPlugin, LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, PluginContextData, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, VERSION,
|
|
2863
|
+
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 };
|