@mongosh/node-runtime-worker-thread 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongosh/node-runtime-worker-thread",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "MongoDB shell runtime that lives in a worker thread",
5
5
  "homepage": "https://github.com/mongodb-js/mongosh",
6
6
  "license": "Apache-2.0",
@@ -28,22 +28,18 @@
28
28
  "prepublish": "npm run webpack-build"
29
29
  },
30
30
  "devDependencies": {
31
- "@mongosh/browser-runtime-core": "1.6.0",
32
- "@mongosh/browser-runtime-electron": "1.6.0",
33
- "@mongosh/service-provider-core": "1.6.0",
34
- "@mongosh/service-provider-server": "1.6.0",
35
- "@mongosh/types": "1.6.0",
36
- "bson": "^4.7.0",
31
+ "@mongosh/browser-runtime-core": "1.6.2",
32
+ "@mongosh/browser-runtime-electron": "1.6.2",
33
+ "@mongosh/service-provider-core": "1.6.2",
34
+ "@mongosh/service-provider-server": "1.6.2",
35
+ "@mongosh/types": "1.6.2",
36
+ "bson": "^4.7.1",
37
37
  "mocha": "^7.1.2",
38
- "postmsg-rpc": "^2.4.0",
39
- "terser-webpack-plugin": "^4.2.3",
40
- "ts-loader": "^8.0.14",
41
- "webpack": "^4.44.2",
42
- "webpack-cli": "^4.3.1"
38
+ "postmsg-rpc": "^2.4.0"
43
39
  },
44
40
  "dependencies": {
45
41
  "interruptor": "^1.0.1",
46
42
  "system-ca": "^1.0.2"
47
43
  },
48
- "gitHead": "fbbf54a08fb315ae5fde693a98d439b9aa3285f8"
44
+ "gitHead": "a825d141aa5f25d90d915c9048e9c5277027ae9e"
49
45
  }
@@ -1,8 +1,10 @@
1
1
  import path from 'path';
2
- import { ChildProcess, fork } from 'child_process';
2
+ import { ChildProcess, fork, spawn } from 'child_process';
3
3
  import { Caller, cancel, createCaller } from './rpc';
4
4
  import { expect } from 'chai';
5
5
  import { WorkerRuntime } from './worker-runtime';
6
+ import { once } from 'events';
7
+ import { promisify } from 'util';
6
8
 
7
9
  const childProcessModulePath = path.resolve(
8
10
  __dirname,
@@ -22,7 +24,7 @@ describe('child process worker proxy', () => {
22
24
  }
23
25
 
24
26
  if (childProcess) {
25
- childProcess.kill('SIGTERM');
27
+ childProcess.disconnect();
26
28
  childProcess = null;
27
29
  }
28
30
  });
@@ -34,4 +36,38 @@ describe('child process worker proxy', () => {
34
36
  const result = await caller.evaluate('1 + 1');
35
37
  expect(result.printable).to.equal(2);
36
38
  });
39
+
40
+ it('should exit on its own when the parent process disconnects', async() => {
41
+ const intermediateProcess = spawn(process.execPath,
42
+ ['-e', `require("child_process")
43
+ .fork(${JSON.stringify(childProcessModulePath)})
44
+ .on("message", function(m) { console.log("message " + m + " from " + this.pid) })`],
45
+ { stdio: ['pipe', 'pipe', 'inherit'] });
46
+
47
+ // Make sure the outer child process runs and has created the inner child process
48
+ const [message] = await once(intermediateProcess.stdout.setEncoding('utf8'), 'data');
49
+ const match = message.trim().match(/^message ready from (?<pid>\d+)$/);
50
+ expect(match).to.not.equal(null);
51
+
52
+ // Make sure the inner child process runs
53
+ const childPid = +match.groups.pid;
54
+ process.kill(childPid, 0);
55
+
56
+ // Kill the intermediate process and wait for the inner child process to also close
57
+ intermediateProcess.kill('SIGTERM');
58
+ let innerChildHasStoppedRunning = false;
59
+ for (let i = 0; i < 200; i++) {
60
+ try {
61
+ process.kill(childPid, 0);
62
+ } catch (err) {
63
+ if (err.code === 'ESRCH') {
64
+ innerChildHasStoppedRunning = true;
65
+ break;
66
+ }
67
+ throw err;
68
+ }
69
+ await promisify(setTimeout)(10);
70
+ }
71
+ expect(innerChildHasStoppedRunning).to.equal(true);
72
+ });
37
73
  });
@@ -114,6 +114,7 @@ const messageBus = createCaller(['emit', 'on'], process);
114
114
 
