mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 21:04:34 +00:00
Merge pull request #436 from nsivertsen/devtools
Enable debugging in Chrome and VS Code - fixes #435
This commit is contained in:
@@ -36,6 +36,8 @@ class Watcher extends EventEmitter {
|
|||||||
live: boolean;
|
live: boolean;
|
||||||
hot: boolean;
|
hot: boolean;
|
||||||
|
|
||||||
|
devtools_port: number;
|
||||||
|
|
||||||
dev_server: DevServer;
|
dev_server: DevServer;
|
||||||
proc: child_process.ChildProcess;
|
proc: child_process.ChildProcess;
|
||||||
filewatchers: Array<{ close: () => void }>;
|
filewatchers: Array<{ close: () => void }>;
|
||||||
@@ -57,6 +59,7 @@ class Watcher extends EventEmitter {
|
|||||||
'dev-port': dev_port,
|
'dev-port': dev_port,
|
||||||
live,
|
live,
|
||||||
hot,
|
hot,
|
||||||
|
'devtools-port': devtools_port,
|
||||||
bundler,
|
bundler,
|
||||||
webpack = 'webpack',
|
webpack = 'webpack',
|
||||||
rollup = 'rollup',
|
rollup = 'rollup',
|
||||||
@@ -68,6 +71,7 @@ class Watcher extends EventEmitter {
|
|||||||
'dev-port': number,
|
'dev-port': number,
|
||||||
live: boolean,
|
live: boolean,
|
||||||
hot: boolean,
|
hot: boolean,
|
||||||
|
'devtools-port': number,
|
||||||
bundler?: string,
|
bundler?: string,
|
||||||
webpack: string,
|
webpack: string,
|
||||||
rollup: string,
|
rollup: string,
|
||||||
@@ -84,6 +88,8 @@ class Watcher extends EventEmitter {
|
|||||||
this.live = live;
|
this.live = live;
|
||||||
this.hot = hot;
|
this.hot = hot;
|
||||||
|
|
||||||
|
this.devtools_port = devtools_port;
|
||||||
|
|
||||||
this.filewatchers = [];
|
this.filewatchers = [];
|
||||||
|
|
||||||
this.current_build = {
|
this.current_build = {
|
||||||
@@ -129,6 +135,9 @@ class Watcher extends EventEmitter {
|
|||||||
|
|
||||||
if (!this.dev_port) this.dev_port = await ports.find(10000);
|
if (!this.dev_port) this.dev_port = await ports.find(10000);
|
||||||
|
|
||||||
|
// Chrome looks for debugging targets on ports 9222 and 9229 by default
|
||||||
|
if (!this.devtools_port) this.devtools_port = await ports.find(9222);
|
||||||
|
|
||||||
let manifest_data: ManifestData;
|
let manifest_data: ManifestData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -238,12 +247,21 @@ class Watcher extends EventEmitter {
|
|||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we need to give the child process its own DevTools port,
|
||||||
|
// otherwise Node will try to use the parent's (and fail)
|
||||||
|
const debugArgRegex = /--inspect(?:-brk|-port)?|--debug-port/;
|
||||||
|
const execArgv = process.execArgv.slice();
|
||||||
|
if (execArgv.some((arg: string) => !!arg.match(debugArgRegex))) {
|
||||||
|
execArgv.push(`--inspect-port=${this.devtools_port}`);
|
||||||
|
}
|
||||||
|
|
||||||
this.proc = child_process.fork(`${dest}/server.js`, [], {
|
this.proc = child_process.fork(`${dest}/server.js`, [], {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
env: Object.assign({
|
env: Object.assign({
|
||||||
PORT: this.port
|
PORT: this.port
|
||||||
}, process.env),
|
}, process.env),
|
||||||
stdio: ['ipc']
|
stdio: ['ipc'],
|
||||||
|
execArgv
|
||||||
});
|
});
|
||||||
|
|
||||||
this.proc.stdout.on('data', chunk => {
|
this.proc.stdout.on('data', chunk => {
|
||||||
|
|||||||
Reference in New Issue
Block a user