Skip to content

Commit 39718c8

Browse files
author
Kartik Raj
committed
s
1 parent 739f65f commit 39718c8

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

build/webpack/webpack.extension.config.js

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
import { Worker } from 'worker_threads';
55
import { traceError, traceVerbose } from '../../../logging';
66

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+
*/
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) => {
1019
traceVerbose(`Starting worker ${workerFileName} with data ${JSON.stringify(workerData)}`);
1120
const worker = new Worker(workerFileName, { workerData });

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,

0 commit comments

Comments
 (0)