storybook 10.1.0-alpha.1 → 10.1.0-alpha.11

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 (202) 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-3IAH5M2U.js +171 -0
  5. package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
  6. package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
  7. package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
  8. package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
  9. package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-74YHFU5B.js} +44 -109
  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-BE2DAXKJ.js +2966 -0
  15. package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
  16. package/dist/_browser-chunks/chunk-EBHB6RPS.js +61 -0
  17. package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
  18. package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
  19. package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
  20. package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -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-L4RMQ7D7.js +223 -0
  26. package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
  27. package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
  28. package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
  29. package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
  30. package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
  31. package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
  32. package/dist/_browser-chunks/chunk-WXP2XJ3O.js +950 -0
  33. package/dist/_browser-chunks/chunk-X3DUQ5RA.js +47 -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-DK2ODWXH.js → syntaxhighlighter-WKBQ5RC7.js} +707 -1851
  39. package/dist/_node-chunks/{builder-manager-6UBDPV7P.js → builder-manager-PMPHOSM2.js} +495 -1013
  40. package/dist/_node-chunks/camelcase-K3IOOFQW.js +18 -0
  41. package/dist/_node-chunks/{chunk-QNUGJO6L.js → chunk-32NE3UE3.js} +15 -24
  42. package/dist/_node-chunks/chunk-4GZCFQFG.js +58 -0
  43. package/dist/_node-chunks/chunk-5QK5MSOI.js +943 -0
  44. package/dist/_node-chunks/{chunk-3FPF5Y2F.js → chunk-6ZOLETQK.js} +8 -10
  45. package/dist/_node-chunks/chunk-7I22Y76Z.js +1047 -0
  46. package/dist/_node-chunks/chunk-AKTRSR3O.js +72 -0
  47. package/dist/_node-chunks/chunk-BBOP3XCK.js +119 -0
  48. package/dist/_node-chunks/chunk-C2GQVDWI.js +34 -0
  49. package/dist/_node-chunks/{chunk-SCTKVDWR.js → chunk-GG2WQZSG.js} +4619 -7350
  50. package/dist/_node-chunks/chunk-GQJOWVVR.js +3214 -0
  51. package/dist/_node-chunks/chunk-JCRM2YVK.js +3009 -0
  52. package/dist/_node-chunks/chunk-KK4AT5F3.js +1029 -0
  53. package/dist/_node-chunks/chunk-L7MYXJUM.js +1114 -0
  54. package/dist/_node-chunks/{chunk-LAU7VVPC.js → chunk-LCZO45L7.js} +469 -983
  55. package/dist/_node-chunks/chunk-LR3QITDI.js +209 -0
  56. package/dist/_node-chunks/chunk-LXG4DK35.js +3171 -0
  57. package/dist/_node-chunks/chunk-MJ3WOS6F.js +37 -0
  58. package/dist/_node-chunks/chunk-PHOZWZZO.js +61 -0
  59. package/dist/_node-chunks/chunk-QECOQWRJ.js +936 -0
  60. package/dist/_node-chunks/chunk-QH4V5YDB.js +20 -0
  61. package/dist/_node-chunks/chunk-R6HWGZWD.js +26 -0
  62. package/dist/_node-chunks/chunk-SPQXMU2Q.js +759 -0
  63. package/dist/_node-chunks/chunk-TXZY6V6O.js +1564 -0
  64. package/dist/_node-chunks/chunk-UGDPX5LE.js +756 -0
  65. package/dist/_node-chunks/chunk-UY26MQLT.js +603 -0
  66. package/dist/_node-chunks/chunk-WK3EMYK6.js +61 -0
  67. package/dist/_node-chunks/{chunk-CJHAP7SE.js → chunk-WLHMN7AP.js} +292 -688
  68. package/dist/_node-chunks/chunk-XGVLB4UJ.js +54 -0
  69. package/dist/_node-chunks/{chunk-J7N7PD5Q.js → chunk-YHRFI6BE.js} +87 -227
  70. package/dist/_node-chunks/chunk-YK4KVMFW.js +18 -0
  71. package/dist/_node-chunks/chunk-ZZALGOA6.js +4523 -0
  72. package/dist/_node-chunks/chunk-ZZPBSYA5.js +301 -0
  73. package/dist/_node-chunks/chunk-ZZSRFAC6.js +45571 -0
  74. package/dist/_node-chunks/dist-4DWOCZUD.js +121 -0
  75. package/dist/_node-chunks/globby-AAARUKEU.js +3452 -0
  76. package/dist/_node-chunks/lib-HEUKGL62.js +366 -0
  77. package/dist/_node-chunks/mdx-N42X6CFJ-DCVRPS6N.js +14329 -0
  78. package/dist/_node-chunks/p-limit-F5ZKJ6WZ.js +116 -0
  79. package/dist/_node-chunks/plugin-7YY7JXCH.js +123 -0
  80. package/dist/_node-chunks/{plugin-HJLCLGNT.js → plugin-SZP3CW6W.js} +36 -56
  81. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-TGKNDPO6.js +46623 -0
  82. package/dist/_node-chunks/webpack-mock-plugin-LNTZZFBE.js +92 -0
  83. package/dist/actions/decorator.js +21 -42
  84. package/dist/actions/index.js +3 -3
  85. package/dist/babel/index.d.ts +671 -335
  86. package/dist/babel/index.js +11 -11
  87. package/dist/bin/core.js +592 -1546
  88. package/dist/bin/dispatcher.js +26 -37
  89. package/dist/bin/loader.js +23 -34
  90. package/dist/channels/index.js +98 -234
  91. package/dist/cli/index.js +1966 -5347
  92. package/dist/client-logger/index.js +31 -61
  93. package/dist/common/index.d.ts +210 -3
  94. package/dist/common/index.js +28 -20
  95. package/dist/components/index.d.ts +472 -280
  96. package/dist/components/index.js +15992 -75
  97. package/dist/core-events/index.js +2 -66
  98. package/dist/core-server/index.js +3837 -7191
  99. package/dist/core-server/presets/common-manager.css +2 -2
  100. package/dist/core-server/presets/common-manager.js +2511 -5219
  101. package/dist/core-server/presets/common-override-preset.js +31 -60
  102. package/dist/core-server/presets/common-preset.js +434 -924
  103. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +15 -19
  104. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +12 -17
  105. package/dist/csf/index.js +534 -1172
  106. package/dist/csf-tools/index.d.ts +15 -4
  107. package/dist/csf-tools/index.js +9 -9
  108. package/dist/docs-tools/index.js +6 -6
  109. package/dist/highlight/index.js +2 -2
  110. package/dist/instrumenter/index.js +199 -415
  111. package/dist/manager/globals-runtime.js +47968 -56484
  112. package/dist/manager/globals.js +2 -3
  113. package/dist/manager/runtime.js +4901 -10318
  114. package/dist/manager-api/index.d.ts +11 -3
  115. package/dist/manager-api/index.js +1250 -2397
  116. package/dist/manager-errors.d.ts +3 -0
  117. package/dist/manager-errors.js +3 -3
  118. package/dist/node-logger/index.d.ts +1 -1
  119. package/dist/node-logger/index.js +1270 -2593
  120. package/dist/preview/globals.js +2 -3
  121. package/dist/preview/runtime.js +10767 -22386
  122. package/dist/preview-api/index.d.ts +67 -68
  123. package/dist/preview-api/index.js +15 -15
  124. package/dist/preview-errors.d.ts +3 -0
  125. package/dist/preview-errors.js +4 -4
  126. package/dist/router/index.js +347 -899
  127. package/dist/server-errors.d.ts +3 -0
  128. package/dist/server-errors.js +10 -10
  129. package/dist/telemetry/index.js +24 -24
  130. package/dist/test/index.js +6129 -11914
  131. package/dist/theming/create.d.ts +4 -2
  132. package/dist/theming/create.js +4 -4
  133. package/dist/theming/index.d.ts +3397 -2628
  134. package/dist/theming/index.js +502 -1091
  135. package/dist/types/index.d.ts +50 -5
  136. package/dist/types/index.js +2 -11
  137. package/dist/viewport/index.js +3 -3
  138. package/package.json +17 -9
  139. package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
  140. package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
  141. package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
  142. package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
  143. package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
  144. package/dist/_browser-chunks/chunk-C4XOKMDU.js +0 -270
  145. package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
  146. package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
  147. package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
  148. package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
  149. package/dist/_browser-chunks/chunk-I74EUU5O.js +0 -5809
  150. package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
  151. package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
  152. package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
  153. package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
  154. package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
  155. package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
  156. package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
  157. package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
  158. package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
  159. package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
  160. package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
  161. package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
  162. package/dist/_browser-chunks/chunk-W4QKLQSC.js +0 -4182
  163. package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
  164. package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
  165. package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
  166. package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
  167. package/dist/_node-chunks/camelcase-WKJOVNPM.js +0 -18
  168. package/dist/_node-chunks/chunk-2RIKHYCS.js +0 -304
  169. package/dist/_node-chunks/chunk-3JCSHYSU.js +0 -1657
  170. package/dist/_node-chunks/chunk-4GE6Q4MX.js +0 -1531
  171. package/dist/_node-chunks/chunk-5SEHHENC.js +0 -64656
  172. package/dist/_node-chunks/chunk-6GD23U64.js +0 -420
  173. package/dist/_node-chunks/chunk-6OAXYS5T.js +0 -1544
  174. package/dist/_node-chunks/chunk-7TNUMFKR.js +0 -4741
  175. package/dist/_node-chunks/chunk-BCDHUXAJ.js +0 -4272
  176. package/dist/_node-chunks/chunk-BYVQZ2HU.js +0 -220
  177. package/dist/_node-chunks/chunk-DAMVKHAC.js +0 -101
  178. package/dist/_node-chunks/chunk-FEOC7OX2.js +0 -1586
  179. package/dist/_node-chunks/chunk-FY7XZPLY.js +0 -2248
  180. package/dist/_node-chunks/chunk-GD2FXWDF.js +0 -697
  181. package/dist/_node-chunks/chunk-HM6B7FE5.js +0 -18
  182. package/dist/_node-chunks/chunk-HORWITP7.js +0 -90
  183. package/dist/_node-chunks/chunk-II4AFH3V.js +0 -28
  184. package/dist/_node-chunks/chunk-MF2PUEWG.js +0 -5029
  185. package/dist/_node-chunks/chunk-RVE4UTVQ.js +0 -1518
  186. package/dist/_node-chunks/chunk-TUFWZUTO.js +0 -69
  187. package/dist/_node-chunks/chunk-TXHNWNH4.js +0 -79
  188. package/dist/_node-chunks/chunk-ULWNTI6M.js +0 -1198
  189. package/dist/_node-chunks/chunk-VYRFXLRO.js +0 -6712
  190. package/dist/_node-chunks/chunk-WNOSTIYP.js +0 -34
  191. package/dist/_node-chunks/chunk-X67VGZN4.js +0 -1250
  192. package/dist/_node-chunks/chunk-XCEBYOA4.js +0 -61
  193. package/dist/_node-chunks/chunk-XW7YMR7I.js +0 -111
  194. package/dist/_node-chunks/chunk-ZRFYQ46H.js +0 -61
  195. package/dist/_node-chunks/dist-APCKHSY3.js +0 -175
  196. package/dist/_node-chunks/globby-TSGXGDA2.js +0 -5222
  197. package/dist/_node-chunks/lib-DZ5TVIU5.js +0 -518
  198. package/dist/_node-chunks/mdx-N42X6CFJ-Z6BYQCPN.js +0 -22017
  199. package/dist/_node-chunks/p-limit-MLJNGG2K.js +0 -168
  200. package/dist/_node-chunks/plugin-J3JI3ZKJ.js +0 -159
  201. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-3QHNTM5B.js +0 -69102
  202. package/dist/_node-chunks/webpack-mock-plugin-4Y3MWPJ6.js +0 -124
