UNPKG

2.77 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.createIpcEnv = exports.checkParentAlive = exports.IPCEntryPoint = exports.ipcEntryPoint = void 0;
19const THEIA_PARENT_PID = 'THEIA_PARENT_PID';
20const THEIA_ENTRY_POINT = 'THEIA_ENTRY_POINT';
21exports.ipcEntryPoint = process.env[THEIA_ENTRY_POINT];
22var IPCEntryPoint;
23(function (IPCEntryPoint) {
24 /**
25 * Throws if `THEIA_ENTRY_POINT` is undefined or empty.
26 */
27 function getScriptFromEnv() {
28 if (!exports.ipcEntryPoint) {
29 throw new Error(`"${THEIA_ENTRY_POINT}" is missing from the environment`);
30 }
31 return exports.ipcEntryPoint;
32 }
33 IPCEntryPoint.getScriptFromEnv = getScriptFromEnv;
34})(IPCEntryPoint = exports.IPCEntryPoint || (exports.IPCEntryPoint = {}));
35/**
36 * Exit the current process if the parent process is not alive.
37 * Relevant only for some OS, like Windows
38 */
39function checkParentAlive() {
40 if (process.env[THEIA_PARENT_PID]) {
41 const parentPid = Number(process.env[THEIA_PARENT_PID]);
42 if (typeof parentPid === 'number' && !isNaN(parentPid)) {
43 setInterval(() => {
44 try {
45 // throws an exception if the main process doesn't exist anymore.
46 process.kill(parentPid, 0);
47 }
48 catch (_a) {
49 process.exit();
50 }
51 }, 5000);
52 }
53 }
54}
55exports.checkParentAlive = checkParentAlive;
56function createIpcEnv(options) {
57 const op = Object.assign({}, options);
58 const childEnv = Object.assign({}, op.env);
59 for (const key of Object.keys(childEnv)) {
60 if (key.startsWith('THEIA_')) {
61 delete childEnv[key];
62 }
63 }
64 childEnv[THEIA_PARENT_PID] = String(process.pid);
65 childEnv[THEIA_ENTRY_POINT] = op.entryPoint;
66 return childEnv;
67}
68exports.createIpcEnv = createIpcEnv;
69//# sourceMappingURL=ipc-protocol.js.map
\No newline at end of file