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

feat: add flag to disable shell mode for nest start --watch #2522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions actions/start.action.ts
Expand Up @@ -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(
Expand All @@ -103,6 +106,7 @@ export class StartAction extends BuildAction {
debugFlag: boolean | string | undefined,
outDirName: string,
binaryToRun: string,
useShell: boolean,
) {
let childProcessRef: any;
process.on(
Expand All @@ -120,6 +124,7 @@ export class StartAction extends BuildAction {
debugFlag,
outDirName,
binaryToRun,
useShell,
);
childProcessRef.on('exit', () => (childProcessRef = undefined));
});
Expand All @@ -133,6 +138,7 @@ export class StartAction extends BuildAction {
debugFlag,
outDirName,
binaryToRun,
useShell,
);
childProcessRef.on('exit', (code: number) => {
process.exitCode = code;
Expand All @@ -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')) {
Expand Down Expand Up @@ -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,
});
}

Expand Down
5 changes: 5 additions & 0 deletions commands/start.command.ts
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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)) {
Expand Down