diff --git a/packages/service-provider-server/package.json b/packages/service-provider-server/package.json index 306a2273a..9ca327db9 100644 --- a/packages/service-provider-server/package.json +++ b/packages/service-provider-server/package.json @@ -12,6 +12,7 @@ "url": "git://github.com/mongodb-js/mongosh.git" }, "scripts": { + "precompile": "rm -rf lib/", "compile": "tsc -p tsconfig.json && webpack --mode production && node scripts/wrap-pack.js", "test": "cross-env TS_NODE_PROJECT=../../configs/tsconfig-mongosh/tsconfig.test.json mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"", "test-ci": "node ../../scripts/run-if-package-requested.js npm test", diff --git a/packages/service-provider-server/src/cli-service-provider.ts b/packages/service-provider-server/src/cli-service-provider.ts index 72aea4529..3fbc69a1e 100644 --- a/packages/service-provider-server/src/cli-service-provider.ts +++ b/packages/service-provider-server/src/cli-service-provider.ts @@ -231,9 +231,17 @@ export class SynchronousCliServiceProvider this.remotePort = channel.port2; this.bus = bus; + let source: string; + try { + source = require('./wrapped.js'); + } catch (err: any) { + throw new Error( + `Could not get Worker thread source code: ${err.message}` + ); + } this.worker = new Worker( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `${require('./wrapped.js')}; SynchronousCliServiceProvider.runWorker();`, + `${source}; SynchronousCliServiceProvider.runWorker();`, { eval: true, workerData: { flag: this.flag } } ); const origEmit: any = this.bus.emit;