Skip to content

Commit

Permalink
Merge pull request #19452 from storybookjs/cli/old-framework-error
Browse files Browse the repository at this point in the history
Core: Throw an error if renderer is used as framework
  • Loading branch information
shilman authored Oct 18, 2022
2 parents 90c58e7 + ccd3f93 commit dd96c9e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/lib/core-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
26 changes: 26 additions & 0 deletions code/lib/core-common/src/utils/validate-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 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
`);
}
}
3 changes: 3 additions & 0 deletions code/lib/core-server/src/build-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
loadAllPresets,
cache,
loadMainConfig,
validateFrameworkName,
} from '@storybook/core-common';
import prompts from 'prompts';
import global from 'global';
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down

0 comments on commit dd96c9e

Please sign in to comment.