From f32283936ce647982456c7715a3ab1b49abf163a Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 11 Oct 2022 22:17:37 -0400 Subject: [PATCH 1/3] Core: Throw an error if renderer is used as framework --- code/lib/core-common/src/index.ts | 1 + .../core-common/src/utils/validate-config.ts | 23 +++++++++++++++++++ code/lib/core-server/src/build-dev.ts | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 code/lib/core-common/src/utils/validate-config.ts diff --git a/code/lib/core-common/src/index.ts b/code/lib/core-common/src/index.ts index 5b95a7716571..8c4df3940980 100644 --- a/code/lib/core-common/src/index.ts +++ b/code/lib/core-common/src/index.ts @@ -22,6 +22,7 @@ export * from './utils/resolve-path-in-sb-cache'; export * from './utils/cache'; export * from './utils/template'; export * from './utils/interpolate'; +export * from './utils/validate-config'; export * from './utils/validate-configuration-files'; export * from './utils/glob-to-regexp'; export * from './utils/normalize-stories'; diff --git a/code/lib/core-common/src/utils/validate-config.ts b/code/lib/core-common/src/utils/validate-config.ts new file mode 100644 index 000000000000..6d0eac5f353b --- /dev/null +++ b/code/lib/core-common/src/utils/validate-config.ts @@ -0,0 +1,23 @@ +import { dedent } from 'ts-dedent'; + +const rendererNames = [ + '@storybook/html', + '@storybook/preact', + '@storybook/react', + '@storybook/server', + '@storybook/svelte', + '@storybook/vue', + '@storybook/vue3', + '@storybook/web-components', +]; + +// Checks that the framework name is not a renderer +export function validateFrameworkName(frameworkName: string) { + if (rendererNames.includes(frameworkName)) { + throw new Error(dedent` + Invalid value of ${frameworkName} in the 'framework' field of Storybook config. + Please see the v7 Migration guide for more information: + https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#framework-field-mandatory + `); + } +} diff --git a/code/lib/core-server/src/build-dev.ts b/code/lib/core-server/src/build-dev.ts index 48f0babcbfcc..72bdd1405bdf 100644 --- a/code/lib/core-server/src/build-dev.ts +++ b/code/lib/core-server/src/build-dev.ts @@ -10,6 +10,7 @@ import { loadAllPresets, cache, loadMainConfig, + validateFrameworkName, } from '@storybook/core-common'; import prompts from 'prompts'; import global from 'global'; @@ -65,6 +66,8 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui const corePresets = []; const frameworkName = typeof framework === 'string' ? framework : framework?.name; + validateFrameworkName(frameworkName); + if (frameworkName) { corePresets.push(join(frameworkName, 'preset')); } else { From fbfeca0a4d11b673ba21c0a68a099d85ef6cdffa Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 11 Oct 2022 22:20:36 -0400 Subject: [PATCH 2/3] Move release-notes test to correct spot --- .../__tests__/release-notes.test.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename code/lib/core-server/src/{build-dev.test.ts => utils/__tests__/release-notes.test.ts} (96%) diff --git a/code/lib/core-server/src/build-dev.test.ts b/code/lib/core-server/src/utils/__tests__/release-notes.test.ts similarity index 96% rename from code/lib/core-server/src/build-dev.test.ts rename to code/lib/core-server/src/utils/__tests__/release-notes.test.ts index 3e3545a0c50d..71062b7a951b 100644 --- a/code/lib/core-server/src/build-dev.test.ts +++ b/code/lib/core-server/src/utils/__tests__/release-notes.test.ts @@ -1,4 +1,4 @@ -import { getReleaseNotesData, RELEASE_NOTES_CACHE_KEY } from './utils/release-notes'; +import { getReleaseNotesData, RELEASE_NOTES_CACHE_KEY } from '../release-notes'; describe('getReleaseNotesData', () => { it('handles errors gracefully', async () => { From ccd3f932b5fd84eb7d7729e87bb347be5939553a Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 17 Oct 2022 09:00:26 -0400 Subject: [PATCH 3/3] Add instructions to run automigrate --- code/lib/core-common/src/utils/validate-config.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/lib/core-common/src/utils/validate-config.ts b/code/lib/core-common/src/utils/validate-config.ts index 6d0eac5f353b..23116e74601b 100644 --- a/code/lib/core-common/src/utils/validate-config.ts +++ b/code/lib/core-common/src/utils/validate-config.ts @@ -16,7 +16,10 @@ export function validateFrameworkName(frameworkName: string) { if (rendererNames.includes(frameworkName)) { throw new Error(dedent` Invalid value of ${frameworkName} in the 'framework' field of Storybook config. - Please see the v7 Migration guide for more information: + + Please run 'npx sb@next automigrate' + + See the v7 Migration guide for more information: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#framework-field-mandatory `); }