diff --git a/actions/start.action.ts b/actions/start.action.ts index 9e649c833..36958bdf7 100644 --- a/actions/start.action.ts +++ b/actions/start.action.ts @@ -6,8 +6,10 @@ import * as killProcess from 'tree-kill'; import { treeKillSync as killProcessSync } from '../lib/utils/tree-kill'; import { Input } from '../commands'; import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default'; -import { Configuration } from '../lib/configuration'; -import { defaultOutDir } from '../lib/configuration/defaults'; +import { + defaultConfiguration, + defaultOutDir, +} from '../lib/configuration/defaults'; import { ERROR_PREFIX } from '../lib/ui'; import { BuildAction } from './build.action'; @@ -47,9 +49,31 @@ export class StartAction extends BuildAction { const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig); const outDir = tsOptions.outDir || defaultOutDir; + const entryFile = + (options.find((option) => option.name === 'entryFile') + ?.value as string) || + getValueOrDefault( + configuration, + 'entryFile', + appName, + undefined, + undefined, + defaultConfiguration.entryFile, + ); + const sourceRoot = + (options.find((option) => option.name === 'sourceRoot') + ?.value as string) || + getValueOrDefault( + configuration, + 'sourceRoot', + appName, + undefined, + undefined, + defaultConfiguration.sourceRoot, + ); const onSuccess = this.createOnSuccessHook( - configuration, - appName, + entryFile, + sourceRoot, debugFlag, outDir, binaryToRun, @@ -73,15 +97,12 @@ export class StartAction extends BuildAction { } public createOnSuccessHook( - configuration: Required, - appName: string, + entryFile: string, + sourceRoot: string, debugFlag: boolean | string | undefined, outDirName: string, binaryToRun = 'node', ) { - const sourceRoot = getValueOrDefault(configuration, 'sourceRoot', appName); - const entryFile = getValueOrDefault(configuration, 'entryFile', appName); - let childProcessRef: any; process.on( 'exit', diff --git a/commands/start.command.ts b/commands/start.command.ts index c77ae0b28..d171b8f71 100644 --- a/commands/start.command.ts +++ b/commands/start.command.ts @@ -17,6 +17,14 @@ export class StartCommand extends AbstractCommand { .option('--webpack', 'Use webpack for compilation.') .option('--webpackPath [path]', 'Path to webpack configuration.') .option('--tsc', 'Use tsc for compilation.') + .option( + '--sourceRoot [sourceRoot]', + 'Points at the root of the source code for the single project in standard mode structures, or the default project in monorepo mode structures.', + ) + .option( + '--entryFile [entryFile]', + "Path to the entry file where this command will work with. Defaults to the one defined at your Nest's CLI config file.", + ) .option('-e, --exec [binary]', 'Binary to run (default: "node").') .option( '--preserveWatchOutput', @@ -48,6 +56,14 @@ export class StartCommand extends AbstractCommand { name: 'exec', value: command.exec, }); + options.push({ + name: 'sourceRoot', + value: command.sourceRoot, + }); + options.push({ + name: 'entryFile', + value: command.entryFile, + }); options.push({ name: 'preserveWatchOutput', value: