From 0baf6c5d43cf4d822c342b8a009da0a4e027a17f Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Wed, 30 Aug 2023 13:55:35 +0800 Subject: [PATCH] Merge pull request #24000 from storybookjs/shilman/filter-addons-telemetry Telemetry: Filter addon options to protect sensitive info (cherry picked from commit 7b4f37f4d7a97b6e21a8dd730d37f8ffb18a2fd0) --- .../telemetry/src/storybook-metadata.test.ts | 27 +++++++++++++++++++ code/lib/telemetry/src/storybook-metadata.ts | 4 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/code/lib/telemetry/src/storybook-metadata.test.ts b/code/lib/telemetry/src/storybook-metadata.test.ts index ab64dc26e9a1..83a206a92761 100644 --- a/code/lib/telemetry/src/storybook-metadata.test.ts +++ b/code/lib/telemetry/src/storybook-metadata.test.ts @@ -349,6 +349,33 @@ describe('storybook-metadata', () => { expect(res.refCount).toEqual(2); }); + test('only reports addon options for addon-essentials', async () => { + const res = await computeStorybookMetadata({ + packageJson: packageJsonMock, + mainConfig: { + ...mainJsMock, + addons: [ + { name: '@storybook/addon-essentials', options: { controls: false } }, + { name: 'addon-foo', options: { foo: 'bar' } }, + ], + }, + }); + expect(res.addons).toMatchInlineSnapshot(` + Object { + "@storybook/addon-essentials": Object { + "options": Object { + "controls": false, + }, + "version": "x.x.x", + }, + "addon-foo": Object { + "options": undefined, + "version": "x.x.x", + }, + } + `); + }); + test.each(Object.entries(metaFrameworks))( 'should detect the supported metaframework: %s', async (metaFramework, name) => { diff --git a/code/lib/telemetry/src/storybook-metadata.ts b/code/lib/telemetry/src/storybook-metadata.ts index 01a54d9c9ec0..2c70b566f97d 100644 --- a/code/lib/telemetry/src/storybook-metadata.ts +++ b/code/lib/telemetry/src/storybook-metadata.ts @@ -114,7 +114,9 @@ export const computeStorybookMetadata = async ({ if (typeof addon === 'string') { addonName = sanitizeAddonName(addon); } else { - options = addon.options; + if (addon.name.includes('addon-essentials')) { + options = addon.options; + } addonName = sanitizeAddonName(addon.name); }