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

Add option to pass --inspect flag to enable server-side debugging #3294

Merged
merged 9 commits into from
Nov 20, 2017
15 changes: 11 additions & 4 deletions bin/next
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ const commands = new Set([
])

let cmd = process.argv[2]
let args
let args = []

if (new Set(['--version', '-v']).has(cmd)) {
console.log(`next.js v${pkg.version}`)
process.exit(0)
}

if (new Set(process.argv).has('--inspect')) {
args.push('--inspect')
process.argv = process.argv.filter(argument => argument !== '--inspect')
}

if (new Set(['--help', '-h']).has(cmd)) {
console.log(`
Usage
Expand All @@ -49,19 +54,21 @@ if (new Set(['--help', '-h']).has(cmd)) {
}

if (commands.has(cmd)) {
args = process.argv.slice(3)
args = args.concat(process.argv.slice(3))
} else {
cmd = defaultCommand
args = process.argv.slice(2)
args = args.concat(process.argv.slice(2))
}

const defaultEnv = cmd === 'dev' ? 'development' : 'production'
process.env.NODE_ENV = process.env.NODE_ENV || defaultEnv

const node = process.argv[0]
const bin = join(__dirname, 'next-' + cmd)
args.push(bin)

const startProcess = () => {
const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] })
const proc = spawn(node, args, { stdio: 'inherit', customFds: [0, 1, 2] })
Copy link
Member

@timneutkens timneutkens Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be bin? = const bin = join(__dirname, 'next-' + cmd) 🤔

Copy link
Contributor Author

@auchenberg auchenberg Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I've changed the scripts to be regular JavaScript files, that doesn't contain #!/usr/bin/env node as we need to launch Node with the --inspect flag and having the files as a shell script doesn't allow that.

So the change here is the that we spawn a child process like node --inspect <path to next-dev>

proc.on('close', (code, signal) => {
if (code !== null) {
process.exit(code)
Expand Down
1 change: 0 additions & 1 deletion bin/next-build
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to change this? While I have never seen anyone running next-build or next-dev commands (instead of next build / next dev, where next command gets executed), this seems to be a breaking change to me, and given the files locate in the bin folder, it makes sense to be able to execute them (so shebang is necessary).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change their, but I haven't found a way to pass the --inspect flag to #!/usr/bin/env node otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auchenberg having this shebang doesn't require you use them. Just leave shebang even if you are going to run them from next using explicit node --inspect next-build.

import { resolve, join } from 'path'
import { existsSync } from 'fs'
import parseArgs from 'minimist'
Expand Down
1 change: 0 additions & 1 deletion bin/next-dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
import 'source-map-support/register'
import { resolve, join } from 'path'
import parseArgs from 'minimist'
Expand Down
1 change: 0 additions & 1 deletion bin/next-export
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
import { resolve, join } from 'path'
import { existsSync } from 'fs'
import parseArgs from 'minimist'
Expand Down
1 change: 0 additions & 1 deletion bin/next-init
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
console.log('`next init` is not supported anymore. These community projects provide the same functionality as `next init` with additional features: http://npmjs.com/next-init and http://npmjs.com/create-next-app.')

process.exit(0)
2 changes: 0 additions & 2 deletions bin/next-start
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { resolve } from 'path'
import parseArgs from 'minimist'
import Server from '../server'
Expand Down