Skip to content

Commit e16b48e

Browse files
author
Kartik Raj
committed
Add fixes
1 parent 7580f32 commit e16b48e

11 files changed

+59
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ log.log
55
**/node_modules
66
*.pyc
77
*.vsix
8+
envVars.txt
89
**/.vscode/.ropeproject/**
910
**/testFiles/**/.cache/**
1011
*.noseids

build/webpack/webpack.extension.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const config = {
1919
target: 'node',
2020
entry: {
2121
extension: './src/client/extension.ts',
22+
'shellExec.worker': './src/client/common/process/worker/shellExec.worker.ts',
23+
'plainExec.worker': './src/client/common/process/worker/plainExec.worker.ts',
24+
'registryKeys.worker': 'src/client/pythonEnvironments/common/registryKeys.worker.ts',
25+
'registryValues.worker': 'src/client/pythonEnvironments/common/registryValues.worker.ts',
2226
},
2327
devtool: 'source-map',
2428
node: {
@@ -51,6 +55,10 @@ const config = {
5155
},
5256
],
5357
},
58+
{
59+
test: /\.worker\.js$/,
60+
use: { loader: 'worker-loader' },
61+
},
5462
],
5563
},
5664
externals: [

package-lock.json

Lines changed: 31 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@
16591659
"typescript": "4.5.5",
16601660
"uuid": "^8.3.2",
16611661
"webpack": "^5.76.0",
1662+
"worker-loader": "^3.0.8",
16621663
"webpack-bundle-analyzer": "^4.5.0",
16631664
"webpack-cli": "^4.9.2",
16641665
"webpack-fix-default-import-plugin": "^1.0.3",

src/client/common/process/worker/main.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22
// Licensed under the MIT License.
33

44
import { Worker } from 'worker_threads';
5-
import { traceError } from '../../../logging';
5+
import { traceVerbose, traceError } from '../../../logging/index';
66

7+
/**
8+
* Executes a worker file. Make sure to declare the worker file as a entry in the webpack config.
9+
* @param workerFileName Filename of the worker file to execute, it has to end with ".worker.js" for webpack to bundle it.
10+
* @param workerData Arguments to the worker file.
11+
* @returns
12+
*/
713
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
814
export async function executeWorkerFile(workerFileName: string, workerData: any): Promise<any> {
15+
if (!workerFileName.endsWith('.worker.js')) {
16+
throw new Error('Worker file must end with ".worker.js" for webpack to bundle webworkers');
17+
}
918
return new Promise((resolve, reject) => {
19+
traceVerbose(`Starting worker ${workerFileName} with data ${JSON.stringify(workerData)}`);
1020
const worker = new Worker(workerFileName, { workerData });
21+
traceVerbose(`Started worker ${workerFileName}`);
1122
worker.on('message', (msg: { err: Error; res: unknown }) => {
23+
traceVerbose(`Worker ${workerFileName} sent message ${JSON.stringify(msg)}`);
1224
if (msg.err) {
1325
reject(msg.err);
1426
}
@@ -19,6 +31,7 @@ export async function executeWorkerFile(workerFileName: string, workerData: any)
1931
reject(ex);
2032
});
2133
worker.on('exit', (code) => {
34+
traceVerbose(`Worker ${workerFileName} exited with code ${code}`);
2235
if (code !== 0) {
2336
reject(new Error(`Worker ${workerFileName} stopped with exit code ${code}`));
2437
}

src/client/common/process/worker/rawProcessApiWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { executeWorkerFile } from './main';
77
import { ExecutionResult, ShellOptions } from './types';
88

99
export function workerShellExec(command: string, options: ShellOptions): Promise<ExecutionResult<string>> {
10-
return executeWorkerFile(path.join(__dirname, 'shellExecWorker.js'), {
10+
return executeWorkerFile(path.join(__dirname, 'shellExec.worker.js'), {
1111
command,
1212
options,
1313
});
@@ -18,7 +18,7 @@ export function workerPlainExec(
1818
args: string[],
1919
options: SpawnOptions = {},
2020
): Promise<ExecutionResult<string>> {
21-
return executeWorkerFile(path.join(__dirname, 'plainExecWorker.js'), {
21+
return executeWorkerFile(path.join(__dirname, 'plainExec.worker.js'), {
2222
file,
2323
args,
2424
options,

src/client/pythonEnvironments/common/windowsRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function readRegistryValues(options: Options, useWorkerThreads: boo
3939
});
4040
return deferred.promise;
4141
}
42-
return executeWorkerFile(path.join(__dirname, 'registryValuesWorker.js'), options);
42+
return executeWorkerFile(path.join(__dirname, 'registryValues.worker.js'), options);
4343
}
4444

4545
export async function readRegistryKeys(options: Options, useWorkerThreads: boolean): Promise<IRegistryKey[]> {
@@ -56,5 +56,5 @@ export async function readRegistryKeys(options: Options, useWorkerThreads: boole
5656
});
5757
return deferred.promise;
5858
}
59-
return executeWorkerFile(path.join(__dirname, 'registryKeysWorker.js'), options);
59+
return executeWorkerFile(path.join(__dirname, 'registryKeys.worker.js'), options);
6060
}

0 commit comments

Comments
 (0)