Skip to content

Commit

Permalink
Merge branch 'feat/manual-restart-watchmode' of https://github.com/sh…
Browse files Browse the repository at this point in the history
…eerlox/nest-cli into sheerlox-feat/manual-restart-watchmode
  • Loading branch information
kamilmysliwiec committed Apr 13, 2023
2 parents 6560db4 + a3b04f1 commit 4eeddcb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/compiler/helpers/manual-restart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function listenForManualRestart(callback: () => void) {
const stdinListener = (data: Buffer) => {
if (data.toString().trim() === 'rs') {
process.stdin.removeListener('data', stdinListener);
callback();
}
};
process.stdin.on('data', stdinListener);
}

export function displayManualRestartTip(): void {
console.log('To restart at any time, enter `rs`..\n');
}
23 changes: 21 additions & 2 deletions lib/compiler/watch-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as ts from 'typescript';
import { Configuration } from '../configuration';
import { CLI_ERRORS } from '../ui/errors';
import { getValueOrDefault } from './helpers/get-value-or-default';
import {
displayManualRestartTip,
listenForManualRestart,
} from './helpers/manual-restart';
import { TsConfigProvider } from './helpers/tsconfig-provider';
import { tsconfigPathsBeforeHookFactory } from './hooks/tsconfig-paths.hook';
import { PluginsLoader } from './plugins-loader';
Expand Down Expand Up @@ -68,7 +72,11 @@ export class WatchCompiler {
host: ts.CompilerHost,
oldProgram: ts.EmitAndSemanticDiagnosticsBuilderProgram,
) => {
const tsconfigPathsPlugin = options ? tsconfigPathsBeforeHookFactory(options) : null;
displayManualRestartTip();

const tsconfigPathsPlugin = options
? tsconfigPathsBeforeHookFactory(options)
: null;
const program = origCreateProgram(
rootNames,
options,
Expand Down Expand Up @@ -118,7 +126,18 @@ export class WatchCompiler {
return program as any;
};

tsBin.createWatchProgram(host);
const watchProgram = tsBin.createWatchProgram(host);

listenForManualRestart(() => {
watchProgram.close();
this.run(
configuration,
configFilename,
appName,
tsCompilerOptions,
onSuccess,
);
});
}

private createDiagnosticReporter(
Expand Down

0 comments on commit 4eeddcb

Please sign in to comment.