diff --git a/code/lib/cli/src/link.ts b/code/lib/cli/src/link.ts index 090f0434fb2a..3a61eb02a147 100644 --- a/code/lib/cli/src/link.ts +++ b/code/lib/cli/src/link.ts @@ -33,9 +33,12 @@ export const exec = async ( return new Promise((resolve, reject) => { const child = spawnAsync(command, { ...options, + shell: true, + stdio: 'pipe', }); - child.stderr.pipe(process.stderr); + child.stderr.pipe(process.stdout); + child.stdout.pipe(process.stdout); child.on('exit', (code) => { if (code === 0) { diff --git a/code/lib/cli/src/repro-generators/scripts.ts b/code/lib/cli/src/repro-generators/scripts.ts index d5056b2540c9..4893e81fd2da 100644 --- a/code/lib/cli/src/repro-generators/scripts.ts +++ b/code/lib/cli/src/repro-generators/scripts.ts @@ -2,7 +2,8 @@ import path from 'path'; import { readJSON, writeJSON, outputFile, remove } from 'fs-extra'; import chalk from 'chalk'; import { command } from 'execa'; -import spawn from 'cross-spawn'; +import type spawn from 'cross-spawn'; +import { spawn as spawnAsync } from 'cross-spawn'; import { cra, cra_typescript } from './configs'; import storybookVersions from '../versions'; @@ -70,18 +71,21 @@ export const exec = async ( logger.debug(command); return new Promise((resolve, reject) => { - const child = spawn(command, { + const child = spawnAsync(command, { ...options, + shell: true, + stdio: 'pipe', }); - child.stderr.pipe(process.stderr); + child.stderr.pipe(process.stdout); + child.stdout.pipe(process.stdout); child.on('exit', (code) => { if (code === 0) { resolve(undefined); } else { logger.error(chalk.red(`An error occurred while executing: \`${command}\``)); - logger.log(errorMessage); + logger.info(errorMessage); reject(new Error(`command exited with code: ${code}: `)); } }); diff --git a/node_modules/.yarn-state.yml b/node_modules/.yarn-state.yml index 7ee729427c55..a6b1a224e847 100644 --- a/node_modules/.yarn-state.yml +++ b/node_modules/.yarn-state.yml @@ -5,6 +5,6 @@ __metadata: version: 1 nmMode: classic -"root-workspace-0b6124@workspace:.": +"@storybook/root@workspace:.": locations: - "" diff --git a/package.json b/package.json index ec338fe09b73..7f2146e9208f 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "name": "@storybook/root", "scripts": { "ci-tests": "cd code; yarn ci-tests", "get-report-message": "cd scripts; yarn get-report-message", diff --git a/scripts/check-dependencies.js b/scripts/check-dependencies.js index 0346dbf48f64..c8bd9114faf9 100755 --- a/scripts/check-dependencies.js +++ b/scripts/check-dependencies.js @@ -1,63 +1,5 @@ #!/usr/bin/env node - -const { spawn } = require('child_process'); -const { join } = require('path'); -const { existsSync } = require('fs'); - -const checkDependencies = async () => { - const scriptsPath = join(__dirname); - const codePath = join(__dirname, '..', 'code'); - - const tasks = []; - - if (!existsSync(join(scriptsPath, 'node_modules'))) { - tasks.push( - spawn('yarn', ['install'], { - cwd: scriptsPath, - stdio: ['inherit', 'inherit', 'inherit'], - }) - ); - } - if (!existsSync(join(codePath, 'node_modules'))) { - tasks.push( - spawn('yarn', ['install'], { - cwd: codePath, - stdio: ['inherit', 'inherit', 'inherit'], - }) - ); - } - - if (tasks.length > 0) { - console.log('installing dependencies'); - - await Promise.all( - tasks.map( - (t) => - new Promise((res, rej) => { - t.on('exit', (code) => { - if (code !== 0) { - rej(); - } else { - res(); - } - }); - }) - ) - ).catch(() => { - tasks.forEach((t) => t.kill()); - throw new Error('Failed to install dependencies'); - }); - - // give the filesystem some time - await new Promise((res, rej) => { - setTimeout(res, 1000); - }); - } -}; - -module.exports = { - checkDependencies, -}; +const { checkDependencies } = require('./utils/cli-utils'); checkDependencies().catch((e) => { console.error(e); diff --git a/scripts/tasks/install.ts b/scripts/tasks/install.ts index e98be69d65ff..653eda568381 100644 --- a/scripts/tasks/install.ts +++ b/scripts/tasks/install.ts @@ -1,15 +1,15 @@ import { pathExists, remove } from 'fs-extra'; import { join } from 'path'; import type { Task } from '../task'; -import { exec } from '../utils/exec'; export const install: Task = { description: 'Install the dependencies of the monorepo', async ready({ codeDir }) { return pathExists(join(codeDir, 'node_modules')); }, - async run({ codeDir }, { dryRun, debug }) { - await exec(`yarn install`, { cwd: codeDir }, { dryRun, debug }); + async run({ codeDir }) { + // eslint-disable-next-line global-require + await require('../utils/cli-utils').checkDependencies(); // these are webpack4 types, we we should never use await remove(join(codeDir, 'node_modules', '@types', 'webpack')); diff --git a/scripts/utils/cli-utils.js b/scripts/utils/cli-utils.js index 5d39797f388d..ba52d9338875 100644 --- a/scripts/utils/cli-utils.js +++ b/scripts/utils/cli-utils.js @@ -14,6 +14,7 @@ const checkDependencies = async () => { tasks.push( spawn('yarn', ['install'], { cwd: scriptsPath, + shell: true, stdio: ['inherit', 'inherit', 'inherit'], }) ); @@ -22,6 +23,7 @@ const checkDependencies = async () => { tasks.push( spawn('yarn', ['install'], { cwd: codePath, + shell: true, stdio: ['inherit', 'inherit', 'inherit'], }) ); diff --git a/yarn.lock b/yarn.lock index 722dc3679e93..60e814efe6f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4,8 +4,8 @@ __metadata: version: 6 -"root-workspace-0b6124@workspace:.": +"@storybook/root@workspace:.": version: 0.0.0-use.local - resolution: "root-workspace-0b6124@workspace:." + resolution: "@storybook/root@workspace:." languageName: unknown linkType: soft