Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Nov 17, 2023
1 parent 739f65f commit 39718c8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions build/webpack/webpack.extension.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const config = {
},
],
},
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' },
},
],
},
externals: [
Expand Down
9 changes: 9 additions & 0 deletions src/client/common/process/worker/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
import { Worker } from 'worker_threads';
import { traceError, traceVerbose } from '../../../logging';

/**
* Executes a worker file.
* @param workerFileName Filename of the worker file to execute, it has to end with ".worker.js" for webpack to bundle it.
* @param workerData Arguments to the worker file.
* @returns
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export async function executeWorkerFile(workerFileName: string, workerData: any): Promise<any> {
if (!workerFileName.endsWith('.worker.js')) {
throw new Error('Worker file must end with ".worker.js" for webpack to bundle webworkers');
}
return new Promise((resolve, reject) => {
traceVerbose(`Starting worker ${workerFileName} with data ${JSON.stringify(workerData)}`);
const worker = new Worker(workerFileName, { workerData });
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/process/worker/rawProcessApiWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkerFile } from './main';
import { ExecutionResult, ShellOptions } from './types';

export function workerShellExec(command: string, options: ShellOptions): Promise<ExecutionResult<string>> {
return executeWorkerFile(path.join(__dirname, 'shellExecWorker.js'), {
return executeWorkerFile(path.join(__dirname, 'shellExec.worker.js'), {
command,
options,
});
Expand All @@ -18,7 +18,7 @@ export function workerPlainExec(
args: string[],
options: SpawnOptions = {},
): Promise<ExecutionResult<string>> {
return executeWorkerFile(path.join(__dirname, 'plainExecWorker.js'), {
return executeWorkerFile(path.join(__dirname, 'plainExec.worker.js'), {
file,
args,
options,
Expand Down

0 comments on commit 39718c8

Please sign in to comment.