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,1053 +0,0 @@
1
- import __node_module__ from 'node:module';
2
- const require = __node_module__.createRequire(import.meta.url)
3
- import { default as path } from "node:path";
4
- import { z } from "zod";
5
-
6
- //#region rolldown:runtime
7
- var __create = Object.create;
8
- var __defProp = Object.defineProperty;
9
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
- var __getOwnPropNames = Object.getOwnPropertyNames;
11
- var __getProtoOf = Object.getPrototypeOf;
12
- var __hasOwnProp = Object.prototype.hasOwnProperty;
13
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = {
14
- exports:{}
15
- }).exports, mod),mod.exports);
16
- var __export = (target, all) => {
17
- for (var name in all) __defProp(target, name, {
18
- get:all[name],
19
- enumerable:true
20
- });
21
- };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === 'object' || typeof from === 'function') for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
- key = keys[i];
25
- if ( !__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
26
- get:(k => from[k]).bind(null, key),
27
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28
- });
29
-
30
- }
31
-
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {},__copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, 'default', {
35
- value:mod,
36
- enumerable:true
37
- }) : target, mod));
38
-
39
- //#endregion
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
- }
49
-
50
- //#endregion
51
- //#region src/utils/transform-to-rollup-output.ts
52
- function transformToRollupOutputChunk(chunk) {
53
- return {
54
- type:'chunk',
55
- get code(){
56
- return chunk.code;
57
- },
58
- set code(code){
59
- chunk.code = code;
60
- },
61
- fileName:chunk.fileName,
62
- name:chunk.name,
63
- get modules(){
64
- return Object.fromEntries(Object.entries(chunk.modules).map(([key,_]) => [key, {}]));
65
- },
66
- get imports(){
67
- return chunk.imports;
68
- },
69
- set imports(imports){
70
- chunk.imports = imports;
71
- },
72
- get dynamicImports(){
73
- return chunk.dynamicImports;
74
- },
75
- exports:chunk.exports,
76
- isEntry:chunk.isEntry,
77
- facadeModuleId:chunk.facadeModuleId || null,
78
- isDynamicEntry:chunk.isDynamicEntry,
79
- get moduleIds(){
80
- return chunk.moduleIds;
81
- },
82
- get map(){
83
- return chunk.map ? JSON.parse(chunk.map) : null;
84
- },
85
- set map(map){
86
- chunk.map = JSON.stringify(map);
87
- },
88
- sourcemapFileName:chunk.sourcemapFileName || null,
89
- preliminaryFileName:chunk.preliminaryFileName
90
- };
91
- }
92
- function transformToRollupOutputAsset(asset) {
93
- return {
94
- type:'asset',
95
- fileName:asset.fileName,
96
- get source(){
97
- return transformAssetSource(asset.source);
98
- },
99
- set source(source){
100
- asset.source = bindingAssetSource(source);
101
- }
102
- };
103
- }
104
- function transformToRollupOutput(output) {
105
- const {chunks, assets} = output;
106
- const [firstChunk,...restChunks] = chunks;
107
- return {
108
- output:[transformToRollupOutputChunk(firstChunk), ...restChunks.map(transformToRollupOutputChunk), ...assets.map(transformToRollupOutputAsset),]
109
- };
110
- }
111
- function transformToOutputBundle(output) {
112
- const bundle = Object.fromEntries(transformToRollupOutput(output).output.map(item => [item.fileName, item]));
113
- return new Proxy(bundle, {
114
- deleteProperty(target, property){
115
- if (typeof property === 'string') {
116
- output.delete(property);
117
- }
118
- return true;
119
- }
120
- });
121
- }
122
-
123
- //#endregion
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();
138
- }
139
- }
140
- return musl;
141
- };
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;
153
- }
154
- if (report.header && report.header.glibcVersionRuntime) {
155
- return false;
156
- }
157
- if (Array.isArray(report.sharedObjects)) {
158
- if (report.sharedObjects.some(isFileMusl)) {
159
- return true;
160
- }
161
- }
162
- return false;
163
- };
164
- const isMuslFromChildProcess = () => {
165
- try{
166
- return require('node:child_process').execSync('ldd --version', {
167
- encoding:'utf8'
168
- }).includes('musl');
169
- }catch(e){
170
- return false;
171
- } };
172
- function requireNative() {
173
- if (process.platform === 'android') {
174
- if (process.arch === 'arm64') {
175
- try{
176
- return require('./rolldown-binding.android-arm64.node');
177
- }catch(e){
178
- loadErrors.push(e);
179
- } try{
180
- return require('@rolldown/binding-android-arm64');
181
- }catch(e){
182
- loadErrors.push(e);
183
- } } else if (process.arch === 'arm') {
184
- try{
185
- return require('./rolldown-binding.android-arm-eabi.node');
186
- }catch(e){
187
- loadErrors.push(e);
188
- } try{
189
- return require('@rolldown/binding-android-arm-eabi');
190
- }catch(e){
191
- loadErrors.push(e);
192
- } } else {
193
- loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
194
- }
195
- } else if (process.platform === 'win32') {
196
- if (process.arch === 'x64') {
197
- try{
198
- return require('./rolldown-binding.win32-x64-msvc.node');
199
- }catch(e){
200
- loadErrors.push(e);
201
- } try{
202
- return require('@rolldown/binding-win32-x64-msvc');
203
- }catch(e){
204
- loadErrors.push(e);
205
- } } else if (process.arch === 'ia32') {
206
- try{
207
- return require('./rolldown-binding.win32-ia32-msvc.node');
208
- }catch(e){
209
- loadErrors.push(e);
210
- } try{
211
- return require('@rolldown/binding-win32-ia32-msvc');
212
- }catch(e){
213
- loadErrors.push(e);
214
- } } else if (process.arch === 'arm64') {
215
- try{
216
- return require('./rolldown-binding.win32-arm64-msvc.node');
217
- }catch(e){
218
- loadErrors.push(e);
219
- } try{
220
- return require('@rolldown/binding-win32-arm64-msvc');
221
- }catch(e){
222
- loadErrors.push(e);
223
- } } else {
224
- loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
225
- }
226
- } else if (process.platform === 'darwin') {
227
- try{
228
- return require('./rolldown-binding.darwin-universal.node');
229
- }catch(e){
230
- loadErrors.push(e);
231
- } try{
232
- return require('@rolldown/binding-darwin-universal');
233
- }catch(e){
234
- loadErrors.push(e);
235
- } if (process.arch === 'x64') {
236
- try{
237
- return require('./rolldown-binding.darwin-x64.node');
238
- }catch(e){
239
- loadErrors.push(e);
240
- } try{
241
- return require('@rolldown/binding-darwin-x64');
242
- }catch(e){
243
- loadErrors.push(e);
244
- } } else if (process.arch === 'arm64') {
245
- try{
246
- return require('./rolldown-binding.darwin-arm64.node');
247
- }catch(e){
248
- loadErrors.push(e);
249
- } try{
250
- return require('@rolldown/binding-darwin-arm64');
251
- }catch(e){
252
- loadErrors.push(e);
253
- } } else {
254
- loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
255
- }
256
- } else if (process.platform === 'freebsd') {
257
- if (process.arch === 'x64') {
258
- try{
259
- return require('./rolldown-binding.freebsd-x64.node');
260
- }catch(e){
261
- loadErrors.push(e);
262
- } try{
263
- return require('@rolldown/binding-freebsd-x64');
264
- }catch(e){
265
- loadErrors.push(e);
266
- } } else if (process.arch === 'arm64') {
267
- try{
268
- return require('./rolldown-binding.freebsd-arm64.node');
269
- }catch(e){
270
- loadErrors.push(e);
271
- } try{
272
- return require('@rolldown/binding-freebsd-arm64');
273
- }catch(e){
274
- loadErrors.push(e);
275
- } } else {
276
- loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
277
- }
278
- } else if (process.platform === 'linux') {
279
- if (process.arch === 'x64') {
280
- if (isMusl()) {
281
- try{
282
- return require('./rolldown-binding.linux-x64-musl.node');
283
- }catch(e){
284
- loadErrors.push(e);
285
- } try{
286
- return require('@rolldown/binding-linux-x64-musl');
287
- }catch(e){
288
- loadErrors.push(e);
289
- } } else {
290
- try{
291
- return require('./rolldown-binding.linux-x64-gnu.node');
292
- }catch(e){
293
- loadErrors.push(e);
294
- } try{
295
- return require('@rolldown/binding-linux-x64-gnu');
296
- }catch(e){
297
- loadErrors.push(e);
298
- } }
299
- } else if (process.arch === 'arm64') {
300
- if (isMusl()) {
301
- try{
302
- return require('./rolldown-binding.linux-arm64-musl.node');
303
- }catch(e){
304
- loadErrors.push(e);
305
- } try{
306
- return require('@rolldown/binding-linux-arm64-musl');
307
- }catch(e){
308
- loadErrors.push(e);
309
- } } else {
310
- try{
311
- return require('./rolldown-binding.linux-arm64-gnu.node');
312
- }catch(e){
313
- loadErrors.push(e);
314
- } try{
315
- return require('@rolldown/binding-linux-arm64-gnu');
316
- }catch(e){
317
- loadErrors.push(e);
318
- } }
319
- } else if (process.arch === 'arm') {
320
- if (isMusl()) {
321
- try{
322
- return require('./rolldown-binding.linux-arm-musleabihf.node');
323
- }catch(e){
324
- loadErrors.push(e);
325
- } try{
326
- return require('@rolldown/binding-linux-arm-musleabihf');
327
- }catch(e){
328
- loadErrors.push(e);
329
- } } else {
330
- try{
331
- return require('./rolldown-binding.linux-arm-gnueabihf.node');
332
- }catch(e){
333
- loadErrors.push(e);
334
- } try{
335
- return require('@rolldown/binding-linux-arm-gnueabihf');
336
- }catch(e){
337
- loadErrors.push(e);
338
- } }
339
- } else if (process.arch === 'riscv64') {
340
- if (isMusl()) {
341
- try{
342
- return require('./rolldown-binding.linux-riscv64-musl.node');
343
- }catch(e){
344
- loadErrors.push(e);
345
- } try{
346
- return require('@rolldown/binding-linux-riscv64-musl');
347
- }catch(e){
348
- loadErrors.push(e);
349
- } } else {
350
- try{
351
- return require('./rolldown-binding.linux-riscv64-gnu.node');
352
- }catch(e){
353
- loadErrors.push(e);
354
- } try{
355
- return require('@rolldown/binding-linux-riscv64-gnu');
356
- }catch(e){
357
- loadErrors.push(e);
358
- } }
359
- } else if (process.arch === 'ppc64') {
360
- try{
361
- return require('./rolldown-binding.linux-ppc64-gnu.node');
362
- }catch(e){
363
- loadErrors.push(e);
364
- } try{
365
- return require('@rolldown/binding-linux-ppc64-gnu');
366
- }catch(e){
367
- loadErrors.push(e);
368
- } } else if (process.arch === 's390x') {
369
- try{
370
- return require('./rolldown-binding.linux-s390x-gnu.node');
371
- }catch(e){
372
- loadErrors.push(e);
373
- } try{
374
- return require('@rolldown/binding-linux-s390x-gnu');
375
- }catch(e){
376
- loadErrors.push(e);
377
- } } else {
378
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
379
- }
380
- } else {
381
- loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
382
- }
383
- }
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');
727
- }
728
- return context.emitFile({
729
- ...file,
730
- source:bindingAssetSource(file.source)
731
- });
732
- };
733
- this.getFileName = context.getFileName.bind(context);
734
- this.parse = unsupported('`PluginContext#parse` is not supported by rolldown.');
735
- }
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
- }
786
-
787
- //#endregion
788
- //#region src/utils/transform-side-effects.ts
789
- var import_binding = __toESM(require_binding());
790
- function bindingifySideEffects(sideEffects) {
791
- switch(sideEffects){
792
- case true:
793
- return import_binding.BindingHookSideEffects.True;
794
- case false:
795
- return import_binding.BindingHookSideEffects.False;
796
- case 'no-treeshake':
797
- return import_binding.BindingHookSideEffects.NoTreeshake;
798
- case null:
799
- case undefined:
800
- return undefined;
801
- default:
802
- throw new Error(`Unexpected side effects: ${sideEffects}`);
803
- }
804
- }
805
-
806
- //#endregion
807
- //#region src/plugin/bindingify-build-hooks.ts
808
- function bindingifyBuildStart(plugin, options) {
809
- const hook = plugin.buildStart;
810
- if ( !hook) {
811
- return undefined;
812
- }
813
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
814
- return async ctx => {
815
- await handler.call(new PluginContext(options, ctx, plugin), options);
816
- };
817
- }
818
- function bindingifyBuildEnd(plugin, options) {
819
- const hook = plugin.buildEnd;
820
- if ( !hook) {
821
- return undefined;
822
- }
823
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
824
- return async(ctx, err) => {
825
- await handler.call(new PluginContext(options, ctx, plugin), err ? new Error(err) : undefined);
826
- };
827
- }
828
- function bindingifyResolveId(plugin, options) {
829
- const hook = plugin.resolveId;
830
- if ( !hook) {
831
- return undefined;
832
- }
833
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
834
- return async(ctx, specifier, importer, extraOptions) => {
835
- const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined, extraOptions);
836
- if (ret == false || ret == null) {
837
- return;
838
- }
839
- if (typeof ret === 'string') {
840
- return {
841
- id:ret
842
- };
843
- }
844
- const result = {
845
- id:ret.id,
846
- external:ret.external
847
- };
848
- if (ret.moduleSideEffects !== null) {
849
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
850
- }
851
- return result;
852
- };
853
- }
854
- function bindingifyResolveDynamicImport(plugin, options) {
855
- const hook = plugin.resolveDynamicImport;
856
- if ( !hook) {
857
- return undefined;
858
- }
859
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
860
- return async(ctx, specifier, importer) => {
861
- const ret = await handler.call(new PluginContext(options, ctx, plugin), specifier, importer ?? undefined);
862
- if (ret == false || ret == null) {
863
- return;
864
- }
865
- if (typeof ret === 'string') {
866
- return {
867
- id:ret
868
- };
869
- }
870
- const result = {
871
- id:ret.id,
872
- external:ret.external
873
- };
874
- if (ret.moduleSideEffects !== null) {
875
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
876
- }
877
- return result;
878
- };
879
- }
880
- function bindingifyTransform(plugin, options) {
881
- const hook = plugin.transform;
882
- if ( !hook) {
883
- return undefined;
884
- }
885
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
886
- return async(ctx, code, id) => {
887
- const ret = await handler.call(new TransformPluginContext(ctx, new PluginContext(options, ctx.inner(), plugin), id, code), code, id);
888
- if (ret == null) {
889
- return undefined;
890
- }
891
- if (typeof ret === 'string') {
892
- return {
893
- code:ret
894
- };
895
- }
896
- return {
897
- code:ret.code,
898
- map:bindingifySourcemap(ret.map),
899
- sideEffects:bindingifySideEffects(ret.moduleSideEffects)
900
- };
901
- };
902
- }
903
- function bindingifyLoad(plugin, options) {
904
- const hook = plugin.load;
905
- if ( !hook) {
906
- return undefined;
907
- }
908
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
909
- return async(ctx, id) => {
910
- const ret = await handler.call(new PluginContext(options, ctx, plugin), id);
911
- if (ret == null) {
912
- return;
913
- }
914
- if (typeof ret === 'string') {
915
- return {
916
- code:ret
917
- };
918
- }
919
- if ( !ret.map) {
920
- return {
921
- code:ret.code
922
- };
923
- }
924
- let map = typeof ret.map === 'object' ? ret.map : JSON.parse(ret.map);
925
- if ( !isEmptySourcemapFiled(map.sources)) {
926
- const directory = path.dirname(id) || '.';
927
- const sourceRoot = map.sourceRoot || '.';
928
- map.sources = map.sources.map(source => path.resolve(directory, sourceRoot, source));
929
- }
930
- const result = {
931
- code:ret.code,
932
- map:bindingifySourcemap(map)
933
- };
934
- if (ret.moduleSideEffects !== null) {
935
- result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
936
- }
937
- return result;
938
- };
939
- }
940
- function bindingifyModuleParsed(plugin, options) {
941
- const hook = plugin.moduleParsed;
942
- if ( !hook) {
943
- return undefined;
944
- }
945
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
946
- return async(ctx, moduleInfo) => {
947
- await handler.call(new PluginContext(options, ctx, plugin), transformModuleInfo(moduleInfo));
948
- };
949
- }
950
-
951
- //#endregion
952
- //#region src/plugin/bindingify-output-hooks.ts
953
- function bindingifyRenderStart(plugin, options, outputOptions) {
954
- const hook = plugin.renderStart;
955
- if ( !hook) {
956
- return undefined;
957
- }
958
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
959
- return async ctx => {
960
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, options);
961
- };
962
- }
963
- function bindingifyRenderChunk(plugin, options, outputOptions) {
964
- const hook = plugin.renderChunk;
965
- if ( !hook) {
966
- return undefined;
967
- }
968
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
969
- return async(ctx, code, chunk) => {
970
- const ret = await handler.call(new PluginContext(options, ctx, plugin), code, chunk, outputOptions);
971
- if (ret == null) {
972
- return;
973
- }
974
- if (typeof ret === 'string') {
975
- return {
976
- code:ret
977
- };
978
- }
979
- if ( !ret.map) {
980
- return {
981
- code:ret.code
982
- };
983
- }
984
- return {
985
- code:ret.code,
986
- map:bindingifySourcemap(ret.map)
987
- };
988
- };
989
- }
990
- function bindingifyAugmentChunkHash(plugin, options) {
991
- const hook = plugin.augmentChunkHash;
992
- if ( !hook) {
993
- return undefined;
994
- }
995
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
996
- return async(ctx, chunk) => {
997
- return await handler.call(new PluginContext(options, ctx, plugin), chunk);
998
- };
999
- }
1000
- function bindingifyRenderError(plugin, options) {
1001
- const hook = plugin.renderError;
1002
- if ( !hook) {
1003
- return undefined;
1004
- }
1005
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
1006
- return async(ctx, err) => {
1007
- handler.call(new PluginContext(options, ctx, plugin), new Error(err));
1008
- };
1009
- }
1010
- function bindingifyGenerateBundle(plugin, options, outputOptions) {
1011
- const hook = plugin.generateBundle;
1012
- if ( !hook) {
1013
- return undefined;
1014
- }
1015
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
1016
- return async(ctx, bundle, isWrite) => {
1017
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, transformToOutputBundle(bundle), isWrite);
1018
- };
1019
- }
1020
- function bindingifyWriteBundle(plugin, options, outputOptions) {
1021
- const hook = plugin.writeBundle;
1022
- if ( !hook) {
1023
- return undefined;
1024
- }
1025
- const [handler,_optionsIgnoredSofar] = normalizeHook(hook);
1026
- return async(ctx, bundle) => {
1027
- handler.call(new PluginContext(options, ctx, plugin), outputOptions, transformToOutputBundle(bundle));
1028
- };
1029
- }
1030
-
1031
- //#endregion
1032
- //#region src/plugin/bindingify-plugin.ts
1033
- function bindingifyPlugin(plugin, options, outputOptions) {
1034
- return {
1035
- name:plugin.name ?? 'unknown',
1036
- buildStart:bindingifyBuildStart(plugin, options),
1037
- resolveId:bindingifyResolveId(plugin, options),
1038
- resolveDynamicImport:bindingifyResolveDynamicImport(plugin, options),
1039
- buildEnd:bindingifyBuildEnd(plugin, options),
1040
- transform:bindingifyTransform(plugin, options),
1041
- moduleParsed:bindingifyModuleParsed(plugin, options),
1042
- load:bindingifyLoad(plugin, options),
1043
- renderChunk:bindingifyRenderChunk(plugin, options, outputOptions),
1044
- augmentChunkHash:bindingifyAugmentChunkHash(plugin, options),
1045
- renderStart:bindingifyRenderStart(plugin, options, outputOptions),
1046
- renderError:bindingifyRenderError(plugin, options),
1047
- generateBundle:bindingifyGenerateBundle(plugin, options, outputOptions),
1048
- writeBundle:bindingifyWriteBundle(plugin, options, outputOptions)
1049
- };
1050
- }
1051
-
1052
- //#endregion
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 };