@rollipop/rolldown 1.0.18 → 1.0.20

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 (32) hide show
  1. package/dist/cli.mjs +19 -8
  2. package/dist/config.d.mts +1 -1
  3. package/dist/config.mjs +2 -2
  4. package/dist/experimental-index.d.mts +14 -4
  5. package/dist/experimental-index.mjs +20 -15
  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-Cyz1BOPl.d.mts → binding-DE7ERejD.d.mts} +88 -27
  16. package/dist/shared/{binding-BkgahC-_.mjs → binding-DamCAbY6.mjs} +26 -26
  17. package/dist/shared/{bindingify-input-options-B5F7R19R.mjs → bindingify-input-options-SGSGV3Kn.mjs} +1350 -1348
  18. package/dist/shared/{constructors-BP8dSdw2.mjs → constructors-CTfc5fh7.mjs} +1 -1
  19. package/dist/shared/{constructors-C2RnsuK3.d.mts → constructors-CqnDcrIL.d.mts} +2 -2
  20. package/dist/shared/{define-config-oEABMwkg.d.mts → define-config-xmEHQczI.d.mts} +2 -7
  21. package/dist/shared/{error-DW8gB2Qq.mjs → error-BmTEI0xY.mjs} +1 -1
  22. package/dist/shared/{load-config-Bh2RCL5t.mjs → load-config-DY5kAiwf.mjs} +1 -1
  23. package/dist/shared/{normalize-string-or-regex-C3Aaex0G.mjs → normalize-string-or-regex-Ddbkskw6.mjs} +1 -1
  24. package/dist/shared/{parse-DodhQ1O5.mjs → parse-CNsctGYH.mjs} +1 -1
  25. package/dist/shared/{resolve-tsconfig-BGfz0QPf.mjs → resolve-tsconfig-B6udNjE_.mjs} +2 -2
  26. package/dist/shared/{rolldown-Yo0wlwlh.mjs → rolldown-C6DTtWMe.mjs} +1 -1
  27. package/dist/shared/{rolldown-build-CA7mRy17.mjs → rolldown-build-BCVOvLca.mjs} +20 -21
  28. package/dist/shared/{transform-BpkSLs0Y.d.mts → transform-DiNoOk6R.d.mts} +1 -1
  29. package/dist/shared/{watch-Bo2HC6b0.mjs → watch-BqeQlZnt.mjs} +4 -4
  30. package/dist/utils-index.d.mts +2 -2
  31. package/dist/utils-index.mjs +2 -2
  32. package/package.json +12 -12
@@ -1,14 +1,14 @@
1
- import { n as __toESM, t as require_binding } from "./binding-BkgahC-_.mjs";
1
+ import { n as __toESM, t as require_binding } from "./binding-DamCAbY6.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-C3Aaex0G.mjs";
3
+ import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-Ddbkskw6.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-DW8gB2Qq.mjs";
5
+ import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-BmTEI0xY.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.0.18";
11
+ var version = "1.0.20";
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.
@@ -564,1427 +565,1426 @@ 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.39.0/node_modules/remeda/dist/lazyDataLastImpl--3B10z3s.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.39.0/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.39.0/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
- }
1262
- function bindingifyTransformCacheHit(args) {
1263
- const hook = args.plugin.transformCacheHit;
1264
- if (!hook) return {};
1265
- const { handler, meta } = normalizeHook(hook);
1266
- return {
1267
- plugin: async (ctx, id) => {
1268
- await handler.call(createPluginContext(args, ctx), id);
1269
- },
1270
- meta: bindingifyPluginHookMeta(meta)
1271
- };
1272
- }
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
+ };
1273
916
  //#endregion
1274
- //#region src/plugin/bindingify-output-hooks.ts
1275
- function bindingifyRenderStart(args) {
1276
- const hook = args.plugin.renderStart;
1277
- if (!hook) return {};
1278
- const { handler, meta } = normalizeHook(hook);
1279
- return {
1280
- plugin: async (ctx, opts) => {
1281
- 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));
1282
- },
1283
- meta: bindingifyPluginHookMeta(meta)
1284
- };
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);
1285
925
  }
1286
- function bindingifyRenderChunk(args) {
1287
- const hook = args.plugin.renderChunk;
1288
- if (!hook) return {};
1289
- const { handler, meta, options } = normalizeHook(hook);
1290
- return {
1291
- plugin: async (ctx, code, chunk, opts, meta) => {
1292
- if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
1293
- const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
1294
- let magicStringInstance;
1295
- if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
1296
- get() {
1297
- if (magicStringInstance) return magicStringInstance;
1298
- magicStringInstance = new RolldownMagicString(code);
1299
- return magicStringInstance;
1300
- },
1301
- configurable: true
1302
- });
1303
- 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);
1304
- if (ret == null) return;
1305
- if (ret instanceof RolldownMagicString) {
1306
- const normalizedCode = ret.toString();
1307
- const generatedMap = ret.generateMap();
1308
- return {
1309
- code: normalizedCode,
1310
- map: bindingifySourcemap({
1311
- file: generatedMap.file,
1312
- mappings: generatedMap.mappings,
1313
- names: generatedMap.names,
1314
- sources: generatedMap.sources,
1315
- sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1316
- })
1317
- };
1318
- }
1319
- if (typeof ret === "string") return { code: ret };
1320
- if (ret.code instanceof RolldownMagicString) {
1321
- const magicString = ret.code;
1322
- const normalizedCode = magicString.toString();
1323
- if (ret.map === null) return {
1324
- code: normalizedCode,
1325
- map: null
1326
- };
1327
- if (ret.map === void 0) {
1328
- const generatedMap = magicString.generateMap();
1329
- return {
1330
- code: normalizedCode,
1331
- map: bindingifySourcemap({
1332
- file: generatedMap.file,
1333
- mappings: generatedMap.mappings,
1334
- names: generatedMap.names,
1335
- sources: generatedMap.sources,
1336
- sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1337
- })
1338
- };
1339
- }
1340
- return {
1341
- code: normalizedCode,
1342
- map: bindingifySourcemap(ret.map)
1343
- };
1344
- }
1345
- if (ret.map === null) return {
1346
- code: ret.code,
1347
- map: null
1348
- };
1349
- return {
1350
- code: ret.code,
1351
- map: bindingifySourcemap(ret.map)
1352
- };
1353
- },
1354
- meta: bindingifyPluginHookMeta(meta),
1355
- filter: bindingifyRenderChunkFilter(options.filter)
1356
- };
1357
- }
1358
- function bindingifyAugmentChunkHash(args) {
1359
- const hook = args.plugin.augmentChunkHash;
1360
- if (!hook) return {};
1361
- const { handler, meta } = normalizeHook(hook);
1362
- return {
1363
- plugin: async (ctx, chunk) => {
1364
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1365
- },
1366
- meta: bindingifyPluginHookMeta(meta)
1367
- };
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;
1368
996
  }
