Skip to content
Permalink
Browse files

Add settings for VS Code debugger

  • Loading branch information...
koistya committed Jul 15, 2017
1 parent fc4bd20 commit b3e996db83033e2a449e69185b82c490c06909bc
Showing with 59 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +34 −0 .vscode/launch.json
  3. +3 −4 README.md
  4. +3 −2 docker-compose.yml
  5. +18 −9 tools/run.js
@@ -10,4 +10,5 @@ docker-compose.override.yml
# Editors and IDEs
.vscode/*
!.vscode/snippets
!.vscode/launch.json
!.vscode/settings.json
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run",
"type": "node",
"request": "attach",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app"
},
{
"name": "Server",
"type": "node",
"request": "attach",
"port": 9230,
"protocol": "inspector",
"sourceMaps": true,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app",
"restart": true
}
  ],
"compounds": [
{
"name": "Run/Server",
"configurations": ["Run", "Server"]
}
]
}
@@ -118,10 +118,9 @@ yarn docker-test-watch # Run unit tests in watch mode inside a Docker c
## Debugging

In order to run the app with [V8 inspector][v8debug] enabled, simply replace `node tools/run.js`
with `node --inspect tools/run.js` in either [`docker-compose.yml`](docker-compose.yml) file, or
even better in `docker-compose.override.yml`. Then restart the app (`docker-compose up`) and
[attach your debugger][vsdebug] to `127.0.0.1:9230` (see [`.vscode/launch.json`](https://gist.github.com/koistya/421ea3e0139225b27f909e98202a34de)
for [VS Code][code] as an example).
with `node --inspect=0.0.0.0:9229 tools/run.js` in either [`docker-compose.yml`](docker-compose.yml)
file or, even better, in `docker-compose.override.yml`. Then restart the app (`docker-compose up`) and
[attach your debugger][vsdebug] to `127.0.0.1:9230` (see [`.vscode/launch.json`](./vscode/launch.json)).


## Keeping Up-to-Date
@@ -41,13 +41,14 @@ services:
expose:
- "8080"
ports:
- "127.0.0.1:9229:9229" # V8 inspector (when NODE_DEBUG=true)
- "127.0.0.1:9229:9229" # V8 inspector for tools/run.js
- "127.0.0.1:9230:9230" # V8 inspector for src/serer.js
volumes:
- yarn:/root/.cache/yarn
- ./:/usr/src/app
user: node
working_dir: /usr/src/app
command: node tools/run.js
command: node tools/run.js # or, `node --inspect=0.0.0.0:9229 tools/run.js`

# SQL and document data store
db:
@@ -16,9 +16,10 @@ const task = require('./task');

let build;
let server;
let debugPort = '9230';

const serverQueue = [];
const isDebug = process.execArgv.includes('--inspect');
const isDebug = process.execArgv.some(x => x.startsWith('--inspect'));

// Gracefull shutdown
process.once('cleanup', () => {
@@ -62,11 +63,14 @@ function spawnServer() {
...Object.keys(pkg.dependencies).reduce((requires, val) => requires.concat(['--require', val]), []),
// If the parent Node.js process is running in debug (inspect) mode,
// launch a debugger for Express.js app on the next port
...process.execArgv,
...process.execArgv.reduce((result, arg) => {
const match = arg.match(/^--(?:inspect|debug)-port=(\S+:|)(\d+)$/);
return match ? [`--inspect-port=${match[1]}${Number(match[2]) + 1}`] : result;
}, isDebug ? ['--inspect-port=9230'] : []),
...process.execArgv.map((arg) => {
if (arg.startsWith('--inspect')) {
const match = arg.match(/^--inspect=(\S+:|)(\d+)$/);
if (match) debugPort = Number(match[2]) + 1;
return `--inspect=${match ? match[1] : '0.0.0.0:'}${debugPort}`;
}
return arg;
}),
'--no-lazy',
// Enable "hot reload", it only works when debugger is off
...(isDebug ? ['./server.js'] : [
@@ -86,13 +90,18 @@ module.exports = task('run', () => Promise.resolve()
.then(() => build({
watch: true,
onComplete() {
if (server) server.kill('SIGTERM');
if (isDebug) {
server = spawnServer();
if (server) {
server.on('exit', () => { server = spawnServer(); });
server.kill('SIGTERM');
} else {
server = spawnServer();
}
} else {
if (server) server.kill('SIGTERM');
server = serverQueue.splice(0, 1)[0] || spawnServer();
server.stdin.write('load'); // this works faster than IPC
while (serverQueue.length < 3) serverQueue.push(spawnServer());
if (server) while (serverQueue.length < 3) serverQueue.push(spawnServer());
}
},
}))

0 comments on commit b3e996d

Please sign in to comment.
You can’t perform that action at this time.