From 860f5fb851bba773806fa742b4eac4b77f82b13e Mon Sep 17 00:00:00 2001 From: Bill Collins Date: Wed, 2 Jul 2025 17:29:50 +0100 Subject: [PATCH] Fix addon detection in automigrations on windows Addon detection is done by sniffing the value returned by getAddonNames, which pulls values from storybook config. However, the wrap-require automation wraps addon references in an absolute path resolver. On windows this means that addons are now reported as e.g. @storybook\\addon-a11y, which defeats detection --- code/core/src/common/utils/get-addon-names.test.ts | 12 ++++++++++++ code/core/src/common/utils/get-addon-names.ts | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/code/core/src/common/utils/get-addon-names.test.ts b/code/core/src/common/utils/get-addon-names.test.ts index 7cfd1db63849..182426948dfe 100644 --- a/code/core/src/common/utils/get-addon-names.test.ts +++ b/code/core/src/common/utils/get-addon-names.test.ts @@ -42,6 +42,18 @@ describe('getAddonNames', () => { expect(result).toEqual(['@storybook/addon-highlight', '@storybook/addon-outline']); }); + it('should extract addon names from windows absolute paths', () => { + const config = { + stories: [], + addons: [ + '\\sandbox\\react-vite-default-ts\\node_modules\\@storybook\\addon-highlight', + '\\sandbox\\react-vite-default-ts\\node_modules\\@storybook\\addon-outline', + ], + }; + const result = getAddonNames(config); + expect(result).toEqual(['@storybook/addon-highlight', '@storybook/addon-outline']); + }); + it('should extract addon names from pnpm paths', () => { const config = { stories: [], diff --git a/code/core/src/common/utils/get-addon-names.ts b/code/core/src/common/utils/get-addon-names.ts index 0c763cf5b271..98d0f3b9ee1a 100644 --- a/code/core/src/common/utils/get-addon-names.ts +++ b/code/core/src/common/utils/get-addon-names.ts @@ -1,5 +1,7 @@ import type { StorybookConfig } from 'storybook/internal/types'; +import { normalizePath } from './normalize-path'; + export const getAddonNames = (mainConfig: StorybookConfig): string[] => { const addons = mainConfig.addons || []; const addonList = addons.map((addon) => { @@ -14,6 +16,9 @@ export const getAddonNames = (mainConfig: StorybookConfig): string[] => { return undefined; } + // Ensure posix paths for plugin name sniffing + name = normalizePath(name); + // For absolute paths, pnpm and yarn pnp, // Remove everything before and including "node_modules/" name = name.replace(/.*node_modules\//, '');