1369
- function bindingifyRenderError(args) {
1370
- const hook = args.plugin.renderError;
1371
- if (!hook) return {};
1372
- const { handler, meta } = normalizeHook(hook);
1373
- return {
1374
- plugin: async (ctx, err) => {
1375
- handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
1376
- },
1377
- meta: bindingifyPluginHookMeta(meta)
1378
- };
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;
1379
1003
  }
1380
- function bindingifyGenerateBundle(args) {
1381
- const hook = args.plugin.generateBundle;
1382
- if (!hook) return {};
1383
- const { handler, meta } = normalizeHook(hook);
1384
- return {
1385
- plugin: async (ctx, bundle, isWrite, opts) => {
1386
- const changed = {
1387
- updated: /* @__PURE__ */ new Set(),
1388
- deleted: /* @__PURE__ */ new Set()
1389
- };
1390
- const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1391
- const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1392
- await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
1393
- return collectChangedBundle(changed, output);
1394
- },
1395
- meta: bindingifyPluginHookMeta(meta)
1396
- };
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
+ });
1397
1012
  }
1398
- function bindingifyWriteBundle(args) {
1399
- const hook = args.plugin.writeBundle;
1400
- if (!hook) return {};
1401
- const { handler, meta } = normalizeHook(hook);
1402
- return {
1403
- plugin: async (ctx, bundle, opts) => {
1404
- const changed = {
1405
- updated: /* @__PURE__ */ new Set(),
1406
- deleted: /* @__PURE__ */ new Set()
1407
- };
1408
- const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1409
- const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1410
- await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
1411
- return collectChangedBundle(changed, output);
1412
- },
1413
- meta: bindingifyPluginHookMeta(meta)
1414
- };
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`);
1415
1020
  }
1416
- function bindingifyCloseBundle(args) {
1417
- const hook = args.plugin.closeBundle;
1418
- if (!hook) return {};
1419
- const { handler, meta } = normalizeHook(hook);
1420
- return {
1421
- plugin: async (ctx, err) => {
1422
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1423
- },
1424
- meta: bindingifyPluginHookMeta(meta)
1425
- };
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);
1426
1025
  }
1427
- function bindingifyBanner(args) {
1428
- const hook = args.plugin.banner;
1429
- if (!hook) return {};
1430
- const { handler, meta } = normalizeHook(hook);
1431
- return {
1432
- plugin: async (ctx, chunk) => {
1433
- if (typeof handler === "string") return handler;
1434
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1435
- },
1436
- meta: bindingifyPluginHookMeta(meta)
1437
- };
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;
1438
1040
  }
1439
- function bindingifyFooter(args) {
1440
- const hook = args.plugin.footer;
1441
- if (!hook) return {};
1442
- const { handler, meta } = normalizeHook(hook);
1443
- return {
1444
- plugin: async (ctx, chunk) => {
1445
- if (typeof handler === "string") return handler;
1446
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1447
- },
1448
- meta: bindingifyPluginHookMeta(meta)
1449
- };
1041
+ function generateAtomMatcher(kind, matcher) {
1042
+ return kind === "code" ? filter.code(matcher) : filter.id(matcher);
1450
1043
  }
1451
- function bindingifyIntro(args) {
1452
- const hook = args.plugin.intro;
1453
- if (!hook) return {};
1454
- const { handler, meta } = normalizeHook(hook);
1455
- return {
1456
- plugin: async (ctx, chunk) => {
1457
- if (typeof handler === "string") return handler;
1458
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1459
- },
1460
- meta: bindingifyPluginHookMeta(meta)
1461
- };
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;
1462
1066
  }
1463
- function bindingifyOutro(args) {
1464
- const hook = args.plugin.outro;
1465
- if (!hook) return {};
1466
- const { handler, meta } = normalizeHook(hook);
1467
- return {
1468
- plugin: async (ctx, chunk) => {
1469
- if (typeof handler === "string") return handler;
1470
- return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1471
- },
1472
- meta: bindingifyPluginHookMeta(meta)
1473
- };
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;
1474
1072
  }
1475
- //#endregion
1476
- //#region src/plugin/bindingify-watch-hooks.ts
1477
- function bindingifyWatchChange(args) {
1478
- const hook = args.plugin.watchChange;
1479
- if (!hook) return {};
1480
- const { handler, meta } = normalizeHook(hook);
1481
- return {
1482
- plugin: async (ctx, id, event) => {
1483
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
1484
- },
1485
- meta: bindingifyPluginHookMeta(meta)
1486
- };
1073
+ function bindingifyFilterExpr(expr) {
1074
+ let list = [];
1075
+ bindingifyFilterExprImpl(expr, list);
1076
+ return list;
1487
1077
  }
1488
- function bindingifyCloseWatcher(args) {
1489
- const hook = args.plugin.closeWatcher;
1490
- if (!hook) return {};
1491
- const { handler, meta } = normalizeHook(hook);
1492
- return {
1493
- plugin: async (ctx) => {
1494
- await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
1495
- },
1496
- meta: bindingifyPluginHookMeta(meta)
1497
- };
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
+ }
1498
1088
  }
1499
- //#endregion
1500
- //#region src/plugin/generated/hook-usage.ts
1501
- var HookUsage = class {
1502
- bitflag = BigInt(0);
1503
- constructor() {}
1504
- union(kind) {
1505
- this.bitflag |= BigInt(kind);
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.`);
1091
+ }
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}`);
1506
1161
  }
1507
- inner() {
1508
- 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) };
1509
1173
  }
1510
- };
1511
- function extractHookUsage(plugin) {
1512
- let hookUsage = new HookUsage();
1513
- if (plugin.buildStart) hookUsage.union(1);
1514
- if (plugin.resolveId) hookUsage.union(2);
1515
- if (plugin.resolveDynamicImport) hookUsage.union(4);
1516
- if (plugin.load) hookUsage.union(8);
1517
- if (plugin.transform) hookUsage.union(16);
1518
- if (plugin.moduleParsed) hookUsage.union(32);
1519
- if (plugin.buildEnd) hookUsage.union(64);
1520
- if (plugin.renderStart) hookUsage.union(128);
1521
- if (plugin.renderError) hookUsage.union(256);
1522
- if (plugin.renderChunk) hookUsage.union(512);
1523
- if (plugin.augmentChunkHash) hookUsage.union(1024);
1524
- if (plugin.generateBundle) hookUsage.union(2048);
1525
- if (plugin.writeBundle) hookUsage.union(4096);
1526
- if (plugin.closeBundle) hookUsage.union(8192);
1527
- if (plugin.watchChange) hookUsage.union(16384);
1528
- if (plugin.closeWatcher) hookUsage.union(32768);
1529
- if (plugin.banner) hookUsage.union(131072);
1530
- if (plugin.footer) hookUsage.union(262144);
1531
- if (plugin.intro) hookUsage.union(524288);
1532
- if (plugin.outro) hookUsage.union(1048576);
1533
- if (plugin.transformCacheHit) hookUsage.union(2097152);
1534
- 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;
1535
1191
  }
1536
1192
  //#endregion
1537
- //#region src/plugin/bindingify-plugin.ts
1538
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
1539
- const args = {
1540
- plugin,
1541
- options,
1542
- outputOptions,
1543
- pluginContextData,
1544
- onLog,
1545
- logLevel,
1546
- watchMode,
1547
- normalizedOutputPlugins
1548
- };
1549
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
1550
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
1551
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
1552
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
1553
- const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
1554
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
1555
- const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1556
- const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
1557
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
1558
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1559
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1560
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1561
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1562
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1563
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1564
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1565
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1566
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
1567
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
1568
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1569
- const { plugin: transformCacheHit, meta: transformCacheHitMeta } = bindingifyTransformCacheHit(args);
1570
- let hookUsage = extractHookUsage(plugin).inner();
1571
- return wrapHandlers({
1572
- name: plugin.name,
1573
- buildStart,
1574
- buildStartMeta,
1575
- resolveId,
1576
- resolveIdMeta,
1577
- resolveIdFilter,
1578
- resolveDynamicImport,
1579
- resolveDynamicImportMeta,
1580
- buildEnd,
1581
- buildEndMeta,
1582
- transform,
1583
- transformMeta,
1584
- transformFilter,
1585
- moduleParsed,
1586
- moduleParsedMeta,
1587
- load,
1588
- loadMeta,
1589
- loadFilter,
1590
- renderChunk,
1591
- renderChunkMeta,
1592
- renderChunkFilter,
1593
- augmentChunkHash,
1594
- augmentChunkHashMeta,
1595
- renderStart,
1596
- renderStartMeta,
1597
- renderError,
1598
- renderErrorMeta,
1599
- generateBundle,
1600
- generateBundleMeta,
1601
- writeBundle,
1602
- writeBundleMeta,
1603
- closeBundle,
1604
- closeBundleMeta,
1605
- banner,
1606
- bannerMeta,
1607
- footer,
1608
- footerMeta,
1609
- intro,
1610
- introMeta,
1611
- outro,
1612
- outroMeta,
1613
- watchChange,
1614
- watchChangeMeta,
1615
- closeWatcher,
1616
- closeWatcherMeta,
1617
- transformCacheHit,
1618
- transformCacheHitMeta,
1619
- hookUsage
1620
- });
1193
+ //#region src/plugin/bindingify-plugin-hook-meta.ts
1194
+ function bindingifyPluginHookMeta(options) {
1195
+ return { order: bindingPluginOrder(options.order) };
1621
1196
  }
1622
- function wrapHandlers(plugin) {
1623
- for (const hookName of [
1624
- "buildStart",
1625
- "resolveId",
1626
- "resolveDynamicImport",
1627
- "buildEnd",
1628
- "transform",
1629
- "moduleParsed",
1630
- "load",
1631
- "renderChunk",
1632
- "augmentChunkHash",
1633
- "renderStart",
1634
- "renderError",
1635
- "generateBundle",
1636
- "writeBundle",
1637
- "closeBundle",
1638
- "banner",
1639
- "footer",
1640
- "intro",
1641
- "outro",
1642
- "watchChange",
1643
- "closeWatcher",
1644
- "transformCacheHit"
1645
- ]) {
1646
- const handler = plugin[hookName];
1647
- if (handler) plugin[hookName] = async (...args) => {
1648
- try {
1649
- return await handler(...args);
1650
- } catch (e) {
1651
- return error(logPluginError(e, plugin.name, {
1652
- hook: hookName,
1653
- id: hookName === "transform" ? args[2] : hookName === "transformCacheHit" ? args[1] : void 0
1654
- }));
1655
- }
1656
- };
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}`);
1657
1204
  }
