Skip to content

Commit

Permalink
Merge pull request #22501 from storybookjs/build/vite-react-plugin-co…
Browse files Browse the repository at this point in the history
…nflict

Sandboxes: Pin @vitejs/plugin-react to avoid conflict
  • Loading branch information
chakAs3 committed May 10, 2023
2 parents df5b79e + cd28e82 commit 2d87152
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { join, resolve, sep } from 'path';
import slash from 'slash';
import type { Task } from '../task';
import { executeCLIStep, steps } from '../utils/cli-step';
import { installYarn2, configureYarn2ForVerdaccio, addPackageResolutions } from '../utils/yarn';
import {
installYarn2,
configureYarn2ForVerdaccio,
addPackageResolutions,
addWorkaroundResolutions,
} from '../utils/yarn';
import { exec } from '../utils/exec';
import type { ConfigFile } from '../../code/lib/csf-tools';
import { writeConfig } from '../../code/lib/csf-tools';
Expand Down Expand Up @@ -81,6 +86,7 @@ export const install: Task['run'] = async (
dryRun,
debug,
});
await addWorkaroundResolutions({ cwd, dryRun, debug });
} else {
// We need to add package resolutions to ensure that we only ever install the latest version
// of any storybook packages as verdaccio is not able to both proxy to npm and publish over
Expand Down
13 changes: 13 additions & 0 deletions scripts/utils/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export const installYarn2 = async ({ cwd, dryRun, debug }: YarnOptions) => {
);
};

export const addWorkaroundResolutions = async ({ cwd, dryRun }: YarnOptions) => {
logger.info(`🔢 Adding resolutions for workarounds`);
if (dryRun) return;

const packageJsonPath = path.join(cwd, 'package.json');
const packageJson = await readJSON(packageJsonPath);
packageJson.resolutions = {
...packageJson.resolutions,
'@vitejs/plugin-react': '^4.0.0', // due to conflicting version in @storybook/vite-react
};
await writeJSON(packageJsonPath, packageJson, { spaces: 2 });
};

export const configureYarn2ForVerdaccio = async ({ cwd, dryRun, debug }: YarnOptions) => {
const command = [
// We don't want to use the cache or we might get older copies of our built packages
Expand Down

0 comments on commit 2d87152

Please sign in to comment.