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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fix vite config automigration to resolve from project root #26262

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions code/lib/cli/src/automigrate/fixes/vite-config-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import findUp from 'find-up';
import { getFrameworkPackageName } from '../helpers/mainConfigFile';
import { frameworkToRenderer } from '../../helpers';
import { frameworkPackages } from '@storybook/core-common';
import path from 'path';

interface ViteConfigFileRunOptions {
plugins: string[];
Expand All @@ -15,13 +16,13 @@ export const viteConfigFile = {

versionRange: ['<8.0.0-beta.3', '>=8.0.0-beta.3'],

async check({ mainConfig, packageManager }) {
let isViteConfigFileFound = !!(await findUp([
'vite.config.js',
'vite.config.mjs',
'vite.config.cjs',
'vite.config.ts',
]));
promptType: 'notification',

async check({ mainConfig, packageManager, mainConfigPath }) {
let isViteConfigFileFound = !!(await findUp(
['vite.config.js', 'vite.config.mjs', 'vite.config.cjs', 'vite.config.ts'],
{ cwd: mainConfigPath ? path.join(mainConfigPath, '..') : process.cwd() }
));

const rendererToVitePluginMap: Record<string, string> = {
preact: '@preact/preset-vite',
Expand Down
22 changes: 18 additions & 4 deletions code/lib/cli/src/automigrate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export interface RunOptions<ResultType> {
*/
export type Prompt = 'auto' | 'manual' | 'notification';

export interface Fix<ResultType = any> {
type BaseFix<ResultType = any> = {
id: string;
promptType?: Prompt | ((result: ResultType) => Promise<Prompt> | Prompt);
/**
* The from/to version range of Storybook that this fix applies to. The strings are semver ranges.
* The versionRange will only be checked if the automigration is part of an upgrade.
Expand All @@ -38,8 +37,23 @@ export interface Fix<ResultType = any> {
versionRange: [from: string, to: string];
check: (options: CheckOptions) => Promise<ResultType | null>;
prompt: (result: ResultType) => string;
run?: (options: RunOptions<ResultType>) => Promise<void>;
}
};

type PromptType<ResultType = any, T = Prompt> =
| T
| ((result: ResultType) => Promise<Prompt> | Prompt);

export type Fix<ResultType = any> = (
| {
promptType?: PromptType<ResultType, 'auto'>;
run: (options: RunOptions<ResultType>) => Promise<void>;
}
| {
promptType: PromptType<ResultType, 'manual' | 'notification'>;
run?: never;
}
) &
BaseFix<ResultType>;
Comment on lines +42 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


export type FixId = string;

Expand Down