Skip to content

Commit

Permalink
fix(runner): correctly handle official import.meta.resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Dec 12, 2023
1 parent 0150101 commit 3259a81
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions runner/lib/helpers/module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRequire } from 'module';
import { pathToFileURL } from 'url';
import { pathToFileURL, fileURLToPath } from 'url';
import { promises as fs } from 'fs';

/**
*
Expand All @@ -12,11 +13,19 @@ export const resolve = async (specified, parent) => {
}
try {
if (import.meta.resolve) {
return await import.meta.resolve(specified, parent);
const resolved = await import.meta.resolve(specified, parent);
await fs.stat(fileURLToPath(resolved));
return resolved;
}
} catch (err) {
if (/MODULE_NOT_FOUND/.test(/** @type {any} */ (err).code)) {
throw err;
} catch (e) {
const err = /** @type {NodeJS.ErrnoException} */ (e);
switch (err.code) {
case 'ENOENT':
return undefined;
case 'MODULE_NOT_FOUND':
break;
default:
throw err;
}
// Fall-through
}
Expand Down

0 comments on commit 3259a81

Please sign in to comment.