-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add pure ES module build #138
Add pure ES module build #138
Comments
Maybe? I mean, there is already a separate browser build, so adding a Node ES module target would not be an undue burden on top of that. In particular, now that Node 13 includes support for the I'm also happy to keep on transpiling code, rather than publishing sources directly. This allows using features like class properties in code. On that note, I think it might make sense to delay introducing this in a release until Node v14 is released in April, so that the Babel transpilation target can be set as |
This turned out not to require any additional build target; just a little bit of package.json config and two additional I opted not to add ES module endpoints for the deprecated import paths, on account of those never having worked in the first place in a Node ES context. |
Cool but this is Node only, so it's more of a "Node ES module". This does not add compatibility for Deno or quickjs. Should I make a separate issue for a "pure ES module" build?
How do you determine what time that makes sense? |
Ah, I may have misunderstood what you were asking for earlier. No need to open a new issue, let's just reopen this and specify the title a bit more. Providing an ES-only version of the library in parallel with the CommonJS export is tricky, because the AST level of its API uses and exposes a bunch of classes, which are then used for The current ES module implementation therefore relies on being able to I'm not really deeply familiar with Deno, but I gather that with something like this it'd be possible to add a Going forward, I'd be quite willing to consider a v2 of the library that would drop the CommonJS export, and effectively solve this problem at the same time. But I don't think that makes sense quite yet, as almost all Node apps are still using CommonJS at least at runtime. |
Maybe another way of fixing this would be using another method to check if an object is a const NODE_SYMBOL = Symbol.for('npm.yaml.Node')
class Node {
static yamlType = NODE_SYMBOL
static isNode(val) {
return typeof val === 'object' && val?.constructor?.yamlType === NODE_SYMBOL
}
} And then, the official way of testing if something is a |
I'd really rather not break Given that the actual source is entirely ES, it should be possible for anyone that needs an ES-only package to build it from the repo. Therefore, and given that I don't see this happening with the npm-distributed package at least for a year, possibly more, I'm going to close this issue (again). This should also clarify that this isn't expected to become a part of the yaml 2 release in a few months' time. |
Hello,
please add an additional ES module build. The source code is already almost an ES module, the two incompatibilities are imports not pointing at files (with file extensions) and using class fields.
Class fields are more or less final and can be left alone so the only change necessary for
src/
to be an ES module are the imports. I tried rewriting them which works fine in Node v13 and higher but breaks all the tests because jest does not support it jet. They're working on it though.In the meantime I suggest adding a third babel build using no preset and an additional plugin:
["@pika/babel-plugin-esm-import-rewrite", {addExtensions: true}]
. Also pointing themodule
field to the new build inpackage.json
.Are you open to this? And if so do you want a pull request implementing this?
BTW this is a great library and especially the documentation is fantastic
The text was updated successfully, but these errors were encountered: