Skip to content

Commit 8941216

Browse files
committed
Troubleshoot windows failure with new URL
Must use `fileURLToPath` to convert properly back from URL into a path.
1 parent e02b20c commit 8941216

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/bin.test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { existsSync } from 'fs';
2+
import { fileURLToPath } from 'url';
23
import execa from 'execa';
34
import { join } from 'path';
45
import { createTempDir, TempDir } from 'broccoli-test-helper';
56
import slash from 'slash';
67

7-
const COMPILED_BIN_PATH = new URL('./bin.js', import.meta.url).pathname;
8+
const COMPILED_BIN_PATH = fileURLToPath(new URL('./bin.js', import.meta.url));
9+
810
if (!existsSync(COMPILED_BIN_PATH)) {
9-
throw new Error('Missing compiled output, run `yarn build`!');
11+
throw new Error(
12+
`Missing compiled output, run \`yarn build\`! Looked at ${COMPILED_BIN_PATH} (based on ${
13+
import.meta.url
14+
})`
15+
);
1016
}
1117

1218
function run(args: string[], cwd: string) {

src/bin.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as os from 'os';
44
import { readFileSync } from 'fs';
55
import { program } from 'commander';
66
import run from './runner.js';
7+
import { pathToFileURL } from 'url';
78

89
const version = JSON.parse(
910
readFileSync(new URL('../package.json', import.meta.url), { encoding: 'utf-8' })
@@ -36,5 +37,6 @@ if (program.args.length < 1 || !programOptions.transform) {
3637
silent: programOptions.silent,
3738
};
3839

40+
const transformPath = pathToFileURL(programOptions.transform);
3941
run(programOptions.transform, program.args, options);
4042
}

src/runner.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import workerpool from 'workerpool';
1212

1313
tmp.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

1718
class NoFilesError extends Error {}
1819

@@ -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

241242
function 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

Comments
 (0)