-
Notifications
You must be signed in to change notification settings - Fork 385
feat: add util.inspect with full options support #1271
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
base: main
Are you sure you want to change the base?
Conversation
9a0249f to
62505f4
Compare
|
I have a vague memory that console.log is a limited version of inspect but that they share codebase (I might be wrong on that). Could there be some re-use? |
2797aa7 to
3b20c9a
Compare
Yes they do and we should do so here I as well. @chessbyte when I created console initially I build it a bit simplified and "just" appended the string recursively. In order to conform more to Node.js and other runtime we should do a two phase approach instead. So instead of building the string from the get-go in a single pass we can store the console line in an internal representation enum of the actual values. Then we can render them to stdout/stderr using a renderer which actually prints the message. This way we can adjust when to line break depending on how many items that are in the object/array/string etc and format depending on terminal width etc. This is exactly how it's done in Node where printing e deeply nested object on a small window renders different output and "pretty-print" vs doing so on a larger screen. The performance impact of this should be quite small since we're not going to deep anyway and is still appending to a string buffer first before printing. So in summery: @Sytten thoughts? |
|
@richarddavison @Sytten hoping I addressed feedback in 2nd commit |
Implements util.inspect() function with the following features:
- depth: control recursion depth for nested objects (supports null for infinite)
- colors: ANSI color output support
- showHidden: show non-enumerable properties
- customInspect: call Symbol.for('nodejs.util.inspect.custom') methods
- maxArrayLength: limit array/set/map elements displayed
- maxStringLength: truncate long strings
- sorted: sort object keys (boolean or custom comparator function)
- breakLength: line length at which to break to multiple lines
- compact: control inline vs multiline formatting (number or false)
Also exports:
- util.inspect.custom symbol (nodejs.util.inspect.custom)
- util.inspect.defaultOptions object
Fixes awslabs#1257
…pect Refactors the logging library to use a two-phase approach: - Phase 1: Build intermediate representation (PrintIR enum) from JS values - Phase 2: Render IR to formatted string with formatting decisions This enables: - Shared codebase between console.log and util.inspect - Dynamic formatting based on breakLength/compact options - Better separation of concerns for future enhancements New files: - ir.rs: PrintIR enum for intermediate representation - builder.rs: Converts JS values to PrintIR - renderer.rs: Renders PrintIR to formatted strings Also adds util.inspect to API.md documentation.
be6a960 to
82423db
Compare
|
Agreed this is the way to go |
|
@Sytten @richarddavison what is the status of this PR? It has been sitting since my changes on Saturday without any activity. |
|
No offense but we cant just merge 2k lines of vibe code just like that. We work on llrt when we can and we will need to maintain that code for the years to come, this will take a least a couple weeks to get merged. |
|
When I ran the open-source project ManageIQ for a decade and received PRs, I treated them as serendipitous gifts. When I felt they were too complex, I would request that they be chopped into multiple smaller PRs. When I felt that the code may be unstable, I would ask for more tests. When I did not like the code organization, I would suggest something more suitable to the project. That project is still going strong at manageiq.org :-) Your feedback is a bit insulting to someone who is genuinely trying to help move along a project that achieved NONE of its targeted goals for 2025. Perfect is the enemy of good enough! Best of luck with your approach! |
Some things takes a while to get right. We prioritize to get them right then to ship to soon. Most of these features have a lot of edge cases that needs to be handled.
We do highly appreciate all PR and effort to make this project better and add more features. Thanks for the work you have done. However, significant changes like this will take a while to get through. I also see a couple of optimization paths we can do with this. Thanks for contributing and I encourage you to continue to do so! |
@richarddavison I would like nothing more than to add as many tests as there are edge conditions, so that we all feel comfortable about the implemented code.
@richarddavison I have no issue with PRs taking time to merge because you want to get big changes right. Having said that, before this project reaches 1.0 status, I encourage you to iterate quicker and trust your tests to avoid regressions. This particular PR introduces new functionality to address a reported issue of missing functionality. It should not break any existing users of llrt as nothing should be using |
Issue # (if available)
Fixes #1257
Description of changes
Implements util.inspect() function with the following features:
Also exports:
Checklist
tests/unitand/or in Rust for my feature if neededmake fixto format JS and apply Clippy auto fixesmake checktypes/directoryBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.