Skip to content

Commit

Permalink
Merge pull request #26077 from storybookjs/shilman/addon-removal-tele…
Browse files Browse the repository at this point in the history
…metry

Core: Add addon removal telemetry
  • Loading branch information
shilman authored Feb 19, 2024
2 parents fd6a748 + aea7ea3 commit a36c4ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
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

0 comments on commit a36c4ed

Please sign in to comment.