Closed AStoker closed 3 years ago
Hi 👋 ,
I agree that there is a need for this because it occured to me several times (that an import cannot be found because some of my node_modules is using extensionless specifiers).
However I have a big doubt regarding performance. To achieve what you suggest, the script would have to parse a huge amount of js files (node_modules content can be veryy big) to collect extensionless imports. Moreover the generated importmap file could grow a lot.
In the light of https://github.com/jkrems/proposal-pkg-exports/issues/49#issuecomment-789759581 I start to reconsider parsing js to be aware of static and dynamic imports.
In the end, even if the generated importmap becomes huge and the time to generates it explodes what matters is that the tool becomes more intelligent and helpful for the humans using it.
I am working on it in https://github.com/jsenv/jsenv-node-module-import-map/pull/27
I have just release version 13.0.0, you can follow https://github.com/jsenv/jsenv-node-module-import-map#usage to use it. Now files are parsed to find extension less import and auto generate the required mappings.
I have tested version 13.0.0 on two large codebases of mine and it worked. However I haven't tested it on a codebase written in typescript for instance. Let me know if it works or not ;)
My application pulls in
@aurelia/kernel
which correctly gets the mapnode_modules/@aurelia/kernel/dist/esnext/index.js
. Inside theindex.js
file, another import is requested for a local fileThere is no mapping for this, so this is being treated like a regular import (which would be invalid because it's lacking the .js extension). Seems like just a missing use case for relative files?