diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c87ce9455071a..dbb0fa7766345 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -296,9 +296,9 @@ "resolved": "https://registry.npmjs.org/native-keymap/-/native-keymap-1.2.5.tgz" }, "native-watchdog": { - "version": "0.2.0", - "from": "native-watchdog@0.2.0", - "resolved": "https://registry.npmjs.org/native-watchdog/-/native-watchdog-0.2.0.tgz" + "version": "0.3.0", + "from": "native-watchdog@0.3.0", + "resolved": "https://registry.npmjs.org/native-watchdog/-/native-watchdog-0.3.0.tgz" }, "node-pty": { "version": "0.7.0", diff --git a/package.json b/package.json index c6bf393632168..aaf934266b077 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "keytar": "^4.0.3", "minimist": "1.2.0", "native-keymap": "1.2.5", - "native-watchdog": "0.2.0", + "native-watchdog": "0.3.0", "node-pty": "0.7.0", "nsfw": "1.0.16", "semver": "4.3.6", diff --git a/src/typings/native-watchdog.d.ts b/src/typings/native-watchdog.d.ts index 5ab15e00fbf9c..e7342da904733 100644 --- a/src/typings/native-watchdog.d.ts +++ b/src/typings/native-watchdog.d.ts @@ -7,4 +7,6 @@ declare module 'native-watchdog' { export function start(timeout: number): void; + export function exit(exitCode: number): void; + } diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index 5ee81a16bf3b3..8a55e8bb280be 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -17,15 +17,33 @@ import { QueryType, ISearchQuery } from 'vs/platform/search/common/search'; import { DiskSearch } from 'vs/workbench/services/search/node/searchService'; import { IInitData, IEnvironment, IWorkspaceData, MainContext } from 'vs/workbench/api/node/extHost.protocol'; import * as errors from 'vs/base/common/errors'; -// import * as watchdog from 'native-watchdog'; +import * as watchdog from 'native-watchdog'; -const nativeExit = process.exit.bind(process); +// const nativeExit = process.exit.bind(process); process.exit = function () { const err = new Error('An extension called process.exit() and this was prevented.'); console.warn(err.stack); }; export function exit(code?: number) { - nativeExit(code); + //nativeExit(code); + + // TODO@electron + // See https://github.com/Microsoft/vscode/issues/32990 + // calling process.exit() does not exit the process when the process is being debugged + // It waits for the debugger to disconnect, but in our version, the debugger does not + // receive an event that the process desires to exit such that it can disconnect. + + // Do exactly what node.js would have done, minus the wait for the debugger part + + if (code || code === 0) { + process.exitCode = code; + } + + if (!(process)._exiting) { + (process)._exiting = true; + process.emit('exit', process.exitCode || 0); + } + watchdog.exit(process.exitCode || 0); } interface ITestRunner {