storybook 10.1.0-alpha.12 → 10.1.0-alpha.13

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 (87) hide show
  1. package/dist/_browser-chunks/{chunk-74YHFU5B.js → chunk-2XZMBGTA.js} +1 -1
  2. package/dist/_browser-chunks/{chunk-EBHB6RPS.js → chunk-FQ7SLVLR.js} +6 -1
  3. package/dist/_browser-chunks/{chunk-X3DUQ5RA.js → chunk-GFY5R5EY.js} +1 -1
  4. package/dist/_node-chunks/{builder-manager-YUOHSIUB.js → builder-manager-DWDUVXZM.js} +27 -22
  5. package/dist/_node-chunks/{chunk-B6JWY6PC.js → camelcase-EETCRTJX.js} +8 -8
  6. package/dist/_node-chunks/{chunk-CZ5GHJCC.js → chunk-2W4GZCLE.js} +7 -7
  7. package/dist/_node-chunks/{chunk-E5FJS66Z.js → chunk-447655DM.js} +6 -6
  8. package/dist/_node-chunks/{chunk-WFLWJO24.js → chunk-4EJUC2SD.js} +4998 -1685
  9. package/dist/_node-chunks/chunk-4ZJOH2UN.js +61 -0
  10. package/dist/_node-chunks/chunk-654SJIMS.js +23 -0
  11. package/dist/_node-chunks/{chunk-2DMESZFJ.js → chunk-7IAVT2FU.js} +7 -7
  12. package/dist/_node-chunks/{chunk-5KLIDWFN.js → chunk-7KFHRNOT.js} +7 -7
  13. package/dist/_node-chunks/{chunk-XXPJ7XR3.js → chunk-AZIPBEBK.js} +6 -6
  14. package/dist/_node-chunks/{chunk-WUXQMQCB.js → chunk-B76FDKVB.js} +6 -6
  15. package/dist/_node-chunks/chunk-B7PGKETD.js +3781 -0
  16. package/dist/_node-chunks/{chunk-EZWWR7AR.js → chunk-CLUBH2LP.js} +55 -36
  17. package/dist/_node-chunks/{chunk-DUXPWBOK.js → chunk-CMYD2JNN.js} +7 -7
  18. package/dist/_node-chunks/{chunk-QCO2ZM7F.js → chunk-DIPKXLEP.js} +55 -32
  19. package/dist/_node-chunks/{chunk-DWXTZT3D.js → chunk-DPFYWXEA.js} +6 -6
  20. package/dist/_node-chunks/{chunk-FZLRAH4N.js → chunk-FCVNHU2F.js} +7 -7
  21. package/dist/_node-chunks/{chunk-QYQIZBS6.js → chunk-JQ7RQS5Q.js} +6 -6
  22. package/dist/_node-chunks/chunk-LEL5OSY3.js +18 -0
  23. package/dist/_node-chunks/{chunk-WA6KZQZ2.js → chunk-LPKSBF62.js} +6 -6
  24. package/dist/_node-chunks/chunk-LYEZOJ43.js +78 -0
  25. package/dist/_node-chunks/{chunk-JARUEMEP.js → chunk-MIA5324I.js} +7 -7
  26. package/dist/_node-chunks/{chunk-A4APXFQ2.js → chunk-MJM4TEMP.js} +14 -8
  27. package/dist/_node-chunks/{chunk-NAOYEL54.js → chunk-OVVZIUHS.js} +7 -7
  28. package/dist/_node-chunks/{chunk-5HV3B5OP.js → chunk-RUUNVQ6W.js} +1104 -13
  29. package/dist/_node-chunks/{chunk-2D2IODUU.js → chunk-URLNGLC2.js} +51 -71
  30. package/dist/_node-chunks/{chunk-OP3INKUD.js → chunk-WC2YEQHJ.js} +6 -6
  31. package/dist/_node-chunks/{chunk-4FT2DHGE.js → chunk-XKRVQL2G.js} +8 -8
  32. package/dist/_node-chunks/{chunk-SEMIAAWG.js → chunk-Z2OWEMX3.js} +8 -8
  33. package/dist/_node-chunks/{dist-DS2B5A3J.js → dist-22CLJ4BC.js} +9 -9
  34. package/dist/_node-chunks/{globby-6THB7HVX.js → globby-GR24TGSK.js} +9 -9
  35. package/dist/_node-chunks/{lib-5NKX4YGG.js → lib-G2LGVRPC.js} +7 -7
  36. package/dist/_node-chunks/{mdx-N42X6CFJ-ZLT3QOFF.js → mdx-N42X6CFJ-W6P6IDDW.js} +8 -8
  37. package/dist/_node-chunks/{p-limit-PDMWNG7W.js → p-limit-K4FZHG2F.js} +7 -7
  38. package/dist/babel/index.js +10 -11
  39. package/dist/bin/core.js +32 -26
  40. package/dist/bin/dispatcher.js +31 -20
  41. package/dist/bin/loader.js +10 -13
  42. package/dist/cli/index.d.ts +692 -133
  43. package/dist/cli/index.js +1005 -177
  44. package/dist/common/index.d.ts +139 -62
  45. package/dist/common/index.js +63 -49
  46. package/dist/core-server/index.d.ts +3 -2
  47. package/dist/core-server/index.js +96 -1413
  48. package/dist/core-server/presets/common-override-preset.js +9 -9
  49. package/dist/core-server/presets/common-preset.js +25 -65
  50. package/dist/csf-tools/index.js +9 -9
  51. package/dist/manager/globals-runtime.js +32 -3
  52. package/dist/manager/runtime.js +1 -1
  53. package/dist/manager-api/index.d.ts +1 -1
  54. package/dist/manager-api/index.js +4 -4
  55. package/dist/manager-errors.d.ts +6 -0
  56. package/dist/manager-errors.js +2 -2
  57. package/dist/mocking-utils/index.d.ts +1126 -0
  58. package/dist/{_node-chunks/chunk-ZXSD6L3S.js → mocking-utils/index.js} +441 -16
  59. package/dist/node-logger/index.d.ts +192 -24
  60. package/dist/node-logger/index.js +23 -3148
  61. package/dist/preview/runtime.js +31 -2
  62. package/dist/preview-api/index.d.ts +69 -68
  63. package/dist/preview-errors.d.ts +6 -0
  64. package/dist/preview-errors.js +2 -2
  65. package/dist/server-errors.d.ts +31 -1
  66. package/dist/server-errors.js +17 -10
  67. package/dist/telemetry/index.d.ts +23 -2
  68. package/dist/telemetry/index.js +25 -24
  69. package/dist/types/index.d.ts +71 -8
  70. package/dist/types/index.js +25 -1
  71. package/package.json +7 -9
  72. package/dist/_node-chunks/camelcase-JREIL7NV.js +0 -18
  73. package/dist/_node-chunks/chunk-FDXFVHIL.js +0 -1114
  74. package/dist/_node-chunks/chunk-HZG65SU3.js +0 -34
  75. package/dist/_node-chunks/chunk-IXVYNBMD.js +0 -18
  76. package/dist/_node-chunks/chunk-LIH7MTP7.js +0 -3214
  77. package/dist/_node-chunks/chunk-N5GIRUP5.js +0 -1047
  78. package/dist/_node-chunks/chunk-O5DA7YLO.js +0 -3171
  79. package/dist/_node-chunks/chunk-TS2UUH2J.js +0 -301
  80. package/dist/_node-chunks/chunk-Y4E6IGQF.js +0 -61
  81. package/dist/_node-chunks/chunk-ZL3AFKRX.js +0 -1029
  82. package/dist/_node-chunks/plugin-6XMWOGPO.js +0 -123
  83. package/dist/_node-chunks/plugin-LTOXVT6A.js +0 -109
  84. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-2SFE5LQS.js +0 -46582
  85. package/dist/_node-chunks/webpack-mock-plugin-CX5J2U56.js +0 -92
  86. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -32
  87. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -28
