Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add addon removal telemetry #26077

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import { sync as readUpSync } from 'read-pkg-up';
import invariant from 'tiny-invariant';

import { logger } from '@storybook/node-logger';
import { addToGlobalContext } from '@storybook/telemetry';
import { parseList, getEnvConfig, JsPackageManagerFactory, versions } from '@storybook/core-common';
import { addToGlobalContext, telemetry } from '@storybook/telemetry';
import {
parseList,
getEnvConfig,
JsPackageManagerFactory,
versions,
removeAddon as remove,
} from '@storybook/core-common';
import { withTelemetry } from '@storybook/core-server';

import type { CommandOptions } from './generators/types';
import { initiate } from './initiate';
import { add } from './add';
import { removeAddon as remove } from '@storybook/core-common';
import { migrate } from './migrate';
import { upgrade, type UpgradeOptions } from './upgrade';
import { sandbox } from './sandbox';
Expand Down Expand Up @@ -71,7 +77,14 @@ command('remove <addon>')
'--package-manager <npm|pnpm|yarn1|yarn2>',
'Force package manager for installing dependencies'
)
.action((addonName: string, options: any) => remove(addonName, options));
.action((addonName: string, options: any) =>
withTelemetry('remove', { cliOptions: options }, async () => {
await remove(addonName, options);
if (!options.disableTelemetry) {
await telemetry('remove', { addon: addonName, source: 'cli' });
}
})
);

command('upgrade')
.description(`Upgrade your Storybook packages to v${versions.storybook}`)
Expand Down
16 changes: 11 additions & 5 deletions code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getPreviewBodyTemplate,
getPreviewHeadTemplate,
loadEnvs,
removeAddon,
removeAddon as removeAddonBase,
} from '@storybook/core-common';
import type {
CLIOptions,
Expand Down Expand Up @@ -162,10 +162,16 @@ const optionalEnvToBoolean = (input: string | undefined): boolean | undefined =>
};

// eslint-disable-next-line @typescript-eslint/naming-convention
export const experimental_serverAPI = (extension: Record<string, Function>) => ({
...extension,
removeAddon,
});
export const experimental_serverAPI = (extension: Record<string, Function>, options: Options) => {
let removeAddon = removeAddonBase;
if (!options.disableTelemetry) {
removeAddon = async (id: string, opts: any) => {
await telemetry('remove', { addon: id, source: 'api' });
return removeAddonBase(id, opts);
};
}
return { ...extension, removeAddon };
};

/**
* If for some reason this config is not applied, the reason is that
Expand Down
3 changes: 2 additions & 1 deletion code/lib/telemetry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type EventType =
| 'error'
| 'error-metadata'
| 'version-update'
| 'core-config';
| 'core-config'
| 'remove';

export interface Dependency {
version: string | undefined;
Expand Down
Loading