-
-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path mapping part 2 #1664
Path mapping part 2 #1664
Conversation
The ESM loader now resolves import paths using TypeScripts [path mapping][1] feature. [1]: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
@cspotcode - I think I've finished the tests 🥳 🎉 A lot of the new tests are currently failing. I think:
I'm not 100% sure what Do you have any more ideas for tests? Or anything else that needs cleaning up? |
Node only allows dropping some extensions when using
Does this mean we need to update the tests to understand different variants of error messages?
Yeah, that's probably testing absolute paths, to make sure they are not accidentally treated as being relative or dependencies. Where do you see |
Also, congrats on finishing the tests! I will review them this week. |
I spoke too soon. I think on review, I actually haven't finished these:
I need to add paths for
I need to add a path for
I need to add a path for
Still need to write this one! |
Should I be explicitly adding
I copied the error messages from the example tests. I wasn't sure if you intended to update the tests to match the implementation or the implementation to match the tests. If it's the former, I could do that!
It's the last requested test case! (I haven't done it yet) |
That sounds like a lot left, but I think the above are small fixes, so I think I'm pretty close -- I'll try to do another push tomorrow night to wrap it up :) |
Hmm, I'm not sure, I'll try to answer that when I review later this week.
Also not sure about this one, I'll check when I review.
I see. Yeah, for that one, we need to test that path mapping does not apply to absolute and relative paths.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this:
Should I be explicitly adding .js everywhere then?
Is it feasible to add .js
when import
ing, and omit it for require()
s? Or is that what you've already done?
It would allow us to run the tests before we implement .js
->.ts
mapping in require()
. ...if that makes sense.
I copied the error messages from the example tests.
What examples are you referring to? Did they come from me? It's possible that I forgot providing examples somewhere.
If the error messages already being raised look appropriate, then we should update the tests to match the errors being raised.
If you think the error messages being raised are incorrect, inadequate, or should be adjusted, then let's talk about that.
src/test/path-mapping.spec.ts
Outdated
baseDir: 'esm-path-mapping', | ||
command: CMD_ESM_LOADER_WITHOUT_PROJECT, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the postfix as
syntax for all type assertions since it's compatible with TSX files. I realize this project doesn't have TSX, but that's just the convention I use everywhere. So we should stick to that for consistency.
They were in the original PR before I started
Ok, I will review the current errors & get back to you :) |
Closing now that we can all collaborate on #1585 |
@charles-allen I'm creating this pull request so we can discuss and review the tests you are adding for path-mapping.
Closes #704
Closes #1585
Closes #1515
This is a continuation of the work started in #1585
Below is the list of tests, copied from #1585 (review)
baseUrl
is set andpaths
is omittedimport "foo"
to${baseUrl}/foo
baseUrl
is set andpaths
maps"*": ["lib/*"]
import "foo"
should not attempt${baseUrl}/foo
; should only attempt${baseUrl}/lib/foo
paths: {"*": ["src/*"]}
,import "lodash"
should fallback tonode_modules/lodash
import "fs"
.d.ts
, resolution should be skipped; try next onenode_modules/*
) are unaffected by mappingsnode_modules/external-library/index.js
doesimport "lodash"
, it should not get./src/lodash
import "./foo"
should not be mapped even if"*"
mapping existsimport "/absolute/path/foo"
should not be mapped even if"*"
mapping exists