[Fix] extensions: ignore type-only imports - #2270
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2270 +/- ##
==========================================
- Coverage 94.63% 94.60% -0.04%
==========================================
Files 65 65
Lines 2686 2688 +2
Branches 888 888
==========================================
+ Hits 2542 2543 +1
- Misses 144 145 +1
Continue to review full report at Codecov.
|
ljharb
left a comment
There was a problem hiding this comment.
This fix looks good, but the issue it's fixing is about the import/no-unresolved rule
3a0c730 to
46c4709
Compare
|
Thanks! My reading of #2267 is that the original |
|
hm, maybe so - i'll confirm with the OP. |
So, Node requires generated ESM JS files need to have imports that end with `.js` (unless they are importing the root or declared export from a package... but for relative paths, this is a must). But we haven't quite figured out a way to get tsc to force us to do this... so if we mess it up, we only find out at runtime when trying to run a built ESM package. This doesn't even necessarily show up in our tests (Jest does its own thing a lot), and the new smoke-test doesn't cover all of our codebase. So we set up eslint with a particular rule that looks for this. As it happens, this rule doesn't check `import type` (import-js/eslint-plugin-import#2270) but fortunately `import type` doesn't matter to Node. We don't generally enable eslint: there are plenty of rules that we don't pass currently. We can consider adding some rules later as they are found to be valuable. For now we just run this one rule!
So, Node requires generated ESM JS files need to have imports that end with `.js` (unless they are importing the root or declared export from a package... but for relative paths, this is a must). But we haven't quite figured out a way to get tsc to force us to do this... so if we mess it up, we only find out at runtime when trying to run a built ESM package. This doesn't even necessarily show up in our tests (Jest does its own thing a lot), and the new smoke-test doesn't cover all of our codebase. So we set up eslint with a particular rule that looks for this. As it happens, this rule doesn't check `import type` (import-js/eslint-plugin-import#2270) but fortunately `import type` doesn't matter to Node. We don't generally enable eslint: there are plenty of rules that we don't pass currently. We can consider adding some rules later as they are found to be valuable. For now we just run this one rule!
So, Node requires generated ESM JS files need to have imports that end with `.js` (unless they are importing the root or declared export from a package... but for relative paths, this is a must). But we haven't quite figured out a way to get tsc to force us to do this... so if we mess it up, we only find out at runtime when trying to run a built ESM package. This doesn't even necessarily show up in our tests (Jest does its own thing a lot), and the new smoke-test doesn't cover all of our codebase. So we set up eslint with a particular rule that looks for this. As it happens, this rule doesn't check `import type` (import-js/eslint-plugin-import#2270) but fortunately `import type` doesn't matter to Node. We don't generally enable eslint: there are plenty of rules that we don't pass currently. We can consider adding some rules later as they are found to be valuable. For now we just run this one rule!
import/extensionsrule currently errors on unresolved imports (I gather)∴ disable
import/extensionsfor type-only imports, along the lines of #2220.Relates to #2267