lustre-labs / dev-tools

Lustre's CLI and development tooling: zero-config dev server, bundling, and scaffolding.
45 stars 15 forks source link

Rewrite bare js imports to resolve to node_modules. #56

Open hayleigh-dot-dev opened 1 month ago

hayleigh-dot-dev commented 1 month ago

We recently ran into a question where someone was struggling to import a file like import whatever from 'some-package' in their ffi code. Users coming from other js bundlers will expect imports like this to work automatically, and folks using dev-tools for bundling but still using npm to access the js ecosystem will run into this problem every time.

If we were using the npm version of esbuild we could use the node resolution plugin, but because we're using the standalone version we are going to have to work on the js ffi files directly.

Node calls these kinds of imports that are not relative or absolute, "bare" imports. And the rules for how they are resolved are outlined in https://nodejs.org/api/packages.html#package-entry-points. It would be great if we would rewrite these bare imports into ones that resolved to node_modules correctly before running esbuild.