From ca8a47af6a9979a44dd13accd428e7108e78b777 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Thu, 13 Jul 2023 14:58:53 +0800 Subject: [PATCH] Telemetry: Add globals usage to project.json --- code/lib/telemetry/package.json | 1 + code/lib/telemetry/src/storybook-metadata.ts | 11 +++++++++++ code/lib/telemetry/src/types.ts | 3 +++ code/yarn.lock | 1 + 4 files changed, 16 insertions(+) diff --git a/code/lib/telemetry/package.json b/code/lib/telemetry/package.json index 31a3f8b1ffa7..8ad9770dfae6 100644 --- a/code/lib/telemetry/package.json +++ b/code/lib/telemetry/package.json @@ -45,6 +45,7 @@ "dependencies": { "@storybook/client-logger": "7.1.0-rc.1", "@storybook/core-common": "7.1.0-rc.1", + "@storybook/csf-tools": "7.1.0-rc.1", "chalk": "^4.1.0", "detect-package-manager": "^2.0.1", "fetch-retry": "^5.0.2", diff --git a/code/lib/telemetry/src/storybook-metadata.ts b/code/lib/telemetry/src/storybook-metadata.ts index d17294256497..01a54d9c9ec0 100644 --- a/code/lib/telemetry/src/storybook-metadata.ts +++ b/code/lib/telemetry/src/storybook-metadata.ts @@ -7,6 +7,7 @@ import { getProjectRoot, } from '@storybook/core-common'; import type { StorybookConfig, PackageJson } from '@storybook/types'; +import { readConfig } from '@storybook/csf-tools'; import type { StorybookMetadata, Dependency, StorybookAddon } from './types'; import { getActualPackageVersion, getActualPackageVersions } from './package-json'; @@ -160,6 +161,16 @@ export const computeStorybookMetadata = async ({ const hasStorybookEslint = !!allDependencies['eslint-plugin-storybook']; const storybookInfo = getStorybookInfo(packageJson); + + const { previewConfig } = storybookInfo; + if (previewConfig) { + const config = await readConfig(previewConfig); + const usesGlobals = !!( + config.getFieldNode(['globals']) || config.getFieldNode(['globalTypes']) + ); + metadata.preview = { ...metadata.preview, usesGlobals }; + } + const storybookVersion = storybookPackages[storybookInfo.frameworkPackage]?.version; return { diff --git a/code/lib/telemetry/src/types.ts b/code/lib/telemetry/src/types.ts index 25100149fd44..ba3af37719c0 100644 --- a/code/lib/telemetry/src/types.ts +++ b/code/lib/telemetry/src/types.ts @@ -54,6 +54,9 @@ export type StorybookMetadata = { hasCustomBabel?: boolean; features?: StorybookConfig['features']; refCount?: number; + preview?: { + usesGlobals?: boolean; + }; }; export interface Payload { diff --git a/code/yarn.lock b/code/yarn.lock index 820f77a52beb..746279daa5dc 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -7452,6 +7452,7 @@ __metadata: dependencies: "@storybook/client-logger": 7.1.0-rc.1 "@storybook/core-common": 7.1.0-rc.1 + "@storybook/csf-tools": 7.1.0-rc.1 chalk: ^4.1.0 detect-package-manager: ^2.0.1 fetch-retry: ^5.0.2