115
115
  exposeAll(messageBus, workerProcess);
116
116
 
117
+ process.once('disconnect', () => process.exit());
117
118
  process.nextTick(() => {
118
119
  // eslint-disable-next-line chai-friendly/no-unused-expressions
119
120
  process.send?.('ready');
package/webpack.config.js CHANGED
@@ -1,43 +1,17 @@
1
+ 'use strict';
2
+ const { merge } = require('webpack-merge');
1
3
  const path = require('path');
2
- const TerserPlugin = require('terser-webpack-plugin');
4
+
5
+ const baseWebpackConfig = require('../../config/webpack.base.config');
3
6
 
4
7
  /** @type import('webpack').Configuration */
5
8
  const config = {
6
- target: 'node',
7
-
8
9
  output: {
9
10
  path: path.resolve(__dirname, 'dist'),
10
11
  filename: '[name].js',
11
12
  libraryTarget: 'umd'
12
13
  },
13
14
 
14
- module: {
15
- rules: [
16
- {
17
- test: /\.ts$/,
18
- use: [{ loader: 'ts-loader' }],
19
- exclude: [/node_modules/]
20
- }
21
- ]
22
- },
23
-
24
- resolve: {
25
- extensions: ['.ts', '.js']
26
- },
27
-
28
- optimization: {
29
- minimizer: [
30
- new TerserPlugin({
31
- terserOptions: {
32
- // Not keeping classnames breaks shell-api during minification
33
- keep_classnames: true
34
- }
35
- })
36
- ]
37
- },
38
-
39
- node: false,
40
-
41
15
  externals: {
42
16
  'mongodb-client-encryption': 'commonjs2 mongodb-client-encryption',
43
17
  kerberos: 'commonjs2 kerberos',
@@ -51,6 +25,6 @@ const config = {
51
25
  module.exports = ['index', 'child-process-proxy', 'worker-runtime'].map(
52
26
  (entry) => ({
53
27
  entry: { [entry]: path.resolve(__dirname, 'src', `${entry}.ts`) },
54
- ...config
28
+ ...merge(baseWebpackConfig, config)
55
29
  })
56
30
  );
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- import { ChildProcess } from 'child_process';
3
- import { Exposed } from './rpc';
4
- import type { WorkerRuntime } from './index';
5
- import { RuntimeEvaluationListener } from '@mongosh/browser-runtime-core';
6
- export declare class ChildProcessEvaluationListener {
7
- exposedListener: Exposed<Required<Omit<RuntimeEvaluationListener, 'onLoad' | 'getCryptLibraryOptions'>>>;
8
- constructor(workerRuntime: WorkerRuntime, childProcess: ChildProcess);
9
- terminate(): void;
10
- }
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- import { ChildProcess } from 'child_process';
3
- import { MongoshBus } from '@mongosh/types';
4
- import { Exposed } from './rpc';
5
- export declare class ChildProcessMongoshBus {
6
- exposedEmitter: Exposed<MongoshBus>;
7
- constructor(eventEmitter: MongoshBus, childProcess: ChildProcess);
8
- terminate(): void;
9
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- /// <reference types="node" />
2
- import { SpawnOptionsWithoutStdio } from 'child_process';
3
- import { Runtime, RuntimeEvaluationListener, RuntimeEvaluationResult } from '@mongosh/browser-runtime-core';
4
- import type { MongoshBus } from '@mongosh/types';
5
- import type { CompassServiceProvider } from '@mongosh/service-provider-server';
6
- declare type DevtoolsConnectOptions = Parameters<(typeof CompassServiceProvider)['connect']>[1];
7
- declare class WorkerRuntime implements Runtime {
8
- private initOptions;
9
- evaluationListener: RuntimeEvaluationListener | null;
10
- private eventEmitter;
11
- private childProcessMongoshBus;
12
- private childProcessEvaluationListener;
13
- private childProcess;
14
- private childProcessRuntime;
15
- private initWorkerPromise;
16
- private childProcessProxySrcPath;
17
- constructor(uri: string, driverOptions?: DevtoolsConnectOptions, cliOptions?: {
18
- nodb?: boolean;
19
- }, spawnOptions?: SpawnOptionsWithoutStdio, eventEmitter?: MongoshBus);
20
- private initWorker;
21
- evaluate(code: string): Promise<RuntimeEvaluationResult>;
22
- getCompletions(code: string): Promise<import("@mongosh/browser-runtime-core").Completion[]>;
23
- getShellPrompt(): Promise<string>;
24
- setEvaluationListener(listener: RuntimeEvaluationListener | null): RuntimeEvaluationListener | null;
25
- terminate(): Promise<void>;
26
- interrupt(): Promise<boolean>;
27
- waitForRuntimeToBeReady(): Promise<void>;
28
- }
29
- export { WorkerRuntime };
@@ -1,10 +0,0 @@
1
- export declare type UNLOCKED = 'UNLOCKED';
2
- export declare class Lock {
3
- private static UNLOCK_TOKEN;
4
- private promise;
5
- private resolve;
6
- lock(): Promise<UNLOCKED>;
7
- unlock(): boolean;
8
- isLocked(): boolean;
9
- isUnlockToken(resolvedValue: any): resolvedValue is UNLOCKED;
10
- }
package/dist/src/rpc.d.ts DELETED
@@ -1,28 +0,0 @@
1
- export declare function serialize(data: unknown): string;
2
- export declare function deserialize<T = unknown>(str: string): T | string;
3
- declare type RPCMessageBus = {
4
- on: Function;
5
- off: Function;
6
- } & ({
7
- postMessage: Function;
8
- send?: never;
9
- } | {
10
- postMessage?: never;
11
- send?: Function;
12
- });
13
- export declare function removeTrailingUndefined(arr: unknown[]): unknown[];
14
- export declare const close: unique symbol;
15
- export declare const cancel: unique symbol;
16
- export declare type Exposed<T> = {
17
- [k in keyof T]: T[k] & {
18
- close(): void;
19
- };
20
- } & {
21
- [close]: () => void;
22
- };
23
- export declare function exposeAll<O>(obj: O, messageBus: RPCMessageBus): Exposed<O>;
24
- export declare type Caller<Impl, Keys extends keyof Impl = keyof Impl> = CancelableMethods<Pick<Impl, Keys>> & {
25
- [cancel]: () => void;
26
- };
27
- export declare function createCaller<Impl extends {}>(methodNames: Extract<keyof Impl, string>[], messageBus: RPCMessageBus, processors?: Partial<Record<typeof methodNames[number], (...input: any[]) => any[]>>): Caller<Impl, typeof methodNames[number]>;
28
- export {};
@@ -1,13 +0,0 @@
1
- import { RuntimeEvaluationResult } from '@mongosh/browser-runtime-core';
2
- import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
3
- export declare function serializeError(err: Error): Error;
4
- export declare function deserializeError(err: any): Error;
5
- export declare enum SerializedResultTypes {
6
- SerializedErrorResult = "SerializedErrorResult",
7
- InspectResult = "InspectResult",
8
- SerializedShellApiResult = "SerializedShellApiResult"
9
- }
10
- export declare function serializeEvaluationResult({ type, printable, source }: RuntimeEvaluationResult): RuntimeEvaluationResult;
11
- export declare function deserializeEvaluationResult({ type, printable, source }: RuntimeEvaluationResult): RuntimeEvaluationResult;
12
- export declare function serializeConnectOptions(options?: Readonly<DevtoolsConnectOptions>): DevtoolsConnectOptions;
13
- export declare function deserializeConnectOptions(options: Readonly<DevtoolsConnectOptions>): DevtoolsConnectOptions;
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- import { ChildProcess, SpawnOptions, StdioNull, StdioPipe } from 'child_process';
3
- export declare function kill(childProcess: ChildProcess, code?: NodeJS.Signals | number): Promise<void>;
4
- export default function spawnChildFromSource(src: string, spawnOptions?: Omit<SpawnOptions, 'stdio'>, timeoutMs?: number, _stdout?: StdioNull | StdioPipe, _stderr?: StdioNull | StdioPipe): Promise<ChildProcess>;
@@ -1,14 +0,0 @@
1
- import { Runtime, RuntimeEvaluationListener } from '@mongosh/browser-runtime-core';
2
- import { CompassServiceProvider } from '@mongosh/service-provider-server';
3
- import { InterruptHandle } from 'interruptor';
4
- declare type DevtoolsConnectOptions = Parameters<(typeof CompassServiceProvider)['connect']>[1];
5
- export declare type WorkerRuntimeEvaluationListener = RuntimeEvaluationListener & {
6
- onRunInterruptible(handle: InterruptHandle | null): void;
7
- };
8
- export declare type WorkerRuntime = Runtime & {
9
- init(uri: string, driverOptions?: DevtoolsConnectOptions, cliOptions?: {
10
- nodb?: boolean;
11
- }): Promise<void>;
12
- interrupt(): boolean;
13
- };
14
- export {};