You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
will want to turn the foo segment into /node_modules/foo (and leave the rest untouched)
The TS resolver
will want to add the.ts extension to whatever foo/utils resolves into
What should return the PnP resolver?
a. "/node_modules/foo/utils"
b. "/node_modules/foo/sources/utils"
c. "/node_modules/foo/sources/utils.js"
d. ["/node_modules/foo", "./utils"]
Option A is incorrect; the exports field doesn't apply when a file is loaded through an absolute path:
It is not a strong encapsulation since a direct require of any absolute subpath of the package such as require('/path/to/node_modules/pkg/subpath.js') will still load subpath.js.
Option B is good, but requires the PnP loader to not only resolve foo into node_modules/foo, but also ./util into ./sources/utils. To do that requires either to reimplement the exports resolution (with the risks in terms of correctness that come with it), or Node to provide a import.meta.resolveExports('foo/utils', '/node_modules/foo') utility that would do the job for us. This is what we currently do, by embedding a copy of resolve.exports into our loader.
Option C essentially prevents the TS loader from working, since the extension is already resolved.
Option D (which isn't supported by Node at the moment) lets the PnP loader resolves the bare identifier part which Node would presumably process through the same import.meta.resolveExports function described earlier, but keeping it internal.
The text was updated successfully, but these errors were encountered:
I think this is addressed by somehow exposing resolve utils and/or some flavour of createResolve.
Looking at this, this seems like it would be covered by the createResolve({ ...resolveUtilsOverrides }) I mentioned in PR#33. But you've already said that's too limiting. More of the discussion seems to be there, so let's resolve there though.
As a practical example, let's say that we have:
/node_modules/foo/package.json
/node_modules/foo/sources/utils.ts
// Content doesn't matter
/index.js
And let's say that we have a composed pipeline:
The PnP resolver
foo/utils
as inputfoo
segment into/node_modules/foo
(and leave the rest untouched)The TS resolver
.ts
extension to whateverfoo/utils
resolves intoWhat should return the PnP resolver?
a.
"/node_modules/foo/utils"
b.
"/node_modules/foo/sources/utils"
c.
"/node_modules/foo/sources/utils.js"
d.
["/node_modules/foo", "./utils"]
Option A is incorrect; the
exports
field doesn't apply when a file is loaded through an absolute path:Option B is good, but requires the PnP loader to not only resolve
foo
intonode_modules/foo
, but also./util
into./sources/utils
. To do that requires either to reimplement theexports
resolution (with the risks in terms of correctness that come with it), or Node to provide aimport.meta.resolveExports('foo/utils', '/node_modules/foo')
utility that would do the job for us. This is what we currently do, by embedding a copy ofresolve.exports
into our loader.Option C essentially prevents the TS loader from working, since the extension is already resolved.
Option D (which isn't supported by Node at the moment) lets the PnP loader resolves the bare identifier part which Node would presumably process through the same
import.meta.resolveExports
function described earlier, but keeping it internal.The text was updated successfully, but these errors were encountered: