Skip to content

src,lib: add experimental node:formats/toml module - #67874

Open
aduh95 wants to merge 4 commits into
nodejs:mainfrom
aduh95:toml++
Open

aduh95 wants to merge 4 commits into
nodejs:mainfrom
aduh95:toml++

Conversation

@aduh95

@aduh95 aduh95 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Related to #67157 //cc @marcopiraccini

Opt-in with a configure flag, so it can be backported. The plan is to make it opt-out in a future semver-major.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/actions
  • @nodejs/gyp
  • @nodejs/loaders
  • @nodejs/security-wg
  • @nodejs/startup
  • @nodejs/tsc
@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 29, 2026
@github-actions

This comment was marked as outdated.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Add the header-only toml++ library, its updater script and license
entry, for use by node:formats/toml.
Add a TOML parser and serializer backed by toml++, available behind
`--experimental-toml` as the scheme-only `node:formats/toml` builtin.

Assisted-by: Devin
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
This can be reverted once at least one serializer it documents is
enabled by default.

Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor
Platform Number of requisites Proportion of new derivations
x86_64-linux 519 -> 520 => +1 1 / 520 = 0.1%
aarch64-linux 520 -> 521 => +1 1 / 521 = 0.1%
x86_64-darwin 447 -> 448 => +1 1 / 448 = 0.2%
aarch64-darwin 449 -> 450 => +1 1 / 450 = 0.2%
Total 1935 -> 1939 => +4 4 / 1939 = 0.2%
Version changes
Package Version Platforms
tomlplusplus added: 3.4.0 x86_64-darwin
tomlplusplus added: 3.5.1 aarch64-darwin, aarch64-linux, x86_64-linux
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.87500% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.56%. Comparing base (1611823) to head (83860ae).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/formats/toml.js 52.73% 69 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67874      +/-   ##
==========================================
- Coverage   90.58%   90.56%   -0.03%     
==========================================
  Files         802      804       +2     
  Lines      286656   286816     +160     
  Branches    55369    55378       +9     
==========================================
+ Hits       259668   259753      +85     
- Misses      17089    17184      +95     
+ Partials     9899     9879      -20     
Files with missing lines Coverage Δ
lib/formats/toml.js 100.00% <100.00%> (ø)
lib/internal/bootstrap/realm.js 97.06% <100.00%> (+<0.01%) ⬆️
lib/internal/errors.js 98.42% <100.00%> (+<0.01%) ⬆️
src/node_binding.cc 76.78% <ø> (ø)
src/node_binding.h 80.00% <ø> (ø)
src/node_builtins.cc 77.70% <100.00%> (+0.03%) ⬆️
src/node_external_reference.h 100.00% <ø> (ø)
lib/internal/formats/toml.js 52.73% <52.73%> (ø)

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jsumners-nr jsumners-nr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love seeing this move so quickly. Just a bit concerned that the docs attempt to enforce the same API across all formats/ namespaced modules.

Comment thread doc/api/formats.md
Comment on lines +11 to +14
Every format module exports two functions:

* `parse(input[, options])` turns a document into JavaScript values.
* `stringify(value)` turns JavaScript values into a document.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be too restrictive. Each module should strive for such a simple API, but it should also be allowed to export an interface that makes sense for the module.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are not a spec, they only document the existing behavior. If another format is added, the docs will need to be updated anyway. In any case, happy to update if you have a suggestion

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the opening paragraph is sufficient. Lines 11 through 14 can be removed and everything will still make sense.

@jasnell jasnell added the large-pr PRs subject to the large-PR policy. label Dec 1, 2026
Comment thread doc/api/errors.md
An attempt was made to issue Server Name Indication from a TLS server-side
socket, which is only valid from a client.

<a id="ERR_TOML_PARSE"></a>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit... Let's just make sure the err codes with the various formats are consistently named.

Comment thread doc/api/formats.md
* `input` {string|ArrayBuffer|SharedArrayBuffer|TypedArray|DataView} The TOML
document. Binary input must be UTF-8. A leading byte order mark is ignored.
* `options` {Object}
* `bigint` {boolean} If `true`, every integer is returned as a {bigint}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also support a non-throwing parse mode, like the yaml case.


// Basic document.
{
const doc = TOML.parse(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worthwhile using fixtures here to help the tests be more readable

Comment thread src/node_toml.cc
for (const auto& [key, node] : entries) {
Local<String> name;
Local<Value> value;
if (!String::NewFromUtf8(isolate_,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToV8Value?

Comment thread src/node_toml.cc
KeyCollectionMode::kOwnOnly,
static_cast<PropertyFilter>(PropertyFilter::ONLY_ENUMERABLE |
PropertyFilter::SKIP_SYMBOLS),
v8::IndexFilter::kIncludeIndices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using decl at top?

Comment thread src/node_toml.cc
out->push_back(std::move(*node));
}
Leave();
return Just(true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never returns Just(false)?

Would MaybeVoid be better?

Comment thread src/node_toml.cc
return std::make_unique<::toml::value<int64_t>>(integer);
}
if (value->IsArray()) {
auto array = std::make_unique<::toml::array>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if this could accept sequences/sync iterators

Comment thread src/node_toml.cc
Local<Array> info = args[3].As<Array>();
Local<String> message;
if (!String::NewFromUtf8(isolate,
description.data(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToV8Value?

Comment thread src/node_toml.cc

Local<String> result;
if (!String::NewFromUtf8(isolate,
output.data(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToV8Value

case kLocalDate:
return Temporal.PlainDate.from(text);
default:
return Temporal.PlainTime.from(text);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar yet with the primordial captures for Temporal yet... Are these safe captures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

large-pr PRs subject to the large-PR policy. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

5 participants