mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-20 05:02:37 +08:00
remove mainjsFramework automigration
This commit is contained in:
parent
8647baab29
commit
d7f0f405ec
@ -4,7 +4,6 @@ import { cra5 } from './cra5';
|
||||
import { webpack5 } from './webpack5';
|
||||
import { angular12 } from './angular12';
|
||||
import { vue3 } from './vue3';
|
||||
import { mainjsFramework } from './mainjsFramework';
|
||||
import { eslintPlugin } from './eslint-plugin';
|
||||
import { builderVite } from './builder-vite';
|
||||
import { sbScripts } from './sb-scripts';
|
||||
@ -27,7 +26,6 @@ export const fixes: Fix[] = [
|
||||
webpack5,
|
||||
angular12,
|
||||
vue3,
|
||||
mainjsFramework,
|
||||
eslintPlugin,
|
||||
sveltekitFramework,
|
||||
builderVite,
|
||||
|
@ -1,85 +0,0 @@
|
||||
import chalk from 'chalk';
|
||||
import { dedent } from 'ts-dedent';
|
||||
|
||||
import semver from 'semver';
|
||||
import type { ConfigFile } from '@storybook/csf-tools';
|
||||
import { readConfig, writeConfig } from '@storybook/csf-tools';
|
||||
import { getStorybookInfo } from '@storybook/core-common';
|
||||
|
||||
import type { Fix } from '../types';
|
||||
|
||||
const logger = console;
|
||||
|
||||
interface MainjsFrameworkRunOptions {
|
||||
framework: string;
|
||||
main: ConfigFile;
|
||||
}
|
||||
|
||||
export const mainjsFramework: Fix<MainjsFrameworkRunOptions> = {
|
||||
id: 'mainjsFramework',
|
||||
|
||||
async check({ packageManager, configDir, frameworkPackage: userDefinedFrameworkPackage }) {
|
||||
const packageJson = packageManager.retrievePackageJson();
|
||||
|
||||
if (configDir) {
|
||||
logger.info(`📦 Storybook config directory: `, configDir);
|
||||
}
|
||||
|
||||
// FIXME: use renderer in SB7?
|
||||
const {
|
||||
mainConfig,
|
||||
framework,
|
||||
frameworkPackage,
|
||||
version: storybookVersion,
|
||||
} = getStorybookInfo(packageJson, configDir, userDefinedFrameworkPackage);
|
||||
|
||||
if (!mainConfig) {
|
||||
logger.warn('Unable to find storybook main.js config, skipping');
|
||||
return null;
|
||||
}
|
||||
|
||||
const storybookCoerced = storybookVersion && semver.coerce(storybookVersion)?.version;
|
||||
if (!storybookCoerced) {
|
||||
throw new Error(dedent`
|
||||
❌ Unable to determine storybook version.
|
||||
🤔 Are you running automigrate from your project directory?
|
||||
`);
|
||||
}
|
||||
|
||||
const main = await readConfig(mainConfig);
|
||||
const currentFramework = main.getFieldNode(['framework']);
|
||||
const features = main.getFieldValue(['features']);
|
||||
|
||||
if (currentFramework) return null;
|
||||
|
||||
return features?.breakingChangesV7 ||
|
||||
features?.storyStoreV7 ||
|
||||
semver.gte(storybookCoerced, '7.0.0')
|
||||
? { main, framework: frameworkPackage ?? `@storybook/${framework}` }
|
||||
: null;
|
||||
},
|
||||
|
||||
prompt({ framework }) {
|
||||
const frameworkFormatted = chalk.cyan(`framework: '${framework}'`);
|
||||
|
||||
return dedent`
|
||||
We've detected that your main.js configuration file does not specify the
|
||||
'framework' field, which is a requirement in SB7.0 and above. We can add one
|
||||
for you automatically:
|
||||
|
||||
${frameworkFormatted}
|
||||
|
||||
More info: ${chalk.yellow(
|
||||
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mainjs-framework-field'
|
||||
)}
|
||||
`;
|
||||
},
|
||||
|
||||
async run({ result: { main, framework }, dryRun }) {
|
||||
logger.info(`✅ Setting 'framework' to '${framework}' in main.js`);
|
||||
if (!dryRun) {
|
||||
main.setFieldValue(['framework'], framework);
|
||||
await writeConfig(main);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user