vercel / nft

Node.js dependency tracing utility
https://npmjs.com/@vercel/nft
MIT License
1.31k stars 136 forks source link

fix(resolution): Fix resolution of querystringed imports in ESM files #336

Closed lforst closed 1 year ago

lforst commented 1 year ago

Note: This PR is built on top of https://github.com/vercel/nft/pull/322 which I took over because @lobsterkatie is currently out.


Currently, there are two problems with the way @vercel/nft handles ESM imports with querystrings (import * as something from './someFile?someQuerystring';):

This fixes both of those problems by selectively stripping and re-adding the querystring in ESM imports at various points in the nodeFileTrace lifecycle. More specifically, in resolveDependecy and in emitDependency and its helpers, we strip the querystring (and/or don't add it back), with the exception of:

Notes:

Fixes getsentry/sentry-javascript#5998. Fixes #319.

lforst commented 1 year ago

@styfle New PR because @lobsterkatie is out over the holidays. You mind taking a look? It's the same changes but with the feedback on url.parse you wrote.

Btw, feel free to push any changes you want to make directly to this PR!

styfle commented 1 year ago

@lforst There are merge conflicts in the original PR as well as this PR

lforst commented 1 year ago

We don't need this anymore