storybook 10.1.0-alpha.11 → 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 (88) 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-PMPHOSM2.js → builder-manager-DWDUVXZM.js} +27 -22
  5. package/dist/_node-chunks/{chunk-MJ3WOS6F.js → camelcase-EETCRTJX.js} +8 -8
  6. package/dist/_node-chunks/{chunk-UY26MQLT.js → chunk-2W4GZCLE.js} +7 -7
  7. package/dist/_node-chunks/chunk-447655DM.js +20 -0
  8. package/dist/_node-chunks/{chunk-GG2WQZSG.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-5QK5MSOI.js → chunk-7IAVT2FU.js} +7 -7
  12. package/dist/_node-chunks/{chunk-WLHMN7AP.js → chunk-7KFHRNOT.js} +7 -7
  13. package/dist/_node-chunks/{chunk-6ZOLETQK.js → chunk-AZIPBEBK.js} +6 -6
  14. package/dist/_node-chunks/{chunk-AKTRSR3O.js → chunk-B76FDKVB.js} +6 -6
  15. package/dist/_node-chunks/chunk-B7PGKETD.js +3781 -0
  16. package/dist/_node-chunks/{chunk-QECOQWRJ.js → chunk-CLUBH2LP.js} +55 -36
  17. package/dist/_node-chunks/{chunk-PHOZWZZO.js → chunk-CMYD2JNN.js} +7 -7
  18. package/dist/_node-chunks/{chunk-LR3QITDI.js → chunk-DIPKXLEP.js} +55 -32
  19. package/dist/_node-chunks/{chunk-4GZCFQFG.js → chunk-DPFYWXEA.js} +6 -6
  20. package/dist/_node-chunks/{chunk-LCZO45L7.js → chunk-FCVNHU2F.js} +7 -7
  21. package/dist/_node-chunks/{chunk-R6HWGZWD.js → chunk-JQ7RQS5Q.js} +6 -6
  22. package/dist/_node-chunks/chunk-LEL5OSY3.js +18 -0
  23. package/dist/_node-chunks/{chunk-BBOP3XCK.js → chunk-LPKSBF62.js} +6 -6
  24. package/dist/_node-chunks/chunk-LYEZOJ43.js +78 -0
  25. package/dist/_node-chunks/{chunk-ZZALGOA6.js → chunk-MIA5324I.js} +7 -7
  26. package/dist/_node-chunks/{chunk-SPQXMU2Q.js → chunk-MJM4TEMP.js} +14 -8
  27. package/dist/_node-chunks/{chunk-32NE3UE3.js → chunk-OVVZIUHS.js} +7 -7
  28. package/dist/_node-chunks/{chunk-ZZSRFAC6.js → chunk-RUUNVQ6W.js} +1108 -17
  29. package/dist/_node-chunks/{chunk-YHRFI6BE.js → chunk-URLNGLC2.js} +52 -72
  30. package/dist/_node-chunks/{chunk-XGVLB4UJ.js → chunk-WC2YEQHJ.js} +6 -6
  31. package/dist/_node-chunks/{chunk-JCRM2YVK.js → chunk-XKRVQL2G.js} +8 -8
  32. package/dist/_node-chunks/{chunk-TXZY6V6O.js → chunk-Z2OWEMX3.js} +8 -8
  33. package/dist/_node-chunks/{dist-4DWOCZUD.js → dist-22CLJ4BC.js} +9 -9
  34. package/dist/_node-chunks/{globby-AAARUKEU.js → globby-GR24TGSK.js} +9 -9
  35. package/dist/_node-chunks/{lib-HEUKGL62.js → lib-G2LGVRPC.js} +7 -7
  36. package/dist/_node-chunks/{mdx-N42X6CFJ-DCVRPS6N.js → mdx-N42X6CFJ-W6P6IDDW.js} +8 -8
  37. package/dist/_node-chunks/{p-limit-F5ZKJ6WZ.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-UGDPX5LE.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-K3IOOFQW.js +0 -18
  73. package/dist/_node-chunks/chunk-7I22Y76Z.js +0 -1047
  74. package/dist/_node-chunks/chunk-C2GQVDWI.js +0 -34
  75. package/dist/_node-chunks/chunk-GQJOWVVR.js +0 -3214
  76. package/dist/_node-chunks/chunk-KK4AT5F3.js +0 -1029
  77. package/dist/_node-chunks/chunk-L7MYXJUM.js +0 -1114
  78. package/dist/_node-chunks/chunk-LXG4DK35.js +0 -3171
  79. package/dist/_node-chunks/chunk-QH4V5YDB.js +0 -20
  80. package/dist/_node-chunks/chunk-WK3EMYK6.js +0 -61
  81. package/dist/_node-chunks/chunk-YK4KVMFW.js +0 -18
  82. package/dist/_node-chunks/chunk-ZZPBSYA5.js +0 -301
  83. package/dist/_node-chunks/plugin-7YY7JXCH.js +0 -123
  84. package/dist/_node-chunks/plugin-SZP3CW6W.js +0 -109
  85. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-TGKNDPO6.js +0 -46623
  86. package/dist/_node-chunks/webpack-mock-plugin-LNTZZFBE.js +0 -92
  87. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -32
  88. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -28
@@ -1,20 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
- // ../node_modules/slash/index.js
14
- function slash(path) {
15
- return path.startsWith("\\\\?\\") ? path : path.replace(/\\/g, "/");
16
- }
17
-
18
- export {
19
- slash
20
- };
@@ -1,61 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
- // src/common/versions.ts
14
- var versions_default = {
15
- "@storybook/addon-a11y": "10.1.0-alpha.11",
16
- "@storybook/addon-docs": "10.1.0-alpha.11",
17
- "@storybook/addon-links": "10.1.0-alpha.11",
18
- "@storybook/addon-onboarding": "10.1.0-alpha.11",
19
- "storybook-addon-pseudo-states": "10.1.0-alpha.11",
20
- "@storybook/addon-themes": "10.1.0-alpha.11",
21
- "@storybook/addon-vitest": "10.1.0-alpha.11",
22
- "@storybook/builder-vite": "10.1.0-alpha.11",
23
- "@storybook/builder-webpack5": "10.1.0-alpha.11",
24
- storybook: "10.1.0-alpha.11",
25
- "@storybook/angular": "10.1.0-alpha.11",
26
- "@storybook/ember": "10.1.0-alpha.11",
27
- "@storybook/html-vite": "10.1.0-alpha.11",
28
- "@storybook/nextjs": "10.1.0-alpha.11",
29
- "@storybook/nextjs-vite": "10.1.0-alpha.11",
30
- "@storybook/preact-vite": "10.1.0-alpha.11",
31
- "@storybook/react-native-web-vite": "10.1.0-alpha.11",
32
- "@storybook/react-vite": "10.1.0-alpha.11",
33
- "@storybook/react-webpack5": "10.1.0-alpha.11",
34
- "@storybook/server-webpack5": "10.1.0-alpha.11",
35
- "@storybook/svelte-vite": "10.1.0-alpha.11",
36
- "@storybook/sveltekit": "10.1.0-alpha.11",
37
- "@storybook/vue3-vite": "10.1.0-alpha.11",
38
- "@storybook/web-components-vite": "10.1.0-alpha.11",
39
- sb: "10.1.0-alpha.11",
40
- "@storybook/cli": "10.1.0-alpha.11",
41
- "@storybook/codemod": "10.1.0-alpha.11",
42
- "@storybook/core-webpack": "10.1.0-alpha.11",
43
- "create-storybook": "10.1.0-alpha.11",
44
- "@storybook/csf-plugin": "10.1.0-alpha.11",
45
- "eslint-plugin-storybook": "10.1.0-alpha.11",
46
- "@storybook/react-dom-shim": "10.1.0-alpha.11",
47
- "@storybook/preset-create-react-app": "10.1.0-alpha.11",
48
- "@storybook/preset-react-webpack": "10.1.0-alpha.11",
49
- "@storybook/preset-server-webpack": "10.1.0-alpha.11",
50
- "@storybook/html": "10.1.0-alpha.11",
51
- "@storybook/preact": "10.1.0-alpha.11",
52
- "@storybook/react": "10.1.0-alpha.11",
53
- "@storybook/server": "10.1.0-alpha.11",
54
- "@storybook/svelte": "10.1.0-alpha.11",
55
- "@storybook/vue3": "10.1.0-alpha.11",
56
- "@storybook/web-components": "10.1.0-alpha.11"
57
- };
58
-
59
- export {
60
- versions_default
61
- };
@@ -1,18 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
- // package.json
14
- var version = "10.1.0-alpha.11";
15
-
16
- export {
17
- version
18
- };
@@ -1,301 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- import {
13
- basename,
14
- dirname,
15
- isAbsolute,
16
- join,
17
- normalize,
18
- resolve
19
- } from "./chunk-BBOP3XCK.js";
20
-
21
- // src/core-server/mocking-utils/resolve.ts
22
- import { readFileSync as readFileSync2, realpathSync } from "node:fs";
23
- import { createRequire } from "node:module";
24
- import { findMockRedirect } from "@vitest/mocker/redirect";
25
-
26
- // ../node_modules/resolve.exports/dist/index.mjs
27
- function e(e2, n2, r2) {
28
- throw new Error(r2 ? `No known conditions for "${n2}" specifier in "${e2}" package` : `Missing "${n2}" specifier in "${e2}" package`);
29
- }
30
- function n(n2, i, o2, f) {
31
- let s, u, l = r(n2, o2), c = (function(e2) {
32
- let n3 = /* @__PURE__ */ new Set(["default", ...e2.conditions || []]);
33
- return e2.unsafe || n3.add(e2.require ? "require" : "import"), e2.unsafe || n3.add(e2.browser ? "browser" : "node"), n3;
34
- })(f || {}), a = i[l];
35
- if (a === void 0) {
36
- let e2, n3, r2, t3;
37
- for (t3 in i) n3 && t3.length < n3.length || (t3[t3.length - 1] === "/" && l.startsWith(t3) ? (u = l.substring(t3.length), n3 = 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], n3 = t3))));
38
- a = i[n3];
39
- }
40
- return a || e(n2, l), s = t(a, c), s || e(n2, l, 1), u && (function(e2, n3) {
41
- let r2, t3 = 0, i2 = e2.length, o3 = /[*]/g, f2 = /[/]$/;
42
- for (; t3 < i2; t3++) e2[t3] = o3.test(r2 = e2[t3]) ? r2.replace(o3, n3) : f2.test(r2) ? r2 + n3 : r2;
43
- })(s, u), s;
44
- }
45
- function r(e2, n2, r2) {
46
- if (e2 === n2 || n2 === ".") return ".";
47
- let t3 = e2 + "/", i = t3.length, o2 = n2.slice(0, i) === t3, f = o2 ? n2.slice(i) : n2;
48
- return f[0] === "#" ? f : o2 || !r2 ? f.slice(0, 2) === "./" ? f : "./" + f : f;
49
- }
50
- function t(e2, n2, r2) {
51
- if (e2) {
52
- if (typeof e2 == "string") return r2 && r2.add(e2), [e2];
53
- let i, o2;
54
- if (Array.isArray(e2)) {
55
- for (o2 = r2 || /* @__PURE__ */ new Set(), i = 0; i < e2.length; i++) t(e2[i], n2, o2);
56
- if (!r2 && o2.size) return [...o2];
57
- } else for (i in e2) if (n2.has(i)) return t(e2[i], n2, r2);
58
- }
59
- }
60
- function o(e2, r2, t3) {
61
- let i, o2 = e2.exports;
62
- if (o2) {
63
- if (typeof o2 == "string") o2 = { ".": o2 };
64
- else for (i in o2) {
65
- i[0] !== "." && (o2 = { ".": o2 });
66
- break;
67
- }
68
- return n(e2.name, o2, r2 || ".", t3);
69
- }
70
- }
71
-
72
- // src/core-server/mocking-utils/extract.ts
73
- import { readFileSync } from "node:fs";
74
- import { generate, parser, types as t2 } from "storybook/internal/babel";
75
- import { logger } from "storybook/internal/node-logger";
76
- import { telemetry } from "storybook/internal/telemetry";
77
- import { transformSync } from "esbuild";
78
-
79
- // ../node_modules/estree-walker/src/walker.js
80
- var WalkerBase = class {
81
- constructor() {
82
- this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
83
- skip: () => this.should_skip = !0,
84
- remove: () => this.should_remove = !0,
85
- replace: (node) => this.replacement = node
86
- };
87
- }
88
- /**
89
- * @template {Node} Parent
90
- * @param {Parent | null | undefined} parent
91
- * @param {keyof Parent | null | undefined} prop
92
- * @param {number | null | undefined} index
93
- * @param {Node} node
94
- */
95
- replace(parent, prop, index, node) {
96
- parent && prop && (index != null ? parent[prop][index] = node : parent[prop] = node);
97
- }
98
- /**
99
- * @template {Node} Parent
100
- * @param {Parent | null | undefined} parent
101
- * @param {keyof Parent | null | undefined} prop
102
- * @param {number | null | undefined} index
103
- */
104
- remove(parent, prop, index) {
105
- parent && prop && (index != null ? parent[prop].splice(index, 1) : delete parent[prop]);
106
- }
107
- };
108
-
109
- // ../node_modules/estree-walker/src/sync.js
110
- var SyncWalker = class extends WalkerBase {
111
- /**
112
- *
113
- * @param {SyncHandler} [enter]
114
- * @param {SyncHandler} [leave]
115
- */
116
- constructor(enter, leave) {
117
- super(), this.should_skip = !1, this.should_remove = !1, this.replacement = null, this.context = {
118
- skip: () => this.should_skip = !0,
119
- remove: () => this.should_remove = !0,
120
- replace: (node) => this.replacement = node
121
- }, this.enter = enter, this.leave = leave;
122
- }
123
- /**
124
- * @template {Node} Parent
125
- * @param {Node} node
126
- * @param {Parent | null} parent
127
- * @param {keyof Parent} [prop]
128
- * @param {number | null} [index]
129
- * @returns {Node | null}
130
- */
131
- visit(node, parent, prop, index) {
132
- if (node) {
133
- if (this.enter) {
134
- let _should_skip = this.should_skip, _should_remove = this.should_remove, _replacement = this.replacement;
135
- 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);
136
- let skipped = this.should_skip, removed = this.should_remove;
137
- if (this.should_skip = _should_skip, this.should_remove = _should_remove, this.replacement = _replacement, skipped) return node;
138
- if (removed) return null;
139
- }
140
- let key;
141
- for (key in node) {
142
- let value = node[key];
143
- if (value && typeof value == "object")
144
- if (Array.isArray(value)) {
145
- let nodes = (
146
- /** @type {Array<unknown>} */
147
- value
148
- );
149
- for (let i = 0; i < nodes.length; i += 1) {
150
- let item = nodes[i];
151
- isNode(item) && (this.visit(item, node, key, i) || i--);
152
- }
153
- } else isNode(value) && this.visit(value, node, key, null);
154
- }
155
- if (this.leave) {
156
- let _replacement = this.replacement, _should_remove = this.should_remove;
157
- 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);
158
- let removed = this.should_remove;
159
- if (this.replacement = _replacement, this.should_remove = _should_remove, removed) return null;
160
- }
161
- }
162
- return node;
163
- }
164
- };
165
- function isNode(value) {
166
- return value !== null && typeof value == "object" && "type" in value && typeof value.type == "string";
167
- }
168
-
169
- // ../node_modules/estree-walker/src/index.js
170
- function walk(ast, { enter, leave }) {
171
- return new SyncWalker(enter, leave).visit(ast, null);
172
- }
173
-
174
- // src/core-server/mocking-utils/extract.ts
175
- var DEFAULT_MODULE_DIRECTORIES = ["/node_modules/"];
176
- function isModuleDirectory(path) {
177
- let normalizedPath = normalize(path);
178
- return DEFAULT_MODULE_DIRECTORIES.some((dir) => normalizedPath.includes(dir));
179
- }
180
- var babelParser = (code) => parser.parse(code, {
181
- sourceType: "module",
182
- // Enable plugins to handle modern JavaScript features, including TSX.
183
- plugins: ["typescript", "jsx", "classProperties", "objectRestSpread"],
184
- errorRecovery: !0
185
- }).program;
186
- function rewriteSbMockImportCalls(code) {
187
- let ast = babelParser(code);
188
- return walk(ast, {
189
- enter(node) {
190
- 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));
191
- }
192
- }), generate(ast, {}, code);
193
- }
194
- function extractMockCalls(options, parse, root) {
195
- try {
196
- let hasSpyTrue2 = function(objectExpression) {
197
- if (!objectExpression || !objectExpression.properties)
198
- return !1;
199
- for (let prop of objectExpression.properties)
200
- 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)
201
- return !0;
202
- return !1;
203
- };
204
- var hasSpyTrue = hasSpyTrue2;
205
- let previewConfigCode = readFileSync(options.previewConfigPath, "utf-8"), { code: jsCode } = transformSync(previewConfigCode, { loader: "tsx", format: "esm" }), ast = parse(jsCode), mocks = [];
206
- return walk(ast, {
207
- // @ts-expect-error - Node comes from babel
208
- async enter(node) {
209
- 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)
210
- return;
211
- let path;
212
- if (node.arguments[0].type === "StringLiteral")
213
- path = node.arguments[0].value;
214
- else if (node.arguments[0].type === "CallExpression" && node.arguments[0].callee.type === "Import" && node.arguments[0].arguments[0].type === "StringLiteral")
215
- path = node.arguments[0].arguments[0].value;
216
- else
217
- return;
218
- let spy = node.arguments.length > 1 && node.arguments[1].type === "ObjectExpression" && hasSpyTrue2(node.arguments[1]), { absolutePath, redirectPath } = resolveMock(path, root, options.previewConfigPath), pathWithoutExtension = path.replace(/\.[^/.]+$/, ""), basenameAbsolutePath = basename(absolutePath), basenamePath = basename(path), pathWithoutExtensionAndBasename = basenameAbsolutePath === basenamePath ? pathWithoutExtension : path;
219
- mocks.push({
220
- path: pathWithoutExtensionAndBasename,
221
- absolutePath,
222
- redirectPath,
223
- spy
224
- });
225
- }
226
- }), options.coreOptions?.disableTelemetry || telemetry(
227
- "mocking",
228
- {
229
- modulesMocked: mocks.length,
230
- modulesSpied: mocks.map((mock) => mock.spy).filter(Boolean).length,
231
- modulesManuallyMocked: mocks.map((mock) => !!mock.redirectPath).filter(Boolean).length
232
- },
233
- { configDir: options.configDir }
234
- ), mocks;
235
- } catch (error) {
236
- return logger.debug("Error extracting mock calls", error), [];
237
- }
238
- }
239
-
240
- // src/core-server/mocking-utils/resolve.ts
241
- var require2 = createRequire(import.meta.url);
242
- function findPackageJson(specifier, basedir) {
243
- let packageJsonPath = require2.resolve(`${specifier}/package.json`, { paths: [basedir] });
244
- return {
245
- path: packageJsonPath,
246
- data: JSON.parse(readFileSync2(packageJsonPath, "utf-8"))
247
- };
248
- }
249
- function resolveExternalModule(path, root) {
250
- 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);
251
- if (pkg.exports) {
252
- let result = o(pkg, entry, {
253
- browser: !0
254
- });
255
- if (result)
256
- return join(packageDir, result[0]);
257
- }
258
- return require2.resolve(path, { paths: [root] });
259
- }
260
- function getIsExternal(path, importer) {
261
- try {
262
- return !isAbsolute(path) && isModuleDirectory(require2.resolve(path, { paths: [importer] }));
263
- } catch {
264
- return !1;
265
- }
266
- }
267
- function resolveMock(path, root, importer) {
268
- let isExternal = getIsExternal(path, root), externalPath = isExternal ? path : null, absolutePath = isExternal ? resolveExternalModule(path, root) : require2.resolve(path, { paths: [dirname(importer)] }), normalizedAbsolutePath = resolve(absolutePath), redirectPath = findMockRedirect(root, normalizedAbsolutePath, externalPath);
269
- return {
270
- absolutePath: normalizedAbsolutePath,
271
- redirectPath
272
- // will be null if no __mocks__ file is found
273
- };
274
- }
275
- function getRealPath(path, preserveSymlinks) {
276
- try {
277
- return preserveSymlinks ? realpathSync(path) : path;
278
- } catch {
279
- return path;
280
- }
281
- }
282
- function resolveWithExtensions(path, from) {
283
- let extensions = [".js", ".ts", ".tsx", ".mjs", ".cjs", ".svelte", ".vue"];
284
- for (let extension of extensions)
285
- try {
286
- return require2.resolve(path + extension, { paths: [from] });
287
- } catch {
288
- continue;
289
- }
290
- return require2.resolve(path, { paths: [from] });
291
- }
292
-
293
- export {
294
- resolveExternalModule,
295
- getIsExternal,
296
- getRealPath,
297
- resolveWithExtensions,
298
- babelParser,
299
- rewriteSbMockImportCalls,
300
- extractMockCalls
301
- };
@@ -1,123 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- import {
13
- getAutomockCode
14
- } from "./chunk-UGDPX5LE.js";
15
- import {
16
- babelParser,
17
- extractMockCalls,
18
- getRealPath,
19
- rewriteSbMockImportCalls
20
- } from "./chunk-ZZPBSYA5.js";
21
- import {
22
- normalize
23
- } from "./chunk-BBOP3XCK.js";
24
- import "./chunk-XGVLB4UJ.js";
25
-
26
- // src/core-server/presets/vitePlugins/vite-mock/plugin.ts
27
- import { readFileSync } from "node:fs";
28
- import { logger } from "storybook/internal/node-logger";
29
-
30
- // src/core-server/presets/vitePlugins/vite-mock/utils.ts
31
- function getCleanId(id) {
32
- return id.replace(/^.*\/deps\//, "").replace(/\.js.*$/, "").replace(/_/g, "/");
33
- }
34
- function invalidateAllRelatedModules(server, absPath, pkgName) {
35
- for (let mod of server.moduleGraph.idToModuleMap.values())
36
- (mod.id === absPath || mod.id && getCleanId(mod.id) === pkgName) && server.moduleGraph.invalidateModule(mod);
37
- }
38
-
39
- // src/core-server/presets/vitePlugins/vite-mock/plugin.ts
40
- function viteMockPlugin(options) {
41
- let viteConfig, mockCalls = [], normalizedPreviewConfigPath = normalize(options.previewConfigPath);
42
- return [
43
- {
44
- name: "storybook:mock-loader",
45
- configResolved(config) {
46
- viteConfig = config;
47
- },
48
- buildStart() {
49
- mockCalls = extractMockCalls(options, babelParser, viteConfig.root);
50
- },
51
- configureServer(server) {
52
- async function invalidateAffectedFiles(file) {
53
- if (file === options.previewConfigPath || file.includes("__mocks__")) {
54
- let oldMockCalls = mockCalls;
55
- mockCalls = extractMockCalls(options, babelParser, viteConfig.root);
56
- let previewMod = server.moduleGraph.getModuleById(options.previewConfigPath);
57
- previewMod && server.moduleGraph.invalidateModule(previewMod);
58
- for (let call of mockCalls)
59
- invalidateAllRelatedModules(server, call.absolutePath, call.path);
60
- let newAbsPaths = new Set(mockCalls.map((c) => c.absolutePath));
61
- for (let oldCall of oldMockCalls)
62
- newAbsPaths.has(oldCall.absolutePath) || invalidateAllRelatedModules(server, oldCall.absolutePath, oldCall.path);
63
- return server.ws.send({ type: "full-reload" }), [];
64
- }
65
- }
66
- server.watcher.on("change", invalidateAffectedFiles), server.watcher.on("add", invalidateAffectedFiles), server.watcher.on("unlink", invalidateAffectedFiles);
67
- },
68
- load: {
69
- order: "pre",
70
- handler(id) {
71
- let preserveSymlinks = viteConfig.resolve.preserveSymlinks, idNorm = getRealPath(id, preserveSymlinks), cleanId = getCleanId(idNorm);
72
- for (let call of mockCalls)
73
- if (!(getRealPath(call.absolutePath, preserveSymlinks) !== idNorm && call.path !== cleanId) && call.redirectPath)
74
- return this.addWatchFile(call.redirectPath), readFileSync(call.redirectPath, "utf-8");
75
- return null;
76
- }
77
- },
78
- transform: {
79
- order: "pre",
80
- handler(code, id) {
81
- for (let call of mockCalls) {
82
- let preserveSymlinks = viteConfig.resolve.preserveSymlinks, idNorm = getRealPath(id, preserveSymlinks), callNorm = getRealPath(call.absolutePath, preserveSymlinks);
83
- if (viteConfig.command !== "serve") {
84
- if (callNorm !== idNorm)
85
- continue;
86
- } else {
87
- let cleanId = getCleanId(idNorm);
88
- if (call.path !== cleanId && callNorm !== idNorm)
89
- continue;
90
- }
91
- try {
92
- if (!call.redirectPath) {
93
- let automockedCode = getAutomockCode(code, call.spy, babelParser);
94
- return {
95
- code: automockedCode.toString(),
96
- map: automockedCode.generateMap()
97
- };
98
- }
99
- } catch (e) {
100
- return logger.error(`Error automocking ${id}: ${e}`), null;
101
- }
102
- }
103
- return null;
104
- }
105
- }
106
- },
107
- {
108
- name: "storybook:mock-loader-preview",
109
- transform(code, id) {
110
- if (id === normalizedPreviewConfigPath)
111
- try {
112
- return rewriteSbMockImportCalls(code);
113
- } catch (e) {
114
- return logger.debug(`Could not transform sb.mock(import(...)) calls in ${id}: ${e}`), null;
115
- }
116
- return null;
117
- }
118
- }
119
- ];
120
- }
121
- export {
122
- viteMockPlugin
123
- };
@@ -1,109 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- import {
13
- resolvePackageDir
14
- } from "./chunk-SPQXMU2Q.js";
15
- import "./chunk-BBOP3XCK.js";
16
- import {
17
- require_dist
18
- } from "./chunk-PHOZWZZO.js";
19
- import {
20
- __toESM
21
- } from "./chunk-XGVLB4UJ.js";
22
-
23
- // src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts
24
- import { readFileSync } from "node:fs";
25
- import { join } from "node:path";
26
- import { fileURLToPath } from "node:url";
27
-
28
- // ../node_modules/@rolldown/pluginutils/dist/index.js
29
- function exactRegex(str, flags) {
30
- return new RegExp(`^${escapeRegex(str)}$`, flags);
31
- }
32
- var escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
33
- function escapeRegex(str) {
34
- return str.replace(escapeRegexRE, "\\$&");
35
- }
36
-
37
- // src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts
38
- var import_ts_dedent = __toESM(require_dist(), 1);
39
- var entryPath = "/vite-inject-mocker-entry.js", entryCode = import_ts_dedent.dedent`
40
- <script type="module" src=".${entryPath}"></script>
41
- `, server, viteInjectMockerRuntime = (options) => {
42
- let viteConfig;
43
- return {
44
- name: "vite:storybook-inject-mocker-runtime",
45
- buildStart() {
46
- viteConfig.command === "build" && this.emitFile({
47
- type: "chunk",
48
- id: join(
49
- resolvePackageDir("storybook"),
50
- "assets",
51
- "server",
52
- "mocker-runtime.template.js"
53
- ),
54
- fileName: entryPath.slice(1)
55
- });
56
- },
57
- config() {
58
- return {
59
- optimizeDeps: {
60
- include: ["@vitest/mocker", "@vitest/mocker/browser"]
61
- },
62
- resolve: {
63
- // Aliasing necessary for package managers like pnpm, since resolving modules from a virtual module
64
- // leads to errors, if the imported module is not a dependency of the project.
65
- // By resolving the module to the real path, we can avoid this issue.
66
- alias: {
67
- "@vitest/mocker/browser": fileURLToPath(import.meta.resolve("@vitest/mocker/browser")),
68
- "@vitest/mocker": fileURLToPath(import.meta.resolve("@vitest/mocker"))
69
- }
70
- }
71
- };
72
- },
73
- configResolved(config) {
74
- viteConfig = config;
75
- },
76
- configureServer(server_) {
77
- server = server_, options.previewConfigPath && server.watcher.on("change", (file) => {
78
- file === options.previewConfigPath && server.ws.send({
79
- type: "custom",
80
- event: "invalidate-mocker"
81
- });
82
- });
83
- },
84
- resolveId: {
85
- filter: {
86
- id: [exactRegex(entryPath)]
87
- },
88
- handler(id) {
89
- return exactRegex(id).test(entryPath) ? id : null;
90
- }
91
- },
92
- async load(id) {
93
- return exactRegex(id).test(entryPath) ? readFileSync(
94
- join(resolvePackageDir("storybook"), "assets", "server", "mocker-runtime.template.js"),
95
- "utf-8"
96
- ) : null;
97
- },
98
- transformIndexHtml(html) {
99
- let headTag = html.match(/<head[^>]*>/);
100
- if (headTag) {
101
- let headTagIndex = html.indexOf(headTag[0]);
102
- return html.slice(0, headTagIndex + headTag[0].length) + entryCode + html.slice(headTagIndex + headTag[0].length);
103
- }
104
- }
105
- };
106
- };
107
- export {
108
- viteInjectMockerRuntime
109
- };