@@ -0,0 +1,936 @@
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
+ version
14
+ } from "./chunk-YK4KVMFW.js";
15
+ import {
16
+ createFileSystemCache,
17
+ resolvePathInStorybookCache,
18
+ up
19
+ } from "./chunk-GG2WQZSG.js";
20
+ import {
21
+ globalSettings
22
+ } from "./chunk-JCRM2YVK.js";
23
+ import {
24
+ execaCommand,
25
+ getProjectRoot
26
+ } from "./chunk-LXG4DK35.js";
27
+ import {
28
+ getSessionId,
29
+ nanoid,
30
+ set
31
+ } from "./chunk-AKTRSR3O.js";
32
+ import {
33
+ resolvePackageDir
34
+ } from "./chunk-SPQXMU2Q.js";
35
+ import {
36
+ slash
37
+ } from "./chunk-QH4V5YDB.js";
38
+ import {
39
+ require_picocolors
40
+ } from "./chunk-32NE3UE3.js";
41
+ import {
42
+ __commonJS,
43
+ __toESM
44
+ } from "./chunk-XGVLB4UJ.js";
45
+
46
+ // ../node_modules/fetch-retry/index.js
47
+ var require_fetch_retry = __commonJS({
48
+ "../node_modules/fetch-retry/index.js"(exports, module) {
49
+ "use strict";
50
+ module.exports = function(fetch2, defaults) {
51
+ if (defaults = defaults || {}, typeof fetch2 != "function")
52
+ throw new ArgumentError("fetch must be a function");
53
+ if (typeof defaults != "object")
54
+ throw new ArgumentError("defaults must be an object");
55
+ if (defaults.retries !== void 0 && !isPositiveInteger(defaults.retries))
56
+ throw new ArgumentError("retries must be a positive integer");
57
+ if (defaults.retryDelay !== void 0 && !isPositiveInteger(defaults.retryDelay) && typeof defaults.retryDelay != "function")
58
+ throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
59
+ if (defaults.retryOn !== void 0 && !Array.isArray(defaults.retryOn) && typeof defaults.retryOn != "function")
60
+ throw new ArgumentError("retryOn property expects an array or function");
61
+ var baseDefaults = {
62
+ retries: 3,
63
+ retryDelay: 1e3,
64
+ retryOn: []
65
+ };
66
+ return defaults = Object.assign(baseDefaults, defaults), function(input, init) {
67
+ var retries = defaults.retries, retryDelay = defaults.retryDelay, retryOn = defaults.retryOn;
68
+ if (init && init.retries !== void 0)
69
+ if (isPositiveInteger(init.retries))
70
+ retries = init.retries;
71
+ else
72
+ throw new ArgumentError("retries must be a positive integer");
73
+ if (init && init.retryDelay !== void 0)
74
+ if (isPositiveInteger(init.retryDelay) || typeof init.retryDelay == "function")
75
+ retryDelay = init.retryDelay;
76
+ else
77
+ throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
78
+ if (init && init.retryOn)
79
+ if (Array.isArray(init.retryOn) || typeof init.retryOn == "function")
80
+ retryOn = init.retryOn;
81
+ else
82
+ throw new ArgumentError("retryOn property expects an array or function");
83
+ return new Promise(function(resolve, reject) {
84
+ var wrappedFetch = function(attempt) {
85
+ var _input = typeof Request < "u" && input instanceof Request ? input.clone() : input;
86
+ fetch2(_input, init).then(function(response) {
87
+ if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1)
88
+ resolve(response);
89
+ else if (typeof retryOn == "function")
90
+ try {
91
+ return Promise.resolve(retryOn(attempt, null, response)).then(function(retryOnResponse) {
92
+ retryOnResponse ? retry2(attempt, null, response) : resolve(response);
93
+ }).catch(reject);
94
+ } catch (error) {
95
+ reject(error);
96
+ }
97
+ else
98
+ attempt < retries ? retry2(attempt, null, response) : resolve(response);
99
+ }).catch(function(error) {
100
+ if (typeof retryOn == "function")
101
+ try {
102
+ Promise.resolve(retryOn(attempt, error, null)).then(function(retryOnResponse) {
103
+ retryOnResponse ? retry2(attempt, error, null) : reject(error);
104
+ }).catch(function(error2) {
105
+ reject(error2);
106
+ });
107
+ } catch (error2) {
108
+ reject(error2);
109
+ }
110
+ else attempt < retries ? retry2(attempt, error, null) : reject(error);
111
+ });
112
+ };
113
+ function retry2(attempt, error, response) {
114
+ var delay = typeof retryDelay == "function" ? retryDelay(attempt, error, response) : retryDelay;
115
+ setTimeout(function() {
116
+ wrappedFetch(++attempt);
117
+ }, delay);
118
+ }
119
+ wrappedFetch(0);
120
+ });
121
+ };
122
+ };
123
+ function isPositiveInteger(value) {
124
+ return Number.isInteger(value) && value >= 0;
125
+ }
126
+ function ArgumentError(message) {
127
+ this.name = "ArgumentError", this.message = message;
128
+ }
129
+ }
130
+ });
131
+
132
+ // src/telemetry/index.ts
133
+ import { logger as logger2 } from "storybook/internal/node-logger";
134
+
135
+ // src/telemetry/notify.ts
136
+ var import_picocolors = __toESM(require_picocolors(), 1);
137
+ import { cache } from "storybook/internal/common";
138
+ import { CLI_COLORS, logger } from "storybook/internal/node-logger";
139
+ var TELEMETRY_KEY_NOTIFY_DATE = "telemetry-notification-date", notify = async () => {
140
+ await cache.get(TELEMETRY_KEY_NOTIFY_DATE, null) || (cache.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now()), logger.log(
141
+ `${CLI_COLORS.info("Attention:")} Storybook now collects completely anonymous telemetry regarding usage. This information is used to shape Storybook's roadmap and prioritize features.`
142
+ ), logger.log(
143
+ "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:"
144
+ ), logger.log(import_picocolors.default.cyan("https://storybook.js.org/telemetry")), logger.log(""));
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,
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, options) {
201
+ let process3 = execaCommand(command, { shell: !0, 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
+ let command = `git ls-files -- ${globs.join(" ")}`;
231
+ return await execCommandCountLines(command);
232
+ } catch {
233
+ return;
234
+ }
235
+ }, getApplicationFileCount = async (path3) => runTelemetryOperation(
236
+ "applicationFiles",
237
+ async () => getApplicationFilesCountUncached(path3)
238
+ );
239
+
240
+ // src/telemetry/get-chromatic-version.ts
241
+ function getChromaticVersionSpecifier(packageJson) {
242
+ let dependency = packageJson.dependencies?.chromatic || packageJson.devDependencies?.chromatic || packageJson.peerDependencies?.chromatic;
243
+ return dependency || (packageJson.scripts && Object.values(packageJson.scripts).find((s) => s?.match(/chromatic/)) ? "latest" : void 0);
244
+ }
245
+
246
+ // src/telemetry/get-framework-info.ts
247
+ import { normalize } from "node:path";
248
+ import { frameworkPackages } from "storybook/internal/common";
249
+
250
+ // src/telemetry/package-json.ts
251
+ import { fileURLToPath, pathToFileURL } from "node:url";
252
+ var getActualPackageVersions = async (packages) => {
253
+ let packageNames = Object.keys(packages);
254
+ return Promise.all(packageNames.map(getActualPackageVersion));
255
+ }, getActualPackageVersion = async (packageName) => {
256
+ try {
257
+ let packageJson = await getActualPackageJson(packageName);
258
+ return {
259
+ name: packageJson?.name || packageName,
260
+ version: packageJson?.version || null
261
+ };
262
+ } catch {
263
+ return {
264
+ name: packageName,
265
+ version: null
266
+ };
267
+ }
268
+ }, getActualPackageJson = async (packageName) => {
269
+ try {
270
+ let resolvedPackageJsonPath = up({
271
+ cwd: fileURLToPath(import.meta.resolve(packageName, process.cwd()))
272
+ });
273
+ resolvedPackageJsonPath || (resolvedPackageJsonPath = import.meta.resolve(`${packageName}/package.json`, process.cwd()));
274
+ let { default: packageJson } = await import(pathToFileURL(resolvedPackageJsonPath).href, {
275
+ with: { type: "json" }
276
+ });
277
+ return packageJson;
278
+ } catch {
279
+ return;
280
+ }
281
+ };
282
+
283
+ // src/telemetry/get-framework-info.ts
284
+ var knownRenderers = [
285
+ "html",
286
+ "react",
287
+ "svelte",
288
+ "vue3",
289
+ "preact",
290
+ "server",
291
+ "vue",
292
+ "web-components",
293
+ "angular",
294
+ "ember"
295
+ ], knownBuilders = ["builder-webpack5", "builder-vite"];
296
+ function findMatchingPackage(packageJson, suffixes) {
297
+ let { name = "", version: version2, dependencies, devDependencies, peerDependencies } = packageJson, allDependencies = {
298
+ // We include the framework itself because it may be a renderer too (e.g. angular)
299
+ [name]: version2,
300
+ ...dependencies,
301
+ ...devDependencies,
302
+ ...peerDependencies
303
+ };
304
+ return suffixes.map((suffix) => `@storybook/${suffix}`).find((pkg) => allDependencies[pkg]);
305
+ }
306
+ var getFrameworkPackageName = (packageNameOrPath) => {
307
+ let normalizedPath = normalize(packageNameOrPath).replace(new RegExp(/\\/, "g"), "/");
308
+ return Object.keys(frameworkPackages).find((pkg) => normalizedPath.endsWith(pkg)) || cleanPaths(packageNameOrPath).replace(/.*node_modules[\\/]/, "");
309
+ };
310
+ async function getFrameworkInfo(mainConfig) {
311
+ if (!mainConfig?.framework)
312
+ return {};
313
+ let rawName = typeof mainConfig.framework == "string" ? mainConfig.framework : mainConfig.framework?.name;
314
+ if (!rawName)
315
+ return {};
316
+ let frameworkPackageJson = await getActualPackageJson(rawName);
317
+ if (!frameworkPackageJson)
318
+ return {};
319
+ let builder = findMatchingPackage(frameworkPackageJson, knownBuilders), renderer = findMatchingPackage(frameworkPackageJson, knownRenderers), sanitizedFrameworkName = getFrameworkPackageName(rawName), frameworkOptions = typeof mainConfig.framework == "object" ? mainConfig.framework.options : {};
320
+ return {
321
+ framework: {
322
+ name: sanitizedFrameworkName,
323
+ options: frameworkOptions
324
+ },
325
+ builder,
326
+ renderer
327
+ };
328
+ }
329
+
330
+ // src/telemetry/get-has-router-package.ts
331
+ var routerPackages = /* @__PURE__ */ new Set([
332
+ "react-router",
333
+ "react-router-dom",
334
+ "remix",
335
+ "@tanstack/react-router",
336
+ "expo-router",
337
+ "@reach/router",
338
+ "react-easy-router",
339
+ "@remix-run/router",
340
+ "wouter",
341
+ "wouter-preact",
342
+ "preact-router",
343
+ "vue-router",
344
+ "unplugin-vue-router",
345
+ "@angular/router",
346
+ "@solidjs/router",
347
+ // metaframeworks that imply routing
348
+ "next",
349
+ "react-scripts",
350
+ "gatsby",
351
+ "nuxt",
352
+ "@sveltejs/kit"
353
+ ]);
354
+ function getHasRouterPackage(packageJson) {
355
+ return Object.keys(packageJson?.dependencies ?? {}).some(
356
+ (depName) => routerPackages.has(depName)
357
+ );
358
+ }
359
+
360
+ // src/telemetry/get-monorepo-type.ts
361
+ import { existsSync, readFileSync } from "node:fs";
362
+ import { join } from "node:path";
363
+ import { getProjectRoot as getProjectRoot2 } from "storybook/internal/common";
364
+ var monorepoConfigs = {
365
+ Nx: "nx.json",
366
+ Turborepo: "turbo.json",
367
+ Lerna: "lerna.json",
368
+ Rush: "rush.json",
369
+ Lage: "lage.config.json"
370
+ }, getMonorepoType = () => {
371
+ let monorepoType = Object.keys(monorepoConfigs).find((monorepo) => {
372
+ let configFile = join(getProjectRoot2(), monorepoConfigs[monorepo]);
373
+ return existsSync(configFile);
374
+ });
375
+ if (monorepoType)
376
+ return monorepoType;
377
+ if (!existsSync(join(getProjectRoot2(), "package.json")))
378
+ return;
379
+ if (JSON.parse(
380
+ readFileSync(join(getProjectRoot2(), "package.json"), { encoding: "utf8" })
381
+ )?.workspaces)
382
+ return "Workspaces";
383
+ };
384
+
385
+ // ../node_modules/package-manager-detector/dist/commands.mjs
386
+ function dashDashArg(agent, agentCommand) {
387
+ return (args) => args.length > 1 ? [agent, agentCommand, args[0], "--", ...args.slice(1)] : [agent, agentCommand, args[0]];
388
+ }
389
+ function denoExecute() {
390
+ return (args) => ["deno", "run", `npm:${args[0]}`, ...args.slice(1)];
391
+ }
392
+ var npm = {
393
+ agent: ["npm", 0],
394
+ run: dashDashArg("npm", "run"),
395
+ install: ["npm", "i", 0],
396
+ frozen: ["npm", "ci", 0],
397
+ global: ["npm", "i", "-g", 0],
398
+ add: ["npm", "i", 0],
399
+ upgrade: ["npm", "update", 0],
400
+ "upgrade-interactive": null,
401
+ dedupe: ["npm", "dedupe", 0],
402
+ execute: ["npx", 0],
403
+ "execute-local": ["npx", 0],
404
+ uninstall: ["npm", "uninstall", 0],
405
+ global_uninstall: ["npm", "uninstall", "-g", 0]
406
+ }, yarn = {
407
+ agent: ["yarn", 0],
408
+ run: ["yarn", "run", 0],
409
+ install: ["yarn", "install", 0],
410
+ frozen: ["yarn", "install", "--frozen-lockfile", 0],
411
+ global: ["yarn", "global", "add", 0],
412
+ add: ["yarn", "add", 0],
413
+ upgrade: ["yarn", "upgrade", 0],
414
+ "upgrade-interactive": ["yarn", "upgrade-interactive", 0],
415
+ dedupe: null,
416
+ execute: ["npx", 0],
417
+ "execute-local": dashDashArg("yarn", "exec"),
418
+ uninstall: ["yarn", "remove", 0],
419
+ global_uninstall: ["yarn", "global", "remove", 0]
420
+ }, yarnBerry = {
421
+ ...yarn,
422
+ frozen: ["yarn", "install", "--immutable", 0],
423
+ upgrade: ["yarn", "up", 0],
424
+ "upgrade-interactive": ["yarn", "up", "-i", 0],
425
+ dedupe: ["yarn", "dedupe", 0],
426
+ execute: ["yarn", "dlx", 0],
427
+ "execute-local": ["yarn", "exec", 0],
428
+ // Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
429
+ global: ["npm", "i", "-g", 0],
430
+ global_uninstall: ["npm", "uninstall", "-g", 0]
431
+ }, pnpm = {
432
+ agent: ["pnpm", 0],
433
+ run: ["pnpm", "run", 0],
434
+ install: ["pnpm", "i", 0],
435
+ frozen: ["pnpm", "i", "--frozen-lockfile", 0],
436
+ global: ["pnpm", "add", "-g", 0],
437
+ add: ["pnpm", "add", 0],
438
+ upgrade: ["pnpm", "update", 0],
439
+ "upgrade-interactive": ["pnpm", "update", "-i", 0],
440
+ dedupe: ["pnpm", "dedupe", 0],
441
+ execute: ["pnpm", "dlx", 0],
442
+ "execute-local": ["pnpm", "exec", 0],
443
+ uninstall: ["pnpm", "remove", 0],
444
+ global_uninstall: ["pnpm", "remove", "--global", 0]
445
+ }, bun = {
446
+ agent: ["bun", 0],
447
+ run: ["bun", "run", 0],
448
+ install: ["bun", "install", 0],
449
+ frozen: ["bun", "install", "--frozen-lockfile", 0],
450
+ global: ["bun", "add", "-g", 0],
451
+ add: ["bun", "add", 0],
452
+ upgrade: ["bun", "update", 0],
453
+ "upgrade-interactive": ["bun", "update", "-i", 0],
454
+ dedupe: null,
455
+ execute: ["bun", "x", 0],
456
+ "execute-local": ["bun", "x", 0],
457
+ uninstall: ["bun", "remove", 0],
458
+ global_uninstall: ["bun", "remove", "-g", 0]
459
+ }, deno = {
460
+ agent: ["deno", 0],
461
+ run: ["deno", "task", 0],
462
+ install: ["deno", "install", 0],
463
+ frozen: ["deno", "install", "--frozen", 0],
464
+ global: ["deno", "install", "-g", 0],
465
+ add: ["deno", "add", 0],
466
+ upgrade: ["deno", "outdated", "--update", 0],
467
+ "upgrade-interactive": ["deno", "outdated", "--update", 0],
468
+ dedupe: null,
469
+ execute: denoExecute(),
470
+ "execute-local": ["deno", "task", "--eval", 0],
471
+ uninstall: ["deno", "remove", 0],
472
+ global_uninstall: ["deno", "uninstall", "-g", 0]
473
+ }, COMMANDS = {
474
+ npm,
475
+ yarn,
476
+ "yarn@berry": yarnBerry,
477
+ pnpm,
478
+ // pnpm v6.x or below
479
+ "pnpm@6": {
480
+ ...pnpm,
481
+ run: dashDashArg("pnpm", "run")
482
+ },
483
+ bun,
484
+ deno
485
+ };
486
+
487
+ // ../node_modules/package-manager-detector/dist/constants.mjs
488
+ var AGENTS = [
489
+ "npm",
490
+ "yarn",
491
+ "yarn@berry",
492
+ "pnpm",
493
+ "pnpm@6",
494
+ "bun",
495
+ "deno"
496
+ ], LOCKS = {
497
+ "bun.lock": "bun",
498
+ "bun.lockb": "bun",
499
+ "deno.lock": "deno",
500
+ "pnpm-lock.yaml": "pnpm",
501
+ "pnpm-workspace.yaml": "pnpm",
502
+ "yarn.lock": "yarn",
503
+ "package-lock.json": "npm",
504
+ "npm-shrinkwrap.json": "npm"
505
+ }, INSTALL_METADATA = {
506
+ "node_modules/.deno/": "deno",
507
+ "node_modules/.pnpm/": "pnpm",
508
+ "node_modules/.yarn-state.yml": "yarn",
509
+ // yarn v2+ (node-modules)
510
+ "node_modules/.yarn_integrity": "yarn",
511
+ // yarn v1
512
+ "node_modules/.package-lock.json": "npm",
513
+ ".pnp.cjs": "yarn",
514
+ // yarn v3+ (pnp)
515
+ ".pnp.js": "yarn",
516
+ // yarn v2 (pnp)
517
+ "bun.lock": "bun",
518
+ "bun.lockb": "bun"
519
+ };
520
+
521
+ // ../node_modules/package-manager-detector/dist/detect.mjs
522
+ import fs from "node:fs/promises";
523
+ import path2 from "node:path";
524
+ import process2 from "node:process";
525
+ async function pathExists(path22, type) {
526
+ try {
527
+ let stat = await fs.stat(path22);
528
+ return type === "file" ? stat.isFile() : stat.isDirectory();
529
+ } catch {
530
+ return !1;
531
+ }
532
+ }
533
+ function* lookup(cwd = process2.cwd()) {
534
+ let directory = path2.resolve(cwd), { root } = path2.parse(directory);
535
+ for (; directory && directory !== root; )
536
+ yield directory, directory = path2.dirname(directory);
537
+ }
538
+ async function parsePackageJson(filepath, onUnknown) {
539
+ return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
540
+ }
541
+ async function detect(options = {}) {
542
+ let {
543
+ cwd,
544
+ strategies = ["lockfile", "packageManager-field", "devEngines-field"],
545
+ onUnknown
546
+ } = options, stopDir;
547
+ if (typeof options.stopDir == "string") {
548
+ let resolved = path2.resolve(options.stopDir);
549
+ stopDir = (dir) => dir === resolved;
550
+ } else
551
+ stopDir = options.stopDir;
552
+ for (let directory of lookup(cwd)) {
553
+ for (let strategy of strategies)
554
+ switch (strategy) {
555
+ case "lockfile": {
556
+ for (let lock of Object.keys(LOCKS))
557
+ if (await pathExists(path2.join(directory, lock), "file")) {
558
+ let name = LOCKS[lock], result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
559
+ return result || { name, agent: name };
560
+ }
561
+ break;
562
+ }
563
+ case "packageManager-field":
564
+ case "devEngines-field": {
565
+ let result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
566
+ if (result)
567
+ return result;
568
+ break;
569
+ }
570
+ case "install-metadata": {
571
+ for (let metadata of Object.keys(INSTALL_METADATA)) {
572
+ let fileOrDir = metadata.endsWith("/") ? "dir" : "file";
573
+ if (await pathExists(path2.join(directory, metadata), fileOrDir)) {
574
+ let name = INSTALL_METADATA[metadata], agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
575
+ return { name, agent };
576
+ }
577
+ }
578
+ break;
579
+ }
580
+ }
581
+ if (stopDir?.(directory))
582
+ break;
583
+ }
584
+ return null;
585
+ }
586
+ function getNameAndVer(pkg) {
587
+ let handelVer = (version2) => version2?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version2;
588
+ if (typeof pkg.packageManager == "string") {
589
+ let [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
590
+ return { name, ver: handelVer(ver) };
591
+ }
592
+ if (typeof pkg.devEngines?.packageManager?.name == "string")
593
+ return {
594
+ name: pkg.devEngines.packageManager.name,
595
+ ver: handelVer(pkg.devEngines.packageManager.version)
596
+ };
597
+ }
598
+ async function handlePackageManager(filepath, onUnknown) {
599
+ try {
600
+ let pkg = JSON.parse(await fs.readFile(filepath, "utf8")), agent, nameAndVer = getNameAndVer(pkg);
601
+ if (nameAndVer) {
602
+ let name = nameAndVer.name, ver = nameAndVer.ver, version2 = ver;
603
+ 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;
604
+ }
605
+ } catch {
606
+ }
607
+ return null;
608
+ }
609
+ function isMetadataYarnClassic(metadataPath) {
610
+ return metadataPath.endsWith(".yarn_integrity");
611
+ }
612
+
613
+ // src/telemetry/get-package-manager-info.ts
614
+ var getPackageManagerInfo = async () => {
615
+ let packageManagerType = await detect({ cwd: getProjectRoot() });
616
+ if (!packageManagerType)
617
+ return;
618
+ let nodeLinker = "node_modules";
619
+ if (packageManagerType.name === "yarn")
620
+ try {
621
+ let { stdout } = await execaCommand("yarn config get nodeLinker", {
622
+ cwd: getProjectRoot()
623
+ });
624
+ nodeLinker = stdout.trim();
625
+ } catch {
626
+ }
627
+ if (packageManagerType.name === "pnpm")
628
+ try {
629
+ let { stdout } = await execaCommand("pnpm config get nodeLinker", {
630
+ cwd: getProjectRoot()
631
+ });
632
+ nodeLinker = stdout.trim() ?? "isolated";
633
+ } catch {
634
+ }
635
+ return {
636
+ type: packageManagerType.name,
637
+ version: packageManagerType.version,
638
+ agent: packageManagerType.agent,
639
+ nodeLinker
640
+ };
641
+ };
642
+
643
+ // src/telemetry/get-portable-stories-usage.ts
644
+ var getPortableStoriesFileCountUncached = async (path3) => {
645
+ try {
646
+ let command = "git grep -l composeStor" + (path3 ? ` -- ${path3}` : "");
647
+ return await execCommandCountLines(command);
648
+ } catch (err) {
649
+ return err.exitCode === 1 ? 0 : void 0;
650
+ }
651
+ }, getPortableStoriesFileCount = async (path3) => runTelemetryOperation(
652
+ "portableStories",
653
+ async () => getPortableStoriesFileCountUncached(path3)
654
+ );
655
+
656
+ // src/telemetry/storybook-metadata.ts
657
+ var metaFrameworks = {
658
+ next: "Next",
659
+ "react-scripts": "CRA",
660
+ gatsby: "Gatsby",
661
+ "@nuxtjs/storybook": "nuxt",
662
+ "@nrwl/storybook": "nx",
663
+ "@vue/cli-service": "vue-cli",
664
+ "@sveltejs/kit": "sveltekit",
665
+ "@tanstack/react-router": "tanstack-react",
666
+ "@react-router/dev": "react-router",
667
+ "@remix-run/dev": "remix"
668
+ }, sanitizeAddonName = (name) => cleanPaths(name).replace(/\/dist\/.*/, "").replace(/\.[mc]?[tj]?s[x]?$/, "").replace(/\/register$/, "").replace(/\/manager$/, "").replace(/\/preset$/, ""), computeStorybookMetadata = async ({
669
+ packageJsonPath,
670
+ packageJson,
671
+ mainConfig,
672
+ configDir
673
+ }) => {
674
+ let settings = isCI() ? void 0 : await globalSettings(), metadata = {
675
+ generatedAt: (/* @__PURE__ */ new Date()).getTime(),
676
+ userSince: settings?.value.userSince,
677
+ hasCustomBabel: !1,
678
+ hasCustomWebpack: !1,
679
+ hasStaticDirs: !1,
680
+ hasStorybookEslint: !1,
681
+ refCount: 0
682
+ }, allDependencies = {
683
+ ...packageJson?.dependencies,
684
+ ...packageJson?.devDependencies,
685
+ ...packageJson?.peerDependencies
686
+ }, metaFramework = Object.keys(allDependencies).find((dep) => !!metaFrameworks[dep]);
687
+ if (metaFramework) {
688
+ let { version: version2 } = await getActualPackageVersion(metaFramework);
689
+ metadata.metaFramework = {
690
+ name: metaFrameworks[metaFramework],
691
+ packageName: metaFramework,
692
+ version: version2 || "unknown"
693
+ };
694
+ }
695
+ let testPackages = [
696
+ "playwright",
697
+ "vitest",
698
+ "jest",
699
+ "cypress",
700
+ "nightwatch",
701
+ "webdriver",
702
+ "@web/test-runner",
703
+ "puppeteer",
704
+ "karma",
705
+ "jasmine",
706
+ "chai",
707
+ "testing-library",
708
+ "@ngneat/spectator",
709
+ "wdio",
710
+ "msw",
711
+ "miragejs",
712
+ "sinon",
713
+ "chromatic"
714
+ ], testPackageDeps = Object.keys(allDependencies).filter(
715
+ (dep) => testPackages.find((pkg) => dep.includes(pkg))
716
+ );
717
+ metadata.testPackages = Object.fromEntries(
718
+ await Promise.all(
719
+ testPackageDeps.map(async (dep) => [dep, (await getActualPackageVersion(dep))?.version])
720
+ )
721
+ ), metadata.hasRouterPackage = getHasRouterPackage(packageJson);
722
+ let monorepoType = getMonorepoType();
723
+ monorepoType && (metadata.monorepo = monorepoType), metadata.packageManager = await getPackageManagerInfo();
724
+ let language = allDependencies.typescript ? "typescript" : "javascript";
725
+ if (!mainConfig)
726
+ return {
727
+ ...metadata,
728
+ storybookVersionSpecifier: versions.storybook,
729
+ language
730
+ };
731
+ metadata.hasCustomBabel = !!mainConfig.babel, metadata.hasCustomWebpack = !!mainConfig.webpackFinal, metadata.hasStaticDirs = !!mainConfig.staticDirs, typeof mainConfig.typescript == "object" && (metadata.typescriptOptions = mainConfig.typescript);
732
+ let frameworkInfo = await getFrameworkInfo(mainConfig);
733
+ typeof mainConfig.refs == "object" && (metadata.refCount = Object.keys(mainConfig.refs).length), typeof mainConfig.features == "object" && (metadata.features = mainConfig.features);
734
+ let addons = {};
735
+ mainConfig.addons && mainConfig.addons.forEach((addon) => {
736
+ let addonName, options;
737
+ typeof addon == "string" ? addonName = sanitizeAddonName(addon) : (addon.name.includes("addon-essentials") && (options = addon.options), addonName = sanitizeAddonName(addon.name)), addons[addonName] = {
738
+ options,
739
+ version: void 0
740
+ };
741
+ });
742
+ let chromaticVersionSpecifier = getChromaticVersionSpecifier(packageJson);
743
+ chromaticVersionSpecifier && (addons.chromatic = {
744
+ version: void 0,
745
+ versionSpecifier: chromaticVersionSpecifier,
746
+ options: void 0
747
+ }), (await getActualPackageVersions(addons)).forEach(({ name, version: version2 }) => {
748
+ addons[name] = addons[name] || {
749
+ name,
750
+ version: version2
751
+ }, addons[name].version = version2 || void 0;
752
+ });
753
+ let addonNames = Object.keys(addons), storybookPackages = Object.keys(allDependencies).filter((dep) => dep.includes("storybook") && !addonNames.includes(dep)).reduce((acc, dep) => ({
754
+ ...acc,
755
+ [dep]: { version: void 0 }
756
+ }), {});
757
+ (await getActualPackageVersions(storybookPackages)).forEach(({ name, version: version2 }) => {
758
+ storybookPackages[name] = storybookPackages[name] || {
759
+ name,
760
+ version: version2
761
+ }, storybookPackages[name].version = version2 || void 0;
762
+ });
763
+ let hasStorybookEslint = !!allDependencies["eslint-plugin-storybook"], storybookInfo = await getStorybookInfo(configDir);
764
+ try {
765
+ let { previewConfigPath: previewConfig } = storybookInfo;
766
+ if (previewConfig) {
767
+ let config = await readConfig(previewConfig), usesGlobals = !!(config.getFieldNode(["globals"]) || config.getFieldNode(["globalTypes"]));
768
+ metadata.preview = { ...metadata.preview, usesGlobals };
769
+ }
770
+ } catch {
771
+ }
772
+ let portableStoriesFileCount = await getPortableStoriesFileCount(), applicationFileCount = await getApplicationFileCount(dirname(packageJsonPath));
773
+ return {
774
+ ...metadata,
775
+ ...frameworkInfo,
776
+ portableStoriesFileCount,
777
+ applicationFileCount,
778
+ storybookVersion: version,
779
+ storybookVersionSpecifier: storybookInfo.version,
780
+ language,
781
+ storybookPackages,
782
+ addons,
783
+ hasStorybookEslint
784
+ };
785
+ };
786
+ async function getPackageJsonDetails() {
787
+ let packageJsonPath = up();
788
+ return packageJsonPath ? {
789
+ packageJsonPath,
790
+ packageJson: JSON.parse(await readFile(packageJsonPath, "utf8"))
791
+ } : {
792
+ packageJsonPath: process.cwd(),
793
+ packageJson: {}
794
+ };
795
+ }
796
+ var cachedMetadata, getStorybookMetadata = async (_configDir) => {
797
+ if (cachedMetadata)
798
+ return cachedMetadata;
799
+ let { packageJson, packageJsonPath } = await getPackageJsonDetails(), configDir = (_configDir || getStorybookConfiguration(
800
+ String(packageJson?.scripts?.storybook || ""),
801
+ "-c",
802
+ "--config-dir"
803
+ )) ?? ".storybook", mainConfig = await loadMainConfig({ configDir }).catch(() => {
804
+ });
805
+ return cachedMetadata = await computeStorybookMetadata({
806
+ mainConfig,
807
+ packageJson,
808
+ packageJsonPath,
809
+ configDir
810
+ }), cachedMetadata;
811
+ };
812
+
813
+ // src/telemetry/telemetry.ts
814
+ var import_fetch_retry = __toESM(require_fetch_retry(), 1);
815
+ import { readFileSync as readFileSync2 } from "node:fs";
816
+ import * as os from "node:os";
817
+ import { join as join2 } from "node:path";
818
+ import { isCI as isCI2 } from "storybook/internal/common";
819
+
820
+ // src/telemetry/anonymous-id.ts
821
+ import { relative } from "node:path";
822
+ import { getProjectRoot as getProjectRoot3 } from "storybook/internal/common";
823
+ import { execSync } from "child_process";
824
+
825
+ // src/telemetry/one-way-hash.ts
826
+ import { createHash } from "crypto";
827
+ var oneWayHash = (payload) => {
828
+ let hash = createHash("sha256");
829
+ return hash.update("storybook-telemetry-salt"), hash.update(payload), hash.digest("hex");
830
+ };
831
+
832
+ // src/telemetry/anonymous-id.ts
833
+ function normalizeGitUrl(rawUrl) {
834
+ let urlWithoutScheme = rawUrl.trim().replace(/#.*$/, "").replace(/^.*@/, "").replace(/^.*\/\//, "");
835
+ return (urlWithoutScheme.endsWith(".git") ? urlWithoutScheme : `${urlWithoutScheme}.git`).replace(":", "/");
836
+ }
837
+ function unhashedProjectId(remoteUrl, projectRootPath) {
838
+ return `${normalizeGitUrl(remoteUrl)}${slash(projectRootPath)}`;
839
+ }
840
+ var anonymousProjectId, getAnonymousProjectId = () => {
841
+ if (anonymousProjectId)
842
+ return anonymousProjectId;
843
+ try {
844
+ let projectRootPath = relative(getProjectRoot3(), process.cwd()), originBuffer = execSync("git config --local --get remote.origin.url", {
845
+ timeout: 1e3,
846
+ stdio: "pipe"
847
+ });
848
+ anonymousProjectId = oneWayHash(unhashedProjectId(String(originBuffer), projectRootPath));
849
+ } catch {
850
+ }
851
+ return anonymousProjectId;
852
+ };
853
+
854
+ // src/telemetry/fetch.ts
855
+ var fetch = global.fetch;
856
+
857
+ // src/telemetry/telemetry.ts
858
+ var retryingFetch = (0, import_fetch_retry.default)(fetch), URL = process.env.STORYBOOK_TELEMETRY_URL || "https://storybook.js.org/event-log", tasks = [], addToGlobalContext = (key, value) => {
859
+ globalContext[key] = value;
860
+ }, getOperatingSystem = () => {
861
+ try {
862
+ let platform2 = os.platform();
863
+ return platform2 === "win32" ? "Windows" : platform2 === "darwin" ? "macOS" : platform2 === "linux" ? "Linux" : `Other: ${platform2}`;
864
+ } catch {
865
+ return "Unknown";
866
+ }
867
+ }, globalContext = {
868
+ inCI: isCI2(),
869
+ isTTY: process.stdout.isTTY,
870
+ platform: getOperatingSystem(),
871
+ nodeVersion: process.versions.node,
872
+ storybookVersion: getVersionNumber()
873
+ }, prepareRequest = async (data, context, options) => {
874
+ let { eventType, payload, metadata, ...rest } = data, sessionId = await getSessionId(), eventId = nanoid(), body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
875
+ return retryingFetch(URL, {
876
+ method: "post",
877
+ body: JSON.stringify(body),
878
+ headers: { "Content-Type": "application/json" },
879
+ retries: 3,
880
+ retryOn: [503, 504],
881
+ retryDelay: (attempt) => 2 ** attempt * (typeof options?.retryDelay == "number" && !Number.isNaN(options?.retryDelay) ? options.retryDelay : 1e3)
882
+ });
883
+ };
884
+ function getVersionNumber() {
885
+ try {
886
+ return JSON.parse(readFileSync2(join2(resolvePackageDir("storybook"), "package.json"), "utf8")).version;
887
+ } catch {
888
+ return version;
889
+ }
890
+ }
891
+ async function sendTelemetry(data, options = { retryDelay: 1e3, immediate: !1 }) {
892
+ let { eventType, payload, metadata, ...rest } = data, context = options.stripMetadata ? globalContext : {
893
+ ...globalContext,
894
+ anonymousId: getAnonymousProjectId()
895
+ }, request;
896
+ try {
897
+ request = prepareRequest(data, context, options), tasks.push(request);
898
+ let sessionId = await getSessionId(), eventId = nanoid(), body = { ...rest, eventType, eventId, sessionId, metadata, payload, context }, waitFor = options.immediate ? tasks : [request];
899
+ await Promise.all([...waitFor, set(eventType, body)]);
900
+ } catch {
901
+ } finally {
902
+ tasks = tasks.filter((task) => task !== request);
903
+ }
904
+ }
905
+
906
+ // src/telemetry/index.ts
907
+ var isExampleStoryId = (storyId) => storyId.startsWith("example-button--") || storyId.startsWith("example-header--") || storyId.startsWith("example-page--"), telemetry = async (eventType, payload = {}, options = {}) => {
908
+ eventType !== "boot" && options.notify !== !1 && await notify();
909
+ let telemetryData = {
910
+ eventType,
911
+ payload
912
+ };
913
+ try {
914
+ options?.stripMetadata || (telemetryData.metadata = await getStorybookMetadata(options?.configDir));
915
+ } catch (error) {
916
+ payload.metadataErrorMessage = sanitizeError(error).message, options?.enableCrashReports && (payload.metadataError = sanitizeError(error));
917
+ } finally {
918
+ let { error } = payload;
919
+ error && (payload.error = sanitizeError(error)), (!payload.error || options?.enableCrashReports) && (process.env?.STORYBOOK_TELEMETRY_DEBUG && (logger2.info(`
920
+ [telemetry]`), logger2.info(JSON.stringify(telemetryData, null, 2))), await sendTelemetry(telemetryData, options));
921
+ }
922
+ };
923
+
924
+ export {
925
+ removeAnsiEscapeCodes,
926
+ cleanPaths,
927
+ sanitizeError,
928
+ metaFrameworks,
929
+ sanitizeAddonName,
930
+ computeStorybookMetadata,
931
+ getStorybookMetadata,
932
+ oneWayHash,
933
+ addToGlobalContext,
934
+ isExampleStoryId,
935
+ telemetry
936
+ };