-
Notifications
You must be signed in to change notification settings - Fork 337
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
Fix the exports of vscode-languageserver-types #1297
Fix the exports of vscode-languageserver-types #1297
Conversation
The `exports` field is needed for dual publishing CJS and ESM. The `module` field on the other hand, is a non-standard property. Some bundlers incorrectly interpret it, causing interop issues. An additional `package.json` file is written to mark the ESM output as actual ESM.
4c1ce08
to
5ac8036
Compare
It turns out only |
@aeschli can you have a look. I remember that you added the ESM support to types and text documents and I don't know in which use cases we need this and if they are still covered. |
@remcohaszing Yes, our node modules layout need to properly adopt ESM modules. Many packages fully move to esm, but, as you say, that's a breaking change and will cause an outcry. I read up on how to publish a hybrid. https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html supports your suggestion. |
For the The This could be swapped, but it's less convenient. This is in part because TypeScript isn't meant for dual publishing. Also note that I created microsoft/vscode#192144 as an umbrella issue for the exports of several VSCode client libraries. It contains some more general details. |
The changes look good. I tested that consuming the esm script work from our webpack files in VS Code, no client side changes needed. I added a commit that updates the target to es6. Any objections? |
Could this be the reason why RunKit is broken for this library? var vscodeLanguageserverTypes = require("[email protected]"); // ok
var vscodeLanguageserverTypes = require("[email protected]"); // ok
var vscodeLanguageserverTypes = require("[email protected]"); // does not work I have tried using RunKit for my own library and it seems after changing to 3.17.3 it won't run anymore... 🤔 |
I would like to address any concerns in this and related PRs once I get back from vacation next week. |
I just posted them here: microsoft/vscode#192144 (comment) Anyway, I think this PR is mostly fine now. |
Sorry, I have no clue why this is broken. This looks like a RunKit issue. |
Do you target a specific Node.js version? I recommend looking at https://github.com/tsconfig/bases/tree/main/bases to pick a target. Most notably IMO, a target of |
Thanks for the limk, yes then we should go to a more modern version such as es2018. |
The
exports
field is needed for dual publishing CJS and ESM. Themodule
field on the other hand, is a non-standard property. Some bundlers incorrectly interpret it, causing interop issues.An additional
package.json
file is written to mark the ESM output as actual ESM.I don’t really like this solution, but it works.
This may break projects that rely on hacks to use the faux ESM. That could be resolved by adding more exports to support all old paths.I’m not convinced this is an issue.Correctness can be tested on https://arethetypeswrong.github.io. Note that it currently states that the version on npm is ok due to a false negative.
My personal recommendation would be to stop dual publishing to avoid the dual package hazard among other complexities.This still stands, but it would be a breaking change.