Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions scripts/gulp/tasks/gulpGraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions scripts/gulp/tasks/gulpWebpack.ts
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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,
Expand Down
31 changes: 24 additions & 7 deletions scripts/gulp/utils/childProcessUtils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a strange name since it works on *nix and Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree universalSpawn woudl be better