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

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-FTVC2JL7.js} +510 -1019
  40. package/dist/_node-chunks/camelcase-3SMT5WKC.js +37 -0
  41. package/dist/_node-chunks/chunk-2OVULPK3.js +54 -0
  42. package/dist/_node-chunks/chunk-3JJPSDXI.js +3043 -0
  43. package/dist/_node-chunks/chunk-54NMJ4II.js +1564 -0
  44. package/dist/_node-chunks/chunk-5V4A6MSI.js +943 -0
  45. package/dist/_node-chunks/chunk-6DEMT5VX.js +299 -0
  46. package/dist/_node-chunks/{chunk-HHSTA6QS.js → chunk-6L7FFBOW.js} +8 -10
  47. package/dist/_node-chunks/chunk-6ULDIDXV.js +46662 -0
  48. package/dist/_node-chunks/chunk-AREL5IXS.js +603 -0
  49. package/dist/_node-chunks/chunk-DWA53E73.js +23 -0
  50. package/dist/_node-chunks/chunk-FNYKBULZ.js +765 -0
  51. package/dist/_node-chunks/chunk-IUYZQKSX.js +70 -0
  52. package/dist/_node-chunks/{chunk-F6EFOEC7.js → chunk-K673CX4Q.js} +469 -983
  53. package/dist/_node-chunks/chunk-KJAFCNZ3.js +61 -0
  54. package/dist/_node-chunks/chunk-N3BJOOY5.js +78 -0
  55. package/dist/_node-chunks/{chunk-EBUEXRH5.js → chunk-O5FMCQHP.js} +116 -276
  56. package/dist/_node-chunks/chunk-RIKQZHV3.js +29 -0
  57. package/dist/_node-chunks/chunk-RURZIE3W.js +3780 -0
  58. package/dist/_node-chunks/chunk-RVII4SK6.js +919 -0
  59. package/dist/_node-chunks/chunk-S3PBHOVC.js +6024 -0
  60. package/dist/_node-chunks/chunk-SQSFX47N.js +61 -0
  61. package/dist/_node-chunks/{chunk-SGM3ZCCT.js → chunk-TURUTKVH.js} +292 -688
  62. package/dist/_node-chunks/chunk-VRICJPXY.js +72 -0
  63. package/dist/_node-chunks/chunk-WIWWMCEU.js +119 -0
  64. package/dist/_node-chunks/{chunk-ATDHMMIZ.js → chunk-XGNRK7QB.js} +15 -24
  65. package/dist/_node-chunks/chunk-Y2FOTPAE.js +4523 -0
  66. package/dist/_node-chunks/{chunk-GHIBZRKD.js → chunk-Y4UYN72K.js} +8133 -8887
  67. package/dist/_node-chunks/chunk-Z4BMBA5L.js +18 -0
  68. package/dist/_node-chunks/chunk-ZMCJS2GU.js +20 -0
  69. package/dist/_node-chunks/dist-TZLZ3T6L.js +121 -0
  70. package/dist/_node-chunks/globby-22GFCZQD.js +3452 -0
  71. package/dist/_node-chunks/lib-37NQ4ZIJ.js +366 -0
  72. package/dist/_node-chunks/mdx-N42X6CFJ-2TRB7OEH.js +14329 -0
  73. package/dist/_node-chunks/p-limit-UD7TYFDW.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 +602 -1549
  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 +2911 -8519
  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 +11569 -10953
  106. package/dist/manager-api/index.d.ts +1813 -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 +1 -1
  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
