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.main.require not being parsed #47
Comments
Because this issue bothers me quite a lot (currently I have to manually include modules inside Serverless config file which is super awkward) I will actually try to "fix" this and send PR. So if I understood referenced issue correctly it's |
I appreciate the help. Thanks in advance for the contribution.
Yes. My assumption here is that |
I took a quick look at the So I went there and eventually made it work (in tests) by modifying that function (AST explorer has been of great help). Modules required with Anyway, the only difference is this before:
and after:
|
Great work tracking down a fix. That's actually a better place for it since module-definition will also properly correlate that special require with commonjs. Consider using extracting the addition to a method like: return isPlainRequire(node) || isMainScopedRequire(node); where |
Yeah, this was just a "hotfix" to see if idea sticks (tests passed). I'll go with your suggestions and submit the PR (most probably tomorrow). |
I finally managed to find some free time today to do this. I've just sent PR for this. |
@choxnox thanks again for your contribution. I pushed the support all the way up to precinct. There's another missing piece to this though. We now have the ability to extract dependencies from main scoped require statements, but we don't yet know how to resolve them to a file on the filesystem. This is the module and code that's used to handle a commonjs style of module resolution: https://github.com/dependents/node-filing-cabinet/blob/master/index.js#L195. Since Does the fix in precinct completely satisfy your need, or are you trying to generate a dependency tree from your project (at which point, you'll need the mapping of module to file)? Are you open to a PR that adds main scoped commonjs module resolution support to filing cabinet? |
Library works for cases like
require("whatever")
but unfortunately it doesn't detectrequire.main.require("whatever")
which is also legal and used to reference modules relative to the main JS file. Any chance to support this?The text was updated successfully, but these errors were encountered: