Enhacement: support for package.json module property
igmdvc opened this issue · 5 comments
Hi,
First of all, thanks for the great job on this module and also the dependency-tree one which I am currently using.
I am trying to generate dependencies and some of the packages in node_modules that declare the module property as entry point, and it would be nice that, through configuration, we can resolve the filename of the import by using module property instead of the main one.
I have been looking at the source code and I think it would be straightforward by using the option packageFilter from resolve npm module. Something like this inside commonJSLookup resolve.sync:
result = resolve.sync(partial, { basedir: directory, packageFilter: function(obj) { obj.main = obj.module ? obj.module : obj.main; return obj; }, // Add fileDir to resolve index.js files in that dir moduleDirectory: ['node_modules', directory] });
Hey @igmdvc! Thanks for contributing.
When would you want to use the module property instead of what the cjs resolver currently provides? Can you provide an example? Just having a hard time understanding the problem that the module property solves.
Hey @mrjoelkemp,
I am working on a code splitting tool based on node. One of the dependencies is angular, which declares not only main property for ES5 bundles, but also the module one pointing to an ES2015 module bundle. As the bundle I am using is based on ES2015 modules, I would like to choose how to resolve the files from angular or other modules that declares the module property as an entrypoint for es6 files.
Here you have an article that explains the situation:
https://nodesource.com/blog/es-modules-and-node-js-hard-choices/
Sounds great. Would you want to provide a flag to filing-cabinet that turns this mode on? If so, would love to see what the changes would look like in a PR.
For sure, I have some code ready to be added as a PR. Just give me permissions and I will create it
@igmdvc awesome to hear. You can fork the repo and submit a PR. Looking forward to reviewing it.