From bc436e15f1cd53207c5ffd7b93828de715c8a92f Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 11 Sep 2022 13:38:04 +0800 Subject: [PATCH] Build: Add extra dependencies for linked stories --- scripts/sandbox.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/sandbox.ts b/scripts/sandbox.ts index bb2add4c8ca3..3281bdeffcdb 100644 --- a/scripts/sandbox.ts +++ b/scripts/sandbox.ts @@ -24,6 +24,7 @@ import { babelParse } from '../code/lib/csf-tools/src/babelParse'; import TEMPLATES from '../code/lib/cli/src/repro-templates'; import { servePackages } from './utils/serve-packages'; import { filterExistsInCodeDir, codeDir } from './utils/filterExistsInCodeDir'; +import { JsPackageManagerFactory } from '../code/lib/cli/src/js-package-manager'; type Template = keyof typeof TEMPLATES; const templates: Template[] = Object.keys(TEMPLATES) as any; @@ -316,6 +317,23 @@ function workspacePath(type: string, packageName: string, workspaces: Workspace[ return workspace.location; } +function addExtraDependencies({ + cwd, + dryRun, + debug, +}: { + cwd: string; + dryRun: boolean; + debug: boolean; +}) { + const extraDeps = ['@storybook/jest']; + if (debug) console.log('🎁 Adding extra deps', extraDeps); + if (!dryRun) { + const packageManager = JsPackageManagerFactory.getPackageManager(false, cwd); + packageManager.addDependencies({ installAsDevDependencies: true }, extraDeps); + } +} + export async function sandbox(optionValues: OptionValues) { const { template, forceDelete, forceReuse, dryRun, debug, fromLocalRepro } = optionValues; @@ -457,6 +475,9 @@ export async function sandbox(optionValues: OptionValues) { ); } + // Some addon stories require extra dependencies + addExtraDependencies({ cwd, dryRun, debug }); + await addPackageScripts({ cwd, scripts: {