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