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,4 +1,5 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
1
|
+
const require_chunk = require('./chunk-BFvIen8E.cjs');
|
|
2
|
+
const node_buffer = require_chunk.__toESM(require("node:buffer"));
|
|
2
3
|
const zod = require_chunk.__toESM(require("zod"));
|
|
3
4
|
const node_path = require_chunk.__toESM(require("node:path"));
|
|
4
5
|
const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
|
|
@@ -35,7 +36,11 @@ function bindingifySourcemap$1(map) {
|
|
|
35
36
|
//#endregion
|
|
36
37
|
//#region src/utils/error.ts
|
|
37
38
|
function normalizeErrors(rawErrors) {
|
|
38
|
-
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(),
|
|
39
|
+
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
|
|
40
|
+
kind: e.kind,
|
|
41
|
+
message: e.message,
|
|
42
|
+
stack: undefined
|
|
43
|
+
}));
|
|
39
44
|
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
40
45
|
for (let i = 0; i < errors.length; i++) {
|
|
41
46
|
if (i >= 5) {
|
|
@@ -107,6 +112,19 @@ function transformChunkModules(modules) {
|
|
|
107
112
|
|
|
108
113
|
//#endregion
|
|
109
114
|
//#region src/utils/transform-to-rollup-output.ts
|
|
115
|
+
function transformToRollupSourceMap(map) {
|
|
116
|
+
const parsed = JSON.parse(map);
|
|
117
|
+
const obj = {
|
|
118
|
+
...parsed,
|
|
119
|
+
toString() {
|
|
120
|
+
return JSON.stringify(obj);
|
|
121
|
+
},
|
|
122
|
+
toUrl() {
|
|
123
|
+
return `data:application/json;charset=utf-8;base64,${node_buffer.Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
return obj;
|
|
127
|
+
}
|
|
110
128
|
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
111
129
|
const chunk = {
|
|
112
130
|
type: "chunk",
|
|
@@ -132,7 +150,7 @@ function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
|
132
150
|
return bindingChunk.moduleIds;
|
|
133
151
|
},
|
|
134
152
|
get map() {
|
|
135
|
-
return bindingChunk.map ?
|
|
153
|
+
return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
|
|
136
154
|
},
|
|
137
155
|
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
138
156
|
preliminaryFileName: bindingChunk.preliminaryFileName
|
|
@@ -155,10 +173,12 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
|
155
173
|
type: "asset",
|
|
156
174
|
fileName: bindingAsset.fileName,
|
|
157
175
|
originalFileName: bindingAsset.originalFileName || null,
|
|
176
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
158
177
|
get source() {
|
|
159
178
|
return transformAssetSource(bindingAsset.source);
|
|
160
179
|
},
|
|
161
|
-
name: bindingAsset.name ?? undefined
|
|
180
|
+
name: bindingAsset.name ?? undefined,
|
|
181
|
+
names: bindingAsset.names
|
|
162
182
|
};
|
|
163
183
|
const cache = {};
|
|
164
184
|
return new Proxy(asset, {
|
|
@@ -197,9 +217,9 @@ function collectChangedBundle(changed, bundle) {
|
|
|
197
217
|
const item = bundle[key];
|
|
198
218
|
if (item.type === "asset") assets.push({
|
|
199
219
|
filename: item.fileName,
|
|
200
|
-
|
|
220
|
+
originalFileNames: item.originalFileNames,
|
|
201
221
|
source: bindingAssetSource(item.source),
|
|
202
|
-
|
|
222
|
+
names: item.names
|
|
203
223
|
});
|
|
204
224
|
else chunks.push({
|
|
205
225
|
code: item.code,
|
|
@@ -517,7 +537,7 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
|
|
|
517
537
|
}
|
|
518
538
|
module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
|
|
519
539
|
module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
|
|
520
|
-
module.exports.
|
|
540
|
+
module.exports.BindingError = nativeBinding.BindingError;
|
|
521
541
|
module.exports.BindingLog = nativeBinding.BindingLog;
|
|
522
542
|
module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
|
|
523
543
|
module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
|
|
@@ -536,8 +556,10 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
|
|
|
536
556
|
module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
|
|
537
557
|
module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
|
|
538
558
|
module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
|
|
559
|
+
module.exports.HelperMode = nativeBinding.HelperMode;
|
|
539
560
|
module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
|
|
540
561
|
module.exports.registerPlugins = nativeBinding.registerPlugins;
|
|
562
|
+
module.exports.Severity = nativeBinding.Severity;
|
|
541
563
|
module.exports.transform = nativeBinding.transform;
|
|
542
564
|
} });
|
|
543
565
|
|
|
@@ -558,9 +580,7 @@ function unreachable(info) {
|
|
|
558
580
|
throw new Error("unreachable");
|
|
559
581
|
}
|
|
560
582
|
function unsupported(info) {
|
|
561
|
-
|
|
562
|
-
throw new Error(`UNSUPPORTED: ${info}`);
|
|
563
|
-
};
|
|
583
|
+
throw new Error(`UNSUPPORTED: ${info}`);
|
|
564
584
|
}
|
|
565
585
|
function noop(..._args) {}
|
|
566
586
|
|
|
@@ -675,7 +695,7 @@ function locate(source, search, options) {
|
|
|
675
695
|
|
|
676
696
|
//#endregion
|
|
677
697
|
//#region src/log/logs.ts
|
|
678
|
-
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";
|
|
698
|
+
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";
|
|
679
699
|
function logInvalidLogPosition(pluginName) {
|
|
680
700
|
return {
|
|
681
701
|
code: INVALID_LOG_POSITION,
|
|
@@ -694,6 +714,12 @@ function logCycleLoading(pluginName, moduleId) {
|
|
|
694
714
|
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
695
715
|
};
|
|
696
716
|
}
|
|
717
|
+
function logMultiplyNotifyOption() {
|
|
718
|
+
return {
|
|
719
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
720
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
721
|
+
};
|
|
722
|
+
}
|
|
697
723
|
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
698
724
|
const code = error$1.code;
|
|
699
725
|
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
@@ -797,7 +823,8 @@ function getLogger(plugins, onLog, logLevel) {
|
|
|
797
823
|
rolldownVersion: VERSION,
|
|
798
824
|
watchMode: false
|
|
799
825
|
},
|
|
800
|
-
warn: getLogHandler$1(LOG_LEVEL_WARN)
|
|
826
|
+
warn: getLogHandler$1(LOG_LEVEL_WARN),
|
|
827
|
+
pluginName: plugin.name || "unknown"
|
|
801
828
|
}, level, log) === false) return;
|
|
802
829
|
}
|
|
803
830
|
}
|
|
@@ -849,9 +876,9 @@ function relativeId(id) {
|
|
|
849
876
|
|
|
850
877
|
//#endregion
|
|
851
878
|
//#region src/builtin-plugin/utils.ts
|
|
852
|
-
var import_binding$
|
|
879
|
+
var import_binding$6 = require_chunk.__toESM(require_binding());
|
|
853
880
|
function makeBuiltinPluginCallable(plugin) {
|
|
854
|
-
let callablePlugin = new import_binding$
|
|
881
|
+
let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
855
882
|
const wrappedPlugin = plugin;
|
|
856
883
|
for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
|
|
857
884
|
return callablePlugin[key](...args);
|
|
@@ -1020,7 +1047,8 @@ var PluginDriver = class {
|
|
|
1020
1047
|
rolldownVersion: VERSION,
|
|
1021
1048
|
watchMode: false
|
|
1022
1049
|
},
|
|
1023
|
-
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
|
|
1050
|
+
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
|
|
1051
|
+
pluginName: name
|
|
1024
1052
|
}, inputOptions);
|
|
1025
1053
|
if (result) inputOptions = result;
|
|
1026
1054
|
}
|
|
@@ -1084,7 +1112,7 @@ const ModuleSideEffectsRuleSchema = zod.z.object({
|
|
|
1084
1112
|
}).refine((data) => {
|
|
1085
1113
|
return data.test !== undefined || data.external !== undefined;
|
|
1086
1114
|
}, "Either `test` or `external` should be set.");
|
|
1087
|
-
const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.literal("no-external"));
|
|
1115
|
+
const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.function().args(zod.z.string(), zod.z.boolean()).returns(zod.z.boolean().optional())).or(zod.z.literal("no-external"));
|
|
1088
1116
|
const TreeshakingOptionsSchema = zod.z.object({
|
|
1089
1117
|
moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
|
|
1090
1118
|
annotations: zod.z.boolean().optional()
|
|
@@ -1120,6 +1148,7 @@ function transformModuleInfo(info, option) {
|
|
|
1120
1148
|
dynamicImporters: info.dynamicImporters,
|
|
1121
1149
|
importedIds: info.importedIds,
|
|
1122
1150
|
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
1151
|
+
exports: info.exports,
|
|
1123
1152
|
isEntry: info.isEntry,
|
|
1124
1153
|
...option
|
|
1125
1154
|
};
|
|
@@ -1132,31 +1161,30 @@ var MinimalPluginContext = class {
|
|
|
1132
1161
|
warn;
|
|
1133
1162
|
debug;
|
|
1134
1163
|
meta;
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
const pluginName = plugin.name || "unknown";
|
|
1164
|
+
constructor(onLog, logLevel, pluginName) {
|
|
1165
|
+
this.pluginName = pluginName;
|
|
1138
1166
|
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1139
1167
|
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1140
1168
|
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
1141
|
-
this.error = (e) => {
|
|
1142
|
-
return error(logPluginError(normalizeLog(e), pluginName));
|
|
1143
|
-
};
|
|
1144
1169
|
this.meta = {
|
|
1145
1170
|
rollupVersion: "4.23.0",
|
|
1146
1171
|
rolldownVersion: VERSION,
|
|
1147
1172
|
watchMode: false
|
|
1148
1173
|
};
|
|
1149
1174
|
}
|
|
1175
|
+
error(e) {
|
|
1176
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1177
|
+
}
|
|
1150
1178
|
};
|
|
1151
1179
|
|
|
1152
1180
|
//#endregion
|
|
1153
1181
|
//#region src/utils/transform-side-effects.ts
|
|
1154
|
-
var import_binding$
|
|
1182
|
+
var import_binding$5 = require_chunk.__toESM(require_binding());
|
|
1155
1183
|
function bindingifySideEffects(sideEffects) {
|
|
1156
1184
|
switch (sideEffects) {
|
|
1157
|
-
case true: return import_binding$
|
|
1158
|
-
case false: return import_binding$
|
|
1159
|
-
case "no-treeshake": return import_binding$
|
|
1185
|
+
case true: return import_binding$5.BindingHookSideEffects.True;
|
|
1186
|
+
case false: return import_binding$5.BindingHookSideEffects.False;
|
|
1187
|
+
case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
|
|
1160
1188
|
case null:
|
|
1161
1189
|
case undefined: return undefined;
|
|
1162
1190
|
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
@@ -1166,84 +1194,92 @@ function bindingifySideEffects(sideEffects) {
|
|
|
1166
1194
|
//#endregion
|
|
1167
1195
|
//#region src/plugin/plugin-context.ts
|
|
1168
1196
|
var PluginContext = class extends MinimalPluginContext {
|
|
1169
|
-
load;
|
|
1170
|
-
resolve;
|
|
1171
|
-
emitFile;
|
|
1172
|
-
getFileName;
|
|
1173
|
-
getModuleInfo;
|
|
1174
|
-
getModuleIds;
|
|
1175
|
-
addWatchFile;
|
|
1176
|
-
/**
|
|
1177
|
-
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1178
|
-
*/
|
|
1179
|
-
parse;
|
|
1180
1197
|
constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
|
|
1181
|
-
super(onLog, logLevel, plugin);
|
|
1182
|
-
this.
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
const promise = new Promise((resolve, _) => {
|
|
1196
|
-
resolveFn = resolve;
|
|
1197
|
-
});
|
|
1198
|
-
data.loadModulePromiseMap.set(id, promise);
|
|
1199
|
-
try {
|
|
1200
|
-
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1201
|
-
} finally {
|
|
1202
|
-
data.loadModulePromiseMap.delete(id);
|
|
1203
|
-
}
|
|
1204
|
-
return promise;
|
|
1205
|
-
}
|
|
1206
|
-
await createLoadModulePromise();
|
|
1207
|
-
return data.getModuleInfo(id, context);
|
|
1208
|
-
};
|
|
1209
|
-
this.resolve = async (source, importer, options) => {
|
|
1210
|
-
let receipt = undefined;
|
|
1211
|
-
if (options != null) receipt = data.saveResolveOptions(options);
|
|
1212
|
-
const res = await context.resolve(source, importer, {
|
|
1213
|
-
custom: receipt,
|
|
1214
|
-
skipSelf: options?.skipSelf
|
|
1215
|
-
});
|
|
1216
|
-
if (receipt != null) data.removeSavedResolveOptions(receipt);
|
|
1217
|
-
if (res == null) return null;
|
|
1218
|
-
const info = data.getModuleOption(res.id) || {};
|
|
1219
|
-
return {
|
|
1220
|
-
...res,
|
|
1221
|
-
...info
|
|
1222
|
-
};
|
|
1198
|
+
super(onLog, logLevel, plugin.name);
|
|
1199
|
+
this.context = context;
|
|
1200
|
+
this.data = data;
|
|
1201
|
+
this.onLog = onLog;
|
|
1202
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1203
|
+
}
|
|
1204
|
+
async load(options) {
|
|
1205
|
+
const id = options.id;
|
|
1206
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(super.pluginName, this.currentLoadingModule));
|
|
1207
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1208
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1209
|
+
const rawOptions = {
|
|
1210
|
+
meta: options.meta || {},
|
|
1211
|
+
moduleSideEffects: options.moduleSideEffects || null
|
|
1223
1212
|
};
|
|
1224
|
-
this.
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1213
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1214
|
+
async function createLoadModulePromise(context, data) {
|
|
1215
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
1216
|
+
if (loadPromise) return loadPromise;
|
|
1217
|
+
let resolveFn;
|
|
1218
|
+
const promise = new Promise((resolve, _) => {
|
|
1219
|
+
resolveFn = resolve;
|
|
1230
1220
|
});
|
|
1221
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
1222
|
+
try {
|
|
1223
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1224
|
+
} finally {
|
|
1225
|
+
data.loadModulePromiseMap.delete(id);
|
|
1226
|
+
}
|
|
1227
|
+
return promise;
|
|
1228
|
+
}
|
|
1229
|
+
await createLoadModulePromise(this.context, this.data);
|
|
1230
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1231
|
+
}
|
|
1232
|
+
async resolve(source, importer, options) {
|
|
1233
|
+
let receipt = undefined;
|
|
1234
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1235
|
+
const res = await this.context.resolve(source, importer, {
|
|
1236
|
+
custom: receipt,
|
|
1237
|
+
skipSelf: options?.skipSelf
|
|
1238
|
+
});
|
|
1239
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1240
|
+
if (res == null) return null;
|
|
1241
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1242
|
+
return {
|
|
1243
|
+
...res,
|
|
1244
|
+
...info
|
|
1231
1245
|
};
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
this.
|
|
1236
|
-
|
|
1246
|
+
}
|
|
1247
|
+
emitFile(file) {
|
|
1248
|
+
if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
|
|
1249
|
+
return this.context.emitFile({
|
|
1250
|
+
...file,
|
|
1251
|
+
originalFileName: file.originalFileName || undefined,
|
|
1252
|
+
source: bindingAssetSource(file.source)
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
getFileName(referenceId) {
|
|
1256
|
+
return this.context.getFileName(referenceId);
|
|
1257
|
+
}
|
|
1258
|
+
getModuleInfo(id) {
|
|
1259
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1260
|
+
}
|
|
1261
|
+
getModuleIds() {
|
|
1262
|
+
return this.data.getModuleIds(this.context);
|
|
1263
|
+
}
|
|
1264
|
+
addWatchFile(id) {
|
|
1265
|
+
this.context.addWatchFile(id);
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1269
|
+
*/
|
|
1270
|
+
parse(_input, _options) {
|
|
1271
|
+
unsupported("`PluginContext#parse` is not supported by rolldown.");
|
|
1237
1272
|
}
|
|
1238
1273
|
};
|
|
1239
1274
|
|
|
1240
1275
|
//#endregion
|
|
1241
1276
|
//#region src/plugin/transform-plugin-context.ts
|
|
1242
1277
|
var TransformPluginContext = class extends PluginContext {
|
|
1243
|
-
error;
|
|
1244
|
-
getCombinedSourcemap;
|
|
1245
1278
|
constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
1246
1279
|
super(context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
1280
|
+
this.inner = inner;
|
|
1281
|
+
this.moduleId = moduleId;
|
|
1282
|
+
this.moduleSource = moduleSource;
|
|
1247
1283
|
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
1248
1284
|
log = normalizeLog(log);
|
|
1249
1285
|
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
@@ -1254,27 +1290,29 @@ var TransformPluginContext = class extends PluginContext {
|
|
|
1254
1290
|
this.debug = getLogHandler$1(this.debug);
|
|
1255
1291
|
this.warn = getLogHandler$1(this.warn);
|
|
1256
1292
|
this.info = getLogHandler$1(this.info);
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1293
|
+
}
|
|
1294
|
+
error(e, pos) {
|
|
1295
|
+
if (typeof e === "string") e = { message: e };
|
|
1296
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1297
|
+
e.id = this.moduleId;
|
|
1298
|
+
e.hook = "transform";
|
|
1299
|
+
return error(logPluginError(normalizeLog(e), super.pluginName));
|
|
1300
|
+
}
|
|
1301
|
+
getCombinedSourcemap() {
|
|
1302
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1265
1303
|
}
|
|
1266
1304
|
};
|
|
1267
1305
|
|
|
1268
1306
|
//#endregion
|
|
1269
1307
|
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1270
|
-
var import_binding$
|
|
1308
|
+
var import_binding$4 = require_chunk.__toESM(require_binding());
|
|
1271
1309
|
function bindingifyPluginHookMeta(options) {
|
|
1272
1310
|
return { order: bindingPluginOrder(options.order) };
|
|
1273
1311
|
}
|
|
1274
1312
|
function bindingPluginOrder(order) {
|
|
1275
1313
|
switch (order) {
|
|
1276
|
-
case "post": return import_binding$
|
|
1277
|
-
case "pre": return import_binding$
|
|
1314
|
+
case "post": return import_binding$4.BindingPluginOrder.Post;
|
|
1315
|
+
case "pre": return import_binding$4.BindingPluginOrder.Pre;
|
|
1278
1316
|
case null:
|
|
1279
1317
|
case undefined: return undefined;
|
|
1280
1318
|
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
@@ -1355,7 +1393,7 @@ function bindingifyBuildEnd(args) {
|
|
|
1355
1393
|
const { handler, meta } = normalizeHook(hook);
|
|
1356
1394
|
return {
|
|
1357
1395
|
plugin: async (ctx, err) => {
|
|
1358
|
-
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err
|
|
1396
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
|
|
1359
1397
|
},
|
|
1360
1398
|
meta: bindingifyPluginHookMeta(meta)
|
|
1361
1399
|
};
|
|
@@ -1494,7 +1532,9 @@ function bindingifyModuleParsed(args) {
|
|
|
1494
1532
|
//#endregion
|
|
1495
1533
|
//#region src/options/normalized-output-options.ts
|
|
1496
1534
|
function mapFunctionOption(option, name) {
|
|
1497
|
-
return typeof option === "undefined" ?
|
|
1535
|
+
return typeof option === "undefined" ? () => {
|
|
1536
|
+
unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
|
|
1537
|
+
} : option;
|
|
1498
1538
|
}
|
|
1499
1539
|
var NormalizedOutputOptionsImpl = class {
|
|
1500
1540
|
inner;
|
|
@@ -1582,6 +1622,9 @@ var NormalizedOutputOptionsImpl = class {
|
|
|
1582
1622
|
get comments() {
|
|
1583
1623
|
return this.inner.comments;
|
|
1584
1624
|
}
|
|
1625
|
+
get polyfillRequire() {
|
|
1626
|
+
return this.inner.polyfillRequire;
|
|
1627
|
+
}
|
|
1585
1628
|
};
|
|
1586
1629
|
|
|
1587
1630
|
//#endregion
|
|
@@ -1632,7 +1675,7 @@ function bindingifyRenderError(args) {
|
|
|
1632
1675
|
const { handler, meta } = normalizeHook(hook);
|
|
1633
1676
|
return {
|
|
1634
1677
|
plugin: async (ctx, err) => {
|
|
1635
|
-
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel),
|
|
1678
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
1636
1679
|
},
|
|
1637
1680
|
meta: bindingifyPluginHookMeta(meta)
|
|
1638
1681
|
};
|
|
@@ -1933,7 +1976,7 @@ function normalizedStringOrRegex(pattern) {
|
|
|
1933
1976
|
|
|
1934
1977
|
//#endregion
|
|
1935
1978
|
//#region src/utils/bindingify-input-options.ts
|
|
1936
|
-
var import_binding$
|
|
1979
|
+
var import_binding$3 = require_chunk.__toESM(require_binding());
|
|
1937
1980
|
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
|
|
1938
1981
|
const pluginContextData = new PluginContextData();
|
|
1939
1982
|
const plugins = rawPlugins.map((plugin) => {
|
|
@@ -1964,7 +2007,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
|
|
|
1964
2007
|
profilerNames: inputOptions?.profilerNames,
|
|
1965
2008
|
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1966
2009
|
watch: bindingifyWatch(inputOptions.watch),
|
|
1967
|
-
dropLabels: inputOptions.dropLabels
|
|
2010
|
+
dropLabels: inputOptions.dropLabels,
|
|
2011
|
+
keepNames: inputOptions.keepNames,
|
|
2012
|
+
checks: inputOptions.checks
|
|
1968
2013
|
};
|
|
1969
2014
|
}
|
|
1970
2015
|
function bindingifyExternal(external) {
|
|
@@ -1988,7 +2033,7 @@ function bindingifyResolve(resolve) {
|
|
|
1988
2033
|
return {
|
|
1989
2034
|
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
1990
2035
|
find: name,
|
|
1991
|
-
replacements:
|
|
2036
|
+
replacements: arraify(replacement)
|
|
1992
2037
|
})) : undefined,
|
|
1993
2038
|
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
1994
2039
|
target: name,
|
|
@@ -2022,10 +2067,10 @@ function bindingifyInject(inject) {
|
|
|
2022
2067
|
}
|
|
2023
2068
|
function bindingifyLogLevel(logLevel) {
|
|
2024
2069
|
switch (logLevel) {
|
|
2025
|
-
case "silent": return import_binding$
|
|
2026
|
-
case "debug": return import_binding$
|
|
2027
|
-
case "warn": return import_binding$
|
|
2028
|
-
case "info": return import_binding$
|
|
2070
|
+
case "silent": return import_binding$3.BindingLogLevel.Silent;
|
|
2071
|
+
case "debug": return import_binding$3.BindingLogLevel.Debug;
|
|
2072
|
+
case "warn": return import_binding$3.BindingLogLevel.Warn;
|
|
2073
|
+
case "info": return import_binding$3.BindingLogLevel.Info;
|
|
2029
2074
|
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2030
2075
|
}
|
|
2031
2076
|
}
|
|
@@ -2060,10 +2105,6 @@ function bindingifyWatch(watch$1) {
|
|
|
2060
2105
|
include: normalizedStringOrRegex(watch$1.include),
|
|
2061
2106
|
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2062
2107
|
};
|
|
2063
|
-
if (watch$1.notify) value.notify = {
|
|
2064
|
-
pollInterval: watch$1.notify.pollInterval,
|
|
2065
|
-
compareContents: watch$1.notify.compareContents
|
|
2066
|
-
};
|
|
2067
2108
|
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
2068
2109
|
return value;
|
|
2069
2110
|
}
|
|
@@ -2118,7 +2159,8 @@ function bindingifyOutputOptions(outputOptions) {
|
|
|
2118
2159
|
minify: outputOptions.minify,
|
|
2119
2160
|
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
2120
2161
|
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
2121
|
-
advancedChunks: outputOptions.advancedChunks
|
|
2162
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
2163
|
+
polyfillRequire: outputOptions.polyfillRequire
|
|
2122
2164
|
};
|
|
2123
2165
|
}
|
|
2124
2166
|
function bindingifyAddon(configAddon) {
|
|
@@ -2287,10 +2329,7 @@ function createComposedPlugin(plugins) {
|
|
|
2287
2329
|
const createFixedPluginResolveFnMap = new Map();
|
|
2288
2330
|
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2289
2331
|
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2290
|
-
if (createFixedPluginResolveFn)
|
|
2291
|
-
...ctx,
|
|
2292
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
2293
|
-
};
|
|
2332
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2294
2333
|
return ctx;
|
|
2295
2334
|
}
|
|
2296
2335
|
if (batchedHooks.resolveId) {
|
|
@@ -2299,14 +2338,14 @@ function createComposedPlugin(plugins) {
|
|
|
2299
2338
|
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2300
2339
|
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2301
2340
|
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2302
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
2341
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2303
2342
|
return (source, importer, rawContextResolveOptions) => {
|
|
2304
2343
|
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2305
2344
|
if (contextResolveOptions.skipSelf) {
|
|
2306
2345
|
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2307
2346
|
contextResolveOptions.skipSelf = false;
|
|
2308
2347
|
}
|
|
2309
|
-
return
|
|
2348
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2310
2349
|
};
|
|
2311
2350
|
};
|
|
2312
2351
|
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
@@ -2364,12 +2403,10 @@ function createComposedPlugin(plugins) {
|
|
|
2364
2403
|
}
|
|
2365
2404
|
for (const [handler, plugin] of batchedHandlers) {
|
|
2366
2405
|
const { handler: handlerFn } = normalizeHook(handler);
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
}
|
|
2372
|
-
}, code, id, moduleType);
|
|
2406
|
+
this.getCombinedSourcemap = () => {
|
|
2407
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2408
|
+
};
|
|
2409
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2373
2410
|
if (!isNullish(result)) {
|
|
2374
2411
|
if (typeof result === "string") updateOutput(result);
|
|
2375
2412
|
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
@@ -2504,7 +2541,7 @@ else newPlugins.push(toBeComposed[0]);
|
|
|
2504
2541
|
|
|
2505
2542
|
//#endregion
|
|
2506
2543
|
//#region src/utils/initialize-parallel-plugins.ts
|
|
2507
|
-
var import_binding$
|
|
2544
|
+
var import_binding$2 = require_chunk.__toESM(require_binding());
|
|
2508
2545
|
async function initializeParallelPlugins(plugins) {
|
|
2509
2546
|
const pluginInfos = [];
|
|
2510
2547
|
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
@@ -2517,7 +2554,7 @@ async function initializeParallelPlugins(plugins) {
|
|
|
2517
2554
|
}
|
|
2518
2555
|
if (pluginInfos.length <= 0) return undefined;
|
|
2519
2556
|
const count = Math.min((0, node_os.availableParallelism)(), 8);
|
|
2520
|
-
const parallelJsPluginRegistry = new import_binding$
|
|
2557
|
+
const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
|
|
2521
2558
|
const registryId = parallelJsPluginRegistry.id;
|
|
2522
2559
|
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2523
2560
|
const stopWorkers = async () => {
|
|
@@ -2556,9 +2593,8 @@ else resolve();
|
|
|
2556
2593
|
}
|
|
2557
2594
|
|
|
2558
2595
|
//#endregion
|
|
2559
|
-
//#region src/utils/create-bundler.ts
|
|
2560
|
-
|
|
2561
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
2596
|
+
//#region src/utils/create-bundler-option.ts
|
|
2597
|
+
async function createBundlerOptions(inputOptions, outputOptions) {
|
|
2562
2598
|
const pluginDriver = new PluginDriver();
|
|
2563
2599
|
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
2564
2600
|
if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
|
|
@@ -2574,7 +2610,13 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2574
2610
|
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
|
|
2575
2611
|
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
2576
2612
|
return {
|
|
2577
|
-
|
|
2613
|
+
bundlerOptions: {
|
|
2614
|
+
inputOptions: bindingInputOptions,
|
|
2615
|
+
outputOptions: bindingOutputOptions,
|
|
2616
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
2617
|
+
},
|
|
2618
|
+
inputOptions,
|
|
2619
|
+
onLog,
|
|
2578
2620
|
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
2579
2621
|
};
|
|
2580
2622
|
} catch (e) {
|
|
@@ -2583,6 +2625,22 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2583
2625
|
}
|
|
2584
2626
|
}
|
|
2585
2627
|
|
|
2628
|
+
//#endregion
|
|
2629
|
+
//#region src/utils/create-bundler.ts
|
|
2630
|
+
var import_binding$1 = require_chunk.__toESM(require_binding());
|
|
2631
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
2632
|
+
const option = await createBundlerOptions(inputOptions, outputOptions);
|
|
2633
|
+
try {
|
|
2634
|
+
return {
|
|
2635
|
+
bundler: new import_binding$1.Bundler(option.bundlerOptions),
|
|
2636
|
+
stopWorkers: option.stopWorkers
|
|
2637
|
+
};
|
|
2638
|
+
} catch (e) {
|
|
2639
|
+
await option.stopWorkers?.();
|
|
2640
|
+
throw e;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2586
2644
|
//#endregion
|
|
2587
2645
|
//#region src/api/rolldown/rolldown-build.ts
|
|
2588
2646
|
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
@@ -2625,98 +2683,129 @@ const rolldown = async (input) => {
|
|
|
2625
2683
|
return new RolldownBuild(input);
|
|
2626
2684
|
};
|
|
2627
2685
|
|
|
2686
|
+
//#endregion
|
|
2687
|
+
//#region src/api/watch/watch-emitter.ts
|
|
2688
|
+
var WatcherEmitter = class {
|
|
2689
|
+
listeners = new Map();
|
|
2690
|
+
timer;
|
|
2691
|
+
constructor() {
|
|
2692
|
+
this.timer = setInterval(
|
|
2693
|
+
() => {},
|
|
2694
|
+
1e9
|
|
2695
|
+
/* Low power usage */
|
|
2696
|
+
);
|
|
2697
|
+
}
|
|
2698
|
+
on(event, listener) {
|
|
2699
|
+
const listeners = this.listeners.get(event);
|
|
2700
|
+
if (listeners) listeners.push(listener);
|
|
2701
|
+
else this.listeners.set(event, [listener]);
|
|
2702
|
+
return this;
|
|
2703
|
+
}
|
|
2704
|
+
async onEvent(event) {
|
|
2705
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
2706
|
+
if (listeners) switch (event.eventKind()) {
|
|
2707
|
+
case "close":
|
|
2708
|
+
case "restart":
|
|
2709
|
+
for (const listener of listeners) await listener();
|
|
2710
|
+
break;
|
|
2711
|
+
case "event":
|
|
2712
|
+
for (const listener of listeners) {
|
|
2713
|
+
const code = event.bundleEventKind();
|
|
2714
|
+
switch (code) {
|
|
2715
|
+
case "BUNDLE_END":
|
|
2716
|
+
const { duration, output } = event.bundleEndData();
|
|
2717
|
+
await listener({
|
|
2718
|
+
code: "BUNDLE_END",
|
|
2719
|
+
duration,
|
|
2720
|
+
output: [output]
|
|
2721
|
+
});
|
|
2722
|
+
break;
|
|
2723
|
+
case "ERROR":
|
|
2724
|
+
const errors = event.errors();
|
|
2725
|
+
await listener({
|
|
2726
|
+
code: "ERROR",
|
|
2727
|
+
error: normalizeErrors(errors)
|
|
2728
|
+
});
|
|
2729
|
+
break;
|
|
2730
|
+
default:
|
|
2731
|
+
await listener({ code });
|
|
2732
|
+
break;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
break;
|
|
2736
|
+
case "change":
|
|
2737
|
+
for (const listener of listeners) {
|
|
2738
|
+
const { path: path$2, kind } = event.watchChangeData();
|
|
2739
|
+
await listener(path$2, { event: kind });
|
|
2740
|
+
}
|
|
2741
|
+
break;
|
|
2742
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
async close() {
|
|
2746
|
+
clearInterval(this.timer);
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2628
2750
|
//#endregion
|
|
2629
2751
|
//#region src/api/watch/watcher.ts
|
|
2752
|
+
var import_binding = require_chunk.__toESM(require_binding());
|
|
2630
2753
|
var Watcher = class {
|
|
2631
2754
|
closed;
|
|
2632
|
-
controller;
|
|
2633
2755
|
inner;
|
|
2756
|
+
emitter;
|
|
2634
2757
|
stopWorkers;
|
|
2635
|
-
|
|
2636
|
-
constructor(inner, stopWorkers) {
|
|
2758
|
+
constructor(emitter, inner, stopWorkers) {
|
|
2637
2759
|
this.closed = false;
|
|
2638
|
-
this.controller = new AbortController();
|
|
2639
2760
|
this.inner = inner;
|
|
2761
|
+
this.emitter = emitter;
|
|
2762
|
+
const originClose = emitter.close.bind(emitter);
|
|
2763
|
+
emitter.close = async () => {
|
|
2764
|
+
await this.close();
|
|
2765
|
+
originClose();
|
|
2766
|
+
};
|
|
2640
2767
|
this.stopWorkers = stopWorkers;
|
|
2641
2768
|
}
|
|
2642
2769
|
async close() {
|
|
2770
|
+
if (this.closed) return;
|
|
2643
2771
|
this.closed = true;
|
|
2644
|
-
|
|
2772
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
2645
2773
|
await this.inner.close();
|
|
2646
|
-
this.controller.abort();
|
|
2647
2774
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
if (listeners) listeners.push(listener);
|
|
2651
|
-
else this.listeners.set(event, [listener]);
|
|
2652
|
-
return this;
|
|
2653
|
-
}
|
|
2654
|
-
watch() {
|
|
2655
|
-
const timer = setInterval(
|
|
2656
|
-
() => {},
|
|
2657
|
-
1e9
|
|
2658
|
-
/* Low power usage */
|
|
2659
|
-
);
|
|
2660
|
-
this.controller.signal.addEventListener("abort", () => {
|
|
2661
|
-
clearInterval(timer);
|
|
2662
|
-
});
|
|
2663
|
-
process.nextTick(() => this.inner.start(async (event) => {
|
|
2664
|
-
const listeners = this.listeners.get(event.eventKind());
|
|
2665
|
-
if (listeners) switch (event.eventKind()) {
|
|
2666
|
-
case "close":
|
|
2667
|
-
case "restart":
|
|
2668
|
-
for (const listener of listeners) await listener();
|
|
2669
|
-
break;
|
|
2670
|
-
case "event":
|
|
2671
|
-
for (const listener of listeners) {
|
|
2672
|
-
const code = event.bundleEventKind();
|
|
2673
|
-
switch (code) {
|
|
2674
|
-
case "BUNDLE_END":
|
|
2675
|
-
const { duration, output } = event.bundleEndData();
|
|
2676
|
-
await listener({
|
|
2677
|
-
code: "BUNDLE_END",
|
|
2678
|
-
duration,
|
|
2679
|
-
output: [output]
|
|
2680
|
-
});
|
|
2681
|
-
break;
|
|
2682
|
-
case "ERROR":
|
|
2683
|
-
const errors = event.errors();
|
|
2684
|
-
await listener({
|
|
2685
|
-
code: "ERROR",
|
|
2686
|
-
error: normalizeErrors(errors)
|
|
2687
|
-
});
|
|
2688
|
-
break;
|
|
2689
|
-
default:
|
|
2690
|
-
await listener({ code });
|
|
2691
|
-
break;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
break;
|
|
2695
|
-
case "change":
|
|
2696
|
-
for (const listener of listeners) {
|
|
2697
|
-
const { path: path$2, kind } = event.watchChangeData();
|
|
2698
|
-
await listener(path$2, { event: kind });
|
|
2699
|
-
}
|
|
2700
|
-
break;
|
|
2701
|
-
default: throw new Error(`Unknown event: ${event}`);
|
|
2702
|
-
}
|
|
2703
|
-
}));
|
|
2775
|
+
start() {
|
|
2776
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
2704
2777
|
}
|
|
2705
2778
|
};
|
|
2779
|
+
async function createWatcher(emitter, input) {
|
|
2780
|
+
const options = Array.isArray(input) ? input : [input];
|
|
2781
|
+
const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
|
|
2782
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
2783
|
+
const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
2784
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
2785
|
+
watcher.start();
|
|
2786
|
+
}
|
|
2787
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
2788
|
+
let result;
|
|
2789
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
2790
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
2791
|
+
if (notifyOption) if (result) {
|
|
2792
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
2793
|
+
return result;
|
|
2794
|
+
} else result = notifyOption;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2706
2797
|
|
|
2707
2798
|
//#endregion
|
|
2708
2799
|
//#region src/api/watch/index.ts
|
|
2709
|
-
const watch =
|
|
2710
|
-
const
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
watcher.watch();
|
|
2714
|
-
return watcher;
|
|
2800
|
+
const watch = (input) => {
|
|
2801
|
+
const emitter = new WatcherEmitter();
|
|
2802
|
+
createWatcher(emitter, input);
|
|
2803
|
+
return emitter;
|
|
2715
2804
|
};
|
|
2716
2805
|
|
|
2717
2806
|
//#endregion
|
|
2718
2807
|
//#region package.json
|
|
2719
|
-
var version = "0.15.
|
|
2808
|
+
var version = "0.15.1";
|
|
2720
2809
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2721
2810
|
|
|
2722
2811
|
//#endregion
|
|
@@ -2724,10 +2813,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
|
|
|
2724
2813
|
async function build(options) {
|
|
2725
2814
|
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
2726
2815
|
else {
|
|
2727
|
-
const { output,...inputOptions } = options;
|
|
2816
|
+
const { output, write = true,...inputOptions } = options;
|
|
2728
2817
|
const build$1 = await rolldown(inputOptions);
|
|
2729
|
-
|
|
2730
|
-
|
|
2818
|
+
try {
|
|
2819
|
+
if (write) return await build$1.write(output);
|
|
2820
|
+
else return await build$1.generate(output);
|
|
2821
|
+
} finally {
|
|
2822
|
+
await build$1.close();
|
|
2823
|
+
}
|
|
2731
2824
|
}
|
|
2732
2825
|
}
|
|
2733
2826
|
|