feat(util): add util.formatWithOptions (unblocks debug npm package)#948
Merged
Conversation
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`.
This was referenced May 18, 2026
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).
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.
Summary
util.formatWithOptions(inspectOptions, format[, ...args])to Perry'snode:utilsurface — manifest entry + JS stub that ignores the options bag and delegates toutil.format.debugnpm package (top-1k by downloads, transitive dep of express / socket.io / many others); without this the#463HIR-lower gate bails any compile that pulls indebug(directly or viaperry.compilePackages).%o/%Orendering withcolors,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 fmtclean.cargo build --release -p perry-runtime -p perry-stdlib -p perry-jsruntime -p perrysucceeds../target/release/perry test-files/test_util_format_with_options.ts -o /tmp/tfwo && /tmp/tfworuns without the#463error (output isundefined\nundefined, mirroring the existingutil.formatstub — full%s/%dexpansion is a separate task).import debug from "debug"(withperry.compilePackages: ["debug"]) now compiles past the formatWithOptions gate and links to an executable, where it previously bailed at HIR-lower../scripts/regen_api_docs.shregenerateddocs/api/perry.d.tsanddocs/src/api/reference.md; coverage now reports 867 entries across 71 modules.