Skip to content

Commit

Permalink
Troubleshoot windows failure with new URL
Browse files Browse the repository at this point in the history
Must use `fileURLToPath` to convert properly back from URL into a path.
  • Loading branch information
rwjblue committed Nov 4, 2021
1 parent e02b20c commit 8941216
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/bin.test.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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);
}
14 changes: 8 additions & 6 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
}
}

0 comments on commit 8941216

Please sign in to comment.