Skip to content

feat(util): add util.formatWithOptions (unblocks debug npm package)#948

Merged
proggeramlug merged 1 commit into
mainfrom
pr-util-format-with-options
May 17, 2026
Merged

feat(util): add util.formatWithOptions (unblocks debug npm package)#948
proggeramlug merged 1 commit into
mainfrom
pr-util-format-with-options

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

  • Adds util.formatWithOptions(inspectOptions, format[, ...args]) to Perry's node:util surface — manifest entry + JS stub that ignores the options bag and delegates to util.format.
  • Required by the debug npm package (top-1k by downloads, transitive dep of express / socket.io / many others); without this the #463 HIR-lower gate bails any compile that pulls in debug (directly or via perry.compilePackages).
  • Real options-passthrough (%o / %O rendering with colors, depth, breakLength, …) is a follow-up; today's stub just lifts the gate so callers compile and exercise their actual code paths.

Test plan

  • cargo fmt clean.
  • cargo build --release -p perry-runtime -p perry-stdlib -p perry-jsruntime -p perry succeeds.
  • New regression test: ./target/release/perry test-files/test_util_format_with_options.ts -o /tmp/tfwo && /tmp/tfwo runs without the #463 error (output is undefined\nundefined, mirroring the existing util.format stub — full %s/%d expansion is a separate task).
  • Debug-package smoke: import debug from "debug" (with perry.compilePackages: ["debug"]) now compiles past the formatWithOptions gate and links to an executable, where it previously bailed at HIR-lower.
  • ./scripts/regen_api_docs.sh regenerated docs/api/perry.d.ts and docs/src/api/reference.md; coverage now reports 867 entries across 71 modules.
  • No conflict markers in Cargo.toml / CLAUDE.md / CHANGELOG.md.

Lifts the #463 unimplemented-API gate for `util.formatWithOptions(options,
format, ...args)`. Required by the `debug` npm package (top-1k by
downloads, transitive dep of express/socket.io/many others).

The JS stub ignores the inspect-options bag and delegates to the existing
`util.format` — full options-passthrough is a follow-up. Regenerated
`docs/api/perry.d.ts` + `docs/src/api/reference.md` so the api-docs-drift
check stays green. Regression test:
`test-files/test_util_format_with_options.ts`.
@proggeramlug proggeramlug merged commit b384b94 into main May 17, 2026
8 of 9 checks passed
@proggeramlug proggeramlug deleted the pr-util-format-with-options branch May 17, 2026 19:34
proggeramlug added a commit that referenced this pull request May 18, 2026
…ions (#1011)

The manifest entries for `util.format` and `util.formatWithOptions` lifted
the #463 gate but no native runtime was wired up. Both calls fell through
the receiver-less native-method-call early-out in `lower_call/native.rs`
and returned `TAG_UNDEFINED` — `console.log(util.format("hi %s", "x"))`
printed `undefined`, and `test_util_format_with_options` had been the
parity gate's lone NEW failure since #948 added the manifest entry.

Three small pieces:

- runtime/builtins.rs: new `js_util_format(arr_ptr)` walks a heap array
  whose element 0 is the format string and 1.. are substitution values.
  Handles `%s` / `%d` / `%i` / `%f` / `%j` / `%o` / `%O` / `%%` and
  appends any trailing args space-separated — same shape as Node's
  `util.format`.
- codegen/runtime_decls.rs: declare the extern.
- codegen/lower_call/native.rs: ahead of the receiver-less fall-through,
  recognize `util.format` / `util.formatWithOptions`, bundle the args
  into a heap array (mirrors `js_console_log_spread`), and dispatch.
  `formatWithOptions` drops `args[0]` (the inspect-options bag) and
  delegates to the same runtime — full options-passthrough (real
  `%o`/`%O` styling with colors/depth/breakLength) is a follow-up.

Validation:

- `node test-files/test_util_format_with_options.ts` and the perry
  binary now produce the same output (`Hello world` + `x=k y=7`).
- `scripts/run_native_no_fallback_tests.sh` — 35 passed, 0 failed (no
  regression on the broader smoke).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant