storybook 10.1.0-alpha.9 → 10.1.0-beta.0

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 (198) hide show
  1. package/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
  2. package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
  3. package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
  4. package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-2XZMBGTA.js} +44 -109
  5. package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
  6. package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
  7. package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
  8. package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
  9. package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
  10. package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
  11. package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
  12. package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
  13. package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
  14. package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
  15. package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
  16. package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
  17. package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
  18. package/dist/_browser-chunks/chunk-FQ7SLVLR.js +66 -0
  19. package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
  20. package/dist/_browser-chunks/chunk-GFY5R5EY.js +47 -0
  21. package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
  22. package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
  23. package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
  24. package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
  25. package/dist/_browser-chunks/{chunk-OWPZQM2D.js → chunk-L4RMQ7D7.js} +60 -110
  26. package/dist/_browser-chunks/chunk-P4F4UVXX.js +951 -0
  27. package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
  28. package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
  29. package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
  30. package/dist/_browser-chunks/chunk-SS2NHR7W.js +2969 -0
  31. package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
  32. package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
  33. package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
  34. package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
  35. package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
  36. package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
  37. package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
  38. package/dist/_browser-chunks/{syntaxhighlighter-CAVLW7PM.js → syntaxhighlighter-IQDEPFLK.js} +704 -1848
  39. package/dist/_node-chunks/{builder-manager-SM3UWERX.js → builder-manager-BDAQHXFI.js} +510 -1019
  40. package/dist/_node-chunks/camelcase-3C7DZZPX.js +37 -0
  41. package/dist/_node-chunks/chunk-2IIQTGNE.js +6024 -0
  42. package/dist/_node-chunks/chunk-56U5LEMP.js +3043 -0
  43. package/dist/_node-chunks/chunk-7LIRCAQE.js +20 -0
  44. package/dist/_node-chunks/chunk-7RN6TXKP.js +603 -0
  45. package/dist/_node-chunks/chunk-7SJ7PZNL.js +4523 -0
  46. package/dist/_node-chunks/{chunk-HHSTA6QS.js → chunk-BG4RDXG7.js} +8 -10
  47. package/dist/_node-chunks/chunk-CBQKMXLQ.js +18 -0
  48. package/dist/_node-chunks/chunk-CN2IW2KQ.js +1564 -0
  49. package/dist/_node-chunks/chunk-CQMAU6UQ.js +943 -0
  50. package/dist/_node-chunks/{chunk-EBUEXRH5.js → chunk-D6ND3TVY.js} +116 -276
  51. package/dist/_node-chunks/chunk-DC355CYB.js +61 -0
  52. package/dist/_node-chunks/{chunk-SGM3ZCCT.js → chunk-EVK2SBW5.js} +292 -688
  53. package/dist/_node-chunks/chunk-IXWEUXJ2.js +119 -0
  54. package/dist/_node-chunks/{chunk-F6EFOEC7.js → chunk-KVRF22SH.js} +469 -983
  55. package/dist/_node-chunks/chunk-LEDP4QQW.js +919 -0
  56. package/dist/_node-chunks/{chunk-GHIBZRKD.js → chunk-MMVV6DGG.js} +8133 -8887
  57. package/dist/_node-chunks/chunk-O5CGEVRI.js +29 -0
  58. package/dist/_node-chunks/chunk-OZZO56XN.js +299 -0
  59. package/dist/_node-chunks/chunk-POT2EVGD.js +78 -0
  60. package/dist/_node-chunks/chunk-R5YGFSTV.js +3781 -0
  61. package/dist/_node-chunks/chunk-SQCTM2OS.js +23 -0
  62. package/dist/_node-chunks/chunk-UFOFO5H7.js +54 -0
  63. package/dist/_node-chunks/chunk-VBF7ALJF.js +72 -0
  64. package/dist/_node-chunks/chunk-W6MAMTUF.js +70 -0
  65. package/dist/_node-chunks/chunk-WURL4XOT.js +46662 -0
  66. package/dist/_node-chunks/chunk-XGK6MVKR.js +61 -0
  67. package/dist/_node-chunks/chunk-YV3GDSDT.js +765 -0
  68. package/dist/_node-chunks/{chunk-ATDHMMIZ.js → chunk-YWV55YW3.js} +15 -24
  69. package/dist/_node-chunks/dist-KEP4IFRN.js +121 -0
  70. package/dist/_node-chunks/globby-4WUBTDCN.js +3452 -0
  71. package/dist/_node-chunks/lib-JVOEKTYM.js +366 -0
  72. package/dist/_node-chunks/mdx-N42X6CFJ-C5WFYYXR.js +14329 -0
  73. package/dist/_node-chunks/p-limit-LDY632RS.js +116 -0
  74. package/dist/actions/decorator.js +21 -42
  75. package/dist/actions/index.js +3 -3
  76. package/dist/babel/index.d.ts +671 -335
  77. package/dist/babel/index.js +10 -11
  78. package/dist/bin/core.js +601 -1548
  79. package/dist/bin/dispatcher.js +36 -36
  80. package/dist/bin/loader.js +24 -38
  81. package/dist/channels/index.js +98 -234
  82. package/dist/cli/index.d.ts +1479 -133
  83. package/dist/cli/index.js +30 -8540
  84. package/dist/client-logger/index.js +31 -61
  85. package/dist/common/index.d.ts +139 -62
  86. package/dist/common/index.js +66 -51
  87. package/dist/components/index.d.ts +575 -273
  88. package/dist/components/index.js +14863 -4313
  89. package/dist/core-events/index.js +2 -66
  90. package/dist/core-server/index.d.ts +3 -2
  91. package/dist/core-server/index.js +2908 -8518
  92. package/dist/core-server/presets/common-manager.css +2 -2
  93. package/dist/core-server/presets/common-manager.js +2521 -5233
  94. package/dist/core-server/presets/common-override-preset.js +31 -60
  95. package/dist/core-server/presets/common-preset.js +663 -962
  96. package/dist/csf/index.js +534 -1179
  97. package/dist/csf-tools/index.js +9 -9
  98. package/dist/docs-tools/index.js +6 -6
  99. package/dist/highlight/index.js +2 -2
  100. package/dist/instrumenter/index.js +199 -415
  101. package/dist/manager/globals-runtime.js +59044 -67141
  102. package/dist/manager/globals.js +2 -3
  103. package/dist/manager/manager-stores.d.ts +1 -0
  104. package/dist/manager/manager-stores.js +23 -0
  105. package/dist/manager/runtime.js +11511 -10953
  106. package/dist/manager-api/index.d.ts +1811 -2
  107. package/dist/manager-api/index.js +1348 -2401
  108. package/dist/manager-errors.d.ts +9 -0
  109. package/dist/manager-errors.js +3 -3
  110. package/dist/mocking-utils/index.d.ts +1126 -0
  111. package/dist/mocking-utils/index.js +1181 -0
  112. package/dist/node-logger/index.d.ts +192 -24
  113. package/dist/node-logger/index.js +23 -4471
  114. package/dist/preview/globals.js +2 -3
  115. package/dist/preview/runtime.js +10799 -22393
  116. package/dist/preview-api/index.d.ts +68 -69
  117. package/dist/preview-api/index.js +13 -13
  118. package/dist/preview-errors.d.ts +9 -0
  119. package/dist/preview-errors.js +4 -4
  120. package/dist/router/index.js +347 -899
  121. package/dist/server-errors.d.ts +34 -1
  122. package/dist/server-errors.js +17 -10
  123. package/dist/telemetry/index.d.ts +24 -3
  124. package/dist/telemetry/index.js +25 -24
  125. package/dist/test/index.js +6131 -11916
  126. package/dist/theming/create.d.ts +1 -0
  127. package/dist/theming/create.js +4 -4
  128. package/dist/theming/index.d.ts +3366 -2599
  129. package/dist/theming/index.js +501 -1091
  130. package/dist/types/index.d.ts +72 -8
  131. package/dist/types/index.js +27 -12
  132. package/dist/viewport/index.js +3 -3
  133. package/package.json +26 -17
  134. package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
  135. package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
  136. package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
  137. package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
  138. package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
  139. package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
  140. package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
  141. package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
  142. package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
  143. package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
  144. package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
  145. package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
  146. package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
  147. package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
  148. package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
  149. package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
  150. package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
  151. package/dist/_browser-chunks/chunk-RW5PKMWM.js +0 -4182
  152. package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
  153. package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
  154. package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
  155. package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
  156. package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
  157. package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
  158. package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
  159. package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
  160. package/dist/_node-chunks/camelcase-H5QSGQLK.js +0 -18
  161. package/dist/_node-chunks/chunk-3THWHQOC.js +0 -61
  162. package/dist/_node-chunks/chunk-45YUOLTU.js +0 -69
  163. package/dist/_node-chunks/chunk-4QSNCPAU.js +0 -64656
  164. package/dist/_node-chunks/chunk-744PQSOU.js +0 -79
  165. package/dist/_node-chunks/chunk-74Z2U7QG.js +0 -1544
  166. package/dist/_node-chunks/chunk-7MB7TFPO.js +0 -1198
  167. package/dist/_node-chunks/chunk-A7GS4RFT.js +0 -697
  168. package/dist/_node-chunks/chunk-BIA3A5UM.js +0 -61
  169. package/dist/_node-chunks/chunk-C5G7CLWX.js +0 -1657
  170. package/dist/_node-chunks/chunk-DLFUKMYJ.js +0 -1531
  171. package/dist/_node-chunks/chunk-EMRGRXKT.js +0 -111
  172. package/dist/_node-chunks/chunk-EX46EHHY.js +0 -420
  173. package/dist/_node-chunks/chunk-F76QKNOJ.js +0 -304
  174. package/dist/_node-chunks/chunk-HDCRUTEF.js +0 -220
  175. package/dist/_node-chunks/chunk-HUYAOIPH.js +0 -90
  176. package/dist/_node-chunks/chunk-IBJZQZJC.js +0 -101
  177. package/dist/_node-chunks/chunk-KZN2RDDT.js +0 -6712
  178. package/dist/_node-chunks/chunk-LYUNFU3F.js +0 -4741
  179. package/dist/_node-chunks/chunk-N44SIS6K.js +0 -28
  180. package/dist/_node-chunks/chunk-NILZM6KR.js +0 -18
  181. package/dist/_node-chunks/chunk-PC4ZRP6W.js +0 -34
  182. package/dist/_node-chunks/chunk-TJNGOQUH.js +0 -4272
  183. package/dist/_node-chunks/chunk-UBSYLHIL.js +0 -1250
  184. package/dist/_node-chunks/chunk-UTCLXPOC.js +0 -1518
  185. package/dist/_node-chunks/chunk-WOXXODXP.js +0 -5029
  186. package/dist/_node-chunks/chunk-XC4MEUA6.js +0 -1586
  187. package/dist/_node-chunks/chunk-YRXXMKRR.js +0 -2256
  188. package/dist/_node-chunks/dist-SL73W244.js +0 -175
  189. package/dist/_node-chunks/globby-ZSHAUQZ5.js +0 -5222
  190. package/dist/_node-chunks/lib-U2VIPUTI.js +0 -518
  191. package/dist/_node-chunks/mdx-N42X6CFJ-ZLHD33JK.js +0 -22017
  192. package/dist/_node-chunks/p-limit-K5BS5MSV.js +0 -168
  193. package/dist/_node-chunks/plugin-5PD4YIUH.js +0 -129
  194. package/dist/_node-chunks/plugin-MONDT2WL.js +0 -159
  195. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-EUZJRG3W.js +0 -69102
  196. package/dist/_node-chunks/webpack-mock-plugin-T4LDXEHE.js +0 -124
  197. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -36
  198. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -33
