diff --git a/scripts/gulp/tasks/gulpGraphql.ts b/scripts/gulp/tasks/gulpGraphql.ts index 8927aff03a6d..866e6ea3d61f 100644 --- a/scripts/gulp/tasks/gulpGraphql.ts +++ b/scripts/gulp/tasks/gulpGraphql.ts @@ -9,8 +9,7 @@ import { minifyIntrospectionQuery } from '@urql/introspection' import { nexusTypegen, watchNexusTypegen } from '../utils/nexusTypegenUtil' import { monorepoPaths } from '../monorepoPaths' -import { spawned, winSpawn } from '../utils/childProcessUtils' -import { spawn } from 'child_process' +import { spawned } from '../utils/childProcessUtils' import { DEFAULT_INTERNAL_CLOUD_ENV } from '../gulpConstants' export async function nexusCodegen () { @@ -43,13 +42,13 @@ export async function graphqlCodegen () { } export async function graphqlCodegenWatch () { - const spawned = spawn(winSpawn('graphql-codegen'), ['--watch', '--config', 'graphql-codegen.yml'], { + const spawnedProcess = await spawned('gql-codegen', 'yarn graphql-codegen --watch --config graphql-codegen.yml', { cwd: monorepoPaths.root, }) const dfd = pDefer() let hasResolved = false - spawned.stdout.on('data', (chunk) => { + spawnedProcess.stdout?.on('data', (chunk) => { const strs = `${chunk}`.split('\n').filter((f) => f) const timestampRegex = /\[\d{2}:\d{2}:\d{2}\]/ const isFailureBlock = strs.some((s) => s.includes('[failed]')) @@ -75,7 +74,7 @@ export async function graphqlCodegenWatch () { }) }) - spawned.stderr.on('data', (data) => { + spawnedProcess.stderr?.on('data', (data) => { console.error(chalk.red(String(data))) }) diff --git a/scripts/gulp/tasks/gulpWebpack.ts b/scripts/gulp/tasks/gulpWebpack.ts index 976f55b1047b..a4c6ec465fbd 100644 --- a/scripts/gulp/tasks/gulpWebpack.ts +++ b/scripts/gulp/tasks/gulpWebpack.ts @@ -1,8 +1,7 @@ import chalk from 'chalk' -import { spawn } from 'child_process' import pDefer from 'p-defer' import { monorepoPaths } from '../monorepoPaths' -import { winSpawn } from '../utils/childProcessUtils' +import { spawned } from '../utils/childProcessUtils' import { addChildProcess } from './gulpRegistry' export function webpackRunner () { @@ -24,23 +23,21 @@ type RunWebpackCfg = { export async function runWebpack (cfg: RunWebpackCfg) { const { cwd, args = [], env = process.env, devServer = false, prefix } = cfg const dfd = pDefer() - const spawned = spawn( - winSpawn(devServer + const spawnedProcess = await spawned('webpack-watch', + [devServer ? 'webpack-dev-server' - : 'webpack'), - args, + : 'webpack', ...args].join(' '), { cwd, env: { ...(env || process.env), FORCE_COLOR: '1', }, - }, - ) + }) - addChildProcess(spawned) + addChildProcess(spawnedProcess) - spawned.stdout.on('data', (chunk) => { + spawnedProcess.stdout?.on('data', (chunk) => { process.stdout.write('\n') String(chunk) .split('\n') @@ -59,7 +56,7 @@ export async function runWebpack (cfg: RunWebpackCfg) { }) }) - spawned.stderr.on('data', (chunk) => { + spawnedProcess.stderr?.on('data', (chunk) => { process.stderr.write('\n') String(chunk) .split('\n') diff --git a/scripts/gulp/utils/childProcessUtils.ts b/scripts/gulp/utils/childProcessUtils.ts index 0c7e51728d9e..e76b8b08e987 100644 --- a/scripts/gulp/utils/childProcessUtils.ts +++ b/scripts/gulp/utils/childProcessUtils.ts @@ -7,6 +7,7 @@ import { prefixLog, prefixStream } from './prefixStream' import { addChildProcess } from '../tasks/gulpRegistry' export type AllSpawnableApps = + | `webpack-${string}` | `cmd-${string}` | `vite-${string}` | `vite:build-${string}` @@ -269,14 +270,3 @@ function streamHandler (cp: ChildProcess, config: StreamHandlerConfig) { return dfd.promise } - -const isWin = process.platform === 'win32' - -/** - * Pretreat commands to make them compatible with windows - * @param command - * @returns - */ -export function winSpawn (command: string): string { - return `${(`./node_modules/.bin/${command}`).replace(/\//g, '\\')}${isWin ? '.cmd' : ''}` -}