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