@@ -1,14 +1,23 @@
1
- import CJS_COMPAT_NODE_URL_57ru1wfqqjv from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_57ru1wfqqjv from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_57ru1wfqqjv from "node:module";
1
+ import CJS_COMPAT_NODE_URL_h0pwn2pcb57 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_h0pwn2pcb57 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_h0pwn2pcb57 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_57ru1wfqqjv.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_57ru1wfqqjv.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_57ru1wfqqjv.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_h0pwn2pcb57.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_h0pwn2pcb57.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_h0pwn2pcb57.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
+ import {
13
+ basename,
14
+ dirname,
15
+ isAbsolute,
16
+ join,
17
+ normalize,
18
+ resolve
19
+ } from "../_node-chunks/chunk-LPKSBF62.js";
20
+ import "../_node-chunks/chunk-WC2YEQHJ.js";
12
21
 
13
22
  // ../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
14
23
  var comma = 44, semicolon = 59, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
@@ -68,11 +77,11 @@ var BitSet = class _BitSet {
68
77
  constructor(arg) {
69
78
  this.bits = arg instanceof _BitSet ? arg.bits.slice() : [];
70
79
  }
71
- add(n2) {
72
- this.bits[n2 >> 5] |= 1 << (n2 & 31);
80
+ add(n3) {
81
+ this.bits[n3 >> 5] |= 1 << (n3 & 31);
73
82
  }
74
- has(n2) {
75
- return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
83
+ has(n3) {
84
+ return !!(this.bits[n3 >> 5] & 1 << (n3 & 31));
76
85
  }
77
86
  }, Chunk = class _Chunk {
78
87
  constructor(start, end, content) {
@@ -661,22 +670,209 @@ var wordRegex = /\w/, Mappings = class {
661
670
  }
662
671
  };
663
672
 
664
- // src/core-server/presets/vitePlugins/vite-inject-mocker/constants.ts
665
- var __STORYBOOK_GLOBAL_THIS_ACCESSOR__ = "__vitest_mocker__";
673
+ // ../node_modules/estree-walker/src/walker.js
674
+ var WalkerBase = class {
675
+ constructor() {
676
+ this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
677
+ skip: () => this.should_skip = !0,
678
+ remove: () => this.should_remove = !0,
679
+ replace: (node) => this.replacement = node
680
+ };
681
+ }
682
+ /**
683
+ * @template {Node} Parent
684
+ * @param {Parent | null | undefined} parent
685
+ * @param {keyof Parent | null | undefined} prop
686
+ * @param {number | null | undefined} index
687
+ * @param {Node} node
688
+ */
689
+ replace(parent, prop, index, node) {
690
+ parent && prop && (index != null ? parent[prop][index] = node : parent[prop] = node);
691
+ }
692
+ /**
693
+ * @template {Node} Parent
694
+ * @param {Parent | null | undefined} parent
695
+ * @param {keyof Parent | null | undefined} prop
696
+ * @param {number | null | undefined} index
697
+ */
698
+ remove(parent, prop, index) {
699
+ parent && prop && (index != null ? parent[prop].splice(index, 1) : delete parent[prop]);
700
+ }
701
+ };
666
702
 
667
- // src/core-server/mocking-utils/esmWalker.ts
703
+ // ../node_modules/estree-walker/src/sync.js
704
+ var SyncWalker = class extends WalkerBase {
705
+ /**
706
+ *
707
+ * @param {SyncHandler} [enter]
708
+ * @param {SyncHandler} [leave]
709
+ */
710
+ constructor(enter, leave) {
711
+ super(), this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
712
+ skip: () => this.should_skip = !0,
713
+ remove: () => this.should_remove = !0,
714
+ replace: (node) => this.replacement = node
715
+ }, this.enter = enter, this.leave = leave;
716
+ }
717
+ /**
718
+ * @template {Node} Parent
719
+ * @param {Node} node
720
+ * @param {Parent | null} parent
721
+ * @param {keyof Parent} [prop]
722
+ * @param {number | null} [index]
723
+ * @returns {Node | null}
724
+ */
725
+ visit(node, parent, prop, index) {
726
+ if (node) {
727
+ if (this.enter) {
728
+ let _should_skip = this.should_skip, _should_remove = this.should_remove, _replacement = this.replacement;
729
+ this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.enter.call(this.context, node, parent, prop, index), this.replacement && (node = this.replacement, this.replace(parent, prop, index, node)), this.should_remove && this.remove(parent, prop, index);
730
+ let skipped = this.should_skip, removed = this.should_remove;
731
+ if (this.should_skip = _should_skip, this.should_remove = _should_remove, this.replacement = _replacement, skipped) return node;
732
+ if (removed) return null;
733
+ }
734
+ let key;
735
+ for (key in node) {
736
+ let value = node[key];
737
+ if (value && typeof value == "object")
738
+ if (Array.isArray(value)) {
739
+ let nodes = (
740
+ /** @type {Array<unknown>} */
741
+ value
742
+ );
743
+ for (let i = 0; i < nodes.length; i += 1) {
744
+ let item = nodes[i];
745
+ isNode(item) && (this.visit(item, node, key, i) || i--);
746
+ }
747
+ } else isNode(value) && this.visit(value, node, key, null);
748
+ }
749
+ if (this.leave) {
750
+ let _replacement = this.replacement, _should_remove = this.should_remove;
751
+ this.replacement = null, this.should_remove = !1, this.leave.call(this.context, node, parent, prop, index), this.replacement && (node = this.replacement, this.replace(parent, prop, index, node)), this.should_remove && this.remove(parent, prop, index);
752
+ let removed = this.should_remove;
753
+ if (this.replacement = _replacement, this.should_remove = _should_remove, removed) return null;
754
+ }
755
+ }
756
+ return node;
757
+ }
758
+ };
759
+ function isNode(value) {
760
+ return value !== null && typeof value == "object" && "type" in value && typeof value.type == "string";
761
+ }
762
+
763
+ // ../node_modules/estree-walker/src/index.js
764
+ function walk(ast, { enter, leave }) {
765
+ return new SyncWalker(enter, leave).visit(ast, null);
766
+ }
767
+
768
+ // src/mocking-utils/esmWalker.ts
769
+ var isNodeInPatternWeakSet = /* @__PURE__ */ new WeakSet();
770
+ function setIsNodeInPattern(node) {
771
+ return isNodeInPatternWeakSet.add(node);
772
+ }
773
+ function isNodeInPattern(node) {
774
+ return isNodeInPatternWeakSet.has(node);
775
+ }
776
+ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallExpression }) {
777
+ let parentStack = [], varKindStack = [], scopeMap = /* @__PURE__ */ new WeakMap(), identifiers = [], setScope = (node, name) => {
778
+ let scopeIds = scopeMap.get(node);
779
+ scopeIds && scopeIds.has(name) || (scopeIds || (scopeIds = /* @__PURE__ */ new Set(), scopeMap.set(node, scopeIds)), scopeIds.add(name));
780
+ };
781
+ function isInScope(name, parents) {
782
+ return parents.some((node) => node && scopeMap.get(node)?.has(name));
783
+ }
784
+ function handlePattern(p, parentScope) {
785
+ p.type === "Identifier" ? setScope(parentScope, p.name) : p.type === "RestElement" ? handlePattern(p.argument, parentScope) : p.type === "ObjectPattern" ? p.properties.forEach((property) => {
786
+ property.type === "RestElement" ? setScope(parentScope, property.argument.name) : handlePattern(property.value, parentScope);
787
+ }) : p.type === "ArrayPattern" ? p.elements.forEach((element) => {
788
+ element && handlePattern(element, parentScope);
789
+ }) : p.type === "AssignmentPattern" ? handlePattern(p.left, parentScope) : setScope(parentScope, p.name);
790
+ }
791
+ walk(root, {
792
+ enter(node, parent) {
793
+ if (node.type === "ImportDeclaration")
794
+ return this.skip();
795
+ if (parent && !(parent.type === "IfStatement" && node === parent.alternate) && parentStack.unshift(parent), node.type === "VariableDeclaration" && varKindStack.unshift(node.kind), node.type === "CallExpression" && onCallExpression?.(node), node.type === "MetaProperty" && node.meta.name === "import" ? onImportMeta?.(node) : node.type === "ImportExpression" && onDynamicImport?.(node), node.type === "Identifier")
796
+ !isInScope(node.name, parentStack) && isRefIdentifier(node, parent, parentStack) && identifiers.push([node, parentStack.slice(0)]);
797
+ else if (isFunctionNode(node)) {
798
+ if (node.type === "FunctionDeclaration") {
799
+ let parentScope = findParentScope(parentStack);
800
+ parentScope && setScope(parentScope, node.id.name);
801
+ }
802
+ node.params.forEach((p) => {
803
+ if (p.type === "ObjectPattern" || p.type === "ArrayPattern") {
804
+ handlePattern(p, node);
805
+ return;
806
+ }
807
+ walk(p.type === "AssignmentPattern" ? p.left : p, {
808
+ enter(child, parent2) {
809
+ if (parent2?.type === "AssignmentPattern" && parent2?.right === child)
810
+ return this.skip();
811
+ child.type === "Identifier" && (isStaticPropertyKey(child, parent2) || parent2?.type === "TemplateLiteral" && parent2?.expressions.includes(child) || parent2?.type === "CallExpression" && parent2?.callee === child || setScope(node, child.name));
812
+ }
813
+ });
814
+ });
815
+ } else if (node.type === "Property" && parent.type === "ObjectPattern")
816
+ setIsNodeInPattern(node);
817
+ else if (node.type === "VariableDeclarator") {
818
+ let parentFunction = findParentScope(parentStack, varKindStack[0] === "var");
819
+ parentFunction && handlePattern(node.id, parentFunction);
820
+ } else node.type === "CatchClause" && node.param && handlePattern(node.param, node);
821
+ },
822
+ leave(node, parent) {
823
+ parent && !(parent.type === "IfStatement" && node === parent.alternate) && parentStack.shift(), node.type === "VariableDeclaration" && varKindStack.shift();
824
+ }
825
+ }), identifiers.forEach(([node, stack]) => {
826
+ if (!isInScope(node.name, stack)) {
827
+ let parent = stack[0], grandparent = stack[1], hasBindingShortcut = isStaticProperty(parent) && parent.shorthand && (!isNodeInPattern(parent) || isInDestructuringAssignment(parent, parentStack)), classDeclaration = parent.type === "PropertyDefinition" && grandparent?.type === "ClassBody" || parent.type === "ClassDeclaration" && node === parent.superClass, classExpression = parent.type === "ClassExpression" && node === parent.id;
828
+ onIdentifier?.(
829
+ node,
830
+ {
831
+ hasBindingShortcut,
832
+ classDeclaration,
833
+ classExpression
834
+ },
835
+ stack
836
+ );
837
+ }
838
+ });
839
+ }
840
+ function isRefIdentifier(id, parent, parentStack) {
841
+ return !(parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id || isFunctionNode(parent) && (parent.id === id || parent.params.includes(id)) || parent.type === "MethodDefinition" && !parent.computed || isStaticPropertyKey(id, parent) || isNodeInPattern(parent) && parent.value === id || parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack) || parent.type === "MemberExpression" && parent.property === id && !parent.computed || parent.type === "ExportSpecifier" || id.name === "arguments");
842
+ }
843
+ function isStaticProperty(node) {
844
+ return node && node.type === "Property" && !node.computed;
845
+ }
846
+ function isStaticPropertyKey(node, parent) {
847
+ return isStaticProperty(parent) && parent.key === node;
848
+ }
849
+ var functionNodeTypeRE = /Function(?:Expression|Declaration)$|Method$/;
850
+ function isFunctionNode(node) {
851
+ return functionNodeTypeRE.test(node.type);
852
+ }
853
+ var blockNodeTypeRE = /^BlockStatement$|^For(?:In|Of)?Statement$/;
854
+ function isBlock(node) {
855
+ return blockNodeTypeRE.test(node.type);
856
+ }
857
+ function findParentScope(parentStack, isVar = !1) {
858
+ return parentStack.find(isVar ? isFunctionNode : isBlock);
859
+ }
860
+ function isInDestructuringAssignment(parent, parentStack) {
861
+ return parent && (parent.type === "Property" || parent.type === "ArrayPattern") ? parentStack.some((i) => i.type === "AssignmentExpression") : !1;
862
+ }
668
863
  function getArbitraryModuleIdentifier(node) {
669
864
  return node.type === "Identifier" ? node.name : node.raw;
670
865
  }
