Skip to content

Commit a6f9f67

Browse files
author
Kartik Raj
committed
z
1 parent 53b0faa commit a6f9f67

File tree

6 files changed

+39
-46
lines changed

6 files changed

+39
-46
lines changed

build/webpack/webpack.extension.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ const config = {
5151
},
5252
],
5353
},
54-
{
55-
test: /\.worker\.js$/,
56-
use: { loader: 'worker-loader' },
57-
},
5854
],
5955
},
6056
externals: [

src/client/common/process/proc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { IDisposable } from '../types';
77
import { EnvironmentVariables } from '../variables/types';
88
import { execObservable, killPid, plainExec, shellExec } from './rawProcessApis';
99
import { ExecutionResult, IProcessService, ObservableExecutionResult, ShellOptions, SpawnOptions } from './types';
10-
import { workerPlainExec, workerShellExec } from './worker/rawProcessApiWrapper';
10+
import { workerPlainExec } from './worker/workerPlainExec';
11+
import { workerShellExec } from './worker/workerShellExec';
1112

1213
export class ProcessService extends EventEmitter implements IProcessService {
1314
private processesToKill = new Set<IDisposable>();

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// !!!! IMPORTANT: DO NOT IMPORT FROM VSCODE MODULE AS IT IS NOT AVAILABLE INSIDE WORKER THREADS !!!!
5+
46
import { Worker } from 'worker_threads';
5-
import { traceVerbose, traceError } from '../../../logging/index';
67

7-
/**
8-
* Executes a worker file.
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-
*/
138
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
149
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-
}
1810
return new Promise((resolve, reject) => {
19-
traceVerbose(`Starting worker ${workerFileName} with data ${JSON.stringify(workerData)}`);
2011
const worker = new Worker(workerFileName, { workerData });
21-
traceVerbose(`Started worker ${workerFileName}`);
2212
worker.on('message', (msg: { err: Error; res: unknown }) => {
23-
traceVerbose(`Worker ${workerFileName} sent message ${JSON.stringify(msg)}`);
2413
if (msg.err) {
2514
reject(msg.err);
2615
}
2716
resolve(msg.res);
2817
});
2918
worker.on('error', (ex: Error) => {
30-
traceError(`Error in worker ${workerFileName}`, ex);
3119
reject(ex);
3220
});
3321
worker.on('exit', (code) => {
34-
traceVerbose(`Worker ${workerFileName} exited with code ${code}`);
3522
if (code !== 0) {
3623
reject(new Error(`Worker ${workerFileName} stopped with exit code ${code}`));
3724
}

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/client/common/process/worker/plainExec.worker.ts renamed to src/client/common/process/worker/workerPlainExec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// !!!! IMPORTANT: DO NOT IMPORT FROM VSCODE MODULE AS IT IS NOT AVAILABLE INSIDE WORKER THREADS !!!!
5+
6+
import { SpawnOptions } from 'child_process';
17
import { isMainThread, parentPort, workerData } from 'worker_threads';
8+
import { executeWorkerFile } from './main';
9+
import { ExecutionResult } from './types';
10+
211
import { _workerPlainExecImpl } from './workerRawProcessApis';
312

13+
export function workerPlainExec(
14+
file: string,
15+
args: string[],
16+
options: SpawnOptions = {},
17+
): Promise<ExecutionResult<string>> {
18+
return executeWorkerFile(__filename, {
19+
file,
20+
args,
21+
options,
22+
});
23+
}
24+
425
if (!isMainThread) {
526
_workerPlainExecImpl(workerData.file, workerData.args, workerData.options)
627
.then((res) => {

src/client/common/process/worker/shellExec.worker.ts renamed to src/client/common/process/worker/workerShellExec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// !!!! IMPORTANT: DO NOT IMPORT FROM VSCODE MODULE AS IT IS NOT AVAILABLE INSIDE WORKER THREADS !!!!
5+
16
import { isMainThread, parentPort, workerData } from 'worker_threads';
7+
import { executeWorkerFile } from './main';
8+
import { ExecutionResult, ShellOptions } from './types';
29
import { _workerShellExecImpl } from './workerRawProcessApis';
310

11+
export function workerShellExec(command: string, options: ShellOptions): Promise<ExecutionResult<string>> {
12+
return executeWorkerFile(__filename, {
13+
command,
14+
options,
15+
});
16+
}
17+
418
if (!isMainThread) {
519
_workerShellExecImpl(workerData.command, workerData.options, workerData.defaultEnv)
620
.then((res) => {

0 commit comments

Comments
 (0)