node-precinct icon indicating copy to clipboard operation
node-precinct copied to clipboard

require.resolve not being listed as a dependency

Open mistic opened this issue 6 years ago • 2 comments

I'm trying to use this module in order to create a list of all the dependencies in use into my application. However the require.resolve is not being listed as a dependency.

Any idea how to solve this @mrjoelkemp ?

mistic avatar Aug 16 '18 05:08 mistic

Hey @mistic. Thanks for the issue! Can you provide an example of how you're using require.resolve?

Based on my assumptions on how you're using it, we'd need to add support for it in the commonjs detective. I could definitely see your future example being a test case here: https://github.com/dependents/node-detective-cjs/blob/master/test/test.js#L33.

Here is where we sniff for require(): https://github.com/dependents/node-detective-cjs/blob/master/index.js#L13-L26. You could add support for require.resolve there by looking for a resolve function call that's an attribute of a require object.

If you're unfamiliar with ASTs, you're basically iterating through the keys in a big object and looking for a particular part of it (if it exists). Here's a good tool for seeing the AST representation of some code to look for the part of the object that represents require.resolve(''): https://astexplorer.net/#/gist/ed8f609760da184363377d975063552b/45f0e4dae0e876853a9997fde5faeeb7137e4746.

I'm super open to a PR in node-detective-cjs with the fix.

mrjoelkemp avatar Aug 17 '18 18:08 mrjoelkemp

Hey @mistic. Similar support was recently added by a contributor for supporting require.main.require. That (https://github.com/dependents/node-precinct/issues/47) could be a good starting point if you or another contributor would like to address this issue.

mrjoelkemp avatar Oct 27 '18 12:10 mrjoelkemp