671
866
 
672
- // src/core-server/mocking-utils/automock.ts
867
+ // src/mocking-utils/automock.ts
868
+ var __STORYBOOK_GLOBAL_THIS_ACCESSOR__ = "__vitest_mocker__";
673
869
  function getAutomockCode(originalCode, isSpy, parse) {
674
870
  return automockModule(originalCode, isSpy ? "autospy" : "automock", parse, {
675
871
  globalThisAccessor: JSON.stringify(__STORYBOOK_GLOBAL_THIS_ACCESSOR__)
676
872
  });
677
873
  }
678
874
  function automockModule(code, mockType, parse, options = {}) {
679
- let globalThisAccessor = options.globalThisAccessor || '"__vitest_mocker__"', ast = parse(code), m = new MagicString(code), allSpecifiers = [], importIndex = 0;
875
+ let globalThisAccessor = options.globalThisAccessor || JSON.stringify(__STORYBOOK_GLOBAL_THIS_ACCESSOR__), ast = parse(code), m = new MagicString(code), allSpecifiers = [], importIndex = 0;
680
876
  for (let _node of ast.body) {
681
877
  if (_node.type === "ExportAllDeclaration")
682
878
  throw new Error(
@@ -751,6 +947,235 @@ ${allSpecifiers.map(({ name, alias }, index) => ` __vitest_mocked_${index}__ as
751
947
  return m.append(moduleObject + assigning + specifiersExports), m;
752
948
  }
753
949
 
950
+ // src/mocking-utils/extract.ts
951
+ import { readFileSync as readFileSync2 } from "node:fs";
952
+ import { generate, parser, types as t2 } from "storybook/internal/babel";
953
+ import { logger } from "storybook/internal/node-logger";
954
+ import { telemetry } from "storybook/internal/telemetry";
955
+ import { transformSync } from "esbuild";
956
+
957
+ // src/mocking-utils/resolve.ts
958
+ import { readFileSync, realpathSync } from "node:fs";
959
+ import { createRequire } from "node:module";
960
+
961
+ // ../node_modules/resolve.exports/dist/index.mjs
962
+ function e(e2, n3, r2) {
963
+ throw new Error(r2 ? `No known conditions for "${n3}" specifier in "${e2}" package` : `Missing "${n3}" specifier in "${e2}" package`);
964
+ }
965
+ function n2(n3, i, o2, f) {
966
+ let s, u, l = r(n3, o2), c = (function(e2) {
967
+ let n4 = /* @__PURE__ */ new Set(["default", ...e2.conditions || []]);
968
+ return e2.unsafe || n4.add(e2.require ? "require" : "import"), e2.unsafe || n4.add(e2.browser ? "browser" : "node"), n4;
969
+ })(f || {}), a = i[l];
970
+ if (a === void 0) {
971
+ let e2, n4, r2, t3;
972
+ for (t3 in i) n4 && t3.length < n4.length || (t3[t3.length - 1] === "/" && l.startsWith(t3) ? (u = l.substring(t3.length), n4 = t3) : t3.length > 1 && (r2 = t3.indexOf("*", 1), ~r2 && (e2 = RegExp("^" + t3.substring(0, r2) + "(.*)" + t3.substring(1 + r2) + "$").exec(l), e2 && e2[1] && (u = e2[1], n4 = t3))));
973
+ a = i[n4];
974
+ }
975
+ return a || e(n3, l), s = t(a, c), s || e(n3, l, 1), u && (function(e2, n4) {
976
+ let r2, t3 = 0, i2 = e2.length, o3 = /[*]/g, f2 = /[/]$/;
977
+ for (; t3 < i2; t3++) e2[t3] = o3.test(r2 = e2[t3]) ? r2.replace(o3, n4) : f2.test(r2) ? r2 + n4 : r2;
978
+ })(s, u), s;
979
+ }
980
+ function r(e2, n3, r2) {
981
+ if (e2 === n3 || n3 === ".") return ".";
982
+ let t3 = e2 + "/", i = t3.length, o2 = n3.slice(0, i) === t3, f = o2 ? n3.slice(i) : n3;
983
+ return f[0] === "#" ? f : o2 || !r2 ? f.slice(0, 2) === "./" ? f : "./" + f : f;
984
+ }
985
+ function t(e2, n3, r2) {
986
+ if (e2) {
987
+ if (typeof e2 == "string") return r2 && r2.add(e2), [e2];
988
+ let i, o2;
989
+ if (Array.isArray(e2)) {
990
+ for (o2 = r2 || /* @__PURE__ */ new Set(), i = 0; i < e2.length; i++) t(e2[i], n3, o2);
991
+ if (!r2 && o2.size) return [...o2];
992
+ } else for (i in e2) if (n3.has(i)) return t(e2[i], n3, r2);
993
+ }
994
+ }
995
+ function o(e2, r2, t3) {
996
+ let i, o2 = e2.exports;
997
+ if (o2) {
998
+ if (typeof o2 == "string") o2 = { ".": o2 };
999
+ else for (i in o2) {
1000
+ i[0] !== "." && (o2 = { ".": o2 });
1001
+ break;
1002
+ }
1003
+ return n2(e2.name, o2, r2 || ".", t3);
1004
+ }
1005
+ }
1006
+
1007
+ // src/mocking-utils/resolve.ts
1008
+ var require2 = createRequire(import.meta.url);
1009
+ function findPackageJson(specifier, basedir) {
1010
+ let packageJsonPath = require2.resolve(`${specifier}/package.json`, { paths: [basedir] });
1011
+ return {
1012
+ path: packageJsonPath,
1013
+ data: JSON.parse(readFileSync(packageJsonPath, "utf-8"))
1014
+ };
1015
+ }
1016
+ function resolveExternalModule(path, root) {
1017
+ let parts = path.split("/"), packageName = path.startsWith("@") ? `${parts[0]}/${parts[1]}` : parts[0], entry = `.${path.slice(packageName.length)}`, { path: packageJsonPath, data: pkg } = findPackageJson(packageName, root), packageDir = dirname(packageJsonPath);
1018
+ if (pkg.exports) {
1019
+ let result = o(pkg, entry, {
1020
+ browser: !0
1021
+ });
1022
+ if (result)
1023
+ return join(packageDir, result[0]);
1024
+ }
1025
+ return require2.resolve(path, { paths: [root] });
1026
+ }
1027
+ function getIsExternal(path, importer) {
1028
+ try {
1029
+ return !isAbsolute(path) && isModuleDirectory(require2.resolve(path, { paths: [importer] }));
1030
+ } catch {
1031
+ return !1;
1032
+ }
1033
+ }
1034
+ function resolveMock(path, root, importer, findMockRedirect) {
1035
+ let isExternal2 = getIsExternal(path, root), externalPath = isExternal2 ? path : null, absolutePath = isExternal2 ? resolveExternalModule(path, root) : require2.resolve(path, { paths: [dirname(importer)] }), normalizedAbsolutePath = resolve(absolutePath), redirectPath = findMockRedirect(root, normalizedAbsolutePath, externalPath);
1036
+ return {
1037
+ absolutePath: normalizedAbsolutePath,
1038
+ redirectPath
1039
+ // will be null if no __mocks__ file is found
1040
+ };
1041
+ }
1042
+ function isExternal(path, from) {
1043
+ try {
1044
+ return !isAbsolute(path) && isModuleDirectory(require2.resolve(path, { paths: [from] }));
1045
+ } catch {
1046
+ return !1;
1047
+ }
1048
+ }
1049
+ function getRealPath(path, preserveSymlinks) {
1050
+ try {
1051
+ return preserveSymlinks ? realpathSync(path) : path;
1052
+ } catch {
1053
+ return path;
1054
+ }
1055
+ }
1056
+ function resolveWithExtensions(path, from) {
1057
+ let extensions = [".js", ".ts", ".tsx", ".mjs", ".cjs", ".svelte", ".vue"];
1058
+ for (let extension of extensions)
1059
+ try {
1060
+ return require2.resolve(path + extension, { paths: [from] });
1061
+ } catch {
1062
+ continue;
1063
+ }
1064
+ return require2.resolve(path, { paths: [from] });
1065
+ }
1066
+
1067
+ // src/mocking-utils/extract.ts
1068
+ var DEFAULT_MODULE_DIRECTORIES = ["/node_modules/"];
1069
+ function isModuleDirectory(path) {
1070
+ let normalizedPath = normalize(path);
1071
+ return DEFAULT_MODULE_DIRECTORIES.some((dir) => normalizedPath.includes(dir));
1072
+ }
1073
+ var babelParser = (code) => parser.parse(code, {
1074
+ sourceType: "module",
1075
+ // Enable plugins to handle modern JavaScript features, including TSX.
1076
+ plugins: ["typescript", "jsx", "classProperties", "objectRestSpread"],
1077
+ errorRecovery: !0
1078
+ }).program;
1079
+ function rewriteSbMockImportCalls(code) {
1080
+ let ast = babelParser(code);
1081
+ return walk(ast, {
1082
+ enter(node) {
1083
+ node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "sb" && node.callee.property.type === "Identifier" && node.callee.property.name === "mock" && node.arguments.length > 0 && node.arguments[0].type === "CallExpression" && node.arguments[0].callee.type === "Import" && node.arguments[0].arguments.length === 1 && node.arguments[0].arguments[0].type === "StringLiteral" && (node.arguments[0] = t2.stringLiteral(node.arguments[0].arguments[0].value));
1084
+ }
1085
+ }), generate(ast, {}, code);
1086
+ }
1087
+ function extractMockCalls(options, parse, root, findMockRedirect) {
1088
+ try {
1089
+ let hasSpyTrue2 = function(objectExpression) {
1090
+ if (!objectExpression || !objectExpression.properties)
1091
+ return !1;
1092
+ for (let prop of objectExpression.properties)
1093
+ if (prop.type === "ObjectProperty" && (prop.key.type === "Identifier" && prop.key.name === "spy" || prop.key.type === "StringLiteral" && prop.key.value === "spy") && prop.value.type === "BooleanLiteral" && prop.value.value === !0)
1094
+ return !0;
1095
+ return !1;
1096
+ };
1097
+ var hasSpyTrue = hasSpyTrue2;
1098
+ let previewConfigCode = readFileSync2(options.previewConfigPath, "utf-8"), { code: jsCode } = transformSync(previewConfigCode, { loader: "tsx", format: "esm" }), ast = parse(jsCode), mocks = [];
1099
+ return walk(ast, {
1100
+ // @ts-expect-error - Node comes from babel
1101
+ async enter(node) {
1102
+ if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || node.callee.object.type !== "Identifier" || node.callee.object.name !== "sb" || node.callee.property.type !== "Identifier" || node.callee.property.name !== "mock" || node.arguments.length === 0)
1103
+ return;
1104
+ let path;
1105
+ if (node.arguments[0].type === "StringLiteral")
1106
+ path = node.arguments[0].value;
1107
+ else if (node.arguments[0].type === "CallExpression" && node.arguments[0].callee.type === "Import" && node.arguments[0].arguments[0].type === "StringLiteral")
1108
+ path = node.arguments[0].arguments[0].value;
1109
+ else
1110
+ return;
1111
+ let spy = node.arguments.length > 1 && node.arguments[1].type === "ObjectExpression" && hasSpyTrue2(node.arguments[1]), { absolutePath, redirectPath } = resolveMock(
1112
+ path,
1113
+ root,
1114
+ options.previewConfigPath,
1115
+ findMockRedirect
1116
+ ), pathWithoutExtension = path.replace(/\.[^/.]+$/, ""), basenameAbsolutePath = basename(absolutePath), basenamePath = basename(path), pathWithoutExtensionAndBasename = basenameAbsolutePath === basenamePath ? pathWithoutExtension : path;
1117
+ mocks.push({
1118
+ path: pathWithoutExtensionAndBasename,
1119
+ absolutePath,
1120
+ redirectPath,
1121
+ spy
1122
+ });
1123
+ }
1124
+ }), options.coreOptions?.disableTelemetry || telemetry(
1125
+ "mocking",
1126
+ {
1127
+ modulesMocked: mocks.length,
1128
+ modulesSpied: mocks.map((mock) => mock.spy).filter(Boolean).length,
1129
+ modulesManuallyMocked: mocks.map((mock) => !!mock.redirectPath).filter(Boolean).length
1130
+ },
1131
+ { configDir: options.configDir }
1132
+ ), mocks;
1133
+ } catch (error) {
1134
+ return logger.debug("Error extracting mock calls: " + String(error)), [];
1135
+ }
1136
+ }
1137
+
1138
+ // src/mocking-utils/runtime.ts
1139
+ import { resolvePackageDir } from "storybook/internal/common";
1140
+ import { buildSync } from "esbuild";
1141
+ var runtimeTemplatePath = join(
1142
+ resolvePackageDir("storybook"),
1143
+ "assets",
1144
+ "server",
1145
+ "mocker-runtime.template.js"
1146
+ );
1147
+ function getMockerRuntime() {
1148
+ return buildSync({
1149
+ entryPoints: [runtimeTemplatePath],
1150
+ bundle: !0,
1151
+ write: !1,
1152
+ // Return the result in memory instead of writing to disk
1153
+ format: "esm",
1154
+ target: "es2020",
1155
+ external: ["msw/browser", "msw/core/http"]
1156
+ }).outputFiles[0].text;
1157
+ }
754
1158
  export {
755
- getAutomockCode
1159
+ __STORYBOOK_GLOBAL_THIS_ACCESSOR__,
1160
+ automockModule,
1161
+ babelParser,
1162
+ esmWalker,
1163
+ extractMockCalls,
1164
+ getArbitraryModuleIdentifier,
1165
+ getAutomockCode,
1166
+ getIsExternal,
1167
+ getMockerRuntime,
1168
+ getRealPath,
1169
+ isExternal,
1170
+ isFunctionNode,
1171
+ isInDestructuringAssignment,
1172
+ isModuleDirectory,
1173
+ isNodeInPattern,
1174
+ isStaticProperty,
1175
+ isStaticPropertyKey,
1176
+ resolveExternalModule,
1177
+ resolveMock,
1178
+ resolveWithExtensions,
1179
+ rewriteSbMockImportCalls,
1180
+ setIsNodeInPattern
756
1181
  };