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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
  2. package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
  3. package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
  4. package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-2XZMBGTA.js} +44 -109
  5. package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
  6. package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
  7. package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
  8. package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
  9. package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
  10. package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
  11. package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
  12. package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
  13. package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
  14. package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
  15. package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
  16. package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
  17. package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
  18. package/dist/_browser-chunks/chunk-FQ7SLVLR.js +66 -0
  19. package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
  20. package/dist/_browser-chunks/chunk-GFY5R5EY.js +47 -0
  21. package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
  22. package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
  23. package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
  24. package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
  25. package/dist/_browser-chunks/{chunk-OWPZQM2D.js → chunk-L4RMQ7D7.js} +60 -110
  26. package/dist/_browser-chunks/chunk-P4F4UVXX.js +951 -0
  27. package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
  28. package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
  29. package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
  30. package/dist/_browser-chunks/chunk-SS2NHR7W.js +2969 -0
  31. package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
  32. package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
  33. package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
  34. package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
  35. package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
  36. package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
  37. package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
  38. package/dist/_browser-chunks/{syntaxhighlighter-CAVLW7PM.js → syntaxhighlighter-IQDEPFLK.js} +704 -1848
  39. package/dist/_node-chunks/{builder-manager-57OYTFQ5.js → builder-manager-BDAQHXFI.js} +510 -1019
  40. package/dist/_node-chunks/camelcase-3C7DZZPX.js +37 -0
  41. package/dist/_node-chunks/chunk-2IIQTGNE.js +6024 -0
  42. package/dist/_node-chunks/chunk-56U5LEMP.js +3043 -0
  43. package/dist/_node-chunks/chunk-7LIRCAQE.js +20 -0
  44. package/dist/_node-chunks/chunk-7RN6TXKP.js +603 -0
  45. package/dist/_node-chunks/chunk-7SJ7PZNL.js +4523 -0
  46. package/dist/_node-chunks/{chunk-2GK7NW46.js → chunk-BG4RDXG7.js} +8 -10
  47. package/dist/_node-chunks/chunk-CBQKMXLQ.js +18 -0
  48. package/dist/_node-chunks/chunk-CN2IW2KQ.js +1564 -0
  49. package/dist/_node-chunks/chunk-CQMAU6UQ.js +943 -0
  50. package/dist/_node-chunks/{chunk-RG4Z25PY.js → chunk-D6ND3TVY.js} +116 -276
  51. package/dist/_node-chunks/chunk-DC355CYB.js +61 -0
  52. package/dist/_node-chunks/{chunk-EBYCXVVR.js → chunk-EVK2SBW5.js} +292 -688
  53. package/dist/_node-chunks/chunk-IXWEUXJ2.js +119 -0
  54. package/dist/_node-chunks/{chunk-6F6CCOXH.js → chunk-KVRF22SH.js} +469 -983
  55. package/dist/_node-chunks/chunk-LEDP4QQW.js +919 -0
  56. package/dist/_node-chunks/{chunk-C4KEDJ6O.js → chunk-MMVV6DGG.js} +8133 -8887
  57. package/dist/_node-chunks/chunk-O5CGEVRI.js +29 -0
  58. package/dist/_node-chunks/chunk-OZZO56XN.js +299 -0
  59. package/dist/_node-chunks/chunk-POT2EVGD.js +78 -0
  60. package/dist/_node-chunks/chunk-R5YGFSTV.js +3781 -0
  61. package/dist/_node-chunks/chunk-SQCTM2OS.js +23 -0
  62. package/dist/_node-chunks/chunk-UFOFO5H7.js +54 -0
  63. package/dist/_node-chunks/chunk-VBF7ALJF.js +72 -0
  64. package/dist/_node-chunks/chunk-W6MAMTUF.js +70 -0
  65. package/dist/_node-chunks/chunk-WURL4XOT.js +46662 -0
  66. package/dist/_node-chunks/chunk-XGK6MVKR.js +61 -0
  67. package/dist/_node-chunks/chunk-YV3GDSDT.js +765 -0
  68. package/dist/_node-chunks/{chunk-RSHLCHYY.js → chunk-YWV55YW3.js} +15 -24
  69. package/dist/_node-chunks/dist-KEP4IFRN.js +121 -0
  70. package/dist/_node-chunks/globby-4WUBTDCN.js +3452 -0
  71. package/dist/_node-chunks/lib-JVOEKTYM.js +366 -0
  72. package/dist/_node-chunks/mdx-N42X6CFJ-C5WFYYXR.js +14329 -0
  73. package/dist/_node-chunks/p-limit-LDY632RS.js +116 -0
  74. package/dist/actions/decorator.js +21 -42
  75. package/dist/actions/index.js +3 -3
  76. package/dist/babel/index.d.ts +671 -335
  77. package/dist/babel/index.js +10 -11
  78. package/dist/bin/core.js +601 -1548
  79. package/dist/bin/dispatcher.js +36 -36
  80. package/dist/bin/loader.js +24 -38
  81. package/dist/channels/index.js +98 -234
  82. package/dist/cli/index.d.ts +1479 -133
  83. package/dist/cli/index.js +30 -8540
  84. package/dist/client-logger/index.js +31 -61
  85. package/dist/common/index.d.ts +139 -62
  86. package/dist/common/index.js +66 -51
  87. package/dist/components/index.d.ts +575 -273
  88. package/dist/components/index.js +14863 -4313
  89. package/dist/core-events/index.js +2 -66
  90. package/dist/core-server/index.d.ts +3 -2
  91. package/dist/core-server/index.js +2910 -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 +11511 -10953
  106. package/dist/manager-api/index.d.ts +1811 -2
  107. package/dist/manager-api/index.js +1348 -2401
  108. package/dist/manager-errors.d.ts +9 -0
  109. package/dist/manager-errors.js +3 -3
  110. package/dist/mocking-utils/index.d.ts +1126 -0
  111. package/dist/mocking-utils/index.js +1181 -0
  112. package/dist/node-logger/index.d.ts +192 -24
  113. package/dist/node-logger/index.js +23 -4471
  114. package/dist/preview/globals.js +2 -3
  115. package/dist/preview/runtime.js +10799 -22393
  116. package/dist/preview-api/index.d.ts +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-2KEDZHZ2.js +0 -18
  161. package/dist/_node-chunks/chunk-34NNXTBR.js +0 -28
  162. package/dist/_node-chunks/chunk-3N2A3KZX.js +0 -420
  163. package/dist/_node-chunks/chunk-5P7P5KDN.js +0 -90
  164. package/dist/_node-chunks/chunk-5WBRBDXI.js +0 -79
  165. package/dist/_node-chunks/chunk-7PWTU7T2.js +0 -697
  166. package/dist/_node-chunks/chunk-CHRHQ7AZ.js +0 -4272
  167. package/dist/_node-chunks/chunk-D4EGQLJI.js +0 -64656
  168. package/dist/_node-chunks/chunk-EKCURTKU.js +0 -1544
  169. package/dist/_node-chunks/chunk-GBVPPW4H.js +0 -1657
  170. package/dist/_node-chunks/chunk-J6VOKT2F.js +0 -220
  171. package/dist/_node-chunks/chunk-JLBYSGXS.js +0 -69
  172. package/dist/_node-chunks/chunk-LLCELSUL.js +0 -1198
  173. package/dist/_node-chunks/chunk-NS4OCQ4F.js +0 -61
  174. package/dist/_node-chunks/chunk-NXVLFYDR.js +0 -1518
  175. package/dist/_node-chunks/chunk-NZPWAJOZ.js +0 -304
  176. package/dist/_node-chunks/chunk-OYFSIV3I.js +0 -6712
  177. package/dist/_node-chunks/chunk-OZ43LMDF.js +0 -5029
  178. package/dist/_node-chunks/chunk-Q5HJHFF2.js +0 -61
  179. package/dist/_node-chunks/chunk-QHER4CEN.js +0 -34
  180. package/dist/_node-chunks/chunk-RF2PJM54.js +0 -1531
  181. package/dist/_node-chunks/chunk-S3OHGEE3.js +0 -101
  182. package/dist/_node-chunks/chunk-S5XOMVSV.js +0 -2256
  183. package/dist/_node-chunks/chunk-SGXQZ47H.js +0 -1586
  184. package/dist/_node-chunks/chunk-TDU6OVUH.js +0 -111
  185. package/dist/_node-chunks/chunk-TYQQFNQX.js +0 -1250
  186. package/dist/_node-chunks/chunk-WNGLARN2.js +0 -4741
  187. package/dist/_node-chunks/chunk-YUOVDCXL.js +0 -18
  188. package/dist/_node-chunks/dist-O5FB7YUW.js +0 -175
  189. package/dist/_node-chunks/globby-3NMV7WHX.js +0 -5222
  190. package/dist/_node-chunks/lib-VZD7BRSA.js +0 -518
  191. package/dist/_node-chunks/mdx-N42X6CFJ-3RP7RKKU.js +0 -22017
  192. package/dist/_node-chunks/p-limit-LIKBTXEJ.js +0 -168
  193. package/dist/_node-chunks/plugin-2NYZBK4A.js +0 -129
  194. package/dist/_node-chunks/plugin-6QGMO7J7.js +0 -159
  195. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-Z2JI6J2H.js +0 -69102
  196. package/dist/_node-chunks/webpack-mock-plugin-D4BE2SSI.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,304 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_rqth4iav4b from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_rqth4iav4b from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_rqth4iav4b from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_rqth4iav4b.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_rqth4iav4b.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_rqth4iav4b.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- import {
13
- require_build
14
- } from "./chunk-7PWTU7T2.js";
15
- import {
16
- resolvePackageDir
17
- } from "./chunk-EKCURTKU.js";
18
- import {
19
- require_prompts
20
- } from "./chunk-OZ43LMDF.js";
21
- import {
22
- require_dist
23
- } from "./chunk-JLBYSGXS.js";
24
- import {
25
- require_picocolors
26
- } from "./chunk-RSHLCHYY.js";
27
- import {
28
- __name,
29
- __toESM
30
- } from "./chunk-Q5HJHFF2.js";
31
-
32
- // src/core-server/utils/server-statics.ts
33
- var import_picocolors = __toESM(require_picocolors(), 1);
34
- var import_sirv = __toESM(require_build(), 1);
35
- var import_ts_dedent = __toESM(require_dist(), 1);
36
- import { existsSync, statSync } from "node:fs";
37
- import { readFile, stat } from "node:fs/promises";
38
- import { basename, isAbsolute, join, posix, resolve, sep, win32 } from "node:path";
39
- import { getDirectoryFromWorkingDir, resolvePathInStorybookCache } from "storybook/internal/common";
40
- import { logger, once } from "storybook/internal/node-logger";
41
- var cacheDir = resolvePathInStorybookCache("", "ignored-sub").split("ignored-sub")[0];
42
- var files = /* @__PURE__ */ new Map();
43
- var readFileOnce = /* @__PURE__ */ __name(async (path) => {
44
- if (files.has(path)) {
45
- return files.get(path);
46
- } else {
47
- const [data, stats] = await Promise.all([readFile(path, "utf-8"), stat(path)]);
48
- const result = { data, mtime: stats.mtimeMs };
49
- files.set(path, result);
50
- return result;
51
- }
52
- }, "readFileOnce");
53
- var faviconWrapperPath = join(
54
- resolvePackageDir("storybook"),
55
- "/assets/browser/favicon-wrapper.svg"
56
- );
57
- var prepareNestedSvg = /* @__PURE__ */ __name((svg) => {
58
- const [, openingTag, contents, closingTag] = svg?.match(/(<svg[^>]*>)(.*?)(<\/svg>)/s) ?? [];
59
- if (!openingTag || !contents || !closingTag) {
60
- return svg;
61
- }
62
- let width;
63
- let height;
64
- let modifiedTag = openingTag.replace(/width=["']([^"']*)["']/g, (_, value) => {
65
- width = parseFloat(value);
66
- return 'width="32px"';
67
- }).replace(/height=["']([^"']*)["']/g, (_, value) => {
68
- height = parseFloat(value);
69
- return 'height="32px"';
70
- });
71
- const hasViewBox = /viewBox=["'][^"']*["']/.test(modifiedTag);
72
- if (!hasViewBox && width && height) {
73
- modifiedTag = modifiedTag.replace(/>$/, ` viewBox="0 0 ${width} ${height}">`);
74
- }
75
- modifiedTag = modifiedTag.replace(/preserveAspectRatio=["'][^"']*["']/g, "").replace(/>$/, ' preserveAspectRatio="xMidYMid meet">');
76
- return modifiedTag + contents + closingTag;
77
- }, "prepareNestedSvg");
78
- async function useStatics(app, options) {
79
- const staticDirs = await options.presets.apply("staticDirs") ?? [];
80
- const faviconPath = await options.presets.apply("favicon");
81
- const faviconDir = resolve(faviconPath, "..");
82
- const faviconFile = basename(faviconPath);
83
- app.use(`/${faviconFile}`, async (req, res, next) => {
84
- const status = req.query.status;
85
- if (status && faviconFile.endsWith(".svg") && ["active", "critical", "negative", "positive", "warning"].includes(status)) {
86
- const [faviconInfo, faviconWrapperInfo] = await Promise.all([
87
- readFileOnce(join(faviconDir, faviconFile)),
88
- readFileOnce(faviconWrapperPath)
89
- ]).catch((e) => {
90
- if (e instanceof Error) {
91
- once.warn(`Failed to read favicon: ${e.message}`);
92
- }
93
- return [null, null];
94
- });
95
- if (faviconInfo && faviconWrapperInfo) {
96
- const svg = faviconWrapperInfo.data.replace('<g id="mask"', `<g mask="url(#${status}-mask)"`).replace('<use id="status"', `<use href="#${status}"`).replace('<use id="icon" />', prepareNestedSvg(faviconInfo.data));
97
- res.setHeader("Content-Type", "image/svg+xml");
98
- res.setHeader("ETag", `"${faviconWrapperInfo.mtime}-${faviconInfo.mtime}"`);
99
- res.end(svg);
100
- return;
101
- }
102
- }
103
- req.url = `/${faviconFile}`;
104
- return sirvWorkaround(faviconDir)(req, res, next);
105
- });
106
- staticDirs.map((dir) => {
107
- try {
108
- const { staticDir, staticPath, targetEndpoint } = mapStaticDir(dir, options.configDir);
109
- if (!targetEndpoint.startsWith("/sb-") && !staticDir.startsWith(cacheDir)) {
110
- logger.info(
111
- `=> Serving static files from ${import_picocolors.default.cyan(staticDir)} at ${import_picocolors.default.cyan(targetEndpoint)}`
112
- );
113
- }
114
- if (existsSync(staticPath) && statSync(staticPath).isFile()) {
115
- const staticPathDir = resolve(staticPath, "..");
116
- const staticPathFile = basename(staticPath);
117
- app.use(targetEndpoint, (req, res, next) => {
118
- req.url = `/${staticPathFile}`;
119
- sirvWorkaround(staticPathDir)(req, res, next);
120
- });
121
- } else {
122
- app.use(targetEndpoint, sirvWorkaround(staticPath));
123
- }
124
- } catch (e) {
125
- if (e instanceof Error) {
126
- logger.warn(e.message);
127
- }
128
- }
129
- });
130
- }
131
- __name(useStatics, "useStatics");
132
- var sirvWorkaround = /* @__PURE__ */ __name((dir, opts = {}) => (req, res, next) => {
133
- const originalParsedUrl = req._parsedUrl;
134
- const maybeNext = next ? () => {
135
- req._parsedUrl = originalParsedUrl;
136
- next();
137
- } : void 0;
138
- (0, import_sirv.default)(dir, { dev: true, etag: true, extensions: [], ...opts })(req, res, maybeNext);
139
- }, "sirvWorkaround");
140
- var parseStaticDir = /* @__PURE__ */ __name((arg) => {
141
- const lastColonIndex = arg.lastIndexOf(":");
142
- const isWindowsAbsolute = win32.isAbsolute(arg);
143
- const isWindowsRawDirOnly = isWindowsAbsolute && lastColonIndex === 1;
144
- const splitIndex = lastColonIndex !== -1 && !isWindowsRawDirOnly ? lastColonIndex : arg.length;
145
- const [from, to] = [arg.slice(0, splitIndex), arg.slice(splitIndex + 1)];
146
- const staticDir = isAbsolute(from) ? from : `./${from}`;
147
- const staticPath = resolve(staticDir);
148
- if (!existsSync(staticPath)) {
149
- throw new Error(
150
- import_ts_dedent.dedent`
151
- Failed to load static files, no such directory: ${import_picocolors.default.cyan(staticPath)}
152
- Make sure this directory exists.
153
- `
154
- );
155
- }
156
- const targetRaw = to || (statSync(staticPath).isFile() ? basename(staticPath) : "/");
157
- const target = targetRaw.split(sep).join(posix.sep);
158
- const targetDir = target.replace(/^\/?/, "./");
159
- const targetEndpoint = targetDir.substring(1);
160
- return { staticDir, staticPath, targetDir, targetEndpoint };
161
- }, "parseStaticDir");
162
- var mapStaticDir = /* @__PURE__ */ __name((staticDir, configDir) => {
163
- const specifier = typeof staticDir === "string" ? staticDir : `${staticDir.from}:${staticDir.to}`;
164
- const normalizedDir = isAbsolute(specifier) ? specifier : getDirectoryFromWorkingDir({ configDir, workingDir: process.cwd(), directory: specifier });
165
- return parseStaticDir(normalizedDir);
166
- }, "mapStaticDir");
167
-
168
- // src/core-server/withTelemetry.ts
169
- var import_prompts = __toESM(require_prompts(), 1);
170
- import { HandledError, cache, isCI, loadAllPresets } from "storybook/internal/common";
171
- import { logger as logger2 } from "storybook/internal/node-logger";
172
- import { getPrecedingUpgrade, oneWayHash, telemetry } from "storybook/internal/telemetry";
173
- var promptCrashReports = /* @__PURE__ */ __name(async () => {
174
- if (isCI() || !process.stdout.isTTY) {
175
- return void 0;
176
- }
177
- const { enableCrashReports } = await (0, import_prompts.default)({
178
- type: "confirm",
179
- name: "enableCrashReports",
180
- message: `Would you like to help improve Storybook by sending anonymous crash reports?`,
181
- initial: true
182
- });
183
- await cache.set("enableCrashReports", enableCrashReports);
184
- return enableCrashReports;
185
- }, "promptCrashReports");
186
- async function getErrorLevel({
187
- cliOptions,
188
- presetOptions,
189
- skipPrompt
190
- }) {
191
- if (cliOptions.disableTelemetry) {
192
- return "none";
193
- }
194
- if (!presetOptions) {
195
- return "full";
196
- }
197
- const presets = await loadAllPresets(presetOptions);
198
- const core = await presets.apply("core");
199
- if (core?.enableCrashReports !== void 0) {
200
- return core.enableCrashReports ? "full" : "error";
201
- }
202
- if (core?.disableTelemetry) {
203
- return "none";
204
- }
205
- const valueFromCache = await cache.get("enableCrashReports") ?? await cache.get("enableCrashreports");
206
- if (valueFromCache !== void 0) {
207
- return valueFromCache ? "full" : "error";
208
- }
209
- if (skipPrompt) {
210
- return "error";
211
- }
212
- const valueFromPrompt = await promptCrashReports();
213
- if (valueFromPrompt !== void 0) {
214
- return valueFromPrompt ? "full" : "error";
215
- }
216
- return "full";
217
- }
218
- __name(getErrorLevel, "getErrorLevel");
219
- async function sendTelemetryError(_error, eventType, options) {
220
- try {
221
- let errorLevel = "error";
222
- try {
223
- errorLevel = await getErrorLevel(options);
224
- } catch (err) {
225
- }
226
- if (errorLevel !== "none") {
227
- const precedingUpgrade = await getPrecedingUpgrade();
228
- const error = _error;
229
- let errorHash;
230
- if ("message" in error) {
231
- errorHash = error.message ? oneWayHash(error.message) : "EMPTY_MESSAGE";
232
- } else {
233
- errorHash = "NO_MESSAGE";
234
- }
235
- const { code, name, category } = error;
236
- await telemetry(
237
- "error",
238
- {
239
- code,
240
- name,
241
- category,
242
- eventType,
243
- precedingUpgrade,
244
- error: errorLevel === "full" ? error : void 0,
245
- errorHash,
246
- // if we ever end up sending a non-error instance, we'd like to know
247
- isErrorInstance: error instanceof Error
248
- },
249
- {
250
- immediate: true,
251
- configDir: options.cliOptions.configDir || options.presetOptions?.configDir,
252
- enableCrashReports: errorLevel === "full"
253
- }
254
- );
255
- }
256
- } catch (err) {
257
- }
258
- }
259
- __name(sendTelemetryError, "sendTelemetryError");
260
- async function withTelemetry(eventType, options, run) {
261
- const enableTelemetry = !(options.cliOptions.disableTelemetry || options.cliOptions.test === true);
262
- let canceled = false;
263
- async function cancelTelemetry() {
264
- canceled = true;
265
- if (enableTelemetry) {
266
- await telemetry("canceled", { eventType }, { stripMetadata: true, immediate: true });
267
- }
268
- process.exit(0);
269
- }
270
- __name(cancelTelemetry, "cancelTelemetry");
271
- if (eventType === "init") {
272
- process.on("SIGINT", cancelTelemetry);
273
- }
274
- if (enableTelemetry) {
275
- telemetry("boot", { eventType }, { stripMetadata: true });
276
- }
277
- try {
278
- return await run();
279
- } catch (error) {
280
- if (canceled) {
281
- return void 0;
282
- }
283
- if (!(error instanceof HandledError)) {
284
- const { printError = logger2.error } = options;
285
- printError(error);
286
- }
287
- if (enableTelemetry) {
288
- await sendTelemetryError(error, eventType, options);
289
- }
290
- throw error;
291
- } finally {
292
- process.off("SIGINT", cancelTelemetry);
293
- }
294
- }
295
- __name(withTelemetry, "withTelemetry");
296
-
297
- export {
298
- useStatics,
299
- parseStaticDir,
300
- mapStaticDir,
301
- getErrorLevel,
302
- sendTelemetryError,
303
- withTelemetry
304
- };