rolldown 0.15.0 → 0.15.1-commit.cc6f557
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.cjs +249 -183
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/esm/cli.mjs +343 -277
- package/dist/esm/experimental-index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{chunk-BK2Ye-xa.cjs → chunk-BFvIen8E.cjs} +0 -11
- package/dist/shared/{consola_36c0034f-_8_dG1Nr.cjs → consola_36c0034f-B7L-radJ.cjs} +2 -2
- package/dist/shared/{consola_36c0034f-DWsVjwtA.mjs → consola_36c0034f-D9ce-831.mjs} +10 -10
- package/dist/shared/{prompt-RFvZMmjc.cjs → prompt-BiXtYIJ2.cjs} +3 -3
- package/dist/shared/{prompt-DGW8ZJmn.mjs → prompt-DlQ-08lk.mjs} +2 -2
- package/dist/shared/{src-DEPa5yhI.mjs → src-C4XpZnTu.mjs} +332 -233
- package/dist/shared/{src-COU7qQBJ.cjs → src-DKykz7Lg.cjs} +321 -216
- package/dist/tsconfig.dts.tsbuildinfo +1 -0
- package/dist/types/api/build.d.ts +2 -0
- package/dist/types/api/watch/index.d.ts +2 -2
- package/dist/types/api/watch/watch-emitter.d.ts +31 -0
- package/dist/types/api/watch/watcher.d.ts +7 -27
- package/dist/types/binding.d.ts +114 -19
- package/dist/types/builtin-plugin/constructors.d.ts +1 -5
- package/dist/types/cli/arguments/index.d.ts +5 -3
- package/dist/types/cli/arguments/schema.d.ts +10 -397
- package/dist/types/cli/colors.d.ts +11 -1
- package/dist/types/cli/load-config.d.ts +3 -0
- package/dist/types/cli/logger.d.ts +5 -0
- package/dist/types/constants/plugin.d.ts +8 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/log/logging.d.ts +6 -6
- package/dist/types/log/logs.d.ts +2 -0
- package/dist/types/options/input-options-schema.d.ts +3 -595
- package/dist/types/options/input-options.d.ts +26 -3
- package/dist/types/options/normalized-input-options.d.ts +1 -1
- package/dist/types/options/normalized-output-options.d.ts +21 -17
- package/dist/types/options/output-options-schema.d.ts +2 -146
- package/dist/types/options/output-options.d.ts +1 -0
- package/dist/types/plugin/minimal-plugin-context.d.ts +3 -3
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/dist/types/plugin/plugin-context.d.ts +14 -10
- package/dist/types/plugin/transform-plugin-context.d.ts +7 -4
- package/dist/types/rollup.d.ts +4 -0
- package/dist/types/treeshake/module-side-effects.d.ts +14 -115
- package/dist/types/types/module-info.d.ts +1 -0
- package/dist/types/types/rolldown-output.d.ts +6 -0
- package/dist/types/utils/bindingify-input-options.d.ts +1 -1
- package/dist/types/utils/create-bundler-option.d.ts +11 -0
- package/dist/types/utils/error.d.ts +2 -1
- package/dist/types/utils/misc.d.ts +1 -1
- package/dist/types/utils/transform-sourcemap.d.ts +1 -1
- package/dist/types/utils/zod-ext.d.ts +6 -5
- package/package.json +16 -16
- package/dist/types/cli/utils.d.ts +0 -6
- package/dist/types/log/locate-character/index.d.ts +0 -13
|
@@ -1,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,13 @@ 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", MINIFY_WARNING = "MINIFY_WARNING";
|
|
699
|
+
function logMinifyWarning() {
|
|
700
|
+
return {
|
|
701
|
+
code: MINIFY_WARNING,
|
|
702
|
+
message: "The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use."
|
|
703
|
+
};
|
|
704
|
+
}
|
|
679
705
|
function logInvalidLogPosition(pluginName) {
|
|
680
706
|
return {
|
|
681
707
|
code: INVALID_LOG_POSITION,
|
|
@@ -694,6 +720,12 @@ function logCycleLoading(pluginName, moduleId) {
|
|
|
694
720
|
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
695
721
|
};
|
|
696
722
|
}
|
|
723
|
+
function logMultiplyNotifyOption() {
|
|
724
|
+
return {
|
|
725
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
726
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
727
|
+
};
|
|
728
|
+
}
|
|
697
729
|
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
698
730
|
const code = error$1.code;
|
|
699
731
|
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
@@ -797,7 +829,8 @@ function getLogger(plugins, onLog, logLevel) {
|
|
|
797
829
|
rolldownVersion: VERSION,
|
|
798
830
|
watchMode: false
|
|
799
831
|
},
|
|
800
|
-
warn: getLogHandler$1(LOG_LEVEL_WARN)
|
|
832
|
+
warn: getLogHandler$1(LOG_LEVEL_WARN),
|
|
833
|
+
pluginName: plugin.name || "unknown"
|
|
801
834
|
}, level, log) === false) return;
|
|
802
835
|
}
|
|
803
836
|
}
|
|
@@ -849,9 +882,9 @@ function relativeId(id) {
|
|
|
849
882
|
|
|
850
883
|
//#endregion
|
|
851
884
|
//#region src/builtin-plugin/utils.ts
|
|
852
|
-
var import_binding$
|
|
885
|
+
var import_binding$6 = require_chunk.__toESM(require_binding());
|
|
853
886
|
function makeBuiltinPluginCallable(plugin) {
|
|
854
|
-
let callablePlugin = new import_binding$
|
|
887
|
+
let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
855
888
|
const wrappedPlugin = plugin;
|
|
856
889
|
for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
|
|
857
890
|
return callablePlugin[key](...args);
|
|
@@ -1020,7 +1053,8 @@ var PluginDriver = class {
|
|
|
1020
1053
|
rolldownVersion: VERSION,
|
|
1021
1054
|
watchMode: false
|
|
1022
1055
|
},
|
|
1023
|
-
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
|
|
1056
|
+
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
|
|
1057
|
+
pluginName: name
|
|
1024
1058
|
}, inputOptions);
|
|
1025
1059
|
if (result) inputOptions = result;
|
|
1026
1060
|
}
|
|
@@ -1084,7 +1118,7 @@ const ModuleSideEffectsRuleSchema = zod.z.object({
|
|
|
1084
1118
|
}).refine((data) => {
|
|
1085
1119
|
return data.test !== undefined || data.external !== undefined;
|
|
1086
1120
|
}, "Either `test` or `external` should be set.");
|
|
1087
|
-
const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.literal("no-external"));
|
|
1121
|
+
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
1122
|
const TreeshakingOptionsSchema = zod.z.object({
|
|
1089
1123
|
moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
|
|
1090
1124
|
annotations: zod.z.boolean().optional()
|
|
@@ -1120,6 +1154,7 @@ function transformModuleInfo(info, option) {
|
|
|
1120
1154
|
dynamicImporters: info.dynamicImporters,
|
|
1121
1155
|
importedIds: info.importedIds,
|
|
1122
1156
|
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
1157
|
+
exports: info.exports,
|
|
1123
1158
|
isEntry: info.isEntry,
|
|
1124
1159
|
...option
|
|
1125
1160
|
};
|
|
@@ -1132,31 +1167,30 @@ var MinimalPluginContext = class {
|
|
|
1132
1167
|
warn;
|
|
1133
1168
|
debug;
|
|
1134
1169
|
meta;
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
const pluginName = plugin.name || "unknown";
|
|
1170
|
+
constructor(onLog, logLevel, pluginName) {
|
|
1171
|
+
this.pluginName = pluginName;
|
|
1138
1172
|
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1139
1173
|
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1140
1174
|
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
1141
|
-
this.error = (e) => {
|
|
1142
|
-
return error(logPluginError(normalizeLog(e), pluginName));
|
|
1143
|
-
};
|
|
1144
1175
|
this.meta = {
|
|
1145
1176
|
rollupVersion: "4.23.0",
|
|
1146
1177
|
rolldownVersion: VERSION,
|
|
1147
1178
|
watchMode: false
|
|
1148
1179
|
};
|
|
1149
1180
|
}
|
|
1181
|
+
error(e) {
|
|
1182
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1183
|
+
}
|
|
1150
1184
|
};
|
|
1151
1185
|
|
|
1152
1186
|
//#endregion
|
|
1153
1187
|
//#region src/utils/transform-side-effects.ts
|
|
1154
|
-
var import_binding$
|
|
1188
|
+
var import_binding$5 = require_chunk.__toESM(require_binding());
|
|
1155
1189
|
function bindingifySideEffects(sideEffects) {
|
|
1156
1190
|
switch (sideEffects) {
|
|
1157
|
-
case true: return import_binding$
|
|
1158
|
-
case false: return import_binding$
|
|
1159
|
-
case "no-treeshake": return import_binding$
|
|
1191
|
+
case true: return import_binding$5.BindingHookSideEffects.True;
|
|
1192
|
+
case false: return import_binding$5.BindingHookSideEffects.False;
|
|
1193
|
+
case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
|
|
1160
1194
|
case null:
|
|
1161
1195
|
case undefined: return undefined;
|
|
1162
1196
|
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
@@ -1166,84 +1200,92 @@ function bindingifySideEffects(sideEffects) {
|
|
|
1166
1200
|
//#endregion
|
|
1167
1201
|
//#region src/plugin/plugin-context.ts
|
|
1168
1202
|
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
1203
|
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
|
-
};
|
|
1204
|
+
super(onLog, logLevel, plugin.name);
|
|
1205
|
+
this.context = context;
|
|
1206
|
+
this.data = data;
|
|
1207
|
+
this.onLog = onLog;
|
|
1208
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1209
|
+
}
|
|
1210
|
+
async load(options) {
|
|
1211
|
+
const id = options.id;
|
|
1212
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
1213
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1214
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1215
|
+
const rawOptions = {
|
|
1216
|
+
meta: options.meta || {},
|
|
1217
|
+
moduleSideEffects: options.moduleSideEffects || null
|
|
1223
1218
|
};
|
|
1224
|
-
this.
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1219
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1220
|
+
async function createLoadModulePromise(context, data) {
|
|
1221
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
1222
|
+
if (loadPromise) return loadPromise;
|
|
1223
|
+
let resolveFn;
|
|
1224
|
+
const promise = new Promise((resolve, _) => {
|
|
1225
|
+
resolveFn = resolve;
|
|
1230
1226
|
});
|
|
1227
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
1228
|
+
try {
|
|
1229
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1230
|
+
} finally {
|
|
1231
|
+
data.loadModulePromiseMap.delete(id);
|
|
1232
|
+
}
|
|
1233
|
+
return promise;
|
|
1234
|
+
}
|
|
1235
|
+
await createLoadModulePromise(this.context, this.data);
|
|
1236
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1237
|
+
}
|
|
1238
|
+
async resolve(source, importer, options) {
|
|
1239
|
+
let receipt = undefined;
|
|
1240
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1241
|
+
const res = await this.context.resolve(source, importer, {
|
|
1242
|
+
custom: receipt,
|
|
1243
|
+
skipSelf: options?.skipSelf
|
|
1244
|
+
});
|
|
1245
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1246
|
+
if (res == null) return null;
|
|
1247
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1248
|
+
return {
|
|
1249
|
+
...res,
|
|
1250
|
+
...info
|
|
1231
1251
|
};
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
this.
|
|
1236
|
-
|
|
1252
|
+
}
|
|
1253
|
+
emitFile(file) {
|
|
1254
|
+
if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
|
|
1255
|
+
return this.context.emitFile({
|
|
1256
|
+
...file,
|
|
1257
|
+
originalFileName: file.originalFileName || undefined,
|
|
1258
|
+
source: bindingAssetSource(file.source)
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
getFileName(referenceId) {
|
|
1262
|
+
return this.context.getFileName(referenceId);
|
|
1263
|
+
}
|
|
1264
|
+
getModuleInfo(id) {
|
|
1265
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1266
|
+
}
|
|
1267
|
+
getModuleIds() {
|
|
1268
|
+
return this.data.getModuleIds(this.context);
|
|
1269
|
+
}
|
|
1270
|
+
addWatchFile(id) {
|
|
1271
|
+
this.context.addWatchFile(id);
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
1275
|
+
*/
|
|
1276
|
+
parse(_input, _options) {
|
|
1277
|
+
unsupported("`PluginContext#parse` is not supported by rolldown.");
|
|
1237
1278
|
}
|
|
1238
1279
|
};
|
|
1239
1280
|
|
|
1240
1281
|
//#endregion
|
|
1241
1282
|
//#region src/plugin/transform-plugin-context.ts
|
|
1242
1283
|
var TransformPluginContext = class extends PluginContext {
|
|
1243
|
-
error;
|
|
1244
|
-
getCombinedSourcemap;
|
|
1245
1284
|
constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
1246
1285
|
super(context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
1286
|
+
this.inner = inner;
|
|
1287
|
+
this.moduleId = moduleId;
|
|
1288
|
+
this.moduleSource = moduleSource;
|
|
1247
1289
|
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
1248
1290
|
log = normalizeLog(log);
|
|
1249
1291
|
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
@@ -1254,27 +1296,29 @@ var TransformPluginContext = class extends PluginContext {
|
|
|
1254
1296
|
this.debug = getLogHandler$1(this.debug);
|
|
1255
1297
|
this.warn = getLogHandler$1(this.warn);
|
|
1256
1298
|
this.info = getLogHandler$1(this.info);
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1299
|
+
}
|
|
1300
|
+
error(e, pos) {
|
|
1301
|
+
if (typeof e === "string") e = { message: e };
|
|
1302
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1303
|
+
e.id = this.moduleId;
|
|
1304
|
+
e.hook = "transform";
|
|
1305
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1306
|
+
}
|
|
1307
|
+
getCombinedSourcemap() {
|
|
1308
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1265
1309
|
}
|
|
1266
1310
|
};
|
|
1267
1311
|
|
|
1268
1312
|
//#endregion
|
|
1269
1313
|
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1270
|
-
var import_binding$
|
|
1314
|
+
var import_binding$4 = require_chunk.__toESM(require_binding());
|
|
1271
1315
|
function bindingifyPluginHookMeta(options) {
|
|
1272
1316
|
return { order: bindingPluginOrder(options.order) };
|
|
1273
1317
|
}
|
|
1274
1318
|
function bindingPluginOrder(order) {
|
|
1275
1319
|
switch (order) {
|
|
1276
|
-
case "post": return import_binding$
|
|
1277
|
-
case "pre": return import_binding$
|
|
1320
|
+
case "post": return import_binding$4.BindingPluginOrder.Post;
|
|
1321
|
+
case "pre": return import_binding$4.BindingPluginOrder.Pre;
|
|
1278
1322
|
case null:
|
|
1279
1323
|
case undefined: return undefined;
|
|
1280
1324
|
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
@@ -1355,7 +1399,7 @@ function bindingifyBuildEnd(args) {
|
|
|
1355
1399
|
const { handler, meta } = normalizeHook(hook);
|
|
1356
1400
|
return {
|
|
1357
1401
|
plugin: async (ctx, err) => {
|
|
1358
|
-
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err
|
|
1402
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
|
|
1359
1403
|
},
|
|
1360
1404
|
meta: bindingifyPluginHookMeta(meta)
|
|
1361
1405
|
};
|
|
@@ -1494,7 +1538,9 @@ function bindingifyModuleParsed(args) {
|
|
|
1494
1538
|
//#endregion
|
|
1495
1539
|
//#region src/options/normalized-output-options.ts
|
|
1496
1540
|
function mapFunctionOption(option, name) {
|
|
1497
|
-
return typeof option === "undefined" ?
|
|
1541
|
+
return typeof option === "undefined" ? () => {
|
|
1542
|
+
unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
|
|
1543
|
+
} : option;
|
|
1498
1544
|
}
|
|
1499
1545
|
var NormalizedOutputOptionsImpl = class {
|
|
1500
1546
|
inner;
|
|
@@ -1582,6 +1628,9 @@ var NormalizedOutputOptionsImpl = class {
|
|
|
1582
1628
|
get comments() {
|
|
1583
1629
|
return this.inner.comments;
|
|
1584
1630
|
}
|
|
1631
|
+
get polyfillRequire() {
|
|
1632
|
+
return this.inner.polyfillRequire;
|
|
1633
|
+
}
|
|
1585
1634
|
};
|
|
1586
1635
|
|
|
1587
1636
|
//#endregion
|
|
@@ -1632,7 +1681,7 @@ function bindingifyRenderError(args) {
|
|
|
1632
1681
|
const { handler, meta } = normalizeHook(hook);
|
|
1633
1682
|
return {
|
|
1634
1683
|
plugin: async (ctx, err) => {
|
|
1635
|
-
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel),
|
|
1684
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
1636
1685
|
},
|
|
1637
1686
|
meta: bindingifyPluginHookMeta(meta)
|
|
1638
1687
|
};
|
|
@@ -1933,7 +1982,7 @@ function normalizedStringOrRegex(pattern) {
|
|
|
1933
1982
|
|
|
1934
1983
|
//#endregion
|
|
1935
1984
|
//#region src/utils/bindingify-input-options.ts
|
|
1936
|
-
var import_binding$
|
|
1985
|
+
var import_binding$3 = require_chunk.__toESM(require_binding());
|
|
1937
1986
|
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
|
|
1938
1987
|
const pluginContextData = new PluginContextData();
|
|
1939
1988
|
const plugins = rawPlugins.map((plugin) => {
|
|
@@ -1964,7 +2013,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
|
|
|
1964
2013
|
profilerNames: inputOptions?.profilerNames,
|
|
1965
2014
|
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1966
2015
|
watch: bindingifyWatch(inputOptions.watch),
|
|
1967
|
-
dropLabels: inputOptions.dropLabels
|
|
2016
|
+
dropLabels: inputOptions.dropLabels,
|
|
2017
|
+
keepNames: inputOptions.keepNames,
|
|
2018
|
+
checks: inputOptions.checks
|
|
1968
2019
|
};
|
|
1969
2020
|
}
|
|
1970
2021
|
function bindingifyExternal(external) {
|
|
@@ -1988,7 +2039,7 @@ function bindingifyResolve(resolve) {
|
|
|
1988
2039
|
return {
|
|
1989
2040
|
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
1990
2041
|
find: name,
|
|
1991
|
-
replacements:
|
|
2042
|
+
replacements: arraify(replacement)
|
|
1992
2043
|
})) : undefined,
|
|
1993
2044
|
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
1994
2045
|
target: name,
|
|
@@ -2022,10 +2073,10 @@ function bindingifyInject(inject) {
|
|
|
2022
2073
|
}
|
|
2023
2074
|
function bindingifyLogLevel(logLevel) {
|
|
2024
2075
|
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$
|
|
2076
|
+
case "silent": return import_binding$3.BindingLogLevel.Silent;
|
|
2077
|
+
case "debug": return import_binding$3.BindingLogLevel.Debug;
|
|
2078
|
+
case "warn": return import_binding$3.BindingLogLevel.Warn;
|
|
2079
|
+
case "info": return import_binding$3.BindingLogLevel.Info;
|
|
2029
2080
|
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2030
2081
|
}
|
|
2031
2082
|
}
|
|
@@ -2041,15 +2092,20 @@ function bindingifyInput(input) {
|
|
|
2041
2092
|
});
|
|
2042
2093
|
}
|
|
2043
2094
|
function bindingifyJsx(input) {
|
|
2095
|
+
if (input === false) return { type: "Disable" };
|
|
2044
2096
|
if (input) {
|
|
2045
|
-
|
|
2097
|
+
if (input.mode === "preserve") return { type: "Preserve" };
|
|
2098
|
+
const mode = input.mode ?? "automatic";
|
|
2046
2099
|
return {
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2100
|
+
type: "Enable",
|
|
2101
|
+
field0: {
|
|
2102
|
+
runtime: mode,
|
|
2103
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
|
|
2104
|
+
pragma: input.factory,
|
|
2105
|
+
pragmaFrag: input.fragment,
|
|
2106
|
+
development: input.development,
|
|
2107
|
+
refresh: input.refresh
|
|
2108
|
+
}
|
|
2053
2109
|
};
|
|
2054
2110
|
}
|
|
2055
2111
|
}
|
|
@@ -2060,10 +2116,6 @@ function bindingifyWatch(watch$1) {
|
|
|
2060
2116
|
include: normalizedStringOrRegex(watch$1.include),
|
|
2061
2117
|
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2062
2118
|
};
|
|
2063
|
-
if (watch$1.notify) value.notify = {
|
|
2064
|
-
pollInterval: watch$1.notify.pollInterval,
|
|
2065
|
-
compareContents: watch$1.notify.compareContents
|
|
2066
|
-
};
|
|
2067
2119
|
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
2068
2120
|
return value;
|
|
2069
2121
|
}
|
|
@@ -2118,7 +2170,8 @@ function bindingifyOutputOptions(outputOptions) {
|
|
|
2118
2170
|
minify: outputOptions.minify,
|
|
2119
2171
|
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
2120
2172
|
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
2121
|
-
advancedChunks: outputOptions.advancedChunks
|
|
2173
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
2174
|
+
polyfillRequire: outputOptions.polyfillRequire
|
|
2122
2175
|
};
|
|
2123
2176
|
}
|
|
2124
2177
|
function bindingifyAddon(configAddon) {
|
|
@@ -2287,10 +2340,7 @@ function createComposedPlugin(plugins) {
|
|
|
2287
2340
|
const createFixedPluginResolveFnMap = new Map();
|
|
2288
2341
|
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2289
2342
|
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2290
|
-
if (createFixedPluginResolveFn)
|
|
2291
|
-
...ctx,
|
|
2292
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
2293
|
-
};
|
|
2343
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2294
2344
|
return ctx;
|
|
2295
2345
|
}
|
|
2296
2346
|
if (batchedHooks.resolveId) {
|
|
@@ -2299,14 +2349,14 @@ function createComposedPlugin(plugins) {
|
|
|
2299
2349
|
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2300
2350
|
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2301
2351
|
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2302
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
2352
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2303
2353
|
return (source, importer, rawContextResolveOptions) => {
|
|
2304
2354
|
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2305
2355
|
if (contextResolveOptions.skipSelf) {
|
|
2306
2356
|
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2307
2357
|
contextResolveOptions.skipSelf = false;
|
|
2308
2358
|
}
|
|
2309
|
-
return
|
|
2359
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2310
2360
|
};
|
|
2311
2361
|
};
|
|
2312
2362
|
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
@@ -2364,12 +2414,10 @@ function createComposedPlugin(plugins) {
|
|
|
2364
2414
|
}
|
|
2365
2415
|
for (const [handler, plugin] of batchedHandlers) {
|
|
2366
2416
|
const { handler: handlerFn } = normalizeHook(handler);
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
}
|
|
2372
|
-
}, code, id, moduleType);
|
|
2417
|
+
this.getCombinedSourcemap = () => {
|
|
2418
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2419
|
+
};
|
|
2420
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2373
2421
|
if (!isNullish(result)) {
|
|
2374
2422
|
if (typeof result === "string") updateOutput(result);
|
|
2375
2423
|
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
@@ -2504,7 +2552,7 @@ else newPlugins.push(toBeComposed[0]);
|
|
|
2504
2552
|
|
|
2505
2553
|
//#endregion
|
|
2506
2554
|
//#region src/utils/initialize-parallel-plugins.ts
|
|
2507
|
-
var import_binding$
|
|
2555
|
+
var import_binding$2 = require_chunk.__toESM(require_binding());
|
|
2508
2556
|
async function initializeParallelPlugins(plugins) {
|
|
2509
2557
|
const pluginInfos = [];
|
|
2510
2558
|
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
@@ -2517,7 +2565,7 @@ async function initializeParallelPlugins(plugins) {
|
|
|
2517
2565
|
}
|
|
2518
2566
|
if (pluginInfos.length <= 0) return undefined;
|
|
2519
2567
|
const count = Math.min((0, node_os.availableParallelism)(), 8);
|
|
2520
|
-
const parallelJsPluginRegistry = new import_binding$
|
|
2568
|
+
const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
|
|
2521
2569
|
const registryId = parallelJsPluginRegistry.id;
|
|
2522
2570
|
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2523
2571
|
const stopWorkers = async () => {
|
|
@@ -2556,17 +2604,17 @@ else resolve();
|
|
|
2556
2604
|
}
|
|
2557
2605
|
|
|
2558
2606
|
//#endregion
|
|
2559
|
-
//#region src/utils/create-bundler.ts
|
|
2560
|
-
|
|
2561
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
2607
|
+
//#region src/utils/create-bundler-option.ts
|
|
2608
|
+
async function createBundlerOptions(inputOptions, outputOptions) {
|
|
2562
2609
|
const pluginDriver = new PluginDriver();
|
|
2563
2610
|
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
2564
2611
|
if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
|
|
2565
2612
|
const inputPlugins = await normalizePluginOption(inputOptions.plugins);
|
|
2566
2613
|
const outputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
2567
|
-
outputOptions = pluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
|
|
2568
2614
|
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
2569
2615
|
const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel);
|
|
2616
|
+
outputOptions = pluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
|
|
2617
|
+
if (outputOptions.minify === true) onLog(LOG_LEVEL_WARN, logMinifyWarning());
|
|
2570
2618
|
let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(await normalizePluginOption(outputOptions.plugins), ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
|
|
2571
2619
|
if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
|
|
2572
2620
|
const parallelPluginInitResult = await initializeParallelPlugins(plugins);
|
|
@@ -2574,7 +2622,13 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2574
2622
|
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
|
|
2575
2623
|
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
2576
2624
|
return {
|
|
2577
|
-
|
|
2625
|
+
bundlerOptions: {
|
|
2626
|
+
inputOptions: bindingInputOptions,
|
|
2627
|
+
outputOptions: bindingOutputOptions,
|
|
2628
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
2629
|
+
},
|
|
2630
|
+
inputOptions,
|
|
2631
|
+
onLog,
|
|
2578
2632
|
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
2579
2633
|
};
|
|
2580
2634
|
} catch (e) {
|
|
@@ -2583,6 +2637,22 @@ async function createBundler(inputOptions, outputOptions) {
|
|
|
2583
2637
|
}
|
|
2584
2638
|
}
|
|
2585
2639
|
|
|
2640
|
+
//#endregion
|
|
2641
|
+
//#region src/utils/create-bundler.ts
|
|
2642
|
+
var import_binding$1 = require_chunk.__toESM(require_binding());
|
|
2643
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
2644
|
+
const option = await createBundlerOptions(inputOptions, outputOptions);
|
|
2645
|
+
try {
|
|
2646
|
+
return {
|
|
2647
|
+
bundler: new import_binding$1.Bundler(option.bundlerOptions),
|
|
2648
|
+
stopWorkers: option.stopWorkers
|
|
2649
|
+
};
|
|
2650
|
+
} catch (e) {
|
|
2651
|
+
await option.stopWorkers?.();
|
|
2652
|
+
throw e;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2586
2656
|
//#endregion
|
|
2587
2657
|
//#region src/api/rolldown/rolldown-build.ts
|
|
2588
2658
|
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
@@ -2625,98 +2695,129 @@ const rolldown = async (input) => {
|
|
|
2625
2695
|
return new RolldownBuild(input);
|
|
2626
2696
|
};
|
|
2627
2697
|
|
|
2698
|
+
//#endregion
|
|
2699
|
+
//#region src/api/watch/watch-emitter.ts
|
|
2700
|
+
var WatcherEmitter = class {
|
|
2701
|
+
listeners = new Map();
|
|
2702
|
+
timer;
|
|
2703
|
+
constructor() {
|
|
2704
|
+
this.timer = setInterval(
|
|
2705
|
+
() => {},
|
|
2706
|
+
1e9
|
|
2707
|
+
/* Low power usage */
|
|
2708
|
+
);
|
|
2709
|
+
}
|
|
2710
|
+
on(event, listener) {
|
|
2711
|
+
const listeners = this.listeners.get(event);
|
|
2712
|
+
if (listeners) listeners.push(listener);
|
|
2713
|
+
else this.listeners.set(event, [listener]);
|
|
2714
|
+
return this;
|
|
2715
|
+
}
|
|
2716
|
+
async onEvent(event) {
|
|
2717
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
2718
|
+
if (listeners) switch (event.eventKind()) {
|
|
2719
|
+
case "close":
|
|
2720
|
+
case "restart":
|
|
2721
|
+
for (const listener of listeners) await listener();
|
|
2722
|
+
break;
|
|
2723
|
+
case "event":
|
|
2724
|
+
for (const listener of listeners) {
|
|
2725
|
+
const code = event.bundleEventKind();
|
|
2726
|
+
switch (code) {
|
|
2727
|
+
case "BUNDLE_END":
|
|
2728
|
+
const { duration, output } = event.bundleEndData();
|
|
2729
|
+
await listener({
|
|
2730
|
+
code: "BUNDLE_END",
|
|
2731
|
+
duration,
|
|
2732
|
+
output: [output]
|
|
2733
|
+
});
|
|
2734
|
+
break;
|
|
2735
|
+
case "ERROR":
|
|
2736
|
+
const errors = event.errors();
|
|
2737
|
+
await listener({
|
|
2738
|
+
code: "ERROR",
|
|
2739
|
+
error: normalizeErrors(errors)
|
|
2740
|
+
});
|
|
2741
|
+
break;
|
|
2742
|
+
default:
|
|
2743
|
+
await listener({ code });
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
break;
|
|
2748
|
+
case "change":
|
|
2749
|
+
for (const listener of listeners) {
|
|
2750
|
+
const { path: path$2, kind } = event.watchChangeData();
|
|
2751
|
+
await listener(path$2, { event: kind });
|
|
2752
|
+
}
|
|
2753
|
+
break;
|
|
2754
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
async close() {
|
|
2758
|
+
clearInterval(this.timer);
|
|
2759
|
+
}
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2628
2762
|
//#endregion
|
|
2629
2763
|
//#region src/api/watch/watcher.ts
|
|
2764
|
+
var import_binding = require_chunk.__toESM(require_binding());
|
|
2630
2765
|
var Watcher = class {
|
|
2631
2766
|
closed;
|
|
2632
|
-
controller;
|
|
2633
2767
|
inner;
|
|
2768
|
+
emitter;
|
|
2634
2769
|
stopWorkers;
|
|
2635
|
-
|
|
2636
|
-
constructor(inner, stopWorkers) {
|
|
2770
|
+
constructor(emitter, inner, stopWorkers) {
|
|
2637
2771
|
this.closed = false;
|
|
2638
|
-
this.controller = new AbortController();
|
|
2639
2772
|
this.inner = inner;
|
|
2773
|
+
this.emitter = emitter;
|
|
2774
|
+
const originClose = emitter.close.bind(emitter);
|
|
2775
|
+
emitter.close = async () => {
|
|
2776
|
+
await this.close();
|
|
2777
|
+
originClose();
|
|
2778
|
+
};
|
|
2640
2779
|
this.stopWorkers = stopWorkers;
|
|
2641
2780
|
}
|
|
2642
2781
|
async close() {
|
|
2782
|
+
if (this.closed) return;
|
|
2643
2783
|
this.closed = true;
|
|
2644
|
-
|
|
2784
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
2645
2785
|
await this.inner.close();
|
|
2646
|
-
this.controller.abort();
|
|
2647
2786
|
}
|
|
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
|
-
}));
|
|
2787
|
+
start() {
|
|
2788
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
2704
2789
|
}
|
|
2705
2790
|
};
|
|
2791
|
+
async function createWatcher(emitter, input) {
|
|
2792
|
+
const options = Array.isArray(input) ? input : [input];
|
|
2793
|
+
const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
|
|
2794
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
2795
|
+
const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
2796
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
2797
|
+
watcher.start();
|
|
2798
|
+
}
|
|
2799
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
2800
|
+
let result;
|
|
2801
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
2802
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
2803
|
+
if (notifyOption) if (result) {
|
|
2804
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
2805
|
+
return result;
|
|
2806
|
+
} else result = notifyOption;
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2706
2809
|
|
|
2707
2810
|
//#endregion
|
|
2708
2811
|
//#region src/api/watch/index.ts
|
|
2709
|
-
const watch =
|
|
2710
|
-
const
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
watcher.watch();
|
|
2714
|
-
return watcher;
|
|
2812
|
+
const watch = (input) => {
|
|
2813
|
+
const emitter = new WatcherEmitter();
|
|
2814
|
+
createWatcher(emitter, input);
|
|
2815
|
+
return emitter;
|
|
2715
2816
|
};
|
|
2716
2817
|
|
|
2717
2818
|
//#endregion
|
|
2718
2819
|
//#region package.json
|
|
2719
|
-
var version = "0.15.
|
|
2820
|
+
var version = "0.15.1-commit.cc6f557";
|
|
2720
2821
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2721
2822
|
|
|
2722
2823
|
//#endregion
|
|
@@ -2724,10 +2825,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
|
|
|
2724
2825
|
async function build(options) {
|
|
2725
2826
|
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
2726
2827
|
else {
|
|
2727
|
-
const { output,...inputOptions } = options;
|
|
2828
|
+
const { output, write = true,...inputOptions } = options;
|
|
2728
2829
|
const build$1 = await rolldown(inputOptions);
|
|
2729
|
-
|
|
2730
|
-
|
|
2830
|
+
try {
|
|
2831
|
+
if (write) return await build$1.write(output);
|
|
2832
|
+
else return await build$1.generate(output);
|
|
2833
|
+
} finally {
|
|
2834
|
+
await build$1.close();
|
|
2835
|
+
}
|
|
2731
2836
|
}
|
|
2732
2837
|
}
|
|
2733
2838
|
|