diff --git a/scripts/exec-sync.js b/scripts/exec-sync.js deleted file mode 100644 index a9babe22d1bde7..00000000000000 --- a/scripts/exec-sync.js +++ /dev/null @@ -1,23 +0,0 @@ -// @ts-check -const child_process = require('child_process'); -const chalk = require('chalk'); -const { logStatus } = require('./logging'); - -/** - * @deprecated Use `child_process.execSync` directly. - * Execute a command synchronously. - * - * @param {string} cmd Command to execute - * @param {string} [displayName] Display name for the command - * @param {string} [cwd] Working directory in which to run the command - */ -function execSync(cmd, displayName, cwd = process.cwd()) { - logStatus(chalk.gray('Executing: ') + chalk.cyan(displayName || cmd)); - - child_process.execSync(cmd, { - cwd, - stdio: 'inherit', - }); -} - -module.exports = execSync; diff --git a/scripts/exec.js b/scripts/exec.js deleted file mode 100644 index 40cd4fd16bbce3..00000000000000 --- a/scripts/exec.js +++ /dev/null @@ -1,53 +0,0 @@ -// @ts-check -const child_process = require('child_process'); -const chalk = require('chalk'); -const { logStatus } = require('./logging'); - -/** - * @deprecated Use `child_process.exec` directly. - * Execute a command. - * - * @typedef {{ - * stdout?: string | Buffer; - * stderr?: string | Buffer; - * err?: import("child_process").ExecException - * }} ExecResult - * - * @param {string} cmd Command to execute - * @param {string} [displayName] Display name for the command - * @param {string} [cwd] Working directory in which to run the command - * @param {{ stdout?: any; stderr?: any; }} [opts] Pipe stdout/stderr somewhere. Can pass `process` global. - * @returns {Promise} - */ -function exec(cmd, displayName, cwd = process.cwd(), opts = {}) { - logStatus(chalk.gray('Executing: ') + chalk.cyan(displayName || cmd)); - - const execOptions = { - cwd, - encoding: 'utf8', - }; - - return new Promise((resolve, reject) => { - const child = child_process.exec(cmd, execOptions, (error, stdout, stderr) => - error - ? reject({ - error, - stdout: stdout, - stderr: stderr, - }) - : resolve({ - stdout: stdout, - stderr: stderr, - }), - ); - - if (opts.stdout) { - child.stdout.pipe(opts.stdout); - } - if (opts.stderr) { - child.stderr.pipe(opts.stderr); - } - }); -} - -module.exports = exec; diff --git a/scripts/lint-staged/eslint.js b/scripts/lint-staged/eslint.js index 52201404dbce37..2f0abc633ccf84 100644 --- a/scripts/lint-staged/eslint.js +++ b/scripts/lint-staged/eslint.js @@ -3,9 +3,11 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); +const { promisify } = require('util'); +const child_process = require('child_process'); const { rollup: lernaAliases } = require('lerna-alias'); const { default: PQueue } = require('p-queue'); -const exec = require('../exec'); +const exec = promisify(child_process.exec); const eslintForPackageScript = path.join(__dirname, 'eslint-for-package.js'); @@ -60,7 +62,7 @@ async function runEslintOnFilesGroupedPerPackage() { Object.entries(filesGroupedByPackage).map(([packagePath, files]) => async () => { // This script handles running eslint on ONLY the appropriate files for each package. // See its comments for more details. - return exec(`node ${eslintForPackageScript} ${files.join(' ')}`, undefined, packagePath, process).catch(() => { + return exec(`node ${eslintForPackageScript} ${files.join(' ')}`, { cwd: packagePath }).catch(() => { // The subprocess should already have handled logging. Just mark that there was an error. hasError = true; }); diff --git a/scripts/local-codepen.js b/scripts/local-codepen.js index 73c80051659e11..3db188609f2e63 100644 --- a/scripts/local-codepen.js +++ b/scripts/local-codepen.js @@ -3,7 +3,7 @@ const WebpackDevServer = require('webpack-dev-server'); const path = require('path'); const fs = require('fs'); const yargs = require('yargs'); -const execSync = require('./exec-sync'); +const { execSync } = require('child_process'); const { findGitRoot } = require('./monorepo/index'); const chalk = require('chalk'); @@ -19,7 +19,7 @@ if (fs.existsSync(configPath)) { try { console.log("Attempting to npm link globally installed ngrok so it can be require'd"); // This will probably install ngrok globally if it's not already present - execSync('npm link ngrok@3', undefined, gitRoot); + execSync('npm link ngrok@3', { cwd: gitRoot, stdio: 'inherit' }); // @ts-expect-error - no types for ngrok ngrok = require('ngrok'); } catch (err) { diff --git a/scripts/tasks/webpack.ts b/scripts/tasks/webpack.ts index d65b944d3f3166..00d4c99b1e1a32 100644 --- a/scripts/tasks/webpack.ts +++ b/scripts/tasks/webpack.ts @@ -1,7 +1,7 @@ import { webpackCliTask, argv, logger } from 'just-scripts'; import * as path from 'path'; import * as fs from 'fs'; -import execSync from '../exec-sync'; +import { execSync } from 'child_process'; import { getJustArgv } from './argv'; export function webpack() { @@ -48,7 +48,7 @@ export function webpackDevServer( process.env.cached = String(args.cached); - execSync(cmd); + execSync(cmd, { stdio: 'inherit' }); } }; } diff --git a/scripts/token-pipeline.ts b/scripts/token-pipeline.ts index 405874813d1471..3ce57f08518d8e 100644 --- a/scripts/token-pipeline.ts +++ b/scripts/token-pipeline.ts @@ -2,9 +2,9 @@ import path from 'path'; import * as fs from 'fs-extra'; import * as _ from 'lodash'; import * as yargs from 'yargs'; +import { execSync } from 'child_process'; import { findGitRoot } from './monorepo'; -import execSync from './exec-sync'; import { createTempDir } from './projects-test'; const themes = ['light', 'dark', 'teamsDark', 'highContrast'] as const; @@ -34,6 +34,8 @@ function getGeneratedFiles(tmpDir: string) { function runPipeline(theme: typeof themes[number], pipelineDir: string, outDir: string) { console.log(`Running pipeline for ${theme} theme`); + console.log(`Generate tokens for theme`); + // https://github.com/microsoft/fluentui-token-pipeline execSync( [ @@ -44,8 +46,7 @@ function runPipeline(theme: typeof themes[number], pipelineDir: string, outDir: `--in src/${_.kebabCase(theme)}.json`, `--out ${outDir}/${theme}`, ].join(' '), - `Generate tokens for theme:${theme}`, - pipelineDir, + { cwd: pipelineDir }, ); } @@ -59,14 +60,15 @@ function setupDesignTokensRepo(options: { argv: typeof argv }) { return { pipelineDir, tmpDir }; } + console.log('Clone design tokens repo'); // clone repo, install deps - execSync( - 'git clone --depth 1 https://github.com/microsoft/fluentui-design-tokens.git', - 'Clone design tokens repo', - tmpDir, - ); + execSync('git clone --depth 1 https://github.com/microsoft/fluentui-design-tokens.git', { + cwd: tmpDir, + stdio: 'inherit', + }); const pipelineDir = path.join(tmpDir, 'fluentui-design-tokens'); - execSync('npm install', 'Install dependencies', pipelineDir); + console.log('Install dependencies'); + execSync('npm install', { cwd: pipelineDir, stdio: 'inherit' }); return { pipelineDir, tmpDir }; } @@ -83,7 +85,8 @@ const tokenPipeline = () => { fs.copySync(file.src, file.dest, { overwrite: true }); }); - execSync(`npx prettier --write ${path.join(repoRoot, 'packages/react-components/react-theme/src')}`, 'Prettier'); + console.log('Format'); + execSync(`npx prettier --write ${path.join(repoRoot, 'packages/react-components/react-theme/src')}`); }; tokenPipeline();