Skip to content

Commit

Permalink
Add file:// prefix manually to avoid OS-related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
psmyrek committed Nov 21, 2024
1 parent b08cb3d commit 9e3b7a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import crypto from 'crypto';
import upath from 'upath';
import os from 'os';
import url from 'url';
import fs from 'fs/promises';
import { Worker } from 'worker_threads';
import { registerAbortController, deregisterAbortController } from './abortcontroller.js';
Expand Down Expand Up @@ -67,22 +66,6 @@ export default async function executeInParallel( options ) {
defaultAbortController = registerAbortController();
}

let exit = false;

try {
console.log( 'pathToFileURL().href = ', url.pathToFileURL( callbackModule ).href );
} catch ( e ) {
console.log( 'Unable to convert path to URL.' );
console.log( 'cwd = ', cwd );
console.log( 'callbackModule = ', callbackModule );

exit = true;
}

if ( exit ) {
return;
}

const workers = packagesInThreads.map( packages => {
return createWorker( {
signal: signal || defaultAbortController.signal,
Expand All @@ -91,8 +74,8 @@ export default async function executeInParallel( options ) {
packages,
taskOptions,
// The callback module is dynamically imported inside worker script.
// On Windows, absolute path to a dynamically imported file must be valid "file://" protocol URL.
callbackModule: url.pathToFileURL( callbackModule ).toString()
// To make it work in Windows, absolute path to a dynamically imported file must start with the "file:" protocol URL.
callbackModule: 'file://' + callbackModule
}
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ describe( 'executeInParallel()', () => {
const [ firstWorker, secondWorker ] = stubs.WorkerMock.instances;

expect( firstWorker.workerData ).toBeInstanceOf( Object );
expect( firstWorker.workerData ).toHaveProperty( 'callbackModule', 'file:///C:/Users/ckeditor/uuid-4.mjs' );
expect( firstWorker.workerData ).toHaveProperty( 'callbackModule', 'file://C:/Users/ckeditor/uuid-4.mjs' );
expect( firstWorker.workerData ).toHaveProperty( 'packages' );

expect( secondWorker.workerData ).toBeInstanceOf( Object );
expect( secondWorker.workerData ).toHaveProperty( 'callbackModule', 'file:///C:/Users/ckeditor/uuid-4.mjs' );
expect( secondWorker.workerData ).toHaveProperty( 'callbackModule', 'file://C:/Users/ckeditor/uuid-4.mjs' );
expect( secondWorker.workerData ).toHaveProperty( 'packages' );

// Workers did not emit an error.
Expand Down

0 comments on commit 9e3b7a3

Please sign in to comment.