@@ -12,7 +12,8 @@ import workerpool from 'workerpool';
1212
1313tmp . setGracefulCleanup ( ) ;
1414
15- const WORKER_URL = new URL ( './worker.js' , import . meta. url ) ;
15+ import { fileURLToPath } from 'url' ;
16+ const WORKER_PATH = fileURLToPath ( new URL ( './worker.js' , import . meta. url ) ) ;
1617
1718class NoFilesError extends Error { }
1819
@@ -121,7 +122,7 @@ class StatsCollector {
121122}
122123
123124export default async function run (
124- transformFile : string ,
125+ transformFile : URL ,
125126 filePaths : string [ ] ,
126127 options : { silent ?: boolean ; cpus : number }
127128) : Promise < void > {
@@ -151,11 +152,11 @@ export default async function run(
151152/**
152153 * Returns the location of the transform module on disk.
153154 */
154- async function loadTransform ( transformFile : string ) : Promise < string > {
155- const isRemote = transformFile . startsWith ( 'http' ) ;
155+ async function loadTransform ( transformFile : URL ) : Promise < string > {
156+ const isLocal = transformFile . protocol === 'file:' ;
156157
157- if ( ! isRemote ) {
158- return resolve ( process . cwd ( ) , transformFile ) ;
158+ if ( isLocal ) {
159+ return fileURLToPath ( transformFile ) ;
159160 }
160161
161162 const contents = await downloadFile ( transformFile ) ;
@@ -166,9 +167,9 @@ async function loadTransform(transformFile: string): Promise<string> {
166167 return filePath . name ;
167168}
168169
169- function downloadFile ( url : string ) : Promise < string > {
170+ function downloadFile ( url : URL ) : Promise < string > {
170171 return new Promise ( ( resolve , reject ) => {
171- const transport = url . startsWith ( 'https' ) ? https : http ;
172+ const transport = url . protocol === 'https:' ? https : http ;
172173
173174 let contents = '' ;
174175 transport
@@ -221,7 +222,7 @@ async function spawnWorkers(
221222
222223 logger . spin ( 'Processed 0 files' ) ;
223224
224- const pool = workerpool . pool ( WORKER_URL . pathname , { maxWorkers : cpus } ) ;
225+ const pool = workerpool . pool ( WORKER_PATH , { maxWorkers : cpus } ) ;
225226
226227 let i = 0 ;
227228 const worker = ( queue as any ) . async . asyncify ( async ( file : string ) => {
@@ -240,13 +241,14 @@ async function spawnWorkers(
240241
241242function handleError ( err : any , logger : Logger ) : void {
242243 if ( err . code === 'MODULE_NOT_FOUND' ) {
243- logger . error ( ' Transform plugin not found' ) ;
244+ logger . error ( ` Transform plugin not found` ) ;
244245 } else if ( err instanceof NoFilesError ) {
245246 logger . error ( 'No files matched' ) ;
246247 } else {
247248 logger . error ( err ) ;
248- if ( err . stack ) {
249- logger . error ( err . stack ) ;
250- }
249+ }
250+
251+ if ( err . stack ) {
252+ logger . error ( err . stack ) ;
251253 }
252254}
0 commit comments