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
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const { __commonJSMin, __toESM } = require("./chunk-eib2uzZZ.cjs");
|
|
2
|
-
const { default:
|
|
2
|
+
const { default: path } = __toESM(require("node:path"));
|
|
3
3
|
const { z } = __toESM(require("zod"));
|
|
4
|
-
const { Worker } = __toESM(require("node:worker_threads"));
|
|
5
|
-
const { availableParallelism } = __toESM(require("node:os"));
|
|
6
4
|
|
|
7
|
-
//#region src/utils/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
5
|
+
//#region src/utils/asset-source.ts
|
|
6
|
+
function transformAssetSource(bindingAssetSource$1) {
|
|
7
|
+
return bindingAssetSource$1.inner;
|
|
8
|
+
}
|
|
9
|
+
function bindingAssetSource(source) {
|
|
10
|
+
return {
|
|
11
|
+
inner:source
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
//#endregion
|
|
@@ -24,6 +24,7 @@ function transformToRollupOutputChunk(chunk) {
|
|
|
24
24
|
chunk.code = code;
|
|
25
25
|
},
|
|
26
26
|
fileName:chunk.fileName,
|
|
27
|
+
name:chunk.name,
|
|
27
28
|
get modules(){
|
|
28
29
|
return Object.fromEntries(Object.entries(chunk.modules).map(([key,_]) => [key, {}]));
|
|
29
30
|
},
|
|
@@ -58,10 +59,10 @@ function transformToRollupOutputAsset(asset) {
|
|
|
58
59
|
type:'asset',
|
|
59
60
|
fileName:asset.fileName,
|
|
60
61
|
get source(){
|
|
61
|
-
return asset.source;
|
|
62
|
+
return transformAssetSource(asset.source);
|
|
62
63
|
},
|
|
63
64
|
set source(source){
|
|
64
|
-
asset.source = source;
|
|
65
|
+
asset.source = bindingAssetSource(source);
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
}
|
|
@@ -69,7 +70,7 @@ function transformToRollupOutput(output) {
|
|
|
69
70
|
const {chunks, assets} = output;
|
|
70
71
|
const [firstChunk,...restChunks] = chunks;
|
|
71
72
|
return {
|
|
72
|
-
output:[transformToRollupOutputChunk(firstChunk), ...restChunks.map(transformToRollupOutputChunk), ...assets.map(transformToRollupOutputAsset)]
|
|
73
|
+
output:[transformToRollupOutputChunk(firstChunk), ...restChunks.map(transformToRollupOutputChunk), ...assets.map(transformToRollupOutputAsset),]
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
function transformToOutputBundle(output) {
|
|
@@ -85,353 +86,45 @@ function transformToOutputBundle(output) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
//#endregion
|
|
88
|
-
//#region src/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//#region src/utils/transform-sourcemap.ts
|
|
103
|
-
function isEmptySourcemapFiled(array) {
|
|
104
|
-
if ( !array) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
if (array.length === 0 || !array[0]) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/utils/transform-module-info.ts
|
|
115
|
-
function transformModuleInfo(info) {
|
|
116
|
-
return {
|
|
117
|
-
get ast(){
|
|
118
|
-
return unsupported('ModuleInfo#ast');
|
|
119
|
-
},
|
|
120
|
-
get code(){
|
|
121
|
-
return info.code;
|
|
122
|
-
},
|
|
123
|
-
id:info.id,
|
|
124
|
-
importers:info.importers,
|
|
125
|
-
dynamicImporters:info.dynamicImporters,
|
|
126
|
-
importedIds:info.importedIds,
|
|
127
|
-
dynamicallyImportedIds:info.dynamicallyImportedIds,
|
|
128
|
-
isEntry:info.isEntry
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/log/logging.ts
|
|
134
|
-
const LogLevelSchema = z.literal('info').or(z.literal('debug')).or(z.literal('warn'));
|
|
135
|
-
const LogLevelWithErrorSchema = LogLevelSchema.or(z.literal('error'));
|
|
136
|
-
const LogLevelOptionSchema = LogLevelSchema.or(z.literal('silent'));
|
|
137
|
-
const LOG_LEVEL_SILENT = 'silent';
|
|
138
|
-
const LOG_LEVEL_ERROR = 'error';
|
|
139
|
-
const LOG_LEVEL_WARN = 'warn';
|
|
140
|
-
const LOG_LEVEL_INFO = 'info';
|
|
141
|
-
const LOG_LEVEL_DEBUG = 'debug';
|
|
142
|
-
const logLevelPriority = {
|
|
143
|
-
[LOG_LEVEL_DEBUG]:0,
|
|
144
|
-
[LOG_LEVEL_INFO]:1,
|
|
145
|
-
[LOG_LEVEL_WARN]:2,
|
|
146
|
-
[LOG_LEVEL_SILENT]:3
|
|
147
|
-
};
|
|
148
|
-
const RollupLogSchema = z.any();
|
|
149
|
-
const RollupLogWithStringSchema = RollupLogSchema.or(z.string());
|
|
150
|
-
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region src/utils/code-frame.ts
|
|
153
|
-
function spaces(index) {
|
|
154
|
-
let result = '';
|
|
155
|
-
while(index--) result += ' ';
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
function tabsToSpaces(value) {
|
|
159
|
-
return value.replace(/^\t+/, match => match.split('\t').join(' '));
|
|
160
|
-
}
|
|
161
|
-
const LINE_TRUNCATE_LENGTH = 120;
|
|
162
|
-
const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
|
|
163
|
-
const ELLIPSIS = '...';
|
|
164
|
-
function getCodeFrame(source, line, column) {
|
|
165
|
-
let lines = source.split('\n');
|
|
166
|
-
if (line > lines.length) return '';
|
|
167
|
-
|
|
168
|
-
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
|
|
169
|
-
const frameStart = Math.max(0, line - 3);
|
|
170
|
-
let frameEnd = Math.min(line + 2, lines.length);
|
|
171
|
-
lines = lines.slice(frameStart, frameEnd);
|
|
172
|
-
while( !/\S/.test(lines[lines.length - 1])) {
|
|
173
|
-
lines.pop();
|
|
174
|
-
frameEnd -= 1;
|
|
175
|
-
}
|
|
176
|
-
const digits = String(frameEnd).length;
|
|
177
|
-
return lines.map((sourceLine, index) => {
|
|
178
|
-
const isErrorLine = frameStart + index + 1 === line;
|
|
179
|
-
let lineNumber = String(index + frameStart + 1);
|
|
180
|
-
while(lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
181
|
-
let displayedLine = tabsToSpaces(sourceLine);
|
|
182
|
-
if (displayedLine.length > maxLineLength) {
|
|
183
|
-
displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
184
|
-
}
|
|
185
|
-
if (isErrorLine) {
|
|
186
|
-
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + '^';
|
|
187
|
-
return `${lineNumber}: ${displayedLine}
|
|
188
|
-
${indicator}`;
|
|
189
|
-
}
|
|
190
|
-
return `${lineNumber}: ${displayedLine}`;
|
|
191
|
-
}).join('\n');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region ../../node_modules/.pnpm/locate-character@3.0.0/node_modules/locate-character/src/index.js
|
|
196
|
-
function rangeContains(range, index) {
|
|
197
|
-
return range.start <= index && index < range.end;
|
|
198
|
-
}
|
|
199
|
-
function getLocator(source, options={}) {
|
|
200
|
-
const {offsetLine=0, offsetColumn=0} = options;
|
|
201
|
-
let start = 0;
|
|
202
|
-
const ranges = source.split('\n').map((line, i$1) => {
|
|
203
|
-
const end = start + line.length + 1;
|
|
204
|
-
const range = {
|
|
205
|
-
start,
|
|
206
|
-
end,
|
|
207
|
-
line:i$1
|
|
208
|
-
};
|
|
209
|
-
start = end;
|
|
210
|
-
return range;
|
|
211
|
-
});
|
|
212
|
-
let i = 0;
|
|
213
|
-
function locator(search, index) {
|
|
214
|
-
if (typeof search === 'string') {
|
|
215
|
-
search = source.indexOf(search, index ?? 0);
|
|
216
|
-
}
|
|
217
|
-
if (search === -1) return undefined;
|
|
218
|
-
|
|
219
|
-
let range = ranges[i];
|
|
220
|
-
const d = search >= range.end ? 1 : -1;
|
|
221
|
-
while(range) {
|
|
222
|
-
if (rangeContains(range, search)) {
|
|
223
|
-
return {
|
|
224
|
-
line:offsetLine + range.line,
|
|
225
|
-
column:offsetColumn + search - range.start,
|
|
226
|
-
character:search
|
|
227
|
-
};
|
|
89
|
+
//#region src/binding.js
|
|
90
|
+
var require_binding = __commonJSMin((exports, module) => {
|
|
91
|
+
const {readFileSync} = require('node:fs');
|
|
92
|
+
let nativeBinding = null;
|
|
93
|
+
const loadErrors = [];
|
|
94
|
+
const isMusl = () => {
|
|
95
|
+
let musl = false;
|
|
96
|
+
if (process.platform === 'linux') {
|
|
97
|
+
musl = isMuslFromFilesystem();
|
|
98
|
+
if (musl === null) {
|
|
99
|
+
musl = isMuslFromReport();
|
|
100
|
+
}
|
|
101
|
+
if (musl === null) {
|
|
102
|
+
musl = isMuslFromChildProcess();
|
|
228
103
|
}
|
|
229
|
-
i += d;
|
|
230
|
-
range = ranges[i];
|
|
231
104
|
}
|
|
232
|
-
|
|
233
|
-
return locator;
|
|
234
|
-
}
|
|
235
|
-
function locate(source, search, options) {
|
|
236
|
-
return getLocator(source, options)(search, options && options.startIndex);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/log/logs.ts
|
|
241
|
-
const INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', PLUGIN_ERROR = 'PLUGIN_ERROR';
|
|
242
|
-
function logInvalidLogPosition(pluginName) {
|
|
243
|
-
return {
|
|
244
|
-
code:INVALID_LOG_POSITION,
|
|
245
|
-
message:`Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
|
|
105
|
+
return musl;
|
|
246
106
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (id) {
|
|
259
|
-
error2.id = id;
|
|
260
|
-
}
|
|
261
|
-
return error2;
|
|
262
|
-
}
|
|
263
|
-
function error(base) {
|
|
264
|
-
if ( !(base instanceof Error)) {
|
|
265
|
-
base = Object.assign(new Error(base.message), base);
|
|
266
|
-
Object.defineProperty(base, 'name', {
|
|
267
|
-
value:'RollupError',
|
|
268
|
-
writable:true
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
throw base;
|
|
272
|
-
}
|
|
273
|
-
function augmentCodeLocation(properties, pos, source, id) {
|
|
274
|
-
if (typeof pos === 'object') {
|
|
275
|
-
const {line, column} = pos;
|
|
276
|
-
properties.loc = {
|
|
277
|
-
column,
|
|
278
|
-
file:id,
|
|
279
|
-
line
|
|
280
|
-
};
|
|
281
|
-
} else {
|
|
282
|
-
properties.pos = pos;
|
|
283
|
-
const location = locate(source, pos, {
|
|
284
|
-
offsetLine:1
|
|
285
|
-
});
|
|
286
|
-
if ( !location) {
|
|
287
|
-
return;
|
|
107
|
+
const isFileMusl = f => f.includes('libc.musl-') || f.includes('ld-musl-');
|
|
108
|
+
const isMuslFromFilesystem = () => {
|
|
109
|
+
try{
|
|
110
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl');
|
|
111
|
+
}catch{
|
|
112
|
+
return null;
|
|
113
|
+
} };
|
|
114
|
+
const isMuslFromReport = () => {
|
|
115
|
+
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null;
|
|
116
|
+
if ( !report) {
|
|
117
|
+
return null;
|
|
288
118
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
column,
|
|
292
|
-
file:id,
|
|
293
|
-
line
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
if (properties.frame === void 0) {
|
|
297
|
-
const {line, column} = properties.loc;
|
|
298
|
-
properties.frame = getCodeFrame(source, line, column);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region src/log/logHandler.ts
|
|
304
|
-
const normalizeLog = log => typeof log === 'string' ? {
|
|
305
|
-
message:log
|
|
306
|
-
} : typeof log === 'function' ? normalizeLog(log()) : log;
|
|
307
|
-
function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
308
|
-
if (logLevelPriority[level] < logLevelPriority[logLevel]) {
|
|
309
|
-
return noop;
|
|
310
|
-
}
|
|
311
|
-
return (log, pos) => {
|
|
312
|
-
if (pos != null) {
|
|
313
|
-
logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
|
|
119
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
120
|
+
return false;
|
|
314
121
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
122
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
123
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
318
126
|
}
|
|
319
|
-
|
|
320
|
-
log.plugin = pluginName;
|
|
321
|
-
logger(level, log);
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
//#endregion
|
|
326
|
-
//#region src/plugin/plugin-context.ts
|
|
327
|
-
class PluginContext {
|
|
328
|
-
debug;
|
|
329
|
-
|
|
330
|
-
info;
|
|
331
|
-
|
|
332
|
-
warn;
|
|
333
|
-
|
|
334
|
-
error;
|
|
335
|
-
|
|
336
|
-
resolve;
|
|
337
|
-
|
|
338
|
-
constructor(options, context, plugin){
|
|
339
|
-
const onLog = options.onLog;
|
|
340
|
-
const pluginName = plugin.name || 'unknown';
|
|
341
|
-
const logLevel = options.logLevel;
|
|
342
|
-
this.debug = getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
343
|
-
this.warn = getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', onLog, pluginName, logLevel);
|
|
344
|
-
this.info = getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
345
|
-
this.error = e => {
|
|
346
|
-
return error(logPluginError(normalizeLog(e), pluginName));
|
|
347
|
-
};
|
|
348
|
-
this.resolve = context.resolve.bind(context);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
//#endregion
|
|
353
|
-
//#region src/plugin/transfrom-plugin-context.ts
|
|
354
|
-
class TransformPluginContext {
|
|
355
|
-
debug;
|
|
356
|
-
|
|
357
|
-
info;
|
|
358
|
-
|
|
359
|
-
warn;
|
|
360
|
-
|
|
361
|
-
error;
|
|
362
|
-
|
|
363
|
-
resolve;
|
|
364
|
-
|
|
365
|
-
getCombinedSourcemap;
|
|
366
|
-
|
|
367
|
-
constructor(inner, context, moduleId, moduleSource){
|
|
368
|
-
const getLogHandler$1 = handler => (log, pos) => {
|
|
369
|
-
log = normalizeLog(log);
|
|
370
|
-
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
371
|
-
|
|
372
|
-
log.id = moduleId;
|
|
373
|
-
log.hook = 'transform';
|
|
374
|
-
handler(log);
|
|
375
|
-
};
|
|
376
|
-
this.debug = getLogHandler$1(context.debug);
|
|
377
|
-
this.warn = getLogHandler$1(context.warn);
|
|
378
|
-
this.info = getLogHandler$1(context.info);
|
|
379
|
-
this.error = (error$1, pos) => {
|
|
380
|
-
if (typeof error$1 === 'string') error$1 = {
|
|
381
|
-
message:error$1
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
if (pos) augmentCodeLocation(error$1, pos, moduleSource, moduleId);
|
|
385
|
-
|
|
386
|
-
error$1.id = moduleId;
|
|
387
|
-
error$1.hook = 'transform';
|
|
388
|
-
return context.error(error$1);
|
|
389
|
-
};
|
|
390
|
-
this.resolve = context.resolve;
|
|
391
|
-
this.getCombinedSourcemap = () => JSON.parse(inner.getCombinedSourcemap());
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
//#endregion
|
|
396
|
-
//#region src/binding.js
|
|
397
|
-
var require_binding = __commonJSMin((exports, module) => {
|
|
398
|
-
const {readFileSync} = require('node:fs');
|
|
399
|
-
let nativeBinding = null;
|
|
400
|
-
const loadErrors = [];
|
|
401
|
-
const isMusl = () => {
|
|
402
|
-
let musl = false;
|
|
403
|
-
if (process.platform === 'linux') {
|
|
404
|
-
musl = isMuslFromFilesystem();
|
|
405
|
-
if (musl === null) {
|
|
406
|
-
musl = isMuslFromReport();
|
|
407
|
-
}
|
|
408
|
-
if (musl === null) {
|
|
409
|
-
musl = isMuslFromChildProcess();
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return musl;
|
|
413
|
-
};
|
|
414
|
-
const isFileMusl = f => f.includes('libc.musl-') || f.includes('ld-musl-');
|
|
415
|
-
const isMuslFromFilesystem = () => {
|
|
416
|
-
try{
|
|
417
|
-
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl');
|
|
418
|
-
}catch{
|
|
419
|
-
return null;
|
|
420
|
-
} };
|
|
421
|
-
const isMuslFromReport = () => {
|
|
422
|
-
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null;
|
|
423
|
-
if ( !report) {
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
|
-
if (report.header && report.header.glibcVersionRuntime) {
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
if (Array.isArray(report.sharedObjects)) {
|
|
430
|
-
if (report.sharedObjects.some(isFileMusl)) {
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return false;
|
|
127
|
+
return false;
|
|
435
128
|
};
|
|
436
129
|
const isMuslFromChildProcess = () => {
|
|
437
130
|
try{
|
|
@@ -653,60 +346,423 @@ var require_binding = __commonJSMin((exports, module) => {
|
|
|
653
346
|
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
|
|
654
347
|
}
|
|
655
348
|
}
|
|
656
|
-
nativeBinding = requireNative();
|
|
657
|
-
if ( !nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
658
|
-
try{
|
|
659
|
-
nativeBinding = require('./rolldown-binding.wasi.cjs');
|
|
660
|
-
}catch(err){
|
|
661
|
-
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
662
|
-
console.error(err);
|
|
349
|
+
nativeBinding = requireNative();
|
|
350
|
+
if ( !nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
351
|
+
try{
|
|
352
|
+
nativeBinding = require('./rolldown-binding.wasi.cjs');
|
|
353
|
+
}catch(err){
|
|
354
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
355
|
+
console.error(err);
|
|
356
|
+
}
|
|
357
|
+
} if ( !nativeBinding) {
|
|
358
|
+
try{
|
|
359
|
+
nativeBinding = require('@rolldown/binding-wasm32-wasi');
|
|
360
|
+
}catch(err){
|
|
361
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
362
|
+
console.error(err);
|
|
363
|
+
}
|
|
364
|
+
} }
|
|
365
|
+
}
|
|
366
|
+
if ( !nativeBinding) {
|
|
367
|
+
if (loadErrors.length > 0) {
|
|
368
|
+
throw new Error('Failed to load native binding', {
|
|
369
|
+
cause:loadErrors
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
throw new Error(`Failed to load native binding`);
|
|
373
|
+
}
|
|
374
|
+
module.exports.BindingLog = nativeBinding.BindingLog;
|
|
375
|
+
module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
|
|
376
|
+
module.exports.BindingOutputAsset = nativeBinding.BindingOutputAsset;
|
|
377
|
+
module.exports.BindingOutputChunk = nativeBinding.BindingOutputChunk;
|
|
378
|
+
module.exports.BindingOutputs = nativeBinding.BindingOutputs;
|
|
379
|
+
module.exports.BindingPluginContext = nativeBinding.BindingPluginContext;
|
|
380
|
+
module.exports.BindingTransformPluginContext = nativeBinding.BindingTransformPluginContext;
|
|
381
|
+
module.exports.Bundler = nativeBinding.Bundler;
|
|
382
|
+
module.exports.FinalBindingOutputs = nativeBinding.FinalBindingOutputs;
|
|
383
|
+
module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
|
|
384
|
+
module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
|
|
385
|
+
module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
|
|
386
|
+
module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
|
|
387
|
+
module.exports.registerPlugins = nativeBinding.registerPlugins;
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/utils/normalize-hook.ts
|
|
392
|
+
function normalizeHook(hook) {
|
|
393
|
+
if (typeof hook === 'function') {
|
|
394
|
+
return [hook, {}];
|
|
395
|
+
}
|
|
396
|
+
const {handler,...options} = hook;
|
|
397
|
+
return [handler, options];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/utils/transform-sourcemap.ts
|
|
402
|
+
function isEmptySourcemapFiled(array) {
|
|
403
|
+
if ( !array) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
if (array.length === 0 || !array[0]) {
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/utils/misc.ts
|
|
414
|
+
function arraify(value) {
|
|
415
|
+
return Array.isArray(value) ? value : [value];
|
|
416
|
+
}
|
|
417
|
+
function unimplemented(info) {
|
|
418
|
+
if (info) {
|
|
419
|
+
throw new Error(`unimplemented: ${info}`);
|
|
420
|
+
}
|
|
421
|
+
throw new Error('unimplemented');
|
|
422
|
+
}
|
|
423
|
+
function unsupported(info) {
|
|
424
|
+
return () => {
|
|
425
|
+
throw new Error(`UNSUPPORTED: ${info}`);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function noop(..._args) {
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/utils/transform-module-info.ts
|
|
433
|
+
function transformModuleInfo(info) {
|
|
434
|
+
return {
|
|
435
|
+
get ast(){
|
|
436
|
+
return unsupported('ModuleInfo#ast');
|
|
437
|
+
},
|
|
438
|
+
get code(){
|
|
439
|
+
return info.code;
|
|
440
|
+
},
|
|
441
|
+
id:info.id,
|
|
442
|
+
importers:info.importers,
|
|
443
|
+
dynamicImporters:info.dynamicImporters,
|
|
444
|
+
importedIds:info.importedIds,
|
|
445
|
+
dynamicallyImportedIds:info.dynamicallyImportedIds,
|
|
446
|
+
isEntry:info.isEntry
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/types/sourcemap.ts
|
|
452
|
+
function bindingifySourcemap(map) {
|
|
453
|
+
if (map == null) return;
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
inner:typeof map === 'string' ? map : {
|
|
457
|
+
file:map.file ?? undefined,
|
|
458
|
+
mappings:map.mappings,
|
|
459
|
+
sourceRoot:map.sourceRoot,
|
|
460
|
+
sources:map.sources?.map(s => s ?? undefined),
|
|
461
|
+
sourcesContent:map.sourcesContent?.map(s => s ?? undefined),
|
|
462
|
+
names:map.names
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/log/logging.ts
|
|
469
|
+
const LogLevelSchema = z.literal('info').or(z.literal('debug')).or(z.literal('warn'));
|
|
470
|
+
const LogLevelWithErrorSchema = LogLevelSchema.or(z.literal('error'));
|
|
471
|
+
const LogLevelOptionSchema = LogLevelSchema.or(z.literal('silent'));
|
|
472
|
+
const LOG_LEVEL_SILENT = 'silent';
|
|
473
|
+
const LOG_LEVEL_ERROR = 'error';
|
|
474
|
+
const LOG_LEVEL_WARN = 'warn';
|
|
475
|
+
const LOG_LEVEL_INFO = 'info';
|
|
476
|
+
const LOG_LEVEL_DEBUG = 'debug';
|
|
477
|
+
const logLevelPriority = {
|
|
478
|
+
[LOG_LEVEL_DEBUG]:0,
|
|
479
|
+
[LOG_LEVEL_INFO]:1,
|
|
480
|
+
[LOG_LEVEL_WARN]:2,
|
|
481
|
+
[LOG_LEVEL_SILENT]:3
|
|
482
|
+
};
|
|
483
|
+
const RollupLogSchema = z.any();
|
|
484
|
+
const RollupLogWithStringSchema = RollupLogSchema.or(z.string());
|
|
485
|
+
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/utils/code-frame.ts
|
|
488
|
+
function spaces(index) {
|
|
489
|
+
let result = '';
|
|
490
|
+
while(index--) result += ' ';
|
|
491
|
+
return result;
|
|
492
|
+
}
|
|
493
|
+
function tabsToSpaces(value) {
|
|
494
|
+
return value.replace(/^\t+/, match => match.split(' ').join(' '));
|
|
495
|
+
}
|
|
496
|
+
const LINE_TRUNCATE_LENGTH = 120;
|
|
497
|
+
const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
|
|
498
|
+
const ELLIPSIS = '...';
|
|
499
|
+
function getCodeFrame(source, line, column) {
|
|
500
|
+
let lines = source.split('\n');
|
|
501
|
+
if (line > lines.length) return '';
|
|
502
|
+
|
|
503
|
+
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
|
|
504
|
+
const frameStart = Math.max(0, line - 3);
|
|
505
|
+
let frameEnd = Math.min(line + 2, lines.length);
|
|
506
|
+
lines = lines.slice(frameStart, frameEnd);
|
|
507
|
+
while( !/\S/.test(lines[lines.length - 1])) {
|
|
508
|
+
lines.pop();
|
|
509
|
+
frameEnd -= 1;
|
|
510
|
+
}
|
|
511
|
+
const digits = String(frameEnd).length;
|
|
512
|
+
return lines.map((sourceLine, index) => {
|
|
513
|
+
const isErrorLine = frameStart + index + 1 === line;
|
|
514
|
+
let lineNumber = String(index + frameStart + 1);
|
|
515
|
+
while(lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
516
|
+
let displayedLine = tabsToSpaces(sourceLine);
|
|
517
|
+
if (displayedLine.length > maxLineLength) {
|
|
518
|
+
displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
519
|
+
}
|
|
520
|
+
if (isErrorLine) {
|
|
521
|
+
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + '^';
|
|
522
|
+
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
523
|
+
}
|
|
524
|
+
return `${lineNumber}: ${displayedLine}`;
|
|
525
|
+
}).join('\n');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region ../../node_modules/.pnpm/locate-character@3.0.0/node_modules/locate-character/src/index.js
|
|
530
|
+
function rangeContains(range, index) {
|
|
531
|
+
return range.start <= index && index < range.end;
|
|
532
|
+
}
|
|
533
|
+
function getLocator(source, options={}) {
|
|
534
|
+
const {offsetLine=0, offsetColumn=0} = options;
|
|
535
|
+
let start = 0;
|
|
536
|
+
const ranges = source.split('\n').map((line, i$1) => {
|
|
537
|
+
const end = start + line.length + 1;
|
|
538
|
+
const range = {
|
|
539
|
+
start,
|
|
540
|
+
end,
|
|
541
|
+
line:i$1
|
|
542
|
+
};
|
|
543
|
+
start = end;
|
|
544
|
+
return range;
|
|
545
|
+
});
|
|
546
|
+
let i = 0;
|
|
547
|
+
function locator(search, index) {
|
|
548
|
+
if (typeof search === 'string') {
|
|
549
|
+
search = source.indexOf(search, index ?? 0);
|
|
550
|
+
}
|
|
551
|
+
if (search === -1) return undefined;
|
|
552
|
+
|
|
553
|
+
let range = ranges[i];
|
|
554
|
+
const d = search >= range.end ? 1 : -1;
|
|
555
|
+
while(range) {
|
|
556
|
+
if (rangeContains(range, search)) {
|
|
557
|
+
return {
|
|
558
|
+
line:offsetLine + range.line,
|
|
559
|
+
column:offsetColumn + search - range.start,
|
|
560
|
+
character:search
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
i += d;
|
|
564
|
+
range = ranges[i];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return locator;
|
|
568
|
+
}
|
|
569
|
+
function locate(source, search, options) {
|
|
570
|
+
return getLocator(source, options)(search, options && options.startIndex);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/log/logs.ts
|
|
575
|
+
const INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', PLUGIN_ERROR = 'PLUGIN_ERROR';
|
|
576
|
+
function logInvalidLogPosition(pluginName) {
|
|
577
|
+
return {
|
|
578
|
+
code:INVALID_LOG_POSITION,
|
|
579
|
+
message:`Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function logPluginError(error$1, plugin, {hook, id}={}) {
|
|
583
|
+
const code = error$1.code;
|
|
584
|
+
if ( !error$1.pluginCode && code != null && (typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
|
|
585
|
+
error$1.pluginCode = code;
|
|
586
|
+
}
|
|
587
|
+
error$1.code = PLUGIN_ERROR;
|
|
588
|
+
error$1.plugin = plugin;
|
|
589
|
+
if (hook) {
|
|
590
|
+
error$1.hook = hook;
|
|
591
|
+
}
|
|
592
|
+
if (id) {
|
|
593
|
+
error$1.id = id;
|
|
594
|
+
}
|
|
595
|
+
return error$1;
|
|
596
|
+
}
|
|
597
|
+
function error(base) {
|
|
598
|
+
if ( !(base instanceof Error)) {
|
|
599
|
+
base = Object.assign(new Error(base.message), base);
|
|
600
|
+
Object.defineProperty(base, 'name', {
|
|
601
|
+
value:'RollupError',
|
|
602
|
+
writable:true
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
throw base;
|
|
606
|
+
}
|
|
607
|
+
function augmentCodeLocation(properties, pos, source, id) {
|
|
608
|
+
if (typeof pos === 'object') {
|
|
609
|
+
const {line, column} = pos;
|
|
610
|
+
properties.loc = {
|
|
611
|
+
column,
|
|
612
|
+
file:id,
|
|
613
|
+
line
|
|
614
|
+
};
|
|
615
|
+
} else {
|
|
616
|
+
properties.pos = pos;
|
|
617
|
+
const location = locate(source, pos, {
|
|
618
|
+
offsetLine:1
|
|
619
|
+
});
|
|
620
|
+
if ( !location) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const {line, column} = location;
|
|
624
|
+
properties.loc = {
|
|
625
|
+
column,
|
|
626
|
+
file:id,
|
|
627
|
+
line
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
if (properties.frame === undefined) {
|
|
631
|
+
const {line, column} = properties.loc;
|
|
632
|
+
properties.frame = getCodeFrame(source, line, column);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/log/logHandler.ts
|
|
638
|
+
const normalizeLog = log => typeof log === 'string' ? {
|
|
639
|
+
message:log
|
|
640
|
+
} : typeof log === 'function' ? normalizeLog(log()) : log;
|
|
641
|
+
function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
642
|
+
if (logLevelPriority[level] < logLevelPriority[logLevel]) {
|
|
643
|
+
return noop;
|
|
644
|
+
}
|
|
645
|
+
return (log, pos) => {
|
|
646
|
+
if (pos != null) {
|
|
647
|
+
logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
|
|
648
|
+
}
|
|
649
|
+
log = normalizeLog(log);
|
|
650
|
+
if (log.code && !log.pluginCode) {
|
|
651
|
+
log.pluginCode = log.code;
|
|
652
|
+
}
|
|
653
|
+
log.code = code;
|
|
654
|
+
log.plugin = pluginName;
|
|
655
|
+
logger(level, log);
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/plugin/plugin-context.ts
|
|
661
|
+
class PluginContext {
|
|
662
|
+
debug;
|
|
663
|
+
|
|
664
|
+
info;
|
|
665
|
+
|
|
666
|
+
warn;
|
|
667
|
+
|
|
668
|
+
error;
|
|
669
|
+
|
|
670
|
+
resolve;
|
|
671
|
+
|
|
672
|
+
emitFile;
|
|
673
|
+
|
|
674
|
+
getFileName;
|
|
675
|
+
|
|
676
|
+
parse;
|
|
677
|
+
|
|
678
|
+
constructor(options, context, plugin){
|
|
679
|
+
const onLog = options.onLog;
|
|
680
|
+
const pluginName = plugin.name || 'unknown';
|
|
681
|
+
const logLevel = options.logLevel;
|
|
682
|
+
this.debug = getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
683
|
+
this.warn = getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', onLog, pluginName, logLevel);
|
|
684
|
+
this.info = getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
685
|
+
this.error = e => {
|
|
686
|
+
return error(logPluginError(normalizeLog(e), pluginName));
|
|
687
|
+
};
|
|
688
|
+
this.resolve = context.resolve.bind(context);
|
|
689
|
+
this.emitFile = file => {
|
|
690
|
+
if (file.type !== 'asset') {
|
|
691
|
+
return unimplemented('PluginContext.emitFile: only asset type is supported');
|
|
663
692
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}catch(err){
|
|
668
|
-
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
669
|
-
console.error(err);
|
|
670
|
-
}
|
|
671
|
-
} }
|
|
672
|
-
}
|
|
673
|
-
if ( !nativeBinding) {
|
|
674
|
-
if (loadErrors.length > 0) {
|
|
675
|
-
throw new Error('Failed to load native binding', {
|
|
676
|
-
cause:loadErrors
|
|
693
|
+
return context.emitFile({
|
|
694
|
+
...file,
|
|
695
|
+
source:bindingAssetSource(file.source)
|
|
677
696
|
});
|
|
678
|
-
}
|
|
679
|
-
|
|
697
|
+
};
|
|
698
|
+
this.getFileName = context.getFileName.bind(context);
|
|
699
|
+
this.parse = unsupported('`PluginContext#parse` is not supported by rolldown.');
|
|
680
700
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/plugin/transfrom-plugin-context.ts
|
|
705
|
+
class TransformPluginContext {
|
|
706
|
+
debug;
|
|
707
|
+
|
|
708
|
+
info;
|
|
709
|
+
|
|
710
|
+
warn;
|
|
711
|
+
|
|
712
|
+
error;
|
|
713
|
+
|
|
714
|
+
resolve;
|
|
715
|
+
|
|
716
|
+
emitFile;
|
|
717
|
+
|
|
718
|
+
getFileName;
|
|
719
|
+
|
|
720
|
+
parse;
|
|
721
|
+
|
|
722
|
+
constructor(inner, context, moduleId, moduleSource){
|
|
723
|
+
const getLogHandler$1 = handler => (log, pos) => {
|
|
724
|
+
log = normalizeLog(log);
|
|
725
|
+
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
726
|
+
|
|
727
|
+
log.id = moduleId;
|
|
728
|
+
log.hook = 'transform';
|
|
729
|
+
handler(log);
|
|
730
|
+
};
|
|
731
|
+
this.debug = getLogHandler$1(context.debug);
|
|
732
|
+
this.warn = getLogHandler$1(context.warn);
|
|
733
|
+
this.info = getLogHandler$1(context.info);
|
|
734
|
+
this.error = (error$1, pos) => {
|
|
735
|
+
if (typeof error$1 === 'string') error$1 = {
|
|
736
|
+
message:error$1
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
if (pos) augmentCodeLocation(error$1, pos, moduleSource, moduleId);
|
|
740
|
+
|
|
741
|
+
error$1.id = moduleId;
|
|
742
|
+
error$1.hook = 'transform';
|
|
743
|
+
return context.error(error$1);
|
|
744
|
+
};
|
|
745
|
+
this.resolve = context.resolve;
|
|
746
|
+
this.parse = context.parse;
|
|
747
|
+
this.emitFile = context.emitFile;
|
|
748
|
+
this.getFileName = context.getFileName;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
695
751
|
|
|
696
752
|
//#endregion
|
|
697
753
|
//#region src/utils/transform-side-effects.ts
|
|
698
|
-
var import_binding
|
|
754
|
+
var import_binding = __toESM(require_binding());
|
|
699
755
|
function bindingifySideEffects(sideEffects) {
|
|
700
756
|
switch(sideEffects){
|
|
701
757
|
case true:
|
|
702
|
-
return import_binding
|
|
758
|
+
return import_binding.BindingHookSideEffects.True;
|
|
703
759
|
case false:
|
|
704
|
-
return import_binding
|
|
760
|
+
return import_binding.BindingHookSideEffects.False;
|
|
705
761
|
case 'no-treeshake':
|
|
706
|
-
return import_binding
|
|
762
|
+
return import_binding.BindingHookSideEffects.NoTreeshake;
|
|
707
763
|
case null:
|
|
708
|
-
case
|
|
709
|
-
return
|
|
764
|
+
case undefined:
|
|
765
|
+
return undefined;
|
|
710
766
|
default:
|
|
711
767
|
throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
712
768
|
}
|
|
@@ -717,7 +773,7 @@ function bindingifySideEffects(sideEffects) {
|
|
|
717
773
|
function bindingifyBuildStart(plugin, options) {
|
|
718
774
|
const hook = plugin.buildStart;
|
|
719
775
|
if ( !hook) {
|
|
720
|
-
return
|
|
776
|
+
return undefined;
|
|
721
777
|
}
|
|
722
778
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
723
779
|
return async ctx => {
|
|
@@ -727,21 +783,21 @@ function bindingifyBuildStart(plugin, options) {
|
|
|
727
783
|
function bindingifyBuildEnd(plugin, options) {
|
|
728
784
|
const hook = plugin.buildEnd;
|
|
729
785
|
if ( !hook) {
|
|
730
|
-
return
|
|
786
|
+
return undefined;
|
|
731
787
|
}
|
|
732
788
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
733
789
|
return async(ctx, err) => {
|
|
734
|
-
await handler.call(new PluginContext(options, ctx, plugin), err ? new Error(err) :
|
|
790
|
+
await handler.call(new PluginContext(options, ctx, plugin), err ? new Error(err) : undefined);
|
|
735
791
|
};
|
|
736
792
|
}
|
|
737
793
|
function bindingifyResolveId(plugin, options) {
|
|
738
794
|
const hook = plugin.resolveId;
|
|
739
795
|
if ( !hook) {
|
|
740
|
-
return
|
|
796
|
+
return undefined;
|
|
741
797
|
}
|
|
742
798
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
743
799
|
return async(ctx, specifier, importer, extraOptions) => {
|
|
744
|
-
const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ??
|
|
800
|
+
const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined, extraOptions);
|
|
745
801
|
if (ret == false || ret == null) {
|
|
746
802
|
return;
|
|
747
803
|
}
|
|
@@ -763,11 +819,11 @@ function bindingifyResolveId(plugin, options) {
|
|
|
763
819
|
function bindingifyResolveDynamicImport(plugin, options) {
|
|
764
820
|
const hook = plugin.resolveDynamicImport;
|
|
765
821
|
if ( !hook) {
|
|
766
|
-
return
|
|
822
|
+
return undefined;
|
|
767
823
|
}
|
|
768
824
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
769
825
|
return async(ctx, specifier, importer) => {
|
|
770
|
-
const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ??
|
|
826
|
+
const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined);
|
|
771
827
|
if (ret == false || ret == null) {
|
|
772
828
|
return;
|
|
773
829
|
}
|
|
@@ -789,13 +845,13 @@ function bindingifyResolveDynamicImport(plugin, options) {
|
|
|
789
845
|
function bindingifyTransform(plugin, options) {
|
|
790
846
|
const hook = plugin.transform;
|
|
791
847
|
if ( !hook) {
|
|
792
|
-
return
|
|
848
|
+
return undefined;
|
|
793
849
|
}
|
|
794
850
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
795
851
|
return async(ctx, code, id) => {
|
|
796
852
|
const ret = await handler.call(new TransformPluginContext(ctx, new PluginContext(options, ctx.inner(), plugin), id, code), code, id);
|
|
797
853
|
if (ret == null) {
|
|
798
|
-
return
|
|
854
|
+
return undefined;
|
|
799
855
|
}
|
|
800
856
|
if (typeof ret === 'string') {
|
|
801
857
|
return {
|
|
@@ -804,7 +860,7 @@ function bindingifyTransform(plugin, options) {
|
|
|
804
860
|
}
|
|
805
861
|
return {
|
|
806
862
|
code:ret.code,
|
|
807
|
-
map:
|
|
863
|
+
map:bindingifySourcemap(ret.map),
|
|
808
864
|
sideEffects:bindingifySideEffects(ret.moduleSideEffects)
|
|
809
865
|
};
|
|
810
866
|
};
|
|
@@ -812,7 +868,7 @@ function bindingifyTransform(plugin, options) {
|
|
|
812
868
|
function bindingifyLoad(plugin, options) {
|
|
813
869
|
const hook = plugin.load;
|
|
814
870
|
if ( !hook) {
|
|
815
|
-
return
|
|
871
|
+
return undefined;
|
|
816
872
|
}
|
|
817
873
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
818
874
|
return async(ctx, id) => {
|
|
@@ -832,13 +888,13 @@ function bindingifyLoad(plugin, options) {
|
|
|
832
888
|
}
|
|
833
889
|
let map = typeof ret.map === 'object' ? ret.map : JSON.parse(ret.map);
|
|
834
890
|
if ( !isEmptySourcemapFiled(map.sources)) {
|
|
835
|
-
const directory = path
|
|
891
|
+
const directory = path.dirname(id) || '.';
|
|
836
892
|
const sourceRoot = map.sourceRoot || '.';
|
|
837
|
-
map.sources = map.sources.map(source => path
|
|
893
|
+
map.sources = map.sources.map(source => path.resolve(directory, sourceRoot, source));
|
|
838
894
|
}
|
|
839
895
|
const result = {
|
|
840
896
|
code:ret.code,
|
|
841
|
-
map:
|
|
897
|
+
map:bindingifySourcemap(map)
|
|
842
898
|
};
|
|
843
899
|
if (ret.moduleSideEffects !== null) {
|
|
844
900
|
result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
|
|
@@ -849,7 +905,7 @@ function bindingifyLoad(plugin, options) {
|
|
|
849
905
|
function bindingifyModuleParsed(plugin, options) {
|
|
850
906
|
const hook = plugin.moduleParsed;
|
|
851
907
|
if ( !hook) {
|
|
852
|
-
return
|
|
908
|
+
return undefined;
|
|
853
909
|
}
|
|
854
910
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
855
911
|
return async(ctx, moduleInfo) => {
|
|
@@ -862,7 +918,7 @@ function bindingifyModuleParsed(plugin, options) {
|
|
|
862
918
|
function bindingifyRenderStart(plugin, options, outputOptions) {
|
|
863
919
|
const hook = plugin.renderStart;
|
|
864
920
|
if ( !hook) {
|
|
865
|
-
return
|
|
921
|
+
return undefined;
|
|
866
922
|
}
|
|
867
923
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
868
924
|
return async ctx => {
|
|
@@ -872,7 +928,7 @@ function bindingifyRenderStart(plugin, options, outputOptions) {
|
|
|
872
928
|
function bindingifyRenderChunk(plugin, options, outputOptions) {
|
|
873
929
|
const hook = plugin.renderChunk;
|
|
874
930
|
if ( !hook) {
|
|
875
|
-
return
|
|
931
|
+
return undefined;
|
|
876
932
|
}
|
|
877
933
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
878
934
|
return async(ctx, code, chunk) => {
|
|
@@ -892,14 +948,14 @@ function bindingifyRenderChunk(plugin, options, outputOptions) {
|
|
|
892
948
|
}
|
|
893
949
|
return {
|
|
894
950
|
code:ret.code,
|
|
895
|
-
map:
|
|
951
|
+
map:bindingifySourcemap(ret.map)
|
|
896
952
|
};
|
|
897
953
|
};
|
|
898
954
|
}
|
|
899
955
|
function bindingifyAugmentChunkHash(plugin, options) {
|
|
900
956
|
const hook = plugin.augmentChunkHash;
|
|
901
957
|
if ( !hook) {
|
|
902
|
-
return
|
|
958
|
+
return undefined;
|
|
903
959
|
}
|
|
904
960
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
905
961
|
return async(ctx, chunk) => {
|
|
@@ -909,7 +965,7 @@ function bindingifyAugmentChunkHash(plugin, options) {
|
|
|
909
965
|
function bindingifyRenderError(plugin, options) {
|
|
910
966
|
const hook = plugin.renderError;
|
|
911
967
|
if ( !hook) {
|
|
912
|
-
return
|
|
968
|
+
return undefined;
|
|
913
969
|
}
|
|
914
970
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
915
971
|
return async(ctx, err) => {
|
|
@@ -919,7 +975,7 @@ function bindingifyRenderError(plugin, options) {
|
|
|
919
975
|
function bindingifyGenerateBundle(plugin, options, outputOptions) {
|
|
920
976
|
const hook = plugin.generateBundle;
|
|
921
977
|
if ( !hook) {
|
|
922
|
-
return
|
|
978
|
+
return undefined;
|
|
923
979
|
}
|
|
924
980
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
925
981
|
return async(ctx, bundle, isWrite) => {
|
|
@@ -929,7 +985,7 @@ function bindingifyGenerateBundle(plugin, options, outputOptions) {
|
|
|
929
985
|
function bindingifyWriteBundle(plugin, options, outputOptions) {
|
|
930
986
|
const hook = plugin.writeBundle;
|
|
931
987
|
if ( !hook) {
|
|
932
|
-
return
|
|
988
|
+
return undefined;
|
|
933
989
|
}
|
|
934
990
|
const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
|
|
935
991
|
return async(ctx, bundle) => {
|
|
@@ -959,417 +1015,18 @@ function bindingifyPlugin(plugin, options, outputOptions) {
|
|
|
959
1015
|
}
|
|
960
1016
|
|
|
961
1017
|
//#endregion
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
plugins:options.plugins.map(plugin => {
|
|
967
|
-
if ('_parallel'in plugin) {
|
|
968
|
-
return void 0;
|
|
969
|
-
}
|
|
970
|
-
return bindingifyPlugin(plugin, options, outputOptions);
|
|
971
|
-
}),
|
|
972
|
-
cwd:options.cwd ?? process.cwd(),
|
|
973
|
-
external:options.external ? function bindingifyExternal() {
|
|
974
|
-
const external = options.external;
|
|
975
|
-
if (typeof external === 'function') {
|
|
976
|
-
return (id, importer, isResolved) => {
|
|
977
|
-
if (id.startsWith('\0')) return false;
|
|
978
|
-
|
|
979
|
-
return external(id, importer, isResolved) ?? false;
|
|
980
|
-
};
|
|
981
|
-
}
|
|
982
|
-
const externalArr = arraify(external);
|
|
983
|
-
return (id, _importer, _isResolved) => {
|
|
984
|
-
return externalArr.some(pat => {
|
|
985
|
-
if (pat instanceof RegExp) {
|
|
986
|
-
return pat.test(id);
|
|
987
|
-
}
|
|
988
|
-
return id === pat;
|
|
989
|
-
});
|
|
990
|
-
};
|
|
991
|
-
}() : void 0,
|
|
992
|
-
resolve:options.resolve ? function bindingifyResolve() {
|
|
993
|
-
const {alias,...rest} = options.resolve;
|
|
994
|
-
return {
|
|
995
|
-
alias:alias ? Object.entries(alias).map(([name,replacement]) => ({
|
|
996
|
-
find:name,
|
|
997
|
-
replacements:[replacement]
|
|
998
|
-
})) : void 0,
|
|
999
|
-
...rest
|
|
1000
|
-
};
|
|
1001
|
-
}() : void 0,
|
|
1002
|
-
platform:options.platform,
|
|
1003
|
-
shimMissingExports:options.shimMissingExports,
|
|
1004
|
-
logLevel:bindingifyLogLevel(options.logLevel),
|
|
1005
|
-
onLog:(level, log) => {
|
|
1006
|
-
options.onLog(level, {
|
|
1007
|
-
code:log.code,
|
|
1008
|
-
message:log.message
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
function bindingifyLogLevel(logLevel) {
|
|
1014
|
-
switch(logLevel){
|
|
1015
|
-
case 'silent':
|
|
1016
|
-
return 0;
|
|
1017
|
-
case 'warn':
|
|
1018
|
-
return 1;
|
|
1019
|
-
case 'info':
|
|
1020
|
-
return 2;
|
|
1021
|
-
case 'debug':
|
|
1022
|
-
return 3;
|
|
1023
|
-
default:
|
|
1024
|
-
throw new Error(`Unexpected log level: ${logLevel}`);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
function bindingifyInput(input) {
|
|
1028
|
-
if (Array.isArray(input)) {
|
|
1029
|
-
return input.map(src => {
|
|
1030
|
-
const name = nodePath.parse(src).name;
|
|
1031
|
-
return {
|
|
1032
|
-
name,
|
|
1033
|
-
import:src
|
|
1034
|
-
};
|
|
1035
|
-
});
|
|
1036
|
-
} else {
|
|
1037
|
-
return Object.entries(input).map(value => {
|
|
1038
|
-
return {
|
|
1039
|
-
name:value[0],
|
|
1040
|
-
import:value[1]
|
|
1041
|
-
};
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
//#endregion
|
|
1047
|
-
//#region src/utils/initialize-parallel-plugins.ts
|
|
1048
|
-
var import_binding$1 = __toESM(require_binding());
|
|
1049
|
-
async function initializeParallelPlugins(plugins) {
|
|
1050
|
-
const pluginInfos = [];
|
|
1051
|
-
for (const [index,plugin] of plugins.entries()) {
|
|
1052
|
-
if ('_parallel'in plugin) {
|
|
1053
|
-
const {fileUrl, options} = plugin._parallel;
|
|
1054
|
-
pluginInfos.push({
|
|
1055
|
-
index,
|
|
1056
|
-
fileUrl,
|
|
1057
|
-
options
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
if (pluginInfos.length <= 0) {
|
|
1062
|
-
return void 0;
|
|
1063
|
-
}
|
|
1064
|
-
const count = Math.min(availableParallelism(), 8);
|
|
1065
|
-
const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
|
|
1066
|
-
const registryId = parallelJsPluginRegistry.id;
|
|
1067
|
-
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
1068
|
-
const stopWorkers = async() => {
|
|
1069
|
-
await Promise.all(workers.map(worker => worker.terminate()));
|
|
1070
|
-
};
|
|
1071
|
-
return {
|
|
1072
|
-
registry:parallelJsPluginRegistry,
|
|
1073
|
-
stopWorkers
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
function initializeWorkers(registryId, count, pluginInfos) {
|
|
1077
|
-
return Promise.all(Array.from({
|
|
1078
|
-
length:count
|
|
1079
|
-
}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
1080
|
-
}
|
|
1081
|
-
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
1082
|
-
const urlString = (void 0)('#parallel-plugin-worker');
|
|
1083
|
-
const workerData = {
|
|
1084
|
-
registryId,
|
|
1085
|
-
pluginInfos,
|
|
1086
|
-
threadNumber
|
|
1087
|
-
};
|
|
1088
|
-
let worker;
|
|
1089
|
-
try{
|
|
1090
|
-
worker = new Worker(new URL(urlString), {
|
|
1091
|
-
workerData
|
|
1092
|
-
});
|
|
1093
|
-
worker.unref();
|
|
1094
|
-
await new Promise((resolve, reject) => {
|
|
1095
|
-
worker.once('message', async message => {
|
|
1096
|
-
if (message.type === 'error') {
|
|
1097
|
-
reject(message.error);
|
|
1098
|
-
} else {
|
|
1099
|
-
resolve();
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
return worker;
|
|
1104
|
-
}catch(e){
|
|
1105
|
-
worker?.terminate();
|
|
1106
|
-
throw e;
|
|
1107
|
-
}}
|
|
1108
|
-
|
|
1109
|
-
//#endregion
|
|
1110
|
-
//#region src/log/logger.ts
|
|
1111
|
-
function getLogger(plugins, onLog, logLevel) {
|
|
1112
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
1113
|
-
const logger = (level, log, skipped=new Set()) => {
|
|
1114
|
-
const logPriority = logLevelPriority[level];
|
|
1115
|
-
if (logPriority < minimalPriority) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
for (const plugin of plugins) {
|
|
1119
|
-
if (skipped.has(plugin)) continue;
|
|
1120
|
-
|
|
1121
|
-
const {onLog:pluginOnLog} = plugin;
|
|
1122
|
-
if (pluginOnLog) {
|
|
1123
|
-
const getLogHandler$1 = level2 => {
|
|
1124
|
-
if (logLevelPriority[level2] < minimalPriority) {
|
|
1125
|
-
return () => {
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
return log2 => logger(level2, normalizeLog(log2), new Set(skipped).add(plugin));
|
|
1129
|
-
};
|
|
1130
|
-
const handler = 'handler'in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
|
|
1131
|
-
if (handler.call({
|
|
1132
|
-
debug:getLogHandler$1(LOG_LEVEL_DEBUG),
|
|
1133
|
-
error:log2 => error(normalizeLog(log2)),
|
|
1134
|
-
info:getLogHandler$1(LOG_LEVEL_INFO),
|
|
1135
|
-
warn:getLogHandler$1(LOG_LEVEL_WARN)
|
|
1136
|
-
}, level, log) === false) {
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
onLog(level, log);
|
|
1142
|
-
};
|
|
1143
|
-
return logger;
|
|
1144
|
-
}
|
|
1145
|
-
const getOnLog = (config, logLevel, printLog=defaultPrintLog) => {
|
|
1146
|
-
const {onwarn, onLog} = config;
|
|
1147
|
-
const defaultOnLog = getDefaultOnLog(printLog, onwarn);
|
|
1148
|
-
if (onLog) {
|
|
1149
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
1150
|
-
return (level, log) => onLog(level, addLogToString(log), (level2, handledLog) => {
|
|
1151
|
-
if (level2 === LOG_LEVEL_ERROR) {
|
|
1152
|
-
return error(normalizeLog(handledLog));
|
|
1153
|
-
}
|
|
1154
|
-
if (logLevelPriority[level2] >= minimalPriority) {
|
|
1155
|
-
defaultOnLog(level2, normalizeLog(handledLog));
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
return defaultOnLog;
|
|
1160
|
-
};
|
|
1161
|
-
const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
|
|
1162
|
-
if (level === LOG_LEVEL_WARN) {
|
|
1163
|
-
onwarn(addLogToString(log), warning => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
|
|
1164
|
-
} else {
|
|
1165
|
-
printLog(level, log);
|
|
1166
|
-
}
|
|
1167
|
-
} : printLog;
|
|
1168
|
-
const addLogToString = log => {
|
|
1169
|
-
Object.defineProperty(log, 'toString', {
|
|
1170
|
-
value:() => getExtendedLogMessage(log),
|
|
1171
|
-
writable:true
|
|
1172
|
-
});
|
|
1173
|
-
return log;
|
|
1174
|
-
};
|
|
1175
|
-
const defaultPrintLog = (level, log) => {
|
|
1176
|
-
const message = getExtendedLogMessage(log);
|
|
1177
|
-
switch(level){
|
|
1178
|
-
case LOG_LEVEL_WARN:
|
|
1179
|
-
{
|
|
1180
|
-
return console.warn(message);
|
|
1181
|
-
}
|
|
1182
|
-
case LOG_LEVEL_DEBUG:
|
|
1183
|
-
{
|
|
1184
|
-
return console.debug(message);
|
|
1185
|
-
}
|
|
1186
|
-
default:
|
|
1187
|
-
{
|
|
1188
|
-
return console.info(message);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
const getExtendedLogMessage = log => {
|
|
1193
|
-
let prefix = '';
|
|
1194
|
-
if (log.plugin) {
|
|
1195
|
-
prefix += `(${log.plugin} plugin) `;
|
|
1196
|
-
}
|
|
1197
|
-
if (log.loc) {
|
|
1198
|
-
prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
|
|
1199
|
-
}
|
|
1200
|
-
return prefix + log.message;
|
|
1201
|
-
};
|
|
1202
|
-
function relativeId(id) {
|
|
1203
|
-
if ( !path.isAbsolute(id)) return id;
|
|
1204
|
-
|
|
1205
|
-
return path.relative(path.resolve(), id);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
//#endregion
|
|
1209
|
-
//#region src/utils/normalize-input-options.ts
|
|
1210
|
-
async function normalizeInputOptions(config) {
|
|
1211
|
-
const {input,...rest} = config;
|
|
1212
|
-
const plugins = await normalizePluginOption(config.plugins);
|
|
1213
|
-
const logLevel = config.logLevel || LOG_LEVEL_INFO;
|
|
1214
|
-
const onLog = getLogger(plugins.filter(plugin => !('_parallel'in plugin)), getOnLog(config, logLevel), logLevel);
|
|
1215
|
-
return {
|
|
1216
|
-
...rest,
|
|
1217
|
-
input:input ? typeof input === 'string' ? [input] : input : [],
|
|
1218
|
-
plugins,
|
|
1219
|
-
logLevel,
|
|
1220
|
-
onLog
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
//#endregion
|
|
1225
|
-
//#region src/utils/normalize-output-options.ts
|
|
1226
|
-
function normalizeOutputOptions(opts) {
|
|
1227
|
-
const {dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, entryFileNames, chunkFileNames} = opts;
|
|
1228
|
-
return {
|
|
1229
|
-
dir,
|
|
1230
|
-
format:getFormat(format),
|
|
1231
|
-
exports:exports ?? 'named',
|
|
1232
|
-
sourcemap:sourcemap ?? false,
|
|
1233
|
-
sourcemapIgnoreList:typeof sourcemapIgnoreList === 'function' ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, sourcemapPath) => relativeSourcePath.includes('node_modules'),
|
|
1234
|
-
sourcemapPathTransform,
|
|
1235
|
-
banner:getAddon(opts, 'banner'),
|
|
1236
|
-
footer:getAddon(opts, 'footer'),
|
|
1237
|
-
entryFileNames:entryFileNames ?? '[name].js',
|
|
1238
|
-
chunkFileNames:chunkFileNames ?? '[name]-[hash].js',
|
|
1239
|
-
plugins:[]
|
|
1240
|
-
};
|
|
1241
|
-
}
|
|
1242
|
-
function getFormat(format) {
|
|
1243
|
-
switch(format){
|
|
1244
|
-
case void 0:
|
|
1245
|
-
case 'es':
|
|
1246
|
-
case 'esm':
|
|
1247
|
-
case 'module':
|
|
1248
|
-
{
|
|
1249
|
-
return 'es';
|
|
1250
|
-
}
|
|
1251
|
-
case 'cjs':
|
|
1252
|
-
case 'commonjs':
|
|
1253
|
-
{
|
|
1254
|
-
return 'cjs';
|
|
1255
|
-
}
|
|
1256
|
-
default:
|
|
1257
|
-
unimplemented(`output.format: ${format}`);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
const getAddon = (config, name) => {
|
|
1261
|
-
const configAddon = config[name];
|
|
1262
|
-
if (typeof configAddon === 'function') {
|
|
1263
|
-
return configAddon;
|
|
1264
|
-
}
|
|
1265
|
-
return async() => configAddon || '';
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
//#endregion
|
|
1269
|
-
//#region src/options/bindingify-output-options.ts
|
|
1270
|
-
function bindingifyOutputOptions(outputOptions) {
|
|
1271
|
-
const {dir, format, exports, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, entryFileNames, chunkFileNames, banner, footer} = outputOptions;
|
|
1272
|
-
return {
|
|
1273
|
-
dir,
|
|
1274
|
-
format:function() {
|
|
1275
|
-
switch(format){
|
|
1276
|
-
case 'es':
|
|
1277
|
-
return 'esm';
|
|
1278
|
-
case 'cjs':
|
|
1279
|
-
return 'cjs';
|
|
1280
|
-
}
|
|
1281
|
-
}(),
|
|
1282
|
-
exports,
|
|
1283
|
-
sourcemap:bindingifySourcemap(sourcemap),
|
|
1284
|
-
sourcemapIgnoreList,
|
|
1285
|
-
sourcemapPathTransform,
|
|
1286
|
-
banner,
|
|
1287
|
-
footer,
|
|
1288
|
-
entryFileNames,
|
|
1289
|
-
chunkFileNames,
|
|
1290
|
-
plugins:[]
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
function bindingifySourcemap(sourcemap) {
|
|
1294
|
-
switch(sourcemap){
|
|
1295
|
-
case true:
|
|
1296
|
-
return 'file';
|
|
1297
|
-
case 'inline':
|
|
1298
|
-
return 'inline';
|
|
1299
|
-
case false:
|
|
1300
|
-
case void 0:
|
|
1301
|
-
case 'hidden':
|
|
1302
|
-
return 'hidden';
|
|
1303
|
-
default:
|
|
1304
|
-
throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
//#endregion
|
|
1309
|
-
//#region src/plugin/plugin-driver.ts
|
|
1310
|
-
class PluginDriver {
|
|
1311
|
-
callOptionsHook(inputOptions){
|
|
1312
|
-
const logLevel = inputOptions.logLevel;
|
|
1313
|
-
const plugins = inputOptions.plugins.filter(plugin => !('_parallel'in plugin));
|
|
1314
|
-
const logger = inputOptions.onLog;
|
|
1315
|
-
for (const plugin of plugins) {
|
|
1316
|
-
const name = plugin.name || 'unknown';
|
|
1317
|
-
const options = plugin.options;
|
|
1318
|
-
if (options) {
|
|
1319
|
-
const [handler,_optionsIgnoredSofar] = normalizeHook(options);
|
|
1320
|
-
handler.call({
|
|
1321
|
-
debug:getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
|
|
1322
|
-
error:e => error(logPluginError(normalizeLog(e), name, {
|
|
1323
|
-
hook:'onLog'
|
|
1324
|
-
})),
|
|
1325
|
-
info:getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
|
|
1326
|
-
warn:getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel)
|
|
1327
|
-
}, inputOptions);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
//#endregion
|
|
1334
|
-
//#region src/utils/create-bundler.ts
|
|
1335
|
-
var import_binding = __toESM(require_binding());
|
|
1336
|
-
async function createBundler(inputOptions, outputOptions) {
|
|
1337
|
-
const pluginDriver = new PluginDriver();
|
|
1338
|
-
const normalizedInputOptions = await normalizeInputOptions(inputOptions);
|
|
1339
|
-
pluginDriver.callOptionsHook(normalizedInputOptions);
|
|
1340
|
-
const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
|
|
1341
|
-
try{
|
|
1342
|
-
const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
|
|
1343
|
-
const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
|
|
1344
|
-
return {
|
|
1345
|
-
bundler:new import_binding.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
|
|
1346
|
-
stopWorkers:parallelPluginInitResult?.stopWorkers
|
|
1347
|
-
};
|
|
1348
|
-
}catch(e){
|
|
1349
|
-
await parallelPluginInitResult?.stopWorkers();
|
|
1350
|
-
throw e;
|
|
1351
|
-
}}
|
|
1352
|
-
|
|
1353
|
-
//#endregion
|
|
1354
|
-
//#region src/utils/index.ts
|
|
1355
|
-
function arraify(value) {
|
|
1356
|
-
return Array.isArray(value) ? value : [value];
|
|
1357
|
-
}
|
|
1358
|
-
function unimplemented(info) {
|
|
1359
|
-
if (info) {
|
|
1360
|
-
throw new Error(`unimplemented: ${info}`);
|
|
1361
|
-
}
|
|
1362
|
-
throw new Error('unimplemented');
|
|
1363
|
-
}
|
|
1364
|
-
function unsupported(info) {
|
|
1365
|
-
throw new Error(`Rolldown unsupported api: ${info}`);
|
|
1366
|
-
}
|
|
1367
|
-
function noop(..._args) {
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
//#endregion
|
|
1018
|
+
exports.LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;
|
|
1019
|
+
exports.LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;
|
|
1020
|
+
exports.LOG_LEVEL_INFO = LOG_LEVEL_INFO;
|
|
1021
|
+
exports.LOG_LEVEL_WARN = LOG_LEVEL_WARN;
|
|
1371
1022
|
exports.arraify = arraify;
|
|
1372
1023
|
exports.bindingifyPlugin = bindingifyPlugin;
|
|
1373
|
-
exports.
|
|
1024
|
+
exports.error = error;
|
|
1025
|
+
exports.getLogHandler = getLogHandler;
|
|
1026
|
+
exports.logLevelPriority = logLevelPriority;
|
|
1027
|
+
exports.logPluginError = logPluginError;
|
|
1028
|
+
exports.normalizeHook = normalizeHook;
|
|
1029
|
+
exports.normalizeLog = normalizeLog;
|
|
1374
1030
|
exports.require_binding = require_binding;
|
|
1375
1031
|
exports.transformToRollupOutput = transformToRollupOutput;
|
|
1032
|
+
exports.unimplemented = unimplemented;
|