rolldown 1.0.0-beta.3-commit.98f16a0 → 1.0.0-beta.3-commit.d298c0b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.cjs +4 -4
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +4 -4
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{parse-ast-index-CSo7-trQ.mjs → parse-ast-index-Aeq00bwr.mjs} +0 -1
- package/dist/shared/{parse-ast-index-DtSwpkV3.cjs → parse-ast-index-CQpWnODq.cjs} +0 -1
- package/dist/shared/{prompt-zTLhvFXo.mjs → prompt-CxK9euq3.mjs} +2 -2
- package/dist/shared/{prompt-Dh7e4K1i.cjs → prompt-ZZScCEWI.cjs} +2 -2
- package/dist/shared/{src-Bkdoz1UK.mjs → src-CeA4I13P.mjs} +2025 -1988
- package/dist/shared/{src-DOQfmgRW.cjs → src-GI88yV1N.cjs} +2025 -1988
- package/dist/types/binding.d.ts +11 -8
- package/dist/types/options/input-options.d.ts +0 -1
- package/dist/types/plugin/plugin-context.d.ts +2 -2
- package/dist/types/types/rolldown-output.d.ts +2 -0
- package/dist/types/types/sourcemap.d.ts +2 -1
- package/dist/types/utils/validator.d.ts +1 -2
- package/package.json +17 -17
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('./chunk-qZFfknuJ.cjs');
|
|
3
|
-
const require_parse_ast_index = require('./parse-ast-index-
|
|
3
|
+
const require_parse_ast_index = require('./parse-ast-index-CQpWnODq.cjs');
|
|
4
4
|
const node_path = require_chunk.__toESM(require("node:path"));
|
|
5
|
+
const valibot = require_chunk.__toESM(require("valibot"));
|
|
6
|
+
const __valibot_to_json_schema = require_chunk.__toESM(require("@valibot/to-json-schema"));
|
|
5
7
|
const node_buffer = require_chunk.__toESM(require("node:buffer"));
|
|
6
8
|
const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
|
|
7
9
|
const node_os = require_chunk.__toESM(require("node:os"));
|
|
8
|
-
const valibot = require_chunk.__toESM(require("valibot"));
|
|
9
|
-
const __valibot_to_json_schema = require_chunk.__toESM(require("@valibot/to-json-schema"));
|
|
10
10
|
|
|
11
11
|
//#region src/utils/define-config.ts
|
|
12
12
|
function defineConfig(config) {
|
|
@@ -406,2093 +406,2127 @@ function getSortedPlugins(hookName, plugins) {
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
//#endregion
|
|
409
|
-
//#region src/utils/
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
function
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
} })
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
function isEmptySourcemapFiled(array) {
|
|
683
|
-
if (!array) return true;
|
|
684
|
-
if (array.length === 0 || !array[0]) return true;
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
688
|
-
if (!rawMap) return;
|
|
689
|
-
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
690
|
-
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
691
|
-
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
692
|
-
return map;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
//#endregion
|
|
696
|
-
//#region src/utils/transform-module-info.ts
|
|
697
|
-
function transformModuleInfo(info, option) {
|
|
698
|
-
return {
|
|
699
|
-
get ast() {
|
|
700
|
-
return unsupported("ModuleInfo#ast");
|
|
701
|
-
},
|
|
702
|
-
get code() {
|
|
703
|
-
return info.code;
|
|
704
|
-
},
|
|
705
|
-
id: info.id,
|
|
706
|
-
importers: info.importers,
|
|
707
|
-
dynamicImporters: info.dynamicImporters,
|
|
708
|
-
importedIds: info.importedIds,
|
|
709
|
-
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
710
|
-
exports: info.exports,
|
|
711
|
-
isEntry: info.isEntry,
|
|
712
|
-
...option
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region src/plugin/minimal-plugin-context.ts
|
|
718
|
-
var MinimalPluginContext = class {
|
|
719
|
-
info;
|
|
720
|
-
warn;
|
|
721
|
-
debug;
|
|
722
|
-
meta;
|
|
723
|
-
constructor(onLog, logLevel, pluginName) {
|
|
724
|
-
this.pluginName = pluginName;
|
|
725
|
-
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
726
|
-
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
727
|
-
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
728
|
-
this.meta = {
|
|
729
|
-
rollupVersion: "4.23.0",
|
|
730
|
-
rolldownVersion: VERSION,
|
|
731
|
-
watchMode: false
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
error(e) {
|
|
735
|
-
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e), this.pluginName));
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
//#endregion
|
|
740
|
-
//#region src/utils/transform-side-effects.ts
|
|
741
|
-
function bindingifySideEffects(sideEffects) {
|
|
742
|
-
switch (sideEffects) {
|
|
743
|
-
case true: return require_parse_ast_index.import_binding.BindingHookSideEffects.True;
|
|
744
|
-
case false: return require_parse_ast_index.import_binding.BindingHookSideEffects.False;
|
|
745
|
-
case "no-treeshake": return require_parse_ast_index.import_binding.BindingHookSideEffects.NoTreeshake;
|
|
746
|
-
case null:
|
|
747
|
-
case void 0: return void 0;
|
|
748
|
-
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
//#endregion
|
|
753
|
-
//#region src/plugin/plugin-context.ts
|
|
754
|
-
var PluginContext = class extends MinimalPluginContext {
|
|
755
|
-
getModuleInfo;
|
|
756
|
-
constructor(outputOptions, context, plugin, data, onLog, logLevel, currentLoadingModule) {
|
|
757
|
-
super(onLog, logLevel, plugin.name);
|
|
758
|
-
this.outputOptions = outputOptions;
|
|
759
|
-
this.context = context;
|
|
760
|
-
this.data = data;
|
|
761
|
-
this.onLog = onLog;
|
|
762
|
-
this.currentLoadingModule = currentLoadingModule;
|
|
763
|
-
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
764
|
-
}
|
|
765
|
-
async load(options) {
|
|
766
|
-
const id = options.id;
|
|
767
|
-
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, require_parse_ast_index.logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
768
|
-
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
769
|
-
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
770
|
-
const rawOptions = {
|
|
771
|
-
meta: options.meta || {},
|
|
772
|
-
moduleSideEffects: options.moduleSideEffects || null,
|
|
773
|
-
invalidate: false
|
|
774
|
-
};
|
|
775
|
-
this.data.updateModuleOption(id, rawOptions);
|
|
776
|
-
async function createLoadModulePromise(context, data) {
|
|
777
|
-
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
778
|
-
if (loadPromise) return loadPromise;
|
|
779
|
-
let resolveFn;
|
|
780
|
-
const promise = new Promise((resolve, _) => {
|
|
781
|
-
resolveFn = resolve;
|
|
782
|
-
});
|
|
783
|
-
data.loadModulePromiseMap.set(id, promise);
|
|
784
|
-
try {
|
|
785
|
-
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
786
|
-
} finally {
|
|
787
|
-
data.loadModulePromiseMap.delete(id);
|
|
788
|
-
}
|
|
789
|
-
return promise;
|
|
790
|
-
}
|
|
791
|
-
await createLoadModulePromise(this.context, this.data);
|
|
792
|
-
return this.data.getModuleInfo(id, this.context);
|
|
793
|
-
}
|
|
794
|
-
async resolve(source, importer, options) {
|
|
795
|
-
let receipt = void 0;
|
|
796
|
-
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
797
|
-
const res = await this.context.resolve(source, importer, {
|
|
798
|
-
custom: receipt,
|
|
799
|
-
skipSelf: options?.skipSelf
|
|
800
|
-
});
|
|
801
|
-
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
802
|
-
if (res == null) return null;
|
|
803
|
-
const info = this.data.getModuleOption(res.id) || {};
|
|
804
|
-
return {
|
|
805
|
-
...res,
|
|
806
|
-
...info
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
emitFile = (file) => {
|
|
810
|
-
if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
|
|
811
|
-
if (file.type === "chunk") return this.context.emitChunk(file);
|
|
812
|
-
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
813
|
-
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
814
|
-
return this.context.emitFile({
|
|
815
|
-
...file,
|
|
816
|
-
originalFileName: file.originalFileName || void 0,
|
|
817
|
-
source: bindingAssetSource(file.source)
|
|
818
|
-
}, filename, fnSanitizedFileName);
|
|
819
|
-
};
|
|
820
|
-
getAssetFileNames(file) {
|
|
821
|
-
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
822
|
-
names: file.name ? [file.name] : [],
|
|
823
|
-
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
824
|
-
source: file.source,
|
|
825
|
-
type: "asset"
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
getFileName(referenceId) {
|
|
829
|
-
return this.context.getFileName(referenceId);
|
|
830
|
-
}
|
|
831
|
-
getModuleIds() {
|
|
832
|
-
return this.data.getModuleIds(this.context);
|
|
833
|
-
}
|
|
834
|
-
addWatchFile(id) {
|
|
835
|
-
this.context.addWatchFile(id);
|
|
836
|
-
}
|
|
837
|
-
parse(input, options) {
|
|
838
|
-
return require_parse_ast_index.parseAst(input, options);
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
//#endregion
|
|
843
|
-
//#region src/plugin/transform-plugin-context.ts
|
|
844
|
-
var TransformPluginContext = class extends PluginContext {
|
|
845
|
-
constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
846
|
-
super(outputOptions, context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
847
|
-
this.inner = inner;
|
|
848
|
-
this.moduleId = moduleId;
|
|
849
|
-
this.moduleSource = moduleSource;
|
|
850
|
-
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
851
|
-
log = normalizeLog(log);
|
|
852
|
-
if (pos) require_parse_ast_index.augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
853
|
-
log.id = moduleId;
|
|
854
|
-
log.hook = "transform";
|
|
855
|
-
handler(log);
|
|
856
|
-
};
|
|
857
|
-
this.debug = getLogHandler$1(this.debug);
|
|
858
|
-
this.warn = getLogHandler$1(this.warn);
|
|
859
|
-
this.info = getLogHandler$1(this.info);
|
|
860
|
-
}
|
|
861
|
-
error(e, pos) {
|
|
862
|
-
if (typeof e === "string") e = { message: e };
|
|
863
|
-
if (pos) require_parse_ast_index.augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
864
|
-
e.id = this.moduleId;
|
|
865
|
-
e.hook = "transform";
|
|
866
|
-
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e), this.pluginName));
|
|
867
|
-
}
|
|
868
|
-
getCombinedSourcemap() {
|
|
869
|
-
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
//#endregion
|
|
874
|
-
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
875
|
-
function bindingifyPluginHookMeta(options) {
|
|
876
|
-
return { order: bindingPluginOrder(options.order) };
|
|
877
|
-
}
|
|
878
|
-
function bindingPluginOrder(order) {
|
|
879
|
-
switch (order) {
|
|
880
|
-
case "post": return require_parse_ast_index.import_binding.BindingPluginOrder.Post;
|
|
881
|
-
case "pre": return require_parse_ast_index.import_binding.BindingPluginOrder.Pre;
|
|
882
|
-
case null:
|
|
883
|
-
case void 0: return void 0;
|
|
884
|
-
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
//#endregion
|
|
889
|
-
//#region src/constants/plugin-context.ts
|
|
890
|
-
const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
|
|
891
|
-
|
|
892
|
-
//#endregion
|
|
893
|
-
//#region src/plugin/bindingify-hook-filter.ts
|
|
894
|
-
function bindingifyStringFilter(matcher) {
|
|
895
|
-
if (typeof matcher === "string" || matcher instanceof RegExp) return { include: [matcher] };
|
|
896
|
-
if (Array.isArray(matcher)) return { include: matcher };
|
|
897
|
-
return {
|
|
898
|
-
include: matcher.include ? arraify(matcher.include) : void 0,
|
|
899
|
-
exclude: matcher.exclude ? arraify(matcher.exclude) : void 0
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
function bindingifyResolveIdFilter(filterOption) {
|
|
903
|
-
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
|
|
904
|
-
}
|
|
905
|
-
function bindingifyLoadFilter(filterOption) {
|
|
906
|
-
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
|
|
907
|
-
}
|
|
908
|
-
function bindingifyTransformFilter(filterOption) {
|
|
909
|
-
if (!filterOption) return void 0;
|
|
910
|
-
const { id, code, moduleType } = filterOption;
|
|
911
|
-
let moduleTypeRet;
|
|
912
|
-
if (moduleType) if (Array.isArray(moduleType)) moduleTypeRet = moduleType;
|
|
913
|
-
else moduleTypeRet = moduleType.include;
|
|
914
|
-
return {
|
|
915
|
-
id: id ? bindingifyStringFilter(id) : void 0,
|
|
916
|
-
code: code ? bindingifyStringFilter(code) : void 0,
|
|
917
|
-
moduleType: moduleTypeRet
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
//#endregion
|
|
922
|
-
//#region src/options/normalized-input-options.ts
|
|
923
|
-
var NormalizedInputOptionsImpl = class {
|
|
924
|
-
inner;
|
|
925
|
-
constructor(inner, onLog) {
|
|
926
|
-
this.onLog = onLog;
|
|
927
|
-
this.inner = inner;
|
|
928
|
-
}
|
|
929
|
-
get shimMissingExports() {
|
|
930
|
-
return this.inner.shimMissingExports;
|
|
931
|
-
}
|
|
932
|
-
get input() {
|
|
933
|
-
return this.inner.input;
|
|
934
|
-
}
|
|
935
|
-
get cwd() {
|
|
936
|
-
return this.inner.cwd ?? void 0;
|
|
937
|
-
}
|
|
938
|
-
get platform() {
|
|
939
|
-
return this.inner.platform;
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
//#endregion
|
|
944
|
-
//#region src/plugin/bindingify-build-hooks.ts
|
|
945
|
-
function bindingifyBuildStart(args) {
|
|
946
|
-
const hook = args.plugin.buildStart;
|
|
947
|
-
if (!hook) return {};
|
|
948
|
-
const { handler, meta } = normalizeHook(hook);
|
|
949
|
-
return {
|
|
950
|
-
plugin: async (ctx, opts) => {
|
|
951
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedInputOptionsImpl(opts, args.onLog));
|
|
952
|
-
},
|
|
953
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
function bindingifyBuildEnd(args) {
|
|
957
|
-
const hook = args.plugin.buildEnd;
|
|
958
|
-
if (!hook) return {};
|
|
959
|
-
const { handler, meta } = normalizeHook(hook);
|
|
960
|
-
return {
|
|
961
|
-
plugin: async (ctx, err) => {
|
|
962
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : void 0);
|
|
963
|
-
},
|
|
964
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
function bindingifyResolveId(args) {
|
|
968
|
-
const hook = args.plugin.resolveId;
|
|
969
|
-
if (!hook) return {};
|
|
970
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
971
|
-
return {
|
|
972
|
-
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
973
|
-
const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
|
|
974
|
-
const newExtraOptions = {
|
|
975
|
-
...extraOptions,
|
|
976
|
-
custom: contextResolveOptions?.custom,
|
|
977
|
-
[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
|
|
978
|
-
};
|
|
979
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? void 0, newExtraOptions);
|
|
980
|
-
if (ret == null) return;
|
|
981
|
-
if (ret === false) return {
|
|
982
|
-
id: specifier,
|
|
983
|
-
external: true
|
|
984
|
-
};
|
|
985
|
-
if (typeof ret === "string") return { id: ret };
|
|
986
|
-
let exist = args.pluginContextData.updateModuleOption(ret.id, {
|
|
987
|
-
meta: ret.meta || {},
|
|
988
|
-
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
989
|
-
invalidate: false
|
|
990
|
-
});
|
|
991
|
-
return {
|
|
992
|
-
id: ret.id,
|
|
993
|
-
external: ret.external,
|
|
994
|
-
sideEffects: bindingifySideEffects(exist.moduleSideEffects)
|
|
995
|
-
};
|
|
996
|
-
},
|
|
997
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
998
|
-
filter: bindingifyResolveIdFilter(options.filter)
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
function bindingifyResolveDynamicImport(args) {
|
|
1002
|
-
const hook = args.plugin.resolveDynamicImport;
|
|
1003
|
-
if (!hook) return {};
|
|
1004
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1005
|
-
return {
|
|
1006
|
-
plugin: async (ctx, specifier, importer) => {
|
|
1007
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? void 0);
|
|
1008
|
-
if (ret == null) return;
|
|
1009
|
-
if (ret === false) return {
|
|
1010
|
-
id: specifier,
|
|
1011
|
-
external: true
|
|
1012
|
-
};
|
|
1013
|
-
if (typeof ret === "string") return { id: ret };
|
|
1014
|
-
const result = {
|
|
1015
|
-
id: ret.id,
|
|
1016
|
-
external: ret.external
|
|
1017
|
-
};
|
|
1018
|
-
if (ret.moduleSideEffects !== null) result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
|
|
1019
|
-
args.pluginContextData.updateModuleOption(ret.id, {
|
|
1020
|
-
meta: ret.meta || {},
|
|
1021
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
1022
|
-
invalidate: false
|
|
1023
|
-
});
|
|
1024
|
-
return result;
|
|
1025
|
-
},
|
|
1026
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
function bindingifyTransform(args) {
|
|
1030
|
-
const hook = args.plugin.transform;
|
|
1031
|
-
if (!hook) return {};
|
|
1032
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
1033
|
-
return {
|
|
1034
|
-
plugin: async (ctx, code, id, meta$1) => {
|
|
1035
|
-
const ret = await handler.call(new TransformPluginContext(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel), code, id, meta$1);
|
|
1036
|
-
if (ret == null) return void 0;
|
|
1037
|
-
if (typeof ret === "string") return { code: ret };
|
|
1038
|
-
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1039
|
-
meta: ret.meta ?? {},
|
|
1040
|
-
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1041
|
-
invalidate: false
|
|
1042
|
-
});
|
|
1043
|
-
return {
|
|
1044
|
-
code: ret.code,
|
|
1045
|
-
map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
|
|
1046
|
-
sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
|
|
1047
|
-
moduleType: ret.moduleType
|
|
1048
|
-
};
|
|
1049
|
-
},
|
|
1050
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
1051
|
-
filter: bindingifyTransformFilter(options.filter)
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
function bindingifyLoad(args) {
|
|
1055
|
-
const hook = args.plugin.load;
|
|
1056
|
-
if (!hook) return {};
|
|
1057
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
1058
|
-
return {
|
|
1059
|
-
plugin: async (ctx, id) => {
|
|
1060
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, id), id);
|
|
1061
|
-
if (ret == null) return;
|
|
1062
|
-
if (typeof ret === "string") return { code: ret };
|
|
1063
|
-
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1064
|
-
meta: ret.meta || {},
|
|
1065
|
-
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1066
|
-
invalidate: false
|
|
1067
|
-
});
|
|
1068
|
-
let map = preProcessSourceMap(ret, id);
|
|
1069
|
-
return {
|
|
1070
|
-
code: ret.code,
|
|
1071
|
-
map: bindingifySourcemap$1(map),
|
|
1072
|
-
moduleType: ret.moduleType,
|
|
1073
|
-
sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
|
|
1074
|
-
};
|
|
1075
|
-
},
|
|
1076
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
1077
|
-
filter: bindingifyLoadFilter(options.filter)
|
|
1078
|
-
};
|
|
1079
|
-
}
|
|
1080
|
-
function preProcessSourceMap(ret, id) {
|
|
1081
|
-
if (!ret.map) return;
|
|
1082
|
-
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
1083
|
-
if (!isEmptySourcemapFiled(map.sources)) {
|
|
1084
|
-
const directory = node_path.default.dirname(id) || ".";
|
|
1085
|
-
const sourceRoot = map.sourceRoot || ".";
|
|
1086
|
-
map.sources = map.sources.map((source) => node_path.default.resolve(directory, sourceRoot, source));
|
|
1087
|
-
}
|
|
1088
|
-
return map;
|
|
1089
|
-
}
|
|
1090
|
-
function bindingifyModuleParsed(args) {
|
|
1091
|
-
const hook = args.plugin.moduleParsed;
|
|
1092
|
-
if (!hook) return {};
|
|
1093
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1094
|
-
return {
|
|
1095
|
-
plugin: async (ctx, moduleInfo) => {
|
|
1096
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
1097
|
-
},
|
|
1098
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
//#endregion
|
|
1103
|
-
//#region src/utils/bindingify-output-options.ts
|
|
1104
|
-
function bindingifyOutputOptions(outputOptions) {
|
|
1105
|
-
const { dir, format, exports: exports$1, hashCharacters, sourcemap, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName } = outputOptions;
|
|
1106
|
-
return {
|
|
1107
|
-
dir,
|
|
1108
|
-
file: file == null ? void 0 : file,
|
|
1109
|
-
format: bindingifyFormat(format),
|
|
1110
|
-
exports: exports$1,
|
|
1111
|
-
hashCharacters,
|
|
1112
|
-
sourcemap: bindingifySourcemap(sourcemap),
|
|
1113
|
-
sourcemapDebugIds,
|
|
1114
|
-
sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
|
|
1115
|
-
sourcemapPathTransform,
|
|
1116
|
-
banner: bindingifyAddon(banner),
|
|
1117
|
-
footer: bindingifyAddon(footer),
|
|
1118
|
-
intro: bindingifyAddon(intro),
|
|
1119
|
-
outro: bindingifyAddon(outro),
|
|
1120
|
-
extend: outputOptions.extend,
|
|
1121
|
-
globals,
|
|
1122
|
-
esModule,
|
|
1123
|
-
name,
|
|
1124
|
-
assetFileNames: bindingifyAssetFilenames(assetFileNames),
|
|
1125
|
-
entryFileNames,
|
|
1126
|
-
chunkFileNames,
|
|
1127
|
-
cssEntryFileNames,
|
|
1128
|
-
cssChunkFileNames,
|
|
1129
|
-
plugins: [],
|
|
1130
|
-
minify: outputOptions.minify,
|
|
1131
|
-
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
1132
|
-
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
1133
|
-
advancedChunks: outputOptions.advancedChunks,
|
|
1134
|
-
polyfillRequire: outputOptions.polyfillRequire,
|
|
1135
|
-
target: outputOptions.target,
|
|
1136
|
-
sanitizeFileName
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
function bindingifyAddon(configAddon) {
|
|
1140
|
-
return async (chunk) => {
|
|
1141
|
-
if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
|
|
1142
|
-
return configAddon || "";
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
function bindingifyFormat(format) {
|
|
1146
|
-
switch (format) {
|
|
1147
|
-
case void 0:
|
|
1148
|
-
case "es":
|
|
1149
|
-
case "esm":
|
|
1150
|
-
case "module": return "es";
|
|
1151
|
-
case "cjs":
|
|
1152
|
-
case "commonjs": return "cjs";
|
|
1153
|
-
case "iife": return "iife";
|
|
1154
|
-
case "umd": return "umd";
|
|
1155
|
-
case "experimental-app": return "app";
|
|
1156
|
-
default: unimplemented(`output.format: ${format}`);
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
function bindingifySourcemap(sourcemap) {
|
|
1160
|
-
switch (sourcemap) {
|
|
1161
|
-
case true: return "file";
|
|
1162
|
-
case "inline": return "inline";
|
|
1163
|
-
case false:
|
|
1164
|
-
case void 0: return void 0;
|
|
1165
|
-
case "hidden": return "hidden";
|
|
1166
|
-
default: throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
|
|
1170
|
-
return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
|
|
1171
|
-
}
|
|
1172
|
-
function bindingifyAssetFilenames(assetFileNames) {
|
|
1173
|
-
if (typeof assetFileNames === "function") return (asset) => {
|
|
1174
|
-
return assetFileNames({
|
|
1175
|
-
names: asset.names,
|
|
1176
|
-
originalFileNames: asset.originalFileNames,
|
|
1177
|
-
source: transformAssetSource(asset.source),
|
|
1178
|
-
type: "asset"
|
|
1179
|
-
});
|
|
1180
|
-
};
|
|
1181
|
-
return assetFileNames;
|
|
409
|
+
//#region src/utils/validator.ts
|
|
410
|
+
const StringOrRegExpSchema = valibot.union([valibot.string(), valibot.instance(RegExp)]);
|
|
411
|
+
const LogLevelSchema = valibot.union([
|
|
412
|
+
valibot.literal("debug"),
|
|
413
|
+
valibot.literal("info"),
|
|
414
|
+
valibot.literal("warn")
|
|
415
|
+
]);
|
|
416
|
+
const LogLevelOptionSchema = valibot.union([LogLevelSchema, valibot.literal("silent")]);
|
|
417
|
+
const LogLevelWithErrorSchema = valibot.union([LogLevelSchema, valibot.literal("error")]);
|
|
418
|
+
const RollupLogSchema = valibot.any();
|
|
419
|
+
const RollupLogWithStringSchema = valibot.union([RollupLogSchema, valibot.string()]);
|
|
420
|
+
const InputOptionSchema = valibot.union([
|
|
421
|
+
valibot.string(),
|
|
422
|
+
valibot.array(valibot.string()),
|
|
423
|
+
valibot.record(valibot.string(), valibot.string())
|
|
424
|
+
]);
|
|
425
|
+
const ExternalSchema = valibot.union([
|
|
426
|
+
StringOrRegExpSchema,
|
|
427
|
+
valibot.array(StringOrRegExpSchema),
|
|
428
|
+
valibot.pipe(valibot.function(), valibot.args(valibot.tuple([
|
|
429
|
+
valibot.string(),
|
|
430
|
+
valibot.optional(valibot.string()),
|
|
431
|
+
valibot.boolean()
|
|
432
|
+
])), valibot.returns(valibot.nullish(valibot.boolean())))
|
|
433
|
+
]);
|
|
434
|
+
const ModuleTypesSchema = valibot.record(valibot.string(), valibot.union([
|
|
435
|
+
valibot.literal("base64"),
|
|
436
|
+
valibot.literal("binary"),
|
|
437
|
+
valibot.literal("css"),
|
|
438
|
+
valibot.literal("dataurl"),
|
|
439
|
+
valibot.literal("empty"),
|
|
440
|
+
valibot.literal("js"),
|
|
441
|
+
valibot.literal("json"),
|
|
442
|
+
valibot.literal("jsx"),
|
|
443
|
+
valibot.literal("text"),
|
|
444
|
+
valibot.literal("ts"),
|
|
445
|
+
valibot.literal("tsx")
|
|
446
|
+
]));
|
|
447
|
+
const JsxOptionsSchema = valibot.strictObject({
|
|
448
|
+
development: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Development specific information")),
|
|
449
|
+
factory: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Jsx element transformation")),
|
|
450
|
+
fragment: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Jsx fragment transformation")),
|
|
451
|
+
importSource: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Import the factory of element and fragment if mode is classic")),
|
|
452
|
+
jsxImportSource: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Import the factory of element and fragment if mode is automatic")),
|
|
453
|
+
mode: valibot.pipe(valibot.optional(valibot.union([
|
|
454
|
+
valibot.literal("classic"),
|
|
455
|
+
valibot.literal("automatic"),
|
|
456
|
+
valibot.literal("preserve")
|
|
457
|
+
])), valibot.description("Jsx transformation mode")),
|
|
458
|
+
refresh: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("React refresh transformation"))
|
|
459
|
+
});
|
|
460
|
+
const WatchOptionsSchema = valibot.strictObject({
|
|
461
|
+
chokidar: valibot.optional(valibot.never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
|
|
462
|
+
exclude: valibot.optional(valibot.union([StringOrRegExpSchema, valibot.array(StringOrRegExpSchema)])),
|
|
463
|
+
include: valibot.optional(valibot.union([StringOrRegExpSchema, valibot.array(StringOrRegExpSchema)])),
|
|
464
|
+
notify: valibot.pipe(valibot.optional(valibot.strictObject({
|
|
465
|
+
compareContents: valibot.optional(valibot.boolean()),
|
|
466
|
+
pollInterval: valibot.optional(valibot.number())
|
|
467
|
+
})), valibot.description("Notify options")),
|
|
468
|
+
skipWrite: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Skip the bundle.write() step")),
|
|
469
|
+
buildDelay: valibot.pipe(valibot.optional(valibot.number()), valibot.description("Throttle watch rebuilds"))
|
|
470
|
+
});
|
|
471
|
+
const ChecksOptionsSchema = valibot.strictObject({ circularDependency: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Whether to emit warnings when detecting circular dependencies")) });
|
|
472
|
+
const MinifyOptionsSchema = valibot.strictObject({
|
|
473
|
+
mangle: valibot.boolean(),
|
|
474
|
+
compress: valibot.boolean(),
|
|
475
|
+
deadCodeElimination: valibot.boolean(),
|
|
476
|
+
removeWhitespace: valibot.boolean()
|
|
477
|
+
});
|
|
478
|
+
const ResolveOptionsSchema = valibot.strictObject({
|
|
479
|
+
alias: valibot.optional(valibot.record(valibot.string(), valibot.union([valibot.string(), valibot.array(valibot.string())]))),
|
|
480
|
+
aliasFields: valibot.optional(valibot.array(valibot.array(valibot.string()))),
|
|
481
|
+
conditionNames: valibot.optional(valibot.array(valibot.string())),
|
|
482
|
+
extensionAlias: valibot.optional(valibot.record(valibot.string(), valibot.array(valibot.string()))),
|
|
483
|
+
exportsFields: valibot.optional(valibot.array(valibot.array(valibot.string()))),
|
|
484
|
+
extensions: valibot.optional(valibot.array(valibot.string())),
|
|
485
|
+
mainFields: valibot.optional(valibot.array(valibot.string())),
|
|
486
|
+
mainFiles: valibot.optional(valibot.array(valibot.string())),
|
|
487
|
+
modules: valibot.optional(valibot.array(valibot.string())),
|
|
488
|
+
symlinks: valibot.optional(valibot.boolean()),
|
|
489
|
+
tsconfigFilename: valibot.optional(valibot.string())
|
|
490
|
+
});
|
|
491
|
+
const TreeshakingOptionsSchema = valibot.union([valibot.boolean(), valibot.looseObject({ annotations: valibot.optional(valibot.boolean()) })]);
|
|
492
|
+
const OnLogSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([
|
|
493
|
+
LogLevelSchema,
|
|
494
|
+
RollupLogSchema,
|
|
495
|
+
valibot.pipe(valibot.function(), valibot.args(valibot.tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
|
|
496
|
+
])));
|
|
497
|
+
const OnwarnSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([RollupLogSchema, valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.union([RollupLogWithStringSchema, valibot.pipe(valibot.function(), valibot.returns(RollupLogWithStringSchema))])])))])));
|
|
498
|
+
const InputOptionsSchema = valibot.strictObject({
|
|
499
|
+
input: valibot.optional(InputOptionSchema),
|
|
500
|
+
plugins: valibot.optional(valibot.custom(() => true)),
|
|
501
|
+
external: valibot.optional(ExternalSchema),
|
|
502
|
+
resolve: valibot.optional(ResolveOptionsSchema),
|
|
503
|
+
cwd: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Current working directory")),
|
|
504
|
+
platform: valibot.pipe(valibot.optional(valibot.union([
|
|
505
|
+
valibot.literal("browser"),
|
|
506
|
+
valibot.literal("neutral"),
|
|
507
|
+
valibot.literal("node")
|
|
508
|
+
])), valibot.description(`Platform for which the code should be generated (node, ${require_parse_ast_index.colors.underline("browser")}, neutral)`)),
|
|
509
|
+
shimMissingExports: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Create shim variables for missing exports")),
|
|
510
|
+
treeshake: valibot.optional(TreeshakingOptionsSchema),
|
|
511
|
+
logLevel: valibot.pipe(valibot.optional(LogLevelOptionSchema), valibot.description(`Log level (${require_parse_ast_index.colors.dim("silent")}, ${require_parse_ast_index.colors.underline(require_parse_ast_index.colors.gray("info"))}, debug, ${require_parse_ast_index.colors.yellow("warn")})`)),
|
|
512
|
+
onLog: valibot.optional(OnLogSchema),
|
|
513
|
+
onwarn: valibot.optional(OnwarnSchema),
|
|
514
|
+
moduleTypes: valibot.pipe(valibot.optional(ModuleTypesSchema), valibot.description("Module types for customized extensions")),
|
|
515
|
+
experimental: valibot.optional(valibot.strictObject({
|
|
516
|
+
disableLiveBindings: valibot.optional(valibot.boolean()),
|
|
517
|
+
enableComposingJsPlugins: valibot.optional(valibot.boolean()),
|
|
518
|
+
resolveNewUrlToAsset: valibot.optional(valibot.boolean()),
|
|
519
|
+
strictExecutionOrder: valibot.optional(valibot.boolean()),
|
|
520
|
+
hmr: valibot.optional(valibot.boolean())
|
|
521
|
+
})),
|
|
522
|
+
define: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Define global variables")),
|
|
523
|
+
inject: valibot.optional(valibot.record(valibot.string(), valibot.union([valibot.string(), valibot.tuple([valibot.string(), valibot.string()])]))),
|
|
524
|
+
profilerNames: valibot.optional(valibot.boolean()),
|
|
525
|
+
jsx: valibot.optional(valibot.union([valibot.boolean(), JsxOptionsSchema])),
|
|
526
|
+
watch: valibot.optional(valibot.union([WatchOptionsSchema, valibot.literal(false)])),
|
|
527
|
+
dropLabels: valibot.pipe(valibot.optional(valibot.array(valibot.string())), valibot.description("Remove labeled statements with these label names")),
|
|
528
|
+
checks: valibot.optional(ChecksOptionsSchema),
|
|
529
|
+
keepNames: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Keep function/class name"))
|
|
530
|
+
});
|
|
531
|
+
const InputCliOverrideSchema = valibot.strictObject({
|
|
532
|
+
external: valibot.pipe(valibot.optional(valibot.array(valibot.string())), valibot.description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
|
|
533
|
+
inject: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Inject import statements on demand")),
|
|
534
|
+
treeshake: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("enable treeshaking")),
|
|
535
|
+
jsx: valibot.pipe(valibot.optional(JsxOptionsSchema), valibot.description("enable jsx"))
|
|
536
|
+
});
|
|
537
|
+
const InputCliOptionsSchema = valibot.omit(valibot.strictObject({
|
|
538
|
+
...InputOptionsSchema.entries,
|
|
539
|
+
...InputCliOverrideSchema.entries
|
|
540
|
+
}), [
|
|
541
|
+
"input",
|
|
542
|
+
"plugins",
|
|
543
|
+
"onwarn",
|
|
544
|
+
"onLog",
|
|
545
|
+
"resolve",
|
|
546
|
+
"experimental",
|
|
547
|
+
"profilerNames",
|
|
548
|
+
"watch"
|
|
549
|
+
]);
|
|
550
|
+
var ESTarget = function(ESTarget$1) {
|
|
551
|
+
ESTarget$1["ES6"] = "es6";
|
|
552
|
+
ESTarget$1["ES2015"] = "es2015";
|
|
553
|
+
ESTarget$1["ES2016"] = "es2016";
|
|
554
|
+
ESTarget$1["ES2017"] = "es2017";
|
|
555
|
+
ESTarget$1["ES2018"] = "es2018";
|
|
556
|
+
ESTarget$1["ES2019"] = "es2019";
|
|
557
|
+
ESTarget$1["ES2020"] = "es2020";
|
|
558
|
+
ESTarget$1["ES2021"] = "es2021";
|
|
559
|
+
ESTarget$1["ES2022"] = "es2022";
|
|
560
|
+
ESTarget$1["ES2023"] = "es2023";
|
|
561
|
+
ESTarget$1["ES2024"] = "es2024";
|
|
562
|
+
ESTarget$1["ESNext"] = "esnext";
|
|
563
|
+
return ESTarget$1;
|
|
564
|
+
}(ESTarget || {});
|
|
565
|
+
const ModuleFormatSchema = valibot.union([
|
|
566
|
+
valibot.literal("es"),
|
|
567
|
+
valibot.literal("cjs"),
|
|
568
|
+
valibot.literal("esm"),
|
|
569
|
+
valibot.literal("module"),
|
|
570
|
+
valibot.literal("commonjs"),
|
|
571
|
+
valibot.literal("iife"),
|
|
572
|
+
valibot.literal("umd")
|
|
573
|
+
]);
|
|
574
|
+
const AddonFunctionSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.custom(() => true)])), valibot.returnsAsync(valibot.unionAsync([valibot.string(), valibot.pipeAsync(valibot.promise(), valibot.awaitAsync(), valibot.string())])));
|
|
575
|
+
const ChunkFileNamesSchema = valibot.union([valibot.string(), valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.custom(() => true)])), valibot.returns(valibot.string()))]);
|
|
576
|
+
const AssetFileNamesSchema = valibot.union([valibot.string(), valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.custom(() => true)])), valibot.returns(valibot.string()))]);
|
|
577
|
+
const SanitizeFileNameSchema = valibot.union([valibot.boolean(), valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.string()])), valibot.returns(valibot.string()))]);
|
|
578
|
+
const GlobalsFunctionSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.string()])), valibot.returns(valibot.string()));
|
|
579
|
+
const AdvancedChunksSchema = valibot.strictObject({
|
|
580
|
+
minSize: valibot.optional(valibot.number()),
|
|
581
|
+
maxSize: valibot.optional(valibot.number()),
|
|
582
|
+
minModuleSize: valibot.optional(valibot.number()),
|
|
583
|
+
maxModuleSize: valibot.optional(valibot.number()),
|
|
584
|
+
minShareCount: valibot.optional(valibot.number()),
|
|
585
|
+
groups: valibot.optional(valibot.array(valibot.strictObject({
|
|
586
|
+
name: valibot.string(),
|
|
587
|
+
test: valibot.optional(valibot.union([valibot.string(), valibot.instance(RegExp)])),
|
|
588
|
+
priority: valibot.optional(valibot.number()),
|
|
589
|
+
minSize: valibot.optional(valibot.number()),
|
|
590
|
+
minShareCount: valibot.optional(valibot.number()),
|
|
591
|
+
maxSize: valibot.optional(valibot.number()),
|
|
592
|
+
minModuleSize: valibot.optional(valibot.number()),
|
|
593
|
+
maxModuleSize: valibot.optional(valibot.number())
|
|
594
|
+
})))
|
|
595
|
+
});
|
|
596
|
+
const OutputOptionsSchema = valibot.strictObject({
|
|
597
|
+
dir: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Output directory, defaults to `dist` if `file` is not set")),
|
|
598
|
+
file: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Single output file")),
|
|
599
|
+
exports: valibot.pipe(valibot.optional(valibot.union([
|
|
600
|
+
valibot.literal("auto"),
|
|
601
|
+
valibot.literal("named"),
|
|
602
|
+
valibot.literal("default"),
|
|
603
|
+
valibot.literal("none")
|
|
604
|
+
])), valibot.description(`Specify a export mode (${require_parse_ast_index.colors.underline("auto")}, named, default, none)`)),
|
|
605
|
+
hashCharacters: valibot.pipe(valibot.optional(valibot.union([
|
|
606
|
+
valibot.literal("base64"),
|
|
607
|
+
valibot.literal("base36"),
|
|
608
|
+
valibot.literal("hex")
|
|
609
|
+
])), valibot.description("Use the specified character set for file hashes")),
|
|
610
|
+
format: valibot.pipe(valibot.optional(ModuleFormatSchema), valibot.description(`Output format of the generated bundle (supports ${require_parse_ast_index.colors.underline("esm")}, cjs, and iife)`)),
|
|
611
|
+
sourcemap: valibot.pipe(valibot.optional(valibot.union([
|
|
612
|
+
valibot.boolean(),
|
|
613
|
+
valibot.literal("inline"),
|
|
614
|
+
valibot.literal("hidden")
|
|
615
|
+
])), valibot.description(`Generate sourcemap (\`-s inline\` for inline, or ${require_parse_ast_index.colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
|
|
616
|
+
sourcemapDebugIds: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Inject sourcemap debug IDs")),
|
|
617
|
+
sourcemapIgnoreList: valibot.optional(valibot.union([valibot.boolean(), valibot.custom(() => true)])),
|
|
618
|
+
sourcemapPathTransform: valibot.optional(valibot.custom(() => true)),
|
|
619
|
+
banner: valibot.optional(valibot.union([valibot.string(), AddonFunctionSchema])),
|
|
620
|
+
footer: valibot.optional(valibot.union([valibot.string(), AddonFunctionSchema])),
|
|
621
|
+
intro: valibot.optional(valibot.union([valibot.string(), AddonFunctionSchema])),
|
|
622
|
+
outro: valibot.optional(valibot.union([valibot.string(), AddonFunctionSchema])),
|
|
623
|
+
extend: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Extend global variable defined by name in IIFE / UMD formats")),
|
|
624
|
+
esModule: valibot.optional(valibot.union([valibot.boolean(), valibot.literal("if-default-prop")])),
|
|
625
|
+
assetFileNames: valibot.optional(AssetFileNamesSchema),
|
|
626
|
+
entryFileNames: valibot.optional(ChunkFileNamesSchema),
|
|
627
|
+
chunkFileNames: valibot.optional(ChunkFileNamesSchema),
|
|
628
|
+
cssEntryFileNames: valibot.optional(ChunkFileNamesSchema),
|
|
629
|
+
cssChunkFileNames: valibot.optional(ChunkFileNamesSchema),
|
|
630
|
+
sanitizeFileName: valibot.optional(SanitizeFileNameSchema),
|
|
631
|
+
minify: valibot.pipe(valibot.optional(valibot.union([valibot.boolean(), MinifyOptionsSchema])), valibot.description("Minify the bundled file")),
|
|
632
|
+
name: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name for UMD / IIFE format outputs")),
|
|
633
|
+
globals: valibot.pipe(valibot.optional(valibot.union([valibot.record(valibot.string(), valibot.string()), GlobalsFunctionSchema])), valibot.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
634
|
+
externalLiveBindings: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("external live bindings")),
|
|
635
|
+
inlineDynamicImports: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Inline dynamic imports")),
|
|
636
|
+
advancedChunks: valibot.optional(AdvancedChunksSchema),
|
|
637
|
+
comments: valibot.pipe(valibot.optional(valibot.union([valibot.literal("none"), valibot.literal("preserve-legal")])), valibot.description("Control comments in the output")),
|
|
638
|
+
target: valibot.pipe(valibot.optional(valibot.enum(ESTarget)), valibot.description("The JavaScript target environment")),
|
|
639
|
+
plugins: valibot.optional(valibot.custom(() => true))
|
|
640
|
+
});
|
|
641
|
+
const getAddonDescription = (placement, wrapper) => {
|
|
642
|
+
return `Code to insert the ${require_parse_ast_index.colors.bold(placement)} of the bundled file (${require_parse_ast_index.colors.bold(wrapper)} the wrapper function)`;
|
|
643
|
+
};
|
|
644
|
+
const OutputCliOverrideSchema = valibot.strictObject({
|
|
645
|
+
assetFileNames: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name pattern for asset files")),
|
|
646
|
+
entryFileNames: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name pattern for emitted entry chunks")),
|
|
647
|
+
chunkFileNames: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name pattern for emitted secondary chunks")),
|
|
648
|
+
cssEntryFileNames: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name pattern for emitted css entry chunks")),
|
|
649
|
+
cssChunkFileNames: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Name pattern for emitted css secondary chunks")),
|
|
650
|
+
sanitizeFileName: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Sanitize file name")),
|
|
651
|
+
banner: valibot.pipe(valibot.optional(valibot.string()), valibot.description(getAddonDescription("top", "outside"))),
|
|
652
|
+
footer: valibot.pipe(valibot.optional(valibot.string()), valibot.description(getAddonDescription("bottom", "outside"))),
|
|
653
|
+
intro: valibot.pipe(valibot.optional(valibot.string()), valibot.description(getAddonDescription("top", "inside"))),
|
|
654
|
+
outro: valibot.pipe(valibot.optional(valibot.string()), valibot.description(getAddonDescription("bottom", "inside"))),
|
|
655
|
+
esModule: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
|
|
656
|
+
globals: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
657
|
+
advancedChunks: valibot.pipe(valibot.optional(valibot.strictObject({
|
|
658
|
+
minSize: valibot.pipe(valibot.optional(valibot.number()), valibot.description("Minimum size of the chunk")),
|
|
659
|
+
minShareCount: valibot.pipe(valibot.optional(valibot.number()), valibot.description("Minimum share count of the chunk"))
|
|
660
|
+
})), valibot.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
661
|
+
minify: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Minify the bundled file"))
|
|
662
|
+
});
|
|
663
|
+
const OutputCliOptionsSchema = valibot.omit(valibot.strictObject({
|
|
664
|
+
...OutputOptionsSchema.entries,
|
|
665
|
+
...OutputCliOverrideSchema.entries
|
|
666
|
+
}), [
|
|
667
|
+
"sourcemapIgnoreList",
|
|
668
|
+
"sourcemapPathTransform",
|
|
669
|
+
"plugins"
|
|
670
|
+
]);
|
|
671
|
+
const CliOptionsSchema = valibot.strictObject({
|
|
672
|
+
config: valibot.pipe(valibot.optional(valibot.union([valibot.string(), valibot.boolean()])), valibot.description("Path to the config file (default: `rolldown.config.js`)")),
|
|
673
|
+
help: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Show help")),
|
|
674
|
+
version: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Show version number")),
|
|
675
|
+
watch: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Watch files in bundle and rebuild on changes")),
|
|
676
|
+
...InputCliOptionsSchema.entries,
|
|
677
|
+
...OutputCliOptionsSchema.entries
|
|
678
|
+
});
|
|
679
|
+
function validateCliOptions(options) {
|
|
680
|
+
let parsed = valibot.safeParse(CliOptionsSchema, options);
|
|
681
|
+
return [parsed.output, parsed.issues?.map((issue) => issue.path?.join(", ")).filter((v) => v !== void 0)];
|
|
1182
682
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
return this.inner.format;
|
|
1206
|
-
}
|
|
1207
|
-
get exports() {
|
|
1208
|
-
return this.inner.exports;
|
|
1209
|
-
}
|
|
1210
|
-
get sourcemap() {
|
|
1211
|
-
return this.inner.sourcemap;
|
|
1212
|
-
}
|
|
1213
|
-
get cssEntryFileNames() {
|
|
1214
|
-
return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
|
|
1215
|
-
}
|
|
1216
|
-
get cssChunkFileNames() {
|
|
1217
|
-
return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
|
|
1218
|
-
}
|
|
1219
|
-
get shimMissingExports() {
|
|
1220
|
-
return this.inner.shimMissingExports;
|
|
1221
|
-
}
|
|
1222
|
-
get name() {
|
|
1223
|
-
return this.inner.name ?? void 0;
|
|
1224
|
-
}
|
|
1225
|
-
get file() {
|
|
1226
|
-
return this.inner.file ?? void 0;
|
|
1227
|
-
}
|
|
1228
|
-
get inlineDynamicImports() {
|
|
1229
|
-
return this.inner.inlineDynamicImports;
|
|
1230
|
-
}
|
|
1231
|
-
get externalLiveBindings() {
|
|
1232
|
-
return this.inner.externalLiveBindings;
|
|
1233
|
-
}
|
|
1234
|
-
get banner() {
|
|
1235
|
-
return normalizeAddon(this.outputOptions.banner);
|
|
1236
|
-
}
|
|
1237
|
-
get footer() {
|
|
1238
|
-
return normalizeAddon(this.outputOptions.footer);
|
|
1239
|
-
}
|
|
1240
|
-
get intro() {
|
|
1241
|
-
return normalizeAddon(this.outputOptions.intro);
|
|
1242
|
-
}
|
|
1243
|
-
get outro() {
|
|
1244
|
-
return normalizeAddon(this.outputOptions.outro);
|
|
1245
|
-
}
|
|
1246
|
-
get esModule() {
|
|
1247
|
-
return this.inner.esModule;
|
|
1248
|
-
}
|
|
1249
|
-
get extend() {
|
|
1250
|
-
return this.inner.extend;
|
|
1251
|
-
}
|
|
1252
|
-
get globals() {
|
|
1253
|
-
return this.inner.globals || this.outputOptions.globals;
|
|
1254
|
-
}
|
|
1255
|
-
get hashCharacters() {
|
|
1256
|
-
return this.inner.hashCharacters;
|
|
1257
|
-
}
|
|
1258
|
-
get sourcemapDebugIds() {
|
|
1259
|
-
return this.inner.sourcemapDebugIds;
|
|
1260
|
-
}
|
|
1261
|
-
get sourcemapIgnoreList() {
|
|
1262
|
-
return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
|
|
1263
|
-
}
|
|
1264
|
-
get sourcemapPathTransform() {
|
|
1265
|
-
return this.outputOptions.sourcemapPathTransform;
|
|
1266
|
-
}
|
|
1267
|
-
get minify() {
|
|
1268
|
-
return this.inner.minify;
|
|
1269
|
-
}
|
|
1270
|
-
get comments() {
|
|
1271
|
-
return this.inner.comments;
|
|
683
|
+
const inputHelperMsgRecord = { output: { ignored: true } };
|
|
684
|
+
const outputHelperMsgRecord = {};
|
|
685
|
+
function validateOption(key, options) {
|
|
686
|
+
if (process.env.ROLLDOWN_OPTIONS_VALIDATION === "loose") return;
|
|
687
|
+
let parsed = valibot.safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
|
|
688
|
+
if (!parsed.success) {
|
|
689
|
+
const errors = parsed.issues.map((issue) => {
|
|
690
|
+
const issuePaths = issue.path.map((path$2) => path$2.key);
|
|
691
|
+
let issueMsg = issue.message;
|
|
692
|
+
if (issue.type === "union") {
|
|
693
|
+
const subIssue = issue.issues?.find((i) => !(i.type !== issue.received && i.input === issue.input));
|
|
694
|
+
if (subIssue) {
|
|
695
|
+
if (subIssue.path) issuePaths.push(subIssue.path.map((path$2) => path$2.key));
|
|
696
|
+
issueMsg = subIssue.message;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const stringPath = issuePaths.join(".");
|
|
700
|
+
const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
|
|
701
|
+
if (helper && helper.ignored) return "";
|
|
702
|
+
return `- For the "${stringPath}". ${issueMsg}. ${helper ? helper.msg : ""}`;
|
|
703
|
+
}).filter(Boolean);
|
|
704
|
+
if (errors.length) throw new Error(`Failed validate ${key} options.\n` + errors.join("\n"));
|
|
1272
705
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
706
|
+
}
|
|
707
|
+
function getInputCliKeys() {
|
|
708
|
+
return valibot.keyof(InputCliOptionsSchema).options;
|
|
709
|
+
}
|
|
710
|
+
function getOutputCliKeys() {
|
|
711
|
+
return valibot.keyof(OutputCliOptionsSchema).options;
|
|
712
|
+
}
|
|
713
|
+
function getJsonSchema() {
|
|
714
|
+
return (0, __valibot_to_json_schema.toJsonSchema)(CliOptionsSchema);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/utils/asset-source.ts
|
|
719
|
+
function transformAssetSource(bindingAssetSource$1) {
|
|
720
|
+
return bindingAssetSource$1.inner;
|
|
721
|
+
}
|
|
722
|
+
function bindingAssetSource(source) {
|
|
723
|
+
return { inner: source };
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/types/sourcemap.ts
|
|
728
|
+
function bindingifySourcemap$1(map) {
|
|
729
|
+
if (map == null) return;
|
|
730
|
+
return { inner: typeof map === "string" ? map : {
|
|
731
|
+
file: map.file ?? void 0,
|
|
732
|
+
mappings: map.mappings,
|
|
733
|
+
sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
|
|
734
|
+
sources: map.sources?.map((s) => s ?? void 0),
|
|
735
|
+
sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
|
|
736
|
+
names: map.names,
|
|
737
|
+
x_google_ignoreList: map.x_google_ignoreList,
|
|
738
|
+
debugId: "debugId" in map ? map.debugId : void 0
|
|
739
|
+
} };
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/utils/error.ts
|
|
744
|
+
function normalizeErrors(rawErrors) {
|
|
745
|
+
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
|
|
746
|
+
kind: e.kind,
|
|
747
|
+
message: e.message,
|
|
748
|
+
stack: void 0
|
|
749
|
+
}));
|
|
750
|
+
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
751
|
+
for (let i = 0; i < errors.length; i++) {
|
|
752
|
+
if (i >= 5) {
|
|
753
|
+
summary += "\n...";
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
summary += getErrorMessage(errors[i]) + "\n";
|
|
1275
757
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
758
|
+
const wrapper = new Error(summary);
|
|
759
|
+
Object.defineProperty(wrapper, "errors", {
|
|
760
|
+
configurable: true,
|
|
761
|
+
enumerable: true,
|
|
762
|
+
get: () => errors,
|
|
763
|
+
set: (value) => Object.defineProperty(wrapper, "errors", {
|
|
764
|
+
configurable: true,
|
|
765
|
+
enumerable: true,
|
|
766
|
+
value
|
|
767
|
+
})
|
|
768
|
+
});
|
|
769
|
+
return wrapper;
|
|
770
|
+
}
|
|
771
|
+
function getErrorMessage(e) {
|
|
772
|
+
let s = "";
|
|
773
|
+
if (e.plugin) s += `[plugin ${e.plugin}]`;
|
|
774
|
+
const id = e.id ?? e.loc?.file;
|
|
775
|
+
if (id) {
|
|
776
|
+
s += " " + id;
|
|
777
|
+
if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
|
|
1278
778
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
779
|
+
if (s) s += "\n";
|
|
780
|
+
const message = `${e.name ?? "Error"}: ${e.message}`;
|
|
781
|
+
s += message;
|
|
782
|
+
if (e.frame) s = joinNewLine(s, e.frame);
|
|
783
|
+
if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
|
|
784
|
+
return s;
|
|
785
|
+
}
|
|
786
|
+
function joinNewLine(s1, s2) {
|
|
787
|
+
return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
|
|
1283
788
|
}
|
|
1284
789
|
|
|
1285
790
|
//#endregion
|
|
1286
|
-
//#region src/
|
|
1287
|
-
function
|
|
1288
|
-
const hook = args.plugin.renderStart;
|
|
1289
|
-
if (!hook) return {};
|
|
1290
|
-
const { handler, meta } = normalizeHook(hook);
|
|
791
|
+
//#region src/utils/transform-rendered-module.ts
|
|
792
|
+
function transformToRenderedModule(bindingRenderedModule) {
|
|
1291
793
|
return {
|
|
1292
|
-
|
|
1293
|
-
|
|
794
|
+
get code() {
|
|
795
|
+
return bindingRenderedModule.code;
|
|
1294
796
|
},
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
}
|
|
1298
|
-
function bindingifyRenderChunk(args) {
|
|
1299
|
-
const hook = args.plugin.renderChunk;
|
|
1300
|
-
if (!hook) return {};
|
|
1301
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1302
|
-
return {
|
|
1303
|
-
plugin: async (ctx, code, chunk, opts) => {
|
|
1304
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins));
|
|
1305
|
-
if (ret == null) return;
|
|
1306
|
-
if (typeof ret === "string") return { code: ret };
|
|
1307
|
-
if (!ret.map) return { code: ret.code };
|
|
1308
|
-
return {
|
|
1309
|
-
code: ret.code,
|
|
1310
|
-
map: bindingifySourcemap$1(ret.map)
|
|
1311
|
-
};
|
|
797
|
+
get renderedLength() {
|
|
798
|
+
return bindingRenderedModule.code?.length || 0;
|
|
1312
799
|
},
|
|
1313
|
-
|
|
800
|
+
get renderedExports() {
|
|
801
|
+
return bindingRenderedModule.renderedExports;
|
|
802
|
+
}
|
|
1314
803
|
};
|
|
1315
804
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
805
|
+
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region src/utils/transform-rendered-chunk.ts
|
|
808
|
+
function transformRenderedChunk(chunk) {
|
|
1320
809
|
return {
|
|
1321
|
-
|
|
1322
|
-
return
|
|
810
|
+
get name() {
|
|
811
|
+
return chunk.name;
|
|
1323
812
|
},
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1327
|
-
function bindingifyRenderError(args) {
|
|
1328
|
-
const hook = args.plugin.renderError;
|
|
1329
|
-
if (!hook) return {};
|
|
1330
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1331
|
-
return {
|
|
1332
|
-
plugin: async (ctx, err) => {
|
|
1333
|
-
handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
813
|
+
get isEntry() {
|
|
814
|
+
return chunk.isEntry;
|
|
1334
815
|
},
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
function bindingifyGenerateBundle(args) {
|
|
1339
|
-
const hook = args.plugin.generateBundle;
|
|
1340
|
-
if (!hook) return {};
|
|
1341
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1342
|
-
return {
|
|
1343
|
-
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
1344
|
-
const changed = {
|
|
1345
|
-
updated: new Set(),
|
|
1346
|
-
deleted: new Set()
|
|
1347
|
-
};
|
|
1348
|
-
const output = transformToOutputBundle(bundle, changed);
|
|
1349
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins), output, isWrite);
|
|
1350
|
-
return collectChangedBundle(changed, output);
|
|
816
|
+
get isDynamicEntry() {
|
|
817
|
+
return chunk.isDynamicEntry;
|
|
1351
818
|
},
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1355
|
-
function bindingifyWriteBundle(args) {
|
|
1356
|
-
const hook = args.plugin.writeBundle;
|
|
1357
|
-
if (!hook) return {};
|
|
1358
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1359
|
-
return {
|
|
1360
|
-
plugin: async (ctx, bundle, opts) => {
|
|
1361
|
-
const changed = {
|
|
1362
|
-
updated: new Set(),
|
|
1363
|
-
deleted: new Set()
|
|
1364
|
-
};
|
|
1365
|
-
const output = transformToOutputBundle(bundle, changed);
|
|
1366
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins), output);
|
|
1367
|
-
return collectChangedBundle(changed, output);
|
|
819
|
+
get facadeModuleId() {
|
|
820
|
+
return chunk.facadeModuleId;
|
|
1368
821
|
},
|
|
1369
|
-
|
|
822
|
+
get moduleIds() {
|
|
823
|
+
return chunk.moduleIds;
|
|
824
|
+
},
|
|
825
|
+
get exports() {
|
|
826
|
+
return chunk.exports;
|
|
827
|
+
},
|
|
828
|
+
get fileName() {
|
|
829
|
+
return chunk.fileName;
|
|
830
|
+
},
|
|
831
|
+
get imports() {
|
|
832
|
+
return chunk.imports;
|
|
833
|
+
},
|
|
834
|
+
get dynamicImports() {
|
|
835
|
+
return chunk.dynamicImports;
|
|
836
|
+
},
|
|
837
|
+
get modules() {
|
|
838
|
+
return transformChunkModules(chunk.modules);
|
|
839
|
+
}
|
|
1370
840
|
};
|
|
1371
841
|
}
|
|
1372
|
-
function
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
842
|
+
function transformChunkModules(modules) {
|
|
843
|
+
const result = {};
|
|
844
|
+
for (let i = 0; i < modules.values.length; i++) {
|
|
845
|
+
let key = modules.keys[i];
|
|
846
|
+
const mod = modules.values[i];
|
|
847
|
+
result[key] = transformToRenderedModule(mod);
|
|
848
|
+
}
|
|
849
|
+
return result;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/utils/transform-to-rollup-output.ts
|
|
854
|
+
function transformToRollupSourceMap(map) {
|
|
855
|
+
const parsed = JSON.parse(map);
|
|
856
|
+
const obj = {
|
|
857
|
+
...parsed,
|
|
858
|
+
toString() {
|
|
859
|
+
return JSON.stringify(obj);
|
|
1379
860
|
},
|
|
1380
|
-
|
|
861
|
+
toUrl() {
|
|
862
|
+
return `data:application/json;charset=utf-8;base64,${node_buffer.Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
863
|
+
}
|
|
1381
864
|
};
|
|
865
|
+
return obj;
|
|
1382
866
|
}
|
|
1383
|
-
function
|
|
1384
|
-
const
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
867
|
+
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
868
|
+
const chunk = {
|
|
869
|
+
type: "chunk",
|
|
870
|
+
get code() {
|
|
871
|
+
return bindingChunk.code;
|
|
872
|
+
},
|
|
873
|
+
fileName: bindingChunk.fileName,
|
|
874
|
+
name: bindingChunk.name,
|
|
875
|
+
get modules() {
|
|
876
|
+
return transformChunkModules(bindingChunk.modules);
|
|
877
|
+
},
|
|
878
|
+
get imports() {
|
|
879
|
+
return bindingChunk.imports;
|
|
880
|
+
},
|
|
881
|
+
get dynamicImports() {
|
|
882
|
+
return bindingChunk.dynamicImports;
|
|
883
|
+
},
|
|
884
|
+
exports: bindingChunk.exports,
|
|
885
|
+
isEntry: bindingChunk.isEntry,
|
|
886
|
+
facadeModuleId: bindingChunk.facadeModuleId || null,
|
|
887
|
+
isDynamicEntry: bindingChunk.isDynamicEntry,
|
|
888
|
+
get moduleIds() {
|
|
889
|
+
return bindingChunk.moduleIds;
|
|
1391
890
|
},
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
}
|
|
1395
|
-
function bindingifyFooter(args) {
|
|
1396
|
-
const hook = args.plugin.footer;
|
|
1397
|
-
if (!hook) return {};
|
|
1398
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1399
|
-
return {
|
|
1400
|
-
plugin: async (ctx, chunk) => {
|
|
1401
|
-
if (typeof handler === "string") return handler;
|
|
1402
|
-
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
891
|
+
get map() {
|
|
892
|
+
return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
|
|
1403
893
|
},
|
|
1404
|
-
|
|
894
|
+
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
895
|
+
preliminaryFileName: bindingChunk.preliminaryFileName
|
|
1405
896
|
};
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
return {
|
|
1412
|
-
plugin: async (ctx, chunk) => {
|
|
1413
|
-
if (typeof handler === "string") return handler;
|
|
1414
|
-
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
897
|
+
const cache = {};
|
|
898
|
+
return new Proxy(chunk, {
|
|
899
|
+
get(target, p) {
|
|
900
|
+
if (p in cache) return cache[p];
|
|
901
|
+
return target[p];
|
|
1415
902
|
},
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
const hook = args.plugin.outro;
|
|
1421
|
-
if (!hook) return {};
|
|
1422
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1423
|
-
return {
|
|
1424
|
-
plugin: async (ctx, chunk) => {
|
|
1425
|
-
if (typeof handler === "string") return handler;
|
|
1426
|
-
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
903
|
+
set(target, p, newValue) {
|
|
904
|
+
cache[p] = newValue;
|
|
905
|
+
changed?.updated.add(bindingChunk.fileName);
|
|
906
|
+
return true;
|
|
1427
907
|
},
|
|
1428
|
-
|
|
1429
|
-
|
|
908
|
+
has(target, p) {
|
|
909
|
+
if (p in cache) return true;
|
|
910
|
+
return p in target;
|
|
911
|
+
}
|
|
912
|
+
});
|
|
1430
913
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
plugin: async (ctx, id, event) => {
|
|
1440
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event });
|
|
914
|
+
function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
915
|
+
const asset = {
|
|
916
|
+
type: "asset",
|
|
917
|
+
fileName: bindingAsset.fileName,
|
|
918
|
+
originalFileName: bindingAsset.originalFileName || null,
|
|
919
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
920
|
+
get source() {
|
|
921
|
+
return transformAssetSource(bindingAsset.source);
|
|
1441
922
|
},
|
|
1442
|
-
|
|
923
|
+
name: bindingAsset.name ?? void 0,
|
|
924
|
+
names: bindingAsset.names
|
|
1443
925
|
};
|
|
926
|
+
const cache = {};
|
|
927
|
+
return new Proxy(asset, {
|
|
928
|
+
get(target, p) {
|
|
929
|
+
if (p in cache) return cache[p];
|
|
930
|
+
return target[p];
|
|
931
|
+
},
|
|
932
|
+
set(target, p, newValue) {
|
|
933
|
+
cache[p] = newValue;
|
|
934
|
+
changed?.updated.add(bindingAsset.fileName);
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
});
|
|
1444
938
|
}
|
|
1445
|
-
function
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
939
|
+
function transformToRollupOutput(output, changed) {
|
|
940
|
+
handleOutputErrors(output);
|
|
941
|
+
const { chunks, assets } = output;
|
|
942
|
+
return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
|
|
943
|
+
}
|
|
944
|
+
function handleOutputErrors(output) {
|
|
945
|
+
const rawErrors = output.errors;
|
|
946
|
+
if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
|
|
947
|
+
}
|
|
948
|
+
function transformToOutputBundle(output, changed) {
|
|
949
|
+
const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
|
|
950
|
+
return new Proxy(bundle, { deleteProperty(target, property) {
|
|
951
|
+
if (typeof property === "string") changed.deleted.add(property);
|
|
952
|
+
return true;
|
|
953
|
+
} });
|
|
954
|
+
}
|
|
955
|
+
function collectChangedBundle(changed, bundle) {
|
|
956
|
+
const assets = [];
|
|
957
|
+
const chunks = [];
|
|
958
|
+
for (const key in bundle) {
|
|
959
|
+
if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
|
|
960
|
+
const item = bundle[key];
|
|
961
|
+
if (item.type === "asset") assets.push({
|
|
962
|
+
filename: item.fileName,
|
|
963
|
+
originalFileNames: item.originalFileNames,
|
|
964
|
+
source: bindingAssetSource(item.source),
|
|
965
|
+
names: item.names
|
|
966
|
+
});
|
|
967
|
+
else chunks.push({
|
|
968
|
+
code: item.code,
|
|
969
|
+
filename: item.fileName,
|
|
970
|
+
name: item.name,
|
|
971
|
+
isEntry: item.isEntry,
|
|
972
|
+
exports: item.exports,
|
|
973
|
+
modules: {},
|
|
974
|
+
imports: item.imports,
|
|
975
|
+
dynamicImports: item.dynamicImports,
|
|
976
|
+
facadeModuleId: item.facadeModuleId || void 0,
|
|
977
|
+
isDynamicEntry: item.isDynamicEntry,
|
|
978
|
+
moduleIds: item.moduleIds,
|
|
979
|
+
map: bindingifySourcemap$1(item.map),
|
|
980
|
+
sourcemapFilename: item.sourcemapFileName || void 0,
|
|
981
|
+
preliminaryFilename: item.preliminaryFileName
|
|
982
|
+
});
|
|
983
|
+
}
|
|
1449
984
|
return {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
985
|
+
assets,
|
|
986
|
+
chunks,
|
|
987
|
+
deleted: Array.from(changed.deleted)
|
|
1454
988
|
};
|
|
1455
989
|
}
|
|
1456
990
|
|
|
1457
991
|
//#endregion
|
|
1458
|
-
//#region src/
|
|
1459
|
-
function
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
renderChunkMeta,
|
|
1510
|
-
augmentChunkHash,
|
|
1511
|
-
augmentChunkHashMeta,
|
|
1512
|
-
renderStart,
|
|
1513
|
-
renderStartMeta,
|
|
1514
|
-
renderError,
|
|
1515
|
-
renderErrorMeta,
|
|
1516
|
-
generateBundle,
|
|
1517
|
-
generateBundleMeta,
|
|
1518
|
-
writeBundle,
|
|
1519
|
-
writeBundleMeta,
|
|
1520
|
-
closeBundle,
|
|
1521
|
-
closeBundleMeta,
|
|
1522
|
-
banner,
|
|
1523
|
-
bannerMeta,
|
|
1524
|
-
footer,
|
|
1525
|
-
footerMeta,
|
|
1526
|
-
intro,
|
|
1527
|
-
introMeta,
|
|
1528
|
-
outro,
|
|
1529
|
-
outroMeta,
|
|
1530
|
-
watchChange,
|
|
1531
|
-
watchChangeMeta,
|
|
1532
|
-
closeWatcher,
|
|
1533
|
-
closeWatcherMeta
|
|
1534
|
-
};
|
|
1535
|
-
return wrapHandlers(result);
|
|
1536
|
-
}
|
|
1537
|
-
function wrapHandlers(plugin) {
|
|
1538
|
-
for (const hookName of [
|
|
1539
|
-
"buildStart",
|
|
1540
|
-
"resolveId",
|
|
1541
|
-
"resolveDynamicImport",
|
|
1542
|
-
"buildEnd",
|
|
1543
|
-
"transform",
|
|
1544
|
-
"moduleParsed",
|
|
1545
|
-
"load",
|
|
1546
|
-
"renderChunk",
|
|
1547
|
-
"augmentChunkHash",
|
|
1548
|
-
"renderStart",
|
|
1549
|
-
"renderError",
|
|
1550
|
-
"generateBundle",
|
|
1551
|
-
"writeBundle",
|
|
1552
|
-
"closeBundle",
|
|
1553
|
-
"banner",
|
|
1554
|
-
"footer",
|
|
1555
|
-
"intro",
|
|
1556
|
-
"outro",
|
|
1557
|
-
"watchChange",
|
|
1558
|
-
"closeWatcher"
|
|
1559
|
-
]) {
|
|
1560
|
-
const handler = plugin[hookName];
|
|
1561
|
-
if (handler) plugin[hookName] = async (...args) => {
|
|
1562
|
-
try {
|
|
1563
|
-
return await handler(...args);
|
|
1564
|
-
} catch (e) {
|
|
1565
|
-
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e, plugin.name, {
|
|
1566
|
-
hook: hookName,
|
|
1567
|
-
id: hookName === "transform" ? args[2] : void 0
|
|
1568
|
-
}));
|
|
1569
|
-
}
|
|
992
|
+
//#region src/utils/transform-sourcemap.ts
|
|
993
|
+
function isEmptySourcemapFiled(array) {
|
|
994
|
+
if (!array) return true;
|
|
995
|
+
if (array.length === 0 || !array[0]) return true;
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
999
|
+
if (!rawMap) return;
|
|
1000
|
+
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
1001
|
+
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
1002
|
+
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
1003
|
+
return map;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
//#endregion
|
|
1007
|
+
//#region src/utils/transform-module-info.ts
|
|
1008
|
+
function transformModuleInfo(info, option) {
|
|
1009
|
+
return {
|
|
1010
|
+
get ast() {
|
|
1011
|
+
return unsupported("ModuleInfo#ast");
|
|
1012
|
+
},
|
|
1013
|
+
get code() {
|
|
1014
|
+
return info.code;
|
|
1015
|
+
},
|
|
1016
|
+
id: info.id,
|
|
1017
|
+
importers: info.importers,
|
|
1018
|
+
dynamicImporters: info.dynamicImporters,
|
|
1019
|
+
importedIds: info.importedIds,
|
|
1020
|
+
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
1021
|
+
exports: info.exports,
|
|
1022
|
+
isEntry: info.isEntry,
|
|
1023
|
+
...option
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
//#endregion
|
|
1028
|
+
//#region src/plugin/minimal-plugin-context.ts
|
|
1029
|
+
var MinimalPluginContext = class {
|
|
1030
|
+
info;
|
|
1031
|
+
warn;
|
|
1032
|
+
debug;
|
|
1033
|
+
meta;
|
|
1034
|
+
constructor(onLog, logLevel, pluginName) {
|
|
1035
|
+
this.pluginName = pluginName;
|
|
1036
|
+
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1037
|
+
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
1038
|
+
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
1039
|
+
this.meta = {
|
|
1040
|
+
rollupVersion: "4.23.0",
|
|
1041
|
+
rolldownVersion: VERSION,
|
|
1042
|
+
watchMode: false
|
|
1570
1043
|
};
|
|
1571
1044
|
}
|
|
1572
|
-
|
|
1045
|
+
error(e) {
|
|
1046
|
+
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e), this.pluginName));
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region src/utils/transform-side-effects.ts
|
|
1052
|
+
function bindingifySideEffects(sideEffects) {
|
|
1053
|
+
switch (sideEffects) {
|
|
1054
|
+
case true: return require_parse_ast_index.import_binding.BindingHookSideEffects.True;
|
|
1055
|
+
case false: return require_parse_ast_index.import_binding.BindingHookSideEffects.False;
|
|
1056
|
+
case "no-treeshake": return require_parse_ast_index.import_binding.BindingHookSideEffects.NoTreeshake;
|
|
1057
|
+
case null:
|
|
1058
|
+
case void 0: return void 0;
|
|
1059
|
+
default: throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
1060
|
+
}
|
|
1573
1061
|
}
|
|
1574
1062
|
|
|
1575
1063
|
//#endregion
|
|
1576
|
-
//#region src/plugin/plugin-context
|
|
1577
|
-
var
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
} else {
|
|
1588
|
-
this.moduleOptionMap.set(id, option);
|
|
1589
|
-
return option;
|
|
1590
|
-
}
|
|
1591
|
-
return existing;
|
|
1064
|
+
//#region src/plugin/plugin-context.ts
|
|
1065
|
+
var PluginContext = class extends MinimalPluginContext {
|
|
1066
|
+
getModuleInfo;
|
|
1067
|
+
constructor(outputOptions, context, plugin, data, onLog, logLevel, currentLoadingModule) {
|
|
1068
|
+
super(onLog, logLevel, plugin.name);
|
|
1069
|
+
this.outputOptions = outputOptions;
|
|
1070
|
+
this.context = context;
|
|
1071
|
+
this.data = data;
|
|
1072
|
+
this.onLog = onLog;
|
|
1073
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1074
|
+
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
1592
1075
|
}
|
|
1593
|
-
|
|
1594
|
-
const
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1076
|
+
async load(options) {
|
|
1077
|
+
const id = options.id;
|
|
1078
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, require_parse_ast_index.logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
1079
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1080
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1081
|
+
const rawOptions = {
|
|
1082
|
+
meta: options.meta || {},
|
|
1083
|
+
moduleSideEffects: options.moduleSideEffects || null,
|
|
1084
|
+
invalidate: false
|
|
1085
|
+
};
|
|
1086
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1087
|
+
async function createLoadModulePromise(context, data) {
|
|
1088
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
1089
|
+
if (loadPromise) return loadPromise;
|
|
1090
|
+
let resolveFn;
|
|
1091
|
+
const promise = new Promise((resolve, _) => {
|
|
1092
|
+
resolveFn = resolve;
|
|
1093
|
+
});
|
|
1094
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
1095
|
+
try {
|
|
1096
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
1097
|
+
} finally {
|
|
1098
|
+
data.loadModulePromiseMap.delete(id);
|
|
1099
|
+
}
|
|
1100
|
+
return promise;
|
|
1602
1101
|
}
|
|
1603
|
-
|
|
1102
|
+
await createLoadModulePromise(this.context, this.data);
|
|
1103
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1604
1104
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
if (
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1105
|
+
async resolve(source, importer, options) {
|
|
1106
|
+
let receipt = void 0;
|
|
1107
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1108
|
+
const res = await this.context.resolve(source, importer, {
|
|
1109
|
+
custom: receipt,
|
|
1110
|
+
skipSelf: options?.skipSelf
|
|
1111
|
+
});
|
|
1112
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1113
|
+
if (res == null) return null;
|
|
1114
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1115
|
+
return {
|
|
1116
|
+
...res,
|
|
1117
|
+
...info
|
|
1118
|
+
};
|
|
1612
1119
|
}
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1120
|
+
emitFile = (file) => {
|
|
1121
|
+
if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
|
|
1122
|
+
if (file.type === "chunk") return this.context.emitChunk(file);
|
|
1123
|
+
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
1124
|
+
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
1125
|
+
return this.context.emitFile({
|
|
1126
|
+
...file,
|
|
1127
|
+
originalFileName: file.originalFileName || void 0,
|
|
1128
|
+
source: bindingAssetSource(file.source)
|
|
1129
|
+
}, filename, fnSanitizedFileName);
|
|
1130
|
+
};
|
|
1131
|
+
getAssetFileNames(file) {
|
|
1132
|
+
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
1133
|
+
names: file.name ? [file.name] : [],
|
|
1134
|
+
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
1135
|
+
source: file.source,
|
|
1136
|
+
type: "asset"
|
|
1627
1137
|
});
|
|
1628
|
-
return info;
|
|
1629
1138
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1139
|
+
getFileName(referenceId) {
|
|
1140
|
+
return this.context.getFileName(referenceId);
|
|
1141
|
+
}
|
|
1142
|
+
getModuleIds() {
|
|
1143
|
+
return this.data.getModuleIds(this.context);
|
|
1144
|
+
}
|
|
1145
|
+
addWatchFile(id) {
|
|
1146
|
+
this.context.addWatchFile(id);
|
|
1147
|
+
}
|
|
1148
|
+
parse(input, options) {
|
|
1149
|
+
return require_parse_ast_index.parseAst(input, options);
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region src/plugin/transform-plugin-context.ts
|
|
1155
|
+
var TransformPluginContext = class extends PluginContext {
|
|
1156
|
+
constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
1157
|
+
super(outputOptions, context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
1158
|
+
this.inner = inner;
|
|
1159
|
+
this.moduleId = moduleId;
|
|
1160
|
+
this.moduleSource = moduleSource;
|
|
1161
|
+
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
1162
|
+
log = normalizeLog(log);
|
|
1163
|
+
if (pos) require_parse_ast_index.augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
1164
|
+
log.id = moduleId;
|
|
1165
|
+
log.hook = "transform";
|
|
1166
|
+
handler(log);
|
|
1167
|
+
};
|
|
1168
|
+
this.debug = getLogHandler$1(this.debug);
|
|
1169
|
+
this.warn = getLogHandler$1(this.warn);
|
|
1170
|
+
this.info = getLogHandler$1(this.info);
|
|
1171
|
+
}
|
|
1172
|
+
error(e, pos) {
|
|
1173
|
+
if (typeof e === "string") e = { message: e };
|
|
1174
|
+
if (pos) require_parse_ast_index.augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1175
|
+
e.id = this.moduleId;
|
|
1176
|
+
e.hook = "transform";
|
|
1177
|
+
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e), this.pluginName));
|
|
1178
|
+
}
|
|
1179
|
+
getCombinedSourcemap() {
|
|
1180
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
//#endregion
|
|
1185
|
+
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1186
|
+
function bindingifyPluginHookMeta(options) {
|
|
1187
|
+
return { order: bindingPluginOrder(options.order) };
|
|
1188
|
+
}
|
|
1189
|
+
function bindingPluginOrder(order) {
|
|
1190
|
+
switch (order) {
|
|
1191
|
+
case "post": return require_parse_ast_index.import_binding.BindingPluginOrder.Post;
|
|
1192
|
+
case "pre": return require_parse_ast_index.import_binding.BindingPluginOrder.Pre;
|
|
1193
|
+
case null:
|
|
1194
|
+
case void 0: return void 0;
|
|
1195
|
+
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region src/constants/plugin-context.ts
|
|
1201
|
+
const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
|
|
1202
|
+
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/plugin/bindingify-hook-filter.ts
|
|
1205
|
+
function bindingifyStringFilter(matcher) {
|
|
1206
|
+
if (typeof matcher === "string" || matcher instanceof RegExp) return { include: [matcher] };
|
|
1207
|
+
if (Array.isArray(matcher)) return { include: matcher };
|
|
1208
|
+
return {
|
|
1209
|
+
include: matcher.include ? arraify(matcher.include) : void 0,
|
|
1210
|
+
exclude: matcher.exclude ? arraify(matcher.exclude) : void 0
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
function bindingifyResolveIdFilter(filterOption) {
|
|
1214
|
+
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
|
|
1215
|
+
}
|
|
1216
|
+
function bindingifyLoadFilter(filterOption) {
|
|
1217
|
+
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
|
|
1218
|
+
}
|
|
1219
|
+
function bindingifyTransformFilter(filterOption) {
|
|
1220
|
+
if (!filterOption) return void 0;
|
|
1221
|
+
const { id, code, moduleType } = filterOption;
|
|
1222
|
+
let moduleTypeRet;
|
|
1223
|
+
if (moduleType) if (Array.isArray(moduleType)) moduleTypeRet = moduleType;
|
|
1224
|
+
else moduleTypeRet = moduleType.include;
|
|
1225
|
+
return {
|
|
1226
|
+
id: id ? bindingifyStringFilter(id) : void 0,
|
|
1227
|
+
code: code ? bindingifyStringFilter(code) : void 0,
|
|
1228
|
+
moduleType: moduleTypeRet
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
//#endregion
|
|
1233
|
+
//#region src/options/normalized-input-options.ts
|
|
1234
|
+
var NormalizedInputOptionsImpl = class {
|
|
1235
|
+
inner;
|
|
1236
|
+
constructor(inner, onLog) {
|
|
1237
|
+
this.onLog = onLog;
|
|
1238
|
+
this.inner = inner;
|
|
1239
|
+
}
|
|
1240
|
+
get shimMissingExports() {
|
|
1241
|
+
return this.inner.shimMissingExports;
|
|
1633
1242
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
this.resolveOptionsMap.set(index, options);
|
|
1637
|
-
return index;
|
|
1243
|
+
get input() {
|
|
1244
|
+
return this.inner.input;
|
|
1638
1245
|
}
|
|
1639
|
-
|
|
1640
|
-
return this.
|
|
1246
|
+
get cwd() {
|
|
1247
|
+
return this.inner.cwd ?? void 0;
|
|
1641
1248
|
}
|
|
1642
|
-
|
|
1643
|
-
this.
|
|
1249
|
+
get platform() {
|
|
1250
|
+
return this.inner.platform;
|
|
1644
1251
|
}
|
|
1645
1252
|
};
|
|
1646
1253
|
|
|
1647
1254
|
//#endregion
|
|
1648
|
-
//#region src/
|
|
1649
|
-
function
|
|
1650
|
-
|
|
1651
|
-
if (!
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
//#endregion
|
|
1656
|
-
//#region src/utils/bindingify-input-options.ts
|
|
1657
|
-
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel) {
|
|
1658
|
-
const pluginContextData = new PluginContextData();
|
|
1659
|
-
const plugins = rawPlugins.map((plugin) => {
|
|
1660
|
-
if ("_parallel" in plugin) return void 0;
|
|
1661
|
-
if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
|
|
1662
|
-
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel);
|
|
1663
|
-
});
|
|
1255
|
+
//#region src/plugin/bindingify-build-hooks.ts
|
|
1256
|
+
function bindingifyBuildStart(args) {
|
|
1257
|
+
const hook = args.plugin.buildStart;
|
|
1258
|
+
if (!hook) return {};
|
|
1259
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1664
1260
|
return {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
cwd: inputOptions.cwd ?? process.cwd(),
|
|
1668
|
-
external: bindingifyExternal(inputOptions.external),
|
|
1669
|
-
resolve: bindingifyResolve(inputOptions.resolve),
|
|
1670
|
-
platform: inputOptions.platform,
|
|
1671
|
-
shimMissingExports: inputOptions.shimMissingExports,
|
|
1672
|
-
logLevel: bindingifyLogLevel(logLevel),
|
|
1673
|
-
onLog,
|
|
1674
|
-
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
1675
|
-
moduleTypes: inputOptions.moduleTypes,
|
|
1676
|
-
define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
|
|
1677
|
-
inject: bindingifyInject(inputOptions.inject),
|
|
1678
|
-
experimental: {
|
|
1679
|
-
strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
|
|
1680
|
-
disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
|
|
1681
|
-
viteMode: inputOptions.experimental?.viteMode,
|
|
1682
|
-
resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
|
|
1683
|
-
hmr: inputOptions.experimental?.hmr
|
|
1261
|
+
plugin: async (ctx, opts) => {
|
|
1262
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedInputOptionsImpl(opts, args.onLog));
|
|
1684
1263
|
},
|
|
1685
|
-
|
|
1686
|
-
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1687
|
-
watch: bindingifyWatch(inputOptions.watch),
|
|
1688
|
-
dropLabels: inputOptions.dropLabels,
|
|
1689
|
-
keepNames: inputOptions.keepNames,
|
|
1690
|
-
checks: inputOptions.checks,
|
|
1691
|
-
deferSyncScanData: () => {
|
|
1692
|
-
let ret = [];
|
|
1693
|
-
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
1694
|
-
if (value.invalidate) ret.push({
|
|
1695
|
-
id: key,
|
|
1696
|
-
sideEffects: bindingifySideEffects(value.moduleSideEffects)
|
|
1697
|
-
});
|
|
1698
|
-
});
|
|
1699
|
-
return ret;
|
|
1700
|
-
}
|
|
1264
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1701
1265
|
};
|
|
1702
1266
|
}
|
|
1703
|
-
function
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
return id === pat;
|
|
1714
|
-
});
|
|
1715
|
-
};
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
function bindingifyResolve(resolve) {
|
|
1719
|
-
if (resolve) {
|
|
1720
|
-
const { alias, extensionAlias,...rest } = resolve;
|
|
1721
|
-
return {
|
|
1722
|
-
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
1723
|
-
find: name,
|
|
1724
|
-
replacements: arraify(replacement)
|
|
1725
|
-
})) : void 0,
|
|
1726
|
-
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
1727
|
-
target: name,
|
|
1728
|
-
replacements: value
|
|
1729
|
-
})) : void 0,
|
|
1730
|
-
...rest
|
|
1731
|
-
};
|
|
1732
|
-
}
|
|
1267
|
+
function bindingifyBuildEnd(args) {
|
|
1268
|
+
const hook = args.plugin.buildEnd;
|
|
1269
|
+
if (!hook) return {};
|
|
1270
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1271
|
+
return {
|
|
1272
|
+
plugin: async (ctx, err) => {
|
|
1273
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : void 0);
|
|
1274
|
+
},
|
|
1275
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1276
|
+
};
|
|
1733
1277
|
}
|
|
1734
|
-
function
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1278
|
+
function bindingifyResolveId(args) {
|
|
1279
|
+
const hook = args.plugin.resolveId;
|
|
1280
|
+
if (!hook) return {};
|
|
1281
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1282
|
+
return {
|
|
1283
|
+
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
1284
|
+
const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
|
|
1285
|
+
const newExtraOptions = {
|
|
1286
|
+
...extraOptions,
|
|
1287
|
+
custom: contextResolveOptions?.custom,
|
|
1288
|
+
[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
|
|
1289
|
+
};
|
|
1290
|
+
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? void 0, newExtraOptions);
|
|
1291
|
+
if (ret == null) return;
|
|
1292
|
+
if (ret === false) return {
|
|
1293
|
+
id: specifier,
|
|
1294
|
+
external: true
|
|
1741
1295
|
};
|
|
1296
|
+
if (typeof ret === "string") return { id: ret };
|
|
1297
|
+
let exist = args.pluginContextData.updateModuleOption(ret.id, {
|
|
1298
|
+
meta: ret.meta || {},
|
|
1299
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1300
|
+
invalidate: false
|
|
1301
|
+
});
|
|
1742
1302
|
return {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
imported: item[1]
|
|
1303
|
+
id: ret.id,
|
|
1304
|
+
external: ret.external,
|
|
1305
|
+
sideEffects: bindingifySideEffects(exist.moduleSideEffects)
|
|
1747
1306
|
};
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
from: item
|
|
1753
|
-
};
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
function bindingifyLogLevel(logLevel) {
|
|
1757
|
-
switch (logLevel) {
|
|
1758
|
-
case "silent": return require_parse_ast_index.import_binding.BindingLogLevel.Silent;
|
|
1759
|
-
case "debug": return require_parse_ast_index.import_binding.BindingLogLevel.Debug;
|
|
1760
|
-
case "warn": return require_parse_ast_index.import_binding.BindingLogLevel.Warn;
|
|
1761
|
-
case "info": return require_parse_ast_index.import_binding.BindingLogLevel.Info;
|
|
1762
|
-
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
function bindingifyInput(input) {
|
|
1766
|
-
if (input === void 0) return [];
|
|
1767
|
-
if (typeof input === "string") return [{ import: input }];
|
|
1768
|
-
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
1769
|
-
return Object.entries(input).map((value) => {
|
|
1770
|
-
return {
|
|
1771
|
-
name: value[0],
|
|
1772
|
-
import: value[1]
|
|
1773
|
-
};
|
|
1774
|
-
});
|
|
1307
|
+
},
|
|
1308
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1309
|
+
filter: bindingifyResolveIdFilter(options.filter)
|
|
1310
|
+
};
|
|
1775
1311
|
}
|
|
1776
|
-
function
|
|
1777
|
-
|
|
1778
|
-
if (
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1312
|
+
function bindingifyResolveDynamicImport(args) {
|
|
1313
|
+
const hook = args.plugin.resolveDynamicImport;
|
|
1314
|
+
if (!hook) return {};
|
|
1315
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1316
|
+
return {
|
|
1317
|
+
plugin: async (ctx, specifier, importer) => {
|
|
1318
|
+
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? void 0);
|
|
1319
|
+
if (ret == null) return;
|
|
1320
|
+
if (ret === false) return {
|
|
1321
|
+
id: specifier,
|
|
1322
|
+
external: true
|
|
1323
|
+
};
|
|
1324
|
+
if (typeof ret === "string") return { id: ret };
|
|
1325
|
+
const result = {
|
|
1326
|
+
id: ret.id,
|
|
1327
|
+
external: ret.external
|
|
1328
|
+
};
|
|
1329
|
+
if (ret.moduleSideEffects !== null) result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
|
|
1330
|
+
args.pluginContextData.updateModuleOption(ret.id, {
|
|
1331
|
+
meta: ret.meta || {},
|
|
1332
|
+
moduleSideEffects: ret.moduleSideEffects || null,
|
|
1333
|
+
invalidate: false
|
|
1334
|
+
});
|
|
1335
|
+
return result;
|
|
1336
|
+
},
|
|
1337
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1338
|
+
};
|
|
1793
1339
|
}
|
|
1794
|
-
function
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1340
|
+
function bindingifyTransform(args) {
|
|
1341
|
+
const hook = args.plugin.transform;
|
|
1342
|
+
if (!hook) return {};
|
|
1343
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1344
|
+
return {
|
|
1345
|
+
plugin: async (ctx, code, id, meta$1) => {
|
|
1346
|
+
const ret = await handler.call(new TransformPluginContext(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel), code, id, meta$1);
|
|
1347
|
+
if (ret == null) return void 0;
|
|
1348
|
+
if (typeof ret === "string") return { code: ret };
|
|
1349
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1350
|
+
meta: ret.meta ?? {},
|
|
1351
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1352
|
+
invalidate: false
|
|
1353
|
+
});
|
|
1354
|
+
return {
|
|
1355
|
+
code: ret.code,
|
|
1356
|
+
map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
|
|
1357
|
+
sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
|
|
1358
|
+
moduleType: ret.moduleType
|
|
1359
|
+
};
|
|
1360
|
+
},
|
|
1361
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1362
|
+
filter: bindingifyTransformFilter(options.filter)
|
|
1363
|
+
};
|
|
1805
1364
|
}
|
|
1806
|
-
function
|
|
1807
|
-
|
|
1808
|
-
if (
|
|
1809
|
-
|
|
1810
|
-
|
|
1365
|
+
function bindingifyLoad(args) {
|
|
1366
|
+
const hook = args.plugin.load;
|
|
1367
|
+
if (!hook) return {};
|
|
1368
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1369
|
+
return {
|
|
1370
|
+
plugin: async (ctx, id) => {
|
|
1371
|
+
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, id), id);
|
|
1372
|
+
if (ret == null) return;
|
|
1373
|
+
if (typeof ret === "string") return { code: ret };
|
|
1374
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1375
|
+
meta: ret.meta || {},
|
|
1376
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1377
|
+
invalidate: false
|
|
1378
|
+
});
|
|
1379
|
+
let map = preProcessSourceMap(ret, id);
|
|
1380
|
+
return {
|
|
1381
|
+
code: ret.code,
|
|
1382
|
+
map: bindingifySourcemap$1(map),
|
|
1383
|
+
moduleType: ret.moduleType,
|
|
1384
|
+
sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
|
|
1385
|
+
};
|
|
1386
|
+
},
|
|
1387
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1388
|
+
filter: bindingifyLoadFilter(options.filter)
|
|
1811
1389
|
};
|
|
1812
|
-
let normalizedConfig = { moduleSideEffects: true };
|
|
1813
|
-
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
1814
|
-
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
1815
|
-
external: true,
|
|
1816
|
-
sideEffects: false
|
|
1817
|
-
}, {
|
|
1818
|
-
external: false,
|
|
1819
|
-
sideEffects: true
|
|
1820
|
-
}];
|
|
1821
|
-
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
1822
|
-
normalizedConfig.annotations = config.annotations ?? true;
|
|
1823
|
-
return normalizedConfig;
|
|
1824
1390
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1391
|
+
function preProcessSourceMap(ret, id) {
|
|
1392
|
+
if (!ret.map) return;
|
|
1393
|
+
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
1394
|
+
if (!isEmptySourcemapFiled(map.sources)) {
|
|
1395
|
+
const directory = node_path.default.dirname(id) || ".";
|
|
1396
|
+
const sourceRoot = map.sourceRoot || ".";
|
|
1397
|
+
map.sources = map.sources.map((source) => node_path.default.resolve(directory, sourceRoot, source));
|
|
1398
|
+
}
|
|
1399
|
+
return map;
|
|
1834
1400
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1401
|
+
function bindingifyModuleParsed(args) {
|
|
1402
|
+
const hook = args.plugin.moduleParsed;
|
|
1403
|
+
if (!hook) return {};
|
|
1404
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1405
|
+
return {
|
|
1406
|
+
plugin: async (ctx, moduleInfo) => {
|
|
1407
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
1408
|
+
},
|
|
1409
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1410
|
+
};
|
|
1843
1411
|
}
|
|
1844
1412
|
|
|
1845
1413
|
//#endregion
|
|
1846
|
-
//#region
|
|
1847
|
-
function
|
|
1848
|
-
|
|
1414
|
+
//#region src/utils/bindingify-output-options.ts
|
|
1415
|
+
function bindingifyOutputOptions(outputOptions) {
|
|
1416
|
+
const { dir, format, exports: exports$1, hashCharacters, sourcemap, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName } = outputOptions;
|
|
1417
|
+
return {
|
|
1418
|
+
dir,
|
|
1419
|
+
file: file == null ? void 0 : file,
|
|
1420
|
+
format: bindingifyFormat(format),
|
|
1421
|
+
exports: exports$1,
|
|
1422
|
+
hashCharacters,
|
|
1423
|
+
sourcemap: bindingifySourcemap(sourcemap),
|
|
1424
|
+
sourcemapDebugIds,
|
|
1425
|
+
sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
|
|
1426
|
+
sourcemapPathTransform,
|
|
1427
|
+
banner: bindingifyAddon(banner),
|
|
1428
|
+
footer: bindingifyAddon(footer),
|
|
1429
|
+
intro: bindingifyAddon(intro),
|
|
1430
|
+
outro: bindingifyAddon(outro),
|
|
1431
|
+
extend: outputOptions.extend,
|
|
1432
|
+
globals,
|
|
1433
|
+
esModule,
|
|
1434
|
+
name,
|
|
1435
|
+
assetFileNames: bindingifyAssetFilenames(assetFileNames),
|
|
1436
|
+
entryFileNames,
|
|
1437
|
+
chunkFileNames,
|
|
1438
|
+
cssEntryFileNames,
|
|
1439
|
+
cssChunkFileNames,
|
|
1440
|
+
plugins: [],
|
|
1441
|
+
minify: outputOptions.minify,
|
|
1442
|
+
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
1443
|
+
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
1444
|
+
advancedChunks: outputOptions.advancedChunks,
|
|
1445
|
+
polyfillRequire: outputOptions.polyfillRequire,
|
|
1446
|
+
target: outputOptions.target,
|
|
1447
|
+
sanitizeFileName
|
|
1448
|
+
};
|
|
1849
1449
|
}
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
1855
|
-
return function isPluginHookName$1(hookName) {
|
|
1856
|
-
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
1450
|
+
function bindingifyAddon(configAddon) {
|
|
1451
|
+
return async (chunk) => {
|
|
1452
|
+
if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
|
|
1453
|
+
return configAddon || "";
|
|
1857
1454
|
};
|
|
1858
|
-
}();
|
|
1859
|
-
|
|
1860
|
-
//#endregion
|
|
1861
|
-
//#region src/utils/compose-js-plugins.ts
|
|
1862
|
-
const unsupportedHookName = [
|
|
1863
|
-
"augmentChunkHash",
|
|
1864
|
-
"generateBundle",
|
|
1865
|
-
"moduleParsed",
|
|
1866
|
-
"onLog",
|
|
1867
|
-
"options",
|
|
1868
|
-
"outputOptions",
|
|
1869
|
-
"renderError",
|
|
1870
|
-
"renderStart",
|
|
1871
|
-
"resolveDynamicImport",
|
|
1872
|
-
"writeBundle"
|
|
1873
|
-
];
|
|
1874
|
-
const unsupportedHooks = new Set(unsupportedHookName);
|
|
1875
|
-
function isUnsupportedHooks(hookName) {
|
|
1876
|
-
return unsupportedHooks.has(hookName);
|
|
1877
1455
|
}
|
|
1878
|
-
function
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
case "buildEnd": {
|
|
1913
|
-
const handlers = batchedHooks.buildEnd ?? [];
|
|
1914
|
-
batchedHooks.buildEnd = handlers;
|
|
1915
|
-
if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
|
|
1916
|
-
break;
|
|
1917
|
-
}
|
|
1918
|
-
case "renderChunk": {
|
|
1919
|
-
const handlers = batchedHooks.renderChunk ?? [];
|
|
1920
|
-
batchedHooks.renderChunk = handlers;
|
|
1921
|
-
if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
|
|
1922
|
-
break;
|
|
1923
|
-
}
|
|
1924
|
-
case "banner":
|
|
1925
|
-
case "footer":
|
|
1926
|
-
case "intro":
|
|
1927
|
-
case "outro": {
|
|
1928
|
-
const hook = plugin[pluginProp];
|
|
1929
|
-
if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
|
|
1930
|
-
break;
|
|
1931
|
-
}
|
|
1932
|
-
case "closeBundle": {
|
|
1933
|
-
const handlers = batchedHooks.closeBundle ?? [];
|
|
1934
|
-
batchedHooks.closeBundle = handlers;
|
|
1935
|
-
if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
|
|
1936
|
-
break;
|
|
1937
|
-
}
|
|
1938
|
-
case "watchChange": {
|
|
1939
|
-
const handlers = batchedHooks.watchChange ?? [];
|
|
1940
|
-
batchedHooks.watchChange = handlers;
|
|
1941
|
-
if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
|
|
1942
|
-
break;
|
|
1943
|
-
}
|
|
1944
|
-
case "closeWatcher": {
|
|
1945
|
-
const handlers = batchedHooks.closeWatcher ?? [];
|
|
1946
|
-
batchedHooks.closeWatcher = handlers;
|
|
1947
|
-
if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
|
|
1948
|
-
break;
|
|
1949
|
-
}
|
|
1950
|
-
default: {}
|
|
1951
|
-
}
|
|
1456
|
+
function bindingifyFormat(format) {
|
|
1457
|
+
switch (format) {
|
|
1458
|
+
case void 0:
|
|
1459
|
+
case "es":
|
|
1460
|
+
case "esm":
|
|
1461
|
+
case "module": return "es";
|
|
1462
|
+
case "cjs":
|
|
1463
|
+
case "commonjs": return "cjs";
|
|
1464
|
+
case "iife": return "iife";
|
|
1465
|
+
case "umd": return "umd";
|
|
1466
|
+
case "experimental-app": return "app";
|
|
1467
|
+
default: unimplemented(`output.format: ${format}`);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
function bindingifySourcemap(sourcemap) {
|
|
1471
|
+
switch (sourcemap) {
|
|
1472
|
+
case true: return "file";
|
|
1473
|
+
case "inline": return "inline";
|
|
1474
|
+
case false:
|
|
1475
|
+
case void 0: return void 0;
|
|
1476
|
+
case "hidden": return "hidden";
|
|
1477
|
+
default: throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
|
|
1481
|
+
return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
|
|
1482
|
+
}
|
|
1483
|
+
function bindingifyAssetFilenames(assetFileNames) {
|
|
1484
|
+
if (typeof assetFileNames === "function") return (asset) => {
|
|
1485
|
+
return assetFileNames({
|
|
1486
|
+
names: asset.names,
|
|
1487
|
+
originalFileNames: asset.originalFileNames,
|
|
1488
|
+
source: transformAssetSource(asset.source),
|
|
1489
|
+
type: "asset"
|
|
1952
1490
|
});
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1491
|
+
};
|
|
1492
|
+
return assetFileNames;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
//#endregion
|
|
1496
|
+
//#region src/options/normalized-output-options.ts
|
|
1497
|
+
var NormalizedOutputOptionsImpl = class {
|
|
1498
|
+
constructor(inner, outputOptions, normalizedOutputPlugins) {
|
|
1499
|
+
this.inner = inner;
|
|
1500
|
+
this.outputOptions = outputOptions;
|
|
1501
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
1960
1502
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
|
|
1964
|
-
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
1965
|
-
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
1966
|
-
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
1967
|
-
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
1968
|
-
return (source, importer, rawContextResolveOptions) => {
|
|
1969
|
-
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
1970
|
-
if (contextResolveOptions.skipSelf) {
|
|
1971
|
-
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
1972
|
-
contextResolveOptions.skipSelf = false;
|
|
1973
|
-
}
|
|
1974
|
-
return resolve(source, importer, contextResolveOptions);
|
|
1975
|
-
};
|
|
1976
|
-
};
|
|
1977
|
-
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
1978
|
-
}
|
|
1979
|
-
composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
|
|
1980
|
-
const hookResolveIdOptions = rawHookResolveIdOptions;
|
|
1981
|
-
const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
|
|
1982
|
-
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
1983
|
-
const [handler, plugin] = batchedHandlers[handlerIdx];
|
|
1984
|
-
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
1985
|
-
if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
|
|
1986
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
1987
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
|
|
1988
|
-
if (!isNullish(result)) return result;
|
|
1989
|
-
}
|
|
1990
|
-
};
|
|
1503
|
+
get dir() {
|
|
1504
|
+
return this.inner.dir ?? void 0;
|
|
1991
1505
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
1506
|
+
get entryFileNames() {
|
|
1507
|
+
return this.inner.entryFilenames || this.outputOptions.entryFileNames;
|
|
1508
|
+
}
|
|
1509
|
+
get chunkFileNames() {
|
|
1510
|
+
return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
|
|
1511
|
+
}
|
|
1512
|
+
get assetFileNames() {
|
|
1513
|
+
return this.inner.assetFilenames || this.outputOptions.assetFileNames;
|
|
1514
|
+
}
|
|
1515
|
+
get format() {
|
|
1516
|
+
return this.inner.format;
|
|
1517
|
+
}
|
|
1518
|
+
get exports() {
|
|
1519
|
+
return this.inner.exports;
|
|
1520
|
+
}
|
|
1521
|
+
get sourcemap() {
|
|
1522
|
+
return this.inner.sourcemap;
|
|
1523
|
+
}
|
|
1524
|
+
get cssEntryFileNames() {
|
|
1525
|
+
return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
|
|
1526
|
+
}
|
|
1527
|
+
get cssChunkFileNames() {
|
|
1528
|
+
return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
|
|
1529
|
+
}
|
|
1530
|
+
get shimMissingExports() {
|
|
1531
|
+
return this.inner.shimMissingExports;
|
|
1532
|
+
}
|
|
1533
|
+
get name() {
|
|
1534
|
+
return this.inner.name ?? void 0;
|
|
1535
|
+
}
|
|
1536
|
+
get file() {
|
|
1537
|
+
return this.inner.file ?? void 0;
|
|
1538
|
+
}
|
|
1539
|
+
get inlineDynamicImports() {
|
|
1540
|
+
return this.inner.inlineDynamicImports;
|
|
1541
|
+
}
|
|
1542
|
+
get externalLiveBindings() {
|
|
1543
|
+
return this.inner.externalLiveBindings;
|
|
1544
|
+
}
|
|
1545
|
+
get banner() {
|
|
1546
|
+
return normalizeAddon(this.outputOptions.banner);
|
|
1547
|
+
}
|
|
1548
|
+
get footer() {
|
|
1549
|
+
return normalizeAddon(this.outputOptions.footer);
|
|
1550
|
+
}
|
|
1551
|
+
get intro() {
|
|
1552
|
+
return normalizeAddon(this.outputOptions.intro);
|
|
1553
|
+
}
|
|
1554
|
+
get outro() {
|
|
1555
|
+
return normalizeAddon(this.outputOptions.outro);
|
|
1556
|
+
}
|
|
1557
|
+
get esModule() {
|
|
1558
|
+
return this.inner.esModule;
|
|
1559
|
+
}
|
|
1560
|
+
get extend() {
|
|
1561
|
+
return this.inner.extend;
|
|
1562
|
+
}
|
|
1563
|
+
get globals() {
|
|
1564
|
+
return this.inner.globals || this.outputOptions.globals;
|
|
1565
|
+
}
|
|
1566
|
+
get hashCharacters() {
|
|
1567
|
+
return this.inner.hashCharacters;
|
|
1568
|
+
}
|
|
1569
|
+
get sourcemapDebugIds() {
|
|
1570
|
+
return this.inner.sourcemapDebugIds;
|
|
1571
|
+
}
|
|
1572
|
+
get sourcemapIgnoreList() {
|
|
1573
|
+
return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
|
|
1574
|
+
}
|
|
1575
|
+
get sourcemapPathTransform() {
|
|
1576
|
+
return this.outputOptions.sourcemapPathTransform;
|
|
1577
|
+
}
|
|
1578
|
+
get minify() {
|
|
1579
|
+
return this.inner.minify;
|
|
1580
|
+
}
|
|
1581
|
+
get comments() {
|
|
1582
|
+
return this.inner.comments;
|
|
1583
|
+
}
|
|
1584
|
+
get polyfillRequire() {
|
|
1585
|
+
return this.inner.polyfillRequire;
|
|
1586
|
+
}
|
|
1587
|
+
get plugins() {
|
|
1588
|
+
return this.normalizedOutputPlugins;
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
function normalizeAddon(value) {
|
|
1592
|
+
if (typeof value === "function") return value;
|
|
1593
|
+
return () => value || "";
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
//#endregion
|
|
1597
|
+
//#region src/plugin/bindingify-output-hooks.ts
|
|
1598
|
+
function bindingifyRenderStart(args) {
|
|
1599
|
+
const hook = args.plugin.renderStart;
|
|
1600
|
+
if (!hook) return {};
|
|
1601
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1602
|
+
return {
|
|
1603
|
+
plugin: async (ctx, opts) => {
|
|
1604
|
+
handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins), new NormalizedInputOptionsImpl(opts, args.onLog));
|
|
1605
|
+
},
|
|
1606
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
function bindingifyRenderChunk(args) {
|
|
1610
|
+
const hook = args.plugin.renderChunk;
|
|
1611
|
+
if (!hook) return {};
|
|
1612
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1613
|
+
return {
|
|
1614
|
+
plugin: async (ctx, code, chunk, opts) => {
|
|
1615
|
+
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins));
|
|
1616
|
+
if (ret == null) return;
|
|
1617
|
+
if (typeof ret === "string") return { code: ret };
|
|
1618
|
+
if (!ret.map) return { code: ret.code };
|
|
1619
|
+
return {
|
|
1620
|
+
code: ret.code,
|
|
1621
|
+
map: bindingifySourcemap$1(ret.map)
|
|
1622
|
+
};
|
|
1623
|
+
},
|
|
1624
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
function bindingifyAugmentChunkHash(args) {
|
|
1628
|
+
const hook = args.plugin.augmentChunkHash;
|
|
1629
|
+
if (!hook) return {};
|
|
1630
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1631
|
+
return {
|
|
1632
|
+
plugin: async (ctx, chunk) => {
|
|
1633
|
+
return await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
1634
|
+
},
|
|
1635
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
function bindingifyRenderError(args) {
|
|
1639
|
+
const hook = args.plugin.renderError;
|
|
1640
|
+
if (!hook) return {};
|
|
1641
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1642
|
+
return {
|
|
1643
|
+
plugin: async (ctx, err) => {
|
|
1644
|
+
handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
1645
|
+
},
|
|
1646
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
function bindingifyGenerateBundle(args) {
|
|
1650
|
+
const hook = args.plugin.generateBundle;
|
|
1651
|
+
if (!hook) return {};
|
|
1652
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1653
|
+
return {
|
|
1654
|
+
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
1655
|
+
const changed = {
|
|
1656
|
+
updated: new Set(),
|
|
1657
|
+
deleted: new Set()
|
|
1658
|
+
};
|
|
1659
|
+
const output = transformToOutputBundle(bundle, changed);
|
|
1660
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins), output, isWrite);
|
|
1661
|
+
return collectChangedBundle(changed, output);
|
|
1662
|
+
},
|
|
1663
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function bindingifyWriteBundle(args) {
|
|
1667
|
+
const hook = args.plugin.writeBundle;
|
|
1668
|
+
if (!hook) return {};
|
|
1669
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1670
|
+
return {
|
|
1671
|
+
plugin: async (ctx, bundle, opts) => {
|
|
1672
|
+
const changed = {
|
|
1673
|
+
updated: new Set(),
|
|
1674
|
+
deleted: new Set()
|
|
1675
|
+
};
|
|
1676
|
+
const output = transformToOutputBundle(bundle, changed);
|
|
1677
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts, args.outputOptions, args.normalizedOutputPlugins), output);
|
|
1678
|
+
return collectChangedBundle(changed, output);
|
|
1679
|
+
},
|
|
1680
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
function bindingifyCloseBundle(args) {
|
|
1684
|
+
const hook = args.plugin.closeBundle;
|
|
1685
|
+
if (!hook) return {};
|
|
1686
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1687
|
+
return {
|
|
1688
|
+
plugin: async (ctx) => {
|
|
1689
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
|
|
1690
|
+
},
|
|
1691
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
function bindingifyBanner(args) {
|
|
1695
|
+
const hook = args.plugin.banner;
|
|
1696
|
+
if (!hook) return {};
|
|
1697
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1698
|
+
return {
|
|
1699
|
+
plugin: async (ctx, chunk) => {
|
|
1700
|
+
if (typeof handler === "string") return handler;
|
|
1701
|
+
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
1702
|
+
},
|
|
1703
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
function bindingifyFooter(args) {
|
|
1707
|
+
const hook = args.plugin.footer;
|
|
1708
|
+
if (!hook) return {};
|
|
1709
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1710
|
+
return {
|
|
1711
|
+
plugin: async (ctx, chunk) => {
|
|
1712
|
+
if (typeof handler === "string") return handler;
|
|
1713
|
+
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
1714
|
+
},
|
|
1715
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
function bindingifyIntro(args) {
|
|
1719
|
+
const hook = args.plugin.intro;
|
|
1720
|
+
if (!hook) return {};
|
|
1721
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1722
|
+
return {
|
|
1723
|
+
plugin: async (ctx, chunk) => {
|
|
1724
|
+
if (typeof handler === "string") return handler;
|
|
1725
|
+
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
1726
|
+
},
|
|
1727
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function bindingifyOutro(args) {
|
|
1731
|
+
const hook = args.plugin.outro;
|
|
1732
|
+
if (!hook) return {};
|
|
1733
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1734
|
+
return {
|
|
1735
|
+
plugin: async (ctx, chunk) => {
|
|
1736
|
+
if (typeof handler === "string") return handler;
|
|
1737
|
+
return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
1738
|
+
},
|
|
1739
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
//#endregion
|
|
1744
|
+
//#region src/plugin/bindingify-watch-hooks.ts
|
|
1745
|
+
function bindingifyWatchChange(args) {
|
|
1746
|
+
const hook = args.plugin.watchChange;
|
|
1747
|
+
if (!hook) return {};
|
|
1748
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1749
|
+
return {
|
|
1750
|
+
plugin: async (ctx, id, event) => {
|
|
1751
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event });
|
|
1752
|
+
},
|
|
1753
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
function bindingifyCloseWatcher(args) {
|
|
1757
|
+
const hook = args.plugin.closeWatcher;
|
|
1758
|
+
if (!hook) return {};
|
|
1759
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1760
|
+
return {
|
|
1761
|
+
plugin: async (ctx) => {
|
|
1762
|
+
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
|
|
1763
|
+
},
|
|
1764
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
//#endregion
|
|
1769
|
+
//#region src/plugin/bindingify-plugin.ts
|
|
1770
|
+
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel) {
|
|
1771
|
+
const args = {
|
|
1772
|
+
plugin,
|
|
1773
|
+
options,
|
|
1774
|
+
outputOptions,
|
|
1775
|
+
pluginContextData,
|
|
1776
|
+
onLog,
|
|
1777
|
+
logLevel,
|
|
1778
|
+
normalizedOutputPlugins
|
|
1779
|
+
};
|
|
1780
|
+
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
|
|
1781
|
+
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
|
|
1782
|
+
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
|
|
1783
|
+
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
|
|
1784
|
+
const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
|
|
1785
|
+
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
|
|
1786
|
+
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
|
|
1787
|
+
const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args);
|
|
1788
|
+
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
1789
|
+
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
1790
|
+
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
1791
|
+
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
1792
|
+
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
1793
|
+
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
1794
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
|
|
1795
|
+
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
|
|
1796
|
+
const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
|
|
1797
|
+
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
|
|
1798
|
+
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
1799
|
+
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
1800
|
+
const result = {
|
|
1801
|
+
name: plugin.name,
|
|
1802
|
+
buildStart,
|
|
1803
|
+
buildStartMeta,
|
|
1804
|
+
resolveId,
|
|
1805
|
+
resolveIdMeta,
|
|
1806
|
+
resolveIdFilter,
|
|
1807
|
+
resolveDynamicImport,
|
|
1808
|
+
resolveDynamicImportMeta,
|
|
1809
|
+
buildEnd,
|
|
1810
|
+
buildEndMeta,
|
|
1811
|
+
transform,
|
|
1812
|
+
transformMeta,
|
|
1813
|
+
transformFilter,
|
|
1814
|
+
moduleParsed,
|
|
1815
|
+
moduleParsedMeta,
|
|
1816
|
+
load,
|
|
1817
|
+
loadMeta,
|
|
1818
|
+
loadFilter,
|
|
1819
|
+
renderChunk,
|
|
1820
|
+
renderChunkMeta,
|
|
1821
|
+
augmentChunkHash,
|
|
1822
|
+
augmentChunkHashMeta,
|
|
1823
|
+
renderStart,
|
|
1824
|
+
renderStartMeta,
|
|
1825
|
+
renderError,
|
|
1826
|
+
renderErrorMeta,
|
|
1827
|
+
generateBundle,
|
|
1828
|
+
generateBundleMeta,
|
|
1829
|
+
writeBundle,
|
|
1830
|
+
writeBundleMeta,
|
|
1831
|
+
closeBundle,
|
|
1832
|
+
closeBundleMeta,
|
|
1833
|
+
banner,
|
|
1834
|
+
bannerMeta,
|
|
1835
|
+
footer,
|
|
1836
|
+
footerMeta,
|
|
1837
|
+
intro,
|
|
1838
|
+
introMeta,
|
|
1839
|
+
outro,
|
|
1840
|
+
outroMeta,
|
|
1841
|
+
watchChange,
|
|
1842
|
+
watchChangeMeta,
|
|
1843
|
+
closeWatcher,
|
|
1844
|
+
closeWatcherMeta
|
|
1845
|
+
};
|
|
1846
|
+
return wrapHandlers(result);
|
|
1847
|
+
}
|
|
1848
|
+
function wrapHandlers(plugin) {
|
|
1849
|
+
for (const hookName of [
|
|
1850
|
+
"buildStart",
|
|
1851
|
+
"resolveId",
|
|
1852
|
+
"resolveDynamicImport",
|
|
1853
|
+
"buildEnd",
|
|
1854
|
+
"transform",
|
|
1855
|
+
"moduleParsed",
|
|
1856
|
+
"load",
|
|
1857
|
+
"renderChunk",
|
|
1858
|
+
"augmentChunkHash",
|
|
1859
|
+
"renderStart",
|
|
1860
|
+
"renderError",
|
|
1861
|
+
"generateBundle",
|
|
1862
|
+
"writeBundle",
|
|
1863
|
+
"closeBundle",
|
|
1864
|
+
"banner",
|
|
1865
|
+
"footer",
|
|
1866
|
+
"intro",
|
|
1867
|
+
"outro",
|
|
1868
|
+
"watchChange",
|
|
1869
|
+
"closeWatcher"
|
|
1870
|
+
]) {
|
|
1871
|
+
const handler = plugin[hookName];
|
|
1872
|
+
if (handler) plugin[hookName] = async (...args) => {
|
|
1873
|
+
try {
|
|
1874
|
+
return await handler(...args);
|
|
1875
|
+
} catch (e) {
|
|
1876
|
+
return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e, plugin.name, {
|
|
1877
|
+
hook: hookName,
|
|
1878
|
+
id: hookName === "transform" ? args[2] : void 0
|
|
1879
|
+
}));
|
|
2112
1880
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
return plugin;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
//#endregion
|
|
1887
|
+
//#region src/plugin/plugin-context-data.ts
|
|
1888
|
+
var PluginContextData = class {
|
|
1889
|
+
moduleOptionMap = new Map();
|
|
1890
|
+
resolveOptionsMap = new Map();
|
|
1891
|
+
loadModulePromiseMap = new Map();
|
|
1892
|
+
updateModuleOption(id, option) {
|
|
1893
|
+
const existing = this.moduleOptionMap.get(id);
|
|
1894
|
+
if (existing) {
|
|
1895
|
+
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
1896
|
+
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
1897
|
+
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
1898
|
+
} else {
|
|
1899
|
+
this.moduleOptionMap.set(id, option);
|
|
1900
|
+
return option;
|
|
1901
|
+
}
|
|
1902
|
+
return existing;
|
|
1903
|
+
}
|
|
1904
|
+
getModuleOption(id) {
|
|
1905
|
+
const option = this.moduleOptionMap.get(id);
|
|
1906
|
+
if (!option) {
|
|
1907
|
+
const raw = {
|
|
1908
|
+
moduleSideEffects: null,
|
|
1909
|
+
meta: {}
|
|
1910
|
+
};
|
|
1911
|
+
this.moduleOptionMap.set(id, raw);
|
|
1912
|
+
return raw;
|
|
1913
|
+
}
|
|
1914
|
+
return option;
|
|
1915
|
+
}
|
|
1916
|
+
getModuleInfo(id, context) {
|
|
1917
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
1918
|
+
if (bindingInfo) {
|
|
1919
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
1920
|
+
return this.proxyModuleInfo(id, info);
|
|
1921
|
+
}
|
|
1922
|
+
return null;
|
|
1923
|
+
}
|
|
1924
|
+
proxyModuleInfo(id, info) {
|
|
1925
|
+
let moduleSideEffects = info.moduleSideEffects;
|
|
1926
|
+
Object.defineProperty(info, "moduleSideEffects", {
|
|
1927
|
+
get() {
|
|
1928
|
+
return moduleSideEffects;
|
|
1929
|
+
},
|
|
1930
|
+
set: (v) => {
|
|
1931
|
+
this.updateModuleOption(id, {
|
|
1932
|
+
moduleSideEffects: v,
|
|
1933
|
+
meta: info.meta,
|
|
1934
|
+
invalidate: true
|
|
1935
|
+
});
|
|
1936
|
+
moduleSideEffects = v;
|
|
2124
1937
|
}
|
|
2125
|
-
|
|
1938
|
+
});
|
|
1939
|
+
return info;
|
|
1940
|
+
}
|
|
1941
|
+
getModuleIds(context) {
|
|
1942
|
+
const moduleIds = context.getModuleIds();
|
|
1943
|
+
return moduleIds.values();
|
|
1944
|
+
}
|
|
1945
|
+
saveResolveOptions(options) {
|
|
1946
|
+
const index = this.resolveOptionsMap.size;
|
|
1947
|
+
this.resolveOptionsMap.set(index, options);
|
|
1948
|
+
return index;
|
|
1949
|
+
}
|
|
1950
|
+
getSavedResolveOptions(receipt) {
|
|
1951
|
+
return this.resolveOptionsMap.get(receipt);
|
|
1952
|
+
}
|
|
1953
|
+
removeSavedResolveOptions(receipt) {
|
|
1954
|
+
this.resolveOptionsMap.delete(receipt);
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
|
|
1958
|
+
//#endregion
|
|
1959
|
+
//#region src/utils/normalize-string-or-regex.ts
|
|
1960
|
+
function normalizedStringOrRegex(pattern) {
|
|
1961
|
+
if (!pattern) return void 0;
|
|
1962
|
+
if (!Array.isArray(pattern)) pattern = [pattern];
|
|
1963
|
+
return pattern;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
//#endregion
|
|
1967
|
+
//#region src/utils/bindingify-input-options.ts
|
|
1968
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel) {
|
|
1969
|
+
const pluginContextData = new PluginContextData();
|
|
1970
|
+
const plugins = rawPlugins.map((plugin) => {
|
|
1971
|
+
if ("_parallel" in plugin) return void 0;
|
|
1972
|
+
if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
|
|
1973
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel);
|
|
1974
|
+
});
|
|
1975
|
+
return {
|
|
1976
|
+
input: bindingifyInput(inputOptions.input),
|
|
1977
|
+
plugins,
|
|
1978
|
+
cwd: inputOptions.cwd ?? process.cwd(),
|
|
1979
|
+
external: bindingifyExternal(inputOptions.external),
|
|
1980
|
+
resolve: bindingifyResolve(inputOptions.resolve),
|
|
1981
|
+
platform: inputOptions.platform,
|
|
1982
|
+
shimMissingExports: inputOptions.shimMissingExports,
|
|
1983
|
+
logLevel: bindingifyLogLevel(logLevel),
|
|
1984
|
+
onLog,
|
|
1985
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
1986
|
+
moduleTypes: inputOptions.moduleTypes,
|
|
1987
|
+
define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
|
|
1988
|
+
inject: bindingifyInject(inputOptions.inject),
|
|
1989
|
+
experimental: {
|
|
1990
|
+
strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
|
|
1991
|
+
disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
|
|
1992
|
+
viteMode: inputOptions.experimental?.viteMode,
|
|
1993
|
+
resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
|
|
1994
|
+
hmr: inputOptions.experimental?.hmr
|
|
1995
|
+
},
|
|
1996
|
+
profilerNames: inputOptions?.profilerNames,
|
|
1997
|
+
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1998
|
+
watch: bindingifyWatch(inputOptions.watch),
|
|
1999
|
+
dropLabels: inputOptions.dropLabels,
|
|
2000
|
+
keepNames: inputOptions.keepNames,
|
|
2001
|
+
checks: inputOptions.checks,
|
|
2002
|
+
deferSyncScanData: () => {
|
|
2003
|
+
let ret = [];
|
|
2004
|
+
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
2005
|
+
if (value.invalidate) ret.push({
|
|
2006
|
+
id: key,
|
|
2007
|
+
sideEffects: bindingifySideEffects(value.moduleSideEffects)
|
|
2008
|
+
});
|
|
2009
|
+
});
|
|
2010
|
+
return ret;
|
|
2126
2011
|
}
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
function bindingifyExternal(external) {
|
|
2015
|
+
if (external) {
|
|
2016
|
+
if (typeof external === "function") return (id, importer, isResolved) => {
|
|
2017
|
+
if (id.startsWith("\0")) return false;
|
|
2018
|
+
return external(id, importer, isResolved) ?? false;
|
|
2019
|
+
};
|
|
2020
|
+
const externalArr = arraify(external);
|
|
2021
|
+
return (id, _importer, _isResolved) => {
|
|
2022
|
+
return externalArr.some((pat) => {
|
|
2023
|
+
if (pat instanceof RegExp) return pat.test(id);
|
|
2024
|
+
return id === pat;
|
|
2025
|
+
});
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
function bindingifyResolve(resolve) {
|
|
2030
|
+
if (resolve) {
|
|
2031
|
+
const { alias, extensionAlias,...rest } = resolve;
|
|
2032
|
+
return {
|
|
2033
|
+
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
2034
|
+
find: name,
|
|
2035
|
+
replacements: arraify(replacement)
|
|
2036
|
+
})) : void 0,
|
|
2037
|
+
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
2038
|
+
target: name,
|
|
2039
|
+
replacements: value
|
|
2040
|
+
})) : void 0,
|
|
2041
|
+
...rest
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
function bindingifyInject(inject) {
|
|
2046
|
+
if (inject) return Object.entries(inject).map(([alias, item]) => {
|
|
2047
|
+
if (Array.isArray(item)) {
|
|
2048
|
+
if (item[1] === "*") return {
|
|
2049
|
+
tagNamespace: true,
|
|
2050
|
+
alias,
|
|
2051
|
+
from: item[0]
|
|
2052
|
+
};
|
|
2053
|
+
return {
|
|
2054
|
+
tagNamed: true,
|
|
2055
|
+
alias,
|
|
2056
|
+
from: item[0],
|
|
2057
|
+
imported: item[1]
|
|
2058
|
+
};
|
|
2059
|
+
} else return {
|
|
2060
|
+
tagNamed: true,
|
|
2061
|
+
imported: "default",
|
|
2062
|
+
alias,
|
|
2063
|
+
from: item
|
|
2064
|
+
};
|
|
2127
2065
|
});
|
|
2128
|
-
return composed;
|
|
2129
2066
|
}
|
|
2130
|
-
function
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2067
|
+
function bindingifyLogLevel(logLevel) {
|
|
2068
|
+
switch (logLevel) {
|
|
2069
|
+
case "silent": return require_parse_ast_index.import_binding.BindingLogLevel.Silent;
|
|
2070
|
+
case "debug": return require_parse_ast_index.import_binding.BindingLogLevel.Debug;
|
|
2071
|
+
case "warn": return require_parse_ast_index.import_binding.BindingLogLevel.Warn;
|
|
2072
|
+
case "info": return require_parse_ast_index.import_binding.BindingLogLevel.Info;
|
|
2073
|
+
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
function bindingifyInput(input) {
|
|
2077
|
+
if (input === void 0) return [];
|
|
2078
|
+
if (typeof input === "string") return [{ import: input }];
|
|
2079
|
+
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
2080
|
+
return Object.entries(input).map((value) => {
|
|
2081
|
+
return {
|
|
2082
|
+
name: value[0],
|
|
2083
|
+
import: value[1]
|
|
2084
|
+
};
|
|
2142
2085
|
});
|
|
2143
|
-
if (hasNotComposablePattern) return false;
|
|
2144
|
-
return true;
|
|
2145
2086
|
}
|
|
2146
|
-
function
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2087
|
+
function bindingifyJsx(input) {
|
|
2088
|
+
if (input === false) return { type: "Disable" };
|
|
2089
|
+
if (input) {
|
|
2090
|
+
if (input.mode === "preserve") return { type: "Preserve" };
|
|
2091
|
+
const mode = input.mode ?? "automatic";
|
|
2092
|
+
return {
|
|
2093
|
+
type: "Enable",
|
|
2094
|
+
field0: {
|
|
2095
|
+
runtime: mode,
|
|
2096
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
|
|
2097
|
+
pragma: input.factory,
|
|
2098
|
+
pragmaFrag: input.fragment,
|
|
2099
|
+
development: input.development,
|
|
2100
|
+
refresh: input.refresh
|
|
2156
2101
|
}
|
|
2157
|
-
|
|
2158
|
-
}
|
|
2159
|
-
});
|
|
2160
|
-
if (toBeComposed.length > 0) {
|
|
2161
|
-
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2162
|
-
else newPlugins.push(toBeComposed[0]);
|
|
2163
|
-
toBeComposed.length = 0;
|
|
2102
|
+
};
|
|
2164
2103
|
}
|
|
2165
|
-
return newPlugins;
|
|
2166
2104
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
const { fileUrl, options } = plugin._parallel;
|
|
2174
|
-
pluginInfos.push({
|
|
2175
|
-
index,
|
|
2176
|
-
fileUrl,
|
|
2177
|
-
options
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
if (pluginInfos.length <= 0) return void 0;
|
|
2181
|
-
const count = Math.min((0, node_os.availableParallelism)(), 8);
|
|
2182
|
-
const parallelJsPluginRegistry = new require_parse_ast_index.import_binding.ParallelJsPluginRegistry(count);
|
|
2183
|
-
const registryId = parallelJsPluginRegistry.id;
|
|
2184
|
-
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2185
|
-
const stopWorkers = async () => {
|
|
2186
|
-
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
2187
|
-
};
|
|
2188
|
-
return {
|
|
2189
|
-
registry: parallelJsPluginRegistry,
|
|
2190
|
-
stopWorkers
|
|
2105
|
+
function bindingifyWatch(watch$1) {
|
|
2106
|
+
if (watch$1) return {
|
|
2107
|
+
buildDelay: watch$1.buildDelay,
|
|
2108
|
+
skipWrite: watch$1.skipWrite,
|
|
2109
|
+
include: normalizedStringOrRegex(watch$1.include),
|
|
2110
|
+
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2191
2111
|
};
|
|
2192
2112
|
}
|
|
2193
|
-
function
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
const workerData = {
|
|
2199
|
-
registryId,
|
|
2200
|
-
pluginInfos,
|
|
2201
|
-
threadNumber
|
|
2113
|
+
function bindingifyTreeshakeOptions(config) {
|
|
2114
|
+
if (config === false) return void 0;
|
|
2115
|
+
if (config === true || config === void 0) return {
|
|
2116
|
+
moduleSideEffects: true,
|
|
2117
|
+
annotations: true
|
|
2202
2118
|
};
|
|
2203
|
-
let
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
worker?.terminate();
|
|
2216
|
-
throw e;
|
|
2217
|
-
}
|
|
2119
|
+
let normalizedConfig = { moduleSideEffects: true };
|
|
2120
|
+
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
2121
|
+
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
2122
|
+
external: true,
|
|
2123
|
+
sideEffects: false
|
|
2124
|
+
}, {
|
|
2125
|
+
external: false,
|
|
2126
|
+
sideEffects: true
|
|
2127
|
+
}];
|
|
2128
|
+
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
2129
|
+
normalizedConfig.annotations = config.annotations ?? true;
|
|
2130
|
+
return normalizedConfig;
|
|
2218
2131
|
}
|
|
2219
2132
|
|
|
2220
2133
|
//#endregion
|
|
2221
|
-
//#region
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
development: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Development specific information")),
|
|
2261
|
-
factory: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Jsx element transformation")),
|
|
2262
|
-
fragment: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Jsx fragment transformation")),
|
|
2263
|
-
importSource: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Import the factory of element and fragment if mode is classic")),
|
|
2264
|
-
jsxImportSource: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Import the factory of element and fragment if mode is automatic")),
|
|
2265
|
-
mode: valibot.pipe(valibot.optional(valibot.union([valibot.literal("classic"), valibot.literal("automatic")])), valibot.description("Jsx transformation mode")),
|
|
2266
|
-
refresh: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("React refresh transformation"))
|
|
2267
|
-
});
|
|
2268
|
-
const WatchOptionsSchema = valibot.strictObject({
|
|
2269
|
-
chokidar: valibot.optional(valibot.any()),
|
|
2270
|
-
exclude: valibot.optional(valibot.union([StringOrRegExpSchema, valibot.array(StringOrRegExpSchema)])),
|
|
2271
|
-
include: valibot.optional(valibot.union([StringOrRegExpSchema, valibot.array(StringOrRegExpSchema)])),
|
|
2272
|
-
notify: valibot.pipe(valibot.optional(valibot.strictObject({
|
|
2273
|
-
compareContents: valibot.optional(valibot.boolean()),
|
|
2274
|
-
pollInterval: valibot.optional(valibot.number())
|
|
2275
|
-
})), valibot.description("Notify options")),
|
|
2276
|
-
skipWrite: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Skip the bundle.write() step")),
|
|
2277
|
-
buildDelay: valibot.pipe(valibot.optional(valibot.number()), valibot.description("Throttle watch rebuilds"))
|
|
2278
|
-
});
|
|
2279
|
-
const ChecksOptionsSchema = valibot.strictObject({ circularDependency: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Whether to emit warnings when detecting circular dependencies")) });
|
|
2280
|
-
const MinifyOptionsSchema = valibot.strictObject({
|
|
2281
|
-
mangle: valibot.boolean(),
|
|
2282
|
-
compress: valibot.boolean(),
|
|
2283
|
-
deadCodeElimination: valibot.boolean(),
|
|
2284
|
-
removeWhitespace: valibot.boolean()
|
|
2285
|
-
});
|
|
2286
|
-
const ResolveOptionsSchema = valibot.strictObject({
|
|
2287
|
-
alias: valibot.optional(valibot.record(valibot.string(), valibot.union([valibot.string(), valibot.array(valibot.string())]))),
|
|
2288
|
-
aliasFields: valibot.optional(valibot.array(valibot.array(valibot.string()))),
|
|
2289
|
-
conditionNames: valibot.optional(valibot.array(valibot.string())),
|
|
2290
|
-
extensionAlias: valibot.optional(valibot.record(valibot.string(), valibot.array(valibot.string()))),
|
|
2291
|
-
exportsFields: valibot.optional(valibot.array(valibot.array(valibot.string()))),
|
|
2292
|
-
extensions: valibot.optional(valibot.array(valibot.string())),
|
|
2293
|
-
mainFields: valibot.optional(valibot.array(valibot.string())),
|
|
2294
|
-
mainFiles: valibot.optional(valibot.array(valibot.string())),
|
|
2295
|
-
modules: valibot.optional(valibot.array(valibot.string())),
|
|
2296
|
-
symlinks: valibot.optional(valibot.boolean()),
|
|
2297
|
-
tsconfigFilename: valibot.optional(valibot.string())
|
|
2298
|
-
});
|
|
2299
|
-
const TreeshakingOptionsSchema = valibot.union([valibot.boolean(), valibot.looseObject({ annotations: valibot.optional(valibot.boolean()) })]);
|
|
2300
|
-
const OnLogSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([
|
|
2301
|
-
LogLevelSchema,
|
|
2302
|
-
RollupLogSchema,
|
|
2303
|
-
valibot.pipe(valibot.function(), valibot.args(valibot.tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
|
|
2304
|
-
])));
|
|
2305
|
-
const OnwarnSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([RollupLogSchema, valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.union([RollupLogWithStringSchema, valibot.pipe(valibot.function(), valibot.returns(RollupLogWithStringSchema))])])))])));
|
|
2306
|
-
const InputOptionsSchema = valibot.strictObject({
|
|
2307
|
-
input: valibot.optional(InputOptionSchema),
|
|
2308
|
-
plugins: valibot.optional(valibot.custom(() => true)),
|
|
2309
|
-
external: valibot.optional(ExternalSchema),
|
|
2310
|
-
resolve: valibot.optional(ResolveOptionsSchema),
|
|
2311
|
-
cwd: valibot.pipe(valibot.optional(valibot.string()), valibot.description("Current working directory")),
|
|
2312
|
-
platform: valibot.pipe(valibot.optional(valibot.union([
|
|
2313
|
-
valibot.literal("browser"),
|
|
2314
|
-
valibot.literal("neutral"),
|
|
2315
|
-
valibot.literal("node")
|
|
2316
|
-
])), valibot.description(`Platform for which the code should be generated (node, ${require_parse_ast_index.colors.underline("browser")}, neutral)`)),
|
|
2317
|
-
shimMissingExports: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("Create shim variables for missing exports")),
|
|
2318
|
-
treeshake: valibot.optional(TreeshakingOptionsSchema),
|
|
2319
|
-
logLevel: valibot.pipe(valibot.optional(LogLevelOptionSchema), valibot.description(`Log level (${require_parse_ast_index.colors.dim("silent")}, ${require_parse_ast_index.colors.underline(require_parse_ast_index.colors.gray("info"))}, debug, ${require_parse_ast_index.colors.yellow("warn")})`)),
|
|
2320
|
-
onLog: valibot.optional(OnLogSchema),
|
|
2321
|
-
onwarn: valibot.optional(OnwarnSchema),
|
|
2322
|
-
moduleTypes: valibot.pipe(valibot.optional(ModuleTypesSchema), valibot.description("Module types for customized extensions")),
|
|
2323
|
-
experimental: valibot.optional(valibot.strictObject({
|
|
2324
|
-
disableLiveBindings: valibot.optional(valibot.boolean()),
|
|
2325
|
-
enableComposingJsPlugins: valibot.optional(valibot.boolean()),
|
|
2326
|
-
resolveNewUrlToAsset: valibot.optional(valibot.boolean()),
|
|
2327
|
-
strictExecutionOrder: valibot.optional(valibot.boolean()),
|
|
2328
|
-
hmr: valibot.optional(valibot.boolean())
|
|
2329
|
-
})),
|
|
2330
|
-
define: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Define global variables")),
|
|
2331
|
-
inject: valibot.optional(valibot.record(valibot.string(), valibot.union([valibot.string(), valibot.tuple([valibot.string(), valibot.string()])]))),
|
|
2332
|
-
profilerNames: valibot.optional(valibot.boolean()),
|
|
2333
|
-
jsx: valibot.optional(JsxOptionsSchema),
|
|
2334
|
-
watch: valibot.optional(valibot.union([WatchOptionsSchema, valibot.literal(false)])),
|
|
2335
|
-
dropLabels: valibot.pipe(valibot.optional(valibot.array(valibot.string())), valibot.description("Remove labeled statements with these label names")),
|
|
2336
|
-
checks: valibot.optional(ChecksOptionsSchema)
|
|
2337
|
-
});
|
|
2338
|
-
const InputCliOverrideSchema = valibot.strictObject({
|
|
2339
|
-
external: valibot.pipe(valibot.optional(valibot.array(valibot.string())), valibot.description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
|
|
2340
|
-
inject: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Inject import statements on demand")),
|
|
2341
|
-
treeshake: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("enable treeshaking"))
|
|
2342
|
-
});
|
|
2343
|
-
const InputCliOptionsSchema = valibot.omit(valibot.strictObject({
|
|
2344
|
-
...InputOptionsSchema.entries,
|
|
2345
|
-
...InputCliOverrideSchema.entries
|
|
2346
|
-
}), [
|
|
2347
|
-
"input",
|
|
2348
|
-
"plugins",
|
|
2349
|
-
"onwarn",
|
|
2134
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
|
|
2135
|
+
function u$1(o, n, a) {
|
|
2136
|
+
let t$1 = (r) => o(r, ...n);
|
|
2137
|
+
return a === void 0 ? t$1 : Object.assign(t$1, {
|
|
2138
|
+
lazy: a,
|
|
2139
|
+
lazyArgs: n
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
//#endregion
|
|
2144
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-WIMGWYZL.js
|
|
2145
|
+
function u(r, n, o) {
|
|
2146
|
+
let a = r.length - n.length;
|
|
2147
|
+
if (a === 0) return r(...n);
|
|
2148
|
+
if (a === 1) return u$1(r, n, o);
|
|
2149
|
+
throw new Error("Wrong number of arguments");
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
//#endregion
|
|
2153
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
|
|
2154
|
+
function t(...n) {
|
|
2155
|
+
return u(Object.keys, n);
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
//#endregion
|
|
2159
|
+
//#region src/utils/plugin/index.ts
|
|
2160
|
+
const isPluginHookName = function() {
|
|
2161
|
+
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
2162
|
+
return function isPluginHookName$1(hookName) {
|
|
2163
|
+
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
2164
|
+
};
|
|
2165
|
+
}();
|
|
2166
|
+
|
|
2167
|
+
//#endregion
|
|
2168
|
+
//#region src/utils/compose-js-plugins.ts
|
|
2169
|
+
const unsupportedHookName = [
|
|
2170
|
+
"augmentChunkHash",
|
|
2171
|
+
"generateBundle",
|
|
2172
|
+
"moduleParsed",
|
|
2350
2173
|
"onLog",
|
|
2351
|
-
"
|
|
2352
|
-
"
|
|
2353
|
-
"
|
|
2354
|
-
"
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
]
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
const
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
|
|
2174
|
+
"options",
|
|
2175
|
+
"outputOptions",
|
|
2176
|
+
"renderError",
|
|
2177
|
+
"renderStart",
|
|
2178
|
+
"resolveDynamicImport",
|
|
2179
|
+
"writeBundle"
|
|
2180
|
+
];
|
|
2181
|
+
const unsupportedHooks = new Set(unsupportedHookName);
|
|
2182
|
+
function isUnsupportedHooks(hookName) {
|
|
2183
|
+
return unsupportedHooks.has(hookName);
|
|
2184
|
+
}
|
|
2185
|
+
function createComposedPlugin(plugins) {
|
|
2186
|
+
const names = [];
|
|
2187
|
+
const batchedHooks = {};
|
|
2188
|
+
plugins.forEach((plugin, index) => {
|
|
2189
|
+
const pluginName = plugin.name || `Anonymous(index: ${index})`;
|
|
2190
|
+
names.push(pluginName);
|
|
2191
|
+
t(plugin).forEach((pluginProp) => {
|
|
2192
|
+
if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
|
|
2193
|
+
if (!isPluginHookName(pluginProp)) return;
|
|
2194
|
+
switch (pluginProp) {
|
|
2195
|
+
case "buildStart": {
|
|
2196
|
+
const handlers = batchedHooks.buildStart ?? [];
|
|
2197
|
+
batchedHooks.buildStart = handlers;
|
|
2198
|
+
if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
case "load": {
|
|
2202
|
+
const handlers = batchedHooks.load ?? [];
|
|
2203
|
+
batchedHooks.load = handlers;
|
|
2204
|
+
if (plugin.load) handlers.push([plugin.load, plugin]);
|
|
2205
|
+
break;
|
|
2206
|
+
}
|
|
2207
|
+
case "transform": {
|
|
2208
|
+
const handlers = batchedHooks.transform ?? [];
|
|
2209
|
+
batchedHooks.transform = handlers;
|
|
2210
|
+
if (plugin.transform) handlers.push([plugin.transform, plugin]);
|
|
2211
|
+
break;
|
|
2212
|
+
}
|
|
2213
|
+
case "resolveId": {
|
|
2214
|
+
const handlers = batchedHooks.resolveId ?? [];
|
|
2215
|
+
batchedHooks.resolveId = handlers;
|
|
2216
|
+
if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
case "buildEnd": {
|
|
2220
|
+
const handlers = batchedHooks.buildEnd ?? [];
|
|
2221
|
+
batchedHooks.buildEnd = handlers;
|
|
2222
|
+
if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
|
|
2223
|
+
break;
|
|
2224
|
+
}
|
|
2225
|
+
case "renderChunk": {
|
|
2226
|
+
const handlers = batchedHooks.renderChunk ?? [];
|
|
2227
|
+
batchedHooks.renderChunk = handlers;
|
|
2228
|
+
if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
|
|
2229
|
+
break;
|
|
2230
|
+
}
|
|
2231
|
+
case "banner":
|
|
2232
|
+
case "footer":
|
|
2233
|
+
case "intro":
|
|
2234
|
+
case "outro": {
|
|
2235
|
+
const hook = plugin[pluginProp];
|
|
2236
|
+
if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
|
|
2237
|
+
break;
|
|
2238
|
+
}
|
|
2239
|
+
case "closeBundle": {
|
|
2240
|
+
const handlers = batchedHooks.closeBundle ?? [];
|
|
2241
|
+
batchedHooks.closeBundle = handlers;
|
|
2242
|
+
if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
|
|
2243
|
+
break;
|
|
2244
|
+
}
|
|
2245
|
+
case "watchChange": {
|
|
2246
|
+
const handlers = batchedHooks.watchChange ?? [];
|
|
2247
|
+
batchedHooks.watchChange = handlers;
|
|
2248
|
+
if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
|
|
2249
|
+
break;
|
|
2250
|
+
}
|
|
2251
|
+
case "closeWatcher": {
|
|
2252
|
+
const handlers = batchedHooks.closeWatcher ?? [];
|
|
2253
|
+
batchedHooks.closeWatcher = handlers;
|
|
2254
|
+
if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
|
|
2255
|
+
break;
|
|
2256
|
+
}
|
|
2257
|
+
default: {}
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
});
|
|
2261
|
+
const composed = { name: `Composed(${names.join(", ")})` };
|
|
2262
|
+
const createFixedPluginResolveFnMap = new Map();
|
|
2263
|
+
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2264
|
+
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2265
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2266
|
+
return ctx;
|
|
2267
|
+
}
|
|
2268
|
+
if (batchedHooks.resolveId) {
|
|
2269
|
+
const batchedHandlers = batchedHooks.resolveId;
|
|
2270
|
+
const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
|
|
2271
|
+
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2272
|
+
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2273
|
+
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2274
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2275
|
+
return (source, importer, rawContextResolveOptions) => {
|
|
2276
|
+
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2277
|
+
if (contextResolveOptions.skipSelf) {
|
|
2278
|
+
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2279
|
+
contextResolveOptions.skipSelf = false;
|
|
2280
|
+
}
|
|
2281
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2282
|
+
};
|
|
2283
|
+
};
|
|
2284
|
+
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
2285
|
+
}
|
|
2286
|
+
composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
|
|
2287
|
+
const hookResolveIdOptions = rawHookResolveIdOptions;
|
|
2288
|
+
const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
|
|
2289
|
+
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2290
|
+
const [handler, plugin] = batchedHandlers[handlerIdx];
|
|
2291
|
+
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2292
|
+
if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
|
|
2293
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2294
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
|
|
2295
|
+
if (!isNullish(result)) return result;
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
t(batchedHooks).forEach((hookName) => {
|
|
2300
|
+
switch (hookName) {
|
|
2301
|
+
case "resolveId": break;
|
|
2302
|
+
case "buildStart": {
|
|
2303
|
+
if (batchedHooks.buildStart) {
|
|
2304
|
+
const batchedHandlers = batchedHooks.buildStart;
|
|
2305
|
+
composed.buildStart = async function(options) {
|
|
2306
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2307
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2308
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
|
|
2309
|
+
}));
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
break;
|
|
2313
|
+
}
|
|
2314
|
+
case "load": {
|
|
2315
|
+
if (batchedHooks.load) {
|
|
2316
|
+
const batchedHandlers = batchedHooks.load;
|
|
2317
|
+
composed.load = async function(id) {
|
|
2318
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2319
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2320
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
|
|
2321
|
+
if (!isNullish(result)) return result;
|
|
2322
|
+
}
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
break;
|
|
2326
|
+
}
|
|
2327
|
+
case "transform": {
|
|
2328
|
+
if (batchedHooks.transform) {
|
|
2329
|
+
const batchedHandlers = batchedHooks.transform;
|
|
2330
|
+
composed.transform = async function(initialCode, id, moduleType) {
|
|
2331
|
+
let code = initialCode;
|
|
2332
|
+
let moduleSideEffects = void 0;
|
|
2333
|
+
function updateOutput(newCode, newModuleSideEffects) {
|
|
2334
|
+
code = newCode;
|
|
2335
|
+
moduleSideEffects = newModuleSideEffects ?? void 0;
|
|
2336
|
+
}
|
|
2337
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2338
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2339
|
+
this.getCombinedSourcemap = () => {
|
|
2340
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2341
|
+
};
|
|
2342
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2343
|
+
if (!isNullish(result)) {
|
|
2344
|
+
if (typeof result === "string") updateOutput(result);
|
|
2345
|
+
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return {
|
|
2349
|
+
code,
|
|
2350
|
+
moduleSideEffects
|
|
2351
|
+
};
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
break;
|
|
2355
|
+
}
|
|
2356
|
+
case "buildEnd": {
|
|
2357
|
+
if (batchedHooks.buildEnd) {
|
|
2358
|
+
const batchedHandlers = batchedHooks.buildEnd;
|
|
2359
|
+
composed.buildEnd = async function(err) {
|
|
2360
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2361
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2362
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
|
|
2363
|
+
}));
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
break;
|
|
2367
|
+
}
|
|
2368
|
+
case "renderChunk": {
|
|
2369
|
+
if (batchedHooks.renderChunk) {
|
|
2370
|
+
const batchedHandlers = batchedHooks.renderChunk;
|
|
2371
|
+
composed.renderChunk = async function(code, chunk, options) {
|
|
2372
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2373
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2374
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
|
|
2375
|
+
if (!isNullish(result)) return result;
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
case "banner":
|
|
2382
|
+
case "footer":
|
|
2383
|
+
case "intro":
|
|
2384
|
+
case "outro": {
|
|
2385
|
+
const hooks = batchedHooks[hookName];
|
|
2386
|
+
if (hooks?.length) composed[hookName] = async function(chunk) {
|
|
2387
|
+
const ret = [];
|
|
2388
|
+
for (const [hook, plugin] of hooks) {
|
|
2389
|
+
const { handler } = normalizeHook(hook);
|
|
2390
|
+
ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
|
|
2391
|
+
}
|
|
2392
|
+
return ret.join("\n");
|
|
2393
|
+
};
|
|
2394
|
+
break;
|
|
2395
|
+
}
|
|
2396
|
+
case "closeBundle": {
|
|
2397
|
+
if (batchedHooks.closeBundle) {
|
|
2398
|
+
const batchedHandlers = batchedHooks.closeBundle;
|
|
2399
|
+
composed.closeBundle = async function() {
|
|
2400
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2401
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2402
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2403
|
+
}));
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
break;
|
|
2407
|
+
}
|
|
2408
|
+
case "watchChange": {
|
|
2409
|
+
if (batchedHooks.watchChange) {
|
|
2410
|
+
const batchedHandlers = batchedHooks.watchChange;
|
|
2411
|
+
composed.watchChange = async function(id, event) {
|
|
2412
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2413
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2414
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
|
|
2415
|
+
}));
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
break;
|
|
2419
|
+
}
|
|
2420
|
+
case "closeWatcher": {
|
|
2421
|
+
if (batchedHooks.closeWatcher) {
|
|
2422
|
+
const batchedHandlers = batchedHooks.closeWatcher;
|
|
2423
|
+
composed.closeWatcher = async function() {
|
|
2424
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2425
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2426
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2427
|
+
}));
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
break;
|
|
2431
|
+
}
|
|
2432
|
+
default: {}
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2435
|
+
return composed;
|
|
2477
2436
|
}
|
|
2478
|
-
function
|
|
2479
|
-
|
|
2480
|
-
|
|
2437
|
+
function isComposablePlugin(plugin) {
|
|
2438
|
+
if (plugin instanceof BuiltinPlugin) return false;
|
|
2439
|
+
if ("_parallel" in plugin) return false;
|
|
2440
|
+
const hasNotComposablePattern = t(plugin).some((hookName) => {
|
|
2441
|
+
if (!isPluginHookName(hookName)) return false;
|
|
2442
|
+
const OK_TO_COMPOSE = false;
|
|
2443
|
+
if (isUnsupportedHooks(hookName)) return !OK_TO_COMPOSE;
|
|
2444
|
+
if (plugin[hookName]) {
|
|
2445
|
+
const { meta } = normalizeHook(plugin[hookName]);
|
|
2446
|
+
if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
|
|
2447
|
+
}
|
|
2448
|
+
return OK_TO_COMPOSE;
|
|
2449
|
+
});
|
|
2450
|
+
if (hasNotComposablePattern) return false;
|
|
2451
|
+
return true;
|
|
2481
2452
|
}
|
|
2482
|
-
function
|
|
2483
|
-
|
|
2453
|
+
function composeJsPlugins(plugins) {
|
|
2454
|
+
const newPlugins = [];
|
|
2455
|
+
const toBeComposed = [];
|
|
2456
|
+
plugins.forEach((plugin) => {
|
|
2457
|
+
if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
|
|
2458
|
+
else {
|
|
2459
|
+
if (toBeComposed.length > 0) {
|
|
2460
|
+
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2461
|
+
else newPlugins.push(toBeComposed[0]);
|
|
2462
|
+
toBeComposed.length = 0;
|
|
2463
|
+
}
|
|
2464
|
+
newPlugins.push(plugin);
|
|
2465
|
+
}
|
|
2466
|
+
});
|
|
2467
|
+
if (toBeComposed.length > 0) {
|
|
2468
|
+
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2469
|
+
else newPlugins.push(toBeComposed[0]);
|
|
2470
|
+
toBeComposed.length = 0;
|
|
2471
|
+
}
|
|
2472
|
+
return newPlugins;
|
|
2484
2473
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2474
|
+
|
|
2475
|
+
//#endregion
|
|
2476
|
+
//#region src/utils/initialize-parallel-plugins.ts
|
|
2477
|
+
async function initializeParallelPlugins(plugins) {
|
|
2478
|
+
const pluginInfos = [];
|
|
2479
|
+
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
2480
|
+
const { fileUrl, options } = plugin._parallel;
|
|
2481
|
+
pluginInfos.push({
|
|
2482
|
+
index,
|
|
2483
|
+
fileUrl,
|
|
2484
|
+
options
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
if (pluginInfos.length <= 0) return void 0;
|
|
2488
|
+
const count = Math.min((0, node_os.availableParallelism)(), 8);
|
|
2489
|
+
const parallelJsPluginRegistry = new require_parse_ast_index.import_binding.ParallelJsPluginRegistry(count);
|
|
2490
|
+
const registryId = parallelJsPluginRegistry.id;
|
|
2491
|
+
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2492
|
+
const stopWorkers = async () => {
|
|
2493
|
+
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
2494
|
+
};
|
|
2495
|
+
return {
|
|
2496
|
+
registry: parallelJsPluginRegistry,
|
|
2497
|
+
stopWorkers
|
|
2498
|
+
};
|
|
2487
2499
|
}
|
|
2488
|
-
function
|
|
2489
|
-
return (
|
|
2500
|
+
function initializeWorkers(registryId, count, pluginInfos) {
|
|
2501
|
+
return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
2502
|
+
}
|
|
2503
|
+
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
2504
|
+
const urlString = (void 0)("#parallel-plugin-worker");
|
|
2505
|
+
const workerData = {
|
|
2506
|
+
registryId,
|
|
2507
|
+
pluginInfos,
|
|
2508
|
+
threadNumber
|
|
2509
|
+
};
|
|
2510
|
+
let worker;
|
|
2511
|
+
try {
|
|
2512
|
+
worker = new node_worker_threads.Worker(new URL(urlString), { workerData });
|
|
2513
|
+
worker.unref();
|
|
2514
|
+
await new Promise((resolve, reject) => {
|
|
2515
|
+
worker.once("message", async (message) => {
|
|
2516
|
+
if (message.type === "error") reject(message.error);
|
|
2517
|
+
else resolve();
|
|
2518
|
+
});
|
|
2519
|
+
});
|
|
2520
|
+
return worker;
|
|
2521
|
+
} catch (e) {
|
|
2522
|
+
worker?.terminate();
|
|
2523
|
+
throw e;
|
|
2524
|
+
}
|
|
2490
2525
|
}
|
|
2491
2526
|
|
|
2492
2527
|
//#endregion
|
|
2493
2528
|
//#region src/utils/create-bundler-option.ts
|
|
2494
2529
|
async function createBundlerOptions(inputOptions, outputOptions, isClose) {
|
|
2495
|
-
if (inputOptions.treeshake !== void 0) validateTreeShakingOptions(inputOptions.treeshake);
|
|
2496
2530
|
const inputPlugins = await normalizePluginOption(inputOptions.plugins);
|
|
2497
2531
|
const outputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
2498
2532
|
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
@@ -2554,11 +2588,13 @@ var RolldownBuild = class {
|
|
|
2554
2588
|
return this.#bundler = await createBundler(this.#inputOptions, outputOptions, isClose);
|
|
2555
2589
|
}
|
|
2556
2590
|
async generate(outputOptions = {}) {
|
|
2591
|
+
validateOption("output", outputOptions);
|
|
2557
2592
|
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
2558
2593
|
const output = await bundler.generate();
|
|
2559
2594
|
return transformToRollupOutput(output);
|
|
2560
2595
|
}
|
|
2561
2596
|
async write(outputOptions = {}) {
|
|
2597
|
+
validateOption("output", outputOptions);
|
|
2562
2598
|
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
2563
2599
|
const output = await bundler.write();
|
|
2564
2600
|
return transformToRollupOutput(output);
|
|
@@ -2576,6 +2612,7 @@ var RolldownBuild = class {
|
|
|
2576
2612
|
//#endregion
|
|
2577
2613
|
//#region src/api/rolldown/index.ts
|
|
2578
2614
|
const rolldown = async (input) => {
|
|
2615
|
+
validateOption("input", input);
|
|
2579
2616
|
const inputOptions = await PluginDriver.callOptionsHook(input);
|
|
2580
2617
|
return new RolldownBuild(inputOptions);
|
|
2581
2618
|
};
|
|
@@ -2704,7 +2741,7 @@ const watch = (input) => {
|
|
|
2704
2741
|
|
|
2705
2742
|
//#endregion
|
|
2706
2743
|
//#region package.json
|
|
2707
|
-
var version = "1.0.0-beta.3-commit.
|
|
2744
|
+
var version = "1.0.0-beta.3-commit.d298c0b";
|
|
2708
2745
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2709
2746
|
|
|
2710
2747
|
//#endregion
|