Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Test: Prompt switch to experimental-nextjs-vite #29814

Merged
merged 16 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
extractProperFrameworkName,
loadAllPresets,
loadMainConfig,
serverResolve,
validateFrameworkName,
} from 'storybook/internal/common';
import { readConfig, writeConfig } from 'storybook/internal/csf-tools';
import { colors, logger } from 'storybook/internal/node-logger';

// eslint-disable-next-line depend/ban-dependencies
Expand Down Expand Up @@ -53,6 +55,34 @@ export default async function postInstall(options: PostinstallOptions) {
// if Vitest is installed, we use the same version to keep consistency across Vitest packages
const vitestVersionToInstall = vitestVersionSpecifier ?? 'latest';

if (info.frameworkPackageName === '@storybook/nextjs') {
const out = await prompts({
type: 'confirm',
name: 'migrateToExperimentalNextjsVite',
message: `To use this addon, you should migrate to use @storybook/experimental-nextjs-vite, do you want to migrate?`,
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
initial: true,
});

if (out.migrateToExperimentalNextjsVite) {
await packageManager.addDependencies({ installAsDevDependencies: true }, [
'@storybook/experimental-nextjs-vite',
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
]);

await packageManager.removeDependencies({}, ['@storybook/next']);
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

// update the storybook main.ts config file
const mainJsPath = serverResolve(resolve(options.configDir, 'main')) as string;

const config = await readConfig(mainJsPath);
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

config.setFieldValue(['framework'], '@storybook/experimental-nextjs-vite');
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

await writeConfig(config, mainJsPath);

info.frameworkPackageName = '@storybook/experimental-nextjs-vite';
}
}

const annotationsImport = [
'@storybook/nextjs',
'@storybook/experimental-nextjs-vite',
Expand Down
Loading