mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
Enable debugging in Chrome and VS Code - fixes 435
This commit is contained in:
@@ -36,6 +36,8 @@ class Watcher extends EventEmitter {
|
||||
live: boolean;
|
||||
hot: boolean;
|
||||
|
||||
devtools_port: number;
|
||||
|
||||
dev_server: DevServer;
|
||||
proc: child_process.ChildProcess;
|
||||
filewatchers: Array<{ close: () => void }>;
|
||||
@@ -57,6 +59,7 @@ class Watcher extends EventEmitter {
|
||||
'dev-port': dev_port,
|
||||
live,
|
||||
hot,
|
||||
'devtools-port': devtools_port,
|
||||
bundler,
|
||||
webpack = 'webpack',
|
||||
rollup = 'rollup',
|
||||
@@ -68,6 +71,7 @@ class Watcher extends EventEmitter {
|
||||
'dev-port': number,
|
||||
live: boolean,
|
||||
hot: boolean,
|
||||
'devtools-port': number,
|
||||
bundler?: string,
|
||||
webpack: string,
|
||||
rollup: string,
|
||||
@@ -84,6 +88,8 @@ class Watcher extends EventEmitter {
|
||||
this.live = live;
|
||||
this.hot = hot;
|
||||
|
||||
this.devtools_port = devtools_port;
|
||||
|
||||
this.filewatchers = [];
|
||||
|
||||
this.current_build = {
|
||||
@@ -129,6 +135,9 @@ class Watcher extends EventEmitter {
|
||||
|
||||
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;
|
||||
|
||||
try {
|
||||
@@ -238,12 +247,21 @@ class Watcher extends EventEmitter {
|
||||
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`, [], {
|
||||
cwd: process.cwd(),
|
||||
env: Object.assign({
|
||||
PORT: this.port
|
||||
}, process.env),
|
||||
stdio: ['ipc']
|
||||
stdio: ['ipc'],
|
||||
execArgv
|
||||
});
|
||||
|
||||
this.proc.stdout.on('data', chunk => {
|
||||
|
||||
Reference in New Issue
Block a user