storybook 10.2.0-alpha.16 → 10.2.0-alpha.18

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 (70) hide show
  1. package/dist/_node-chunks/{builder-manager-DQ6DNDHX.js → builder-manager-RC5VXLE2.js} +14 -12
  2. package/dist/_node-chunks/{camelcase-ILOVTISA.js → camelcase-3YERF6B7.js} +7 -7
  3. package/dist/_node-chunks/chunk-2H33L3XJ.js +61 -0
  4. package/dist/_node-chunks/{chunk-47ZRY4XW.js → chunk-2M7TBZBZ.js} +6 -6
  5. package/dist/_node-chunks/{chunk-TTACLBSG.js → chunk-4HG57EIN.js} +7 -7
  6. package/dist/_node-chunks/{chunk-CFXIZS6A.js → chunk-4PWGJYBL.js} +7 -7
  7. package/dist/_node-chunks/{chunk-K6FMM5LS.js → chunk-54FLVGBQ.js} +6 -6
  8. package/dist/_node-chunks/{chunk-3PMH6BEP.js → chunk-5BYTBW23.js} +6 -6
  9. package/dist/_node-chunks/{chunk-TDBTCAEB.js → chunk-5QNVOHBZ.js} +125 -73
  10. package/dist/_node-chunks/{chunk-SWN4HCJE.js → chunk-6TOW3ZMZ.js} +6 -6
  11. package/dist/_node-chunks/{chunk-FNQ5WLS5.js → chunk-A2364FS2.js} +7 -7
  12. package/dist/_node-chunks/{chunk-ZN5DGHF3.js → chunk-BWA66NDS.js} +10 -10
  13. package/dist/_node-chunks/{chunk-RIEIAV32.js → chunk-DIZCVGPK.js} +7 -7
  14. package/dist/_node-chunks/{chunk-PGYIGHRK.js → chunk-F347QVLI.js} +9 -9
  15. package/dist/_node-chunks/chunk-GJRLPTXZ.js +144 -0
  16. package/dist/_node-chunks/{chunk-LOJ73E6E.js → chunk-H4TYBETM.js} +9 -9
  17. package/dist/_node-chunks/{chunk-IVYTDHSW.js → chunk-HXE2FZ3F.js} +7 -7
  18. package/dist/_node-chunks/{chunk-KAAWGCHX.js → chunk-IHBEBZVB.js} +12 -12
  19. package/dist/_node-chunks/chunk-JK62DOZL.js +23 -0
  20. package/dist/_node-chunks/{chunk-WVXPIXUS.js → chunk-LMYIILVH.js} +7 -7
  21. package/dist/_node-chunks/{chunk-XWGABQX7.js → chunk-N73BCSUL.js} +6 -6
  22. package/dist/_node-chunks/{chunk-OKUHCLLJ.js → chunk-OT3P3RDM.js} +9 -9
  23. package/dist/_node-chunks/{chunk-JXU4P6K3.js → chunk-OZGI27C5.js} +6 -6
  24. package/dist/_node-chunks/{chunk-6QEWR44T.js → chunk-OZHRGJKY.js} +7 -7
  25. package/dist/_node-chunks/chunk-Q3WHGQXN.js +18 -0
  26. package/dist/_node-chunks/{chunk-TLGG6YAX.js → chunk-QNYGS5WG.js} +511 -127
  27. package/dist/_node-chunks/{chunk-WIOSV6HC.js → chunk-QXDUEJWP.js} +6 -6
  28. package/dist/_node-chunks/{chunk-M6AUSQA3.js → chunk-USLMTVEL.js} +22 -22
  29. package/dist/_node-chunks/{chunk-YFUVKP3W.js → chunk-XH6HLMNG.js} +7 -7
  30. package/dist/_node-chunks/{chunk-XJMJA2L4.js → chunk-ZUTW3EKD.js} +250 -14
  31. package/dist/_node-chunks/{globby-A35XB3PP.js → globby-IVEL6LAU.js} +9 -9
  32. package/dist/_node-chunks/{lib-D5I6ETBH.js → lib-IDUN2DHZ.js} +7 -7
  33. package/dist/_node-chunks/{mdx-N42X6CFJ-DZ4EAFAE.js → mdx-N42X6CFJ-V7NAUWUX.js} +8 -8
  34. package/dist/_node-chunks/{p-limit-2CRKZRXN.js → p-limit-VA3OYXXM.js} +7 -7
  35. package/dist/babel/index.js +10 -10
  36. package/dist/bin/core.js +12 -12
  37. package/dist/bin/dispatcher.js +11 -11
  38. package/dist/bin/loader.js +9 -9
  39. package/dist/cli/index.js +18 -18
  40. package/dist/common/index.js +19 -19
  41. package/dist/components/index.d.ts +2 -1
  42. package/dist/components/index.js +55 -60
  43. package/dist/core-events/index.d.ts +19 -3
  44. package/dist/core-events/index.js +5 -1
  45. package/dist/core-server/index.d.ts +69 -2
  46. package/dist/core-server/index.js +38 -34
  47. package/dist/core-server/presets/common-override-preset.js +11 -11
  48. package/dist/core-server/presets/common-preset.js +519 -234
  49. package/dist/csf/index.d.ts +15 -3
  50. package/dist/csf/index.js +37 -13
  51. package/dist/csf-tools/index.d.ts +19 -1
  52. package/dist/csf-tools/index.js +11 -10
  53. package/dist/manager/globals-runtime.js +107 -81
  54. package/dist/manager/runtime.js +829 -167
  55. package/dist/manager-api/index.d.ts +2 -0
  56. package/dist/manager-api/index.js +10 -2
  57. package/dist/mocking-utils/index.js +8 -8
  58. package/dist/node-logger/index.js +9 -9
  59. package/dist/preview/runtime.js +33 -6
  60. package/dist/preview-api/index.d.ts +68 -67
  61. package/dist/server-errors.js +11 -11
  62. package/dist/telemetry/index.d.ts +14 -2
  63. package/dist/telemetry/index.js +23 -22
  64. package/dist/theming/index.js +16 -0
  65. package/dist/types/index.d.ts +2 -0
  66. package/package.json +2 -1
  67. package/dist/_node-chunks/chunk-5E2HAJXY.js +0 -35
  68. package/dist/_node-chunks/chunk-DGLVYUKY.js +0 -61
  69. package/dist/_node-chunks/chunk-MSK3YTQT.js +0 -23
  70. package/dist/_node-chunks/chunk-SPPXK6CQ.js +0 -18
