@rolldown/browser 1.1.2 → 1.1.3
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/cli.mjs +19 -8
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +2 -2
- package/dist/experimental-index.browser.mjs +13 -8
- package/dist/experimental-index.d.mts +15 -5
- package/dist/experimental-index.mjs +14 -9
- package/dist/filter-index.d.mts +1 -1
- package/dist/index.browser.mjs +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/parallel-plugin-worker.mjs +1 -1
- package/dist/parallel-plugin.d.mts +2 -2
- package/dist/parse-ast-index.d.mts +1 -1
- package/dist/plugins-index.d.mts +3 -3
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/{rolldown-build-DkMkdHEX.js → rolldown-build-AEs_8s-I.js} +1459 -1460
- package/dist/shared/{binding-dOJO0Ipo.d.mts → binding-DyMVbTi5.d.mts} +0 -26
- package/dist/shared/{bindingify-input-options-CM59dkv7.mjs → bindingify-input-options-C6gxQEeC.mjs} +1326 -1327
- package/dist/shared/{constructors-DXDHUcCD.d.mts → constructors-CDyv7p8V.d.mts} +2 -2
- package/dist/shared/{define-config-VyEuugfx.d.mts → define-config-Tz8fY30o.d.mts} +2 -2
- package/dist/shared/{load-config-ZI8T7gXR.mjs → load-config-C6ynET_w.mjs} +1 -1
- package/dist/shared/{rolldown-build-CNErHQbt.mjs → rolldown-build-CVwFjky2.mjs} +12 -12
- package/dist/shared/{rolldown-DWdNBjur.mjs → rolldown-ro17jDL2.mjs} +1 -1
- package/dist/shared/{transform-Wt-zRSFQ.d.mts → transform-DudVZDD5.d.mts} +1 -1
- package/dist/shared/{utils-CuJMMtAZ.d.mts → utils-DLIXIK5m.d.mts} +1 -1
- package/dist/shared/{watch-DNIwEbWZ.mjs → watch-DyYqAbie.mjs} +2 -2
- package/dist/utils-index.d.mts +2 -2
- package/package.json +2 -2
package/dist/shared/{bindingify-input-options-CM59dkv7.mjs → bindingify-input-options-C6gxQEeC.mjs}
RENAMED
|
@@ -7,7 +7,7 @@ import { BindingAttachDebugInfo, BindingChunkModuleOrderBy, BindingLogLevel, Bin
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import fsp from "node:fs/promises";
|
|
9
9
|
//#region package.json
|
|
10
|
-
var version = "1.1.
|
|
10
|
+
var version = "1.1.3";
|
|
11
11
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/constants/version.ts
|
|
@@ -563,1410 +563,1410 @@ function collectChangedBundle(changed, bundle) {
|
|
|
563
563
|
};
|
|
564
564
|
}
|
|
565
565
|
//#endregion
|
|
566
|
-
//#region src/
|
|
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
|
-
BindingMagicString.prototype.appendRight = function(index, content) {
|
|
596
|
-
assertString(content, "inserted content must be a string");
|
|
597
|
-
return nativeAppendRight.call(this, index, content);
|
|
598
|
-
};
|
|
599
|
-
BindingMagicString.prototype.prependLeft = function(index, content) {
|
|
600
|
-
assertString(content, "inserted content must be a string");
|
|
601
|
-
return nativePrependLeft.call(this, index, content);
|
|
602
|
-
};
|
|
603
|
-
BindingMagicString.prototype.prependRight = function(index, content) {
|
|
604
|
-
assertString(content, "inserted content must be a string");
|
|
605
|
-
return nativePrependRight.call(this, index, content);
|
|
606
|
-
};
|
|
607
|
-
BindingMagicString.prototype.overwrite = function(start, end, content, options) {
|
|
608
|
-
assertString(content, "replacement content must be a string");
|
|
609
|
-
return nativeOverwrite.call(this, start, end, content, options);
|
|
610
|
-
};
|
|
611
|
-
BindingMagicString.prototype.update = function(start, end, content, options) {
|
|
612
|
-
assertString(content, "replacement content must be a string");
|
|
613
|
-
return nativeUpdate.call(this, start, end, content, options);
|
|
614
|
-
};
|
|
615
|
-
const nativeReplace = BindingMagicString.prototype.replace;
|
|
616
|
-
const nativeReplaceAll = BindingMagicString.prototype.replaceAll;
|
|
617
|
-
BindingMagicString.prototype.replace = function(searchValue, replacement) {
|
|
618
|
-
if (typeof searchValue === "string") return nativeReplace.call(this, searchValue, replacement);
|
|
619
|
-
if (searchValue.global) searchValue.lastIndex = 0;
|
|
620
|
-
const lastMatchEnd = this.replaceRegex(searchValue, replacement);
|
|
621
|
-
if (searchValue.global) searchValue.lastIndex = 0;
|
|
622
|
-
else if (searchValue.sticky) searchValue.lastIndex = lastMatchEnd === -1 ? 0 : lastMatchEnd;
|
|
623
|
-
return this;
|
|
624
|
-
};
|
|
625
|
-
BindingMagicString.prototype.replaceAll = function(searchValue, replacement) {
|
|
626
|
-
if (typeof searchValue === "string") return nativeReplaceAll.call(this, searchValue, replacement);
|
|
627
|
-
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
628
|
-
searchValue.lastIndex = 0;
|
|
629
|
-
this.replaceRegex(searchValue, replacement);
|
|
630
|
-
searchValue.lastIndex = 0;
|
|
631
|
-
return this;
|
|
632
|
-
};
|
|
633
|
-
/**
|
|
634
|
-
* A native MagicString implementation powered by Rust.
|
|
635
|
-
*
|
|
636
|
-
* @experimental
|
|
637
|
-
*/
|
|
638
|
-
const RolldownMagicString = BindingMagicString;
|
|
639
|
-
//#endregion
|
|
640
|
-
//#region src/utils/transform-module-info.ts
|
|
641
|
-
function transformModuleInfo(info, option) {
|
|
642
|
-
return {
|
|
643
|
-
get ast() {
|
|
644
|
-
return unsupported("ModuleInfo#ast");
|
|
645
|
-
},
|
|
646
|
-
get code() {
|
|
647
|
-
return info.code;
|
|
648
|
-
},
|
|
649
|
-
id: info.id,
|
|
650
|
-
importers: info.importers,
|
|
651
|
-
dynamicImporters: info.dynamicImporters,
|
|
652
|
-
importedIds: info.importedIds,
|
|
653
|
-
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
654
|
-
exports: info.exports,
|
|
655
|
-
isEntry: info.isEntry,
|
|
656
|
-
inputFormat: info.inputFormat,
|
|
657
|
-
...option
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
//#endregion
|
|
661
|
-
//#region src/utils/transform-sourcemap.ts
|
|
662
|
-
function isEmptySourcemapFiled(array) {
|
|
663
|
-
if (!array) return true;
|
|
664
|
-
if (array.length === 0 || !array[0]) return true;
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
|
-
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
668
|
-
if (!rawMap) return;
|
|
669
|
-
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
670
|
-
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
671
|
-
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
672
|
-
return map;
|
|
673
|
-
}
|
|
674
|
-
//#endregion
|
|
675
|
-
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/lazyDataLastImpl--3B10z3s.js
|
|
676
|
-
function e(e, t, n) {
|
|
677
|
-
let r = (n) => e(n, ...t);
|
|
678
|
-
return n === void 0 ? r : Object.assign(r, {
|
|
679
|
-
lazy: n,
|
|
680
|
-
lazyArgs: t
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/purry.js
|
|
685
|
-
function t$1(t, n, r) {
|
|
686
|
-
let i = t.length - n.length;
|
|
687
|
-
if (i === 0) return t(...n);
|
|
688
|
-
if (i === 1) return e(t, n, r);
|
|
689
|
-
throw Error(`Wrong number of arguments`);
|
|
690
|
-
}
|
|
691
|
-
//#endregion
|
|
692
|
-
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/partition.js
|
|
693
|
-
function t(...t) {
|
|
694
|
-
return t$1(n, t);
|
|
695
|
-
}
|
|
696
|
-
const n = (e, t) => {
|
|
697
|
-
let n = [[], []];
|
|
698
|
-
for (let [r, i] of e.entries()) t(i, r, e) ? n[0].push(i) : n[1].push(i);
|
|
699
|
-
return n;
|
|
566
|
+
//#region src/options/normalized-input-options.ts
|
|
567
|
+
var NormalizedInputOptionsImpl = class extends PlainObjectLike {
|
|
568
|
+
onLog;
|
|
569
|
+
inputPlugins;
|
|
570
|
+
inner;
|
|
571
|
+
constructor(inner, onLog, inputPlugins) {
|
|
572
|
+
super();
|
|
573
|
+
this.onLog = onLog;
|
|
574
|
+
this.inputPlugins = inputPlugins;
|
|
575
|
+
this.inner = inner;
|
|
576
|
+
}
|
|
577
|
+
get shimMissingExports() {
|
|
578
|
+
return this.inner.shimMissingExports;
|
|
579
|
+
}
|
|
580
|
+
get input() {
|
|
581
|
+
return this.inner.input;
|
|
582
|
+
}
|
|
583
|
+
get cwd() {
|
|
584
|
+
return this.inner.cwd;
|
|
585
|
+
}
|
|
586
|
+
get platform() {
|
|
587
|
+
return this.inner.platform;
|
|
588
|
+
}
|
|
589
|
+
get context() {
|
|
590
|
+
return this.inner.context;
|
|
591
|
+
}
|
|
592
|
+
get plugins() {
|
|
593
|
+
return this.inputPlugins;
|
|
594
|
+
}
|
|
700
595
|
};
|
|
596
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
|
|
597
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
|
|
598
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
|
|
599
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
|
|
600
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
|
|
701
601
|
//#endregion
|
|
702
|
-
//#region src/
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
return kind === "code" ? code(matcher) : id(matcher);
|
|
713
|
-
}
|
|
714
|
-
function transformFilterMatcherToFilterExprs(filterOption) {
|
|
715
|
-
if (!filterOption) return;
|
|
716
|
-
if (Array.isArray(filterOption)) return filterOption;
|
|
717
|
-
const { id, code, moduleType: moduleType$1 } = filterOption;
|
|
718
|
-
let ret = [];
|
|
719
|
-
let idIncludes = [];
|
|
720
|
-
let idExcludes = [];
|
|
721
|
-
let codeIncludes = [];
|
|
722
|
-
let codeExcludes = [];
|
|
723
|
-
if (id) [idIncludes, idExcludes] = t(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
|
|
724
|
-
if (code) [codeIncludes, codeExcludes] = t(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
|
|
725
|
-
ret.push(...idExcludes);
|
|
726
|
-
ret.push(...codeExcludes);
|
|
727
|
-
let andExprList = [];
|
|
728
|
-
if (moduleType$1) {
|
|
729
|
-
let moduleTypes = Array.isArray(moduleType$1) ? moduleType$1 : moduleType$1.include ?? [];
|
|
730
|
-
andExprList.push(or(...moduleTypes.map((m) => moduleType(m))));
|
|
602
|
+
//#region src/options/normalized-output-options.ts
|
|
603
|
+
var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
|
|
604
|
+
inner;
|
|
605
|
+
outputOptions;
|
|
606
|
+
normalizedOutputPlugins;
|
|
607
|
+
constructor(inner, outputOptions, normalizedOutputPlugins) {
|
|
608
|
+
super();
|
|
609
|
+
this.inner = inner;
|
|
610
|
+
this.outputOptions = outputOptions;
|
|
611
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
731
612
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
if (andExprList.length) ret.push(include(and(...andExprList)));
|
|
735
|
-
return ret;
|
|
736
|
-
}
|
|
737
|
-
function bindingifyGeneralHookFilter(stringKind, pattern) {
|
|
738
|
-
let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
|
|
739
|
-
let ret = [];
|
|
740
|
-
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
741
|
-
return ret.length > 0 ? { value: ret } : void 0;
|
|
742
|
-
}
|
|
743
|
-
function bindingifyFilterExpr(expr) {
|
|
744
|
-
let list = [];
|
|
745
|
-
bindingifyFilterExprImpl(expr, list);
|
|
746
|
-
return list;
|
|
747
|
-
}
|
|
748
|
-
function containsImporterId(expr) {
|
|
749
|
-
switch (expr.kind) {
|
|
750
|
-
case "and":
|
|
751
|
-
case "or": return expr.args.some(containsImporterId);
|
|
752
|
-
case "not":
|
|
753
|
-
case "include":
|
|
754
|
-
case "exclude": return containsImporterId(expr.expr);
|
|
755
|
-
case "importerId": return true;
|
|
756
|
-
default: return false;
|
|
613
|
+
get dir() {
|
|
614
|
+
return this.inner.dir ?? void 0;
|
|
757
615
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
|
|
761
|
-
}
|
|
762
|
-
function bindingifyFilterExprImpl(expr, list) {
|
|
763
|
-
switch (expr.kind) {
|
|
764
|
-
case "and": {
|
|
765
|
-
let args = expr.args;
|
|
766
|
-
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
767
|
-
list.push({
|
|
768
|
-
kind: "And",
|
|
769
|
-
payload: args.length
|
|
770
|
-
});
|
|
771
|
-
break;
|
|
772
|
-
}
|
|
773
|
-
case "or": {
|
|
774
|
-
let args = expr.args;
|
|
775
|
-
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
776
|
-
list.push({
|
|
777
|
-
kind: "Or",
|
|
778
|
-
payload: args.length
|
|
779
|
-
});
|
|
780
|
-
break;
|
|
781
|
-
}
|
|
782
|
-
case "not":
|
|
783
|
-
bindingifyFilterExprImpl(expr.expr, list);
|
|
784
|
-
list.push({ kind: "Not" });
|
|
785
|
-
break;
|
|
786
|
-
case "id":
|
|
787
|
-
list.push({
|
|
788
|
-
kind: "Id",
|
|
789
|
-
payload: expr.pattern
|
|
790
|
-
});
|
|
791
|
-
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
792
|
-
break;
|
|
793
|
-
case "importerId":
|
|
794
|
-
list.push({
|
|
795
|
-
kind: "ImporterId",
|
|
796
|
-
payload: expr.pattern
|
|
797
|
-
});
|
|
798
|
-
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
799
|
-
break;
|
|
800
|
-
case "moduleType":
|
|
801
|
-
list.push({
|
|
802
|
-
kind: "ModuleType",
|
|
803
|
-
payload: expr.pattern
|
|
804
|
-
});
|
|
805
|
-
break;
|
|
806
|
-
case "code":
|
|
807
|
-
list.push({
|
|
808
|
-
kind: "Code",
|
|
809
|
-
payload: expr.pattern
|
|
810
|
-
});
|
|
811
|
-
break;
|
|
812
|
-
case "include":
|
|
813
|
-
bindingifyFilterExprImpl(expr.expr, list);
|
|
814
|
-
list.push({ kind: "Include" });
|
|
815
|
-
break;
|
|
816
|
-
case "exclude":
|
|
817
|
-
bindingifyFilterExprImpl(expr.expr, list);
|
|
818
|
-
list.push({ kind: "Exclude" });
|
|
819
|
-
break;
|
|
820
|
-
case "query":
|
|
821
|
-
list.push({
|
|
822
|
-
kind: "QueryKey",
|
|
823
|
-
payload: expr.key
|
|
824
|
-
});
|
|
825
|
-
list.push({
|
|
826
|
-
kind: "QueryValue",
|
|
827
|
-
payload: expr.pattern
|
|
828
|
-
});
|
|
829
|
-
break;
|
|
830
|
-
default: throw new Error(`Unknown filter expression: ${expr}`);
|
|
616
|
+
get entryFileNames() {
|
|
617
|
+
return this.inner.entryFilenames || this.outputOptions.entryFileNames;
|
|
831
618
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
if (!filterOption) return;
|
|
835
|
-
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
836
|
-
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
837
|
-
}
|
|
838
|
-
function bindingifyLoadFilter(filterOption) {
|
|
839
|
-
if (!filterOption) return;
|
|
840
|
-
if (Array.isArray(filterOption)) {
|
|
841
|
-
assertNoImporterId(filterOption, "load");
|
|
842
|
-
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
619
|
+
get chunkFileNames() {
|
|
620
|
+
return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
|
|
843
621
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
function bindingifyTransformFilter(filterOption) {
|
|
847
|
-
if (!filterOption) return;
|
|
848
|
-
let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
|
|
849
|
-
assertNoImporterId(filterExprs, "transform");
|
|
850
|
-
let ret = [];
|
|
851
|
-
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
852
|
-
return { value: ret.length > 0 ? ret : void 0 };
|
|
853
|
-
}
|
|
854
|
-
function bindingifyRenderChunkFilter(filterOption) {
|
|
855
|
-
if (!filterOption) return;
|
|
856
|
-
if (Array.isArray(filterOption)) {
|
|
857
|
-
assertNoImporterId(filterOption, "renderChunk");
|
|
858
|
-
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
622
|
+
get assetFileNames() {
|
|
623
|
+
return this.inner.assetFilenames || this.outputOptions.assetFileNames;
|
|
859
624
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
//#endregion
|
|
863
|
-
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
864
|
-
function bindingifyPluginHookMeta(options) {
|
|
865
|
-
return { order: bindingPluginOrder(options.order) };
|
|
866
|
-
}
|
|
867
|
-
function bindingPluginOrder(order) {
|
|
868
|
-
switch (order) {
|
|
869
|
-
case "post": return BindingPluginOrder.Post;
|
|
870
|
-
case "pre": return BindingPluginOrder.Pre;
|
|
871
|
-
case null:
|
|
872
|
-
case void 0: return;
|
|
873
|
-
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
625
|
+
get format() {
|
|
626
|
+
return this.inner.format;
|
|
874
627
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
//#region src/plugin/fs.ts
|
|
878
|
-
const fsModule = {
|
|
879
|
-
appendFile: fsp.appendFile,
|
|
880
|
-
copyFile: fsp.copyFile,
|
|
881
|
-
mkdir: fsp.mkdir,
|
|
882
|
-
mkdtemp: fsp.mkdtemp,
|
|
883
|
-
readdir: fsp.readdir,
|
|
884
|
-
readFile: fsp.readFile,
|
|
885
|
-
realpath: fsp.realpath,
|
|
886
|
-
rename: fsp.rename,
|
|
887
|
-
rmdir: fsp.rmdir,
|
|
888
|
-
stat: fsp.stat,
|
|
889
|
-
lstat: fsp.lstat,
|
|
890
|
-
unlink: fsp.unlink,
|
|
891
|
-
writeFile: fsp.writeFile
|
|
892
|
-
};
|
|
893
|
-
//#endregion
|
|
894
|
-
//#region src/plugin/plugin-context.ts
|
|
895
|
-
var PluginContextImpl = class extends MinimalPluginContextImpl {
|
|
896
|
-
outputOptions;
|
|
897
|
-
context;
|
|
898
|
-
data;
|
|
899
|
-
onLog;
|
|
900
|
-
currentLoadingModule;
|
|
901
|
-
fs = fsModule;
|
|
902
|
-
getModuleInfo;
|
|
903
|
-
constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
|
|
904
|
-
super(onLog, logLevel, plugin.name, watchMode);
|
|
905
|
-
this.outputOptions = outputOptions;
|
|
906
|
-
this.context = context;
|
|
907
|
-
this.data = data;
|
|
908
|
-
this.onLog = onLog;
|
|
909
|
-
this.currentLoadingModule = currentLoadingModule;
|
|
910
|
-
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
628
|
+
get exports() {
|
|
629
|
+
return this.inner.exports;
|
|
911
630
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
915
|
-
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
916
|
-
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
917
|
-
const rawOptions = {
|
|
918
|
-
meta: options.meta || {},
|
|
919
|
-
moduleSideEffects: options.moduleSideEffects || null,
|
|
920
|
-
invalidate: false
|
|
921
|
-
};
|
|
922
|
-
this.data.updateModuleOption(id, rawOptions);
|
|
923
|
-
let loadPromise = this.data.loadModulePromiseMap.get(id);
|
|
924
|
-
if (!loadPromise) {
|
|
925
|
-
loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
|
|
926
|
-
this.data.loadModulePromiseMap.delete(id);
|
|
927
|
-
});
|
|
928
|
-
this.data.loadModulePromiseMap.set(id, loadPromise);
|
|
929
|
-
}
|
|
930
|
-
await loadPromise;
|
|
931
|
-
return this.data.getModuleInfo(id, this.context);
|
|
631
|
+
get sourcemap() {
|
|
632
|
+
return this.inner.sourcemap;
|
|
932
633
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
936
|
-
const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
|
|
937
|
-
if (key.startsWith("vite:")) (acc ??= {})[key] = value;
|
|
938
|
-
return acc;
|
|
939
|
-
}, void 0);
|
|
940
|
-
const res = await this.context.resolve(source, importer, {
|
|
941
|
-
importKind: options?.kind,
|
|
942
|
-
custom: receipt,
|
|
943
|
-
isEntry: options?.isEntry,
|
|
944
|
-
skipSelf: options?.skipSelf,
|
|
945
|
-
vitePluginCustom
|
|
946
|
-
});
|
|
947
|
-
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
948
|
-
if (res == null) return null;
|
|
949
|
-
const info = this.data.getModuleOption(res.id) || {};
|
|
950
|
-
return {
|
|
951
|
-
...res,
|
|
952
|
-
external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
|
|
953
|
-
...info,
|
|
954
|
-
moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
|
|
955
|
-
packageJsonPath: res.packageJsonPath
|
|
956
|
-
};
|
|
634
|
+
get sourcemapBaseUrl() {
|
|
635
|
+
return this.inner.sourcemapBaseUrl ?? void 0;
|
|
957
636
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
fileName: file.fileName,
|
|
961
|
-
name: file.name,
|
|
962
|
-
code: file.code,
|
|
963
|
-
exports: file.exports,
|
|
964
|
-
map: bindingifySourcemap(file.map),
|
|
965
|
-
sourcemapFileName: file.sourcemapFileName,
|
|
966
|
-
facadeModuleId: file.facadeModuleId,
|
|
967
|
-
isEntry: file.isEntry,
|
|
968
|
-
isDynamicEntry: file.isDynamicEntry
|
|
969
|
-
});
|
|
970
|
-
if (file.type === "chunk") return this.context.emitChunk({
|
|
971
|
-
preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
|
|
972
|
-
...file
|
|
973
|
-
});
|
|
974
|
-
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
975
|
-
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
976
|
-
return this.context.emitFile({
|
|
977
|
-
...file,
|
|
978
|
-
originalFileName: file.originalFileName || void 0,
|
|
979
|
-
source: bindingAssetSource(file.source)
|
|
980
|
-
}, filename, fnSanitizedFileName);
|
|
981
|
-
};
|
|
982
|
-
getAssetFileNames(file) {
|
|
983
|
-
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
984
|
-
type: "asset",
|
|
985
|
-
name: file.name,
|
|
986
|
-
names: file.name ? [file.name] : [],
|
|
987
|
-
originalFileName: file.originalFileName,
|
|
988
|
-
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
989
|
-
source: file.source
|
|
990
|
-
});
|
|
637
|
+
get shimMissingExports() {
|
|
638
|
+
return this.inner.shimMissingExports;
|
|
991
639
|
}
|
|
992
|
-
|
|
993
|
-
return this.
|
|
640
|
+
get name() {
|
|
641
|
+
return this.inner.name ?? void 0;
|
|
994
642
|
}
|
|
995
|
-
|
|
996
|
-
return this.
|
|
643
|
+
get file() {
|
|
644
|
+
return this.inner.file ?? void 0;
|
|
997
645
|
}
|
|
998
|
-
|
|
999
|
-
this.
|
|
646
|
+
get codeSplitting() {
|
|
647
|
+
return this.inner.codeSplitting;
|
|
1000
648
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
649
|
+
/**
|
|
650
|
+
* @deprecated Use `codeSplitting` instead.
|
|
651
|
+
*/
|
|
652
|
+
get inlineDynamicImports() {
|
|
653
|
+
return !this.inner.codeSplitting;
|
|
1003
654
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
//#region src/plugin/load-plugin-context.ts
|
|
1007
|
-
var LoadPluginContextImpl = class extends PluginContextImpl {
|
|
1008
|
-
inner;
|
|
1009
|
-
constructor(outputOptions, context, plugin, data, inner, moduleId, onLog, logLevelOption, watchMode) {
|
|
1010
|
-
super(outputOptions, context, plugin, data, onLog, logLevelOption, watchMode, moduleId);
|
|
1011
|
-
this.inner = inner;
|
|
655
|
+
get dynamicImportInCjs() {
|
|
656
|
+
return this.inner.dynamicImportInCjs;
|
|
1012
657
|
}
|
|
1013
|
-
|
|
1014
|
-
this.inner.
|
|
658
|
+
get externalLiveBindings() {
|
|
659
|
+
return this.inner.externalLiveBindings;
|
|
1015
660
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
this.
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
661
|
+
get banner() {
|
|
662
|
+
return normalizeAddon(this.outputOptions.banner);
|
|
663
|
+
}
|
|
664
|
+
get footer() {
|
|
665
|
+
return normalizeAddon(this.outputOptions.footer);
|
|
666
|
+
}
|
|
667
|
+
get postBanner() {
|
|
668
|
+
return normalizeAddon(this.outputOptions.postBanner);
|
|
669
|
+
}
|
|
670
|
+
get postFooter() {
|
|
671
|
+
return normalizeAddon(this.outputOptions.postFooter);
|
|
672
|
+
}
|
|
673
|
+
get intro() {
|
|
674
|
+
return normalizeAddon(this.outputOptions.intro);
|
|
675
|
+
}
|
|
676
|
+
get outro() {
|
|
677
|
+
return normalizeAddon(this.outputOptions.outro);
|
|
678
|
+
}
|
|
679
|
+
get esModule() {
|
|
680
|
+
return this.inner.esModule;
|
|
681
|
+
}
|
|
682
|
+
get extend() {
|
|
683
|
+
return this.inner.extend;
|
|
684
|
+
}
|
|
685
|
+
get globals() {
|
|
686
|
+
return this.inner.globals || this.outputOptions.globals;
|
|
687
|
+
}
|
|
688
|
+
get paths() {
|
|
689
|
+
return this.outputOptions.paths;
|
|
690
|
+
}
|
|
691
|
+
get hashCharacters() {
|
|
692
|
+
return this.inner.hashCharacters;
|
|
693
|
+
}
|
|
694
|
+
get sourcemapDebugIds() {
|
|
695
|
+
return this.inner.sourcemapDebugIds;
|
|
696
|
+
}
|
|
697
|
+
get sourcemapExcludeSources() {
|
|
698
|
+
return this.inner.sourcemapExcludeSources;
|
|
699
|
+
}
|
|
700
|
+
get sourcemapIgnoreList() {
|
|
701
|
+
return this.outputOptions.sourcemapIgnoreList;
|
|
702
|
+
}
|
|
703
|
+
get sourcemapPathTransform() {
|
|
704
|
+
return this.outputOptions.sourcemapPathTransform;
|
|
705
|
+
}
|
|
706
|
+
get minify() {
|
|
707
|
+
let ret = this.inner.minify;
|
|
708
|
+
if (typeof ret === "object" && ret !== null) {
|
|
709
|
+
delete ret["codegen"];
|
|
710
|
+
delete ret["module"];
|
|
711
|
+
delete ret["sourcemap"];
|
|
712
|
+
}
|
|
713
|
+
return ret;
|
|
714
|
+
}
|
|
715
|
+
get legalComments() {
|
|
716
|
+
return this.inner.legalComments;
|
|
717
|
+
}
|
|
718
|
+
get comments() {
|
|
719
|
+
const c = this.inner.comments;
|
|
720
|
+
return {
|
|
721
|
+
legal: c.legal ?? true,
|
|
722
|
+
annotation: c.annotation ?? true,
|
|
723
|
+
jsdoc: c.jsdoc ?? true
|
|
1034
724
|
};
|
|
1035
|
-
this.debug = getLogHandler(this.debug);
|
|
1036
|
-
this.warn = getLogHandler(this.warn);
|
|
1037
|
-
this.info = getLogHandler(this.info);
|
|
1038
725
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1042
|
-
e.id = this.moduleId;
|
|
1043
|
-
e.hook = "transform";
|
|
1044
|
-
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
726
|
+
get polyfillRequire() {
|
|
727
|
+
return this.inner.polyfillRequire;
|
|
1045
728
|
}
|
|
1046
|
-
|
|
1047
|
-
return
|
|
729
|
+
get plugins() {
|
|
730
|
+
return this.normalizedOutputPlugins;
|
|
1048
731
|
}
|
|
1049
|
-
|
|
1050
|
-
this.inner.
|
|
732
|
+
get preserveModules() {
|
|
733
|
+
return this.inner.preserveModules;
|
|
1051
734
|
}
|
|
1052
|
-
|
|
1053
|
-
this.inner.
|
|
735
|
+
get preserveModulesRoot() {
|
|
736
|
+
return this.inner.preserveModulesRoot;
|
|
737
|
+
}
|
|
738
|
+
get virtualDirname() {
|
|
739
|
+
return this.inner.virtualDirname;
|
|
740
|
+
}
|
|
741
|
+
get topLevelVar() {
|
|
742
|
+
return this.inner.topLevelVar ?? false;
|
|
743
|
+
}
|
|
744
|
+
get minifyInternalExports() {
|
|
745
|
+
return this.inner.minifyInternalExports ?? false;
|
|
1054
746
|
}
|
|
1055
747
|
};
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
748
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
|
|
749
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
|
|
750
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
|
|
751
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
|
|
752
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
|
|
753
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
|
|
754
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
|
|
755
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
|
|
756
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
|
|
757
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
|
|
758
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
|
|
759
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "codeSplitting", null);
|
|
760
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
|
|
761
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dynamicImportInCjs", null);
|
|
762
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
|
|
763
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
|
|
764
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
|
|
765
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postBanner", null);
|
|
766
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postFooter", null);
|
|
767
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
|
|
768
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
|
|
769
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
|
|
770
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
|
|
771
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
|
|
772
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
|
|
773
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
|
|
774
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
|
|
775
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapExcludeSources", null);
|
|
776
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
|
|
777
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
|
|
778
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
|
|
779
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
|
|
780
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "comments", null);
|
|
781
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
|
|
782
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
|
|
783
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
|
|
784
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
|
|
785
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
|
|
786
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
|
|
787
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
|
|
788
|
+
function normalizeAddon(value) {
|
|
789
|
+
if (typeof value === "function") return value;
|
|
790
|
+
return () => value || "";
|
|
1060
791
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
const { handler, meta } = normalizeHook(hook);
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region src/utils/transform-module-info.ts
|
|
794
|
+
function transformModuleInfo(info, option) {
|
|
1065
795
|
return {
|
|
1066
|
-
|
|
1067
|
-
|
|
796
|
+
get ast() {
|
|
797
|
+
return unsupported("ModuleInfo#ast");
|
|
1068
798
|
},
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
function bindingifyBuildEnd(args) {
|
|
1073
|
-
const hook = args.plugin.buildEnd;
|
|
1074
|
-
if (!hook) return {};
|
|
1075
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1076
|
-
return {
|
|
1077
|
-
plugin: async (ctx, err) => {
|
|
1078
|
-
await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
799
|
+
get code() {
|
|
800
|
+
return info.code;
|
|
1079
801
|
},
|
|
1080
|
-
|
|
802
|
+
id: info.id,
|
|
803
|
+
importers: info.importers,
|
|
804
|
+
dynamicImporters: info.dynamicImporters,
|
|
805
|
+
importedIds: info.importedIds,
|
|
806
|
+
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
807
|
+
exports: info.exports,
|
|
808
|
+
isEntry: info.isEntry,
|
|
809
|
+
inputFormat: info.inputFormat,
|
|
810
|
+
...option
|
|
1081
811
|
};
|
|
1082
812
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
813
|
+
//#endregion
|
|
814
|
+
//#region src/plugin/plugin-context-data.ts
|
|
815
|
+
var PluginContextData = class {
|
|
816
|
+
onLog;
|
|
817
|
+
outputOptions;
|
|
818
|
+
normalizedInputPlugins;
|
|
819
|
+
normalizedOutputPlugins;
|
|
820
|
+
moduleOptionMap = /* @__PURE__ */ new Map();
|
|
821
|
+
resolveOptionsMap = /* @__PURE__ */ new Map();
|
|
822
|
+
loadModulePromiseMap = /* @__PURE__ */ new Map();
|
|
823
|
+
renderedChunkMeta = null;
|
|
824
|
+
normalizedInputOptions = null;
|
|
825
|
+
normalizedOutputOptions = null;
|
|
826
|
+
constructor(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins) {
|
|
827
|
+
this.onLog = onLog;
|
|
828
|
+
this.outputOptions = outputOptions;
|
|
829
|
+
this.normalizedInputPlugins = normalizedInputPlugins;
|
|
830
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
831
|
+
}
|
|
832
|
+
updateModuleOption(id, option) {
|
|
833
|
+
const existing = this.moduleOptionMap.get(id);
|
|
834
|
+
if (existing) {
|
|
835
|
+
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
836
|
+
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
837
|
+
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
838
|
+
} else {
|
|
839
|
+
this.moduleOptionMap.set(id, option);
|
|
840
|
+
return option;
|
|
841
|
+
}
|
|
842
|
+
return existing;
|
|
843
|
+
}
|
|
844
|
+
getModuleOption(id) {
|
|
845
|
+
const option = this.moduleOptionMap.get(id);
|
|
846
|
+
if (!option) {
|
|
847
|
+
const raw = {
|
|
848
|
+
moduleSideEffects: null,
|
|
849
|
+
meta: {}
|
|
1103
850
|
};
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
id: specifier,
|
|
1131
|
-
external: true
|
|
1132
|
-
};
|
|
1133
|
-
if (typeof ret === "string") return { id: ret };
|
|
1134
|
-
const result = {
|
|
1135
|
-
id: ret.id,
|
|
1136
|
-
external: ret.external,
|
|
1137
|
-
packageJsonPath: ret.packageJsonPath
|
|
1138
|
-
};
|
|
1139
|
-
if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
|
|
1140
|
-
args.pluginContextData.updateModuleOption(ret.id, {
|
|
1141
|
-
meta: ret.meta || {},
|
|
1142
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
1143
|
-
invalidate: false
|
|
1144
|
-
});
|
|
1145
|
-
return result;
|
|
1146
|
-
},
|
|
1147
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
function bindingifyTransform(args) {
|
|
1151
|
-
const hook = args.plugin.transform;
|
|
1152
|
-
if (!hook) return {};
|
|
1153
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
1154
|
-
return {
|
|
1155
|
-
plugin: async (ctx, code, id, meta) => {
|
|
1156
|
-
let magicStringInstance, astInstance;
|
|
1157
|
-
Object.defineProperties(meta, {
|
|
1158
|
-
magicString: { get() {
|
|
1159
|
-
if (magicStringInstance) return magicStringInstance;
|
|
1160
|
-
magicStringInstance = new RolldownMagicString(code);
|
|
1161
|
-
return magicStringInstance;
|
|
1162
|
-
} },
|
|
1163
|
-
ast: { get() {
|
|
1164
|
-
if (astInstance) return astInstance;
|
|
1165
|
-
let lang = "js";
|
|
1166
|
-
switch (meta.moduleType) {
|
|
1167
|
-
case "js":
|
|
1168
|
-
case "jsx":
|
|
1169
|
-
case "ts":
|
|
1170
|
-
case "tsx":
|
|
1171
|
-
lang = meta.moduleType;
|
|
1172
|
-
break;
|
|
1173
|
-
default: break;
|
|
1174
|
-
}
|
|
1175
|
-
astInstance = parseAst(code, {
|
|
1176
|
-
astType: meta.moduleType.includes("ts") ? "ts" : "js",
|
|
1177
|
-
lang
|
|
1178
|
-
});
|
|
1179
|
-
return astInstance;
|
|
1180
|
-
} }
|
|
1181
|
-
});
|
|
1182
|
-
const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
|
|
1183
|
-
const ret = await handler.call(transformCtx, code, id, meta);
|
|
1184
|
-
if (ret == null) return;
|
|
1185
|
-
if (typeof ret === "string") return { code: ret };
|
|
1186
|
-
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1187
|
-
meta: ret.meta ?? {},
|
|
1188
|
-
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1189
|
-
invalidate: false
|
|
1190
|
-
});
|
|
1191
|
-
let normalizedCode = void 0;
|
|
1192
|
-
let map = ret.map;
|
|
1193
|
-
let mapHandledByNativeChannel = false;
|
|
1194
|
-
if (typeof ret.code === "string") normalizedCode = ret.code;
|
|
1195
|
-
else if (ret.code instanceof RolldownMagicString) {
|
|
1196
|
-
let magicString = ret.code;
|
|
1197
|
-
normalizedCode = magicString.toString();
|
|
1198
|
-
let fallbackSourcemap = ctx.sendMagicString(magicString);
|
|
1199
|
-
if (fallbackSourcemap != void 0) map = fallbackSourcemap;
|
|
1200
|
-
else mapHandledByNativeChannel = true;
|
|
851
|
+
this.moduleOptionMap.set(id, raw);
|
|
852
|
+
return raw;
|
|
853
|
+
}
|
|
854
|
+
return option;
|
|
855
|
+
}
|
|
856
|
+
getModuleInfo(id, context) {
|
|
857
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
858
|
+
if (bindingInfo) {
|
|
859
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
860
|
+
return this.proxyModuleInfo(id, info);
|
|
861
|
+
}
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
proxyModuleInfo(id, info) {
|
|
865
|
+
let moduleSideEffects = info.moduleSideEffects;
|
|
866
|
+
Object.defineProperty(info, "moduleSideEffects", {
|
|
867
|
+
get() {
|
|
868
|
+
return moduleSideEffects;
|
|
869
|
+
},
|
|
870
|
+
set: (v) => {
|
|
871
|
+
this.updateModuleOption(id, {
|
|
872
|
+
moduleSideEffects: v,
|
|
873
|
+
meta: info.meta,
|
|
874
|
+
invalidate: true
|
|
875
|
+
});
|
|
876
|
+
moduleSideEffects = v;
|
|
1201
877
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)) ?? (mapHandledByNativeChannel || ret.map === null ? null : void 0),
|
|
1205
|
-
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
|
|
1206
|
-
moduleType: ret.moduleType
|
|
1207
|
-
};
|
|
1208
|
-
},
|
|
1209
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
1210
|
-
filter: bindingifyTransformFilter(options.filter)
|
|
1211
|
-
};
|
|
1212
|
-
}
|
|
1213
|
-
function bindingifyLoad(args) {
|
|
1214
|
-
const hook = args.plugin.load;
|
|
1215
|
-
if (!hook) return {};
|
|
1216
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
1217
|
-
return {
|
|
1218
|
-
plugin: async (ctx, id) => {
|
|
1219
|
-
const ret = await handler.call(new LoadPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, args.onLog, args.logLevel, args.watchMode), id);
|
|
1220
|
-
if (ret == null) return;
|
|
1221
|
-
if (typeof ret === "string") return { code: ret };
|
|
1222
|
-
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1223
|
-
meta: ret.meta || {},
|
|
1224
|
-
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1225
|
-
invalidate: false
|
|
1226
|
-
});
|
|
1227
|
-
let map = preProcessSourceMap(ret, id);
|
|
1228
|
-
return {
|
|
1229
|
-
code: ret.code,
|
|
1230
|
-
map: bindingifySourcemap(map),
|
|
1231
|
-
moduleType: ret.moduleType,
|
|
1232
|
-
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
|
|
1233
|
-
};
|
|
1234
|
-
},
|
|
1235
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
1236
|
-
filter: bindingifyLoadFilter(options.filter)
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
function preProcessSourceMap(ret, id) {
|
|
1240
|
-
if (!ret.map) return;
|
|
1241
|
-
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
1242
|
-
if (!isEmptySourcemapFiled(map.sources)) {
|
|
1243
|
-
const directory = path.dirname(id) || ".";
|
|
1244
|
-
const sourceRoot = map.sourceRoot || ".";
|
|
1245
|
-
map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
|
|
878
|
+
});
|
|
879
|
+
return info;
|
|
1246
880
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
881
|
+
getModuleIds(context) {
|
|
882
|
+
return context.getModuleIds().values();
|
|
883
|
+
}
|
|
884
|
+
saveResolveOptions(options) {
|
|
885
|
+
const index = this.resolveOptionsMap.size;
|
|
886
|
+
this.resolveOptionsMap.set(index, options);
|
|
887
|
+
return index;
|
|
888
|
+
}
|
|
889
|
+
getSavedResolveOptions(receipt) {
|
|
890
|
+
return this.resolveOptionsMap.get(receipt);
|
|
891
|
+
}
|
|
892
|
+
removeSavedResolveOptions(receipt) {
|
|
893
|
+
this.resolveOptionsMap.delete(receipt);
|
|
894
|
+
}
|
|
895
|
+
setRenderChunkMeta(meta) {
|
|
896
|
+
this.renderedChunkMeta = meta;
|
|
897
|
+
}
|
|
898
|
+
getRenderChunkMeta() {
|
|
899
|
+
return this.renderedChunkMeta;
|
|
900
|
+
}
|
|
901
|
+
getInputOptions(opts) {
|
|
902
|
+
this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog, this.normalizedInputPlugins);
|
|
903
|
+
return this.normalizedInputOptions;
|
|
904
|
+
}
|
|
905
|
+
getOutputOptions(opts) {
|
|
906
|
+
this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
|
|
907
|
+
return this.normalizedOutputOptions;
|
|
908
|
+
}
|
|
909
|
+
clear() {
|
|
910
|
+
this.renderedChunkMeta = null;
|
|
911
|
+
this.loadModulePromiseMap.clear();
|
|
912
|
+
}
|
|
913
|
+
};
|
|
1260
914
|
//#endregion
|
|
1261
|
-
//#region src/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
},
|
|
1270
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1271
|
-
};
|
|
915
|
+
//#region src/binding-magic-string.ts
|
|
916
|
+
Object.defineProperty(BindingMagicString.prototype, "isRolldownMagicString", {
|
|
917
|
+
value: true,
|
|
918
|
+
writable: false,
|
|
919
|
+
configurable: false
|
|
920
|
+
});
|
|
921
|
+
function assertString(content, msg) {
|
|
922
|
+
if (typeof content !== "string") throw new TypeError(msg);
|
|
1272
923
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
};
|
|
1344
|
-
}
|
|
1345
|
-
function bindingifyAugmentChunkHash(args) {
|
|
1346
|
-
const hook = args.plugin.augmentChunkHash;
|
|
1347
|
-
if (!hook) return {};
|
|
1348
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1349
|
-
return {
|
|
1350
|
-
plugin: async (ctx, chunk) => {
|
|
1351
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1352
|
-
},
|
|
1353
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
function bindingifyRenderError(args) {
|
|
1357
|
-
const hook = args.plugin.renderError;
|
|
1358
|
-
if (!hook) return {};
|
|
1359
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1360
|
-
return {
|
|
1361
|
-
plugin: async (ctx, err) => {
|
|
1362
|
-
handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
|
|
1363
|
-
},
|
|
1364
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1365
|
-
};
|
|
924
|
+
const nativeAppend = BindingMagicString.prototype.append;
|
|
925
|
+
const nativePrepend = BindingMagicString.prototype.prepend;
|
|
926
|
+
const nativeAppendLeft = BindingMagicString.prototype.appendLeft;
|
|
927
|
+
const nativeAppendRight = BindingMagicString.prototype.appendRight;
|
|
928
|
+
const nativePrependLeft = BindingMagicString.prototype.prependLeft;
|
|
929
|
+
const nativePrependRight = BindingMagicString.prototype.prependRight;
|
|
930
|
+
const nativeOverwrite = BindingMagicString.prototype.overwrite;
|
|
931
|
+
const nativeUpdate = BindingMagicString.prototype.update;
|
|
932
|
+
BindingMagicString.prototype.append = function(content) {
|
|
933
|
+
assertString(content, "outro content must be a string");
|
|
934
|
+
return nativeAppend.call(this, content);
|
|
935
|
+
};
|
|
936
|
+
BindingMagicString.prototype.prepend = function(content) {
|
|
937
|
+
assertString(content, "outro content must be a string");
|
|
938
|
+
return nativePrepend.call(this, content);
|
|
939
|
+
};
|
|
940
|
+
BindingMagicString.prototype.appendLeft = function(index, content) {
|
|
941
|
+
assertString(content, "inserted content must be a string");
|
|
942
|
+
return nativeAppendLeft.call(this, index, content);
|
|
943
|
+
};
|
|
944
|
+
BindingMagicString.prototype.appendRight = function(index, content) {
|
|
945
|
+
assertString(content, "inserted content must be a string");
|
|
946
|
+
return nativeAppendRight.call(this, index, content);
|
|
947
|
+
};
|
|
948
|
+
BindingMagicString.prototype.prependLeft = function(index, content) {
|
|
949
|
+
assertString(content, "inserted content must be a string");
|
|
950
|
+
return nativePrependLeft.call(this, index, content);
|
|
951
|
+
};
|
|
952
|
+
BindingMagicString.prototype.prependRight = function(index, content) {
|
|
953
|
+
assertString(content, "inserted content must be a string");
|
|
954
|
+
return nativePrependRight.call(this, index, content);
|
|
955
|
+
};
|
|
956
|
+
BindingMagicString.prototype.overwrite = function(start, end, content, options) {
|
|
957
|
+
assertString(content, "replacement content must be a string");
|
|
958
|
+
return nativeOverwrite.call(this, start, end, content, options);
|
|
959
|
+
};
|
|
960
|
+
BindingMagicString.prototype.update = function(start, end, content, options) {
|
|
961
|
+
assertString(content, "replacement content must be a string");
|
|
962
|
+
return nativeUpdate.call(this, start, end, content, options);
|
|
963
|
+
};
|
|
964
|
+
const nativeReplace = BindingMagicString.prototype.replace;
|
|
965
|
+
const nativeReplaceAll = BindingMagicString.prototype.replaceAll;
|
|
966
|
+
BindingMagicString.prototype.replace = function(searchValue, replacement) {
|
|
967
|
+
if (typeof searchValue === "string") return nativeReplace.call(this, searchValue, replacement);
|
|
968
|
+
if (searchValue.global) searchValue.lastIndex = 0;
|
|
969
|
+
const lastMatchEnd = this.replaceRegex(searchValue, replacement);
|
|
970
|
+
if (searchValue.global) searchValue.lastIndex = 0;
|
|
971
|
+
else if (searchValue.sticky) searchValue.lastIndex = lastMatchEnd === -1 ? 0 : lastMatchEnd;
|
|
972
|
+
return this;
|
|
973
|
+
};
|
|
974
|
+
BindingMagicString.prototype.replaceAll = function(searchValue, replacement) {
|
|
975
|
+
if (typeof searchValue === "string") return nativeReplaceAll.call(this, searchValue, replacement);
|
|
976
|
+
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
977
|
+
searchValue.lastIndex = 0;
|
|
978
|
+
this.replaceRegex(searchValue, replacement);
|
|
979
|
+
searchValue.lastIndex = 0;
|
|
980
|
+
return this;
|
|
981
|
+
};
|
|
982
|
+
/**
|
|
983
|
+
* A native MagicString implementation powered by Rust.
|
|
984
|
+
*
|
|
985
|
+
* @experimental
|
|
986
|
+
*/
|
|
987
|
+
const RolldownMagicString = BindingMagicString;
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/utils/transform-sourcemap.ts
|
|
990
|
+
function isEmptySourcemapFiled(array) {
|
|
991
|
+
if (!array) return true;
|
|
992
|
+
if (array.length === 0 || !array[0]) return true;
|
|
993
|
+
return false;
|
|
1366
994
|
}
|
|
1367
|
-
function
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
const changed = {
|
|
1374
|
-
updated: /* @__PURE__ */ new Set(),
|
|
1375
|
-
deleted: /* @__PURE__ */ new Set()
|
|
1376
|
-
};
|
|
1377
|
-
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1378
|
-
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1379
|
-
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
1380
|
-
return collectChangedBundle(changed, output);
|
|
1381
|
-
},
|
|
1382
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1383
|
-
};
|
|
995
|
+
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
996
|
+
if (!rawMap) return;
|
|
997
|
+
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
998
|
+
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
999
|
+
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
1000
|
+
return map;
|
|
1384
1001
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
return {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
deleted: /* @__PURE__ */ new Set()
|
|
1394
|
-
};
|
|
1395
|
-
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1396
|
-
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1397
|
-
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
|
|
1398
|
-
return collectChangedBundle(changed, output);
|
|
1399
|
-
},
|
|
1400
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1401
|
-
};
|
|
1002
|
+
//#endregion
|
|
1003
|
+
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/lazyDataLastImpl--3B10z3s.js
|
|
1004
|
+
function e(e, t, n) {
|
|
1005
|
+
let r = (n) => e(n, ...t);
|
|
1006
|
+
return n === void 0 ? r : Object.assign(r, {
|
|
1007
|
+
lazy: n,
|
|
1008
|
+
lazyArgs: t
|
|
1009
|
+
});
|
|
1402
1010
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
return
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
},
|
|
1411
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1412
|
-
};
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/purry.js
|
|
1013
|
+
function t$1(t, n, r) {
|
|
1014
|
+
let i = t.length - n.length;
|
|
1015
|
+
if (i === 0) return t(...n);
|
|
1016
|
+
if (i === 1) return e(t, n, r);
|
|
1017
|
+
throw Error(`Wrong number of arguments`);
|
|
1413
1018
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
return {
|
|
1419
|
-
plugin: async (ctx, chunk) => {
|
|
1420
|
-
if (typeof handler === "string") return handler;
|
|
1421
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1422
|
-
},
|
|
1423
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1424
|
-
};
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region ../../node_modules/.pnpm/remeda@2.39.0/node_modules/remeda/dist/partition.js
|
|
1021
|
+
function t(...t) {
|
|
1022
|
+
return t$1(n, t);
|
|
1425
1023
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1024
|
+
const n = (e, t) => {
|
|
1025
|
+
let n = [[], []];
|
|
1026
|
+
for (let [r, i] of e.entries()) t(i, r, e) ? n[0].push(i) : n[1].push(i);
|
|
1027
|
+
return n;
|
|
1028
|
+
};
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/plugin/bindingify-hook-filter.ts
|
|
1031
|
+
function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
|
|
1032
|
+
if (typeof matcher === "string" || matcher instanceof RegExp) return [include(generateAtomMatcher(stringKind, matcher))];
|
|
1033
|
+
if (Array.isArray(matcher)) return matcher.map((m) => include(generateAtomMatcher(stringKind, m)));
|
|
1034
|
+
let ret = [];
|
|
1035
|
+
if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => exclude(generateAtomMatcher(stringKind, m))));
|
|
1036
|
+
if (matcher.include) ret.push(...arraify(matcher.include).map((m) => include(generateAtomMatcher(stringKind, m))));
|
|
1037
|
+
return ret;
|
|
1437
1038
|
}
|
|
1438
|
-
function
|
|
1439
|
-
|
|
1440
|
-
if (!hook) return {};
|
|
1441
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1442
|
-
return {
|
|
1443
|
-
plugin: async (ctx, chunk) => {
|
|
1444
|
-
if (typeof handler === "string") return handler;
|
|
1445
|
-
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1446
|
-
},
|
|
1447
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1448
|
-
};
|
|
1039
|
+
function generateAtomMatcher(kind, matcher) {
|
|
1040
|
+
return kind === "code" ? code(matcher) : id(matcher);
|
|
1449
1041
|
}
|
|
1450
|
-
function
|
|
1451
|
-
|
|
1452
|
-
if (
|
|
1453
|
-
const {
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1042
|
+
function transformFilterMatcherToFilterExprs(filterOption) {
|
|
1043
|
+
if (!filterOption) return;
|
|
1044
|
+
if (Array.isArray(filterOption)) return filterOption;
|
|
1045
|
+
const { id, code, moduleType: moduleType$1 } = filterOption;
|
|
1046
|
+
let ret = [];
|
|
1047
|
+
let idIncludes = [];
|
|
1048
|
+
let idExcludes = [];
|
|
1049
|
+
let codeIncludes = [];
|
|
1050
|
+
let codeExcludes = [];
|
|
1051
|
+
if (id) [idIncludes, idExcludes] = t(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
|
|
1052
|
+
if (code) [codeIncludes, codeExcludes] = t(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
|
|
1053
|
+
ret.push(...idExcludes);
|
|
1054
|
+
ret.push(...codeExcludes);
|
|
1055
|
+
let andExprList = [];
|
|
1056
|
+
if (moduleType$1) {
|
|
1057
|
+
let moduleTypes = Array.isArray(moduleType$1) ? moduleType$1 : moduleType$1.include ?? [];
|
|
1058
|
+
andExprList.push(or(...moduleTypes.map((m) => moduleType(m))));
|
|
1059
|
+
}
|
|
1060
|
+
if (idIncludes.length) andExprList.push(or(...idIncludes.map((item) => item.expr)));
|
|
1061
|
+
if (codeIncludes.length) andExprList.push(or(...codeIncludes.map((item) => item.expr)));
|
|
1062
|
+
if (andExprList.length) ret.push(include(and(...andExprList)));
|
|
1063
|
+
return ret;
|
|
1461
1064
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
const { handler, meta } = normalizeHook(hook);
|
|
1468
|
-
return {
|
|
1469
|
-
plugin: async (ctx, id, event) => {
|
|
1470
|
-
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
|
|
1471
|
-
},
|
|
1472
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1473
|
-
};
|
|
1065
|
+
function bindingifyGeneralHookFilter(stringKind, pattern) {
|
|
1066
|
+
let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
|
|
1067
|
+
let ret = [];
|
|
1068
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
1069
|
+
return ret.length > 0 ? { value: ret } : void 0;
|
|
1474
1070
|
}
|
|
1475
|
-
function
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
return {
|
|
1480
|
-
plugin: async (ctx) => {
|
|
1481
|
-
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
|
|
1482
|
-
},
|
|
1483
|
-
meta: bindingifyPluginHookMeta(meta)
|
|
1484
|
-
};
|
|
1071
|
+
function bindingifyFilterExpr(expr) {
|
|
1072
|
+
let list = [];
|
|
1073
|
+
bindingifyFilterExprImpl(expr, list);
|
|
1074
|
+
return list;
|
|
1485
1075
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1076
|
+
function containsImporterId(expr) {
|
|
1077
|
+
switch (expr.kind) {
|
|
1078
|
+
case "and":
|
|
1079
|
+
case "or": return expr.args.some(containsImporterId);
|
|
1080
|
+
case "not":
|
|
1081
|
+
case "include":
|
|
1082
|
+
case "exclude": return containsImporterId(expr.expr);
|
|
1083
|
+
case "importerId": return true;
|
|
1084
|
+
default: return false;
|
|
1493
1085
|
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1086
|
+
}
|
|
1087
|
+
function assertNoImporterId(filterExprs, hookName) {
|
|
1088
|
+
if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
|
|
1089
|
+
}
|
|
1090
|
+
function bindingifyFilterExprImpl(expr, list) {
|
|
1091
|
+
switch (expr.kind) {
|
|
1092
|
+
case "and": {
|
|
1093
|
+
let args = expr.args;
|
|
1094
|
+
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
1095
|
+
list.push({
|
|
1096
|
+
kind: "And",
|
|
1097
|
+
payload: args.length
|
|
1098
|
+
});
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
case "or": {
|
|
1102
|
+
let args = expr.args;
|
|
1103
|
+
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
1104
|
+
list.push({
|
|
1105
|
+
kind: "Or",
|
|
1106
|
+
payload: args.length
|
|
1107
|
+
});
|
|
1108
|
+
break;
|
|
1109
|
+
}
|
|
1110
|
+
case "not":
|
|
1111
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
1112
|
+
list.push({ kind: "Not" });
|
|
1113
|
+
break;
|
|
1114
|
+
case "id":
|
|
1115
|
+
list.push({
|
|
1116
|
+
kind: "Id",
|
|
1117
|
+
payload: expr.pattern
|
|
1118
|
+
});
|
|
1119
|
+
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
1120
|
+
break;
|
|
1121
|
+
case "importerId":
|
|
1122
|
+
list.push({
|
|
1123
|
+
kind: "ImporterId",
|
|
1124
|
+
payload: expr.pattern
|
|
1125
|
+
});
|
|
1126
|
+
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
1127
|
+
break;
|
|
1128
|
+
case "moduleType":
|
|
1129
|
+
list.push({
|
|
1130
|
+
kind: "ModuleType",
|
|
1131
|
+
payload: expr.pattern
|
|
1132
|
+
});
|
|
1133
|
+
break;
|
|
1134
|
+
case "code":
|
|
1135
|
+
list.push({
|
|
1136
|
+
kind: "Code",
|
|
1137
|
+
payload: expr.pattern
|
|
1138
|
+
});
|
|
1139
|
+
break;
|
|
1140
|
+
case "include":
|
|
1141
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
1142
|
+
list.push({ kind: "Include" });
|
|
1143
|
+
break;
|
|
1144
|
+
case "exclude":
|
|
1145
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
1146
|
+
list.push({ kind: "Exclude" });
|
|
1147
|
+
break;
|
|
1148
|
+
case "query":
|
|
1149
|
+
list.push({
|
|
1150
|
+
kind: "QueryKey",
|
|
1151
|
+
payload: expr.key
|
|
1152
|
+
});
|
|
1153
|
+
list.push({
|
|
1154
|
+
kind: "QueryValue",
|
|
1155
|
+
payload: expr.pattern
|
|
1156
|
+
});
|
|
1157
|
+
break;
|
|
1158
|
+
default: throw new Error(`Unknown filter expression: ${expr}`);
|
|
1496
1159
|
}
|
|
1497
|
-
}
|
|
1498
|
-
function
|
|
1499
|
-
|
|
1500
|
-
if (
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
if (
|
|
1505
|
-
if (
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
if (
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
return
|
|
1160
|
+
}
|
|
1161
|
+
function bindingifyResolveIdFilter(filterOption) {
|
|
1162
|
+
if (!filterOption) return;
|
|
1163
|
+
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
1164
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
1165
|
+
}
|
|
1166
|
+
function bindingifyLoadFilter(filterOption) {
|
|
1167
|
+
if (!filterOption) return;
|
|
1168
|
+
if (Array.isArray(filterOption)) {
|
|
1169
|
+
assertNoImporterId(filterOption, "load");
|
|
1170
|
+
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
1171
|
+
}
|
|
1172
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
1173
|
+
}
|
|
1174
|
+
function bindingifyTransformFilter(filterOption) {
|
|
1175
|
+
if (!filterOption) return;
|
|
1176
|
+
let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
|
|
1177
|
+
assertNoImporterId(filterExprs, "transform");
|
|
1178
|
+
let ret = [];
|
|
1179
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
1180
|
+
return { value: ret.length > 0 ? ret : void 0 };
|
|
1181
|
+
}
|
|
1182
|
+
function bindingifyRenderChunkFilter(filterOption) {
|
|
1183
|
+
if (!filterOption) return;
|
|
1184
|
+
if (Array.isArray(filterOption)) {
|
|
1185
|
+
assertNoImporterId(filterOption, "renderChunk");
|
|
1186
|
+
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
1187
|
+
}
|
|
1188
|
+
return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
|
|
1521
1189
|
}
|
|
1522
1190
|
//#endregion
|
|
1523
|
-
//#region src/plugin/bindingify-plugin.ts
|
|
1524
|
-
function
|
|
1525
|
-
|
|
1526
|
-
plugin,
|
|
1527
|
-
options,
|
|
1528
|
-
outputOptions,
|
|
1529
|
-
pluginContextData,
|
|
1530
|
-
onLog,
|
|
1531
|
-
logLevel,
|
|
1532
|
-
watchMode,
|
|
1533
|
-
normalizedOutputPlugins
|
|
1534
|
-
};
|
|
1535
|
-
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
|
|
1536
|
-
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
|
|
1537
|
-
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
|
|
1538
|
-
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
|
|
1539
|
-
const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
|
|
1540
|
-
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
|
|
1541
|
-
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
|
|
1542
|
-
const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
|
|
1543
|
-
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
1544
|
-
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
1545
|
-
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
1546
|
-
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
1547
|
-
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
1548
|
-
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
1549
|
-
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
|
|
1550
|
-
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
|
|
1551
|
-
const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
|
|
1552
|
-
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
|
|
1553
|
-
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
1554
|
-
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
1555
|
-
let hookUsage = extractHookUsage(plugin).inner();
|
|
1556
|
-
return wrapHandlers({
|
|
1557
|
-
name: plugin.name,
|
|
1558
|
-
buildStart,
|
|
1559
|
-
buildStartMeta,
|
|
1560
|
-
resolveId,
|
|
1561
|
-
resolveIdMeta,
|
|
1562
|
-
resolveIdFilter,
|
|
1563
|
-
resolveDynamicImport,
|
|
1564
|
-
resolveDynamicImportMeta,
|
|
1565
|
-
buildEnd,
|
|
1566
|
-
buildEndMeta,
|
|
1567
|
-
transform,
|
|
1568
|
-
transformMeta,
|
|
1569
|
-
transformFilter,
|
|
1570
|
-
moduleParsed,
|
|
1571
|
-
moduleParsedMeta,
|
|
1572
|
-
load,
|
|
1573
|
-
loadMeta,
|
|
1574
|
-
loadFilter,
|
|
1575
|
-
renderChunk,
|
|
1576
|
-
renderChunkMeta,
|
|
1577
|
-
renderChunkFilter,
|
|
1578
|
-
augmentChunkHash,
|
|
1579
|
-
augmentChunkHashMeta,
|
|
1580
|
-
renderStart,
|
|
1581
|
-
renderStartMeta,
|
|
1582
|
-
renderError,
|
|
1583
|
-
renderErrorMeta,
|
|
1584
|
-
generateBundle,
|
|
1585
|
-
generateBundleMeta,
|
|
1586
|
-
writeBundle,
|
|
1587
|
-
writeBundleMeta,
|
|
1588
|
-
closeBundle,
|
|
1589
|
-
closeBundleMeta,
|
|
1590
|
-
banner,
|
|
1591
|
-
bannerMeta,
|
|
1592
|
-
footer,
|
|
1593
|
-
footerMeta,
|
|
1594
|
-
intro,
|
|
1595
|
-
introMeta,
|
|
1596
|
-
outro,
|
|
1597
|
-
outroMeta,
|
|
1598
|
-
watchChange,
|
|
1599
|
-
watchChangeMeta,
|
|
1600
|
-
closeWatcher,
|
|
1601
|
-
closeWatcherMeta,
|
|
1602
|
-
hookUsage
|
|
1603
|
-
});
|
|
1191
|
+
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
1192
|
+
function bindingifyPluginHookMeta(options) {
|
|
1193
|
+
return { order: bindingPluginOrder(options.order) };
|
|
1604
1194
|
}
|
|
1605
|
-
function
|
|
1606
|
-
|
|
1607
|
-
"
|
|
1608
|
-
"
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
"moduleParsed",
|
|
1613
|
-
"load",
|
|
1614
|
-
"renderChunk",
|
|
1615
|
-
"augmentChunkHash",
|
|
1616
|
-
"renderStart",
|
|
1617
|
-
"renderError",
|
|
1618
|
-
"generateBundle",
|
|
1619
|
-
"writeBundle",
|
|
1620
|
-
"closeBundle",
|
|
1621
|
-
"banner",
|
|
1622
|
-
"footer",
|
|
1623
|
-
"intro",
|
|
1624
|
-
"outro",
|
|
1625
|
-
"watchChange",
|
|
1626
|
-
"closeWatcher"
|
|
1627
|
-
]) {
|
|
1628
|
-
const handler = plugin[hookName];
|
|
1629
|
-
if (handler) plugin[hookName] = async (...args) => {
|
|
1630
|
-
try {
|
|
1631
|
-
return await handler(...args);
|
|
1632
|
-
} catch (e) {
|
|
1633
|
-
return error(logPluginError(e, plugin.name, {
|
|
1634
|
-
hook: hookName,
|
|
1635
|
-
id: hookName === "transform" ? args[2] : void 0
|
|
1636
|
-
}));
|
|
1637
|
-
}
|
|
1638
|
-
};
|
|
1195
|
+
function bindingPluginOrder(order) {
|
|
1196
|
+
switch (order) {
|
|
1197
|
+
case "post": return BindingPluginOrder.Post;
|
|
1198
|
+
case "pre": return BindingPluginOrder.Pre;
|
|
1199
|
+
case null:
|
|
1200
|
+
case void 0: return;
|
|
1201
|
+
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
1639
1202
|
}
|
|
1640
|
-
return plugin;
|
|
1641
1203
|
}
|
|
1642
1204
|
//#endregion
|
|
1643
|
-
//#region src/
|
|
1644
|
-
|
|
1205
|
+
//#region src/plugin/fs.ts
|
|
1206
|
+
const fsModule = {
|
|
1207
|
+
appendFile: fsp.appendFile,
|
|
1208
|
+
copyFile: fsp.copyFile,
|
|
1209
|
+
mkdir: fsp.mkdir,
|
|
1210
|
+
mkdtemp: fsp.mkdtemp,
|
|
1211
|
+
readdir: fsp.readdir,
|
|
1212
|
+
readFile: fsp.readFile,
|
|
1213
|
+
realpath: fsp.realpath,
|
|
1214
|
+
rename: fsp.rename,
|
|
1215
|
+
rmdir: fsp.rmdir,
|
|
1216
|
+
stat: fsp.stat,
|
|
1217
|
+
lstat: fsp.lstat,
|
|
1218
|
+
unlink: fsp.unlink,
|
|
1219
|
+
writeFile: fsp.writeFile
|
|
1220
|
+
};
|
|
1221
|
+
//#endregion
|
|
1222
|
+
//#region src/plugin/plugin-context.ts
|
|
1223
|
+
var PluginContextImpl = class extends MinimalPluginContextImpl {
|
|
1224
|
+
outputOptions;
|
|
1225
|
+
context;
|
|
1226
|
+
data;
|
|
1645
1227
|
onLog;
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1228
|
+
currentLoadingModule;
|
|
1229
|
+
fs = fsModule;
|
|
1230
|
+
getModuleInfo;
|
|
1231
|
+
constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
|
|
1232
|
+
super(onLog, logLevel, plugin.name, watchMode);
|
|
1233
|
+
this.outputOptions = outputOptions;
|
|
1234
|
+
this.context = context;
|
|
1235
|
+
this.data = data;
|
|
1650
1236
|
this.onLog = onLog;
|
|
1651
|
-
this.
|
|
1652
|
-
this.
|
|
1237
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
1238
|
+
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
1653
1239
|
}
|
|
1654
|
-
|
|
1655
|
-
|
|
1240
|
+
async load(options) {
|
|
1241
|
+
const id = options.id;
|
|
1242
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
1243
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
1244
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
1245
|
+
const rawOptions = {
|
|
1246
|
+
meta: options.meta || {},
|
|
1247
|
+
moduleSideEffects: options.moduleSideEffects || null,
|
|
1248
|
+
invalidate: false
|
|
1249
|
+
};
|
|
1250
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
1251
|
+
let loadPromise = this.data.loadModulePromiseMap.get(id);
|
|
1252
|
+
if (!loadPromise) {
|
|
1253
|
+
loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
|
|
1254
|
+
this.data.loadModulePromiseMap.delete(id);
|
|
1255
|
+
});
|
|
1256
|
+
this.data.loadModulePromiseMap.set(id, loadPromise);
|
|
1257
|
+
}
|
|
1258
|
+
await loadPromise;
|
|
1259
|
+
return this.data.getModuleInfo(id, this.context);
|
|
1656
1260
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1261
|
+
async resolve(source, importer, options) {
|
|
1262
|
+
let receipt = void 0;
|
|
1263
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
1264
|
+
const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
|
|
1265
|
+
if (key.startsWith("vite:")) (acc ??= {})[key] = value;
|
|
1266
|
+
return acc;
|
|
1267
|
+
}, void 0);
|
|
1268
|
+
const res = await this.context.resolve(source, importer, {
|
|
1269
|
+
importKind: options?.kind,
|
|
1270
|
+
custom: receipt,
|
|
1271
|
+
isEntry: options?.isEntry,
|
|
1272
|
+
skipSelf: options?.skipSelf,
|
|
1273
|
+
vitePluginCustom
|
|
1274
|
+
});
|
|
1275
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
1276
|
+
if (res == null) return null;
|
|
1277
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
1278
|
+
return {
|
|
1279
|
+
...res,
|
|
1280
|
+
external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
|
|
1281
|
+
...info,
|
|
1282
|
+
moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
|
|
1283
|
+
packageJsonPath: res.packageJsonPath
|
|
1284
|
+
};
|
|
1659
1285
|
}
|
|
1660
|
-
|
|
1661
|
-
return this.
|
|
1286
|
+
emitFile = (file) => {
|
|
1287
|
+
if (file.type === "prebuilt-chunk") return this.context.emitPrebuiltChunk({
|
|
1288
|
+
fileName: file.fileName,
|
|
1289
|
+
name: file.name,
|
|
1290
|
+
code: file.code,
|
|
1291
|
+
exports: file.exports,
|
|
1292
|
+
map: bindingifySourcemap(file.map),
|
|
1293
|
+
sourcemapFileName: file.sourcemapFileName,
|
|
1294
|
+
facadeModuleId: file.facadeModuleId,
|
|
1295
|
+
isEntry: file.isEntry,
|
|
1296
|
+
isDynamicEntry: file.isDynamicEntry
|
|
1297
|
+
});
|
|
1298
|
+
if (file.type === "chunk") return this.context.emitChunk({
|
|
1299
|
+
preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
|
|
1300
|
+
...file
|
|
1301
|
+
});
|
|
1302
|
+
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
1303
|
+
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
1304
|
+
return this.context.emitFile({
|
|
1305
|
+
...file,
|
|
1306
|
+
originalFileName: file.originalFileName || void 0,
|
|
1307
|
+
source: bindingAssetSource(file.source)
|
|
1308
|
+
}, filename, fnSanitizedFileName);
|
|
1309
|
+
};
|
|
1310
|
+
getAssetFileNames(file) {
|
|
1311
|
+
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
1312
|
+
type: "asset",
|
|
1313
|
+
name: file.name,
|
|
1314
|
+
names: file.name ? [file.name] : [],
|
|
1315
|
+
originalFileName: file.originalFileName,
|
|
1316
|
+
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
1317
|
+
source: file.source
|
|
1318
|
+
});
|
|
1662
1319
|
}
|
|
1663
|
-
|
|
1664
|
-
return this.
|
|
1320
|
+
getFileName(referenceId) {
|
|
1321
|
+
return this.context.getFileName(referenceId);
|
|
1665
1322
|
}
|
|
1666
|
-
|
|
1667
|
-
return this.
|
|
1323
|
+
getModuleIds() {
|
|
1324
|
+
return this.data.getModuleIds(this.context);
|
|
1668
1325
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1326
|
+
addWatchFile(id) {
|
|
1327
|
+
this.context.addWatchFile(id);
|
|
1328
|
+
}
|
|
1329
|
+
parse(input, options) {
|
|
1330
|
+
return parseAst(input, options);
|
|
1671
1331
|
}
|
|
1672
1332
|
};
|
|
1673
|
-
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
|
|
1674
|
-
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
|
|
1675
|
-
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
|
|
1676
|
-
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
|
|
1677
|
-
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
|
|
1678
1333
|
//#endregion
|
|
1679
|
-
//#region src/
|
|
1680
|
-
var
|
|
1334
|
+
//#region src/plugin/load-plugin-context.ts
|
|
1335
|
+
var LoadPluginContextImpl = class extends PluginContextImpl {
|
|
1681
1336
|
inner;
|
|
1682
|
-
outputOptions
|
|
1683
|
-
|
|
1684
|
-
constructor(inner, outputOptions, normalizedOutputPlugins) {
|
|
1685
|
-
super();
|
|
1337
|
+
constructor(outputOptions, context, plugin, data, inner, moduleId, onLog, logLevelOption, watchMode) {
|
|
1338
|
+
super(outputOptions, context, plugin, data, onLog, logLevelOption, watchMode, moduleId);
|
|
1686
1339
|
this.inner = inner;
|
|
1687
|
-
this.outputOptions = outputOptions;
|
|
1688
|
-
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
1689
1340
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1341
|
+
addWatchFile(id) {
|
|
1342
|
+
this.inner.addWatchFile(id);
|
|
1692
1343
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1344
|
+
};
|
|
1345
|
+
//#endregion
|
|
1346
|
+
//#region src/plugin/transform-plugin-context.ts
|
|
1347
|
+
var TransformPluginContextImpl = class extends PluginContextImpl {
|
|
1348
|
+
inner;
|
|
1349
|
+
moduleId;
|
|
1350
|
+
moduleSource;
|
|
1351
|
+
constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
|
|
1352
|
+
super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
|
|
1353
|
+
this.inner = inner;
|
|
1354
|
+
this.moduleId = moduleId;
|
|
1355
|
+
this.moduleSource = moduleSource;
|
|
1356
|
+
const getLogHandler = (handler) => (log, pos) => {
|
|
1357
|
+
log = normalizeLog(log);
|
|
1358
|
+
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
1359
|
+
log.id = moduleId;
|
|
1360
|
+
log.hook = "transform";
|
|
1361
|
+
handler(log);
|
|
1362
|
+
};
|
|
1363
|
+
this.debug = getLogHandler(this.debug);
|
|
1364
|
+
this.warn = getLogHandler(this.warn);
|
|
1365
|
+
this.info = getLogHandler(this.info);
|
|
1695
1366
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
get format() {
|
|
1703
|
-
return this.inner.format;
|
|
1704
|
-
}
|
|
1705
|
-
get exports() {
|
|
1706
|
-
return this.inner.exports;
|
|
1707
|
-
}
|
|
1708
|
-
get sourcemap() {
|
|
1709
|
-
return this.inner.sourcemap;
|
|
1710
|
-
}
|
|
1711
|
-
get sourcemapBaseUrl() {
|
|
1712
|
-
return this.inner.sourcemapBaseUrl ?? void 0;
|
|
1713
|
-
}
|
|
1714
|
-
get shimMissingExports() {
|
|
1715
|
-
return this.inner.shimMissingExports;
|
|
1716
|
-
}
|
|
1717
|
-
get name() {
|
|
1718
|
-
return this.inner.name ?? void 0;
|
|
1719
|
-
}
|
|
1720
|
-
get file() {
|
|
1721
|
-
return this.inner.file ?? void 0;
|
|
1722
|
-
}
|
|
1723
|
-
get codeSplitting() {
|
|
1724
|
-
return this.inner.codeSplitting;
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* @deprecated Use `codeSplitting` instead.
|
|
1728
|
-
*/
|
|
1729
|
-
get inlineDynamicImports() {
|
|
1730
|
-
return !this.inner.codeSplitting;
|
|
1731
|
-
}
|
|
1732
|
-
get dynamicImportInCjs() {
|
|
1733
|
-
return this.inner.dynamicImportInCjs;
|
|
1734
|
-
}
|
|
1735
|
-
get externalLiveBindings() {
|
|
1736
|
-
return this.inner.externalLiveBindings;
|
|
1737
|
-
}
|
|
1738
|
-
get banner() {
|
|
1739
|
-
return normalizeAddon(this.outputOptions.banner);
|
|
1740
|
-
}
|
|
1741
|
-
get footer() {
|
|
1742
|
-
return normalizeAddon(this.outputOptions.footer);
|
|
1743
|
-
}
|
|
1744
|
-
get postBanner() {
|
|
1745
|
-
return normalizeAddon(this.outputOptions.postBanner);
|
|
1746
|
-
}
|
|
1747
|
-
get postFooter() {
|
|
1748
|
-
return normalizeAddon(this.outputOptions.postFooter);
|
|
1749
|
-
}
|
|
1750
|
-
get intro() {
|
|
1751
|
-
return normalizeAddon(this.outputOptions.intro);
|
|
1752
|
-
}
|
|
1753
|
-
get outro() {
|
|
1754
|
-
return normalizeAddon(this.outputOptions.outro);
|
|
1755
|
-
}
|
|
1756
|
-
get esModule() {
|
|
1757
|
-
return this.inner.esModule;
|
|
1758
|
-
}
|
|
1759
|
-
get extend() {
|
|
1760
|
-
return this.inner.extend;
|
|
1761
|
-
}
|
|
1762
|
-
get globals() {
|
|
1763
|
-
return this.inner.globals || this.outputOptions.globals;
|
|
1764
|
-
}
|
|
1765
|
-
get paths() {
|
|
1766
|
-
return this.outputOptions.paths;
|
|
1767
|
-
}
|
|
1768
|
-
get hashCharacters() {
|
|
1769
|
-
return this.inner.hashCharacters;
|
|
1770
|
-
}
|
|
1771
|
-
get sourcemapDebugIds() {
|
|
1772
|
-
return this.inner.sourcemapDebugIds;
|
|
1773
|
-
}
|
|
1774
|
-
get sourcemapExcludeSources() {
|
|
1775
|
-
return this.inner.sourcemapExcludeSources;
|
|
1776
|
-
}
|
|
1777
|
-
get sourcemapIgnoreList() {
|
|
1778
|
-
return this.outputOptions.sourcemapIgnoreList;
|
|
1779
|
-
}
|
|
1780
|
-
get sourcemapPathTransform() {
|
|
1781
|
-
return this.outputOptions.sourcemapPathTransform;
|
|
1782
|
-
}
|
|
1783
|
-
get minify() {
|
|
1784
|
-
let ret = this.inner.minify;
|
|
1785
|
-
if (typeof ret === "object" && ret !== null) {
|
|
1786
|
-
delete ret["codegen"];
|
|
1787
|
-
delete ret["module"];
|
|
1788
|
-
delete ret["sourcemap"];
|
|
1789
|
-
}
|
|
1790
|
-
return ret;
|
|
1791
|
-
}
|
|
1792
|
-
get legalComments() {
|
|
1793
|
-
return this.inner.legalComments;
|
|
1794
|
-
}
|
|
1795
|
-
get comments() {
|
|
1796
|
-
const c = this.inner.comments;
|
|
1797
|
-
return {
|
|
1798
|
-
legal: c.legal ?? true,
|
|
1799
|
-
annotation: c.annotation ?? true,
|
|
1800
|
-
jsdoc: c.jsdoc ?? true
|
|
1801
|
-
};
|
|
1802
|
-
}
|
|
1803
|
-
get polyfillRequire() {
|
|
1804
|
-
return this.inner.polyfillRequire;
|
|
1805
|
-
}
|
|
1806
|
-
get plugins() {
|
|
1807
|
-
return this.normalizedOutputPlugins;
|
|
1808
|
-
}
|
|
1809
|
-
get preserveModules() {
|
|
1810
|
-
return this.inner.preserveModules;
|
|
1811
|
-
}
|
|
1812
|
-
get preserveModulesRoot() {
|
|
1813
|
-
return this.inner.preserveModulesRoot;
|
|
1367
|
+
error(e, pos) {
|
|
1368
|
+
if (typeof e === "string") e = { message: e };
|
|
1369
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1370
|
+
e.id = this.moduleId;
|
|
1371
|
+
e.hook = "transform";
|
|
1372
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1814
1373
|
}
|
|
1815
|
-
|
|
1816
|
-
return this.inner.
|
|
1374
|
+
getCombinedSourcemap() {
|
|
1375
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1817
1376
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1377
|
+
addWatchFile(id) {
|
|
1378
|
+
this.inner.addWatchFile(id);
|
|
1820
1379
|
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1380
|
+
sendMagicString(s) {
|
|
1381
|
+
this.inner.sendMagicString(s);
|
|
1823
1382
|
}
|
|
1824
1383
|
};
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1384
|
+
//#endregion
|
|
1385
|
+
//#region src/plugin/bindingify-build-hooks.ts
|
|
1386
|
+
function createPluginContext(args, ctx) {
|
|
1387
|
+
return new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1388
|
+
}
|
|
1389
|
+
function bindingifyBuildStart(args) {
|
|
1390
|
+
const hook = args.plugin.buildStart;
|
|
1391
|
+
if (!hook) return {};
|
|
1392
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1393
|
+
return {
|
|
1394
|
+
plugin: async (ctx, opts) => {
|
|
1395
|
+
await handler.call(createPluginContext(args, ctx), args.pluginContextData.getInputOptions(opts));
|
|
1396
|
+
},
|
|
1397
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
function bindingifyBuildEnd(args) {
|
|
1401
|
+
const hook = args.plugin.buildEnd;
|
|
1402
|
+
if (!hook) return {};
|
|
1403
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1404
|
+
return {
|
|
1405
|
+
plugin: async (ctx, err) => {
|
|
1406
|
+
await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1407
|
+
},
|
|
1408
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
function bindingifyResolveId(args) {
|
|
1412
|
+
const hook = args.plugin.resolveId;
|
|
1413
|
+
if (!hook) return {};
|
|
1414
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1415
|
+
return {
|
|
1416
|
+
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
1417
|
+
const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
|
|
1418
|
+
const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0, {
|
|
1419
|
+
...extraOptions,
|
|
1420
|
+
custom: contextResolveOptions?.custom
|
|
1421
|
+
});
|
|
1422
|
+
if (ret == null) return;
|
|
1423
|
+
if (ret === false) return {
|
|
1424
|
+
id: specifier,
|
|
1425
|
+
external: true,
|
|
1426
|
+
normalizeExternalId: true
|
|
1427
|
+
};
|
|
1428
|
+
if (typeof ret === "string") return {
|
|
1429
|
+
id: ret,
|
|
1430
|
+
normalizeExternalId: false
|
|
1431
|
+
};
|
|
1432
|
+
let exist = args.pluginContextData.updateModuleOption(ret.id, {
|
|
1433
|
+
meta: ret.meta || {},
|
|
1434
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1435
|
+
invalidate: false
|
|
1436
|
+
});
|
|
1437
|
+
return {
|
|
1438
|
+
id: ret.id,
|
|
1439
|
+
external: ret.external,
|
|
1440
|
+
normalizeExternalId: false,
|
|
1441
|
+
moduleSideEffects: exist.moduleSideEffects ?? void 0,
|
|
1442
|
+
packageJsonPath: ret.packageJsonPath
|
|
1443
|
+
};
|
|
1444
|
+
},
|
|
1445
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1446
|
+
filter: bindingifyResolveIdFilter(options.filter)
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
function bindingifyResolveDynamicImport(args) {
|
|
1450
|
+
const hook = args.plugin.resolveDynamicImport;
|
|
1451
|
+
if (!hook) return {};
|
|
1452
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1453
|
+
return {
|
|
1454
|
+
plugin: async (ctx, specifier, importer) => {
|
|
1455
|
+
const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0);
|
|
1456
|
+
if (ret == null) return;
|
|
1457
|
+
if (ret === false) return {
|
|
1458
|
+
id: specifier,
|
|
1459
|
+
external: true
|
|
1460
|
+
};
|
|
1461
|
+
if (typeof ret === "string") return { id: ret };
|
|
1462
|
+
const result = {
|
|
1463
|
+
id: ret.id,
|
|
1464
|
+
external: ret.external,
|
|
1465
|
+
packageJsonPath: ret.packageJsonPath
|
|
1466
|
+
};
|
|
1467
|
+
if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
|
|
1468
|
+
args.pluginContextData.updateModuleOption(ret.id, {
|
|
1469
|
+
meta: ret.meta || {},
|
|
1470
|
+
moduleSideEffects: ret.moduleSideEffects || null,
|
|
1471
|
+
invalidate: false
|
|
1472
|
+
});
|
|
1473
|
+
return result;
|
|
1474
|
+
},
|
|
1475
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
function bindingifyTransform(args) {
|
|
1479
|
+
const hook = args.plugin.transform;
|
|
1480
|
+
if (!hook) return {};
|
|
1481
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1482
|
+
return {
|
|
1483
|
+
plugin: async (ctx, code, id, meta) => {
|
|
1484
|
+
let magicStringInstance, astInstance;
|
|
1485
|
+
Object.defineProperties(meta, {
|
|
1486
|
+
magicString: { get() {
|
|
1487
|
+
if (magicStringInstance) return magicStringInstance;
|
|
1488
|
+
magicStringInstance = new RolldownMagicString(code);
|
|
1489
|
+
return magicStringInstance;
|
|
1490
|
+
} },
|
|
1491
|
+
ast: { get() {
|
|
1492
|
+
if (astInstance) return astInstance;
|
|
1493
|
+
let lang = "js";
|
|
1494
|
+
switch (meta.moduleType) {
|
|
1495
|
+
case "js":
|
|
1496
|
+
case "jsx":
|
|
1497
|
+
case "ts":
|
|
1498
|
+
case "tsx":
|
|
1499
|
+
lang = meta.moduleType;
|
|
1500
|
+
break;
|
|
1501
|
+
default: break;
|
|
1502
|
+
}
|
|
1503
|
+
astInstance = parseAst(code, {
|
|
1504
|
+
astType: meta.moduleType.includes("ts") ? "ts" : "js",
|
|
1505
|
+
lang
|
|
1506
|
+
});
|
|
1507
|
+
return astInstance;
|
|
1508
|
+
} }
|
|
1509
|
+
});
|
|
1510
|
+
const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
|
|
1511
|
+
const ret = await handler.call(transformCtx, code, id, meta);
|
|
1512
|
+
if (ret == null) return;
|
|
1513
|
+
if (typeof ret === "string") return { code: ret };
|
|
1514
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1515
|
+
meta: ret.meta ?? {},
|
|
1516
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1517
|
+
invalidate: false
|
|
1518
|
+
});
|
|
1519
|
+
let normalizedCode = void 0;
|
|
1520
|
+
let map = ret.map;
|
|
1521
|
+
let mapHandledByNativeChannel = false;
|
|
1522
|
+
if (typeof ret.code === "string") normalizedCode = ret.code;
|
|
1523
|
+
else if (ret.code instanceof RolldownMagicString) {
|
|
1524
|
+
let magicString = ret.code;
|
|
1525
|
+
normalizedCode = magicString.toString();
|
|
1526
|
+
let fallbackSourcemap = ctx.sendMagicString(magicString);
|
|
1527
|
+
if (fallbackSourcemap != void 0) map = fallbackSourcemap;
|
|
1528
|
+
else mapHandledByNativeChannel = true;
|
|
1529
|
+
}
|
|
1530
|
+
return {
|
|
1531
|
+
code: normalizedCode,
|
|
1532
|
+
map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)) ?? (mapHandledByNativeChannel || ret.map === null ? null : void 0),
|
|
1533
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
|
|
1534
|
+
moduleType: ret.moduleType
|
|
1535
|
+
};
|
|
1536
|
+
},
|
|
1537
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1538
|
+
filter: bindingifyTransformFilter(options.filter)
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
function bindingifyLoad(args) {
|
|
1542
|
+
const hook = args.plugin.load;
|
|
1543
|
+
if (!hook) return {};
|
|
1544
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1545
|
+
return {
|
|
1546
|
+
plugin: async (ctx, id) => {
|
|
1547
|
+
const ret = await handler.call(new LoadPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, args.onLog, args.logLevel, args.watchMode), id);
|
|
1548
|
+
if (ret == null) return;
|
|
1549
|
+
if (typeof ret === "string") return { code: ret };
|
|
1550
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1551
|
+
meta: ret.meta || {},
|
|
1552
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1553
|
+
invalidate: false
|
|
1554
|
+
});
|
|
1555
|
+
let map = preProcessSourceMap(ret, id);
|
|
1556
|
+
return {
|
|
1557
|
+
code: ret.code,
|
|
1558
|
+
map: bindingifySourcemap(map),
|
|
1559
|
+
moduleType: ret.moduleType,
|
|
1560
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
|
|
1561
|
+
};
|
|
1562
|
+
},
|
|
1563
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1564
|
+
filter: bindingifyLoadFilter(options.filter)
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
function preProcessSourceMap(ret, id) {
|
|
1568
|
+
if (!ret.map) return;
|
|
1569
|
+
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
1570
|
+
if (!isEmptySourcemapFiled(map.sources)) {
|
|
1571
|
+
const directory = path.dirname(id) || ".";
|
|
1572
|
+
const sourceRoot = map.sourceRoot || ".";
|
|
1573
|
+
map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
|
|
1574
|
+
}
|
|
1575
|
+
return map;
|
|
1576
|
+
}
|
|
1577
|
+
function bindingifyModuleParsed(args) {
|
|
1578
|
+
const hook = args.plugin.moduleParsed;
|
|
1579
|
+
if (!hook) return {};
|
|
1580
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1581
|
+
return {
|
|
1582
|
+
plugin: async (ctx, moduleInfo) => {
|
|
1583
|
+
await handler.call(createPluginContext(args, ctx), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
1584
|
+
},
|
|
1585
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
//#endregion
|
|
1589
|
+
//#region src/plugin/bindingify-output-hooks.ts
|
|
1590
|
+
function bindingifyRenderStart(args) {
|
|
1591
|
+
const hook = args.plugin.renderStart;
|
|
1592
|
+
if (!hook) return {};
|
|
1593
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1594
|
+
return {
|
|
1595
|
+
plugin: async (ctx, opts) => {
|
|
1596
|
+
handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
|
|
1597
|
+
},
|
|
1598
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
function bindingifyRenderChunk(args) {
|
|
1602
|
+
const hook = args.plugin.renderChunk;
|
|
1603
|
+
if (!hook) return {};
|
|
1604
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1605
|
+
return {
|
|
1606
|
+
plugin: async (ctx, code, chunk, opts, meta) => {
|
|
1607
|
+
if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
|
|
1608
|
+
const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
|
|
1609
|
+
let magicStringInstance;
|
|
1610
|
+
if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
|
|
1611
|
+
get() {
|
|
1612
|
+
if (magicStringInstance) return magicStringInstance;
|
|
1613
|
+
magicStringInstance = new RolldownMagicString(code);
|
|
1614
|
+
return magicStringInstance;
|
|
1615
|
+
},
|
|
1616
|
+
configurable: true
|
|
1617
|
+
});
|
|
1618
|
+
const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
|
|
1619
|
+
if (ret == null) return;
|
|
1620
|
+
if (ret instanceof RolldownMagicString) {
|
|
1621
|
+
const normalizedCode = ret.toString();
|
|
1622
|
+
const generatedMap = ret.generateMap();
|
|
1623
|
+
return {
|
|
1624
|
+
code: normalizedCode,
|
|
1625
|
+
map: bindingifySourcemap({
|
|
1626
|
+
file: generatedMap.file,
|
|
1627
|
+
mappings: generatedMap.mappings,
|
|
1628
|
+
names: generatedMap.names,
|
|
1629
|
+
sources: generatedMap.sources,
|
|
1630
|
+
sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
|
|
1631
|
+
})
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
if (typeof ret === "string") return { code: ret };
|
|
1635
|
+
if (ret.code instanceof RolldownMagicString) {
|
|
1636
|
+
const magicString = ret.code;
|
|
1637
|
+
const normalizedCode = magicString.toString();
|
|
1638
|
+
if (ret.map === null) return {
|
|
1639
|
+
code: normalizedCode,
|
|
1640
|
+
map: null
|
|
1641
|
+
};
|
|
1642
|
+
if (ret.map === void 0) {
|
|
1643
|
+
const generatedMap = magicString.generateMap();
|
|
1644
|
+
return {
|
|
1645
|
+
code: normalizedCode,
|
|
1646
|
+
map: bindingifySourcemap({
|
|
1647
|
+
file: generatedMap.file,
|
|
1648
|
+
mappings: generatedMap.mappings,
|
|
1649
|
+
names: generatedMap.names,
|
|
1650
|
+
sources: generatedMap.sources,
|
|
1651
|
+
sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
|
|
1652
|
+
})
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
return {
|
|
1656
|
+
code: normalizedCode,
|
|
1657
|
+
map: bindingifySourcemap(ret.map)
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
if (ret.map === null) return {
|
|
1661
|
+
code: ret.code,
|
|
1662
|
+
map: null
|
|
1663
|
+
};
|
|
1664
|
+
return {
|
|
1665
|
+
code: ret.code,
|
|
1666
|
+
map: bindingifySourcemap(ret.map)
|
|
1667
|
+
};
|
|
1668
|
+
},
|
|
1669
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1670
|
+
filter: bindingifyRenderChunkFilter(options.filter)
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
function bindingifyAugmentChunkHash(args) {
|
|
1674
|
+
const hook = args.plugin.augmentChunkHash;
|
|
1675
|
+
if (!hook) return {};
|
|
1676
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1677
|
+
return {
|
|
1678
|
+
plugin: async (ctx, chunk) => {
|
|
1679
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1680
|
+
},
|
|
1681
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
function bindingifyRenderError(args) {
|
|
1685
|
+
const hook = args.plugin.renderError;
|
|
1686
|
+
if (!hook) return {};
|
|
1687
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1688
|
+
return {
|
|
1689
|
+
plugin: async (ctx, err) => {
|
|
1690
|
+
handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
|
|
1691
|
+
},
|
|
1692
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
function bindingifyGenerateBundle(args) {
|
|
1696
|
+
const hook = args.plugin.generateBundle;
|
|
1697
|
+
if (!hook) return {};
|
|
1698
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1699
|
+
return {
|
|
1700
|
+
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
1701
|
+
const changed = {
|
|
1702
|
+
updated: /* @__PURE__ */ new Set(),
|
|
1703
|
+
deleted: /* @__PURE__ */ new Set()
|
|
1704
|
+
};
|
|
1705
|
+
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1706
|
+
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1707
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
1708
|
+
return collectChangedBundle(changed, output);
|
|
1709
|
+
},
|
|
1710
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
function bindingifyWriteBundle(args) {
|
|
1714
|
+
const hook = args.plugin.writeBundle;
|
|
1715
|
+
if (!hook) return {};
|
|
1716
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1717
|
+
return {
|
|
1718
|
+
plugin: async (ctx, bundle, opts) => {
|
|
1719
|
+
const changed = {
|
|
1720
|
+
updated: /* @__PURE__ */ new Set(),
|
|
1721
|
+
deleted: /* @__PURE__ */ new Set()
|
|
1722
|
+
};
|
|
1723
|
+
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1724
|
+
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1725
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
|
|
1726
|
+
return collectChangedBundle(changed, output);
|
|
1727
|
+
},
|
|
1728
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
function bindingifyCloseBundle(args) {
|
|
1732
|
+
const hook = args.plugin.closeBundle;
|
|
1733
|
+
if (!hook) return {};
|
|
1734
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1735
|
+
return {
|
|
1736
|
+
plugin: async (ctx, err) => {
|
|
1737
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1738
|
+
},
|
|
1739
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
function bindingifyBanner(args) {
|
|
1743
|
+
const hook = args.plugin.banner;
|
|
1744
|
+
if (!hook) return {};
|
|
1745
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1746
|
+
return {
|
|
1747
|
+
plugin: async (ctx, chunk) => {
|
|
1748
|
+
if (typeof handler === "string") return handler;
|
|
1749
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1750
|
+
},
|
|
1751
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
function bindingifyFooter(args) {
|
|
1755
|
+
const hook = args.plugin.footer;
|
|
1756
|
+
if (!hook) return {};
|
|
1757
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1758
|
+
return {
|
|
1759
|
+
plugin: async (ctx, chunk) => {
|
|
1760
|
+
if (typeof handler === "string") return handler;
|
|
1761
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1762
|
+
},
|
|
1763
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
function bindingifyIntro(args) {
|
|
1767
|
+
const hook = args.plugin.intro;
|
|
1768
|
+
if (!hook) return {};
|
|
1769
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1770
|
+
return {
|
|
1771
|
+
plugin: async (ctx, chunk) => {
|
|
1772
|
+
if (typeof handler === "string") return handler;
|
|
1773
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1774
|
+
},
|
|
1775
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
function bindingifyOutro(args) {
|
|
1779
|
+
const hook = args.plugin.outro;
|
|
1780
|
+
if (!hook) return {};
|
|
1781
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1782
|
+
return {
|
|
1783
|
+
plugin: async (ctx, chunk) => {
|
|
1784
|
+
if (typeof handler === "string") return handler;
|
|
1785
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1786
|
+
},
|
|
1787
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
//#endregion
|
|
1791
|
+
//#region src/plugin/bindingify-watch-hooks.ts
|
|
1792
|
+
function bindingifyWatchChange(args) {
|
|
1793
|
+
const hook = args.plugin.watchChange;
|
|
1794
|
+
if (!hook) return {};
|
|
1795
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1796
|
+
return {
|
|
1797
|
+
plugin: async (ctx, id, event) => {
|
|
1798
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
|
|
1799
|
+
},
|
|
1800
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
function bindingifyCloseWatcher(args) {
|
|
1804
|
+
const hook = args.plugin.closeWatcher;
|
|
1805
|
+
if (!hook) return {};
|
|
1806
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1807
|
+
return {
|
|
1808
|
+
plugin: async (ctx) => {
|
|
1809
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
|
|
1810
|
+
},
|
|
1811
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1812
|
+
};
|
|
1868
1813
|
}
|
|
1869
1814
|
//#endregion
|
|
1870
|
-
//#region src/plugin/
|
|
1871
|
-
var
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
moduleOptionMap = /* @__PURE__ */ new Map();
|
|
1877
|
-
resolveOptionsMap = /* @__PURE__ */ new Map();
|
|
1878
|
-
loadModulePromiseMap = /* @__PURE__ */ new Map();
|
|
1879
|
-
renderedChunkMeta = null;
|
|
1880
|
-
normalizedInputOptions = null;
|
|
1881
|
-
normalizedOutputOptions = null;
|
|
1882
|
-
constructor(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins) {
|
|
1883
|
-
this.onLog = onLog;
|
|
1884
|
-
this.outputOptions = outputOptions;
|
|
1885
|
-
this.normalizedInputPlugins = normalizedInputPlugins;
|
|
1886
|
-
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
1887
|
-
}
|
|
1888
|
-
updateModuleOption(id, option) {
|
|
1889
|
-
const existing = this.moduleOptionMap.get(id);
|
|
1890
|
-
if (existing) {
|
|
1891
|
-
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
1892
|
-
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
1893
|
-
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
1894
|
-
} else {
|
|
1895
|
-
this.moduleOptionMap.set(id, option);
|
|
1896
|
-
return option;
|
|
1897
|
-
}
|
|
1898
|
-
return existing;
|
|
1899
|
-
}
|
|
1900
|
-
getModuleOption(id) {
|
|
1901
|
-
const option = this.moduleOptionMap.get(id);
|
|
1902
|
-
if (!option) {
|
|
1903
|
-
const raw = {
|
|
1904
|
-
moduleSideEffects: null,
|
|
1905
|
-
meta: {}
|
|
1906
|
-
};
|
|
1907
|
-
this.moduleOptionMap.set(id, raw);
|
|
1908
|
-
return raw;
|
|
1909
|
-
}
|
|
1910
|
-
return option;
|
|
1815
|
+
//#region src/plugin/generated/hook-usage.ts
|
|
1816
|
+
var HookUsage = class {
|
|
1817
|
+
bitflag = BigInt(0);
|
|
1818
|
+
constructor() {}
|
|
1819
|
+
union(kind) {
|
|
1820
|
+
this.bitflag |= BigInt(kind);
|
|
1911
1821
|
}
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
if (bindingInfo) {
|
|
1915
|
-
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
1916
|
-
return this.proxyModuleInfo(id, info);
|
|
1917
|
-
}
|
|
1918
|
-
return null;
|
|
1822
|
+
inner() {
|
|
1823
|
+
return Number(this.bitflag);
|
|
1919
1824
|
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1825
|
+
};
|
|
1826
|
+
function extractHookUsage(plugin) {
|
|
1827
|
+
let hookUsage = new HookUsage();
|
|
1828
|
+
if (plugin.buildStart) hookUsage.union(1);
|
|
1829
|
+
if (plugin.resolveId) hookUsage.union(2);
|
|
1830
|
+
if (plugin.resolveDynamicImport) hookUsage.union(4);
|
|
1831
|
+
if (plugin.load) hookUsage.union(8);
|
|
1832
|
+
if (plugin.transform) hookUsage.union(16);
|
|
1833
|
+
if (plugin.moduleParsed) hookUsage.union(32);
|
|
1834
|
+
if (plugin.buildEnd) hookUsage.union(64);
|
|
1835
|
+
if (plugin.renderStart) hookUsage.union(128);
|
|
1836
|
+
if (plugin.renderError) hookUsage.union(256);
|
|
1837
|
+
if (plugin.renderChunk) hookUsage.union(512);
|
|
1838
|
+
if (plugin.augmentChunkHash) hookUsage.union(1024);
|
|
1839
|
+
if (plugin.generateBundle) hookUsage.union(2048);
|
|
1840
|
+
if (plugin.writeBundle) hookUsage.union(4096);
|
|
1841
|
+
if (plugin.closeBundle) hookUsage.union(8192);
|
|
1842
|
+
if (plugin.watchChange) hookUsage.union(16384);
|
|
1843
|
+
if (plugin.closeWatcher) hookUsage.union(32768);
|
|
1844
|
+
if (plugin.banner) hookUsage.union(131072);
|
|
1845
|
+
if (plugin.footer) hookUsage.union(262144);
|
|
1846
|
+
if (plugin.intro) hookUsage.union(524288);
|
|
1847
|
+
if (plugin.outro) hookUsage.union(1048576);
|
|
1848
|
+
return hookUsage;
|
|
1849
|
+
}
|
|
1850
|
+
//#endregion
|
|
1851
|
+
//#region src/plugin/bindingify-plugin.ts
|
|
1852
|
+
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
1853
|
+
const args = {
|
|
1854
|
+
plugin,
|
|
1855
|
+
options,
|
|
1856
|
+
outputOptions,
|
|
1857
|
+
pluginContextData,
|
|
1858
|
+
onLog,
|
|
1859
|
+
logLevel,
|
|
1860
|
+
watchMode,
|
|
1861
|
+
normalizedOutputPlugins
|
|
1862
|
+
};
|
|
1863
|
+
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
|
|
1864
|
+
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
|
|
1865
|
+
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
|
|
1866
|
+
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
|
|
1867
|
+
const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
|
|
1868
|
+
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
|
|
1869
|
+
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
|
|
1870
|
+
const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
|
|
1871
|
+
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
1872
|
+
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
1873
|
+
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
1874
|
+
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
1875
|
+
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
1876
|
+
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
1877
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
|
|
1878
|
+
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
|
|
1879
|
+
const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
|
|
1880
|
+
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
|
|
1881
|
+
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
1882
|
+
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
1883
|
+
let hookUsage = extractHookUsage(plugin).inner();
|
|
1884
|
+
return wrapHandlers({
|
|
1885
|
+
name: plugin.name,
|
|
1886
|
+
buildStart,
|
|
1887
|
+
buildStartMeta,
|
|
1888
|
+
resolveId,
|
|
1889
|
+
resolveIdMeta,
|
|
1890
|
+
resolveIdFilter,
|
|
1891
|
+
resolveDynamicImport,
|
|
1892
|
+
resolveDynamicImportMeta,
|
|
1893
|
+
buildEnd,
|
|
1894
|
+
buildEndMeta,
|
|
1895
|
+
transform,
|
|
1896
|
+
transformMeta,
|
|
1897
|
+
transformFilter,
|
|
1898
|
+
moduleParsed,
|
|
1899
|
+
moduleParsedMeta,
|
|
1900
|
+
load,
|
|
1901
|
+
loadMeta,
|
|
1902
|
+
loadFilter,
|
|
1903
|
+
renderChunk,
|
|
1904
|
+
renderChunkMeta,
|
|
1905
|
+
renderChunkFilter,
|
|
1906
|
+
augmentChunkHash,
|
|
1907
|
+
augmentChunkHashMeta,
|
|
1908
|
+
renderStart,
|
|
1909
|
+
renderStartMeta,
|
|
1910
|
+
renderError,
|
|
1911
|
+
renderErrorMeta,
|
|
1912
|
+
generateBundle,
|
|
1913
|
+
generateBundleMeta,
|
|
1914
|
+
writeBundle,
|
|
1915
|
+
writeBundleMeta,
|
|
1916
|
+
closeBundle,
|
|
1917
|
+
closeBundleMeta,
|
|
1918
|
+
banner,
|
|
1919
|
+
bannerMeta,
|
|
1920
|
+
footer,
|
|
1921
|
+
footerMeta,
|
|
1922
|
+
intro,
|
|
1923
|
+
introMeta,
|
|
1924
|
+
outro,
|
|
1925
|
+
outroMeta,
|
|
1926
|
+
watchChange,
|
|
1927
|
+
watchChangeMeta,
|
|
1928
|
+
closeWatcher,
|
|
1929
|
+
closeWatcherMeta,
|
|
1930
|
+
hookUsage
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
function wrapHandlers(plugin) {
|
|
1934
|
+
for (const hookName of [
|
|
1935
|
+
"buildStart",
|
|
1936
|
+
"resolveId",
|
|
1937
|
+
"resolveDynamicImport",
|
|
1938
|
+
"buildEnd",
|
|
1939
|
+
"transform",
|
|
1940
|
+
"moduleParsed",
|
|
1941
|
+
"load",
|
|
1942
|
+
"renderChunk",
|
|
1943
|
+
"augmentChunkHash",
|
|
1944
|
+
"renderStart",
|
|
1945
|
+
"renderError",
|
|
1946
|
+
"generateBundle",
|
|
1947
|
+
"writeBundle",
|
|
1948
|
+
"closeBundle",
|
|
1949
|
+
"banner",
|
|
1950
|
+
"footer",
|
|
1951
|
+
"intro",
|
|
1952
|
+
"outro",
|
|
1953
|
+
"watchChange",
|
|
1954
|
+
"closeWatcher"
|
|
1955
|
+
]) {
|
|
1956
|
+
const handler = plugin[hookName];
|
|
1957
|
+
if (handler) plugin[hookName] = async (...args) => {
|
|
1958
|
+
try {
|
|
1959
|
+
return await handler(...args);
|
|
1960
|
+
} catch (e) {
|
|
1961
|
+
return error(logPluginError(e, plugin.name, {
|
|
1962
|
+
hook: hookName,
|
|
1963
|
+
id: hookName === "transform" ? args[2] : void 0
|
|
1964
|
+
}));
|
|
1933
1965
|
}
|
|
1934
|
-
}
|
|
1935
|
-
return info;
|
|
1936
|
-
}
|
|
1937
|
-
getModuleIds(context) {
|
|
1938
|
-
return context.getModuleIds().values();
|
|
1939
|
-
}
|
|
1940
|
-
saveResolveOptions(options) {
|
|
1941
|
-
const index = this.resolveOptionsMap.size;
|
|
1942
|
-
this.resolveOptionsMap.set(index, options);
|
|
1943
|
-
return index;
|
|
1944
|
-
}
|
|
1945
|
-
getSavedResolveOptions(receipt) {
|
|
1946
|
-
return this.resolveOptionsMap.get(receipt);
|
|
1947
|
-
}
|
|
1948
|
-
removeSavedResolveOptions(receipt) {
|
|
1949
|
-
this.resolveOptionsMap.delete(receipt);
|
|
1950
|
-
}
|
|
1951
|
-
setRenderChunkMeta(meta) {
|
|
1952
|
-
this.renderedChunkMeta = meta;
|
|
1953
|
-
}
|
|
1954
|
-
getRenderChunkMeta() {
|
|
1955
|
-
return this.renderedChunkMeta;
|
|
1956
|
-
}
|
|
1957
|
-
getInputOptions(opts) {
|
|
1958
|
-
this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog, this.normalizedInputPlugins);
|
|
1959
|
-
return this.normalizedInputOptions;
|
|
1960
|
-
}
|
|
1961
|
-
getOutputOptions(opts) {
|
|
1962
|
-
this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
|
|
1963
|
-
return this.normalizedOutputOptions;
|
|
1964
|
-
}
|
|
1965
|
-
clear() {
|
|
1966
|
-
this.renderedChunkMeta = null;
|
|
1967
|
-
this.loadModulePromiseMap.clear();
|
|
1966
|
+
};
|
|
1968
1967
|
}
|
|
1969
|
-
|
|
1968
|
+
return plugin;
|
|
1969
|
+
}
|
|
1970
1970
|
//#endregion
|
|
1971
1971
|
//#region src/utils/normalize-transform-options.ts
|
|
1972
1972
|
/**
|
|
@@ -1996,8 +1996,7 @@ function normalizeTransformOptions(inputOptions) {
|
|
|
1996
1996
|
}
|
|
1997
1997
|
//#endregion
|
|
1998
1998
|
//#region src/utils/bindingify-input-options.ts
|
|
1999
|
-
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions,
|
|
2000
|
-
const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins);
|
|
1999
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
2001
2000
|
const plugins = rawPlugins.map((plugin) => {
|
|
2002
2001
|
if ("_parallel" in plugin) return;
|
|
2003
2002
|
if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
|
|
@@ -2236,4 +2235,4 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
|
|
|
2236
2235
|
};
|
|
2237
2236
|
}
|
|
2238
2237
|
//#endregion
|
|
2239
|
-
export { version as C, description as S, LOG_LEVEL_INFO as _,
|
|
2238
|
+
export { version as C, description as S, LOG_LEVEL_INFO as _, transformModuleInfo as a, RUNTIME_MODULE_ID as b, __decorate as c, PlainObjectLike as d, MinimalPluginContextImpl as f, LOG_LEVEL_ERROR as g, LOG_LEVEL_DEBUG as h, PluginContextData as i, transformAssetSource as l, normalizeLog as m, bindingifyPlugin as n, transformToRollupOutput as o, normalizeHook as p, RolldownMagicString as r, transformRenderedChunk as s, bindingifyInputOptions as t, lazyProp as u, LOG_LEVEL_WARN as v, VERSION as x, logLevelPriority as y };
|