Skip to content

Commit

Permalink
Allow no parentURL for bare specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Jun 27, 2024
1 parent 07c68a7 commit 05b5876
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,18 @@ export default async function analyze(
break;
case MODULE_FN:
if (
node.arguments.length > 1 &&
node.arguments.length &&
// TODO: We only cater for the case where the first argument is a string
node.arguments[0].type === 'Literal'
) {
const pathOrSpecifier = node.arguments[0].value;
// It's a relative URL
if (pathOrSpecifier.startsWith('.')) {
// Compute the parentURL if it's statically analyzable
const computedParentURL = await computePureStaticValue(
node.arguments[1],
);
const computedParentURL =
node.arguments.length > 1
? await computePureStaticValue(node.arguments[1])
: undefined;

if (computedParentURL && 'value' in computedParentURL) {
const parentURL =
Expand Down
2 changes: 1 addition & 1 deletion test/unit/module-register/input-esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { register } from 'module';
// Load relative to the current file
register('./hook.mjs', import.meta.url);
// Load from a bare specifier
register('test-pkg', import.meta.url);
register('test-pkg');

0 comments on commit 05b5876

Please sign in to comment.