rolldown 0.13.2 → 0.14.0
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/LICENSE +1 -1
- package/dist/cjs/cli.cjs +388 -95
- package/dist/cjs/experimental-index.cjs +2 -3
- package/dist/cjs/index.cjs +2 -13
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/esm/cli.mjs +387 -94
- package/dist/esm/experimental-index.mjs +1 -2
- package/dist/esm/index.mjs +2 -14
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{consola.36c0034f-eps_ogJv.cjs → consola.36c0034f-HcmWcfPe.cjs} +2 -2
- package/dist/shared/{consola.36c0034f-m5cABVv4.mjs → consola.36c0034f-Xyw7SC_7.mjs} +1 -1
- package/dist/shared/{prompt-Ah5G71p-.cjs → prompt-9Ij3R3TG.cjs} +2 -2
- package/dist/shared/{prompt-9VjtYvi_.mjs → prompt-hoPhcrA-.mjs} +1 -1
- package/dist/shared/rolldown-binding.wasi.cjs +82 -73
- package/dist/shared/src_index-3pqhEViJ.cjs +2785 -0
- package/dist/shared/src_index-ywYMd4vB.mjs +2786 -0
- package/dist/shared/watcher-worker.js +1 -0
- package/dist/types/binding.d.ts +154 -66
- package/dist/types/cli/arguments/alias.d.ts +1 -0
- package/dist/types/cli/arguments/index.d.ts +1 -1
- package/dist/types/cli/arguments/normalize.d.ts +1 -0
- package/dist/types/cli/arguments/schema.d.ts +120 -35
- package/dist/types/constants/plugin.d.ts +1 -1
- package/dist/types/constants/types.d.ts +1 -0
- package/dist/types/experimental-index.d.ts +1 -0
- package/dist/types/index.d.ts +6 -5
- package/dist/types/log/logger.d.ts +9 -2
- package/dist/types/options/input-options.d.ts +241 -13
- package/dist/types/options/normalized-alias-plugin-config.d.ts +0 -2
- package/dist/types/options/normalized-output-options.d.ts +1 -1
- package/dist/types/options/output-options.d.ts +52 -54
- package/dist/types/options/watch-option.d.ts +5 -0
- package/dist/types/plugin/bindingify-hook-filter.d.ts +2 -0
- package/dist/types/plugin/bindingify-output-hooks.d.ts +1 -0
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +7 -0
- package/dist/types/plugin/hook-filter.d.ts +48 -0
- package/dist/types/plugin/index.d.ts +9 -15
- package/dist/types/plugin/plugin-context-data.d.ts +1 -1
- package/dist/types/plugin/plugin-context.d.ts +2 -6
- package/dist/types/plugin/plugin-driver.d.ts +1 -0
- package/dist/types/rolldown-build.d.ts +1 -1
- package/dist/types/rolldown.d.ts +3 -0
- package/dist/types/types/utils.d.ts +1 -0
- package/dist/types/utils/create-bundler.d.ts +3 -2
- package/dist/types/utils/transform-to-rollup-output.d.ts +8 -3
- package/dist/types/watcher.d.ts +31 -0
- package/package.json +19 -17
- package/dist/shared/package-8qJYyGdm.cjs +0 -11
- package/dist/shared/package-unZcnfG9.mjs +0 -9
- package/dist/shared/plugin-context-data-F1I9ytXp.cjs +0 -1435
- package/dist/shared/plugin-context-data-iKSAvmTX.mjs +0 -1442
- package/dist/shared/rolldown-ESzFTeqV.cjs +0 -1087
- package/dist/shared/rolldown-Hf7txSlh.mjs +0 -1071
- /package/dist/shared/{chunk-gQ4GMlVi.cjs → chunk-JoMxl5V2.cjs} +0 -0
|
@@ -1,1087 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { __toESM } = require("./chunk-gQ4GMlVi.cjs");
|
|
4
|
-
const { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARN, PluginContextData, SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF, arraify, bindingifyPlugin, error, getLogHandler, isNullish, logLevelPriority, logPluginError, normalizeHook, normalizeLog, normalizedStringOrRegex, require_binding, transformToRollupOutput, unimplemented } = require("./plugin-context-data-F1I9ytXp.cjs");
|
|
5
|
-
const { default: path } = __toESM(require("node:path"));
|
|
6
|
-
const { isRegExp, isRegExp: isRegExp$1 } = __toESM(require("node:util/types"));
|
|
7
|
-
const { Worker } = __toESM(require("node:worker_threads"));
|
|
8
|
-
const { availableParallelism } = __toESM(require("node:os"));
|
|
9
|
-
|
|
10
|
-
//#region src/options/normalized-ecma-transform-plugin-config.ts
|
|
11
|
-
function normalizeEcmaTransformPluginConfig(config) {
|
|
12
|
-
if (!config) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
let normalizedConfig = {
|
|
16
|
-
jsxInject: config?.jsxInject,
|
|
17
|
-
exclude: normalizedStringOrRegex(config.exclude),
|
|
18
|
-
include: normalizedStringOrRegex(config.include)
|
|
19
|
-
};
|
|
20
|
-
return normalizedConfig;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/options/normalized-alias-plugin-config.ts
|
|
25
|
-
function normalizeAliasPluginConfig(config) {
|
|
26
|
-
if (!config) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
let entries = config.entries.map((entry) => {
|
|
30
|
-
if (isRegExp$1(entry.find)) {
|
|
31
|
-
return {
|
|
32
|
-
find: {
|
|
33
|
-
value: entry.find.source,
|
|
34
|
-
flag: entry.find.flags
|
|
35
|
-
},
|
|
36
|
-
replacement: entry.replacement
|
|
37
|
-
};
|
|
38
|
-
} else {
|
|
39
|
-
return {
|
|
40
|
-
find: {value: entry.find},
|
|
41
|
-
replacement: entry.replacement
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return {entries};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/plugin/builtin-plugin.ts
|
|
50
|
-
var import_binding$3 = __toESM(require_binding());
|
|
51
|
-
class BuiltinPlugin {
|
|
52
|
-
constructor(name, options) {
|
|
53
|
-
this.name = name;
|
|
54
|
-
this.options = options;
|
|
55
|
-
this.name = name;
|
|
56
|
-
this.options = options;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
class ModulePreloadPolyfillPlugin extends BuiltinPlugin {
|
|
60
|
-
constructor(config) {
|
|
61
|
-
super(import_binding$3.BindingBuiltinPluginName.ModulePreloadPolyfillPlugin, config);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
class DynamicImportVarsPlugin extends BuiltinPlugin {
|
|
65
|
-
constructor() {
|
|
66
|
-
super(import_binding$3.BindingBuiltinPluginName.DynamicImportVarsPlugin);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
class ImportGlobPlugin extends BuiltinPlugin {
|
|
70
|
-
constructor(config) {
|
|
71
|
-
super(import_binding$3.BindingBuiltinPluginName.ImportGlobPlugin, config);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
class ManifestPlugin extends BuiltinPlugin {
|
|
75
|
-
constructor(config) {
|
|
76
|
-
super(import_binding$3.BindingBuiltinPluginName.ManifestPlugin, config);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
class WasmHelperPlugin extends BuiltinPlugin {
|
|
80
|
-
constructor() {
|
|
81
|
-
super(import_binding$3.BindingBuiltinPluginName.WasmHelperPlugin);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class WasmFallbackPlugin extends BuiltinPlugin {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(import_binding$3.BindingBuiltinPluginName.WasmFallbackPlugin);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
class LoadFallbackPlugin extends BuiltinPlugin {
|
|
90
|
-
constructor() {
|
|
91
|
-
super(import_binding$3.BindingBuiltinPluginName.LoadFallbackPlugin);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class AliasPlugin extends BuiltinPlugin {
|
|
95
|
-
constructor(config) {
|
|
96
|
-
let normalizedAliasPluginConfig = normalizeAliasPluginConfig(config);
|
|
97
|
-
super(import_binding$3.BindingBuiltinPluginName.AliasPlugin, normalizedAliasPluginConfig);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class TransformPlugin extends BuiltinPlugin {
|
|
101
|
-
constructor(config) {
|
|
102
|
-
let normalizedConfig = normalizeEcmaTransformPluginConfig(config);
|
|
103
|
-
super(import_binding$3.BindingBuiltinPluginName.TransformPlugin, normalizedConfig);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
class JsonPlugin extends BuiltinPlugin {
|
|
107
|
-
constructor(config) {
|
|
108
|
-
super(import_binding$3.BindingBuiltinPluginName.JsonPlugin, config);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
class BuildImportAnalysisPlugin extends BuiltinPlugin {
|
|
112
|
-
constructor(config) {
|
|
113
|
-
super(import_binding$3.BindingBuiltinPluginName.BuildImportAnalysisPlugin, config);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
class ReplacePlugin extends BuiltinPlugin {
|
|
117
|
-
constructor(config) {
|
|
118
|
-
super(import_binding$3.BindingBuiltinPluginName.ReplacePlugin, config);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function modulePreloadPolyfillPlugin(config) {
|
|
122
|
-
return new ModulePreloadPolyfillPlugin(config);
|
|
123
|
-
}
|
|
124
|
-
function dynamicImportVarsPlugin() {
|
|
125
|
-
return new DynamicImportVarsPlugin();
|
|
126
|
-
}
|
|
127
|
-
function importGlobPlugin(config) {
|
|
128
|
-
return new ImportGlobPlugin(config);
|
|
129
|
-
}
|
|
130
|
-
function manifestPlugin(config) {
|
|
131
|
-
return new ManifestPlugin(config);
|
|
132
|
-
}
|
|
133
|
-
function wasmHelperPlugin() {
|
|
134
|
-
return new WasmHelperPlugin();
|
|
135
|
-
}
|
|
136
|
-
function wasmFallbackPlugin() {
|
|
137
|
-
return new WasmFallbackPlugin();
|
|
138
|
-
}
|
|
139
|
-
function transformPlugin(config) {
|
|
140
|
-
return new TransformPlugin(config);
|
|
141
|
-
}
|
|
142
|
-
function loadFallbackPlugin() {
|
|
143
|
-
return new LoadFallbackPlugin();
|
|
144
|
-
}
|
|
145
|
-
function aliasPlugin(config) {
|
|
146
|
-
return new AliasPlugin(config);
|
|
147
|
-
}
|
|
148
|
-
function jsonPlugin(config) {
|
|
149
|
-
return new JsonPlugin(config);
|
|
150
|
-
}
|
|
151
|
-
function buildImportAnalysisPlugin(config) {
|
|
152
|
-
return new BuildImportAnalysisPlugin(config);
|
|
153
|
-
}
|
|
154
|
-
function replacePlugin(values = {}, options = {}) {
|
|
155
|
-
return new ReplacePlugin({
|
|
156
|
-
...options,
|
|
157
|
-
values
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
function bindingifyBuiltInPlugin(plugin) {
|
|
161
|
-
return {
|
|
162
|
-
__name: plugin.name,
|
|
163
|
-
options: plugin.options
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/options/bindingify-input-options.ts
|
|
169
|
-
var import_binding$2 = __toESM(require_binding());
|
|
170
|
-
function bindingifyInputOptions(options, outputOptions) {
|
|
171
|
-
const pluginContextData = new PluginContextData();
|
|
172
|
-
return {
|
|
173
|
-
input: bindingifyInput(options.input),
|
|
174
|
-
plugins: options.plugins.map((plugin) => {
|
|
175
|
-
if ("_parallel"in plugin) {
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
if (plugin instanceof BuiltinPlugin) {
|
|
179
|
-
return bindingifyBuiltInPlugin(plugin);
|
|
180
|
-
}
|
|
181
|
-
return bindingifyPlugin(plugin, options, outputOptions, pluginContextData);
|
|
182
|
-
}),
|
|
183
|
-
cwd: options.cwd ?? process.cwd(),
|
|
184
|
-
external: options.external ? function bindingifyExternal() {
|
|
185
|
-
const external = options.external;
|
|
186
|
-
if (typeof external === "function") {
|
|
187
|
-
return (id, importer, isResolved) => {
|
|
188
|
-
if (id.startsWith("\0")) return false;
|
|
189
|
-
return external(id, importer, isResolved) ?? false;
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
const externalArr = arraify(external);
|
|
193
|
-
return (id, _importer, _isResolved) => {
|
|
194
|
-
return externalArr.some((pat) => {
|
|
195
|
-
if (pat instanceof RegExp) {
|
|
196
|
-
return pat.test(id);
|
|
197
|
-
}
|
|
198
|
-
return id === pat;
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
}() : undefined,
|
|
202
|
-
resolve: options.resolve ? function bindingifyResolve() {
|
|
203
|
-
const { alias: alias,...rest } = options.resolve;
|
|
204
|
-
return {
|
|
205
|
-
alias: alias ? (Object.entries(alias)).map(([name, replacement]) => ({
|
|
206
|
-
find: name,
|
|
207
|
-
replacements: [replacement]
|
|
208
|
-
})) : undefined,
|
|
209
|
-
...rest
|
|
210
|
-
};
|
|
211
|
-
}() : undefined,
|
|
212
|
-
platform: options.platform,
|
|
213
|
-
shimMissingExports: options.shimMissingExports,
|
|
214
|
-
logLevel: bindingifyLogLevel(options.logLevel),
|
|
215
|
-
onLog: (level, log) => {
|
|
216
|
-
options.onLog(level, {
|
|
217
|
-
code: log.code,
|
|
218
|
-
message: log.message
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
treeshake: options.treeshake,
|
|
222
|
-
moduleTypes: options.moduleTypes,
|
|
223
|
-
define: options.define ? Object.entries(options.define) : undefined,
|
|
224
|
-
inject: options.inject ? (Object.entries(options.inject)).map(([alias, item]) => {
|
|
225
|
-
if (Array.isArray(item)) {
|
|
226
|
-
if (item[1] === "*") {
|
|
227
|
-
return {
|
|
228
|
-
tagNamespace: true,
|
|
229
|
-
alias,
|
|
230
|
-
from: item[0]
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
tagNamed: true,
|
|
235
|
-
alias,
|
|
236
|
-
from: item[0],
|
|
237
|
-
imported: item[1]
|
|
238
|
-
};
|
|
239
|
-
} else {
|
|
240
|
-
return {
|
|
241
|
-
tagNamed: true,
|
|
242
|
-
imported: "default",
|
|
243
|
-
alias,
|
|
244
|
-
from: item
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
}) : undefined
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function bindingifyLogLevel(logLevel) {
|
|
251
|
-
switch (logLevel) {
|
|
252
|
-
case "silent": return import_binding$2.BindingLogLevel.Silent;
|
|
253
|
-
case "warn": return import_binding$2.BindingLogLevel.Warn;
|
|
254
|
-
case "info": return import_binding$2.BindingLogLevel.Info;
|
|
255
|
-
case "debug": return import_binding$2.BindingLogLevel.Debug;
|
|
256
|
-
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function bindingifyInput(input) {
|
|
260
|
-
if (Array.isArray(input)) {
|
|
261
|
-
return input.map((src) => {
|
|
262
|
-
return {import: src};
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
return (Object.entries(input)).map((value) => {
|
|
266
|
-
return {
|
|
267
|
-
name: value[0],
|
|
268
|
-
import: value[1]
|
|
269
|
-
};
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/utils/initialize-parallel-plugins.ts
|
|
276
|
-
var import_binding$1 = __toESM(require_binding());
|
|
277
|
-
async function initializeParallelPlugins(plugins) {
|
|
278
|
-
const pluginInfos = [];
|
|
279
|
-
for (const [index, plugin] of plugins.entries()) {
|
|
280
|
-
if ("_parallel"in plugin) {
|
|
281
|
-
const { fileUrl: fileUrl, options: options } = plugin._parallel;
|
|
282
|
-
pluginInfos.push({
|
|
283
|
-
index,
|
|
284
|
-
fileUrl,
|
|
285
|
-
options
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (pluginInfos.length <= 0) {
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
const count = Math.min(availableParallelism(), 8);
|
|
293
|
-
const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
|
|
294
|
-
const registryId = parallelJsPluginRegistry.id;
|
|
295
|
-
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
296
|
-
const stopWorkers = async () => {
|
|
297
|
-
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
298
|
-
};
|
|
299
|
-
return {
|
|
300
|
-
registry: parallelJsPluginRegistry,
|
|
301
|
-
stopWorkers
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function initializeWorkers(registryId, count, pluginInfos) {
|
|
305
|
-
return Promise.all(Array.from({length: count}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
306
|
-
}
|
|
307
|
-
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
308
|
-
const urlString = undefined("#parallel-plugin-worker");
|
|
309
|
-
const workerData = {
|
|
310
|
-
registryId,
|
|
311
|
-
pluginInfos,
|
|
312
|
-
threadNumber
|
|
313
|
-
};
|
|
314
|
-
let worker;
|
|
315
|
-
try {
|
|
316
|
-
worker = new Worker(new URL(urlString), {workerData});
|
|
317
|
-
worker.unref();
|
|
318
|
-
await new Promise((resolve, reject) => {
|
|
319
|
-
worker.once("message", async (message) => {
|
|
320
|
-
if (message.type === "error") {
|
|
321
|
-
reject(message.error);
|
|
322
|
-
} else {
|
|
323
|
-
resolve();
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
return worker;
|
|
328
|
-
} catch (e) {
|
|
329
|
-
worker?.terminate();
|
|
330
|
-
throw e;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
//#endregion
|
|
335
|
-
//#region src/log/logger.ts
|
|
336
|
-
function getLogger(plugins, onLog, logLevel) {
|
|
337
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
338
|
-
const logger = (level, log, skipped = new Set()) => {
|
|
339
|
-
const logPriority = logLevelPriority[level];
|
|
340
|
-
if (logPriority < minimalPriority) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
for (const plugin of plugins) {
|
|
344
|
-
if (skipped.has(plugin)) continue;
|
|
345
|
-
const { onLog: pluginOnLog } = plugin;
|
|
346
|
-
if (pluginOnLog) {
|
|
347
|
-
const getLogHandler$1 = (level$1) => {
|
|
348
|
-
if (logLevelPriority[level$1] < minimalPriority) {
|
|
349
|
-
return () => {};
|
|
350
|
-
}
|
|
351
|
-
return (log$1) => logger(level$1, normalizeLog(log$1), (new Set(skipped)).add(plugin));
|
|
352
|
-
};
|
|
353
|
-
const handler = "handler"in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
|
|
354
|
-
if (handler.call({
|
|
355
|
-
debug: getLogHandler$1(LOG_LEVEL_DEBUG),
|
|
356
|
-
error: (log$1) => error(normalizeLog(log$1)),
|
|
357
|
-
info: getLogHandler$1(LOG_LEVEL_INFO),
|
|
358
|
-
warn: getLogHandler$1(LOG_LEVEL_WARN)
|
|
359
|
-
}, level, log) === false) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
onLog(level, log);
|
|
365
|
-
};
|
|
366
|
-
return logger;
|
|
367
|
-
}
|
|
368
|
-
const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
|
|
369
|
-
const { onwarn: onwarn, onLog: onLog } = config;
|
|
370
|
-
const defaultOnLog = getDefaultOnLog(printLog, onwarn);
|
|
371
|
-
if (onLog) {
|
|
372
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
373
|
-
return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
|
|
374
|
-
if (level$1 === LOG_LEVEL_ERROR) {
|
|
375
|
-
return error(normalizeLog(handledLog));
|
|
376
|
-
}
|
|
377
|
-
if (logLevelPriority[level$1] >= minimalPriority) {
|
|
378
|
-
defaultOnLog(level$1, normalizeLog(handledLog));
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
return defaultOnLog;
|
|
383
|
-
};
|
|
384
|
-
const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
|
|
385
|
-
if (level === LOG_LEVEL_WARN) {
|
|
386
|
-
onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
|
|
387
|
-
} else {
|
|
388
|
-
printLog(level, log);
|
|
389
|
-
}
|
|
390
|
-
} : printLog;
|
|
391
|
-
const addLogToString = (log) => {
|
|
392
|
-
Object.defineProperty(log, "toString", {
|
|
393
|
-
value: () => getExtendedLogMessage(log),
|
|
394
|
-
writable: true
|
|
395
|
-
});
|
|
396
|
-
return log;
|
|
397
|
-
};
|
|
398
|
-
const defaultPrintLog = (level, log) => {
|
|
399
|
-
const message = getExtendedLogMessage(log);
|
|
400
|
-
switch (level) {
|
|
401
|
-
case LOG_LEVEL_WARN: {
|
|
402
|
-
return console.warn(message);
|
|
403
|
-
}
|
|
404
|
-
case LOG_LEVEL_DEBUG: {
|
|
405
|
-
return console.debug(message);
|
|
406
|
-
}
|
|
407
|
-
default: {
|
|
408
|
-
return console.info(message);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
const getExtendedLogMessage = (log) => {
|
|
413
|
-
let prefix = "";
|
|
414
|
-
if (log.plugin) {
|
|
415
|
-
prefix += `(${log.plugin} plugin) `;
|
|
416
|
-
}
|
|
417
|
-
if (log.loc) {
|
|
418
|
-
prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
|
|
419
|
-
}
|
|
420
|
-
return prefix + log.message;
|
|
421
|
-
};
|
|
422
|
-
function relativeId(id) {
|
|
423
|
-
if (!path.isAbsolute(id)) return id;
|
|
424
|
-
return path.relative(path.resolve(), id);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
//#endregion
|
|
428
|
-
//#region src/plugin/plugin-driver.ts
|
|
429
|
-
class PluginDriver {
|
|
430
|
-
async callOptionsHook(inputOptions) {
|
|
431
|
-
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
432
|
-
const plugins = getObjectPlugins(inputOptions.plugins ?? []);
|
|
433
|
-
const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
|
|
434
|
-
for (const plugin of plugins) {
|
|
435
|
-
const name = plugin.name || "unknown";
|
|
436
|
-
const options = plugin.options;
|
|
437
|
-
if (options) {
|
|
438
|
-
const { handler: handler } = normalizeHook(options);
|
|
439
|
-
const result = await handler.call({
|
|
440
|
-
debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
|
|
441
|
-
error: (e) => error(logPluginError(normalizeLog(e), name, {hook: "onLog"})),
|
|
442
|
-
info: getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", logger, name, logLevel),
|
|
443
|
-
warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
|
|
444
|
-
}, inputOptions);
|
|
445
|
-
if (result) {
|
|
446
|
-
inputOptions = result;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return inputOptions;
|
|
451
|
-
}
|
|
452
|
-
callOutputOptionsHook(inputOptions, outputOptions) {
|
|
453
|
-
const plugins = getObjectPlugins(inputOptions.plugins);
|
|
454
|
-
for (const plugin of plugins) {
|
|
455
|
-
const options = plugin.outputOptions;
|
|
456
|
-
if (options) {
|
|
457
|
-
const { handler: handler } = normalizeHook(options);
|
|
458
|
-
const result = handler.call(null, outputOptions);
|
|
459
|
-
if (result) {
|
|
460
|
-
outputOptions = result;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return outputOptions;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
function getObjectPlugins(plugins) {
|
|
468
|
-
return plugins.filter((plugin) => {
|
|
469
|
-
if ("_parallel"in plugin) {
|
|
470
|
-
return undefined;
|
|
471
|
-
}
|
|
472
|
-
if (plugin instanceof BuiltinPlugin) {
|
|
473
|
-
return undefined;
|
|
474
|
-
}
|
|
475
|
-
return plugin;
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
//#endregion
|
|
480
|
-
//#region src/utils/async-flatten.ts
|
|
481
|
-
async function asyncFlatten(array) {
|
|
482
|
-
do {
|
|
483
|
-
array = (await Promise.all(array)).flat(Infinity);
|
|
484
|
-
} while (array.some((v) => v?.then));
|
|
485
|
-
return array;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
//#endregion
|
|
489
|
-
//#region src/utils/normalize-plugin-option.ts
|
|
490
|
-
const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
|
|
491
|
-
|
|
492
|
-
//#endregion
|
|
493
|
-
//#region src/utils/normalize-tree-shake.ts
|
|
494
|
-
function normalizeTreeshakeOptions(config) {
|
|
495
|
-
if (config === false) {
|
|
496
|
-
return undefined;
|
|
497
|
-
}
|
|
498
|
-
if (config === true || config === undefined) {
|
|
499
|
-
return {moduleSideEffects: "true"};
|
|
500
|
-
}
|
|
501
|
-
let normalizedConfig = {moduleSideEffects: ""};
|
|
502
|
-
if (config.moduleSideEffects === undefined) {
|
|
503
|
-
normalizedConfig.moduleSideEffects = "true";
|
|
504
|
-
} else if (isRegExp(config.moduleSideEffects)) {
|
|
505
|
-
normalizedConfig.moduleSideEffects = config.moduleSideEffects.source;
|
|
506
|
-
} else {
|
|
507
|
-
normalizedConfig.moduleSideEffects = config.moduleSideEffects.toString();
|
|
508
|
-
}
|
|
509
|
-
return normalizedConfig;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-K26VP6CL.js
|
|
514
|
-
function u$1(t$1, n, a) {
|
|
515
|
-
let o = (r) => t$1(r, ...n);
|
|
516
|
-
return a === void 0 ? o : Object.assign(o, {
|
|
517
|
-
lazy: a,
|
|
518
|
-
lazyArgs: n
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
//#endregion
|
|
523
|
-
//#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-RAAYCPUM.js
|
|
524
|
-
function u(r, n, a) {
|
|
525
|
-
let o = r.length - n.length;
|
|
526
|
-
if (o === 0) return r(...n);
|
|
527
|
-
if (o === 1) return u$1(r, n, a);
|
|
528
|
-
throw new Error("Wrong number of arguments");
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-NMJS7ULY.js
|
|
533
|
-
function t(...n) {
|
|
534
|
-
return u(Object.keys, n);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
//#endregion
|
|
538
|
-
//#region src/constants/plugin.ts
|
|
539
|
-
const ENUMERATED_PLUGIN_HOOK_NAMES = ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "augmentChunkHash", "buildEnd", "onLog", "resolveDynamicImport", "generateBundle", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "footer", "banner", "intro", "outro",];
|
|
540
|
-
const DEFINED_HOOK_NAMES = {
|
|
541
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
|
|
542
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
|
|
543
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
|
|
544
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
|
|
545
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
|
|
546
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
|
|
547
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
|
|
548
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
|
|
549
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
|
|
550
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
|
|
551
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
|
|
552
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
|
|
553
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
|
|
554
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
|
|
555
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
|
|
556
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
|
|
557
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
|
|
558
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
|
|
559
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
|
|
560
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19]
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region src/utils/plugin/index.ts
|
|
565
|
-
const isPluginHookName = function() {
|
|
566
|
-
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
567
|
-
return function isPluginHookName$1(hookName) {
|
|
568
|
-
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
569
|
-
};
|
|
570
|
-
}();
|
|
571
|
-
|
|
572
|
-
//#endregion
|
|
573
|
-
//#region src/utils/compose-js-plugins.ts
|
|
574
|
-
const unsupportedHookName = ["augmentChunkHash", "generateBundle", "moduleParsed", "onLog", "options", "outputOptions", "renderError", "renderStart", "resolveDynamicImport", "writeBundle",];
|
|
575
|
-
const unsupportedHooks = new Set(unsupportedHookName);
|
|
576
|
-
function isUnsupportedHooks(hookName) {
|
|
577
|
-
return unsupportedHooks.has(hookName);
|
|
578
|
-
}
|
|
579
|
-
function createComposedPlugin(plugins) {
|
|
580
|
-
const names = [];
|
|
581
|
-
const batchedHooks = {};
|
|
582
|
-
plugins.forEach((plugin, index) => {
|
|
583
|
-
const pluginName = plugin.name || `Anonymous(index: ${index})`;
|
|
584
|
-
names.push(pluginName);
|
|
585
|
-
(t(plugin)).forEach((pluginProp) => {
|
|
586
|
-
if (isUnsupportedHooks(pluginProp)) {
|
|
587
|
-
throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
|
|
588
|
-
}
|
|
589
|
-
if (!isPluginHookName(pluginProp)) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
switch (pluginProp) {
|
|
593
|
-
case "buildStart": {
|
|
594
|
-
const handlers = batchedHooks.buildStart ?? [];
|
|
595
|
-
batchedHooks.buildStart = handlers;
|
|
596
|
-
if (plugin.buildStart) {
|
|
597
|
-
handlers.push([plugin.buildStart, plugin]);
|
|
598
|
-
}
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
case "load": {
|
|
602
|
-
const handlers = batchedHooks.load ?? [];
|
|
603
|
-
batchedHooks.load = handlers;
|
|
604
|
-
if (plugin.load) {
|
|
605
|
-
handlers.push([plugin.load, plugin]);
|
|
606
|
-
}
|
|
607
|
-
break;
|
|
608
|
-
}
|
|
609
|
-
case "transform": {
|
|
610
|
-
const handlers = batchedHooks.transform ?? [];
|
|
611
|
-
batchedHooks.transform = handlers;
|
|
612
|
-
if (plugin.transform) {
|
|
613
|
-
handlers.push([plugin.transform, plugin]);
|
|
614
|
-
}
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
case "resolveId": {
|
|
618
|
-
const handlers = batchedHooks.resolveId ?? [];
|
|
619
|
-
batchedHooks.resolveId = handlers;
|
|
620
|
-
if (plugin.resolveId) {
|
|
621
|
-
handlers.push([plugin.resolveId, plugin]);
|
|
622
|
-
}
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
case "buildEnd": {
|
|
626
|
-
const handlers = batchedHooks.buildEnd ?? [];
|
|
627
|
-
batchedHooks.buildEnd = handlers;
|
|
628
|
-
if (plugin.buildEnd) {
|
|
629
|
-
handlers.push([plugin.buildEnd, plugin]);
|
|
630
|
-
}
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
case "renderChunk": {
|
|
634
|
-
const handlers = batchedHooks.renderChunk ?? [];
|
|
635
|
-
batchedHooks.renderChunk = handlers;
|
|
636
|
-
if (plugin.renderChunk) {
|
|
637
|
-
handlers.push([plugin.renderChunk, plugin]);
|
|
638
|
-
}
|
|
639
|
-
break;
|
|
640
|
-
}
|
|
641
|
-
case "banner":
|
|
642
|
-
case "footer":
|
|
643
|
-
case "intro":
|
|
644
|
-
case "outro": {
|
|
645
|
-
const hook = plugin[pluginProp];
|
|
646
|
-
if (hook) {
|
|
647
|
-
;
|
|
648
|
-
(batchedHooks[pluginProp] ??= []).push([hook, plugin]);
|
|
649
|
-
}
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
default: {}
|
|
653
|
-
}
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
const composed = {name: `Composed(${names.join(", ")})`};
|
|
657
|
-
const createFixedPluginResolveFnMap = new Map();
|
|
658
|
-
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
659
|
-
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
660
|
-
if (createFixedPluginResolveFn) {
|
|
661
|
-
return {
|
|
662
|
-
...ctx,
|
|
663
|
-
resolve: createFixedPluginResolveFn(ctx)
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
return ctx;
|
|
667
|
-
}
|
|
668
|
-
if (batchedHooks.resolveId) {
|
|
669
|
-
const batchedHandlers = batchedHooks.resolveId;
|
|
670
|
-
const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
|
|
671
|
-
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
672
|
-
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
673
|
-
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
674
|
-
const createFixedPluginResolveFn = (ctx) => {
|
|
675
|
-
return (source, importer, rawContextResolveOptions) => {
|
|
676
|
-
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
677
|
-
if (contextResolveOptions.skipSelf) {
|
|
678
|
-
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
679
|
-
contextResolveOptions.skipSelf = false;
|
|
680
|
-
}
|
|
681
|
-
return ctx.resolve(source, importer, contextResolveOptions);
|
|
682
|
-
};
|
|
683
|
-
};
|
|
684
|
-
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
685
|
-
}
|
|
686
|
-
composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
|
|
687
|
-
const hookResolveIdOptions = rawHookResolveIdOptions;
|
|
688
|
-
const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
|
|
689
|
-
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
690
|
-
const [handler, plugin] = batchedHandlers[handlerIdx];
|
|
691
|
-
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
692
|
-
if (symbolForCallerThatSkipSelf === handlerSymbol) {
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
696
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
|
|
697
|
-
if (!isNullish(result)) {
|
|
698
|
-
return result;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
(t(batchedHooks)).forEach((hookName) => {
|
|
704
|
-
switch (hookName) {
|
|
705
|
-
case "resolveId": {
|
|
706
|
-
break;
|
|
707
|
-
}
|
|
708
|
-
case "buildStart": {
|
|
709
|
-
if (batchedHooks.buildStart) {
|
|
710
|
-
const batchedHandlers = batchedHooks.buildStart;
|
|
711
|
-
composed.buildStart = async function(options) {
|
|
712
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
713
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
714
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
|
|
715
|
-
}));
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
case "load": {
|
|
721
|
-
if (batchedHooks.load) {
|
|
722
|
-
const batchedHandlers = batchedHooks.load;
|
|
723
|
-
composed.load = async function(id) {
|
|
724
|
-
for (const [handler, plugin] of batchedHandlers) {
|
|
725
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
726
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
|
|
727
|
-
if (!isNullish(result)) {
|
|
728
|
-
return result;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
|
-
case "transform": {
|
|
736
|
-
if (batchedHooks.transform) {
|
|
737
|
-
const batchedHandlers = batchedHooks.transform;
|
|
738
|
-
composed.transform = async function(initialCode, id, moduleType) {
|
|
739
|
-
let code = initialCode;
|
|
740
|
-
let moduleSideEffects = undefined;
|
|
741
|
-
function updateOutput(newCode, newModuleSideEffects) {
|
|
742
|
-
code = newCode;
|
|
743
|
-
moduleSideEffects = newModuleSideEffects ?? undefined;
|
|
744
|
-
}
|
|
745
|
-
for (const [handler, plugin] of batchedHandlers) {
|
|
746
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
747
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
748
|
-
if (!isNullish(result)) {
|
|
749
|
-
if (typeof result === "string") {
|
|
750
|
-
updateOutput(result);
|
|
751
|
-
} else {
|
|
752
|
-
if (result.code) {
|
|
753
|
-
updateOutput(result.code, result.moduleSideEffects);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
return {
|
|
759
|
-
code,
|
|
760
|
-
moduleSideEffects
|
|
761
|
-
};
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
break;
|
|
765
|
-
}
|
|
766
|
-
case "buildEnd": {
|
|
767
|
-
if (batchedHooks.buildEnd) {
|
|
768
|
-
const batchedHandlers = batchedHooks.buildEnd;
|
|
769
|
-
composed.buildEnd = async function(err) {
|
|
770
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
771
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
772
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
|
|
773
|
-
}));
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
case "renderChunk": {
|
|
779
|
-
if (batchedHooks.renderChunk) {
|
|
780
|
-
const batchedHandlers = batchedHooks.renderChunk;
|
|
781
|
-
composed.renderChunk = async function(code, chunk, options) {
|
|
782
|
-
for (const [handler, plugin] of batchedHandlers) {
|
|
783
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
784
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
|
|
785
|
-
if (!isNullish(result)) {
|
|
786
|
-
return result;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
break;
|
|
792
|
-
}
|
|
793
|
-
case "banner":
|
|
794
|
-
case "footer":
|
|
795
|
-
case "intro":
|
|
796
|
-
case "outro": {
|
|
797
|
-
const hooks = batchedHooks[hookName];
|
|
798
|
-
if (hooks?.length) {
|
|
799
|
-
composed[hookName] = async function(chunk) {
|
|
800
|
-
const ret = [];
|
|
801
|
-
for (const [hook, plugin] of hooks) {
|
|
802
|
-
{
|
|
803
|
-
const { handler: handler } = normalizeHook(hook);
|
|
804
|
-
ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
return ret.join("\n");
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
default: {}
|
|
813
|
-
}
|
|
814
|
-
});
|
|
815
|
-
return composed;
|
|
816
|
-
}
|
|
817
|
-
function isComposablePlugin(plugin) {
|
|
818
|
-
if (plugin instanceof BuiltinPlugin) {
|
|
819
|
-
return false;
|
|
820
|
-
}
|
|
821
|
-
if ("_parallel"in plugin) {
|
|
822
|
-
return false;
|
|
823
|
-
}
|
|
824
|
-
const hasNotComposablePattern = (t(plugin)).some((hookName) => {
|
|
825
|
-
if (!isPluginHookName(hookName)) {
|
|
826
|
-
return false;
|
|
827
|
-
}
|
|
828
|
-
const OK_TO_COMPOSE = false;
|
|
829
|
-
if (isUnsupportedHooks(hookName)) {
|
|
830
|
-
return !OK_TO_COMPOSE;
|
|
831
|
-
}
|
|
832
|
-
if (plugin[hookName]) {
|
|
833
|
-
const { meta: meta } = normalizeHook(plugin[hookName]);
|
|
834
|
-
if (meta.order === "pre" || meta.order === "post") {
|
|
835
|
-
return !OK_TO_COMPOSE;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
return OK_TO_COMPOSE;
|
|
839
|
-
});
|
|
840
|
-
if (hasNotComposablePattern) {
|
|
841
|
-
return false;
|
|
842
|
-
}
|
|
843
|
-
return true;
|
|
844
|
-
}
|
|
845
|
-
function composeJsPlugins(plugins) {
|
|
846
|
-
const newPlugins = [];
|
|
847
|
-
const toBeComposed = [];
|
|
848
|
-
plugins.forEach((plugin) => {
|
|
849
|
-
if (isComposablePlugin(plugin)) {
|
|
850
|
-
toBeComposed.push(plugin);
|
|
851
|
-
} else {
|
|
852
|
-
if (toBeComposed.length > 0) {
|
|
853
|
-
if (toBeComposed.length > 1) {
|
|
854
|
-
newPlugins.push(createComposedPlugin(toBeComposed));
|
|
855
|
-
} else {
|
|
856
|
-
newPlugins.push(toBeComposed[0]);
|
|
857
|
-
}
|
|
858
|
-
toBeComposed.length = 0;
|
|
859
|
-
}
|
|
860
|
-
newPlugins.push(plugin);
|
|
861
|
-
}
|
|
862
|
-
});
|
|
863
|
-
if (toBeComposed.length > 0) {
|
|
864
|
-
if (toBeComposed.length > 1) {
|
|
865
|
-
newPlugins.push(createComposedPlugin(toBeComposed));
|
|
866
|
-
} else {
|
|
867
|
-
newPlugins.push(toBeComposed[0]);
|
|
868
|
-
}
|
|
869
|
-
toBeComposed.length = 0;
|
|
870
|
-
}
|
|
871
|
-
return newPlugins;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
//#endregion
|
|
875
|
-
//#region src/utils/normalize-input-options.ts
|
|
876
|
-
async function normalizeInputOptions(config) {
|
|
877
|
-
const { input: input,...rest } = config;
|
|
878
|
-
let plugins = await normalizePluginOption(config.plugins);
|
|
879
|
-
if (rest.experimental?.enableComposingJsPlugins ?? false) {
|
|
880
|
-
plugins = composeJsPlugins(plugins);
|
|
881
|
-
}
|
|
882
|
-
const treeshake = normalizeTreeshakeOptions(config.treeshake);
|
|
883
|
-
const logLevel = config.logLevel || LOG_LEVEL_INFO;
|
|
884
|
-
const onLog = getLogger(getObjectPlugins(plugins), getOnLog(config, logLevel), logLevel);
|
|
885
|
-
return {
|
|
886
|
-
...rest,
|
|
887
|
-
input: input ? typeof input === "string" ? [input] : input : [],
|
|
888
|
-
plugins,
|
|
889
|
-
logLevel,
|
|
890
|
-
onLog,
|
|
891
|
-
treeshake
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
//#endregion
|
|
896
|
-
//#region src/utils/normalize-output-options.ts
|
|
897
|
-
function normalizeOutputOptions(opts) {
|
|
898
|
-
const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, globals: globals, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, name: name, esModule: esModule } = opts;
|
|
899
|
-
return {
|
|
900
|
-
dir: dir,
|
|
901
|
-
format: getFormat(format),
|
|
902
|
-
exports: exports ?? "auto",
|
|
903
|
-
sourcemap: sourcemap ?? false,
|
|
904
|
-
sourcemapIgnoreList: typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules"),
|
|
905
|
-
sourcemapPathTransform,
|
|
906
|
-
banner: getAddon(opts, "banner"),
|
|
907
|
-
footer: getAddon(opts, "footer"),
|
|
908
|
-
intro: getAddon(opts, "intro"),
|
|
909
|
-
outro: getAddon(opts, "outro"),
|
|
910
|
-
esModule: esModule ?? "if-default-prop",
|
|
911
|
-
globals: globals ?? {},
|
|
912
|
-
entryFileNames: entryFileNames ?? "[name].js",
|
|
913
|
-
chunkFileNames: chunkFileNames ?? "[name]-[hash].js",
|
|
914
|
-
assetFileNames: assetFileNames ?? "assets/[name]-[hash][extname]",
|
|
915
|
-
plugins: [],
|
|
916
|
-
minify: opts.minify,
|
|
917
|
-
extend: opts.extend,
|
|
918
|
-
name,
|
|
919
|
-
externalLiveBindings: opts.externalLiveBindings ?? true,
|
|
920
|
-
inlineDynamicImports: opts.inlineDynamicImports ?? false,
|
|
921
|
-
advancedChunks: opts.advancedChunks
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
function getFormat(format) {
|
|
925
|
-
switch (format) {
|
|
926
|
-
case undefined:
|
|
927
|
-
case "es":
|
|
928
|
-
case "esm":
|
|
929
|
-
case "module": {
|
|
930
|
-
return "es";
|
|
931
|
-
}
|
|
932
|
-
case "cjs":
|
|
933
|
-
case "commonjs": {
|
|
934
|
-
return "cjs";
|
|
935
|
-
}
|
|
936
|
-
case "iife": {
|
|
937
|
-
return "iife";
|
|
938
|
-
}
|
|
939
|
-
default: unimplemented(`output.format: ${format}`);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
const getAddon = (config, name) => {
|
|
943
|
-
return async (chunk) => {
|
|
944
|
-
const configAddon = config[name];
|
|
945
|
-
if (typeof configAddon === "function") {
|
|
946
|
-
return configAddon(chunk);
|
|
947
|
-
}
|
|
948
|
-
return configAddon || "";
|
|
949
|
-
};
|
|
950
|
-
};
|
|
951
|
-
|
|
952
|
-
//#endregion
|
|
953
|
-
//#region src/options/bindingify-output-options.ts
|
|
954
|
-
function bindingifyOutputOptions(outputOptions) {
|
|
955
|
-
const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, name: name, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, banner: banner, footer: footer, intro: intro, outro: outro, esModule: esModule, globals: globals } = outputOptions;
|
|
956
|
-
return {
|
|
957
|
-
dir,
|
|
958
|
-
format: function() {
|
|
959
|
-
switch (format) {
|
|
960
|
-
case "es": return "es";
|
|
961
|
-
case "cjs": return "cjs";
|
|
962
|
-
case "iife": return "iife";
|
|
963
|
-
}
|
|
964
|
-
}(),
|
|
965
|
-
exports,
|
|
966
|
-
sourcemap: bindingifySourcemap(sourcemap),
|
|
967
|
-
sourcemapIgnoreList,
|
|
968
|
-
sourcemapPathTransform,
|
|
969
|
-
banner,
|
|
970
|
-
footer,
|
|
971
|
-
intro,
|
|
972
|
-
outro,
|
|
973
|
-
extend: outputOptions.extend,
|
|
974
|
-
globals,
|
|
975
|
-
esModule: bindingifyEsModule(esModule),
|
|
976
|
-
name,
|
|
977
|
-
entryFileNames,
|
|
978
|
-
chunkFileNames,
|
|
979
|
-
assetFileNames,
|
|
980
|
-
plugins: [],
|
|
981
|
-
minify: outputOptions.minify,
|
|
982
|
-
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
983
|
-
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
984
|
-
advancedChunks: outputOptions.advancedChunks
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
function bindingifySourcemap(sourcemap) {
|
|
988
|
-
switch (sourcemap) {
|
|
989
|
-
case true: return "file";
|
|
990
|
-
case "inline": return "inline";
|
|
991
|
-
case false:
|
|
992
|
-
case undefined:
|
|
993
|
-
case "hidden": return "hidden";
|
|
994
|
-
default: throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
function bindingifyEsModule(esModule) {
|
|
998
|
-
switch (esModule) {
|
|
999
|
-
case true:
|
|
1000
|
-
case false:
|
|
1001
|
-
case "if-default-prop": return esModule;
|
|
1002
|
-
default: throw new Error(`unknown esModule: ${esModule}`);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
//#endregion
|
|
1007
|
-
//#region src/utils/create-bundler.ts
|
|
1008
|
-
var import_binding = __toESM(require_binding());
|
|
1009
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
1010
|
-
const pluginDriver = new PluginDriver();
|
|
1011
|
-
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
1012
|
-
const normalizedInputOptions = await normalizeInputOptions(inputOptions);
|
|
1013
|
-
const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
|
|
1014
|
-
try {
|
|
1015
|
-
outputOptions = pluginDriver.callOutputOptionsHook(normalizedInputOptions, outputOptions);
|
|
1016
|
-
const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
|
|
1017
|
-
const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
|
|
1018
|
-
return {
|
|
1019
|
-
bundler: new import_binding.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
|
|
1020
|
-
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
1021
|
-
};
|
|
1022
|
-
} catch (e) {
|
|
1023
|
-
await parallelPluginInitResult?.stopWorkers();
|
|
1024
|
-
throw e;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
//#endregion
|
|
1029
|
-
//#region src/rolldown-build.ts
|
|
1030
|
-
class RolldownBuild {
|
|
1031
|
-
#inputOptions;
|
|
1032
|
-
#bundler;
|
|
1033
|
-
#stopWorkers;
|
|
1034
|
-
constructor(inputOptions) {
|
|
1035
|
-
this.#inputOptions = inputOptions;
|
|
1036
|
-
}
|
|
1037
|
-
async #getBundler(outputOptions) {
|
|
1038
|
-
if (typeof this.#bundler === "undefined") {
|
|
1039
|
-
const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(this.#inputOptions, outputOptions);
|
|
1040
|
-
this.#bundler = bundler;
|
|
1041
|
-
this.#stopWorkers = stopWorkers;
|
|
1042
|
-
}
|
|
1043
|
-
return this.#bundler;
|
|
1044
|
-
}
|
|
1045
|
-
async generate(outputOptions = {}) {
|
|
1046
|
-
const bundler = await this.#getBundler(outputOptions);
|
|
1047
|
-
const output = await bundler.generate();
|
|
1048
|
-
return transformToRollupOutput(output);
|
|
1049
|
-
}
|
|
1050
|
-
async write(outputOptions = {}) {
|
|
1051
|
-
const bundler = await this.#getBundler(outputOptions);
|
|
1052
|
-
const output = await bundler.write();
|
|
1053
|
-
return transformToRollupOutput(output);
|
|
1054
|
-
}
|
|
1055
|
-
async destroy() {
|
|
1056
|
-
await this.#stopWorkers?.();
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
//#endregion
|
|
1061
|
-
//#region src/rolldown.ts
|
|
1062
|
-
const rolldown = async (input) => {
|
|
1063
|
-
return new RolldownBuild(input);
|
|
1064
|
-
};
|
|
1065
|
-
const experimental_scan = async (input) => {
|
|
1066
|
-
const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(input, {});
|
|
1067
|
-
await bundler.scan();
|
|
1068
|
-
await stopWorkers?.();
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
|
-
//#endregion
|
|
1072
|
-
exports.aliasPlugin = aliasPlugin;
|
|
1073
|
-
exports.buildImportAnalysisPlugin = buildImportAnalysisPlugin;
|
|
1074
|
-
exports.composeJsPlugins = composeJsPlugins;
|
|
1075
|
-
exports.dynamicImportVarsPlugin = dynamicImportVarsPlugin;
|
|
1076
|
-
exports.experimental_scan = experimental_scan;
|
|
1077
|
-
exports.importGlobPlugin = importGlobPlugin;
|
|
1078
|
-
exports.jsonPlugin = jsonPlugin;
|
|
1079
|
-
exports.loadFallbackPlugin = loadFallbackPlugin;
|
|
1080
|
-
exports.manifestPlugin = manifestPlugin;
|
|
1081
|
-
exports.modulePreloadPolyfillPlugin = modulePreloadPolyfillPlugin;
|
|
1082
|
-
exports.replacePlugin = replacePlugin;
|
|
1083
|
-
exports.rolldown = rolldown;
|
|
1084
|
-
exports.transformPlugin = transformPlugin;
|
|
1085
|
-
exports.wasmFallbackPlugin = wasmFallbackPlugin;
|
|
1086
|
-
exports.wasmHelperPlugin = wasmHelperPlugin;
|
|
1087
|
-
|