Skip to content

Commit

Permalink
fix(debugger): use a regex to remove bad NODE_OPTIONS flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson authored and vvo committed Mar 19, 2020
1 parent 81bbfe0 commit 86ccdc5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/next/server/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export function printAndExit(message: string, code = 1) {

process.exit(code)
}

export function getNodeOptionsWithoutInspect() {
const NODE_INSPECT_RE = /--inspect(-brk)?(=\S+)? ?/
return (process.env.NODE_OPTIONS || '').replace(NODE_INSPECT_RE, '')
}
1 change: 1 addition & 0 deletions packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ErrorDebug from './error-debug'
import HotReloader from './hot-reloader'
import { findPageFile } from './lib/find-page-file'
import Worker from 'jest-worker'
import { getNodeOptionsWithoutInspect } from './lib/utils'

if (typeof React.Suspense === 'undefined') {
throw new Error(
Expand Down
10 changes: 10 additions & 0 deletions test/integration/cli/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ describe('CLI Usage', () => {
expect(output).toMatch(new RegExp(`http://localhost:${port}`))
})

test("NODE_OPTIONS='--inspect'", async () => {
// this test checks that --inspect works by launching a single debugger for the main Next.js process,
// not for its subprocesses
const port = await findPort()
const output = await runNextCommandDev([dir, '--port', port], true, {
env: { NODE_OPTIONS: '--inspect' },
})
expect(output).toMatch(new RegExp(`http://localhost:${port}`))
})

test('-p', async () => {
const port = await findPort()
const output = await runNextCommandDev([dir, '-p', port], true)
Expand Down

0 comments on commit 86ccdc5

Please sign in to comment.