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

fix(gatsby): only enable debugger when argument is given #26669

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/gatsby-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ class ControllableScript {
this.debugInfo = debugInfo
}
start(): void {
const args = []
const tmpFileName = tmp.tmpNameSync({
tmpdir: path.join(process.cwd(), `.cache`),
})
fs.outputFileSync(tmpFileName, this.script)
this.isRunning = true
const args = [tmpFileName]
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
// 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, {
Expand Down