-
Notifications
You must be signed in to change notification settings - Fork 112
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
JsChecker: support extensionless ES6 imports #409
base: master
Are you sure you want to change the base?
Conversation
Can we add a test for this? |
Test added, but that reminded me of a lingering problem -- moduleLoad error always fires spuriously. Since moduleLoad seems to be redundant to strictDependencies, I suppressed it unconditionally. But probably for the real rules it should be made to work... |
Hm, I see similar Perhaps the rules should just always suppress moduleLoad? |
Sorry for the delay! Yeah, the Regarding this PR, I'm deferring to @alexeagle et al. to decide whether that's something |
Opened an issue for the I'm not sure I understand your other comment -- perhaps Thanks for taking a look |
@alexeagle any thoughts on getting this in? It seems pretty small / unobjectionable to me. |
Sorry for taking so long to come back to this! The longer I think about this, the more opposed I get to allow this. I can't cite the relevant spec right now, but, IIRC, ES6 module imports are supposed to be paths to existing files (which is not true for extensionless imports). IMHO, this should be fixed in the tools producing this broken code. OTOH, I also understand that extensionless imports aren't that uncommon. WDYT about allowing it only behind a flag |
Extensionless imports are explicitly supported by Closure Compiler in NODE resolution mode, which is where I got the idea originally: I don't know the history or context behind them, but after pretty much investigation, this is by far the cleanest way I've found to enable VSCode and other IDEs to understand imports and enable showing info on hover or the ability to click into imported files, for JSX. Since this is supporting a Compiler feature, required for reasonable interop, and I don't really see a downside, I would advocate for not requiring a flag. We can set the flag in our .bazelrc or something if necessary, of course. |
Doesn't node resolution mode also allow importing folders (IIRC by loading Let's say we have the following workspace:
We declare one
|
Sorry, I missed your last response. Relevant link: I agree that your scenario is possible in theory, but it's not possible in practice because the LOAD_AS_DIRECTORY algorithm requires a package.json file, so I don't believe it's possible to trigger that case using rules_closure. Regardless, JsChecker already catches a fraction of the errors, and I think that an additional unusual case which it doesn't catch would not substantially change the developer experience. I suggest that JsChecker supports "LOAD_AS_FILE" but not "LOAD_AS_DIRECTORY". |
There hasn't been any activity in this PR for very long time. |
I want to use extensionless ES6 imports, e.g.
where the module is defined in //path/to/file.js
That seems to work with closure_js_binary without issue, but JsChecker complains. Copying 3 lines from NodeModuleResolver causes the right thing to happen.
If @jart could shed any light on what she had in mind for "Unify path resolution with ModuleLoader", that might be a more robust solution, but this seems to work acceptably.