Repository navigation
lib: add experimental node:yaml module - #67157
Open
marcopiraccini wants to merge 1 commit into
Open
marcopiraccini wants to merge 1 commit into
marcopiraccini wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
marcopiraccini
force-pushed
the
yaml-module
branch
from
October 31, 2026 07:28
405299b to
0d87e9f
Compare
marcopiraccini
marked this pull request as ready for review
October 31, 2026 07:37
marcopiraccini
force-pushed
the
yaml-module
branch
2 times, most recently
from
October 31, 2026 08:29
ad1f666 to
09ed139
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67157 +/- ##
==========================================
+ Coverage 90.69% 90.73% +0.03%
==========================================
Files 797 799 +2
Lines 278787 280456 +1669
Branches 53607 54257 +650
==========================================
+ Hits 252858 254467 +1609
- Misses 16292 16343 +51
- Partials 9637 9646 +9
🚀 New features to boost your workflow:
|
Add a YAML 1.2 parser for the core schema as `node:yaml`, behind `--experimental-yaml`, with `yaml.parse(input)` following the shape of `Bun.YAML.parse()`. The parser is written from scratch, in one pass from text to values, with no new dependency. Anchors and aliases resolve to shared objects, core schema tags are applied, mappings become plain objects and duplicate keys are an error. The official yaml-test-suite is vendored as a JSON fixture and run by test-yaml-test-suite.js: 400 of its 402 cases pass, the two left are documents with duplicate keys. Refs: nodejs#53787 Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
marcopiraccini
force-pushed
the
yaml-module
branch
from
October 31, 2026 10:22
09ed139 to
bbfacd1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a proposal for a built-in YAML parser, with a basic implementation to discuss on: an experimental, parse-only
node:yamlmodule behind--experimental-yaml.The parser supports the YAML 1.2 core schema, anchors, aliases, tags, and multi-document streams. It is written from scratch and has no external dependencies.
This gives Node.js a built-in YAML parser for future configuration support, following the discussion about
.nodercin #53787, where the config file ended up JSON-only because core had no parser.Bun parity
Bun ships
Bun.YAMLsince v1.2.21.yaml.parse()followsBun.YAML.parse()so that code written for it runs unchanged:parse(input)takes a string or binary input (ArrayBuffer,TypedArray,DataView) decoded as UTF-8.null.SyntaxError(here with theERR_INVALID_YAMLcode and the line and column).!!strand!!intare applied.Not covered yet:
Bun.YAML.stringify(value, replacer, space),Blobinput, and importing.yamlfiles as modules. See the next steps.Tests
Tests include the official YAML Test Suite, vendored at a fixed revision. Of 402 cases, 400 pass.
The two that fail, 2JQS and X38W, are documents with duplicate keys: two empty keys, and a key that is an alias of the previous key. The suite only checks that they parse, since duplicate keys are not a syntax error, and provides no expected output for them. The YAML 1.2 specification requires mapping keys to be unique, and this parser enforces it and throws
Duplicate mapping key, as theyamlandjs-yamlpackages do by default. They are listed as known failures with that reason. If the reviewers prefer theJSON.parse()behavior, where the last value wins, the check can be removed and both pass.Review guide
doc/api/yaml.md: API behavior.lib/yaml.js: input validation and document return values.lib/internal/yaml/parser.js: parser implementation.test/parallel/test-yaml.js: API tests.test/parallel/test-yaml-test-suite.js: official suite runner.node:vfssetup in vfs: add minimal node:vfs subsystem #63115.Next steps, if accepted
yaml.stringify(value, replacer, space)with Bun's semantics.import data from './config.yaml' with { type: 'yaml' }.--experimental-config-file.yamlsubsystem label and commit subsystem, as was done forvfs.Refs: