diff --git a/packages/gatsby-cli/src/create-cli.ts b/packages/gatsby-cli/src/create-cli.ts index 532bc83cd70f4..d27e8c6608790 100644 --- a/packages/gatsby-cli/src/create-cli.ts +++ b/packages/gatsby-cli/src/create-cli.ts @@ -175,17 +175,23 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void { .option(`inspect`, { type: `number`, describe: `Opens a port for debugging. See https://www.gatsbyjs.org/docs/debugging-the-build-process/`, - default: 9229, }) .option(`inspect-brk`, { type: `number`, describe: `Opens a port for debugging. Will block until debugger is attached. See https://www.gatsbyjs.org/docs/debugging-the-build-process/`, - default: 9229, }), handler: handlerP( getCommandHandler(`develop`, (args: yargs.Arguments, cmd: Function) => { process.env.NODE_ENV = process.env.NODE_ENV || `development` startGraphQLServer(siteInfo.directory, true) + + if (args.hasOwnProperty(`inspect`)) { + args.inspect = args.inspect || 9229 + } + if (args.hasOwnProperty(`inspect-brk`)) { + args.inspect = args.inspect || 9229 + } + cmd(args) // Return an empty promise to prevent handlerP from exiting early. // The development server shouldn't ever exit until the user directly diff --git a/packages/gatsby/src/commands/develop.ts b/packages/gatsby/src/commands/develop.ts index d9e99d8dce1e8..fe6af0d8e83c8 100644 --- a/packages/gatsby/src/commands/develop.ts +++ b/packages/gatsby/src/commands/develop.ts @@ -100,11 +100,11 @@ class ControllableScript { const args = [tmpFileName] // Passing --inspect isn't necessary for the child process to launch a port but it allows some editors to automatically attach if (this.debugInfo) { - args.push( - this.debugInfo.break - ? `--inspect-brk=${this.debugInfo.port}` - : `--inspect=${this.debugInfo.port}` - ) + if (this.debugInfo.break) { + args.push(`--inspect-brk=${this.debugInfo.port}`) + } else { + args.push(`--inspect=${this.debugInfo.port}`) + } } this.process = spawn(`node`, args, {