1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.createIpcEnv = exports.checkParentAlive = exports.IPCEntryPoint = exports.ipcEntryPoint = void 0;
|
19 | const THEIA_PARENT_PID = 'THEIA_PARENT_PID';
|
20 | const THEIA_ENTRY_POINT = 'THEIA_ENTRY_POINT';
|
21 | exports.ipcEntryPoint = process.env[THEIA_ENTRY_POINT];
|
22 | var IPCEntryPoint;
|
23 | (function (IPCEntryPoint) {
|
24 | |
25 |
|
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 |
|
37 |
|
38 |
|
39 | function 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 |
|
46 | process.kill(parentPid, 0);
|
47 | }
|
48 | catch (_a) {
|
49 | process.exit();
|
50 | }
|
51 | }, 5000);
|
52 | }
|
53 | }
|
54 | }
|
55 | exports.checkParentAlive = checkParentAlive;
|
56 | function 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 | }
|
68 | exports.createIpcEnv = createIpcEnv;
|
69 |
|
\ | No newline at end of file |