Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix dev process on windows #19401

Merged
merged 8 commits into from
Dec 20, 2021
4 changes: 2 additions & 2 deletions scripts/gulp/tasks/gulpGraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { minifyIntrospectionQuery } from '@urql/introspection'

import { nexusTypegen, watchNexusTypegen } from '../utils/nexusTypegenUtil'
import { monorepoPaths } from '../monorepoPaths'
import { spawned } from '../utils/childProcessUtils'
import { spawned, winSpawn } from '../utils/childProcessUtils'
import { spawn } from 'child_process'
import { DEFAULT_INTERNAL_CLOUD_ENV } from '../gulpConstants'

Expand Down Expand Up @@ -43,7 +43,7 @@ export async function graphqlCodegen () {
}

export async function graphqlCodegenWatch () {
const spawned = spawn('graphql-codegen', ['--watch', '--config', 'graphql-codegen.yml'], {
const spawned = spawn(winSpawn('graphql-codegen'), ['--watch', '--config', 'graphql-codegen.yml'], {
cwd: monorepoPaths.root,
})
const dfd = pDefer()
Expand Down
7 changes: 4 additions & 3 deletions scripts/gulp/tasks/gulpWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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 { addChildProcess } from './gulpRegistry'

export function webpackRunner () {
Expand All @@ -24,9 +25,9 @@ export async function runWebpack (cfg: RunWebpackCfg) {
const { cwd, args = [], env = process.env, devServer = false, prefix } = cfg
const dfd = pDefer()
const spawned = spawn(
devServer
? './node_modules/.bin/webpack-dev-server'
: './node_modules/.bin/webpack',
winSpawn(devServer
? 'webpack-dev-server'
: 'webpack'),
args,
{
cwd,
Expand Down
17 changes: 12 additions & 5 deletions scripts/gulp/utils/childProcessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ 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`
}
const useExecutable = winSpawn(executable)

// console.log(useExecutable, rest, spawnOpts)

Expand Down Expand Up @@ -269,3 +265,14 @@ 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 `${(command).replace(/\//g, '\\')}${isWin ? '.cmd' : ''}`
}
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