jsenv / importmap-node-module

Generate importmap for node_modules
35 stars 4 forks source link

Maps aren't generated for relative paths #21

Closed AStoker closed 3 years ago

AStoker commented 4 years ago

My application pulls in @aurelia/kernel which correctly gets the map node_modules/@aurelia/kernel/dist/esnext/index.js. Inside the index.js file, another import is requested for a local file

import { DI } from './di';

There 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?

dmail commented 4 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.

dmail commented 3 years ago

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.

dmail commented 3 years ago

I am working on it in https://github.com/jsenv/jsenv-node-module-import-map/pull/27

dmail commented 3 years ago

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 ;)