@@ -1,1198 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_jpweijb0qqj from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_jpweijb0qqj from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_jpweijb0qqj from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_jpweijb0qqj.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_jpweijb0qqj.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_jpweijb0qqj.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-NILZM6KR.js";
15
- import {
16
- createFileSystemCache,
17
- resolvePathInStorybookCache,
18
- up
19
- } from "./chunk-GHIBZRKD.js";
20
- import {
21
- globalSettings
22
- } from "./chunk-TJNGOQUH.js";
23
- import {
24
- execaCommand,
25
- getProjectRoot
26
- } from "./chunk-LYUNFU3F.js";
27
- import {
28
- getSessionId,
29
- nanoid,
30
- set
31
- } from "./chunk-EMRGRXKT.js";
32
- import {
33
- resolvePackageDir
34
- } from "./chunk-74Z2U7QG.js";
35
- import {
36
- slash
37
- } from "./chunk-N44SIS6K.js";
38
- import {
39
- require_picocolors
40
- } from "./chunk-ATDHMMIZ.js";
41
- import {
42
- __commonJS,
43
- __name,
44
- __toESM
45
- } from "./chunk-3THWHQOC.js";
46
-
47
- // ../node_modules/fetch-retry/index.js
48
- var require_fetch_retry = __commonJS({
49
- "../node_modules/fetch-retry/index.js"(exports, module) {
50
- "use strict";
51
- module.exports = function(fetch2, defaults) {
52
- defaults = defaults || {};
53
- if (typeof fetch2 !== "function") {
54
- throw new ArgumentError("fetch must be a function");
55
- }
56
- if (typeof defaults !== "object") {
57
- throw new ArgumentError("defaults must be an object");
58
- }
59
- if (defaults.retries !== void 0 && !isPositiveInteger(defaults.retries)) {
60
- throw new ArgumentError("retries must be a positive integer");
61
- }
62
- if (defaults.retryDelay !== void 0 && !isPositiveInteger(defaults.retryDelay) && typeof defaults.retryDelay !== "function") {
63
- throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
64
- }
65
- if (defaults.retryOn !== void 0 && !Array.isArray(defaults.retryOn) && typeof defaults.retryOn !== "function") {
66
- throw new ArgumentError("retryOn property expects an array or function");
67
- }
68
- var baseDefaults = {
69
- retries: 3,
70
- retryDelay: 1e3,
71
- retryOn: []
72
- };
73
- defaults = Object.assign(baseDefaults, defaults);
74
- return /* @__PURE__ */ __name(function fetchRetry(input, init) {
75
- var retries = defaults.retries;
76
- var retryDelay = defaults.retryDelay;
77
- var retryOn = defaults.retryOn;
78
- if (init && init.retries !== void 0) {
79
- if (isPositiveInteger(init.retries)) {
80
- retries = init.retries;
81
- } else {
82
- throw new ArgumentError("retries must be a positive integer");
83
- }
84
- }
85
- if (init && init.retryDelay !== void 0) {
86
- if (isPositiveInteger(init.retryDelay) || typeof init.retryDelay === "function") {
87
- retryDelay = init.retryDelay;
88
- } else {
89
- throw new ArgumentError("retryDelay must be a positive integer or a function returning a positive integer");
90
- }
91
- }
92
- if (init && init.retryOn) {
93
- if (Array.isArray(init.retryOn) || typeof init.retryOn === "function") {
94
- retryOn = init.retryOn;
95
- } else {
96
- throw new ArgumentError("retryOn property expects an array or function");
97
- }
98
- }
99
- return new Promise(function(resolve, reject) {
100
- var wrappedFetch = /* @__PURE__ */ __name(function(attempt) {
101
- var _input = typeof Request !== "undefined" && input instanceof Request ? input.clone() : input;
102
- fetch2(_input, init).then(function(response) {
103
- if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {
104
- resolve(response);
105
- } else if (typeof retryOn === "function") {
106
- try {
107
- return Promise.resolve(retryOn(attempt, null, response)).then(function(retryOnResponse) {
108
- if (retryOnResponse) {
109
- retry2(attempt, null, response);
110
- } else {
111
- resolve(response);
112
- }
113
- }).catch(reject);
114
- } catch (error) {
115
- reject(error);
116
- }
117
- } else {
118
- if (attempt < retries) {
119
- retry2(attempt, null, response);
120
- } else {
121
- resolve(response);
122
- }
123
- }
124
- }).catch(function(error) {
125
- if (typeof retryOn === "function") {
126
- try {
127
- Promise.resolve(retryOn(attempt, error, null)).then(function(retryOnResponse) {
128
- if (retryOnResponse) {
129
- retry2(attempt, error, null);
130
- } else {
131
- reject(error);
132
- }
133
- }).catch(function(error2) {
134
- reject(error2);
135
- });
136
- } catch (error2) {
137
- reject(error2);
138
- }
139
- } else if (attempt < retries) {
140
- retry2(attempt, error, null);
141
- } else {
142
- reject(error);
143
- }
144
- });
145
- }, "wrappedFetch");
146
- function retry2(attempt, error, response) {
147
- var delay = typeof retryDelay === "function" ? retryDelay(attempt, error, response) : retryDelay;
148
- setTimeout(function() {
149
- wrappedFetch(++attempt);
150
- }, delay);
151
- }
152
- __name(retry2, "retry");
153
- wrappedFetch(0);
154
- });
155
- }, "fetchRetry");
156
- };
157
- function isPositiveInteger(value) {
158
- return Number.isInteger(value) && value >= 0;
159
- }
160
- __name(isPositiveInteger, "isPositiveInteger");
161
- function ArgumentError(message) {
162
- this.name = "ArgumentError";
163
- this.message = message;
164
- }
165
- __name(ArgumentError, "ArgumentError");
166
- }
167
- });
168
-
169
- // src/telemetry/index.ts
170
- import { logger as logger2 } from "storybook/internal/node-logger";
171
-
172
- // src/telemetry/notify.ts
173
- var import_picocolors = __toESM(require_picocolors(), 1);
174
- import { cache } from "storybook/internal/common";
175
- import { CLI_COLORS, logger } from "storybook/internal/node-logger";
176
- var TELEMETRY_KEY_NOTIFY_DATE = "telemetry-notification-date";
177
- var notify = /* @__PURE__ */ __name(async () => {
178
- const telemetryNotifyDate = await cache.get(TELEMETRY_KEY_NOTIFY_DATE, null);
179
- if (telemetryNotifyDate) {
180
- return;
181
- }
182
- cache.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now());
183
- logger.log(
184
- `${CLI_COLORS.info("Attention:")} Storybook now collects completely anonymous telemetry regarding usage. This information is used to shape Storybook's roadmap and prioritize features.`
185
- );
186
- logger.log(
187
- `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:`
188
- );
189
- logger.log(import_picocolors.default.cyan("https://storybook.js.org/telemetry"));
190
- logger.log("");
191
- }, "notify");
192
-
193
- // src/telemetry/sanitize.ts
194
- import path from "node:path";
195
- function regexpEscape(str) {
196
- return str.replace(/[-[/{}()*+?.\\^$|]/g, `\\$&`);
197
- }
198
- __name(regexpEscape, "regexpEscape");
199
- function removeAnsiEscapeCodes(input = "") {
200
- return input.replace(/\u001B\[[0-9;]*m/g, "");
201
- }
202
- __name(removeAnsiEscapeCodes, "removeAnsiEscapeCodes");
203
- function cleanPaths(str, separator = path.sep) {
204
- if (!str) {
205
- return str;
206
- }
207
- const stack = process.cwd().split(separator);
208
- while (stack.length > 1) {
209
- const currentPath = stack.join(separator);
210
- const currentRegex = new RegExp(regexpEscape(currentPath), `gi`);
211
- str = str.replace(currentRegex, `$SNIP`);
212
- const currentPath2 = stack.join(separator + separator);
213
- const currentRegex2 = new RegExp(regexpEscape(currentPath2), `gi`);
214
- str = str.replace(currentRegex2, `$SNIP`);
215
- stack.pop();
216
- }
217
- return str;
218
- }
219
- __name(cleanPaths, "cleanPaths");
220
- function sanitizeError(error, pathSeparator = path.sep) {
221
- try {
222
- error = {
223
- ...JSON.parse(JSON.stringify(error)),
224
- message: removeAnsiEscapeCodes(error.message),
225
- stack: removeAnsiEscapeCodes(error.stack),
226
- cause: error.cause,
227
- name: error.name
228
- };
229
- const errorString = cleanPaths(JSON.stringify(error), pathSeparator);
230
- return JSON.parse(errorString);
231
- } catch (err) {
232
- return `Sanitization error: ${err?.message}`;
233
- }
234
- }
235
- __name(sanitizeError, "sanitizeError");
236
-
237
- // src/telemetry/storybook-metadata.ts
238
- import { readFile } from "node:fs/promises";
239
- import { dirname } from "node:path";
240
- import {
241
- getStorybookConfiguration,
242
- getStorybookInfo,
243
- isCI,
244
- loadMainConfig,
245
- versions
246
- } from "storybook/internal/common";
247
- import { readConfig } from "storybook/internal/csf-tools";
248
-
249
- // src/telemetry/get-application-file-count.ts
250
- import { sep } from "node:path";
251
-
252
- // src/telemetry/exec-command-count-lines.ts
253
- import { createInterface } from "node:readline";
254
- async function execCommandCountLines(command, options) {
255
- const process3 = execaCommand(command, { shell: true, buffer: false, ...options });
256
- if (!process3.stdout) {
257
- throw new Error("Unexpected missing stdout");
258
- }
259
- let lineCount = 0;
260
- const rl = createInterface(process3.stdout);
261
- rl.on("line", () => {
262
- lineCount += 1;
263
- });
264
- await process3;
265
- rl.close();
266
- return lineCount;
267
- }
268
- __name(execCommandCountLines, "execCommandCountLines");
269
-
270
- // src/telemetry/run-telemetry-operation.ts
271
- var cache2 = createFileSystemCache({
272
- basePath: resolvePathInStorybookCache("telemetry"),
273
- ns: "storybook",
274
- ttl: 24 * 60 * 60 * 1e3
275
- // 24h
276
- });
277
- var runTelemetryOperation = /* @__PURE__ */ __name(async (cacheKey, operation) => {
278
- let cached = await cache2.get(cacheKey);
279
- if (cached === void 0) {
280
- cached = await operation();
281
- if (cached !== void 0) {
282
- await cache2.set(cacheKey, cached);
283
- }
284
- }
285
- return cached;
286
- }, "runTelemetryOperation");
287
-
288
- // src/telemetry/get-application-file-count.ts
289
- var nameMatches = ["page", "screen"];
290
- var extensions = ["js", "jsx", "ts", "tsx"];
291
- var getApplicationFilesCountUncached = /* @__PURE__ */ __name(async (basePath) => {
292
- const bothCasesNameMatches = nameMatches.flatMap((match) => [
293
- match,
294
- [match[0].toUpperCase(), ...match.slice(1)].join("")
295
- ]);
296
- const globs = bothCasesNameMatches.flatMap(
297
- (match) => extensions.map((extension) => `"${basePath}${sep}*${match}*.${extension}"`)
298
- );
299
- try {
300
- const command = `git ls-files -- ${globs.join(" ")}`;
301
- return await execCommandCountLines(command);
302
- } catch {
303
- return void 0;
304
- }
305
- }, "getApplicationFilesCountUncached");
306
- var getApplicationFileCount = /* @__PURE__ */ __name(async (path3) => {
307
- return runTelemetryOperation(
308
- "applicationFiles",
309
- async () => getApplicationFilesCountUncached(path3)
310
- );
311
- }, "getApplicationFileCount");
312
-
313
- // src/telemetry/get-chromatic-version.ts
314
- function getChromaticVersionSpecifier(packageJson) {
315
- const dependency = packageJson.dependencies?.chromatic || packageJson.devDependencies?.chromatic || packageJson.peerDependencies?.chromatic;
316
- if (dependency) {
317
- return dependency;
318
- }
319
- return packageJson.scripts && Object.values(packageJson.scripts).find((s) => s?.match(/chromatic/)) ? "latest" : void 0;
320
- }
321
- __name(getChromaticVersionSpecifier, "getChromaticVersionSpecifier");
322
-
323
- // src/telemetry/get-framework-info.ts
324
- import { normalize } from "node:path";
325
- import { frameworkPackages } from "storybook/internal/common";
326
-
327
- // src/telemetry/package-json.ts
328
- import { fileURLToPath, pathToFileURL } from "node:url";
329
- var getActualPackageVersions = /* @__PURE__ */ __name(async (packages) => {
330
- const packageNames = Object.keys(packages);
331
- return Promise.all(packageNames.map(getActualPackageVersion));
332
- }, "getActualPackageVersions");
333
- var getActualPackageVersion = /* @__PURE__ */ __name(async (packageName) => {
334
- try {
335
- const packageJson = await getActualPackageJson(packageName);
336
- return {
337
- name: packageJson?.name || packageName,
338
- version: packageJson?.version || null
339
- };
340
- } catch (err) {
341
- return {
342
- name: packageName,
343
- version: null
344
- };
345
- }
346
- }, "getActualPackageVersion");
347
- var getActualPackageJson = /* @__PURE__ */ __name(async (packageName) => {
348
- try {
349
- let resolvedPackageJsonPath = up({
350
- cwd: fileURLToPath(import.meta.resolve(packageName, process.cwd()))
351
- });
352
- if (!resolvedPackageJsonPath) {
353
- resolvedPackageJsonPath = import.meta.resolve(`${packageName}/package.json`, process.cwd());
354
- }
355
- const { default: packageJson } = await import(pathToFileURL(resolvedPackageJsonPath).href, {
356
- with: { type: "json" }
357
- });
358
- return packageJson;
359
- } catch (err) {
360
- return void 0;
361
- }
362
- }, "getActualPackageJson");
363
-
364
- // src/telemetry/get-framework-info.ts
365
- var knownRenderers = [
366
- "html",
367
- "react",
368
- "svelte",
369
- "vue3",
370
- "preact",
371
- "server",
372
- "vue",
373
- "web-components",
374
- "angular",
375
- "ember"
376
- ];
377
- var knownBuilders = ["builder-webpack5", "builder-vite"];
378
- function findMatchingPackage(packageJson, suffixes) {
379
- const { name = "", version: version2, dependencies, devDependencies, peerDependencies } = packageJson;
380
- const allDependencies = {
381
- // We include the framework itself because it may be a renderer too (e.g. angular)
382
- [name]: version2,
383
- ...dependencies,
384
- ...devDependencies,
385
- ...peerDependencies
386
- };
387
- return suffixes.map((suffix) => `@storybook/${suffix}`).find((pkg) => allDependencies[pkg]);
388
- }
389
- __name(findMatchingPackage, "findMatchingPackage");
390
- var getFrameworkPackageName = /* @__PURE__ */ __name((packageNameOrPath) => {
391
- const normalizedPath = normalize(packageNameOrPath).replace(new RegExp(/\\/, "g"), "/");
392
- const knownFramework = Object.keys(frameworkPackages).find((pkg) => normalizedPath.endsWith(pkg));
393
- return knownFramework || cleanPaths(packageNameOrPath).replace(/.*node_modules[\\/]/, "");
394
- }, "getFrameworkPackageName");
395
- async function getFrameworkInfo(mainConfig) {
396
- if (!mainConfig?.framework) {
397
- return {};
398
- }
399
- const rawName = typeof mainConfig.framework === "string" ? mainConfig.framework : mainConfig.framework?.name;
400
- if (!rawName) {
401
- return {};
402
- }
403
- const frameworkPackageJson = await getActualPackageJson(rawName);
404
- if (!frameworkPackageJson) {
405
- return {};
406
- }
407
- const builder = findMatchingPackage(frameworkPackageJson, knownBuilders);
408
- const renderer = findMatchingPackage(frameworkPackageJson, knownRenderers);
409
- const sanitizedFrameworkName = getFrameworkPackageName(rawName);
410
- const frameworkOptions = typeof mainConfig.framework === "object" ? mainConfig.framework.options : {};
411
- return {
412
- framework: {
413
- name: sanitizedFrameworkName,
414
- options: frameworkOptions
415
- },
416
- builder,
417
- renderer
418
- };
419
- }
420
- __name(getFrameworkInfo, "getFrameworkInfo");
421
-
422
- // src/telemetry/get-has-router-package.ts
423
- var routerPackages = /* @__PURE__ */ new Set([
424
- "react-router",
425
- "react-router-dom",
426
- "remix",
427
- "@tanstack/react-router",
428
- "expo-router",
429
- "@reach/router",
430
- "react-easy-router",
431
- "@remix-run/router",
432
- "wouter",
433
- "wouter-preact",
434
- "preact-router",
435
- "vue-router",
436
- "unplugin-vue-router",
437
- "@angular/router",
438
- "@solidjs/router",
439
- // metaframeworks that imply routing
440
- "next",
441
- "react-scripts",
442
- "gatsby",
443
- "nuxt",
444
- "@sveltejs/kit"
445
- ]);
446
- function getHasRouterPackage(packageJson) {
447
- return Object.keys(packageJson?.dependencies ?? {}).some(
448
- (depName) => routerPackages.has(depName)
449
- );
450
- }
451
- __name(getHasRouterPackage, "getHasRouterPackage");
452
-
453
- // src/telemetry/get-monorepo-type.ts
454
- import { existsSync, readFileSync } from "node:fs";
455
- import { join } from "node:path";
456
- import { getProjectRoot as getProjectRoot2 } from "storybook/internal/common";
457
- var monorepoConfigs = {
458
- Nx: "nx.json",
459
- Turborepo: "turbo.json",
460
- Lerna: "lerna.json",
461
- Rush: "rush.json",
462
- Lage: "lage.config.json"
463
- };
464
- var getMonorepoType = /* @__PURE__ */ __name(() => {
465
- const keys = Object.keys(monorepoConfigs);
466
- const monorepoType = keys.find((monorepo) => {
467
- const configFile = join(getProjectRoot2(), monorepoConfigs[monorepo]);
468
- return existsSync(configFile);
469
- });
470
- if (monorepoType) {
471
- return monorepoType;
472
- }
473
- if (!existsSync(join(getProjectRoot2(), "package.json"))) {
474
- return void 0;
475
- }
476
- const packageJson = JSON.parse(
477
- readFileSync(join(getProjectRoot2(), "package.json"), { encoding: "utf8" })
478
- );
479
- if (packageJson?.workspaces) {
480
- return "Workspaces";
481
- }
482
- return void 0;
483
- }, "getMonorepoType");
484
-
485
- // ../node_modules/package-manager-detector/dist/commands.mjs
486
- function dashDashArg(agent, agentCommand) {
487
- return (args) => {
488
- if (args.length > 1) {
489
- return [agent, agentCommand, args[0], "--", ...args.slice(1)];
490
- } else {
491
- return [agent, agentCommand, args[0]];
492
- }
493
- };
494
- }
495
- __name(dashDashArg, "dashDashArg");
496
- function denoExecute() {
497
- return (args) => {
498
- return ["deno", "run", `npm:${args[0]}`, ...args.slice(1)];
499
- };
500
- }
501
- __name(denoExecute, "denoExecute");
502
- var npm = {
503
- "agent": ["npm", 0],
504
- "run": dashDashArg("npm", "run"),
505
- "install": ["npm", "i", 0],
506
- "frozen": ["npm", "ci", 0],
507
- "global": ["npm", "i", "-g", 0],
508
- "add": ["npm", "i", 0],
509
- "upgrade": ["npm", "update", 0],
510
- "upgrade-interactive": null,
511
- "execute": ["npx", 0],
512
- "execute-local": ["npx", 0],
513
- "uninstall": ["npm", "uninstall", 0],
514
- "global_uninstall": ["npm", "uninstall", "-g", 0]
515
- };
516
- var yarn = {
517
- "agent": ["yarn", 0],
518
- "run": ["yarn", "run", 0],
519
- "install": ["yarn", "install", 0],
520
- "frozen": ["yarn", "install", "--frozen-lockfile", 0],
521
- "global": ["yarn", "global", "add", 0],
522
- "add": ["yarn", "add", 0],
523
- "upgrade": ["yarn", "upgrade", 0],
524
- "upgrade-interactive": ["yarn", "upgrade-interactive", 0],
525
- "execute": ["npx", 0],
526
- "execute-local": dashDashArg("yarn", "exec"),
527
- "uninstall": ["yarn", "remove", 0],
528
- "global_uninstall": ["yarn", "global", "remove", 0]
529
- };
530
- var yarnBerry = {
531
- ...yarn,
532
- "frozen": ["yarn", "install", "--immutable", 0],
533
- "upgrade": ["yarn", "up", 0],
534
- "upgrade-interactive": ["yarn", "up", "-i", 0],
535
- "execute": ["yarn", "dlx", 0],
536
- "execute-local": ["yarn", "exec", 0],
537
- // Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
538
- "global": ["npm", "i", "-g", 0],
539
- "global_uninstall": ["npm", "uninstall", "-g", 0]
540
- };
541
- var pnpm = {
542
- "agent": ["pnpm", 0],
543
- "run": ["pnpm", "run", 0],
544
- "install": ["pnpm", "i", 0],
545
- "frozen": ["pnpm", "i", "--frozen-lockfile", 0],
546
- "global": ["pnpm", "add", "-g", 0],
547
- "add": ["pnpm", "add", 0],
548
- "upgrade": ["pnpm", "update", 0],
549
- "upgrade-interactive": ["pnpm", "update", "-i", 0],
550
- "execute": ["pnpm", "dlx", 0],
551
- "execute-local": ["pnpm", "exec", 0],
552
- "uninstall": ["pnpm", "remove", 0],
553
- "global_uninstall": ["pnpm", "remove", "--global", 0]
554
- };
555
- var bun = {
556
- "agent": ["bun", 0],
557
- "run": ["bun", "run", 0],
558
- "install": ["bun", "install", 0],
559
- "frozen": ["bun", "install", "--frozen-lockfile", 0],
560
- "global": ["bun", "add", "-g", 0],
561
- "add": ["bun", "add", 0],
562
- "upgrade": ["bun", "update", 0],
563
- "upgrade-interactive": ["bun", "update", 0],
564
- "execute": ["bun", "x", 0],
565
- "execute-local": ["bun", "x", 0],
566
- "uninstall": ["bun", "remove", 0],
567
- "global_uninstall": ["bun", "remove", "-g", 0]
568
- };
569
- var deno = {
570
- "agent": ["deno", 0],
571
- "run": ["deno", "task", 0],
572
- "install": ["deno", "install", 0],
573
- "frozen": ["deno", "install", "--frozen", 0],
574
- "global": ["deno", "install", "-g", 0],
575
- "add": ["deno", "add", 0],
576
- "upgrade": ["deno", "outdated", "--update", 0],
577
- "upgrade-interactive": ["deno", "outdated", "--update", 0],
578
- "execute": denoExecute(),
579
- "execute-local": ["deno", "task", "--eval", 0],
580
- "uninstall": ["deno", "remove", 0],
581
- "global_uninstall": ["deno", "uninstall", "-g", 0]
582
- };
583
- var COMMANDS = {
584
- "npm": npm,
585
- "yarn": yarn,
586
- "yarn@berry": yarnBerry,
587
- "pnpm": pnpm,
588
- // pnpm v6.x or below
589
- "pnpm@6": {
590
- ...pnpm,
591
- run: dashDashArg("pnpm", "run")
592
- },
593
- "bun": bun,
594
- "deno": deno
595
- };
596
-
597
- // ../node_modules/package-manager-detector/dist/constants.mjs
598
- var AGENTS = [
599
- "npm",
600
- "yarn",
601
- "yarn@berry",
602
- "pnpm",
603
- "pnpm@6",
604
- "bun",
605
- "deno"
606
- ];
607
- var LOCKS = {
608
- "bun.lock": "bun",
609
- "bun.lockb": "bun",
610
- "deno.lock": "deno",
611
- "pnpm-lock.yaml": "pnpm",
612
- "pnpm-workspace.yaml": "pnpm",
613
- "yarn.lock": "yarn",
614
- "package-lock.json": "npm",
615
- "npm-shrinkwrap.json": "npm"
616
- };
617
- var INSTALL_METADATA = {
618
- "node_modules/.deno/": "deno",
619
- "node_modules/.pnpm/": "pnpm",
620
- "node_modules/.yarn-state.yml": "yarn",
621
- // yarn v2+ (node-modules)
622
- "node_modules/.yarn_integrity": "yarn",
623
- // yarn v1
624
- "node_modules/.package-lock.json": "npm",
625
- ".pnp.cjs": "yarn",
626
- // yarn v3+ (pnp)
627
- ".pnp.js": "yarn",
628
- // yarn v2 (pnp)
629
- "bun.lock": "bun",
630
- "bun.lockb": "bun"
631
- };
632
-
633
- // ../node_modules/package-manager-detector/dist/detect.mjs
634
- import fs from "node:fs/promises";
635
- import path2 from "node:path";
636
- import process2 from "node:process";
637
- async function pathExists(path22, type) {
638
- try {
639
- const stat = await fs.stat(path22);
640
- return type === "file" ? stat.isFile() : stat.isDirectory();
641
- } catch {
642
- return false;
643
- }
644
- }
645
- __name(pathExists, "pathExists");
646
- function* lookup(cwd = process2.cwd()) {
647
- let directory = path2.resolve(cwd);
648
- const { root } = path2.parse(directory);
649
- while (directory && directory !== root) {
650
- yield directory;
651
- directory = path2.dirname(directory);
652
- }
653
- }
654
- __name(lookup, "lookup");
655
- async function parsePackageJson(filepath, onUnknown) {
656
- return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
657
- }
658
- __name(parsePackageJson, "parsePackageJson");
659
- async function detect(options = {}) {
660
- const {
661
- cwd,
662
- strategies = ["lockfile", "packageManager-field", "devEngines-field"],
663
- onUnknown
664
- } = options;
665
- let stopDir;
666
- if (typeof options.stopDir === "string") {
667
- const resolved = path2.resolve(options.stopDir);
668
- stopDir = /* @__PURE__ */ __name((dir) => dir === resolved, "stopDir");
669
- } else {
670
- stopDir = options.stopDir;
671
- }
672
- for (const directory of lookup(cwd)) {
673
- for (const strategy of strategies) {
674
- switch (strategy) {
675
- case "lockfile": {
676
- for (const lock of Object.keys(LOCKS)) {
677
- if (await pathExists(path2.join(directory, lock), "file")) {
678
- const name = LOCKS[lock];
679
- const result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
680
- if (result)
681
- return result;
682
- else
683
- return { name, agent: name };
684
- }
685
- }
686
- break;
687
- }
688
- case "packageManager-field":
689
- case "devEngines-field": {
690
- const result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
691
- if (result)
692
- return result;
693
- break;
694
- }
695
- case "install-metadata": {
696
- for (const metadata of Object.keys(INSTALL_METADATA)) {
697
- const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
698
- if (await pathExists(path2.join(directory, metadata), fileOrDir)) {
699
- const name = INSTALL_METADATA[metadata];
700
- const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
701
- return { name, agent };
702
- }
703
- }
704
- break;
705
- }
706
- }
707
- }
708
- if (stopDir?.(directory))
709
- break;
710
- }
711
- return null;
712
- }
713
- __name(detect, "detect");
714
- function getNameAndVer(pkg) {
715
- const handelVer = /* @__PURE__ */ __name((version2) => version2?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version2, "handelVer");
716
- if (typeof pkg.packageManager === "string") {
717
- const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
718
- return { name, ver: handelVer(ver) };
719
- }
720
- if (typeof pkg.devEngines?.packageManager?.name === "string") {
721
- return {
722
- name: pkg.devEngines.packageManager.name,
723
- ver: handelVer(pkg.devEngines.packageManager.version)
724
- };
725
- }
726
- return void 0;
727
- }
728
- __name(getNameAndVer, "getNameAndVer");
729
- async function handlePackageManager(filepath, onUnknown) {
730
- try {
731
- const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
732
- let agent;
733
- const nameAndVer = getNameAndVer(pkg);
734
- if (nameAndVer) {
735
- const name = nameAndVer.name;
736
- const ver = nameAndVer.ver;
737
- let version2 = ver;
738
- if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
739
- agent = "yarn@berry";
740
- version2 = "berry";
741
- return { name, agent, version: version2 };
742
- } else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
743
- agent = "pnpm@6";
744
- return { name, agent, version: version2 };
745
- } else if (AGENTS.includes(name)) {
746
- agent = name;
747
- return { name, agent, version: version2 };
748
- } else {
749
- return onUnknown?.(pkg.packageManager) ?? null;
750
- }
751
- }
752
- } catch {
753
- }
754
- return null;
755
- }
756
- __name(handlePackageManager, "handlePackageManager");
757
- function isMetadataYarnClassic(metadataPath) {
758
- return metadataPath.endsWith(".yarn_integrity");
759
- }
760
- __name(isMetadataYarnClassic, "isMetadataYarnClassic");
761
-
762
- // src/telemetry/get-package-manager-info.ts
763
- var getPackageManagerInfo = /* @__PURE__ */ __name(async () => {
764
- const packageManagerType = await detect({ cwd: getProjectRoot() });
765
- if (!packageManagerType) {
766
- return void 0;
767
- }
768
- let nodeLinker = "node_modules";
769
- if (packageManagerType.name === "yarn") {
770
- try {
771
- const { stdout } = await execaCommand("yarn config get nodeLinker", {
772
- cwd: getProjectRoot()
773
- });
774
- nodeLinker = stdout.trim();
775
- } catch (e) {
776
- }
777
- }
778
- if (packageManagerType.name === "pnpm") {
779
- try {
780
- const { stdout } = await execaCommand("pnpm config get nodeLinker", {
781
- cwd: getProjectRoot()
782
- });
783
- nodeLinker = stdout.trim() ?? "isolated";
784
- } catch (e) {
785
- }
786
- }
787
- return {
788
- type: packageManagerType.name,
789
- version: packageManagerType.version,
790
- agent: packageManagerType.agent,
791
- nodeLinker
792
- };
793
- }, "getPackageManagerInfo");
794
-
795
- // src/telemetry/get-portable-stories-usage.ts
796
- var getPortableStoriesFileCountUncached = /* @__PURE__ */ __name(async (path3) => {
797
- try {
798
- const command = `git grep -l composeStor` + (path3 ? ` -- ${path3}` : "");
799
- return await execCommandCountLines(command);
800
- } catch (err) {
801
- return err.exitCode === 1 ? 0 : void 0;
802
- }
803
- }, "getPortableStoriesFileCountUncached");
804
- var getPortableStoriesFileCount = /* @__PURE__ */ __name(async (path3) => {
805
- return runTelemetryOperation(
806
- "portableStories",
807
- async () => getPortableStoriesFileCountUncached(path3)
808
- );
809
- }, "getPortableStoriesFileCount");
810
-
811
- // src/telemetry/storybook-metadata.ts
812
- var metaFrameworks = {
813
- next: "Next",
814
- "react-scripts": "CRA",
815
- gatsby: "Gatsby",
816
- "@nuxtjs/storybook": "nuxt",
817
- "@nrwl/storybook": "nx",
818
- "@vue/cli-service": "vue-cli",
819
- "@sveltejs/kit": "sveltekit",
820
- "@tanstack/react-router": "tanstack-react",
821
- "@react-router/dev": "react-router",
822
- "@remix-run/dev": "remix"
823
- };
824
- var sanitizeAddonName = /* @__PURE__ */ __name((name) => {
825
- return cleanPaths(name).replace(/\/dist\/.*/, "").replace(/\.[mc]?[tj]?s[x]?$/, "").replace(/\/register$/, "").replace(/\/manager$/, "").replace(/\/preset$/, "");
826
- }, "sanitizeAddonName");
827
- var computeStorybookMetadata = /* @__PURE__ */ __name(async ({
828
- packageJsonPath,
829
- packageJson,
830
- mainConfig,
831
- configDir
832
- }) => {
833
- const settings = isCI() ? void 0 : await globalSettings();
834
- const metadata = {
835
- generatedAt: (/* @__PURE__ */ new Date()).getTime(),
836
- userSince: settings?.value.userSince,
837
- hasCustomBabel: false,
838
- hasCustomWebpack: false,
839
- hasStaticDirs: false,
840
- hasStorybookEslint: false,
841
- refCount: 0
842
- };
843
- const allDependencies = {
844
- ...packageJson?.dependencies,
845
- ...packageJson?.devDependencies,
846
- ...packageJson?.peerDependencies
847
- };
848
- const metaFramework = Object.keys(allDependencies).find((dep) => !!metaFrameworks[dep]);
849
- if (metaFramework) {
850
- const { version: version2 } = await getActualPackageVersion(metaFramework);
851
- metadata.metaFramework = {
852
- name: metaFrameworks[metaFramework],
853
- packageName: metaFramework,
854
- version: version2 || "unknown"
855
- };
856
- }
857
- const testPackages = [
858
- "playwright",
859
- "vitest",
860
- "jest",
861
- "cypress",
862
- "nightwatch",
863
- "webdriver",
864
- "@web/test-runner",
865
- "puppeteer",
866
- "karma",
867
- "jasmine",
868
- "chai",
869
- "testing-library",
870
- "@ngneat/spectator",
871
- "wdio",
872
- "msw",
873
- "miragejs",
874
- "sinon",
875
- "chromatic"
876
- ];
877
- const testPackageDeps = Object.keys(allDependencies).filter(
878
- (dep) => testPackages.find((pkg) => dep.includes(pkg))
879
- );
880
- metadata.testPackages = Object.fromEntries(
881
- await Promise.all(
882
- testPackageDeps.map(async (dep) => [dep, (await getActualPackageVersion(dep))?.version])
883
- )
884
- );
885
- metadata.hasRouterPackage = getHasRouterPackage(packageJson);
886
- const monorepoType = getMonorepoType();
887
- if (monorepoType) {
888
- metadata.monorepo = monorepoType;
889
- }
890
- metadata.packageManager = await getPackageManagerInfo();
891
- const language = allDependencies.typescript ? "typescript" : "javascript";
892
- if (!mainConfig) {
893
- return {
894
- ...metadata,
895
- storybookVersionSpecifier: versions.storybook,
896
- language
897
- };
898
- }
899
- metadata.hasCustomBabel = !!mainConfig.babel;
900
- metadata.hasCustomWebpack = !!mainConfig.webpackFinal;
901
- metadata.hasStaticDirs = !!mainConfig.staticDirs;
902
- if (typeof mainConfig.typescript === "object") {
903
- metadata.typescriptOptions = mainConfig.typescript;
904
- }
905
- const frameworkInfo = await getFrameworkInfo(mainConfig);
906
- if (typeof mainConfig.refs === "object") {
907
- metadata.refCount = Object.keys(mainConfig.refs).length;
908
- }
909
- if (typeof mainConfig.features === "object") {
910
- metadata.features = mainConfig.features;
911
- }
912
- const addons = {};
913
- if (mainConfig.addons) {
914
- mainConfig.addons.forEach((addon) => {
915
- let addonName;
916
- let options;
917
- if (typeof addon === "string") {
918
- addonName = sanitizeAddonName(addon);
919
- } else {
920
- if (addon.name.includes("addon-essentials")) {
921
- options = addon.options;
922
- }
923
- addonName = sanitizeAddonName(addon.name);
924
- }
925
- addons[addonName] = {
926
- options,
927
- version: void 0
928
- };
929
- });
930
- }
931
- const chromaticVersionSpecifier = getChromaticVersionSpecifier(packageJson);
932
- if (chromaticVersionSpecifier) {
933
- addons.chromatic = {
934
- version: void 0,
935
- versionSpecifier: chromaticVersionSpecifier,
936
- options: void 0
937
- };
938
- }
939
- const addonVersions = await getActualPackageVersions(addons);
940
- addonVersions.forEach(({ name, version: version2 }) => {
941
- addons[name] = addons[name] || {
942
- name,
943
- version: version2
944
- };
945
- addons[name].version = version2 || void 0;
946
- });
947
- const addonNames = Object.keys(addons);
948
- const storybookPackages = Object.keys(allDependencies).filter((dep) => dep.includes("storybook") && !addonNames.includes(dep)).reduce((acc, dep) => {
949
- return {
950
- ...acc,
951
- [dep]: { version: void 0 }
952
- };
953
- }, {});
954
- const storybookPackageVersions = await getActualPackageVersions(storybookPackages);
955
- storybookPackageVersions.forEach(({ name, version: version2 }) => {
956
- storybookPackages[name] = storybookPackages[name] || {
957
- name,
958
- version: version2
959
- };
960
- storybookPackages[name].version = version2 || void 0;
961
- });
962
- const hasStorybookEslint = !!allDependencies["eslint-plugin-storybook"];
963
- const storybookInfo = await getStorybookInfo(configDir);
964
- try {
965
- const { previewConfigPath: previewConfig } = storybookInfo;
966
- if (previewConfig) {
967
- const config = await readConfig(previewConfig);
968
- const usesGlobals = !!(config.getFieldNode(["globals"]) || config.getFieldNode(["globalTypes"]));
969
- metadata.preview = { ...metadata.preview, usesGlobals };
970
- }
971
- } catch (e) {
972
- }
973
- const portableStoriesFileCount = await getPortableStoriesFileCount();
974
- const applicationFileCount = await getApplicationFileCount(dirname(packageJsonPath));
975
- return {
976
- ...metadata,
977
- ...frameworkInfo,
978
- portableStoriesFileCount,
979
- applicationFileCount,
980
- storybookVersion: version,
981
- storybookVersionSpecifier: storybookInfo.version,
982
- language,
983
- storybookPackages,
984
- addons,
985
- hasStorybookEslint
986
- };
987
- }, "computeStorybookMetadata");
988
- async function getPackageJsonDetails() {
989
- const packageJsonPath = up();
990
- if (packageJsonPath) {
991
- return {
992
- packageJsonPath,
993
- packageJson: JSON.parse(await readFile(packageJsonPath, "utf8"))
994
- };
995
- }
996
- return {
997
- packageJsonPath: process.cwd(),
998
- packageJson: {}
999
- };
1000
- }
1001
- __name(getPackageJsonDetails, "getPackageJsonDetails");
1002
- var cachedMetadata;
1003
- var getStorybookMetadata = /* @__PURE__ */ __name(async (_configDir) => {
1004
- if (cachedMetadata) {
1005
- return cachedMetadata;
1006
- }
1007
- const { packageJson, packageJsonPath } = await getPackageJsonDetails();
1008
- const configDir = (_configDir || getStorybookConfiguration(
1009
- String(packageJson?.scripts?.storybook || ""),
1010
- "-c",
1011
- "--config-dir"
1012
- )) ?? ".storybook";
1013
- const mainConfig = await loadMainConfig({ configDir }).catch(() => void 0);
1014
- cachedMetadata = await computeStorybookMetadata({
1015
- mainConfig,
1016
- packageJson,
1017
- packageJsonPath,
1018
- configDir
1019
- });
1020
- return cachedMetadata;
1021
- }, "getStorybookMetadata");
1022
-
1023
- // src/telemetry/telemetry.ts
1024
- var import_fetch_retry = __toESM(require_fetch_retry(), 1);
1025
- import { readFileSync as readFileSync2 } from "node:fs";
1026
- import * as os from "node:os";
1027
- import { join as join2 } from "node:path";
1028
- import { isCI as isCI2 } from "storybook/internal/common";
1029
-
1030
- // src/telemetry/anonymous-id.ts
1031
- import { relative } from "node:path";
1032
- import { getProjectRoot as getProjectRoot3 } from "storybook/internal/common";
1033
- import { execSync } from "child_process";
1034
-
1035
- // src/telemetry/one-way-hash.ts
1036
- import { createHash } from "crypto";
1037
- var oneWayHash = /* @__PURE__ */ __name((payload) => {
1038
- const hash = createHash("sha256");
1039
- hash.update("storybook-telemetry-salt");
1040
- hash.update(payload);
1041
- return hash.digest("hex");
1042
- }, "oneWayHash");
1043
-
1044
- // src/telemetry/anonymous-id.ts
1045
- function normalizeGitUrl(rawUrl) {
1046
- const urlWithoutHash = rawUrl.trim().replace(/#.*$/, "");
1047
- const urlWithoutUser = urlWithoutHash.replace(/^.*@/, "");
1048
- const urlWithoutScheme = urlWithoutUser.replace(/^.*\/\//, "");
1049
- const urlWithExtension = urlWithoutScheme.endsWith(".git") ? urlWithoutScheme : `${urlWithoutScheme}.git`;
1050
- return urlWithExtension.replace(":", "/");
1051
- }
1052
- __name(normalizeGitUrl, "normalizeGitUrl");
1053
- function unhashedProjectId(remoteUrl, projectRootPath) {
1054
- return `${normalizeGitUrl(remoteUrl)}${slash(projectRootPath)}`;
1055
- }
1056
- __name(unhashedProjectId, "unhashedProjectId");
1057
- var anonymousProjectId;
1058
- var getAnonymousProjectId = /* @__PURE__ */ __name(() => {
1059
- if (anonymousProjectId) {
1060
- return anonymousProjectId;
1061
- }
1062
- try {
1063
- const projectRootPath = relative(getProjectRoot3(), process.cwd());
1064
- const originBuffer = execSync(`git config --local --get remote.origin.url`, {
1065
- timeout: 1e3,
1066
- stdio: `pipe`
1067
- });
1068
- anonymousProjectId = oneWayHash(unhashedProjectId(String(originBuffer), projectRootPath));
1069
- } catch (_) {
1070
- }
1071
- return anonymousProjectId;
1072
- }, "getAnonymousProjectId");
1073
-
1074
- // src/telemetry/fetch.ts
1075
- var fetch = global.fetch;
1076
-
1077
- // src/telemetry/telemetry.ts
1078
- var retryingFetch = (0, import_fetch_retry.default)(fetch);
1079
- var URL = process.env.STORYBOOK_TELEMETRY_URL || "https://storybook.js.org/event-log";
1080
- var tasks = [];
1081
- var addToGlobalContext = /* @__PURE__ */ __name((key, value) => {
1082
- globalContext[key] = value;
1083
- }, "addToGlobalContext");
1084
- var getOperatingSystem = /* @__PURE__ */ __name(() => {
1085
- try {
1086
- const platform2 = os.platform();
1087
- if (platform2 === "win32") {
1088
- return "Windows";
1089
- }
1090
- if (platform2 === "darwin") {
1091
- return "macOS";
1092
- }
1093
- if (platform2 === "linux") {
1094
- return "Linux";
1095
- }
1096
- return `Other: ${platform2}`;
1097
- } catch (_err) {
1098
- return "Unknown";
1099
- }
1100
- }, "getOperatingSystem");
1101
- var globalContext = {
1102
- inCI: isCI2(),
1103
- isTTY: process.stdout.isTTY,
1104
- platform: getOperatingSystem(),
1105
- nodeVersion: process.versions.node,
1106
- storybookVersion: getVersionNumber()
1107
- };
1108
- var prepareRequest = /* @__PURE__ */ __name(async (data, context, options) => {
1109
- const { eventType, payload, metadata, ...rest } = data;
1110
- const sessionId = await getSessionId();
1111
- const eventId = nanoid();
1112
- const body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
1113
- return retryingFetch(URL, {
1114
- method: "post",
1115
- body: JSON.stringify(body),
1116
- headers: { "Content-Type": "application/json" },
1117
- retries: 3,
1118
- retryOn: [503, 504],
1119
- retryDelay: /* @__PURE__ */ __name((attempt) => 2 ** attempt * (typeof options?.retryDelay === "number" && !Number.isNaN(options?.retryDelay) ? options.retryDelay : 1e3), "retryDelay")
1120
- });
1121
- }, "prepareRequest");
1122
- function getVersionNumber() {
1123
- try {
1124
- return JSON.parse(readFileSync2(join2(resolvePackageDir("storybook"), "package.json"), "utf8")).version;
1125
- } catch (e) {
1126
- return version;
1127
- }
1128
- }
1129
- __name(getVersionNumber, "getVersionNumber");
1130
- async function sendTelemetry(data, options = { retryDelay: 1e3, immediate: false }) {
1131
- const { eventType, payload, metadata, ...rest } = data;
1132
- const context = options.stripMetadata ? globalContext : {
1133
- ...globalContext,
1134
- anonymousId: getAnonymousProjectId()
1135
- };
1136
- let request;
1137
- try {
1138
- request = prepareRequest(data, context, options);
1139
- tasks.push(request);
1140
- const sessionId = await getSessionId();
1141
- const eventId = nanoid();
1142
- const body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
1143
- const waitFor = options.immediate ? tasks : [request];
1144
- await Promise.all([...waitFor, set(eventType, body)]);
1145
- } catch (err) {
1146
- } finally {
1147
- tasks = tasks.filter((task) => task !== request);
1148
- }
1149
- }
1150
- __name(sendTelemetry, "sendTelemetry");
1151
-
1152
- // src/telemetry/index.ts
1153
- var isExampleStoryId = /* @__PURE__ */ __name((storyId) => storyId.startsWith("example-button--") || storyId.startsWith("example-header--") || storyId.startsWith("example-page--"), "isExampleStoryId");
1154
- var telemetry = /* @__PURE__ */ __name(async (eventType, payload = {}, options = {}) => {
1155
- if (eventType !== "boot" && options.notify !== false) {
1156
- await notify();
1157
- }
1158
- const telemetryData = {
1159
- eventType,
1160
- payload
1161
- };
1162
- try {
1163
- if (!options?.stripMetadata) {
1164
- telemetryData.metadata = await getStorybookMetadata(options?.configDir);
1165
- }
1166
- } catch (error) {
1167
- payload.metadataErrorMessage = sanitizeError(error).message;
1168
- if (options?.enableCrashReports) {
1169
- payload.metadataError = sanitizeError(error);
1170
- }
1171
- } finally {
1172
- const { error } = payload;
1173
- if (error) {
1174
- payload.error = sanitizeError(error);
1175
- }
1176
- if (!payload.error || options?.enableCrashReports) {
1177
- if (process.env?.STORYBOOK_TELEMETRY_DEBUG) {
1178
- logger2.info("\n[telemetry]");
1179
- logger2.info(JSON.stringify(telemetryData, null, 2));
1180
- }
1181
- await sendTelemetry(telemetryData, options);
1182
- }
1183
- }
1184
- }, "telemetry");
1185
-
1186
- export {
1187
- removeAnsiEscapeCodes,
1188
- cleanPaths,
1189
- sanitizeError,
1190
- metaFrameworks,
1191
- sanitizeAddonName,
1192
- computeStorybookMetadata,
1193
- getStorybookMetadata,
1194
- oneWayHash,
1195
- addToGlobalContext,
1196
- isExampleStoryId,
1197
- telemetry
1198
- };