rolldown 0.10.5 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1032 +0,0 @@
1
- const { __commonJSMin, __toESM } = require("./chunk-eib2uzZZ.cjs");
2
- const { default: path } = __toESM(require("node:path"));
3
- const { z } = __toESM(require("zod"));
4
-
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
- }
14
-
15
- //#endregion
16
- //#region src/utils/transform-to-rollup-output.ts
17
- function transformToRollupOutputChunk(chunk) {
18
- return {
19
- type:'chunk',
20
- get code(){
21
- return chunk.code;
22
- },
23
- set code(code){
24
- chunk.code = code;
25
- },
26
- fileName:chunk.fileName,
27
- name:chunk.name,
28
- get modules(){
29
- return Object.fromEntries(Object.entries(chunk.modules).map(([key,_]) => [key, {}]));
30
- },
31
- get imports(){
32
- return chunk.imports;
33
- },
34
- set imports(imports){
35
- chunk.imports = imports;
36
- },
37
- get dynamicImports(){
38
- return chunk.dynamicImports;
39
- },
40
- exports:chunk.exports,
41
- isEntry:chunk.isEntry,
42
- facadeModuleId:chunk.facadeModuleId || null,
43
- isDynamicEntry:chunk.isDynamicEntry,
44
- get moduleIds(){
45
- return chunk.moduleIds;
46
- },
47
- get map(){
48
- return chunk.map ? JSON.parse(chunk.map) : null;
49
- },
50
- set map(map){
51
- chunk.map = JSON.stringify(map);
52
- },
53
- sourcemapFileName:chunk.sourcemapFileName || null,
54
- preliminaryFileName:chunk.preliminaryFileName
55
- };
56
- }
57
- function transformToRollupOutputAsset(asset) {
58
- return {
59
- type:'asset',
60
- fileName:asset.fileName,
61
- get source(){
62
- return transformAssetSource(asset.source);
63
- },
64
- set source(source){
65
- asset.source = bindingAssetSource(source);
66
- }
67
- };
68
- }
69
- function transformToRollupOutput(output) {
70
- const {chunks, assets} = output;
71
- const [firstChunk,...restChunks] = chunks;
72
- return {
73
- output:[transformToRollupOutputChunk(firstChunk), ...restChunks.map(transformToRollupOutputChunk), ...assets.map(transformToRollupOutputAsset),]
74
- };
75
- }
76
- function transformToOutputBundle(output) {
77
- const bundle = Object.fromEntries(transformToRollupOutput(output).output.map(item => [item.fileName, item]));
78
- return new Proxy(bundle, {
79
- deleteProperty(target, property){
80
- if (typeof property === 'string') {
81
- output.delete(property);
82
- }
83
- return true;
84
- }
85
- });
86
- }
87
-
88
- //#endregion
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();
103
- }
104
- }
105
- return musl;
106
- };
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;
118
- }
119
- if (report.header && report.header.glibcVersionRuntime) {
120
- return false;
121
- }
122
- if (Array.isArray(report.sharedObjects)) {
123
- if (report.sharedObjects.some(isFileMusl)) {
124
- return true;
125
- }
126
- }
127
- return false;
128
- };
129
- const isMuslFromChildProcess = () => {
130
- try{
131
- return require('node:child_process').execSync('ldd --version', {
132
- encoding:'utf8'
133
- }).includes('musl');
134
- }catch(e){
135
- return false;
136
- } };
137
- function requireNative() {
138
- if (process.platform === 'android') {
139
- if (process.arch === 'arm64') {
140
- try{
141
- return require('./rolldown-binding.android-arm64.node');
142
- }catch(e){
143
- loadErrors.push(e);
144
- } try{
145
- return require('@rolldown/binding-android-arm64');
146
- }catch(e){
147
- loadErrors.push(e);
148
- } } else if (process.arch === 'arm') {
149
- try{
150
- return require('./rolldown-binding.android-arm-eabi.node');
151
- }catch(e){
152
- loadErrors.push(e);
153
- } try{
154
- return require('@rolldown/binding-android-arm-eabi');
155
- }catch(e){
156
- loadErrors.push(e);
157
- } } else {
158
- loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
159
- }
160
- } else if (process.platform === 'win32') {
161
- if (process.arch === 'x64') {
162
- try{
163
- return require('./rolldown-binding.win32-x64-msvc.node');
164
- }catch(e){
165
- loadErrors.push(e);
166
- } try{
167
- return require('@rolldown/binding-win32-x64-msvc');
168
- }catch(e){
169
- loadErrors.push(e);
170
- } } else if (process.arch === 'ia32') {
171
- try{
172
- return require('./rolldown-binding.win32-ia32-msvc.node');
173
- }catch(e){
174
- loadErrors.push(e);
175
- } try{
176
- return require('@rolldown/binding-win32-ia32-msvc');
177
- }catch(e){
178
- loadErrors.push(e);
179
- } } else if (process.arch === 'arm64') {
180
- try{
181
- return require('./rolldown-binding.win32-arm64-msvc.node');
182
- }catch(e){
183
- loadErrors.push(e);
184
- } try{
185
- return require('@rolldown/binding-win32-arm64-msvc');
186
- }catch(e){
187
- loadErrors.push(e);
188
- } } else {
189
- loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
190
- }
191
- } else if (process.platform === 'darwin') {
192
- try{
193
- return require('./rolldown-binding.darwin-universal.node');
194
- }catch(e){
195
- loadErrors.push(e);
196
- } try{
197
- return require('@rolldown/binding-darwin-universal');
198
- }catch(e){
199
- loadErrors.push(e);
200
- } if (process.arch === 'x64') {
201
- try{
202
- return require('./rolldown-binding.darwin-x64.node');
203
- }catch(e){
204
- loadErrors.push(e);
205
- } try{
206
- return require('@rolldown/binding-darwin-x64');
207
- }catch(e){
208
- loadErrors.push(e);
209
- } } else if (process.arch === 'arm64') {
210
- try{
211
- return require('./rolldown-binding.darwin-arm64.node');
212
- }catch(e){
213
- loadErrors.push(e);
214
- } try{
215
- return require('@rolldown/binding-darwin-arm64');
216
- }catch(e){
217
- loadErrors.push(e);
218
- } } else {
219
- loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
220
- }
221
- } else if (process.platform === 'freebsd') {
222
- if (process.arch === 'x64') {
223
- try{
224
- return require('./rolldown-binding.freebsd-x64.node');
225
- }catch(e){
226
- loadErrors.push(e);
227
- } try{
228
- return require('@rolldown/binding-freebsd-x64');
229
- }catch(e){
230
- loadErrors.push(e);
231
- } } else if (process.arch === 'arm64') {
232
- try{
233
- return require('./rolldown-binding.freebsd-arm64.node');
234
- }catch(e){
235
- loadErrors.push(e);
236
- } try{
237
- return require('@rolldown/binding-freebsd-arm64');
238
- }catch(e){
239
- loadErrors.push(e);
240
- } } else {
241
- loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
242
- }
243
- } else if (process.platform === 'linux') {
244
- if (process.arch === 'x64') {
245
- if (isMusl()) {
246
- try{
247
- return require('./rolldown-binding.linux-x64-musl.node');
248
- }catch(e){
249
- loadErrors.push(e);
250
- } try{
251
- return require('@rolldown/binding-linux-x64-musl');
252
- }catch(e){
253
- loadErrors.push(e);
254
- } } else {
255
- try{
256
- return require('./rolldown-binding.linux-x64-gnu.node');
257
- }catch(e){
258
- loadErrors.push(e);
259
- } try{
260
- return require('@rolldown/binding-linux-x64-gnu');
261
- }catch(e){
262
- loadErrors.push(e);
263
- } }
264
- } else if (process.arch === 'arm64') {
265
- if (isMusl()) {
266
- try{
267
- return require('./rolldown-binding.linux-arm64-musl.node');
268
- }catch(e){
269
- loadErrors.push(e);
270
- } try{
271
- return require('@rolldown/binding-linux-arm64-musl');
272
- }catch(e){
273
- loadErrors.push(e);
274
- } } else {
275
- try{
276
- return require('./rolldown-binding.linux-arm64-gnu.node');
277
- }catch(e){
278
- loadErrors.push(e);
279
- } try{
280
- return require('@rolldown/binding-linux-arm64-gnu');
281
- }catch(e){
282
- loadErrors.push(e);
283
- } }
284
- } else if (process.arch === 'arm') {
285
- if (isMusl()) {
286
- try{
287
- return require('./rolldown-binding.linux-arm-musleabihf.node');
288
- }catch(e){
289
- loadErrors.push(e);
290
- } try{
291
- return require('@rolldown/binding-linux-arm-musleabihf');
292
- }catch(e){
293
- loadErrors.push(e);
294
- } } else {
295
- try{
296
- return require('./rolldown-binding.linux-arm-gnueabihf.node');
297
- }catch(e){
298
- loadErrors.push(e);
299
- } try{
300
- return require('@rolldown/binding-linux-arm-gnueabihf');
301
- }catch(e){
302
- loadErrors.push(e);
303
- } }
304
- } else if (process.arch === 'riscv64') {
305
- if (isMusl()) {
306
- try{
307
- return require('./rolldown-binding.linux-riscv64-musl.node');
308
- }catch(e){
309
- loadErrors.push(e);
310
- } try{
311
- return require('@rolldown/binding-linux-riscv64-musl');
312
- }catch(e){
313
- loadErrors.push(e);
314
- } } else {
315
- try{
316
- return require('./rolldown-binding.linux-riscv64-gnu.node');
317
- }catch(e){
318
- loadErrors.push(e);
319
- } try{
320
- return require('@rolldown/binding-linux-riscv64-gnu');
321
- }catch(e){
322
- loadErrors.push(e);
323
- } }
324
- } else if (process.arch === 'ppc64') {
325
- try{
326
- return require('./rolldown-binding.linux-ppc64-gnu.node');
327
- }catch(e){
328
- loadErrors.push(e);
329
- } try{
330
- return require('@rolldown/binding-linux-ppc64-gnu');
331
- }catch(e){
332
- loadErrors.push(e);
333
- } } else if (process.arch === 's390x') {
334
- try{
335
- return require('./rolldown-binding.linux-s390x-gnu.node');
336
- }catch(e){
337
- loadErrors.push(e);
338
- } try{
339
- return require('@rolldown/binding-linux-s390x-gnu');
340
- }catch(e){
341
- loadErrors.push(e);
342
- } } else {
343
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
344
- }
345
- } else {
346
- loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
347
- }
348
- }
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');
692
- }
693
- return context.emitFile({
694
- ...file,
695
- source:bindingAssetSource(file.source)
696
- });
697
- };
698
- this.getFileName = context.getFileName.bind(context);
699
- this.parse = unsupported('`PluginContext#parse` is not supported by rolldown.');
700
- }
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
- }
751
-
752
- //#endregion
753
- //#region src/utils/transform-side-effects.ts
754
- var import_binding = __toESM(require_binding());
755
- function bindingifySideEffects(sideEffects) {
756
- switch(sideEffects){
757
- case true:
758
- return import_binding.BindingHookSideEffects.True;
759
- case false:
760
- return import_binding.BindingHookSideEffects.False;
761
- case 'no-treeshake':
762
- return import_binding.BindingHookSideEffects.NoTreeshake;
763
- case null:
764
- case undefined:
765
- return undefined;
766
- default:
767
- throw new Error(`Unexpected side effects: ${sideEffects}`);
768
- }
769
- }
770
-
771
- //#endregion
772
- //#region src/plugin/bindingify-build-hooks.ts
773
- function bindingifyBuildStart(plugin, options) {
774
- const hook = plugin.buildStart;
775
- if ( !hook) {
776
- return undefined;
777
- }
778
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
779
- return async ctx => {
780
- await handler.call(new PluginContext(options, ctx, plugin), options);
781
- };
782
- }
783
- function bindingifyBuildEnd(plugin, options) {
784
- const hook = plugin.buildEnd;
785
- if ( !hook) {
786
- return undefined;
787
- }
788
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
789
- return async(ctx, err) => {
790
- await handler.call(new PluginContext(options, ctx, plugin), err ? new Error(err) : undefined);
791
- };
792
- }
793
- function bindingifyResolveId(plugin, options) {
794
- const hook = plugin.resolveId;
795
- if ( !hook) {
796
- return undefined;
797
- }
798
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
799
- return async(ctx, specifier, importer, extraOptions) => {
800
- const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined, extraOptions);
801
- if (ret == false || ret == null) {
802
- return;
803
- }
804
- if (typeof ret === 'string') {
805
- return {
806
- id:ret
807
- };
808
- }
809
- const result = {
810
- id:ret.id,
811
- external:ret.external
812
- };
813
- if (ret.moduleSideEffects !== null) {
814
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
815
- }
816
- return result;
817
- };
818
- }
819
- function bindingifyResolveDynamicImport(plugin, options) {
820
- const hook = plugin.resolveDynamicImport;
821
- if ( !hook) {
822
- return undefined;
823
- }
824
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
825
- return async(ctx, specifier, importer) => {
826
- const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined);
827
- if (ret == false || ret == null) {
828
- return;
829
- }
830
- if (typeof ret === 'string') {
831
- return {
832
- id:ret
833
- };
834
- }
835
- const result = {
836
- id:ret.id,
837
- external:ret.external
838
- };
839
- if (ret.moduleSideEffects !== null) {
840
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
841
- }
842
- return result;
843
- };
844
- }
845
- function bindingifyTransform(plugin, options) {
846
- const hook = plugin.transform;
847
- if ( !hook) {
848
- return undefined;
849
- }
850
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
851
- return async(ctx, code, id) => {
852
- const ret = await handler.call(new TransformPluginContext(ctx, new PluginContext(options, ctx.inner(), plugin), id, code), code, id);
853
- if (ret == null) {
854
- return undefined;
855
- }
856
- if (typeof ret === 'string') {
857
- return {
858
- code:ret
859
- };
860
- }
861
- return {
862
- code:ret.code,
863
- map:bindingifySourcemap(ret.map),
864
- sideEffects:bindingifySideEffects(ret.moduleSideEffects)
865
- };
866
- };
867
- }
868
- function bindingifyLoad(plugin, options) {
869
- const hook = plugin.load;
870
- if ( !hook) {
871
- return undefined;
872
- }
873
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
874
- return async(ctx, id) => {
875
- const ret = await handler.call(new PluginContext(options, ctx, plugin), id);
876
- if (ret == null) {
877
- return;
878
- }
879
- if (typeof ret === 'string') {
880
- return {
881
- code:ret
882
- };
883
- }
884
- if ( !ret.map) {
885
- return {
886
- code:ret.code
887
- };
888
- }
889
- let map = typeof ret.map === 'object' ? ret.map : JSON.parse(ret.map);
890
- if ( !isEmptySourcemapFiled(map.sources)) {
891
- const directory = path.dirname(id) || '.';
892
- const sourceRoot = map.sourceRoot || '.';
893
- map.sources = map.sources.map(source => path.resolve(directory, sourceRoot, source));
894
- }
895
- const result = {
896
- code:ret.code,
897
- map:bindingifySourcemap(map)
898
- };
899
- if (ret.moduleSideEffects !== null) {
900
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
901
- }
902
- return result;
903
- };
904
- }
905
- function bindingifyModuleParsed(plugin, options) {
906
- const hook = plugin.moduleParsed;
907
- if ( !hook) {
908
- return undefined;
909
- }
910
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
911
- return async(ctx, moduleInfo) => {
912
- await handler.call(new PluginContext(options, ctx, plugin), transformModuleInfo(moduleInfo));
913
- };
914
- }
915
-
916
- //#endregion
917
- //#region src/plugin/bindingify-output-hooks.ts
918
- function bindingifyRenderStart(plugin, options, outputOptions) {
919
- const hook = plugin.renderStart;
920
- if ( !hook) {
921
- return undefined;
922
- }
923
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
924
- return async ctx => {
925
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, options);
926
- };
927
- }
928
- function bindingifyRenderChunk(plugin, options, outputOptions) {
929
- const hook = plugin.renderChunk;
930
- if ( !hook) {
931
- return undefined;
932
- }
933
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
934
- return async(ctx, code, chunk) => {
935
- const ret = await handler.call(new PluginContext(options, ctx, plugin), code, chunk, outputOptions);
936
- if (ret == null) {
937
- return;
938
- }
939
- if (typeof ret === 'string') {
940
- return {
941
- code:ret
942
- };
943
- }
944
- if ( !ret.map) {
945
- return {
946
- code:ret.code
947
- };
948
- }
949
- return {
950
- code:ret.code,
951
- map:bindingifySourcemap(ret.map)
952
- };
953
- };
954
- }
955
- function bindingifyAugmentChunkHash(plugin, options) {
956
- const hook = plugin.augmentChunkHash;
957
- if ( !hook) {
958
- return undefined;
959
- }
960
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
961
- return async(ctx, chunk) => {
962
- return await handler.call(new PluginContext(options, ctx, plugin), chunk);
963
- };
964
- }
965
- function bindingifyRenderError(plugin, options) {
966
- const hook = plugin.renderError;
967
- if ( !hook) {
968
- return undefined;
969
- }
970
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
971
- return async(ctx, err) => {
972
- handler.call(new PluginContext(options, ctx, plugin), new Error(err));
973
- };
974
- }
975
- function bindingifyGenerateBundle(plugin, options, outputOptions) {
976
- const hook = plugin.generateBundle;
977
- if ( !hook) {
978
- return undefined;
979
- }
980
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
981
- return async(ctx, bundle, isWrite) => {
982
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, transformToOutputBundle(bundle), isWrite);
983
- };
984
- }
985
- function bindingifyWriteBundle(plugin, options, outputOptions) {
986
- const hook = plugin.writeBundle;
987
- if ( !hook) {
988
- return undefined;
989
- }
990
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
991
- return async(ctx, bundle) => {
992
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, transformToOutputBundle(bundle));
993
- };
994
- }
995
-
996
- //#endregion
997
- //#region src/plugin/bindingify-plugin.ts
998
- function bindingifyPlugin(plugin, options, outputOptions) {
999
- return {
1000
- name:plugin.name ?? 'unknown',
1001
- buildStart:bindingifyBuildStart(plugin, options),
1002
- resolveId:bindingifyResolveId(plugin, options),
1003
- resolveDynamicImport:bindingifyResolveDynamicImport(plugin, options),
1004
- buildEnd:bindingifyBuildEnd(plugin, options),
1005
- transform:bindingifyTransform(plugin, options),
1006
- moduleParsed:bindingifyModuleParsed(plugin, options),
1007
- load:bindingifyLoad(plugin, options),
1008
- renderChunk:bindingifyRenderChunk(plugin, options, outputOptions),
1009
- augmentChunkHash:bindingifyAugmentChunkHash(plugin, options),
1010
- renderStart:bindingifyRenderStart(plugin, options, outputOptions),
1011
- renderError:bindingifyRenderError(plugin, options),
1012
- generateBundle:bindingifyGenerateBundle(plugin, options, outputOptions),
1013
- writeBundle:bindingifyWriteBundle(plugin, options, outputOptions)
1014
- };
1015
- }
1016
-
1017
- //#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;
1022
- exports.arraify = arraify;
1023
- exports.bindingifyPlugin = bindingifyPlugin;
1024
- exports.error = error;
1025
- exports.getLogHandler = getLogHandler;
1026
- exports.logLevelPriority = logLevelPriority;
1027
- exports.logPluginError = logPluginError;
1028
- exports.normalizeHook = normalizeHook;
1029
- exports.normalizeLog = normalizeLog;
1030
- exports.require_binding = require_binding;
1031
- exports.transformToRollupOutput = transformToRollupOutput;
1032
- exports.unimplemented = unimplemented;