@@ -0,0 +1,919 @@
1
+ import CJS_COMPAT_NODE_URL_hjmvusgt1gv from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_hjmvusgt1gv from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_hjmvusgt1gv from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_hjmvusgt1gv.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_hjmvusgt1gv.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_hjmvusgt1gv.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ version
14
+ } from "./chunk-CBQKMXLQ.js";
15
+ import {
16
+ createFileSystemCache,
17
+ execa,
18
+ execaCommand,
19
+ getProjectRoot,
20
+ resolvePathInStorybookCache,
21
+ up
22
+ } from "./chunk-MMVV6DGG.js";
23
+ import {
24
+ getSessionId,
25
+ nanoid,
26
+ set
27
+ } from "./chunk-VBF7ALJF.js";
28
+ import {
29
+ globalSettings
30
+ } from "./chunk-56U5LEMP.js";
31
+ import {
32
+ resolvePackageDir
33
+ } from "./chunk-YV3GDSDT.js";
34
+ import {
35
+ slash
36
+ } from "./chunk-7LIRCAQE.js";
37
+ import {
38
+ require_dist
39
+ } from "./chunk-XGK6MVKR.js";
40
+ import {
41
+ __commonJS,
42
+ __toESM
43
+ } from "./chunk-UFOFO5H7.js";
44
+
45
+ // ../node_modules/fetch-retry/index.js
46
+ var require_fetch_retry = __commonJS({
47
+ "../node_modules/fetch-retry/index.js"(exports, module) {
48
+ "use strict";
49
+ module.exports = function(fetch2, defaults) {
50
+ if (defaults = defaults || {}, typeof fetch2 != "function")
51
+ throw new ArgumentError("fetch must be a function");
52
+ if (typeof defaults != "object")
53
+ throw new ArgumentError("defaults must be an object");
54
+ if (defaults.retries !== void 0 && !isPositiveInteger(defaults.retries))
55
+ throw new ArgumentError("retries must be a positive integer");
56
+ if (defaults.retryDelay !== void 0 && !isPositiveInteger(defaults.retryDelay) && typeof defaults.retryDelay != "function")
57
+ throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
58
+ if (defaults.retryOn !== void 0 && !Array.isArray(defaults.retryOn) && typeof defaults.retryOn != "function")
59
+ throw new ArgumentError("retryOn property expects an array or function");
60
+ var baseDefaults = {
61
+ retries: 3,
62
+ retryDelay: 1e3,
63
+ retryOn: []
64
+ };
65
+ return defaults = Object.assign(baseDefaults, defaults), function(input, init) {
66
+ var retries = defaults.retries, retryDelay = defaults.retryDelay, retryOn = defaults.retryOn;
67
+ if (init && init.retries !== void 0)
68
+ if (isPositiveInteger(init.retries))
69
+ retries = init.retries;
70
+ else
71
+ throw new ArgumentError("retries must be a positive integer");
72
+ if (init && init.retryDelay !== void 0)
73
+ if (isPositiveInteger(init.retryDelay) || typeof init.retryDelay == "function")
74
+ retryDelay = init.retryDelay;
75
+ else
76
+ throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
77
+ if (init && init.retryOn)
78
+ if (Array.isArray(init.retryOn) || typeof init.retryOn == "function")
79
+ retryOn = init.retryOn;
80
+ else
81
+ throw new ArgumentError("retryOn property expects an array or function");
82
+ return new Promise(function(resolve, reject) {
83
+ var wrappedFetch = function(attempt) {
84
+ var _input = typeof Request < "u" && input instanceof Request ? input.clone() : input;
85
+ fetch2(_input, init).then(function(response) {
86
+ if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1)
87
+ resolve(response);
88
+ else if (typeof retryOn == "function")
89
+ try {
90
+ return Promise.resolve(retryOn(attempt, null, response)).then(function(retryOnResponse) {
91
+ retryOnResponse ? retry2(attempt, null, response) : resolve(response);
92
+ }).catch(reject);
93
+ } catch (error) {
94
+ reject(error);
95
+ }
96
+ else
97
+ attempt < retries ? retry2(attempt, null, response) : resolve(response);
98
+ }).catch(function(error) {
99
+ if (typeof retryOn == "function")
100
+ try {
101
+ Promise.resolve(retryOn(attempt, error, null)).then(function(retryOnResponse) {
102
+ retryOnResponse ? retry2(attempt, error, null) : reject(error);
103
+ }).catch(function(error2) {
104
+ reject(error2);
105
+ });
106
+ } catch (error2) {
107
+ reject(error2);
108
+ }
109
+ else attempt < retries ? retry2(attempt, error, null) : reject(error);
110
+ });
111
+ };
112
+ function retry2(attempt, error, response) {
113
+ var delay = typeof retryDelay == "function" ? retryDelay(attempt, error, response) : retryDelay;
114
+ setTimeout(function() {
115
+ wrappedFetch(++attempt);
116
+ }, delay);
117
+ }
118
+ wrappedFetch(0);
119
+ });
120
+ };
121
+ };
122
+ function isPositiveInteger(value) {
123
+ return Number.isInteger(value) && value >= 0;
124
+ }
125
+ function ArgumentError(message) {
126
+ this.name = "ArgumentError", this.message = message;
127
+ }
128
+ }
129
+ });
130
+
131
+ // src/telemetry/index.ts
132
+ import { logger as logger2 } from "storybook/internal/node-logger";
133
+
134
+ // src/telemetry/notify.ts
135
+ var import_ts_dedent = __toESM(require_dist(), 1);
136
+ import { cache } from "storybook/internal/common";
137
+ import { logger } from "storybook/internal/node-logger";
138
+ var TELEMETRY_KEY_NOTIFY_DATE = "telemetry-notification-date", called = !1, notify = async () => {
139
+ called || (called = !0, await cache.get(TELEMETRY_KEY_NOTIFY_DATE, null) || (cache.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now()), logger.info(
140
+ import_ts_dedent.dedent`
141
+ Attention: Storybook collects completely anonymous telemetry regarding usage. This information is used to shape Storybook's roadmap and prioritize features. You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
142
+ https://storybook.js.org/telemetry
143
+ `
144
+ )));
145
+ };
146
+
147
+ // src/telemetry/sanitize.ts
148
+ import path from "node:path";
149
+ function regexpEscape(str) {
150
+ return str.replace(/[-[/{}()*+?.\\^$|]/g, "\\$&");
151
+ }
152
+ function removeAnsiEscapeCodes(input = "") {
153
+ return input.replace(/\u001B\[[0-9;]*m/g, "");
154
+ }
155
+ function cleanPaths(str, separator = path.sep) {
156
+ if (!str)
157
+ return str;
158
+ let stack = process.cwd().split(separator);
159
+ for (; stack.length > 1; ) {
160
+ let currentPath = stack.join(separator), currentRegex = new RegExp(regexpEscape(currentPath), "gi");
161
+ str = str.replace(currentRegex, "$SNIP");
162
+ let currentPath2 = stack.join(separator + separator), currentRegex2 = new RegExp(regexpEscape(currentPath2), "gi");
163
+ str = str.replace(currentRegex2, "$SNIP"), stack.pop();
164
+ }
165
+ return str;
166
+ }
167
+ function sanitizeError(error, pathSeparator = path.sep) {
168
+ try {
169
+ error = {
170
+ ...JSON.parse(JSON.stringify(error)),
171
+ message: removeAnsiEscapeCodes(error.message),
172
+ stack: removeAnsiEscapeCodes(error.stack),
173
+ cause: error.cause,
174
+ name: error.name
175
+ };
176
+ let errorString = cleanPaths(JSON.stringify(error), pathSeparator);
177
+ return JSON.parse(errorString);
178
+ } catch (err) {
179
+ return `Sanitization error: ${err?.message}`;
180
+ }
181
+ }
182
+
183
+ // src/telemetry/storybook-metadata.ts
184
+ import { readFile } from "node:fs/promises";
185
+ import { dirname } from "node:path";
186
+ import {
187
+ getStorybookConfiguration,
188
+ getStorybookInfo as getStorybookInfo2,
189
+ isCI,
190
+ loadMainConfig,
191
+ versions
192
+ } from "storybook/internal/common";
193
+ import { readConfig } from "storybook/internal/csf-tools";
194
+
195
+ // src/telemetry/get-application-file-count.ts
196
+ import { sep } from "node:path";
197
+
198
+ // src/telemetry/exec-command-count-lines.ts
199
+ import { createInterface } from "node:readline";
200
+ async function execCommandCountLines(command, args, options) {
201
+ let process3 = execa(command, args, { buffer: !1, ...options });
202
+ if (!process3.stdout)
203
+ throw new Error("Unexpected missing stdout");
204
+ let lineCount = 0, rl = createInterface(process3.stdout);
205
+ return rl.on("line", () => {
206
+ lineCount += 1;
207
+ }), await process3, rl.close(), lineCount;
208
+ }
209
+
210
+ // src/telemetry/run-telemetry-operation.ts
211
+ var cache2 = createFileSystemCache({
212
+ basePath: resolvePathInStorybookCache("telemetry"),
213
+ ns: "storybook",
214
+ ttl: 1440 * 60 * 1e3
215
+ // 24h
216
+ }), runTelemetryOperation = async (cacheKey, operation) => {
217
+ let cached = await cache2.get(cacheKey);
218
+ return cached === void 0 && (cached = await operation(), cached !== void 0 && await cache2.set(cacheKey, cached)), cached;
219
+ };
220
+
221
+ // src/telemetry/get-application-file-count.ts
222
+ var nameMatches = ["page", "screen"], extensions = ["js", "jsx", "ts", "tsx"], getApplicationFilesCountUncached = async (basePath) => {
223
+ let globs = nameMatches.flatMap((match) => [
224
+ match,
225
+ [match[0].toUpperCase(), ...match.slice(1)].join("")
226
+ ]).flatMap(
227
+ (match) => extensions.map((extension) => `${basePath}${sep}*${match}*.${extension}`)
228
+ );
229
+ try {
230
+ return await execCommandCountLines("git", ["ls-files", "--", ...globs]);
231
+ } catch {
232
+ return;
233
+ }
234
+ }, getApplicationFileCount = async (path3) => runTelemetryOperation(
235
+ "applicationFiles",
236
+ async () => getApplicationFilesCountUncached(path3)
237
+ );
238
+
239
+ // src/telemetry/get-chromatic-version.ts
240
+ function getChromaticVersionSpecifier(packageJson) {
241
+ let dependency = packageJson.dependencies?.chromatic || packageJson.devDependencies?.chromatic || packageJson.peerDependencies?.chromatic;
242
+ return dependency || (packageJson.scripts && Object.values(packageJson.scripts).find((s) => s?.match(/chromatic/)) ? "latest" : void 0);
243
+ }
244
+
245
+ // src/telemetry/get-framework-info.ts
246
+ import { getStorybookInfo } from "storybook/internal/common";
247
+ var cleanAndSanitizePath = (path3) => cleanPaths(path3).replace(/.*node_modules[\\/]/, "");
248
+ async function getFrameworkInfo(mainConfig, configDir) {
249
+ let { frameworkPackage, rendererPackage, builderPackage } = await getStorybookInfo(configDir), frameworkOptions = typeof mainConfig.framework == "object" ? mainConfig.framework.options : {};
250
+ return {
251
+ framework: {
252
+ name: frameworkPackage ? cleanAndSanitizePath(frameworkPackage) : void 0,
253
+ options: frameworkOptions
254
+ },
255
+ builder: builderPackage ? cleanAndSanitizePath(builderPackage) : void 0,
256
+ renderer: rendererPackage ? cleanAndSanitizePath(rendererPackage) : void 0
257
+ };
258
+ }
259
+
260
+ // src/telemetry/get-has-router-package.ts
261
+ var routerPackages = /* @__PURE__ */ new Set([
262
+ "react-router",
263
+ "react-router-dom",
264
+ "remix",
265
+ "@tanstack/react-router",
266
+ "expo-router",
267
+ "@reach/router",
268
+ "react-easy-router",
269
+ "@remix-run/router",
270
+ "wouter",
271
+ "wouter-preact",
272
+ "preact-router",
273
+ "vue-router",
274
+ "unplugin-vue-router",
275
+ "@angular/router",
276
+ "@solidjs/router",
277
+ // metaframeworks that imply routing
278
+ "next",
279
+ "react-scripts",
280
+ "gatsby",
281
+ "nuxt",
282
+ "@sveltejs/kit"
283
+ ]);
284
+ function getHasRouterPackage(packageJson) {
285
+ return Object.keys(packageJson?.dependencies ?? {}).some(
286
+ (depName) => routerPackages.has(depName)
287
+ );
288
+ }
289
+
290
+ // src/telemetry/get-monorepo-type.ts
291
+ import { existsSync, readFileSync } from "node:fs";
292
+ import { join } from "node:path";
293
+ import { getProjectRoot as getProjectRoot2 } from "storybook/internal/common";
294
+ var monorepoConfigs = {
295
+ Nx: "nx.json",
296
+ Turborepo: "turbo.json",
297
+ Lerna: "lerna.json",
298
+ Rush: "rush.json",
299
+ Lage: "lage.config.json"
300
+ }, getMonorepoType = () => {
301
+ let monorepoType = Object.keys(monorepoConfigs).find((monorepo) => {
302
+ let configFile = join(getProjectRoot2(), monorepoConfigs[monorepo]);
303
+ return existsSync(configFile);
304
+ });
305
+ if (monorepoType)
306
+ return monorepoType;
307
+ if (!existsSync(join(getProjectRoot2(), "package.json")))
308
+ return;
309
+ if (JSON.parse(
310
+ readFileSync(join(getProjectRoot2(), "package.json"), { encoding: "utf8" })
311
+ )?.workspaces)
312
+ return "Workspaces";
313
+ };
314
+
315
+ // ../node_modules/package-manager-detector/dist/commands.mjs
316
+ function dashDashArg(agent, agentCommand) {
317
+ return (args) => args.length > 1 ? [agent, agentCommand, args[0], "--", ...args.slice(1)] : [agent, agentCommand, args[0]];
318
+ }
319
+ function denoExecute() {
320
+ return (args) => ["deno", "run", `npm:${args[0]}`, ...args.slice(1)];
321
+ }
322
+ var npm = {
323
+ agent: ["npm", 0],
324
+ run: dashDashArg("npm", "run"),
325
+ install: ["npm", "i", 0],
326
+ frozen: ["npm", "ci", 0],
327
+ global: ["npm", "i", "-g", 0],
328
+ add: ["npm", "i", 0],
329
+ upgrade: ["npm", "update", 0],
330
+ "upgrade-interactive": null,
331
+ dedupe: ["npm", "dedupe", 0],
332
+ execute: ["npx", 0],
333
+ "execute-local": ["npx", 0],
334
+ uninstall: ["npm", "uninstall", 0],
335
+ global_uninstall: ["npm", "uninstall", "-g", 0]
336
+ }, yarn = {
337
+ agent: ["yarn", 0],
338
+ run: ["yarn", "run", 0],
339
+ install: ["yarn", "install", 0],
340
+ frozen: ["yarn", "install", "--frozen-lockfile", 0],
341
+ global: ["yarn", "global", "add", 0],
342
+ add: ["yarn", "add", 0],
343
+ upgrade: ["yarn", "upgrade", 0],
344
+ "upgrade-interactive": ["yarn", "upgrade-interactive", 0],
345
+ dedupe: null,
346
+ execute: ["npx", 0],
347
+ "execute-local": dashDashArg("yarn", "exec"),
348
+ uninstall: ["yarn", "remove", 0],
349
+ global_uninstall: ["yarn", "global", "remove", 0]
350
+ }, yarnBerry = {
351
+ ...yarn,
352
+ frozen: ["yarn", "install", "--immutable", 0],
353
+ upgrade: ["yarn", "up", 0],
354
+ "upgrade-interactive": ["yarn", "up", "-i", 0],
355
+ dedupe: ["yarn", "dedupe", 0],
356
+ execute: ["yarn", "dlx", 0],
357
+ "execute-local": ["yarn", "exec", 0],
358
+ // Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
359
+ global: ["npm", "i", "-g", 0],
360
+ global_uninstall: ["npm", "uninstall", "-g", 0]
361
+ }, pnpm = {
362
+ agent: ["pnpm", 0],
363
+ run: ["pnpm", "run", 0],
364
+ install: ["pnpm", "i", 0],
365
+ frozen: ["pnpm", "i", "--frozen-lockfile", 0],
366
+ global: ["pnpm", "add", "-g", 0],
367
+ add: ["pnpm", "add", 0],
368
+ upgrade: ["pnpm", "update", 0],
369
+ "upgrade-interactive": ["pnpm", "update", "-i", 0],
370
+ dedupe: ["pnpm", "dedupe", 0],
371
+ execute: ["pnpm", "dlx", 0],
372
+ "execute-local": ["pnpm", "exec", 0],
373
+ uninstall: ["pnpm", "remove", 0],
374
+ global_uninstall: ["pnpm", "remove", "--global", 0]
375
+ }, bun = {
376
+ agent: ["bun", 0],
377
+ run: ["bun", "run", 0],
378
+ install: ["bun", "install", 0],
379
+ frozen: ["bun", "install", "--frozen-lockfile", 0],
380
+ global: ["bun", "add", "-g", 0],
381
+ add: ["bun", "add", 0],
382
+ upgrade: ["bun", "update", 0],
383
+ "upgrade-interactive": ["bun", "update", "-i", 0],
384
+ dedupe: null,
385
+ execute: ["bun", "x", 0],
386
+ "execute-local": ["bun", "x", 0],
387
+ uninstall: ["bun", "remove", 0],
388
+ global_uninstall: ["bun", "remove", "-g", 0]
389
+ }, deno = {
390
+ agent: ["deno", 0],
391
+ run: ["deno", "task", 0],
392
+ install: ["deno", "install", 0],
393
+ frozen: ["deno", "install", "--frozen", 0],
394
+ global: ["deno", "install", "-g", 0],
395
+ add: ["deno", "add", 0],
396
+ upgrade: ["deno", "outdated", "--update", 0],
397
+ "upgrade-interactive": ["deno", "outdated", "--update", 0],
398
+ dedupe: null,
399
+ execute: denoExecute(),
400
+ "execute-local": ["deno", "task", "--eval", 0],
401
+ uninstall: ["deno", "remove", 0],
402
+ global_uninstall: ["deno", "uninstall", "-g", 0]
403
+ }, COMMANDS = {
404
+ npm,
405
+ yarn,
406
+ "yarn@berry": yarnBerry,
407
+ pnpm,
408
+ // pnpm v6.x or below
409
+ "pnpm@6": {
410
+ ...pnpm,
411
+ run: dashDashArg("pnpm", "run")
412
+ },
413
+ bun,
414
+ deno
415
+ };
416
+
417
+ // ../node_modules/package-manager-detector/dist/constants.mjs
418
+ var AGENTS = [
419
+ "npm",
420
+ "yarn",
421
+ "yarn@berry",
422
+ "pnpm",
423
+ "pnpm@6",
424
+ "bun",
425
+ "deno"
426
+ ], LOCKS = {
427
+ "bun.lock": "bun",
428
+ "bun.lockb": "bun",
429
+ "deno.lock": "deno",
430
+ "pnpm-lock.yaml": "pnpm",
431
+ "pnpm-workspace.yaml": "pnpm",
432
+ "yarn.lock": "yarn",
433
+ "package-lock.json": "npm",
434
+ "npm-shrinkwrap.json": "npm"
435
+ }, INSTALL_METADATA = {
436
+ "node_modules/.deno/": "deno",
437
+ "node_modules/.pnpm/": "pnpm",
438
+ "node_modules/.yarn-state.yml": "yarn",
439
+ // yarn v2+ (node-modules)
440
+ "node_modules/.yarn_integrity": "yarn",
441
+ // yarn v1
442
+ "node_modules/.package-lock.json": "npm",
443
+ ".pnp.cjs": "yarn",
444
+ // yarn v3+ (pnp)
445
+ ".pnp.js": "yarn",
446
+ // yarn v2 (pnp)
447
+ "bun.lock": "bun",
448
+ "bun.lockb": "bun"
449
+ };
450
+
451
+ // ../node_modules/package-manager-detector/dist/detect.mjs
452
+ import fs from "node:fs/promises";
453
+ import path2 from "node:path";
454
+ import process2 from "node:process";
455
+ async function pathExists(path22, type) {
456
+ try {
457
+ let stat = await fs.stat(path22);
458
+ return type === "file" ? stat.isFile() : stat.isDirectory();
459
+ } catch {
460
+ return !1;
461
+ }
462
+ }
463
+ function* lookup(cwd = process2.cwd()) {
464
+ let directory = path2.resolve(cwd), { root } = path2.parse(directory);
465
+ for (; directory && directory !== root; )
466
+ yield directory, directory = path2.dirname(directory);
467
+ }
468
+ async function parsePackageJson(filepath, onUnknown) {
469
+ return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
470
+ }
471
+ async function detect(options = {}) {
472
+ let {
473
+ cwd,
474
+ strategies = ["lockfile", "packageManager-field", "devEngines-field"],
475
+ onUnknown
476
+ } = options, stopDir;
477
+ if (typeof options.stopDir == "string") {
478
+ let resolved = path2.resolve(options.stopDir);
479
+ stopDir = (dir) => dir === resolved;
480
+ } else
481
+ stopDir = options.stopDir;
482
+ for (let directory of lookup(cwd)) {
483
+ for (let strategy of strategies)
484
+ switch (strategy) {
485
+ case "lockfile": {
486
+ for (let lock of Object.keys(LOCKS))
487
+ if (await pathExists(path2.join(directory, lock), "file")) {
488
+ let name = LOCKS[lock], result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
489
+ return result || { name, agent: name };
490
+ }
491
+ break;
492
+ }
493
+ case "packageManager-field":
494
+ case "devEngines-field": {
495
+ let result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
496
+ if (result)
497
+ return result;
498
+ break;
499
+ }
500
+ case "install-metadata": {
501
+ for (let metadata of Object.keys(INSTALL_METADATA)) {
502
+ let fileOrDir = metadata.endsWith("/") ? "dir" : "file";
503
+ if (await pathExists(path2.join(directory, metadata), fileOrDir)) {
504
+ let name = INSTALL_METADATA[metadata], agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
505
+ return { name, agent };
506
+ }
507
+ }
508
+ break;
509
+ }
510
+ }
511
+ if (stopDir?.(directory))
512
+ break;
513
+ }
514
+ return null;
515
+ }
516
+ function getNameAndVer(pkg) {
517
+ let handelVer = (version2) => version2?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version2;
518
+ if (typeof pkg.packageManager == "string") {
519
+ let [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
520
+ return { name, ver: handelVer(ver) };
521
+ }
522
+ if (typeof pkg.devEngines?.packageManager?.name == "string")
523
+ return {
524
+ name: pkg.devEngines.packageManager.name,
525
+ ver: handelVer(pkg.devEngines.packageManager.version)
526
+ };
527
+ }
528
+ async function handlePackageManager(filepath, onUnknown) {
529
+ try {
530
+ let pkg = JSON.parse(await fs.readFile(filepath, "utf8")), agent, nameAndVer = getNameAndVer(pkg);
531
+ if (nameAndVer) {
532
+ let name = nameAndVer.name, ver = nameAndVer.ver, version2 = ver;
533
+ return name === "yarn" && ver && Number.parseInt(ver) > 1 ? (agent = "yarn@berry", version2 = "berry", { name, agent, version: version2 }) : name === "pnpm" && ver && Number.parseInt(ver) < 7 ? (agent = "pnpm@6", { name, agent, version: version2 }) : AGENTS.includes(name) ? (agent = name, { name, agent, version: version2 }) : onUnknown?.(pkg.packageManager) ?? null;
534
+ }
535
+ } catch {
536
+ }
537
+ return null;
538
+ }
539
+ function isMetadataYarnClassic(metadataPath) {
540
+ return metadataPath.endsWith(".yarn_integrity");
541
+ }
542
+
543
+ // src/telemetry/get-package-manager-info.ts
544
+ var getPackageManagerInfo = async () => {
545
+ let packageManagerType = await detect({ cwd: getProjectRoot() });
546
+ if (!packageManagerType)
547
+ return;
548
+ let nodeLinker = "node_modules";
549
+ if (packageManagerType.name === "yarn")
550
+ try {
551
+ let { stdout } = await execaCommand("yarn config get nodeLinker", {
552
+ cwd: getProjectRoot()
553
+ });
554
+ nodeLinker = stdout.trim();
555
+ } catch {
556
+ }
557
+ if (packageManagerType.name === "pnpm")
558
+ try {
559
+ let { stdout } = await execaCommand("pnpm config get nodeLinker", {
560
+ cwd: getProjectRoot()
561
+ });
562
+ nodeLinker = stdout.trim() ?? "isolated";
563
+ } catch {
564
+ }
565
+ return {
566
+ type: packageManagerType.name,
567
+ version: packageManagerType.version,
568
+ agent: packageManagerType.agent,
569
+ nodeLinker
570
+ };
571
+ };
572
+
573
+ // src/telemetry/get-portable-stories-usage.ts
574
+ var getPortableStoriesFileCountUncached = async (path3) => {
575
+ try {
576
+ return await execCommandCountLines("git", [
577
+ "grep",
578
+ "-l",
579
+ "composeStor",
580
+ ...path3 ? ["--", path3] : []
581
+ ]);
582
+ } catch (err) {
583
+ return err.exitCode === 1 ? 0 : void 0;
584
+ }
585
+ }, getPortableStoriesFileCount = async (path3) => runTelemetryOperation(
586
+ "portableStories",
587
+ async () => getPortableStoriesFileCountUncached(path3)
588
+ );
589
+
590
+ // src/telemetry/package-json.ts
591
+ import { fileURLToPath, pathToFileURL } from "node:url";
592
+ var getActualPackageVersions = async (packages) => {
593
+ let packageNames = Object.keys(packages);
594
+ return Promise.all(packageNames.map(getActualPackageVersion));
595
+ }, getActualPackageVersion = async (packageName) => {
596
+ try {
597
+ let packageJson = await getActualPackageJson(packageName);
598
+ return {
599
+ name: packageJson?.name || packageName,
600
+ version: packageJson?.version || null
601
+ };
602
+ } catch {
603
+ return {
604
+ name: packageName,
605
+ version: null
606
+ };
607
+ }
608
+ }, getActualPackageJson = async (packageName) => {
609
+ try {
610
+ let resolvedPackageJsonPath = up({
611
+ cwd: fileURLToPath(import.meta.resolve(packageName, process.cwd()))
612
+ });
613
+ resolvedPackageJsonPath || (resolvedPackageJsonPath = import.meta.resolve(`${packageName}/package.json`, process.cwd()));
614
+ let { default: packageJson } = await import(pathToFileURL(resolvedPackageJsonPath).href, {
615
+ with: { type: "json" }
616
+ });
617
+ return packageJson;
618
+ } catch {
619
+ return;
620
+ }
621
+ };
622
+
623
+ // src/telemetry/storybook-metadata.ts
624
+ var metaFrameworks = {
625
+ next: "Next",
626
+ "react-scripts": "CRA",
627
+ gatsby: "Gatsby",
628
+ "@nuxtjs/storybook": "nuxt",
629
+ "@nrwl/storybook": "nx",
630
+ "@vue/cli-service": "vue-cli",
631
+ "@sveltejs/kit": "sveltekit",
632
+ "@tanstack/react-router": "tanstack-react",
633
+ "@react-router/dev": "react-router",
634
+ "@remix-run/dev": "remix"
635
+ }, sanitizeAddonName = (name) => cleanPaths(name).replace(/\/dist\/.*/, "").replace(/\.[mc]?[tj]?s[x]?$/, "").replace(/\/register$/, "").replace(/\/manager$/, "").replace(/\/preset$/, ""), computeStorybookMetadata = async ({
636
+ packageJsonPath,
637
+ packageJson,
638
+ mainConfig,
639
+ configDir
640
+ }) => {
641
+ let settings = isCI() ? void 0 : await globalSettings(), metadata = {
642
+ generatedAt: (/* @__PURE__ */ new Date()).getTime(),
643
+ userSince: settings?.value.userSince,
644
+ hasCustomBabel: !1,
645
+ hasCustomWebpack: !1,
646
+ hasStaticDirs: !1,
647
+ hasStorybookEslint: !1,
648
+ refCount: 0
649
+ }, allDependencies = {
650
+ ...packageJson?.dependencies,
651
+ ...packageJson?.devDependencies,
652
+ ...packageJson?.peerDependencies
653
+ }, metaFramework = Object.keys(allDependencies).find((dep) => !!metaFrameworks[dep]);
654
+ if (metaFramework) {
655
+ let { version: version2 } = await getActualPackageVersion(metaFramework);
656
+ metadata.metaFramework = {
657
+ name: metaFrameworks[metaFramework],
658
+ packageName: metaFramework,
659
+ version: version2 || "unknown"
660
+ };
661
+ }
662
+ let testPackages = [
663
+ "playwright",
664
+ "vitest",
665
+ "jest",
666
+ "cypress",
667
+ "nightwatch",
668
+ "webdriver",
669
+ "@web/test-runner",
670
+ "puppeteer",
671
+ "karma",
672
+ "jasmine",
673
+ "chai",
674
+ "testing-library",
675
+ "@ngneat/spectator",
676
+ "wdio",
677
+ "msw",
678
+ "miragejs",
679
+ "sinon",
680
+ "chromatic"
681
+ ], testPackageDeps = Object.keys(allDependencies).filter(
682
+ (dep) => testPackages.find((pkg) => dep.includes(pkg))
683
+ );
684
+ metadata.testPackages = Object.fromEntries(
685
+ await Promise.all(
686
+ testPackageDeps.map(async (dep) => [dep, (await getActualPackageVersion(dep))?.version])
687
+ )
688
+ ), metadata.hasRouterPackage = getHasRouterPackage(packageJson);
689
+ let monorepoType = getMonorepoType();
690
+ monorepoType && (metadata.monorepo = monorepoType), metadata.packageManager = await getPackageManagerInfo();
691
+ let language = allDependencies.typescript ? "typescript" : "javascript";
692
+ if (!mainConfig)
693
+ return {
694
+ ...metadata,
695
+ storybookVersionSpecifier: versions.storybook,
696
+ language
697
+ };
698
+ metadata.hasCustomBabel = !!mainConfig.babel, metadata.hasCustomWebpack = !!mainConfig.webpackFinal, metadata.hasStaticDirs = !!mainConfig.staticDirs, typeof mainConfig.typescript == "object" && (metadata.typescriptOptions = mainConfig.typescript);
699
+ let frameworkInfo = await getFrameworkInfo(mainConfig, configDir);
700
+ typeof mainConfig.refs == "object" && (metadata.refCount = Object.keys(mainConfig.refs).length), typeof mainConfig.features == "object" && (metadata.features = mainConfig.features);
701
+ let addons = {};
702
+ mainConfig.addons && mainConfig.addons.forEach((addon) => {
703
+ let addonName, options;
704
+ typeof addon == "string" ? addonName = sanitizeAddonName(addon) : (addon.name.includes("addon-essentials") && (options = addon.options), addonName = sanitizeAddonName(addon.name)), addons[addonName] = {
705
+ options,
706
+ version: void 0
707
+ };
708
+ });
709
+ let chromaticVersionSpecifier = getChromaticVersionSpecifier(packageJson);
710
+ chromaticVersionSpecifier && (addons.chromatic = {
711
+ version: void 0,
712
+ versionSpecifier: chromaticVersionSpecifier,
713
+ options: void 0
714
+ }), (await getActualPackageVersions(addons)).forEach(({ name, version: version2 }) => {
715
+ addons[name] = addons[name] || {
716
+ name,
717
+ version: version2
718
+ }, addons[name].version = version2 || void 0;
719
+ });
720
+ let addonNames = Object.keys(addons), storybookPackages = Object.keys(allDependencies).filter((dep) => dep.includes("storybook") && !addonNames.includes(dep)).reduce((acc, dep) => ({
721
+ ...acc,
722
+ [dep]: { version: void 0 }
723
+ }), {});
724
+ (await getActualPackageVersions(storybookPackages)).forEach(({ name, version: version2 }) => {
725
+ storybookPackages[name] = storybookPackages[name] || {
726
+ name,
727
+ version: version2
728
+ }, storybookPackages[name].version = version2 || void 0;
729
+ });
730
+ let hasStorybookEslint = !!allDependencies["eslint-plugin-storybook"], storybookInfo = await getStorybookInfo2(configDir);
731
+ try {
732
+ let { previewConfigPath: previewConfig } = storybookInfo;
733
+ if (previewConfig) {
734
+ let config = await readConfig(previewConfig), usesGlobals = !!(config.getFieldNode(["globals"]) || config.getFieldNode(["globalTypes"]));
735
+ metadata.preview = { ...metadata.preview, usesGlobals };
736
+ }
737
+ } catch {
738
+ }
739
+ let portableStoriesFileCount = await getPortableStoriesFileCount(), applicationFileCount = await getApplicationFileCount(dirname(packageJsonPath));
740
+ return {
741
+ ...metadata,
742
+ ...frameworkInfo,
743
+ portableStoriesFileCount,
744
+ applicationFileCount,
745
+ storybookVersion: version,
746
+ storybookVersionSpecifier: storybookInfo.version ?? "",
747
+ language,
748
+ storybookPackages,
749
+ addons,
750
+ hasStorybookEslint
751
+ };
752
+ };
753
+ async function getPackageJsonDetails() {
754
+ let packageJsonPath = up();
755
+ return packageJsonPath ? {
756
+ packageJsonPath,
757
+ packageJson: JSON.parse(await readFile(packageJsonPath, "utf8"))
758
+ } : {
759
+ packageJsonPath: process.cwd(),
760
+ packageJson: {}
761
+ };
762
+ }
763
+ var cachedMetadata, getStorybookMetadata = async (_configDir) => {
764
+ if (cachedMetadata)
765
+ return cachedMetadata;
766
+ let { packageJson, packageJsonPath } = await getPackageJsonDetails(), configDir = (_configDir || getStorybookConfiguration(
767
+ String(packageJson?.scripts?.storybook || ""),
768
+ "-c",
769
+ "--config-dir"
770
+ )) ?? ".storybook", mainConfig = await loadMainConfig({ configDir }).catch(() => {
771
+ });
772
+ return cachedMetadata = await computeStorybookMetadata({
773
+ mainConfig,
774
+ packageJson,
775
+ packageJsonPath,
776
+ configDir
777
+ }), cachedMetadata;
778
+ };
779
+
780
+ // src/telemetry/telemetry.ts
781
+ var import_fetch_retry = __toESM(require_fetch_retry(), 1);
782
+ import { readFileSync as readFileSync2 } from "node:fs";
783
+ import * as os from "node:os";
784
+ import { join as join2 } from "node:path";
785
+ import { isCI as isCI2 } from "storybook/internal/common";
786
+
787
+ // src/telemetry/anonymous-id.ts
788
+ import { relative } from "node:path";
789
+ import { getProjectRoot as getProjectRoot3 } from "storybook/internal/common";
790
+ import { execSync } from "child_process";
791
+
792
+ // src/telemetry/one-way-hash.ts
793
+ import { createHash } from "crypto";
794
+ var oneWayHash = (payload) => {
795
+ let hash = createHash("sha256");
796
+ return hash.update("storybook-telemetry-salt"), hash.update(payload), hash.digest("hex");
797
+ };
798
+
799
+ // src/telemetry/anonymous-id.ts
800
+ function normalizeGitUrl(rawUrl) {
801
+ let urlWithoutScheme = rawUrl.trim().replace(/#.*$/, "").replace(/^.*@/, "").replace(/^.*\/\//, "");
802
+ return (urlWithoutScheme.endsWith(".git") ? urlWithoutScheme : `${urlWithoutScheme}.git`).replace(":", "/");
803
+ }
804
+ function unhashedProjectId(remoteUrl, projectRootPath) {
805
+ return `${normalizeGitUrl(remoteUrl)}${slash(projectRootPath)}`;
806
+ }
807
+ var anonymousProjectId, getAnonymousProjectId = () => {
808
+ if (anonymousProjectId)
809
+ return anonymousProjectId;
810
+ try {
811
+ let projectRootPath = relative(getProjectRoot3(), process.cwd()), originBuffer = execSync("git config --local --get remote.origin.url", {
812
+ timeout: 1e3,
813
+ stdio: "pipe"
814
+ });
815
+ anonymousProjectId = oneWayHash(unhashedProjectId(String(originBuffer), projectRootPath));
816
+ } catch {
817
+ }
818
+ return anonymousProjectId;
819
+ };
820
+
821
+ // src/telemetry/fetch.ts
822
+ var fetch = global.fetch;
823
+
824
+ // src/telemetry/telemetry.ts
825
+ var retryingFetch = (0, import_fetch_retry.default)(fetch), URL = process.env.STORYBOOK_TELEMETRY_URL || "https://storybook.js.org/event-log", tasks = [], addToGlobalContext = (key, value) => {
826
+ globalContext[key] = value;
827
+ }, getOperatingSystem = () => {
828
+ try {
829
+ let platform2 = os.platform();
830
+ return platform2 === "win32" ? "Windows" : platform2 === "darwin" ? "macOS" : platform2 === "linux" ? "Linux" : `Other: ${platform2}`;
831
+ } catch {
832
+ return "Unknown";
833
+ }
834
+ }, globalContext = {
835
+ inCI: isCI2(),
836
+ isTTY: process.stdout.isTTY,
837
+ platform: getOperatingSystem(),
838
+ nodeVersion: process.versions.node,
839
+ storybookVersion: getVersionNumber()
840
+ }, prepareRequest = async (data, context, options) => {
841
+ let { eventType, payload, metadata, ...rest } = data, sessionId = await getSessionId(), eventId = nanoid(), body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
842
+ return retryingFetch(URL, {
843
+ method: "post",
844
+ body: JSON.stringify(body),
845
+ headers: { "Content-Type": "application/json" },
846
+ retries: 3,
847
+ retryOn: [503, 504],
848
+ retryDelay: (attempt) => 2 ** attempt * (typeof options?.retryDelay == "number" && !Number.isNaN(options?.retryDelay) ? options.retryDelay : 1e3)
849
+ });
850
+ };
851
+ function getVersionNumber() {
852
+ try {
853
+ return JSON.parse(readFileSync2(join2(resolvePackageDir("storybook"), "package.json"), "utf8")).version;
854
+ } catch {
855
+ return version;
856
+ }
857
+ }
858
+ async function sendTelemetry(data, options = { retryDelay: 1e3, immediate: !1 }) {
859
+ let { eventType, payload, metadata, ...rest } = data, context = options.stripMetadata ? globalContext : {
860
+ ...globalContext,
861
+ anonymousId: getAnonymousProjectId()
862
+ }, request;
863
+ try {
864
+ request = prepareRequest(data, context, options), tasks.push(request);
865
+ let sessionId = await getSessionId(), eventId = nanoid(), body = { ...rest, eventType, eventId, sessionId, metadata, payload, context }, waitFor = options.immediate ? tasks : [request];
866
+ await Promise.all([...waitFor, set(eventType, body)]);
867
+ } catch {
868
+ } finally {
869
+ tasks = tasks.filter((task) => task !== request);
870
+ }
871
+ }
872
+
873
+ // src/telemetry/error-collector.ts
874
+ var ErrorCollector = class _ErrorCollector {
875
+ constructor() {
876
+ this.errors = [];
877
+ }
878
+ static getInstance() {
879
+ return _ErrorCollector.instance || (_ErrorCollector.instance = new _ErrorCollector()), _ErrorCollector.instance;
880
+ }
881
+ static addError(error) {
882
+ this.getInstance().errors.push(error);
883
+ }
884
+ static getErrors() {
885
+ return this.getInstance().errors;
886
+ }
887
+ };
888
+
889
+ // src/telemetry/index.ts
890
+ var isExampleStoryId = (storyId) => storyId.startsWith("example-button--") || storyId.startsWith("example-header--") || storyId.startsWith("example-page--"), telemetry = async (eventType, payload = {}, options = {}) => {
891
+ eventType !== "boot" && options.notify !== !1 && await notify();
892
+ let telemetryData = {
893
+ eventType,
894
+ payload
895
+ };
896
+ try {
897
+ options?.stripMetadata || (telemetryData.metadata = await getStorybookMetadata(options?.configDir));
898
+ } catch (error) {
899
+ payload.metadataErrorMessage = sanitizeError(error).message, options?.enableCrashReports && (payload.metadataError = sanitizeError(error));
900
+ } finally {
901
+ let { error } = payload;
902
+ error && (payload.error = sanitizeError(error)), (!payload.error || options?.enableCrashReports) && (process.env?.STORYBOOK_TELEMETRY_DEBUG && (logger2.info("[telemetry]"), logger2.info(JSON.stringify(telemetryData, null, 2))), await sendTelemetry(telemetryData, options));
903
+ }
904
+ };
905
+
906
+ export {
907
+ removeAnsiEscapeCodes,
908
+ cleanPaths,
909
+ sanitizeError,
910
+ metaFrameworks,
911
+ sanitizeAddonName,
912
+ computeStorybookMetadata,
913
+ getStorybookMetadata,
914
+ oneWayHash,
915
+ addToGlobalContext,
916
+ ErrorCollector,
917
+ isExampleStoryId,
918
+ telemetry
919
+ };