Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require.resolve not being listed as a dependency #42

Open
mistic opened this issue Aug 16, 2018 · 2 comments
Open

require.resolve not being listed as a dependency #42

mistic opened this issue Aug 16, 2018 · 2 comments

Comments

@mistic
Copy link

mistic commented Aug 16, 2018

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 ?

@mrjoelkemp
Copy link
Collaborator

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
Copy link
Collaborator

Hey @mistic. Similar support was recently added by a contributor for supporting require.main.require. That (#47) could be a good starting point if you or another contributor would like to address this issue.

ZhenyuCheng pushed a commit to ZhenyuCheng/node-precinct that referenced this issue Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants