Skip to content

Commit

Permalink
Merge pull request #23431 from storybookjs/shilman/globals-telemetry
Browse files Browse the repository at this point in the history
Telemetry: Add globals usage to project.json
  • Loading branch information
shilman authored Jul 13, 2023
2 parents 4f1fe59 + ca8a47a commit 04b9e28
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/lib/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions code/lib/telemetry/src/storybook-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions code/lib/telemetry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export type StorybookMetadata = {
hasCustomBabel?: boolean;
features?: StorybookConfig['features'];
refCount?: number;
preview?: {
usesGlobals?: boolean;
};
};

export interface Payload {
Expand Down
1 change: 1 addition & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04b9e28

Please sign in to comment.