diff --git a/code/addons/themes/postinstall.js b/code/addons/themes/postinstall.js index 01a9b3151e89..87175ac9cbc1 100644 --- a/code/addons/themes/postinstall.js +++ b/code/addons/themes/postinstall.js @@ -1,17 +1,24 @@ const { spawn } = require('child_process'); const PACKAGE_MANAGER_TO_COMMAND = { - npm: 'npx', - yarn1: 'npx', - yarn2: 'yarn dlx', - pnpm: 'pnpm dlx', + npm: ['npx'], + pnpm: ['pnpm', 'dlx'], + yarn1: ['npx'], + yarn2: ['yarn', 'dlx'], }; -module.exports = function postinstall(options) { - const command = PACKAGE_MANAGER_TO_COMMAND[options.packageManager]; +const selectPackageManagerCommand = (packageManager) => PACKAGE_MANAGER_TO_COMMAND[packageManager]; - spawn(command, ['@storybook/auto-config', 'themes'], { +const spawnPackageManagerScript = async (packageManager, args) => { + const [command, ...baseArgs] = selectPackageManagerCommand(packageManager); + + await spawn(command, [...baseArgs, ...args], { stdio: 'inherit', cwd: process.cwd(), + shell: true, }); }; + +module.exports = async function postinstall({ packageManager = 'npm' }) { + await spawnPackageManagerScript(packageManager, ['@storybook/auto-config', 'themes']); +};