@@ -1,54 +1,63 @@
1
- import CJS_COMPAT_NODE_URL_4zwbyhk64wx from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_4zwbyhk64wx from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_4zwbyhk64wx from "node:module";
1
+ import CJS_COMPAT_NODE_URL_bfa4dw0yocr from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_bfa4dw0yocr from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_bfa4dw0yocr from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_4zwbyhk64wx.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_4zwbyhk64wx.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_4zwbyhk64wx.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_bfa4dw0yocr.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_bfa4dw0yocr.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_bfa4dw0yocr.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import "../../_node-chunks/chunk-KAAWGCHX.js";
12
+ import "../../_node-chunks/chunk-IHBEBZVB.js";
13
13
  import {
14
+ doesStoryFileExist,
15
+ generateStoryFile,
16
+ getStoryMetadata,
14
17
  parseStaticDir,
15
18
  sendTelemetryError,
16
19
  throttle
17
- } from "../../_node-chunks/chunk-XJMJA2L4.js";
18
- import "../../_node-chunks/chunk-MSK3YTQT.js";
19
- import "../../_node-chunks/chunk-CFXIZS6A.js";
20
- import "../../_node-chunks/chunk-K6FMM5LS.js";
20
+ } from "../../_node-chunks/chunk-ZUTW3EKD.js";
21
+ import "../../_node-chunks/chunk-JK62DOZL.js";
22
+ import "../../_node-chunks/chunk-4PWGJYBL.js";
23
+ import "../../_node-chunks/chunk-54FLVGBQ.js";
24
+ import {
25
+ isI18nPackage,
26
+ isRouterPackage,
27
+ isStateManagementPackage,
28
+ isStylingPackage
29
+ } from "../../_node-chunks/chunk-GJRLPTXZ.js";
21
30
  import {
22
31
  globalSettings
23
- } from "../../_node-chunks/chunk-LOJ73E6E.js";
32
+ } from "../../_node-chunks/chunk-H4TYBETM.js";
24
33
  import {
25
34
  invariant
26
- } from "../../_node-chunks/chunk-JXU4P6K3.js";
27
- import "../../_node-chunks/chunk-SWN4HCJE.js";
35
+ } from "../../_node-chunks/chunk-OZGI27C5.js";
36
+ import "../../_node-chunks/chunk-6TOW3ZMZ.js";
28
37
  import {
29
38
  resolvePackageDir
30
- } from "../../_node-chunks/chunk-RIEIAV32.js";
39
+ } from "../../_node-chunks/chunk-DIZCVGPK.js";
31
40
  import {
32
41
  isAbsolute,
33
42
  join
34
- } from "../../_node-chunks/chunk-XWGABQX7.js";
43
+ } from "../../_node-chunks/chunk-N73BCSUL.js";
35
44
  import {
36
- loadConfig
37
- } from "../../_node-chunks/chunk-TLGG6YAX.js";
38
- import "../../_node-chunks/chunk-5E2HAJXY.js";
45
+ glob
46
+ } from "../../_node-chunks/chunk-OZHRGJKY.js";
47
+ import "../../_node-chunks/chunk-QNYGS5WG.js";
39
48
  import {
40
49
  require_dist
41
- } from "../../_node-chunks/chunk-YFUVKP3W.js";
42
- import "../../_node-chunks/chunk-PGYIGHRK.js";
43
- import "../../_node-chunks/chunk-WVXPIXUS.js";
50
+ } from "../../_node-chunks/chunk-XH6HLMNG.js";
51
+ import "../../_node-chunks/chunk-F347QVLI.js";
52
+ import "../../_node-chunks/chunk-LMYIILVH.js";
44
53
  import {
45
54
  require_picocolors
46
- } from "../../_node-chunks/chunk-FNQ5WLS5.js";
55
+ } from "../../_node-chunks/chunk-A2364FS2.js";
47
56
  import {
48
57
  __commonJS,
49
58
  __require,
50
59
  __toESM
51
- } from "../../_node-chunks/chunk-3PMH6BEP.js";
60
+ } from "../../_node-chunks/chunk-5BYTBW23.js";
52
61
 
53
62
  // ../../node_modules/shell-quote/quote.js