1658
- return plugin;
1659
1205
  }
1660
1206
  //#endregion
1661
- //#region src/options/normalized-input-options.ts
1662
- 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;
1663
1229
  onLog;
1664
- inputPlugins;
1665
- inner;
1666
- constructor(inner, onLog, inputPlugins) {
1667
- 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;
1668
1238
  this.onLog = onLog;
1669
- this.inputPlugins = inputPlugins;
1670
- this.inner = inner;
1239
+ this.currentLoadingModule = currentLoadingModule;
1240
+ this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
1671
1241
  }
1672
- get shimMissingExports() {
1673
- 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);
1674
1262
  }
1675
- get input() {
1676
- 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
+ };
1677
1287
  }
1678
- get cwd() {
1679
- 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
+ });
1680
1321
  }
1681
- get platform() {
1682
- return this.inner.platform;
1322
+ getFileName(referenceId) {
1323
+ return this.context.getFileName(referenceId);
1683
1324
  }
1684
- get context() {
1685
- return this.inner.context;
1325
+ getModuleIds() {
1326
+ return this.data.getModuleIds(this.context);
1686
1327
  }
1687
- get plugins() {
1688
- return this.inputPlugins;
1328
+ addWatchFile(id) {
1329
+ this.context.addWatchFile(id);
1330
+ }
1331
+ parse(input, options) {
1332
+ return parseAst(input, options);
1689
1333
  }
1690
1334
  };
1691
- __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
1692
- __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
1693
- __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
1694
- __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
1695
- __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
1696
1335
  //#endregion
1697
- //#region src/options/normalized-output-options.ts
1698
- var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
1336
+ //#region src/plugin/load-plugin-context.ts
1337
+ var LoadPluginContextImpl = class extends PluginContextImpl {
1699
1338
  inner;
1700
- outputOptions;
1701
- normalizedOutputPlugins;
1702
- constructor(inner, outputOptions, normalizedOutputPlugins) {
1703
- super();
1339
+ constructor(outputOptions, context, plugin, data, inner, moduleId, onLog, logLevelOption, watchMode) {
1340
+ super(outputOptions, context, plugin, data, onLog, logLevelOption, watchMode, moduleId);
1704
1341
  this.inner = inner;
1705
- this.outputOptions = outputOptions;
1706
- this.normalizedOutputPlugins = normalizedOutputPlugins;
1707
- }
1708
- get dir() {
1709
- return this.inner.dir ?? void 0;
1710
- }
1711
- get entryFileNames() {
1712
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
1713
- }
1714
- get chunkFileNames() {
1715
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
1716
1342
  }
1717
- get assetFileNames() {
1718
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
1343
+ addWatchFile(id) {
1344
+ this.inner.addWatchFile(id);
1719
1345
  }
1720
- get format() {
1721
- return this.inner.format;
1722
- }
1723
- get exports() {
1724
- return this.inner.exports;
1725
- }
1726
- get sourcemap() {
1727
- return this.inner.sourcemap;
1728
- }
1729
- get sourcemapBaseUrl() {
1730
- return this.inner.sourcemapBaseUrl ?? void 0;
1731
- }
1732
- get shimMissingExports() {
1733
- return this.inner.shimMissingExports;
1734
- }
1735
- get name() {
1736
- return this.inner.name ?? void 0;
1737
- }
1738
- get file() {
1739
- return this.inner.file ?? void 0;
1740
- }
1741
- get codeSplitting() {
1742
- return this.inner.codeSplitting;
1743
- }
1744
- /**
1745
- * @deprecated Use `codeSplitting` instead.
1746
- */
1747
- get inlineDynamicImports() {
1748
- return !this.inner.codeSplitting;
1749
- }
1750
- get dynamicImportInCjs() {
1751
- return this.inner.dynamicImportInCjs;
1752
- }
1753
- get externalLiveBindings() {
1754
- return this.inner.externalLiveBindings;
1755
- }
1756
- get banner() {
1757
- return normalizeAddon(this.outputOptions.banner);
1758
- }
1759
- get footer() {
1760
- return normalizeAddon(this.outputOptions.footer);
1761
- }
1762
- get postBanner() {
1763
- return normalizeAddon(this.outputOptions.postBanner);
1764
- }
1765
- get postFooter() {
1766
- return normalizeAddon(this.outputOptions.postFooter);
1767
- }
1768
- get intro() {
1769
- return normalizeAddon(this.outputOptions.intro);
1770
- }
1771
- get outro() {
1772
- return normalizeAddon(this.outputOptions.outro);
1773
- }
1774
- get esModule() {
1775
- return this.inner.esModule;
1776
- }
1777
- get extend() {
1778
- return this.inner.extend;
1779
- }
1780
- get globals() {
1781
- return this.inner.globals || this.outputOptions.globals;
1782
- }
1783
- get paths() {
1784
- return this.outputOptions.paths;
1785
- }
1786
- get hashCharacters() {
1787
- return this.inner.hashCharacters;
1788
- }
1789
- get sourcemapDebugIds() {
1790
- return this.inner.sourcemapDebugIds;
1791
- }
1792
- get sourcemapExcludeSources() {
1793
- return this.inner.sourcemapExcludeSources;
1794
- }
1795
- get sourcemapIgnoreList() {
1796
- return this.outputOptions.sourcemapIgnoreList;
1797
- }
1798
- get sourcemapPathTransform() {
1799
- return this.outputOptions.sourcemapPathTransform;
1800
- }
1801
- get minify() {
1802
- let ret = this.inner.minify;
1803
- if (typeof ret === "object" && ret !== null) {
1804
- delete ret["codegen"];
1805
- delete ret["module"];
1806
- delete ret["sourcemap"];
1807
- }
1808
- return ret;
1809
- }
1810
- get legalComments() {
1811
- return this.inner.legalComments;
1812
- }
1813
- get comments() {
1814
- const c = this.inner.comments;
1815
- return {
1816
- legal: c.legal ?? true,
1817
- annotation: c.annotation ?? true,
1818
- jsdoc: c.jsdoc ?? true
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);
1819
1364
  };
1365
+ this.debug = getLogHandler(this.debug);
1366
+ this.warn = getLogHandler(this.warn);
1367
+ this.info = getLogHandler(this.info);
1820
1368
  }
1821
- get polyfillRequire() {
1822
- return this.inner.polyfillRequire;
1823
- }
1824
- get plugins() {
1825
- return this.normalizedOutputPlugins;
1826
- }
1827
- get preserveModules() {
1828
- return this.inner.preserveModules;
1829
- }
1830
- get preserveModulesRoot() {
1831
- return this.inner.preserveModulesRoot;
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));
1832
1375
  }
1833
- get virtualDirname() {
1834
- return this.inner.virtualDirname;
1376
+ getCombinedSourcemap() {
1377
+ return JSON.parse(this.inner.getCombinedSourcemap());
1835
1378
  }
1836
- get topLevelVar() {
1837
- return this.inner.topLevelVar ?? false;
1379
+ addWatchFile(id) {
1380
+ this.inner.addWatchFile(id);
1838
1381
  }
1839
- get minifyInternalExports() {
1840
- return this.inner.minifyInternalExports ?? false;
1382
+ sendMagicString(s) {
1383
+ this.inner.sendMagicString(s);
1841
1384
  }
1842
1385
  };
1843
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
1844
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
1845
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
1846
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
1847
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
1848
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
1849
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
1850
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
1851
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
1852
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
1853
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
1854
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "codeSplitting", null);
1855
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
1856
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dynamicImportInCjs", null);
1857
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
1858
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
1859
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
1860
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postBanner", null);
1861
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postFooter", null);
1862
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
1863
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
1864
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
1865
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
1866
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
1867
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
1868
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
1869
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
1870
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapExcludeSources", null);
1871
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
1872
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
1873
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
1874
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
1875
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "comments", null);
1876
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
1877
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
1878
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
1879
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
1880
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
1881
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
1882
- __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
1883
- function normalizeAddon(value) {
1884
- if (typeof value === "function") return value;
1885
- 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
+ function bindingifyTransformCacheHit(args) {
1591
+ const hook = args.plugin.transformCacheHit;
1592
+ if (!hook) return {};
1593
+ const { handler, meta } = normalizeHook(hook);
1594
+ return {
1595
+ plugin: async (ctx, id) => {
1596
+ await handler.call(createPluginContext(args, ctx), id);
1597
+ },
1598
+ meta: bindingifyPluginHookMeta(meta)
1599
+ };
1600
+ }
1601
+ //#endregion
1602
+ //#region src/plugin/bindingify-output-hooks.ts
1603
+ function bindingifyRenderStart(args) {
1604
+ const hook = args.plugin.renderStart;
1605
+ if (!hook) return {};
1606
+ const { handler, meta } = normalizeHook(hook);
1607
+ return {
1608
+ plugin: async (ctx, opts) => {
1609
+ 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));
1610
+ },
1611
+ meta: bindingifyPluginHookMeta(meta)
1612
+ };
1613
+ }
1614
+ function bindingifyRenderChunk(args) {
1615
+ const hook = args.plugin.renderChunk;
1616
+ if (!hook) return {};
1617
+ const { handler, meta, options } = normalizeHook(hook);
1618
+ return {
1619
+ plugin: async (ctx, code, chunk, opts, meta) => {
1620
+ if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
1621
+ const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
1622
+ let magicStringInstance;
1623
+ if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
1624
+ get() {
1625
+ if (magicStringInstance) return magicStringInstance;
1626
+ magicStringInstance = new RolldownMagicString(code);
1627
+ return magicStringInstance;
1628
+ },
1629
+ configurable: true
1630
+ });
1631
+ 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);
1632
+ if (ret == null) return;
1633
+ if (ret instanceof RolldownMagicString) {
1634
+ const normalizedCode = ret.toString();
1635
+ const generatedMap = ret.generateMap();
1636
+ return {
1637
+ code: normalizedCode,
1638
+ map: bindingifySourcemap({
1639
+ file: generatedMap.file,
1640
+ mappings: generatedMap.mappings,
1641
+ names: generatedMap.names,
1642
+ sources: generatedMap.sources,
1643
+ sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1644
+ })
1645
+ };
1646
+ }
1647
+ if (typeof ret === "string") return { code: ret };
1648
+ if (ret.code instanceof RolldownMagicString) {
1649
+ const magicString = ret.code;
1650
+ const normalizedCode = magicString.toString();
1651
+ if (ret.map === null) return {
1652
+ code: normalizedCode,
1653
+ map: null
1654
+ };
1655
+ if (ret.map === void 0) {
1656
+ const generatedMap = magicString.generateMap();
1657
+ return {
1658
+ code: normalizedCode,
1659
+ map: bindingifySourcemap({
1660
+ file: generatedMap.file,
1661
+ mappings: generatedMap.mappings,
1662
+ names: generatedMap.names,
1663
+ sources: generatedMap.sources,
1664
+ sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
1665
+ })
1666
+ };
1667
+ }
1668
+ return {
1669
+ code: normalizedCode,
1670
+ map: bindingifySourcemap(ret.map)
1671
+ };
1672
+ }
1673
+ if (ret.map === null) return {
1674
+ code: ret.code,
1675
+ map: null
1676
+ };
1677
+ return {
1678
+ code: ret.code,
1679
+ map: bindingifySourcemap(ret.map)
1680
+ };
1681
+ },
1682
+ meta: bindingifyPluginHookMeta(meta),
1683
+ filter: bindingifyRenderChunkFilter(options.filter)
1684
+ };
1685
+ }
1686
+ function bindingifyAugmentChunkHash(args) {
1687
+ const hook = args.plugin.augmentChunkHash;
1688
+ if (!hook) return {};
1689
+ const { handler, meta } = normalizeHook(hook);
1690
+ return {
1691
+ plugin: async (ctx, chunk) => {
1692
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1693
+ },
1694
+ meta: bindingifyPluginHookMeta(meta)
1695
+ };
1696
+ }
1697
+ function bindingifyRenderError(args) {
1698
+ const hook = args.plugin.renderError;
1699
+ if (!hook) return {};
1700
+ const { handler, meta } = normalizeHook(hook);
1701
+ return {
1702
+ plugin: async (ctx, err) => {
1703
+ handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
1704
+ },
1705
+ meta: bindingifyPluginHookMeta(meta)
1706
+ };
1707
+ }
1708
+ function bindingifyGenerateBundle(args) {
1709
+ const hook = args.plugin.generateBundle;
1710
+ if (!hook) return {};
1711
+ const { handler, meta } = normalizeHook(hook);
1712
+ return {
1713
+ plugin: async (ctx, bundle, isWrite, opts) => {
1714
+ const changed = {
1715
+ updated: /* @__PURE__ */ new Set(),
1716
+ deleted: /* @__PURE__ */ new Set()
1717
+ };
1718
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1719
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1720
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
1721
+ return collectChangedBundle(changed, output);
1722
+ },
1723
+ meta: bindingifyPluginHookMeta(meta)
1724
+ };
1725
+ }
1726
+ function bindingifyWriteBundle(args) {
1727
+ const hook = args.plugin.writeBundle;
1728
+ if (!hook) return {};
1729
+ const { handler, meta } = normalizeHook(hook);
1730
+ return {
1731
+ plugin: async (ctx, bundle, opts) => {
1732
+ const changed = {
1733
+ updated: /* @__PURE__ */ new Set(),
1734
+ deleted: /* @__PURE__ */ new Set()
1735
+ };
1736
+ const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
1737
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
1738
+ await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
1739
+ return collectChangedBundle(changed, output);
1740
+ },
1741
+ meta: bindingifyPluginHookMeta(meta)
1742
+ };
1743
+ }
1744
+ function bindingifyCloseBundle(args) {
1745
+ const hook = args.plugin.closeBundle;
1746
+ if (!hook) return {};
1747
+ const { handler, meta } = normalizeHook(hook);
1748
+ return {
1749
+ plugin: async (ctx, err) => {
1750
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
1751
+ },
1752
+ meta: bindingifyPluginHookMeta(meta)
1753
+ };
1754
+ }
1755
+ function bindingifyBanner(args) {
1756
+ const hook = args.plugin.banner;
1757
+ if (!hook) return {};
1758
+ const { handler, meta } = normalizeHook(hook);
1759
+ return {
1760
+ plugin: async (ctx, chunk) => {
1761
+ if (typeof handler === "string") return handler;
1762
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1763
+ },
1764
+ meta: bindingifyPluginHookMeta(meta)
1765
+ };
1766
+ }
1767
+ function bindingifyFooter(args) {
1768
+ const hook = args.plugin.footer;
1769
+ if (!hook) return {};
1770
+ const { handler, meta } = normalizeHook(hook);
1771
+ return {
1772
+ plugin: async (ctx, chunk) => {
1773
+ if (typeof handler === "string") return handler;
1774
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1775
+ },
1776
+ meta: bindingifyPluginHookMeta(meta)
1777
+ };
1778
+ }
1779
+ function bindingifyIntro(args) {
1780
+ const hook = args.plugin.intro;
1781
+ if (!hook) return {};
1782
+ const { handler, meta } = normalizeHook(hook);
1783
+ return {
1784
+ plugin: async (ctx, chunk) => {
1785
+ if (typeof handler === "string") return handler;
1786
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1787
+ },
1788
+ meta: bindingifyPluginHookMeta(meta)
1789
+ };
1790
+ }
1791
+ function bindingifyOutro(args) {
1792
+ const hook = args.plugin.outro;
1793
+ if (!hook) return {};
1794
+ const { handler, meta } = normalizeHook(hook);
1795
+ return {
1796
+ plugin: async (ctx, chunk) => {
1797
+ if (typeof handler === "string") return handler;
1798
+ return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
1799
+ },
1800
+ meta: bindingifyPluginHookMeta(meta)
1801
+ };
1802
+ }
1803
+ //#endregion
1804
+ //#region src/plugin/bindingify-watch-hooks.ts
1805
+ function bindingifyWatchChange(args) {
1806
+ const hook = args.plugin.watchChange;
1807
+ if (!hook) return {};
1808
+ const { handler, meta } = normalizeHook(hook);
1809
+ return {
1810
+ plugin: async (ctx, id, event) => {
1811
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
1812
+ },
1813
+ meta: bindingifyPluginHookMeta(meta)
1814
+ };
1815
+ }
1816
+ function bindingifyCloseWatcher(args) {
1817
+ const hook = args.plugin.closeWatcher;
1818
+ if (!hook) return {};
1819
+ const { handler, meta } = normalizeHook(hook);
1820
+ return {
1821
+ plugin: async (ctx) => {
1822
+ await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
1823
+ },
1824
+ meta: bindingifyPluginHookMeta(meta)
1825
+ };
1886
1826
  }
