diff --git a/actions/start.action.ts b/actions/start.action.ts index 4b628ad93..680c2f4d0 100644 --- a/actions/start.action.ts +++ b/actions/start.action.ts @@ -72,12 +72,15 @@ export class StartAction extends BuildAction { commandOptions, defaultConfiguration.sourceRoot, ); + const noShellOption = commandOptions.find((option) => option.name === 'noShell') + const useShell = noShellOption ? !noShellOption.value : true; const onSuccess = this.createOnSuccessHook( entryFile, sourceRoot, debugFlag, outDir, binaryToRun, + useShell, ); await this.runBuild( @@ -103,6 +106,7 @@ export class StartAction extends BuildAction { debugFlag: boolean | string | undefined, outDirName: string, binaryToRun: string, + useShell: boolean, ) { let childProcessRef: any; process.on( @@ -120,6 +124,7 @@ export class StartAction extends BuildAction { debugFlag, outDirName, binaryToRun, + useShell, ); childProcessRef.on('exit', () => (childProcessRef = undefined)); }); @@ -133,6 +138,7 @@ export class StartAction extends BuildAction { debugFlag, outDirName, binaryToRun, + useShell, ); childProcessRef.on('exit', (code: number) => { process.exitCode = code; @@ -148,6 +154,7 @@ export class StartAction extends BuildAction { debug: boolean | string | undefined, outDirName: string, binaryToRun: string, + useShell: boolean, ) { let outputFilePath = join(outDirName, sourceRoot, entryFile); if (!fs.existsSync(outputFilePath + '.js')) { @@ -177,11 +184,11 @@ export class StartAction extends BuildAction { } const sourceMapsRegisterPath = this.getSourceMapSupportPkg(); if (sourceMapsRegisterPath !== undefined) { - processArgs.unshift(`-r "${sourceMapsRegisterPath}"`); + processArgs.unshift('-r', `"${sourceMapsRegisterPath}"`); } return spawn(binaryToRun, processArgs, { stdio: 'inherit', - shell: true, + shell: useShell, }); } diff --git a/commands/start.command.ts b/commands/start.command.ts index 361f48fbd..690919339 100644 --- a/commands/start.command.ts +++ b/commands/start.command.ts @@ -38,6 +38,7 @@ export class StartCommand extends AbstractCommand { '--preserveWatchOutput', 'Use "preserveWatchOutput" option when using tsc watch mode.', ) + .option('--noShell', 'Spawn child processes without shell (see node\'s child_process.spawn() method docs)') .description('Run Nest application.') .action(async (app: string, command: Command) => { const options: Input[] = []; @@ -79,6 +80,10 @@ export class StartCommand extends AbstractCommand { !!command.watch && !isWebpackEnabled, }); + options.push({ + name: 'noShell', + value: !!command.noShell, + }) const availableBuilders = ['tsc', 'webpack', 'swc']; if (command.builder && !availableBuilders.includes(command.builder)) {