Skip to content

Commit

Permalink
feat: support module.createRequire dependencies detection
Browse files Browse the repository at this point in the history
  • Loading branch information
maxam2017 committed Dec 25, 2024
1 parent 11ff792 commit 457b00d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,20 @@ export default async function analyze(
if (returned) setKnownBinding(fnName.name, { value: BOUND_REQUIRE });
}
}
// Support module.createRequire
if (
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'module' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'createRequire'
) {
if (parent.type === 'VariableDeclarator') {
const requireName = parent.id.name;
setKnownBinding(requireName, { value: BOUND_REQUIRE });
}
}
},
async leave(_node, _parent) {
const node: Node = _node as any;
Expand Down

0 comments on commit 457b00d

Please sign in to comment.