rolldown 0.10.4 → 0.10.5
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 +8 -8
- package/dist/cjs/index.cjs +3 -2
- package/dist/cjs/parallel-plugin-worker.cjs +1 -1
- package/dist/esm/cli.mjs +8 -8
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{utils_index-ywWHgCJG.mjs → bindingify_plugin-gPrr_HPR.mjs} +474 -827
- package/dist/shared/{utils_index-D-jBnBMP.cjs → bindingify_plugin-sRZqfDBJ.cjs} +484 -827
- package/dist/shared/rolldown-1SJPa4fg.cjs +547 -0
- package/dist/shared/rolldown-bgokD9pg.mjs +544 -0
- package/dist/shared/rolldown-binding.wasi.cjs +46 -25
- package/dist/types/binding.d.ts +256 -0
- package/dist/types/index.d.ts +21 -7
- package/dist/types/options/bindingify-input-options.d.ts +1 -1
- package/dist/types/options/bindingify-output-options.d.ts +1 -0
- package/dist/types/options/input-options.d.ts +31 -6
- package/dist/types/options/normalized-input-options.d.ts +4 -2
- package/dist/types/options/normalized-output-options.d.ts +2 -1
- package/dist/types/options/output-options.d.ts +10 -5
- package/dist/types/plugin/bindingify-builtin-plugin.d.ts +10 -0
- package/dist/types/plugin/bindingify-output-hooks.d.ts +1 -1
- package/dist/types/plugin/bindingify-plugin.d.ts +1 -1
- package/dist/types/plugin/index.d.ts +49 -29
- package/dist/types/plugin/plugin-context.d.ts +14 -0
- package/dist/types/plugin/plugin-driver.d.ts +5 -1
- package/dist/types/plugin/transfrom-plugin-context.d.ts +9 -5
- package/dist/types/rollup.d.ts +1113 -0
- package/dist/types/treeshake/index.d.ts +14 -0
- package/dist/types/treeshake/module-side-effects.d.ts +15 -0
- package/dist/types/types/rolldown-output.d.ts +3 -1
- package/dist/types/types/sourcemap.d.ts +7 -4
- package/dist/types/types/utils.d.ts +3 -0
- package/dist/types/utils/asset-source.d.ts +4 -0
- package/dist/types/utils/index.d.ts +1 -5
- package/dist/types/utils/initialize-parallel-plugins.d.ts +2 -1
- package/dist/types/utils/misc.d.ts +5 -0
- package/dist/types/utils/normalize-hook.d.ts +2 -2
- package/dist/types/utils/normalize-output-options.d.ts +2 -2
- package/dist/types/utils/normalize-plugin-option.d.ts +2 -2
- package/dist/types/utils/normalize-tree-shake.d.ts +3 -0
- package/dist/types/utils/transform-side-effects.d.ts +1 -1
- package/package.json +20 -21
- package/dist/shared/rolldown-ftFKbC6A.mjs +0 -51
- package/dist/shared/rolldown-l_Cw2GW3.cjs +0 -52
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { __toESM } = require("./chunk-eib2uzZZ.cjs");
|
|
4
|
+
const { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARN, arraify, bindingifyPlugin, error, getLogHandler, logLevelPriority, logPluginError, normalizeHook, normalizeLog, require_binding, transformToRollupOutput, unimplemented } = require("./bindingify_plugin-sRZqfDBJ.cjs");
|
|
5
|
+
const { default: nodePath, default: path } = __toESM(require("node:path"));
|
|
6
|
+
const { Worker } = __toESM(require("node:worker_threads"));
|
|
7
|
+
const { availableParallelism } = __toESM(require("node:os"));
|
|
8
|
+
const { isRegExp } = __toESM(require("node:util/types"));
|
|
9
|
+
|
|
10
|
+
//#region src/utils/async-flatten.ts
|
|
11
|
+
async function asyncFlatten(array) {
|
|
12
|
+
do {
|
|
13
|
+
array = (await Promise.all(array)).flat(Infinity);
|
|
14
|
+
}while(array.some(v => v?.then));
|
|
15
|
+
return array;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/normalize-plugin-option.ts
|
|
20
|
+
const normalizePluginOption = async plugins => (await asyncFlatten([plugins])).filter(Boolean);
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/plugin/bindingify-builtin-plugin.ts
|
|
24
|
+
var import_binding$3 = __toESM(require_binding());
|
|
25
|
+
class BuiltinPlugin {
|
|
26
|
+
constructor(name, options){
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.name = name;
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class BuiltinWasmPlugin extends BuiltinPlugin {
|
|
34
|
+
constructor(options){
|
|
35
|
+
super(import_binding$3.BindingBuiltinPluginName.WasmPlugin, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function bindingifyBuiltInPlugin(plugin) {
|
|
39
|
+
return {
|
|
40
|
+
name:plugin.name,
|
|
41
|
+
options:plugin.options
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/options/bindingify-input-options.ts
|
|
47
|
+
var import_binding$2 = __toESM(require_binding());
|
|
48
|
+
function bindingifyInputOptions(options, outputOptions) {
|
|
49
|
+
return {
|
|
50
|
+
input:bindingifyInput(options.input),
|
|
51
|
+
plugins:options.plugins.map(plugin => {
|
|
52
|
+
if ('_parallel'in plugin) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (plugin instanceof BuiltinPlugin) {
|
|
56
|
+
return bindingifyBuiltInPlugin(plugin);
|
|
57
|
+
}
|
|
58
|
+
return bindingifyPlugin(plugin, options, outputOptions);
|
|
59
|
+
}),
|
|
60
|
+
cwd:options.cwd ?? process.cwd(),
|
|
61
|
+
external:options.external ? function bindingifyExternal() {
|
|
62
|
+
const external = options.external;
|
|
63
|
+
if (typeof external === 'function') {
|
|
64
|
+
return (id, importer, isResolved) => {
|
|
65
|
+
if (id.startsWith('\0')) return false;
|
|
66
|
+
|
|
67
|
+
return external(id, importer, isResolved) ?? false;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const externalArr = arraify(external);
|
|
71
|
+
return (id, _importer, _isResolved) => {
|
|
72
|
+
return externalArr.some(pat => {
|
|
73
|
+
if (pat instanceof RegExp) {
|
|
74
|
+
return pat.test(id);
|
|
75
|
+
}
|
|
76
|
+
return id === pat;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}() : undefined,
|
|
80
|
+
resolve:options.resolve ? function bindingifyResolve() {
|
|
81
|
+
const {alias,...rest} = options.resolve;
|
|
82
|
+
return {
|
|
83
|
+
alias:alias ? Object.entries(alias).map(([name,replacement]) => ({
|
|
84
|
+
find:name,
|
|
85
|
+
replacements:[replacement]
|
|
86
|
+
})) : undefined,
|
|
87
|
+
...rest
|
|
88
|
+
};
|
|
89
|
+
}() : undefined,
|
|
90
|
+
platform:options.platform,
|
|
91
|
+
shimMissingExports:options.shimMissingExports,
|
|
92
|
+
logLevel:bindingifyLogLevel(options.logLevel),
|
|
93
|
+
onLog:(level, log) => {
|
|
94
|
+
options.onLog(level, {
|
|
95
|
+
code:log.code,
|
|
96
|
+
message:log.message
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
treeshake:options.treeshake,
|
|
100
|
+
moduleTypes:options.moduleTypes
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function bindingifyLogLevel(logLevel) {
|
|
104
|
+
switch(logLevel){
|
|
105
|
+
case 'silent':
|
|
106
|
+
return import_binding$2.BindingLogLevel.Silent;
|
|
107
|
+
case 'warn':
|
|
108
|
+
return import_binding$2.BindingLogLevel.Warn;
|
|
109
|
+
case 'info':
|
|
110
|
+
return import_binding$2.BindingLogLevel.Info;
|
|
111
|
+
case 'debug':
|
|
112
|
+
return import_binding$2.BindingLogLevel.Debug;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unexpected log level: ${logLevel}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function bindingifyInput(input) {
|
|
118
|
+
if (Array.isArray(input)) {
|
|
119
|
+
return input.map(src => {
|
|
120
|
+
const name = nodePath.parse(src).name;
|
|
121
|
+
return {
|
|
122
|
+
name,
|
|
123
|
+
import:src
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
return Object.entries(input).map(value => {
|
|
128
|
+
return {
|
|
129
|
+
name:value[0],
|
|
130
|
+
import:value[1]
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/initialize-parallel-plugins.ts
|
|
138
|
+
var import_binding$1 = __toESM(require_binding());
|
|
139
|
+
async function initializeParallelPlugins(plugins) {
|
|
140
|
+
const pluginInfos = [];
|
|
141
|
+
for (const [index,plugin] of plugins.entries()) {
|
|
142
|
+
if ('_parallel'in plugin) {
|
|
143
|
+
const {fileUrl, options} = plugin._parallel;
|
|
144
|
+
pluginInfos.push({
|
|
145
|
+
index,
|
|
146
|
+
fileUrl,
|
|
147
|
+
options
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (pluginInfos.length <= 0) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const count = Math.min(availableParallelism(), 8);
|
|
155
|
+
const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
|
|
156
|
+
const registryId = parallelJsPluginRegistry.id;
|
|
157
|
+
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
158
|
+
const stopWorkers = async() => {
|
|
159
|
+
await Promise.all(workers.map(worker => worker.terminate()));
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
registry:parallelJsPluginRegistry,
|
|
163
|
+
stopWorkers
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function initializeWorkers(registryId, count, pluginInfos) {
|
|
167
|
+
return Promise.all(Array.from({
|
|
168
|
+
length:count
|
|
169
|
+
}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
170
|
+
}
|
|
171
|
+
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
172
|
+
const urlString = undefined('#parallel-plugin-worker');
|
|
173
|
+
const workerData = {
|
|
174
|
+
registryId,
|
|
175
|
+
pluginInfos,
|
|
176
|
+
threadNumber
|
|
177
|
+
};
|
|
178
|
+
let worker;
|
|
179
|
+
try{
|
|
180
|
+
worker = new Worker(new URL(urlString), {
|
|
181
|
+
workerData
|
|
182
|
+
});
|
|
183
|
+
worker.unref();
|
|
184
|
+
await new Promise((resolve, reject) => {
|
|
185
|
+
worker.once('message', async message => {
|
|
186
|
+
if (message.type === 'error') {
|
|
187
|
+
reject(message.error);
|
|
188
|
+
} else {
|
|
189
|
+
resolve();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
return worker;
|
|
194
|
+
}catch(e){
|
|
195
|
+
worker?.terminate();
|
|
196
|
+
throw e;
|
|
197
|
+
}}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/log/logger.ts
|
|
201
|
+
function getLogger(plugins, onLog, logLevel) {
|
|
202
|
+
const minimalPriority = logLevelPriority[logLevel];
|
|
203
|
+
const logger = (level, log, skipped=new Set()) => {
|
|
204
|
+
const logPriority = logLevelPriority[level];
|
|
205
|
+
if (logPriority < minimalPriority) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
for (const plugin of plugins) {
|
|
209
|
+
if (skipped.has(plugin)) continue;
|
|
210
|
+
|
|
211
|
+
const {onLog:pluginOnLog} = plugin;
|
|
212
|
+
if (pluginOnLog) {
|
|
213
|
+
const getLogHandler$1 = level$1 => {
|
|
214
|
+
if (logLevelPriority[level$1] < minimalPriority) {
|
|
215
|
+
return () => {
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return log$1 => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
|
|
219
|
+
};
|
|
220
|
+
const handler = 'handler'in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
|
|
221
|
+
if (handler.call({
|
|
222
|
+
debug:getLogHandler$1(LOG_LEVEL_DEBUG),
|
|
223
|
+
error:log$1 => error(normalizeLog(log$1)),
|
|
224
|
+
info:getLogHandler$1(LOG_LEVEL_INFO),
|
|
225
|
+
warn:getLogHandler$1(LOG_LEVEL_WARN)
|
|
226
|
+
}, level, log) === false) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
onLog(level, log);
|
|
232
|
+
};
|
|
233
|
+
return logger;
|
|
234
|
+
}
|
|
235
|
+
const getOnLog = (config, logLevel, printLog=defaultPrintLog) => {
|
|
236
|
+
const {onwarn, onLog} = config;
|
|
237
|
+
const defaultOnLog = getDefaultOnLog(printLog, onwarn);
|
|
238
|
+
if (onLog) {
|
|
239
|
+
const minimalPriority = logLevelPriority[logLevel];
|
|
240
|
+
return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
|
|
241
|
+
if (level$1 === LOG_LEVEL_ERROR) {
|
|
242
|
+
return error(normalizeLog(handledLog));
|
|
243
|
+
}
|
|
244
|
+
if (logLevelPriority[level$1] >= minimalPriority) {
|
|
245
|
+
defaultOnLog(level$1, normalizeLog(handledLog));
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return defaultOnLog;
|
|
250
|
+
};
|
|
251
|
+
const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
|
|
252
|
+
if (level === LOG_LEVEL_WARN) {
|
|
253
|
+
onwarn(addLogToString(log), warning => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
|
|
254
|
+
} else {
|
|
255
|
+
printLog(level, log);
|
|
256
|
+
}
|
|
257
|
+
} : printLog;
|
|
258
|
+
const addLogToString = log => {
|
|
259
|
+
Object.defineProperty(log, 'toString', {
|
|
260
|
+
value:() => getExtendedLogMessage(log),
|
|
261
|
+
writable:true
|
|
262
|
+
});
|
|
263
|
+
return log;
|
|
264
|
+
};
|
|
265
|
+
const defaultPrintLog = (level, log) => {
|
|
266
|
+
const message = getExtendedLogMessage(log);
|
|
267
|
+
switch(level){
|
|
268
|
+
case LOG_LEVEL_WARN:
|
|
269
|
+
{
|
|
270
|
+
return console.warn(message);
|
|
271
|
+
}
|
|
272
|
+
case LOG_LEVEL_DEBUG:
|
|
273
|
+
{
|
|
274
|
+
return console.debug(message);
|
|
275
|
+
}
|
|
276
|
+
default:
|
|
277
|
+
{
|
|
278
|
+
return console.info(message);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const getExtendedLogMessage = log => {
|
|
283
|
+
let prefix = '';
|
|
284
|
+
if (log.plugin) {
|
|
285
|
+
prefix += `(${log.plugin} plugin) `;
|
|
286
|
+
}
|
|
287
|
+
if (log.loc) {
|
|
288
|
+
prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
|
|
289
|
+
}
|
|
290
|
+
return prefix + log.message;
|
|
291
|
+
};
|
|
292
|
+
function relativeId(id) {
|
|
293
|
+
if ( !path.isAbsolute(id)) return id;
|
|
294
|
+
|
|
295
|
+
return path.relative(path.resolve(), id);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/plugin/plugin-driver.ts
|
|
300
|
+
class PluginDriver {
|
|
301
|
+
async callOptionsHook(inputOptions){
|
|
302
|
+
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
303
|
+
const plugins = getObjectPlugins(inputOptions.plugins ?? []);
|
|
304
|
+
const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
|
|
305
|
+
for (const plugin of plugins) {
|
|
306
|
+
const name = plugin.name || 'unknown';
|
|
307
|
+
const options = plugin.options;
|
|
308
|
+
if (options) {
|
|
309
|
+
const [handler,_optionsIgnoredSofar] = normalizeHook(options);
|
|
310
|
+
const result = await handler.call({
|
|
311
|
+
debug:getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
|
|
312
|
+
error:e => error(logPluginError(normalizeLog(e), name, {
|
|
313
|
+
hook:'onLog'
|
|
314
|
+
})),
|
|
315
|
+
info:getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
|
|
316
|
+
warn:getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel)
|
|
317
|
+
}, inputOptions);
|
|
318
|
+
if (result) {
|
|
319
|
+
inputOptions = result;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return inputOptions;
|
|
324
|
+
}
|
|
325
|
+
async callOutputOptionsHook(inputOptions, outputOptions){
|
|
326
|
+
const plugins = getObjectPlugins(inputOptions.plugins);
|
|
327
|
+
for (const plugin of plugins) {
|
|
328
|
+
const options = plugin.outputOptions;
|
|
329
|
+
if (options) {
|
|
330
|
+
const [handler,_optionsIgnoredSofar] = normalizeHook(options);
|
|
331
|
+
const result = await handler.call(null, outputOptions);
|
|
332
|
+
if (result) {
|
|
333
|
+
outputOptions = result;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return outputOptions;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function getObjectPlugins(plugins) {
|
|
341
|
+
return plugins.filter(plugin => {
|
|
342
|
+
if ('_parallel'in plugin) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
if (plugin instanceof BuiltinPlugin) {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
return plugin;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/utils/normalize-tree-shake.ts
|
|
354
|
+
function normalizeTreeshakeOptions(config) {
|
|
355
|
+
if (config === false) {
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
if (config === true || config === undefined) {
|
|
359
|
+
return {
|
|
360
|
+
moduleSideEffects:'true'
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
if (config.moduleSideEffects === undefined) {
|
|
364
|
+
config.moduleSideEffects = 'true';
|
|
365
|
+
} else if (isRegExp(config.moduleSideEffects)) {
|
|
366
|
+
config.moduleSideEffects = config.moduleSideEffects.source;
|
|
367
|
+
} else {
|
|
368
|
+
config.moduleSideEffects = config.moduleSideEffects.toString();
|
|
369
|
+
}
|
|
370
|
+
return config;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/utils/normalize-input-options.ts
|
|
375
|
+
async function normalizeInputOptions(config) {
|
|
376
|
+
const {input,...rest} = config;
|
|
377
|
+
const plugins = await normalizePluginOption(config.plugins);
|
|
378
|
+
const treeshake = normalizeTreeshakeOptions(config.treeshake);
|
|
379
|
+
const logLevel = config.logLevel || LOG_LEVEL_INFO;
|
|
380
|
+
const onLog = getLogger(getObjectPlugins(plugins), getOnLog(config, logLevel), logLevel);
|
|
381
|
+
return {
|
|
382
|
+
...rest,
|
|
383
|
+
input:input ? typeof input === 'string' ? [input] : input : [],
|
|
384
|
+
plugins,
|
|
385
|
+
logLevel,
|
|
386
|
+
onLog,
|
|
387
|
+
treeshake
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/utils/normalize-output-options.ts
|
|
393
|
+
function normalizeOutputOptions(opts) {
|
|
394
|
+
const {dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, entryFileNames, chunkFileNames, assetFileNames} = opts;
|
|
395
|
+
return {
|
|
396
|
+
dir:dir,
|
|
397
|
+
format:getFormat(format),
|
|
398
|
+
exports:exports ?? 'named',
|
|
399
|
+
sourcemap:sourcemap ?? false,
|
|
400
|
+
sourcemapIgnoreList:typeof sourcemapIgnoreList === 'function' ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, sourcemapPath) => relativeSourcePath.includes('node_modules'),
|
|
401
|
+
sourcemapPathTransform,
|
|
402
|
+
banner:getAddon(opts, 'banner'),
|
|
403
|
+
footer:getAddon(opts, 'footer'),
|
|
404
|
+
entryFileNames:entryFileNames ?? '[name].js',
|
|
405
|
+
chunkFileNames:chunkFileNames ?? '[name]-[hash].js',
|
|
406
|
+
assetFileNames:assetFileNames ?? 'assets/[name]-[hash][extname]',
|
|
407
|
+
plugins:[]
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function getFormat(format) {
|
|
411
|
+
switch(format){
|
|
412
|
+
case undefined:
|
|
413
|
+
case 'es':
|
|
414
|
+
case 'esm':
|
|
415
|
+
case 'module':
|
|
416
|
+
{
|
|
417
|
+
return 'es';
|
|
418
|
+
}
|
|
419
|
+
case 'cjs':
|
|
420
|
+
case 'commonjs':
|
|
421
|
+
{
|
|
422
|
+
return 'cjs';
|
|
423
|
+
}
|
|
424
|
+
default:
|
|
425
|
+
unimplemented(`output.format: ${format}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const getAddon = (config, name) => {
|
|
429
|
+
const configAddon = config[name];
|
|
430
|
+
if (typeof configAddon === 'function') {
|
|
431
|
+
return configAddon;
|
|
432
|
+
}
|
|
433
|
+
return async() => configAddon || '';
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/options/bindingify-output-options.ts
|
|
438
|
+
function bindingifyOutputOptions(outputOptions) {
|
|
439
|
+
const {dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, entryFileNames, chunkFileNames, assetFileNames, banner, footer} = outputOptions;
|
|
440
|
+
return {
|
|
441
|
+
dir,
|
|
442
|
+
format:function() {
|
|
443
|
+
switch(format){
|
|
444
|
+
case 'es':
|
|
445
|
+
return 'es';
|
|
446
|
+
case 'cjs':
|
|
447
|
+
return 'cjs';
|
|
448
|
+
}
|
|
449
|
+
}(),
|
|
450
|
+
exports,
|
|
451
|
+
sourcemap:bindingifySourcemap(sourcemap),
|
|
452
|
+
sourcemapIgnoreList,
|
|
453
|
+
sourcemapPathTransform,
|
|
454
|
+
banner,
|
|
455
|
+
footer,
|
|
456
|
+
entryFileNames,
|
|
457
|
+
chunkFileNames,
|
|
458
|
+
assetFileNames,
|
|
459
|
+
plugins:[]
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function bindingifySourcemap(sourcemap) {
|
|
463
|
+
switch(sourcemap){
|
|
464
|
+
case true:
|
|
465
|
+
return 'file';
|
|
466
|
+
case 'inline':
|
|
467
|
+
return 'inline';
|
|
468
|
+
case false:
|
|
469
|
+
case undefined:
|
|
470
|
+
case 'hidden':
|
|
471
|
+
return 'hidden';
|
|
472
|
+
default:
|
|
473
|
+
throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/utils/create-bundler.ts
|
|
479
|
+
var import_binding = __toESM(require_binding());
|
|
480
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
481
|
+
const pluginDriver = new PluginDriver();
|
|
482
|
+
inputOptions = await pluginDriver.callOptionsHook(inputOptions);
|
|
483
|
+
const normalizedInputOptions = await normalizeInputOptions(inputOptions);
|
|
484
|
+
const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
|
|
485
|
+
try{
|
|
486
|
+
outputOptions = await pluginDriver.callOutputOptionsHook(normalizedInputOptions, outputOptions);
|
|
487
|
+
const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
|
|
488
|
+
const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
|
|
489
|
+
return {
|
|
490
|
+
bundler:new import_binding.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
|
|
491
|
+
stopWorkers:parallelPluginInitResult?.stopWorkers
|
|
492
|
+
};
|
|
493
|
+
}catch(e){
|
|
494
|
+
await parallelPluginInitResult?.stopWorkers();
|
|
495
|
+
throw e;
|
|
496
|
+
}}
|
|
497
|
+
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/rolldown-build.ts
|
|
500
|
+
class RolldownBuild {
|
|
501
|
+
#inputOptions;
|
|
502
|
+
|
|
503
|
+
#bundler;
|
|
504
|
+
|
|
505
|
+
#stopWorkers;
|
|
506
|
+
|
|
507
|
+
constructor(inputOptions){
|
|
508
|
+
this.#inputOptions = inputOptions;
|
|
509
|
+
}
|
|
510
|
+
async #getBundler(outputOptions){
|
|
511
|
+
if (typeof this.#bundler === 'undefined') {
|
|
512
|
+
const {bundler, stopWorkers} = await createBundler(this.#inputOptions, outputOptions);
|
|
513
|
+
this.#bundler = bundler;
|
|
514
|
+
this.#stopWorkers = stopWorkers;
|
|
515
|
+
}
|
|
516
|
+
return this.#bundler;
|
|
517
|
+
}
|
|
518
|
+
async generate(outputOptions={}){
|
|
519
|
+
const bundler = await this.#getBundler(outputOptions);
|
|
520
|
+
const output = await bundler.generate();
|
|
521
|
+
return transformToRollupOutput(output);
|
|
522
|
+
}
|
|
523
|
+
async write(outputOptions={}){
|
|
524
|
+
const bundler = await this.#getBundler(outputOptions);
|
|
525
|
+
const output = await bundler.write();
|
|
526
|
+
return transformToRollupOutput(output);
|
|
527
|
+
}
|
|
528
|
+
async destroy(){
|
|
529
|
+
await this.#stopWorkers?.();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/rolldown.ts
|
|
535
|
+
const rolldown = async input => {
|
|
536
|
+
return new RolldownBuild(input);
|
|
537
|
+
};
|
|
538
|
+
const experimental_scan = async input => {
|
|
539
|
+
const {bundler, stopWorkers} = await createBundler(input, {});
|
|
540
|
+
await bundler.scan();
|
|
541
|
+
await stopWorkers?.();
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
//#endregion
|
|
545
|
+
exports.BuiltinWasmPlugin = BuiltinWasmPlugin;
|
|
546
|
+
exports.experimental_scan = experimental_scan;
|
|
547
|
+
exports.rolldown = rolldown;
|