54
63
  var require_quote = __commonJS({
@@ -472,8 +481,8 @@ var require_launch_editor = __commonJS({
472
481
  });
473
482
 
474
483
  // src/core-server/presets/common-preset.ts
475
- import { existsSync as existsSync3 } from "node:fs";
476
- import { readFile as readFile3 } from "node:fs/promises";
484
+ import { existsSync as existsSync2 } from "node:fs";
485
+ import { readFile as readFile4 } from "node:fs/promises";
477
486
  import { normalizeStories, optionalEnvToBoolean } from "storybook/internal/common";
478
487
  import {
479
488
  JsPackageManagerFactory,
@@ -486,191 +495,51 @@ import {
486
495
  import { StoryIndexGenerator } from "storybook/internal/core-server";
487
496
  import { readCsf as readCsf2 } from "storybook/internal/csf-tools";
488
497
  import { logger as logger4 } from "storybook/internal/node-logger";
489
- import { telemetry as telemetry8 } from "storybook/internal/telemetry";
490
- var import_ts_dedent4 = __toESM(require_dist(), 1);
498
+ import { telemetry as telemetry9 } from "storybook/internal/telemetry";
499
+ var import_ts_dedent = __toESM(require_dist(), 1);
491
500
 
492
501
  // src/core-server/server-channel/create-new-story-channel.ts
493
- import { existsSync as existsSync2 } from "node:fs";
494
- import { writeFile } from "node:fs/promises";
495
- import { relative } from "node:path";
496
- import { getStoryId } from "storybook/internal/common";
497
502
  import {
498
503
  CREATE_NEW_STORYFILE_REQUEST,
499
504
  CREATE_NEW_STORYFILE_RESPONSE
500
505
  } from "storybook/internal/core-events";
501
506
  import { telemetry } from "storybook/internal/telemetry";
502
-
503
- // src/core-server/utils/get-new-story-file.ts
504
- import { existsSync } from "node:fs";
505
- import { readFile } from "node:fs/promises";
506
- import { basename, dirname, extname, join as join2 } from "node:path";
507
- import {
508
- extractFrameworkPackageName,
509
- findConfigFile,
510
- getFrameworkName,
511
- getProjectRoot
512
- } from "storybook/internal/common";
513
- import { isCsfFactoryPreview } from "storybook/internal/csf-tools";
514
-
515
- // src/core-server/utils/new-story-templates/csf-factory-template.ts
516
- var import_ts_dedent = __toESM(require_dist(), 1);
517
-
518
- // src/core-server/utils/get-component-variable-name.ts
519
- var getComponentVariableName = async (name) => (await import("../../_node-chunks/camelcase-ILOVTISA.js")).default(name.replace(/^[^a-zA-Z_$]*/, ""), { pascalCase: !0 }).replace(/[^a-zA-Z_$]+/, "");
520
-
521
- // src/core-server/utils/new-story-templates/csf-factory-template.ts
522
- async function getCsfFactoryTemplateForNewStoryFile(data) {
523
- let importName = data.componentIsDefaultExport ? await getComponentVariableName(data.basenameWithoutExtension) : data.componentExportName, importStatement = data.componentIsDefaultExport ? `import ${importName} from './${data.basenameWithoutExtension}';` : `import { ${importName} } from './${data.basenameWithoutExtension}';`;
524
- return import_ts_dedent.dedent`
525
- ${"import preview from '#.storybook/preview';"}
526
-
527
- ${importStatement}
528
-
529
- const meta = preview.meta({
530
- component: ${importName},
531
- });
532
-
533
- export const ${data.exportedStoryName} = meta.story({});
534
- `;
535
- }
536
-
537
- // src/core-server/utils/new-story-templates/javascript.ts
538
- var import_ts_dedent2 = __toESM(require_dist(), 1);
539
- async function getJavaScriptTemplateForNewStoryFile(data) {
540
- let importName = data.componentIsDefaultExport ? await getComponentVariableName(data.basenameWithoutExtension) : data.componentExportName, importStatement = data.componentIsDefaultExport ? `import ${importName} from './${data.basenameWithoutExtension}';` : `import { ${importName} } from './${data.basenameWithoutExtension}';`;
541
- return import_ts_dedent2.dedent`
542
- ${importStatement}
543
-
544
- const meta = {
545
- component: ${importName},
546
- };
547
-
548
- export default meta;
549
-
550
- export const ${data.exportedStoryName} = {};
551
- `;
552
- }
553
-
554
- // src/core-server/utils/new-story-templates/typescript.ts
555
- var import_ts_dedent3 = __toESM(require_dist(), 1);
556
- async function getTypeScriptTemplateForNewStoryFile(data) {
557
- let importName = data.componentIsDefaultExport ? await getComponentVariableName(data.basenameWithoutExtension) : data.componentExportName, importStatement = data.componentIsDefaultExport ? `import ${importName} from './${data.basenameWithoutExtension}'` : `import { ${importName} } from './${data.basenameWithoutExtension}'`;
558
- return import_ts_dedent3.dedent`
559
- import type { Meta, StoryObj } from '${data.frameworkPackage}';
560
-
561
- ${importStatement};
562
-
563
- const meta = {
564
- component: ${importName},
565
- } satisfies Meta<typeof ${importName}>;
566
-
567
- export default meta;
568
-
569
- type Story = StoryObj<typeof meta>;
570
-
571
- export const ${data.exportedStoryName}: Story = {};
572
- `;
573
- }
574
-
575
- // src/core-server/utils/get-new-story-file.ts
576
- async function getNewStoryFile({
577
- componentFilePath,
578
- componentExportName,
579
- componentIsDefaultExport,
580
- componentExportCount
581
- }, options) {
582
- let frameworkPackageName = await getFrameworkName(options), sanitizedFrameworkPackageName = extractFrameworkPackageName(frameworkPackageName), base = basename(componentFilePath), extension = extname(componentFilePath), basenameWithoutExtension = base.replace(extension, ""), dir = dirname(componentFilePath), { storyFileName, isTypescript, storyFileExtension } = getStoryMetadata(componentFilePath), storyFileNameWithExtension = `${storyFileName}.${storyFileExtension}`, alternativeStoryFileNameWithExtension = `${basenameWithoutExtension}.${componentExportName}.stories.${storyFileExtension}`, exportedStoryName = "Default", useCsfFactory = !1;
583
- try {
584
- let previewConfig = findConfigFile("preview", options.configDir);
585
- if (previewConfig) {
586
- let previewContent = await readFile(previewConfig, "utf-8");
587
- useCsfFactory = isCsfFactoryPreview(loadConfig(previewContent));
588
- }
589
- } catch {
590
- }
591
- let storyFileContent = "";
592
- return useCsfFactory ? storyFileContent = await getCsfFactoryTemplateForNewStoryFile({
593
- basenameWithoutExtension,
594
- componentExportName,
595
- componentIsDefaultExport,
596
- exportedStoryName
597
- }) : storyFileContent = isTypescript && frameworkPackageName ? await getTypeScriptTemplateForNewStoryFile({
598
- basenameWithoutExtension,
599
- componentExportName,
600
- componentIsDefaultExport,
601
- frameworkPackage: sanitizedFrameworkPackageName,
602
- exportedStoryName
603
- }) : await getJavaScriptTemplateForNewStoryFile({
604
- basenameWithoutExtension,
605
- componentExportName,
606
- componentIsDefaultExport,
607
- exportedStoryName
608
- }), { storyFilePath: doesStoryFileExist(join2(getProjectRoot(), dir), storyFileName) && componentExportCount > 1 ? join2(getProjectRoot(), dir, alternativeStoryFileNameWithExtension) : join2(getProjectRoot(), dir, storyFileNameWithExtension), exportedStoryName, storyFileContent, dirname };
609
- }
610
- var getStoryMetadata = (componentFilePath) => {
611
- let isTypescript = /\.(ts|tsx|mts|cts)$/.test(componentFilePath), base = basename(componentFilePath), extension = extname(componentFilePath), basenameWithoutExtension = base.replace(extension, ""), storyFileExtension = isTypescript ? "tsx" : "jsx";
612
- return {
613
- storyFileName: `${basenameWithoutExtension}.stories`,
614
- storyFileExtension,
615
- isTypescript
616
- };
617
- }, doesStoryFileExist = (parentFolder, storyFileName) => existsSync(join2(parentFolder, `${storyFileName}.ts`)) || existsSync(join2(parentFolder, `${storyFileName}.tsx`)) || existsSync(join2(parentFolder, `${storyFileName}.js`)) || existsSync(join2(parentFolder, `${storyFileName}.jsx`));
618
-
619
- // src/core-server/server-channel/create-new-story-channel.ts
620
507
  function initCreateNewStoryChannel(channel, options, coreOptions) {
621
508
  return channel.on(
622
509
  CREATE_NEW_STORYFILE_REQUEST,
623
510
  async (data) => {
624
- try {
625
- let { storyFilePath, exportedStoryName, storyFileContent } = await getNewStoryFile(
626
- data.payload,
627
- options
628
- ), relativeStoryFilePath = relative(process.cwd(), storyFilePath), { storyId, kind } = await getStoryId({ storyFilePath, exportedStoryName }, options);
629
- if (existsSync2(storyFilePath)) {
630
- channel.emit(CREATE_NEW_STORYFILE_RESPONSE, {
631
- success: !1,
632
- id: data.id,
633
- payload: {
634
- type: "STORY_FILE_EXISTS",
635
- kind
636
- },
637
- error: `A story file already exists at ${relativeStoryFilePath}`
638
- }), coreOptions.disableTelemetry || telemetry("create-new-story-file", {
639
- success: !1,
640
- error: "STORY_FILE_EXISTS"
641
- });
642
- return;
643
- }
644
- await writeFile(storyFilePath, storyFileContent, "utf-8"), channel.emit(CREATE_NEW_STORYFILE_RESPONSE, {
645
- success: !0,
646
- id: data.id,
647
- payload: {
648
- storyId,
649
- storyFilePath: relative(process.cwd(), storyFilePath),
650
- exportedStoryName
651
- },
652
- error: null
653
- }), coreOptions.disableTelemetry || telemetry("create-new-story-file", {
654
- success: !0
655
- });
656
- } catch (e) {
657
- channel.emit(CREATE_NEW_STORYFILE_RESPONSE, {
658
- success: !1,
659
- id: data.id,
660
- error: e?.message
661
- }), coreOptions.disableTelemetry || await telemetry("create-new-story-file", {
662
- success: !1,
663
- error: e
664
- });
665
- }
511
+ let result = await generateStoryFile(data.payload, options);
512
+ result.success ? (channel.emit(CREATE_NEW_STORYFILE_RESPONSE, {
513
+ success: !0,
514
+ id: data.id,
515
+ payload: {
516
+ storyId: result.storyId,
517
+ storyFilePath: result.storyFilePath,
518
+ exportedStoryName: result.exportedStoryName
519
+ },
520
+ error: null
521
+ }), coreOptions.disableTelemetry || telemetry("create-new-story-file", {
522
+ success: !0
523
+ })) : (channel.emit(CREATE_NEW_STORYFILE_RESPONSE, {
524
+ success: !1,
525
+ id: data.id,
526
+ payload: result.errorType === "STORY_FILE_EXISTS" ? {
527
+ type: "STORY_FILE_EXISTS",
528
+ kind: result.kind
529
+ } : void 0,
530
+ error: result.error || "Unknown error occurred"
531
+ }), coreOptions.disableTelemetry || await telemetry("create-new-story-file", {
532
+ success: !1,
533
+ error: result.errorType || result.error
534
+ }));
666
535
  }
667
536
  ), channel;
668
537
  }
669
538
 
670
539
  // src/core-server/server-channel/file-search-channel.ts
671
- import { readFile as readFile2 } from "node:fs/promises";
672
- import { dirname as dirname2, join as join3 } from "node:path";
673
- import { extractRenderer, getFrameworkName as getFrameworkName2, getProjectRoot as getProjectRoot2 } from "storybook/internal/common";
540
+ import { readFile } from "node:fs/promises";
541
+ import { dirname, join as join2 } from "node:path";
542
+ import { extractRenderer, getFrameworkName, getProjectRoot } from "storybook/internal/common";
674
543
  import {
675
544
  FILE_COMPONENT_SEARCH_REQUEST,
676
545
  FILE_COMPONENT_SEARCH_RESPONSE
@@ -781,7 +650,7 @@ async function searchFiles({
781
650
  ignoredFiles = IGNORED_FILES,
782
651
  fileExtensions = FILE_EXTENSIONS
783
652
  }) {
784
- let { globby, isDynamicPattern } = await import("../../_node-chunks/globby-A35XB3PP.js"), hasSearchSpecialGlobChars = isDynamicPattern(searchQuery, { cwd }), searchQueryHasExtension = /(\.[a-z]+)$/i.test(searchQuery), fileExtensionsPattern = `{${fileExtensions.join(",")}}`, globbedSearchQuery = hasSearchSpecialGlobChars ? searchQuery : searchQueryHasExtension ? [`**/*${searchQuery}*`, `**/*${searchQuery}*/**`] : [
653
+ let { globby, isDynamicPattern } = await import("../../_node-chunks/globby-IVEL6LAU.js"), hasSearchSpecialGlobChars = isDynamicPattern(searchQuery, { cwd }), searchQueryHasExtension = /(\.[a-z]+)$/i.test(searchQuery), fileExtensionsPattern = `{${fileExtensions.join(",")}}`, globbedSearchQuery = hasSearchSpecialGlobChars ? searchQuery : searchQueryHasExtension ? [`**/*${searchQuery}*`, `**/*${searchQuery}*/**`] : [
785
654
  `**/*${searchQuery}*.${fileExtensionsPattern}`,
786
655
  `**/*${searchQuery}*/**/*.${fileExtensionsPattern}`
787
656
  ];
@@ -803,13 +672,13 @@ async function initFileSearchChannel(channel, options, coreOptions) {
803
672
  try {
804
673
  if (!searchQuery)
805
674
  return;
806
- let frameworkName = await getFrameworkName2(options), rendererName = await extractRenderer(frameworkName), entries = (await searchFiles({
675
+ let frameworkName = await getFrameworkName(options), rendererName = await extractRenderer(frameworkName), entries = (await searchFiles({
807
676
  searchQuery,
808
- cwd: getProjectRoot2()
677
+ cwd: getProjectRoot()
809
678
  })).map(async (file) => {
810
679
  let parser3 = getParser(rendererName);
811
680
  try {
812
- let content = await readFile2(join3(getProjectRoot2(), file), "utf-8"), { storyFileName } = getStoryMetadata(join3(getProjectRoot2(), file)), dir = dirname2(file), storyFileExists = doesStoryFileExist(join3(getProjectRoot2(), dir), storyFileName), info = await parser3.parse(content);
681
+ let content = await readFile(join2(getProjectRoot(), file), "utf-8"), { storyFileName } = getStoryMetadata(join2(getProjectRoot(), file)), dir = dirname(file), storyFileExists = doesStoryFileExist(join2(getProjectRoot(), dir), storyFileName), info = await parser3.parse(content);
813
682
  return {
814
683
  filepath: file,
815
684
  exportedComponents: info.exports,
@@ -854,14 +723,430 @@ ${e?.message}`
854
723
  ), channel;
855
724
  }
856
725
 
726
+ // src/core-server/server-channel/ghost-stories-channel.ts
727
+ import { GHOST_STORIES_REQUEST, GHOST_STORIES_RESPONSE } from "storybook/internal/core-events";
728
+ import {
729
+ getLastEvents,
730
+ getSessionId,
731
+ getStorybookMetadata,
732
+ telemetry as telemetry3
733
+ } from "storybook/internal/telemetry";
734
+
735
+ // src/core-server/utils/ghost-stories/get-candidates.ts
736
+ import { readFile as readFile2 } from "node:fs/promises";
737
+ import { babelParse, traverse } from "storybook/internal/babel";
738
+
739
+ // src/core-server/utils/ghost-stories/component-analyzer.ts
740
+ var COMPLEXITY_CONFIG = {
741
+ /** Weight applied to non-empty lines */
742
+ locWeight: 1,
743
+ /** Imports can be cheap, so they get a lower weight */
744
+ importWeight: 0.5,
745
+ /**
746
+ * Defines what raw complexity value should map to the upper bound of a "simple" file For instance
747
+ * 30 LOC + 4 imports = 32. This would result in a score of 0.3
748
+ */
749
+ simpleBaseline: 32,
750
+ simpleScore: 0.3
751
+ }, getComponentComplexity = (fileContent) => {
752
+ let lines = fileContent.split(`
753
+ `), nonEmptyLines = lines.filter((line) => line.trim() !== "").length, importCount = lines.filter((line) => line.trim().startsWith("import")).length, normalizedScore = (nonEmptyLines * COMPLEXITY_CONFIG.locWeight + importCount * COMPLEXITY_CONFIG.importWeight) / (COMPLEXITY_CONFIG.simpleBaseline / COMPLEXITY_CONFIG.simpleScore);
754
+ return Math.min(normalizedScore, 1);
755
+ };
756
+
757
+ // src/core-server/utils/ghost-stories/get-candidates.ts
758
+ function isValidCandidate(source) {
759
+ let ast = babelParse(source), hasJSX = !1, hasExport = !1;
760
+ return traverse(ast, {
761
+ JSXElement(path) {
762
+ hasJSX = !0, hasExport && path.stop();
763
+ },
764
+ JSXFragment(path) {
765
+ hasJSX = !0, hasExport && path.stop();
766
+ },
767
+ ExportNamedDeclaration(path) {
768
+ hasExport = !0, hasJSX && path.stop();
769
+ },
770
+ ExportDefaultDeclaration(path) {
771
+ hasExport = !0, hasJSX && path.stop();
772
+ },
773
+ ExportAllDeclaration(path) {
774
+ hasExport = !0, hasJSX && path.stop();
775
+ }
776
+ }), hasJSX && hasExport;
777
+ }
778
+ async function getCandidatesForStorybook(files, sampleCount) {
779
+ let simpleCandidates = [], analyzedCandidates = [];
780
+ for (let file of files) {
781
+ let source;
782
+ try {
783
+ if (source = await readFile2(file, "utf-8"), !isValidCandidate(source))
784
+ continue;
785
+ } catch {
786
+ continue;
787
+ }
788
+ let complexity = getComponentComplexity(source);
789
+ if (analyzedCandidates.push({ file, complexity }), complexity < 0.3 && (simpleCandidates.push({ file, complexity }), simpleCandidates.length >= sampleCount))
790
+ break;
791
+ }
792
+ let selectedCandidates = [];
793
+ simpleCandidates.length >= sampleCount ? selectedCandidates = simpleCandidates.sort((a, b) => a.complexity - b.complexity).slice(0, sampleCount) : selectedCandidates = analyzedCandidates.sort((a, b) => a.complexity - b.complexity).slice(0, sampleCount);
794
+ let avgComplexity = selectedCandidates.length > 0 ? Number(
795
+ (selectedCandidates.reduce((acc, curr) => acc + curr.complexity, 0) / selectedCandidates.length).toFixed(2)
796
+ ) : 0;
797
+ return {
798
+ candidates: selectedCandidates.map(({ file }) => file),
799
+ analyzedCount: analyzedCandidates.length,
800
+ avgComplexity
801
+ };
802
+ }
803
+ async function getComponentCandidates({
804
+ sampleSize = 20,
805
+ globPattern = "**/*.{tsx,jsx}"
806
+ } = {}) {
807
+ let globMatchCount = 0;
808
+ try {
809
+ let files = [];
810
+ if (files = await glob(globPattern, {
811
+ cwd: process.cwd(),
812
+ absolute: !0,
813
+ ignore: [
814
+ "**/node_modules/**",
815
+ "**/.git/**",
816
+ "**/dist/**",
817
+ "**/__mocks__/**",
818
+ "**/build/**",
819
+ "**/storybook-static/**",
820
+ "**/*.test.*",
821
+ "**/*.d.*",
822
+ "**/*.config.*",
823
+ "**/*.spec.*",
824
+ "**/*.stories.*",
825
+ // skip example story files that come from the CLI
826
+ "**/stories/{Button,Header,Page}.*",
827
+ "**/stories/{button,header,page}.*"
828
+ ]
829
+ }), globMatchCount = files.length, globMatchCount === 0)
830
+ return {
831
+ candidates: [],
832
+ globMatchCount
833
+ };
834
+ let { analyzedCount, avgComplexity, candidates } = await getCandidatesForStorybook(
835
+ files,
836
+ sampleSize
837
+ );
838
+ return {
839
+ analyzedCount,
840
+ avgComplexity,
841
+ candidates,
842
+ globMatchCount
843
+ };
844
+ } catch {
845
+ return {
846
+ candidates: [],
847
+ error: "Failed to find candidates",
848
+ globMatchCount
849
+ };
850
+ }
851
+ }
852
+
853
+ // src/core-server/utils/ghost-stories/run-story-tests.ts
854
+ import { existsSync } from "node:fs";
855
+ import { mkdir, readFile as readFile3 } from "node:fs/promises";
856
+ import { executeCommand, resolvePathInStorybookCache } from "storybook/internal/common";
857
+
858
+ // src/shared/utils/categorize-render-errors.ts
859
+ var ERROR_CATEGORIES = {
860
+ MISSING_PROVIDER: "MISSING_PROVIDER",
861
+ MISSING_STATE_PROVIDER: "MISSING_STATE_PROVIDER",
862
+ MISSING_ROUTER_PROVIDER: "MISSING_ROUTER_PROVIDER",
863
+ MISSING_THEME_PROVIDER: "MISSING_THEME_PROVIDER",
864
+ MISSING_TRANSLATION_PROVIDER: "MISSING_TRANSLATION_PROVIDER",
865
+ MISSING_PORTAL_ROOT: "MISSING_PORTAL_ROOT",
866
+ HOOK_USAGE_ERROR: "HOOK_USAGE_ERROR",
867
+ MODULE_IMPORT_ERROR: "MODULE_IMPORT_ERROR",
868
+ COMPONENT_RENDER_ERROR: "COMPONENT_RENDER_ERROR",
869
+ SERVER_COMPONENTS_ERROR: "SERVER_COMPONENTS_ERROR",
870
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
871
+ // Vite related errors
872
+ DYNAMIC_MODULE_IMPORT_ERROR: "DYNAMIC_MODULE_IMPORT_ERROR",
873
+ // Vitest test run related errors
874
+ TEST_FILE_IMPORT_ERROR: "TEST_FILE_IMPORT_ERROR"
875
+ };
876
+ function buildErrorContext(message, stack) {
877
+ let normalizedMessage = message.toLowerCase(), normalizedStack = (stack ?? "").toLowerCase(), stackDeps = /* @__PURE__ */ new Set(), stackLines = normalizedStack.split(`
878
+ `).filter(Boolean);
879
+ for (let line of stackLines) {
880
+ let depMatch = line.match(/\/deps\/([^:]+)\.js/);
881
+ depMatch && stackDeps.add(depMatch[1]);
882
+ }
883
+ return {
884
+ message,
885
+ stack,
886
+ normalizedMessage,
887
+ normalizedStack,
888
+ stackDeps
889
+ };
890
+ }
891
+ var CATEGORIZATION_RULES = [
892
+ {
893
+ category: ERROR_CATEGORIES.MODULE_IMPORT_ERROR,
894
+ priority: 100,
895
+ match: (ctx) => ctx.normalizedMessage.includes("cannot find module") || ctx.normalizedMessage.includes("module not found") || ctx.normalizedMessage.includes("cannot resolve module")
896
+ },
897
+ {
898
+ category: ERROR_CATEGORIES.TEST_FILE_IMPORT_ERROR,
899
+ priority: 95,
900
+ match: (ctx) => ctx.normalizedMessage.includes("failed to import test file")
901
+ },
902
+ {
903
+ category: ERROR_CATEGORIES.DYNAMIC_MODULE_IMPORT_ERROR,
904
+ priority: 95,
905
+ match: (ctx) => ctx.normalizedMessage.includes("failed to fetch dynamically imported module")
906
+ },
907
+ {
908
+ category: ERROR_CATEGORIES.HOOK_USAGE_ERROR,
909
+ priority: 90,
910
+ match: (ctx) => ctx.normalizedMessage.includes("invalid hook call") || ctx.normalizedMessage.includes("rendered more hooks than") || ctx.normalizedMessage.includes("hooks can only be called")
911
+ },
912
+ {
913
+ category: ERROR_CATEGORIES.MISSING_STATE_PROVIDER,
914
+ priority: 85,
915
+ match: (ctx) => Array.from(ctx.stackDeps).some(isStateManagementPackage) && (ctx.normalizedMessage.includes("context") || ctx.normalizedMessage.includes("undefined") || ctx.normalizedMessage.includes("null"))
916
+ },
917
+ {
918
+ category: ERROR_CATEGORIES.MISSING_ROUTER_PROVIDER,
919
+ priority: 85,
920
+ match: (ctx) => Array.from(ctx.stackDeps).some(isRouterPackage) || ctx.normalizedMessage.includes("usenavigate") || ctx.normalizedMessage.includes("router")
921
+ },
922
+ {
923
+ category: ERROR_CATEGORIES.SERVER_COMPONENTS_ERROR,
924
+ priority: 85,
925
+ match: (ctx) => ctx.normalizedMessage.includes("server components") || ctx.normalizedMessage.includes("use client") || ctx.normalizedMessage.includes("async/await") && ctx.normalizedMessage.includes("not supported")
926
+ },
927
+ {
928
+ category: ERROR_CATEGORIES.MISSING_THEME_PROVIDER,
929
+ priority: 80,
930
+ match: (ctx) => Array.from(ctx.stackDeps).some(isStylingPackage) && (ctx.normalizedMessage.includes("theme") || ctx.normalizedMessage.includes("undefined")) || ctx.normalizedMessage.includes("usetheme") || ctx.normalizedMessage.includes("theme") && ctx.normalizedMessage.includes("provider")
931
+ },
932
+ {
933
+ category: ERROR_CATEGORIES.MISSING_TRANSLATION_PROVIDER,
934
+ priority: 80,
935
+ match: (ctx) => Array.from(ctx.stackDeps).some(isI18nPackage) || ctx.normalizedMessage.includes("i18n") || ctx.normalizedMessage.includes("translation") || ctx.normalizedMessage.includes("locale")
936
+ },
937
+ {
938
+ category: ERROR_CATEGORIES.MISSING_PORTAL_ROOT,
939
+ priority: 70,
940
+ match: (ctx) => ctx.normalizedMessage.includes("portal") && (ctx.normalizedMessage.includes("container") || ctx.normalizedMessage.includes("root")) && (ctx.normalizedMessage.includes("null") || ctx.normalizedMessage.includes("not found"))
941
+ },
942
+ {
943
+ category: ERROR_CATEGORIES.MISSING_PROVIDER,
944
+ priority: 60,
945
+ match: (ctx) => ctx.normalizedMessage.includes("use") && ctx.normalizedMessage.includes("provider") || ctx.normalizedMessage.includes("<provider>") || (ctx.normalizedMessage.includes("could not find") || ctx.normalizedMessage.includes("missing")) && ctx.normalizedMessage.includes("context") || ctx.normalizedMessage.includes("usecontext") && (ctx.normalizedMessage.includes("null") || ctx.normalizedMessage.includes("undefined"))
946
+ },
947
+ {
948
+ category: ERROR_CATEGORIES.COMPONENT_RENDER_ERROR,
949
+ priority: 10,
950
+ match: (ctx) => ctx.normalizedMessage.includes("cannot read") || ctx.normalizedMessage.includes("undefined is not a function") || ctx.normalizedMessage.includes("render")
951
+ }
952
+ ], RULES = CATEGORIZATION_RULES.sort((a, b) => b.priority - a.priority);
953
+ function categorizeError(message, stack) {
954
+ let ctx = buildErrorContext(message, stack), rule = RULES.find((r) => r.match(ctx));
955
+ if (!rule)
956
+ return { category: ERROR_CATEGORIES.UNKNOWN_ERROR, matchedDependencies: [] };
957
+ let matchedDependencies = getMatchedDependencies(rule.category, ctx);
958
+ return { category: rule.category, matchedDependencies };
959
+ }
960
+ function getMatchedDependencies(category, ctx) {
961
+ switch (category) {
962
+ case ERROR_CATEGORIES.MISSING_STATE_PROVIDER:
963
+ return Array.from(ctx.stackDeps).filter(isStateManagementPackage);
964
+ case ERROR_CATEGORIES.MISSING_ROUTER_PROVIDER:
965
+ return Array.from(ctx.stackDeps).filter(isRouterPackage);
966
+ case ERROR_CATEGORIES.MISSING_THEME_PROVIDER:
967
+ return Array.from(ctx.stackDeps).filter(isStylingPackage);
968
+ case ERROR_CATEGORIES.MISSING_TRANSLATION_PROVIDER:
969
+ return Array.from(ctx.stackDeps).filter(isI18nPackage);
970
+ default:
971
+ return [];
972
+ }
973
+ }
974
+
975
+ // src/core-server/utils/ghost-stories/parse-vitest-report.ts
976
+ function extractCategorizedErrors(testResults) {
977
+ let failed = testResults.filter((r) => r.status === "FAIL" && r.error), map = /* @__PURE__ */ new Map(), uniqueErrorMessages = /* @__PURE__ */ new Set();
978
+ for (let r of failed) {
979
+ let { category, matchedDependencies } = categorizeError(r.error, r.stack);
980
+ map.has(category) || map.set(category, { count: 0, uniqueErrors: /* @__PURE__ */ new Set(), matchedDependencies: /* @__PURE__ */ new Set() });
981
+ let data = map.get(category);
982
+ data.count++, matchedDependencies.forEach((dep) => data.matchedDependencies.add(dep)), uniqueErrorMessages.add(r.error), data.uniqueErrors.add(r.error);
983
+ }
984
+ let categorizedErrors = Array.from(map.entries()).reduce(
985
+ (acc, [category, data]) => (acc[category] = {
986
+ uniqueCount: data.uniqueErrors.size,
987
+ count: data.count,
988
+ matchedDependencies: Array.from(data.matchedDependencies).sort()
989
+ }, acc),
990
+ {}
991
+ );
992
+ return {
993
+ totalErrors: failed.length,
994
+ uniqueErrorCount: uniqueErrorMessages.size,
995
+ categorizedErrors
996
+ };
997
+ }
998
+ function parseVitestResults(report) {
999
+ let storyTestResults = [], passedButEmptyRender = 0;
1000
+ for (let testSuite of report.testResults)
1001
+ for (let assertion of testSuite.assertionResults) {
1002
+ let storyId = assertion.meta?.storyId || assertion.fullName, status = assertion.status === "passed" ? "PASS" : assertion.status === "failed" ? "FAIL" : "PENDING", hasEmptyRender = assertion.meta?.reports?.some(
1003
+ (report2) => report2.type === "render-analysis" && report2.result?.emptyRender === !0
1004
+ );
1005
+ status === "PASS" && hasEmptyRender && passedButEmptyRender++;
1006
+ let error, stack;
1007
+ assertion.failureMessages && assertion.failureMessages.length > 0 && (stack = assertion.failureMessages[0], error = stack?.split(`
1008
+ `)[0]), storyTestResults.push({
1009
+ storyId,
1010
+ status,
1011
+ error,
1012
+ stack
1013
+ });
1014
+ }
1015
+ let total = report.numTotalTests, passed = report.numPassedTests, successRate = total > 0 ? parseFloat((passed / total).toFixed(2)) : 0, successRateWithoutEmptyRender = total > 0 ? parseFloat(((passed - passedButEmptyRender) / total).toFixed(2)) : 0, errorClassification = extractCategorizedErrors(storyTestResults), categorizedErrors = errorClassification.categorizedErrors;
1016
+ return {
1017
+ summary: {
1018
+ total,
1019
+ passed,
1020
+ passedButEmptyRender,
1021
+ successRate,
1022
+ successRateWithoutEmptyRender,
1023
+ uniqueErrorCount: errorClassification.uniqueErrorCount,
1024
+ categorizedErrors
1025
+ }
1026
+ };
1027
+ }
1028
+
1029
+ // src/core-server/utils/ghost-stories/run-story-tests.ts
1030
+ async function runStoryTests(componentFilePaths) {
1031
+ try {
1032
+ let cacheDir = resolvePathInStorybookCache("ghost-stories-tests");
1033
+ await mkdir(cacheDir, { recursive: !0 });
1034
+ let timestamp = Date.now(), outputFile = join(cacheDir, `test-results-${timestamp}.json`), startTime = Date.now(), testFailureMessage;
1035
+ try {
1036
+ await executeCommand({
1037
+ command: "npx",
1038
+ args: [
1039
+ "vitest",
1040
+ "run",
1041
+ "--reporter=json",
1042
+ "--testTimeout=1000",
1043
+ `--outputFile=${outputFile}`,
1044
+ ...componentFilePaths
1045
+ ],
1046
+ stdio: "pipe",
1047
+ env: {
1048
+ STORYBOOK_COMPONENT_PATHS: componentFilePaths.join(";")
1049
+ }
1050
+ });
1051
+ } catch (error) {
1052
+ let errorMessage = (error.stderr || String(error) || "").toLowerCase();
1053
+ errorMessage.includes("browsertype.launch") ? testFailureMessage = "Playwright is not installed" : errorMessage.includes("startup error") ? testFailureMessage = "Startup Error" : errorMessage.includes("no tests found") ? testFailureMessage = "No tests found" : errorMessage.includes("test timeout") ? testFailureMessage = "Test timeout" : errorMessage.includes("react-native-web") ? testFailureMessage = "React Native Web error" : errorMessage.includes("unhandled rejection") && (testFailureMessage = "Unhandled Rejection");
1054
+ }
1055
+ let duration = Date.now() - startTime;
1056
+ if (testFailureMessage)
1057
+ return {
1058
+ duration,
1059
+ runError: testFailureMessage
1060
+ };
1061
+ if (!existsSync(outputFile))
1062
+ return {
1063
+ duration,
1064
+ runError: "JSON report not found"
1065
+ };
1066
+ let vitestReport;
1067
+ try {
1068
+ let resultsJson = await readFile3(outputFile, "utf8");
1069
+ vitestReport = JSON.parse(resultsJson);
1070
+ } catch {
1071
+ return {
1072
+ duration,
1073
+ runError: "Failed to read or parse JSON report"
1074
+ };
1075
+ }
1076
+ return !vitestReport.testResults || vitestReport.testResults.length === 0 ? {
1077
+ duration,
1078
+ runError: "No tests found"
1079
+ } : { ...parseVitestResults(vitestReport), duration };
1080
+ } catch {
1081
+ return {
1082
+ runError: "Uncaught error running story tests",
1083
+ duration: 0
1084
+ };
1085
+ }
1086
+ }
1087
+
1088
+ // src/core-server/server-channel/ghost-stories-channel.ts
1089
+ function initGhostStoriesChannel(channel, options, coreOptions) {
1090
+ return coreOptions.disableTelemetry || channel.on(GHOST_STORIES_REQUEST, async () => {
1091
+ let stats = {};
1092
+ try {
1093
+ let ghostRunStart = Date.now(), lastEvents = await getLastEvents(), lastInit = lastEvents?.init;
1094
+ if (!lastEvents || !lastInit)
1095
+ return;
1096
+ let sessionId = await getSessionId();
1097
+ if (lastEvents["ghost-stories"] || lastInit.body?.sessionId && lastInit.body.sessionId !== sessionId)
1098
+ return;
1099
+ let metadata = await getStorybookMetadata(options.configDir), isReactStorybook = metadata?.renderer?.includes("@storybook/react"), hasVitestAddon = !!metadata?.addons && Object.keys(metadata.addons).some(
1100
+ (addonKey) => addonKey.includes("@storybook/addon-vitest")
1101
+ );
1102
+ if (!isReactStorybook || !hasVitestAddon)
1103
+ return;
1104
+ let candidateAnalysisStart = Date.now(), candidatesResult = await getComponentCandidates();
1105
+ if (stats.candidateAnalysisDuration = Date.now() - candidateAnalysisStart, stats.globMatchCount = candidatesResult.globMatchCount, stats.analyzedCount = candidatesResult.analyzedCount ?? 0, stats.avgComplexity = candidatesResult.avgComplexity ?? 0, stats.candidateCount = candidatesResult.candidates.length, candidatesResult.error) {
1106
+ stats.totalRunDuration = Date.now() - ghostRunStart, telemetry3("ghost-stories", {
1107
+ stats,
1108
+ runError: candidatesResult.error
1109
+ });
1110
+ return;
1111
+ }
1112
+ if (candidatesResult.candidates.length === 0) {
1113
+ stats.totalRunDuration = Date.now() - ghostRunStart, telemetry3("ghost-stories", {
1114
+ stats,
1115
+ runError: "No candidates found"
1116
+ });
1117
+ return;
1118
+ }
1119
+ let testRunResult = await runStoryTests(candidatesResult.candidates);
1120
+ if (stats.totalRunDuration = Date.now() - ghostRunStart, stats.testRunDuration = testRunResult.duration, testRunResult.runError) {
1121
+ telemetry3("ghost-stories", {
1122
+ stats,
1123
+ runError: testRunResult.runError
1124
+ });
1125
+ return;
1126
+ }
1127
+ telemetry3("ghost-stories", {
1128
+ stats,
1129
+ results: testRunResult.summary
1130
+ });
1131
+ } catch {
1132
+ telemetry3("ghost-stories", {
1133
+ stats,
1134
+ runError: "Unknown error during ghost run"
1135
+ });
1136
+ } finally {
1137
+ channel.emit(GHOST_STORIES_RESPONSE);
1138
+ }
1139
+ }), channel;
1140
+ }
1141
+
857
1142
  // src/core-server/server-channel/open-in-editor-channel.ts
858
1143
  var import_launch_editor = __toESM(require_launch_editor(), 1);
859
1144
  import { OPEN_IN_EDITOR_REQUEST, OPEN_IN_EDITOR_RESPONSE } from "storybook/internal/core-events";
860
- import { telemetry as telemetry3 } from "storybook/internal/telemetry";
1145
+ import { telemetry as telemetry4 } from "storybook/internal/telemetry";
861
1146
  async function initOpenInEditorChannel(channel, _options, coreOptions) {
862
1147
  return channel.on(OPEN_IN_EDITOR_REQUEST, async (payload) => {
863
1148
  let sendTelemetry = (data) => {
864
- coreOptions.disableTelemetry || telemetry3("open-in-editor", data);
1149
+ coreOptions.disableTelemetry || telemetry4("open-in-editor", data);
865
1150
  };
866
1151
  try {
867
1152
  let { file: targetFile, line, column } = payload;
@@ -890,9 +1175,9 @@ async function initOpenInEditorChannel(channel, _options, coreOptions) {
890
1175
 
891
1176
  // src/core-server/server-channel/preview-initialized-channel.ts
892
1177
  import { PREVIEW_INITIALIZED } from "storybook/internal/core-events";
893
- import { telemetry as telemetry4 } from "storybook/internal/telemetry";
894
- import { getLastEvents } from "storybook/internal/telemetry";
895
- import { getSessionId } from "storybook/internal/telemetry";
1178
+ import { telemetry as telemetry5 } from "storybook/internal/telemetry";
1179
+ import { getLastEvents as getLastEvents2 } from "storybook/internal/telemetry";
1180
+ import { getSessionId as getSessionId2 } from "storybook/internal/telemetry";
896
1181
  var makePayload = (userAgent, lastInit, sessionId) => {
897
1182
  let payload = {
898
1183
  userAgent,
@@ -905,10 +1190,10 @@ function initPreviewInitializedChannel(channel, options, _coreConfig) {
905
1190
  channel.on(PREVIEW_INITIALIZED, async ({ userAgent }) => {
906
1191
  if (!options.disableTelemetry)
907
1192
  try {
908
- let sessionId = await getSessionId(), lastEvents = await getLastEvents(), lastInit = lastEvents.init;
1193
+ let sessionId = await getSessionId2(), lastEvents = await getLastEvents2(), lastInit = lastEvents.init;
909
1194
  if (!lastEvents["preview-first-load"]) {
910
1195
  let payload = makePayload(userAgent, lastInit, sessionId);
911
- telemetry4("preview-first-load", payload);
1196
+ telemetry5("preview-first-load", payload);
912
1197
  }
913
1198
  } catch {
914
1199
  }
@@ -916,10 +1201,10 @@ function initPreviewInitializedChannel(channel, options, _coreConfig) {
916
1201
  }
917
1202
 
918
1203
  // src/core-server/utils/checklist.ts
919
- import { createFileSystemCache, resolvePathInStorybookCache } from "storybook/internal/common";
1204
+ import { createFileSystemCache, resolvePathInStorybookCache as resolvePathInStorybookCache2 } from "storybook/internal/common";
920
1205
  import { experimental_UniversalStore } from "storybook/internal/core-server";
921
1206
  import { logger } from "storybook/internal/node-logger";
922
- import { telemetry as telemetry5 } from "storybook/internal/telemetry";
1207
+ import { telemetry as telemetry6 } from "storybook/internal/telemetry";
923
1208
 
924
1209
  // ../../node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
925
1210
  function isPrimitive(value) {
@@ -1040,7 +1325,7 @@ async function initializeChecklist() {
1040
1325
  ...UNIVERSAL_CHECKLIST_STORE_OPTIONS,
1041
1326
  leader: !0
1042
1327
  }), cache = createFileSystemCache({
1043
- basePath: resolvePathInStorybookCache("checklist"),
1328
+ basePath: resolvePathInStorybookCache2("checklist"),
1044
1329
  ns: "storybook"
1045
1330
  }), [[userState, saveUserState], [projectState, saveProjectState]] = await Promise.all([
1046
1331
  globalSettings().then((settings) => {
@@ -1077,13 +1362,13 @@ async function initializeChecklist() {
1077
1362
  },
1078
1363
  { mutedItems: [], statusItems: [] }
1079
1364
  );
1080
- mutedItems.length > 0 && telemetry5("onboarding-checklist-muted", {
1365
+ mutedItems.length > 0 && telemetry6("onboarding-checklist-muted", {
1081
1366
  items: mutedItems,
1082
1367
  completedItems: entries.reduce((acc, [id, { status }]) => status === "done" || status === "accepted" ? acc.concat([id]) : acc, []),
1083
1368
  skippedItems: entries.reduce((acc, [id, { status }]) => status === "skipped" ? acc.concat([id]) : acc, [])
1084
1369
  }), statusItems.forEach((item) => {
1085
1370
  let { status } = state.items[item];
1086
- telemetry5("onboarding-checklist-status", { item, status });
1371
+ telemetry6("onboarding-checklist-status", { item, status });
1087
1372
  });
1088
1373
  });
1089
1374
  } catch (err) {
@@ -1100,8 +1385,8 @@ var defaultStaticDirs = [
1100
1385
  ], defaultFavicon = join(resolvePackageDir("storybook"), "assets/browser/favicon.svg");
1101
1386
 
1102
1387
  // src/core-server/utils/save-story/save-story.ts
1103
- import { writeFile as writeFile2 } from "node:fs/promises";
1104
- import { basename as basename2, join as join4 } from "node:path";
1388
+ import { writeFile } from "node:fs/promises";
1389
+ import { basename, join as join3 } from "node:path";
1105
1390
  import { formatFileContent } from "storybook/internal/common";
1106
1391
  import {
1107
1392
  SAVE_STORY_REQUEST,
@@ -1111,10 +1396,10 @@ import {
1111
1396
  import { storyNameFromExport, toId } from "storybook/internal/csf";
1112
1397
  import { printCsf, readCsf } from "storybook/internal/csf-tools";
1113
1398
  import { logger as logger2 } from "storybook/internal/node-logger";
1114
- import { isExampleStoryId, telemetry as telemetry6 } from "storybook/internal/telemetry";
1399
+ import { isExampleStoryId, telemetry as telemetry7 } from "storybook/internal/telemetry";
1115
1400
 
1116
1401
  // src/core-server/utils/save-story/duplicate-story-with-new-name.ts
1117
- import { types as t2, traverse } from "storybook/internal/babel";
1402
+ import { types as t2, traverse as traverse2 } from "storybook/internal/babel";
1118
1403
 
1119
1404
  // src/core-server/utils/save-story/utils.ts
1120
1405
  var SaveStoryError = class extends Error {
@@ -1126,7 +1411,7 @@ var duplicateStoryWithNewName = (csfFile, storyName, newStoryName) => {
1126
1411
  if (!cloned)
1127
1412
  throw new SaveStoryError("cannot clone Node");
1128
1413
  let found = !1;
1129
- if (traverse(cloned, {
1414
+ if (traverse2(cloned, {
1130
1415
  Identifier(path) {
1131
1416
  found || path.node.name === storyName && (found = !0, path.node.name = newStoryName);
1132
1417
  },
@@ -1137,7 +1422,7 @@ var duplicateStoryWithNewName = (csfFile, storyName, newStoryName) => {
1137
1422
  noScope: !0
1138
1423
  }), !(t2.isCallExpression(cloned.init) && t2.isMemberExpression(cloned.init.callee) && t2.isIdentifier(cloned.init.callee.property) && cloned.init.callee.property.name === "story") && (t2.isArrowFunctionExpression(cloned.init) || t2.isCallExpression(cloned.init)))
1139
1424
  throw new SaveStoryError("Creating a new story based on a CSF2 story is not supported");
1140
- return traverse(csfFile._ast, {
1425
+ return traverse2(csfFile._ast, {
1141
1426
  Program(path) {
1142
1427
  path.pushContainer(
1143
1428
  "body",
@@ -1148,7 +1433,7 @@ var duplicateStoryWithNewName = (csfFile, storyName, newStoryName) => {
1148
1433
  };
1149
1434
 
1150
1435
  // src/core-server/utils/save-story/update-args-in-csf-file.ts
1151
- import { types as t4, traverse as traverse2 } from "storybook/internal/babel";
1436
+ import { types as t4, traverse as traverse3 } from "storybook/internal/babel";
1152
1437
 
1153
1438
  // src/core-server/utils/save-story/valueToAST.ts
1154
1439
  import { parser as parser2, types as t3 } from "storybook/internal/babel";
@@ -1221,7 +1506,7 @@ var updateArgsInCsfFile = async (node, input) => {
1221
1506
  );
1222
1507
  return;
1223
1508
  }
1224
- traverse2(node, {
1509
+ traverse3(node, {
1225
1510
  ObjectExpression(path) {
1226
1511
  if (found)
1227
1512
  return;
@@ -1279,7 +1564,7 @@ function initializeSaveStory(channel, options, coreConfig) {
1279
1564
  channel.on(SAVE_STORY_REQUEST, async ({ id, payload }) => {
1280
1565
  let { csfId, importPath, args, name } = payload, newStoryId, newStoryName, sourceFileName, sourceFilePath, sourceStoryName;
1281
1566
  try {
1282
- sourceFileName = basename2(importPath), sourceFilePath = join4(process.cwd(), importPath);
1567
+ sourceFileName = basename(importPath), sourceFilePath = join3(process.cwd(), importPath);
1283
1568
  let csf = await readCsf(sourceFilePath, {
1284
1569
  makeTitle: (userTitle) => userTitle || "myTitle"
1285
1570
  }), parsed = csf.parse(), stories = Object.entries(parsed._stories), [componentId, storyId] = csfId.split("--");
@@ -1301,7 +1586,7 @@ function initializeSaveStory(channel, options, coreConfig) {
1301
1586
  new Promise((resolve) => {
1302
1587
  channel.on(STORY_RENDERED, resolve), setTimeout(() => resolve(channel.off(STORY_RENDERED, resolve)), 3e3);
1303
1588
  }),
1304
- writeFile2(sourceFilePath, code)
1589
+ writeFile(sourceFilePath, code)
1305
1590
  ]), channel.emit(SAVE_STORY_RESPONSE, {
1306
1591
  id,
1307
1592
  success: !0,
@@ -1318,7 +1603,7 @@ function initializeSaveStory(channel, options, coreConfig) {
1318
1603
  error: null
1319
1604
  });
1320
1605
  let isCLIExample = isExampleStoryId(newStoryId ?? csfId);
1321
- !coreConfig.disableTelemetry && !isCLIExample && await telemetry6("save-story", {
1606
+ !coreConfig.disableTelemetry && !isCLIExample && await telemetry7("save-story", {
1322
1607
  action: name ? "createStory" : "updateStory",
1323
1608
  success: !0
1324
1609
  });
@@ -1330,7 +1615,7 @@ function initializeSaveStory(channel, options, coreConfig) {
1330
1615
  }), logger2.error(
1331
1616
  `Error writing to ${sourceFilePath}:
1332
1617
  ${error.stack || error.message || error.toString()}`
1333
- ), !coreConfig.disableTelemetry && !(error instanceof SaveStoryError) && await telemetry6("save-story", {
1618
+ ), !coreConfig.disableTelemetry && !(error instanceof SaveStoryError) && await telemetry7("save-story", {
1334
1619
  action: name ? "createStory" : "updateStory",
1335
1620
  success: !1,
1336
1621
  error
@@ -1340,8 +1625,8 @@ ${error.stack || error.message || error.toString()}`
1340
1625
  }
1341
1626
 
1342
1627
  // src/core-server/utils/whats-new.ts
1343
- import { writeFile as writeFile3 } from "node:fs/promises";
1344
- import { findConfigFile as findConfigFile2, loadMainConfig } from "storybook/internal/common";
1628
+ import { writeFile as writeFile2 } from "node:fs/promises";
1629
+ import { findConfigFile, loadMainConfig } from "storybook/internal/common";
1345
1630
  import {
1346
1631
  REQUEST_WHATS_NEW_DATA,
1347
1632
  RESULT_WHATS_NEW_DATA,
@@ -1351,7 +1636,7 @@ import {
1351
1636
  } from "storybook/internal/core-events";
1352
1637
  import { printConfig, readConfig } from "storybook/internal/csf-tools";
1353
1638
  import { logger as logger3 } from "storybook/internal/node-logger";
1354
- import { telemetry as telemetry7 } from "storybook/internal/telemetry";
1639
+ import { telemetry as telemetry8 } from "storybook/internal/telemetry";
1355
1640
  var WHATS_NEW_CACHE = "whats-new-cache", WHATS_NEW_URL = "https://storybook.js.org/whats-new/v1";
1356
1641
  function initializeWhatsNew(channel, options, coreOptions) {
1357
1642
  channel.on(SET_WHATS_NEW_CACHE, async (data) => {
@@ -1381,14 +1666,14 @@ function initializeWhatsNew(channel, options, coreOptions) {
1381
1666
  async ({ disableWhatsNewNotifications }) => {
1382
1667
  let isTelemetryEnabled = coreOptions.disableTelemetry !== !0;
1383
1668
  try {
1384
- let mainPath = findConfigFile2("main", options.configDir);
1669
+ let mainPath = findConfigFile("main", options.configDir);
1385
1670
  invariant(mainPath, `unable to find Storybook main file in ${options.configDir}`);
1386
1671
  let main = await readConfig(mainPath);
1387
1672
  if (!main._exportsObject)
1388
1673
  throw new Error(
1389
1674
  "Unable to parse Storybook main file while trying to read 'core' property"
1390
1675
  );
1391
- main.setFieldValue(["core", "disableWhatsNewNotifications"], disableWhatsNewNotifications), await writeFile3(mainPath, printConfig(main).code), isTelemetryEnabled && await telemetry7("core-config", { disableWhatsNewNotifications });
1676
+ main.setFieldValue(["core", "disableWhatsNewNotifications"], disableWhatsNewNotifications), await writeFile2(mainPath, printConfig(main).code), isTelemetryEnabled && await telemetry8("core-config", { disableWhatsNewNotifications });
1392
1677
  } catch (error) {
1393
1678
  invariant(error instanceof Error), isTelemetryEnabled && await sendTelemetryError(error, "core-config", {
1394
1679
  cliOptions: options,
@@ -1419,9 +1704,9 @@ var interpolate = (string, data = {}) => Object.entries(data).reduce((acc, [k, v
1419
1704
  workingDir: process.cwd(),
1420
1705
  directory: dir
1421
1706
  }) : dir, { staticPath, targetEndpoint } = parseStaticDir(normalizedDir);
1422
- return ["/favicon.svg", "/favicon.ico"].includes(targetEndpoint) && results.push(staticPath), targetEndpoint === "/" && (results.push(join(staticPath, "favicon.svg")), results.push(join(staticPath, "favicon.ico"))), results.filter((path) => existsSync3(path));
1707
+ return ["/favicon.svg", "/favicon.ico"].includes(targetEndpoint) && results.push(staticPath), targetEndpoint === "/" && (results.push(join(staticPath, "favicon.svg")), results.push(join(staticPath, "favicon.ico"))), results.filter((path) => existsSync2(path));
1423
1708
  }).reduce((l1, l2) => l1.concat(l2), []);
1424
- return faviconPaths.length > 1 && logger4.warn(import_ts_dedent4.dedent`
1709
+ return faviconPaths.length > 1 && logger4.warn(import_ts_dedent.dedent`
1425
1710
  Looks like multiple favicons were detected. Using the first one.
1426
1711
 
1427
1712
  ${faviconPaths.join(", ")}
@@ -1478,7 +1763,7 @@ var interpolate = (string, data = {}) => Object.entries(data).reduce((acc, [k, v
1478
1763
  let removeAddon = removeAddonBase, packageManager = JsPackageManagerFactory.getPackageManager({
1479
1764
  configDir: options.configDir
1480
1765
  });
1481
- return options.disableTelemetry || (removeAddon = async (id, opts) => (await telemetry8("remove", { addon: id, source: "api" }), removeAddonBase(id, { ...opts, packageManager }))), { ...extension, removeAddon };
1766
+ return options.disableTelemetry || (removeAddon = async (id, opts) => (await telemetry9("remove", { addon: id, source: "api" }), removeAddonBase(id, { ...opts, packageManager }))), { ...extension, removeAddon };
1482
1767
  }, core = async (existing, options) => ({
1483
1768
  ...existing,
1484
1769
  disableTelemetry: options.disableTelemetry === !0,
@@ -1505,14 +1790,14 @@ var interpolate = (string, data = {}) => Object.entries(data).reduce((acc, [k, v
1505
1790
  return typeof config == "string" ? {} : typeof config > "u" ? null : config.options;
1506
1791
  }, managerHead = async (_, options) => {
1507
1792
  let location = join(options.configDir, "manager-head.html");
1508
- if (existsSync3(location)) {
1509
- let contents = readFile3(location, { encoding: "utf8" }), interpolations = options.presets.apply("env");
1793
+ if (existsSync2(location)) {
1794
+ let contents = readFile4(location, { encoding: "utf8" }), interpolations = options.presets.apply("env");
1510
1795
  return interpolate(await contents, await interpolations);
1511
1796
  }
1512
1797
  return "";
1513
1798
  }, experimental_serverChannel = async (channel, options) => {
1514
1799
  let coreOptions = await options.presets.apply("core");
1515
- return initializeChecklist(), initializeWhatsNew(channel, options, coreOptions), initializeSaveStory(channel, options, coreOptions), initFileSearchChannel(channel, options, coreOptions), initCreateNewStoryChannel(channel, options, coreOptions), initOpenInEditorChannel(channel, options, coreOptions), initPreviewInitializedChannel(channel, options, coreOptions), channel;
1800
+ return initializeChecklist(), initializeWhatsNew(channel, options, coreOptions), initializeSaveStory(channel, options, coreOptions), initFileSearchChannel(channel, options, coreOptions), initCreateNewStoryChannel(channel, options, coreOptions), initGhostStoriesChannel(channel, options, coreOptions), initOpenInEditorChannel(channel, options, coreOptions), initPreviewInitializedChannel(channel, options, coreOptions), channel;
1516
1801
  }, resolvedReact = async (existing) => {
1517
1802
  try {
1518
1803
  return {