rolldown 0.15.0 → 0.15.1
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-BQ98i9JJ.mjs} +312 -225
- package/dist/shared/{src-COU7qQBJ.cjs → src-CkH9jtTi.cjs} +301 -208
- 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 +107 -17
- 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 +16 -1
- 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,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
|
}
|
|
@@ -2092,10 +2131,6 @@ function bindingifyWatch(watch$1) {
|
|
|
2092
2131
|
include: normalizedStringOrRegex(watch$1.include),
|
|
2093
2132
|
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2094
2133
|
};
|
|
2095
|
-
if (watch$1.notify) value.notify = {
|
|
2096
|
-
pollInterval: watch$1.notify.pollInterval,
|
|
2097
|
-
compareContents: watch$1.notify.compareContents
|
|
2098
|
-
};
|
|
2099
2134
|
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
2100
2135
|
return value;
|
|
2101
2136
|
}
|
|
@@ -2150,7 +2185,8 @@ function bindingifyOutputOptions(outputOptions) {
|
|
|
2150
2185
|
minify: outputOptions.minify,
|
|
2151
2186
|
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
2152
2187
|
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
2153
|
-
advancedChunks: outputOptions.advancedChunks
|
|
2188
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
2189
|
+
polyfillRequire: outputOptions.polyfillRequire
|
|
2154
2190
|
};
|
|
2155
2191
|
}
|
|
2156
2192
|
function bindingifyAddon(configAddon) {
|
|
@@ -2319,10 +2355,7 @@ function createComposedPlugin(plugins) {
|
|
|
2319
2355
|
const createFixedPluginResolveFnMap = new Map();
|
|
2320
2356
|
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2321
2357
|
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2322
|
-
if (createFixedPluginResolveFn)
|
|
2323
|
-
...ctx,
|
|
2324
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
2325
|
-
};
|
|
2358
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2326
2359
|
return ctx;
|
|
2327
2360
|
}
|
|
2328
2361
|
if (batchedHooks.resolveId) {
|
|
@@ -2331,14 +2364,14 @@ function createComposedPlugin(plugins) {
|
|
|
2331
2364
|
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2332
2365
|
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2333
2366
|
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2334
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
2367
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2335
2368
|
return (source, importer, rawContextResolveOptions) => {
|
|
2336
2369
|
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2337
2370
|
if (contextResolveOptions.skipSelf) {
|
|
2338
2371
|
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2339
2372
|
contextResolveOptions.skipSelf = false;
|
|
2340
2373
|
}
|
|
2341
|
-
return
|
|
2374
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2342
2375
|
};
|
|
2343
2376
|
};
|
|
2344
2377
|
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
@@ -2396,12 +2429,10 @@ function createComposedPlugin(plugins) {
|
|
|
2396
2429
|
}
|
|
2397
2430
|
for (const [handler, plugin] of batchedHandlers) {
|
|
2398
2431
|
const { handler: handlerFn } = normalizeHook(handler);
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
}
|
|
2404
|
-
}, code, id, moduleType);
|
|
2432
|
+
this.getCombinedSourcemap = () => {
|
|
2433
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2434
|
+
};
|
|
2435
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2405
2436
|
if (!isNullish(result)) {
|
|
2406
2437
|
if (typeof result === "string") updateOutput(result);
|
|
2407
2438
|
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
@@ -2536,7 +2567,7 @@ else newPlugins.push(toBeComposed[0]);
|
|
|
2536
2567
|
|
|
2537
2568
|
//#endregion
|
|
2538
2569
|
//#region src/utils/initialize-parallel-plugins.ts
|
|
2539
|
-
var import_binding$
|
|
2570
|
+
var import_binding$2 = __toESM(require_binding());
|
|
2540
2571
|
async function initializeParallelPlugins(plugins) {
|
|
2541
2572
|
const pluginInfos = [];
|
|
2542
2573
|
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
@@ -2549,7 +2580,7 @@ async function initializeParallelPlugins(plugins) {
|
|
|
2549
2580
|
}
|
|
2550
2581
|
if (pluginInfos.length <= 0) return undefined;
|
|
2551
2582
|
const count = Math.min(availableParallelism(), 8);
|
|
2552
|
-
const parallelJsPluginRegistry = new import_binding$
|
|
2583
|
+
const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
|
|
2553
2584
|
const registryId = parallelJsPluginRegistry.id;
|
|
2554
2585
|
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2555
2586
|
const stopWorkers = async () => {
|
|
@@ -2565,14 +2596,14 @@ function initializeWorkers(registryId, count, pluginInfos) {
|
|
|
2565
2596
|
}
|
|
2566
2597
|
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
2567
2598
|
const urlString = import.meta.resolve("#parallel-plugin-worker");
|
|
2568
|
-
const workerData = {
|
|
2599
|
+
const workerData$1 = {
|
|
2569
2600
|
registryId,
|
|
2570
2601
|
pluginInfos,
|
|
2571
2602
|
threadNumber
|
|
2572
2603
|
};
|
|
2573
2604
|
let worker;
|
|
2574
2605
|
try {
|
|
2575
|
-
worker = new Worker(new URL(urlString), { workerData });
|
|
2606
|
+
worker = new Worker(new URL(urlString), { workerData: workerData$1 });
|
|
2576
2607
|
worker.unref();
|
|
2577
2608
|
await new Promise((resolve, reject) => {
|
|
2578
2609
|
worker.once("message", async (message) => {
|
|
@@ -2588,9 +2619,8 @@ else resolve();
|
|
|
2588
2619
|
}
|
|
2589
2620
|
|
|
2590
2621
|
//#endregion
|
|
2591
|
-
//#region src/utils/create-bundler.ts
|
|
2592
|
-
|
|
2593
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
2622
|
+
//#region src/utils/create-bundler-option.ts
|
|
2623
|
+
async function createBundlerOptions(inputOptions, outputOptions) {
|
|
2594
2624
|
const pluginDriver = new PluginDriver();
|
|
2595
2625
|
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
2596
2626
|
if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
|
|
@@ -2606,7 +2636,13 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2606
2636
|
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
|
|
2607
2637
|
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
2608
2638
|
return {
|
|
2609
|
-
|
|
2639
|
+
bundlerOptions: {
|
|
2640
|
+
inputOptions: bindingInputOptions,
|
|
2641
|
+
outputOptions: bindingOutputOptions,
|
|
2642
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
2643
|
+
},
|
|
2644
|
+
inputOptions,
|
|
2645
|
+
onLog,
|
|
2610
2646
|
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
2611
2647
|
};
|
|
2612
2648
|
} catch (e) {
|
|
@@ -2615,6 +2651,22 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2615
2651
|
}
|
|
2616
2652
|
}
|
|
2617
2653
|
|
|
2654
|
+
//#endregion
|
|
2655
|
+
//#region src/utils/create-bundler.ts
|
|
2656
|
+
var import_binding$1 = __toESM(require_binding());
|
|
2657
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
2658
|
+
const option = await createBundlerOptions(inputOptions, outputOptions);
|
|
2659
|
+
try {
|
|
2660
|
+
return {
|
|
2661
|
+
bundler: new import_binding$1.Bundler(option.bundlerOptions),
|
|
2662
|
+
stopWorkers: option.stopWorkers
|
|
2663
|
+
};
|
|
2664
|
+
} catch (e) {
|
|
2665
|
+
await option.stopWorkers?.();
|
|
2666
|
+
throw e;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2618
2670
|
//#endregion
|
|
2619
2671
|
//#region src/api/rolldown/rolldown-build.ts
|
|
2620
2672
|
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
@@ -2657,98 +2709,129 @@ const rolldown = async (input) => {
|
|
|
2657
2709
|
return new RolldownBuild(input);
|
|
2658
2710
|
};
|
|
2659
2711
|
|
|
2712
|
+
//#endregion
|
|
2713
|
+
//#region src/api/watch/watch-emitter.ts
|
|
2714
|
+
var WatcherEmitter = class {
|
|
2715
|
+
listeners = new Map();
|
|
2716
|
+
timer;
|
|
2717
|
+
constructor() {
|
|
2718
|
+
this.timer = setInterval(
|
|
2719
|
+
() => {},
|
|
2720
|
+
1e9
|
|
2721
|
+
/* Low power usage */
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
on(event, listener) {
|
|
2725
|
+
const listeners = this.listeners.get(event);
|
|
2726
|
+
if (listeners) listeners.push(listener);
|
|
2727
|
+
else this.listeners.set(event, [listener]);
|
|
2728
|
+
return this;
|
|
2729
|
+
}
|
|
2730
|
+
async onEvent(event) {
|
|
2731
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
2732
|
+
if (listeners) switch (event.eventKind()) {
|
|
2733
|
+
case "close":
|
|
2734
|
+
case "restart":
|
|
2735
|
+
for (const listener of listeners) await listener();
|
|
2736
|
+
break;
|
|
2737
|
+
case "event":
|
|
2738
|
+
for (const listener of listeners) {
|
|
2739
|
+
const code = event.bundleEventKind();
|
|
2740
|
+
switch (code) {
|
|
2741
|
+
case "BUNDLE_END":
|
|
2742
|
+
const { duration, output } = event.bundleEndData();
|
|
2743
|
+
await listener({
|
|
2744
|
+
code: "BUNDLE_END",
|
|
2745
|
+
duration,
|
|
2746
|
+
output: [output]
|
|
2747
|
+
});
|
|
2748
|
+
break;
|
|
2749
|
+
case "ERROR":
|
|
2750
|
+
const errors = event.errors();
|
|
2751
|
+
await listener({
|
|
2752
|
+
code: "ERROR",
|
|
2753
|
+
error: normalizeErrors(errors)
|
|
2754
|
+
});
|
|
2755
|
+
break;
|
|
2756
|
+
default:
|
|
2757
|
+
await listener({ code });
|
|
2758
|
+
break;
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
break;
|
|
2762
|
+
case "change":
|
|
2763
|
+
for (const listener of listeners) {
|
|
2764
|
+
const { path: path$2, kind } = event.watchChangeData();
|
|
2765
|
+
await listener(path$2, { event: kind });
|
|
2766
|
+
}
|
|
2767
|
+
break;
|
|
2768
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
async close() {
|
|
2772
|
+
clearInterval(this.timer);
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
|
|
2660
2776
|
//#endregion
|
|
2661
2777
|
//#region src/api/watch/watcher.ts
|
|
2778
|
+
var import_binding = __toESM(require_binding());
|
|
2662
2779
|
var Watcher = class {
|
|
2663
2780
|
closed;
|
|
2664
|
-
controller;
|
|
2665
2781
|
inner;
|
|
2782
|
+
emitter;
|
|
2666
2783
|
stopWorkers;
|
|
2667
|
-
|
|
2668
|
-
constructor(inner, stopWorkers) {
|
|
2784
|
+
constructor(emitter, inner, stopWorkers) {
|
|
2669
2785
|
this.closed = false;
|
|
2670
|
-
this.controller = new AbortController();
|
|
2671
2786
|
this.inner = inner;
|
|
2787
|
+
this.emitter = emitter;
|
|
2788
|
+
const originClose = emitter.close.bind(emitter);
|
|
2789
|
+
emitter.close = async () => {
|
|
2790
|
+
await this.close();
|
|
2791
|
+
originClose();
|
|
2792
|
+
};
|
|
2672
2793
|
this.stopWorkers = stopWorkers;
|
|
2673
2794
|
}
|
|
2674
2795
|
async close() {
|
|
2796
|
+
if (this.closed) return;
|
|
2675
2797
|
this.closed = true;
|
|
2676
|
-
|
|
2798
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
2677
2799
|
await this.inner.close();
|
|
2678
|
-
this.controller.abort();
|
|
2679
2800
|
}
|
|
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
|
-
}));
|
|
2801
|
+
start() {
|
|
2802
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
2736
2803
|
}
|
|
2737
2804
|
};
|
|
2805
|
+
async function createWatcher(emitter, input) {
|
|
2806
|
+
const options = Array.isArray(input) ? input : [input];
|
|
2807
|
+
const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
|
|
2808
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
2809
|
+
const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
2810
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
2811
|
+
watcher.start();
|
|
2812
|
+
}
|
|
2813
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
2814
|
+
let result;
|
|
2815
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
2816
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
2817
|
+
if (notifyOption) if (result) {
|
|
2818
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
2819
|
+
return result;
|
|
2820
|
+
} else result = notifyOption;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2738
2823
|
|
|
2739
2824
|
//#endregion
|
|
2740
2825
|
//#region src/api/watch/index.ts
|
|
2741
|
-
const watch =
|
|
2742
|
-
const
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
watcher.watch();
|
|
2746
|
-
return watcher;
|
|
2826
|
+
const watch = (input) => {
|
|
2827
|
+
const emitter = new WatcherEmitter();
|
|
2828
|
+
createWatcher(emitter, input);
|
|
2829
|
+
return emitter;
|
|
2747
2830
|
};
|
|
2748
2831
|
|
|
2749
2832
|
//#endregion
|
|
2750
2833
|
//#region package.json
|
|
2751
|
-
var version = "0.15.
|
|
2834
|
+
var version = "0.15.1";
|
|
2752
2835
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2753
2836
|
|
|
2754
2837
|
//#endregion
|
|
@@ -2756,10 +2839,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
|
|
|
2756
2839
|
async function build(options) {
|
|
2757
2840
|
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
2758
2841
|
else {
|
|
2759
|
-
const { output,...inputOptions } = options;
|
|
2842
|
+
const { output, write = true,...inputOptions } = options;
|
|
2760
2843
|
const build$1 = await rolldown(inputOptions);
|
|
2761
|
-
|
|
2762
|
-
|
|
2844
|
+
try {
|
|
2845
|
+
if (write) return await build$1.write(output);
|
|
2846
|
+
else return await build$1.generate(output);
|
|
2847
|
+
} finally {
|
|
2848
|
+
await build$1.close();
|
|
2849
|
+
}
|
|
2763
2850
|
}
|
|
2764
2851
|
}
|
|
2765
2852
|
|
|
@@ -2768,4 +2855,4 @@ else return build$1.generate(output);
|
|
|
2768
2855
|
const VERSION = version;
|
|
2769
2856
|
|
|
2770
2857
|
//#endregion
|
|
2771
|
-
export { BuiltinPlugin, LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, PluginContextData, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, VERSION,
|
|
2858
|
+
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 };
|