diff --git a/scripts/gulp/tasks/gulpGraphql.ts b/scripts/gulp/tasks/gulpGraphql.ts index 11984a50bf2..56c78cdcb5e 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 } from '../utils/childProcessUtils' -import { spawn } from 'child_process' +import { spawned, universalSpawn } from '../utils/childProcessUtils' import { DEFAULT_INTERNAL_CLOUD_ENV } from '../gulpConstants' export async function nexusCodegen () { @@ -43,7 +42,7 @@ export async function graphqlCodegen () { } export async function graphqlCodegenWatch () { - const spawned = spawn('graphql-codegen', ['--watch', '--config', 'graphql-codegen.yml'], { + const spawned = universalSpawn('graphql-codegen', ['--watch', '--config', 'graphql-codegen.yml'], { cwd: monorepoPaths.root, }) const dfd = pDefer() diff --git a/scripts/gulp/tasks/gulpWebpack.ts b/scripts/gulp/tasks/gulpWebpack.ts index 2d394ed397a..56b069cdb5f 100644 --- a/scripts/gulp/tasks/gulpWebpack.ts +++ b/scripts/gulp/tasks/gulpWebpack.ts @@ -1,7 +1,7 @@ import chalk from 'chalk' -import { spawn } from 'child_process' import pDefer from 'p-defer' import { monorepoPaths } from '../monorepoPaths' +import { universalSpawn } from '../utils/childProcessUtils' import { addChildProcess } from './gulpRegistry' export function webpackRunner () { @@ -23,10 +23,10 @@ type RunWebpackCfg = { export async function runWebpack (cfg: RunWebpackCfg) { const { cwd, args = [], env = process.env, devServer = false, prefix } = cfg const dfd = pDefer() - const spawned = spawn( + const spawned = universalSpawn( devServer - ? './node_modules/.bin/webpack-dev-server' - : './node_modules/.bin/webpack', + ? 'webpack-dev-server' + : 'webpack', args, { cwd, diff --git a/scripts/gulp/utils/childProcessUtils.ts b/scripts/gulp/utils/childProcessUtils.ts index abf03c602c8..d69c4ffcd2b 100644 --- a/scripts/gulp/utils/childProcessUtils.ts +++ b/scripts/gulp/utils/childProcessUtils.ts @@ -1,4 +1,9 @@ -import { ChildProcess, exec, ExecOptions, fork, ForkOptions, spawn, SpawnOptions } from 'child_process' +import { ChildProcess, + ChildProcessWithoutNullStreams, + exec, ExecOptions, + fork, ForkOptions, + spawn, SpawnOptions, +} from 'child_process' import through2 from 'through2' import pDefer from 'p-defer' import util from 'util' @@ -89,15 +94,10 @@ export async function spawned ( const { waitForExit, waitForData, tapErr, tapOut, ...spawnOpts } = opts const [executable, ...rest] = command.split(' ') - let useExecutable = executable - - if (process.platform === 'win32' && !useExecutable.endsWith('.cmd')) { - useExecutable = `${executable}.cmd` - } // console.log(useExecutable, rest, spawnOpts) - const cp = spawn(useExecutable, rest, { + const cp = universalSpawn(executable, rest, { stdio: 'pipe', ...spawnOpts, env: { @@ -269,3 +269,20 @@ 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 universalSpawn ( + command: string, + args: string[], + opts?: any, +): ChildProcessWithoutNullStreams { + const uCommand = isWin ? `${(command).replace(/\//g, '\\')}.cmd` : command + + return spawn(uCommand, args, opts) +}