diff --git a/src/bin.test.ts b/src/bin.test.ts index 173f9a56..f7320a61 100644 --- a/src/bin.test.ts +++ b/src/bin.test.ts @@ -1,12 +1,18 @@ import { existsSync } from 'fs'; +import { fileURLToPath } from 'url'; import execa from 'execa'; import { join } from 'path'; import { createTempDir, TempDir } from 'broccoli-test-helper'; import slash from 'slash'; -const COMPILED_BIN_PATH = new URL('./bin.js', import.meta.url).pathname; +const COMPILED_BIN_PATH = fileURLToPath(new URL('./bin.js', import.meta.url)); + if (!existsSync(COMPILED_BIN_PATH)) { - throw new Error('Missing compiled output, run `yarn build`!'); + throw new Error( + `Missing compiled output, run \`yarn build\`! Looked at ${COMPILED_BIN_PATH} (based on ${ + import.meta.url + })` + ); } function run(args: string[], cwd: string) { diff --git a/src/bin.ts b/src/bin.ts index b8f7eae6..b0e53ced 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -4,6 +4,7 @@ import * as os from 'os'; import { readFileSync } from 'fs'; import { program } from 'commander'; import run from './runner.js'; +import { pathToFileURL } from 'url'; const version = JSON.parse( readFileSync(new URL('../package.json', import.meta.url), { encoding: 'utf-8' }) @@ -36,5 +37,6 @@ if (program.args.length < 1 || !programOptions.transform) { silent: programOptions.silent, }; + const transformPath = pathToFileURL(programOptions.transform); run(programOptions.transform, program.args, options); } diff --git a/src/runner.ts b/src/runner.ts index 00226f61..80401412 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -12,7 +12,8 @@ import workerpool from 'workerpool'; tmp.setGracefulCleanup(); -const WORKER_URL = new URL('./worker.js', import.meta.url); +import { fileURLToPath } from 'url'; +const WORKER_PATH = fileURLToPath(new URL('./worker.js', import.meta.url)); class NoFilesError extends Error {} @@ -221,7 +222,7 @@ async function spawnWorkers( logger.spin('Processed 0 files'); - const pool = workerpool.pool(WORKER_URL.pathname, { maxWorkers: cpus }); + const pool = workerpool.pool(WORKER_PATH, { maxWorkers: cpus }); let i = 0; const worker = (queue as any).async.asyncify(async (file: string) => { @@ -240,13 +241,14 @@ async function spawnWorkers( function handleError(err: any, logger: Logger): void { if (err.code === 'MODULE_NOT_FOUND') { - logger.error('Transform plugin not found'); + logger.error(`Transform plugin not found`); } else if (err instanceof NoFilesError) { logger.error('No files matched'); } else { logger.error(err); - if (err.stack) { - logger.error(err.stack); - } + } + + if (err.stack) { + logger.error(err.stack); } }