1887
1827
  //#endregion
1888
- //#region src/plugin/plugin-context-data.ts
1889
- var PluginContextData = class {
1890
- onLog;
1891
- outputOptions;
1892
- normalizedInputPlugins;
1893
- normalizedOutputPlugins;
1894
- moduleOptionMap = /* @__PURE__ */ new Map();
1895
- resolveOptionsMap = /* @__PURE__ */ new Map();
1896
- loadModulePromiseMap = /* @__PURE__ */ new Map();
1897
- renderedChunkMeta = null;
1898
- normalizedInputOptions = null;
1899
- normalizedOutputOptions = null;
1900
- constructor(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins) {
1901
- this.onLog = onLog;
1902
- this.outputOptions = outputOptions;
1903
- this.normalizedInputPlugins = normalizedInputPlugins;
1904
- this.normalizedOutputPlugins = normalizedOutputPlugins;
1905
- }
1906
- updateModuleOption(id, option) {
1907
- const existing = this.moduleOptionMap.get(id);
1908
- if (existing) {
1909
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
1910
- if (option.meta != null) Object.assign(existing.meta, option.meta);
1911
- if (option.invalidate != null) existing.invalidate = option.invalidate;
1912
- } else {
1913
- this.moduleOptionMap.set(id, option);
1914
- return option;
1915
- }
1916
- return existing;
1917
- }
1918
- getModuleOption(id) {
1919
- const option = this.moduleOptionMap.get(id);
1920
- if (!option) {
1921
- const raw = {
1922
- moduleSideEffects: null,
1923
- meta: {}
1924
- };
1925
- this.moduleOptionMap.set(id, raw);
1926
- return raw;
1927
- }
1928
- return option;
1828
+ //#region src/plugin/generated/hook-usage.ts
1829
+ var HookUsage = class {
1830
+ bitflag = BigInt(0);
1831
+ constructor() {}
1832
+ union(kind) {
1833
+ this.bitflag |= BigInt(kind);
1929
1834
  }
1930
- getModuleInfo(id, context) {
1931
- const bindingInfo = context.getModuleInfo(id);
1932
- if (bindingInfo) {
1933
- const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
1934
- return this.proxyModuleInfo(id, info);
1935
- }
1936
- return null;
1835
+ inner() {
1836
+ return Number(this.bitflag);
1937
1837
  }
1938
- proxyModuleInfo(id, info) {
1939
- let moduleSideEffects = info.moduleSideEffects;
1940
- Object.defineProperty(info, "moduleSideEffects", {
1941
- get() {
1942
- return moduleSideEffects;
1943
- },
1944
- set: (v) => {
1945
- this.updateModuleOption(id, {
1946
- moduleSideEffects: v,
1947
- meta: info.meta,
1948
- invalidate: true
1949
- });
1950
- moduleSideEffects = v;
1838
+ };
1839
+ function extractHookUsage(plugin) {
1840
+ let hookUsage = new HookUsage();
1841
+ if (plugin.buildStart) hookUsage.union(1);
1842
+ if (plugin.resolveId) hookUsage.union(2);
1843
+ if (plugin.resolveDynamicImport) hookUsage.union(4);
1844
+ if (plugin.load) hookUsage.union(8);
1845
+ if (plugin.transform) hookUsage.union(16);
1846
+ if (plugin.moduleParsed) hookUsage.union(32);
1847
+ if (plugin.buildEnd) hookUsage.union(64);
1848
+ if (plugin.renderStart) hookUsage.union(128);
1849
+ if (plugin.renderError) hookUsage.union(256);
1850
+ if (plugin.renderChunk) hookUsage.union(512);
1851
+ if (plugin.augmentChunkHash) hookUsage.union(1024);
1852
+ if (plugin.generateBundle) hookUsage.union(2048);
1853
+ if (plugin.writeBundle) hookUsage.union(4096);
1854
+ if (plugin.closeBundle) hookUsage.union(8192);
1855
+ if (plugin.watchChange) hookUsage.union(16384);
1856
+ if (plugin.closeWatcher) hookUsage.union(32768);
1857
+ if (plugin.banner) hookUsage.union(131072);
1858
+ if (plugin.footer) hookUsage.union(262144);
1859
+ if (plugin.intro) hookUsage.union(524288);
1860
+ if (plugin.outro) hookUsage.union(1048576);
1861
+ if (plugin.transformCacheHit) hookUsage.union(2097152);
1862
+ return hookUsage;
1863
+ }
1864
+ //#endregion
1865
+ //#region src/plugin/bindingify-plugin.ts
1866
+ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
1867
+ const args = {
1868
+ plugin,
1869
+ options,
1870
+ outputOptions,
1871
+ pluginContextData,
1872
+ onLog,
1873
+ logLevel,
1874
+ watchMode,
1875
+ normalizedOutputPlugins
1876
+ };
1877
+ const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
1878
+ const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
1879
+ const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
1880
+ const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
1881
+ const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
1882
+ const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
1883
+ const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1884
+ const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
1885
+ const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
1886
+ const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1887
+ const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1888
+ const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1889
+ const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1890
+ const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1891
+ const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1892
+ const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1893
+ const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1894
+ const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
1895
+ const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
1896
+ const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1897
+ const { plugin: transformCacheHit, meta: transformCacheHitMeta } = bindingifyTransformCacheHit(args);
1898
+ let hookUsage = extractHookUsage(plugin).inner();
1899
+ return wrapHandlers({
1900
+ name: plugin.name,
1901
+ buildStart,
1902
+ buildStartMeta,
1903
+ resolveId,
1904
+ resolveIdMeta,
1905
+ resolveIdFilter,
1906
+ resolveDynamicImport,
1907
+ resolveDynamicImportMeta,
1908
+ buildEnd,
1909
+ buildEndMeta,
1910
+ transform,
1911
+ transformMeta,
1912
+ transformFilter,
1913
+ moduleParsed,
1914
+ moduleParsedMeta,
1915
+ load,
1916
+ loadMeta,
1917
+ loadFilter,
1918
+ renderChunk,
1919
+ renderChunkMeta,
1920
+ renderChunkFilter,
1921
+ augmentChunkHash,
1922
+ augmentChunkHashMeta,
1923
+ renderStart,
1924
+ renderStartMeta,
1925
+ renderError,
1926
+ renderErrorMeta,
1927
+ generateBundle,
1928
+ generateBundleMeta,
1929
+ writeBundle,
1930
+ writeBundleMeta,
1931
+ closeBundle,
1932
+ closeBundleMeta,
1933
+ banner,
1934
+ bannerMeta,
1935
+ footer,
1936
+ footerMeta,
1937
+ intro,
1938
+ introMeta,
1939
+ outro,
1940
+ outroMeta,
1941
+ watchChange,
1942
+ watchChangeMeta,
1943
+ closeWatcher,
1944
+ closeWatcherMeta,
1945
+ transformCacheHit,
1946
+ transformCacheHitMeta,
1947
+ hookUsage
1948
+ });
1949
+ }
1950
+ function wrapHandlers(plugin) {
1951
+ for (const hookName of [
1952
+ "buildStart",
1953
+ "resolveId",
1954
+ "resolveDynamicImport",
1955
+ "buildEnd",
1956
+ "transform",
1957
+ "moduleParsed",
1958
+ "load",
1959
+ "renderChunk",
1960
+ "augmentChunkHash",
1961
+ "renderStart",
1962
+ "renderError",
1963
+ "generateBundle",
1964
+ "writeBundle",
1965
+ "closeBundle",
1966
+ "banner",
1967
+ "footer",
1968
+ "intro",
1969
+ "outro",
1970
+ "watchChange",
1971
+ "closeWatcher",
1972
+ "transformCacheHit"
1973
+ ]) {
1974
+ const handler = plugin[hookName];
1975
+ if (handler) plugin[hookName] = async (...args) => {
1976
+ try {
1977
+ return await handler(...args);
1978
+ } catch (e) {
1979
+ return error(logPluginError(e, plugin.name, {
1980
+ hook: hookName,
1981
+ id: hookName === "transform" ? args[2] : hookName === "transformCacheHit" ? args[1] : void 0
1982
+ }));
1951
1983
  }
1952
- });
1953
- return info;
1954
- }
1955
- getModuleIds(context) {
1956
- return context.getModuleIds().values();
1957
- }
1958
- saveResolveOptions(options) {
1959
- const index = this.resolveOptionsMap.size;
1960
- this.resolveOptionsMap.set(index, options);
1961
- return index;
1962
- }
1963
- getSavedResolveOptions(receipt) {
1964
- return this.resolveOptionsMap.get(receipt);
1965
- }
1966
- removeSavedResolveOptions(receipt) {
1967
- this.resolveOptionsMap.delete(receipt);
1968
- }
1969
- setRenderChunkMeta(meta) {
1970
- this.renderedChunkMeta = meta;
1971
- }
1972
- getRenderChunkMeta() {
1973
- return this.renderedChunkMeta;
1974
- }
1975
- getInputOptions(opts) {
1976
- this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog, this.normalizedInputPlugins);
1977
- return this.normalizedInputOptions;
1978
- }
1979
- getOutputOptions(opts) {
1980
- this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
1981
- return this.normalizedOutputOptions;
1982
- }
1983
- clear() {
1984
- this.renderedChunkMeta = null;
1985
- this.loadModulePromiseMap.clear();
1984
+ };
1986
1985
  }
1987
- };
1986
+ return plugin;
1987
+ }
1988
1988
  //#endregion
1989
1989
  //#region src/utils/normalize-transform-options.ts
1990
1990
  /**
@@ -1999,10 +1999,13 @@ function normalizeTransformOptions(inputOptions) {
1999
1999
  const dropLabels = transform?.dropLabels;
2000
2000
  let oxcTransformOptions;
2001
2001
  if (transform) {
2002
- const { define: _define, inject: _inject, dropLabels: _dropLabels, ...rest } = transform;
2003
- if (Object.keys(rest).length > 0) {
2002
+ const { define: _define, inject: _inject, dropLabels: _dropLabels, reactCompiler, ...rest } = transform;
2003
+ if (Object.keys(rest).length > 0 || reactCompiler != null) {
2004
2004
  if (rest.jsx === false) rest.jsx = "disable";
2005
- oxcTransformOptions = rest;
2005
+ oxcTransformOptions = {
2006
+ options: rest,
2007
+ ...reactCompiler != null ? { reactCompiler } : {}
2008
+ };
2006
2009
  }
2007
2010
  }
2008
2011
  return {
@@ -2014,8 +2017,7 @@ function normalizeTransformOptions(inputOptions) {
2014
2017
  }
2015
2018
  //#endregion
2016
2019
  //#region src/utils/bindingify-input-options.ts
2017
- function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedInputPlugins, normalizedOutputPlugins, onLog, logLevel, watchMode) {
2018
- const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins);
2020
+ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
2019
2021
  const plugins = rawPlugins.map((plugin) => {
2020
2022
  if ("_parallel" in plugin) return;
2021
2023
  if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
@@ -2255,4 +2257,4 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
2255
2257
  };
2256
2258
  }
2257
2259
  //#endregion
2258
- 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 };
2260
+ 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 };