Skip to content
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

cleanup(js): factor code-frames in nx #14585

Merged
merged 1 commit into from
Feb 5, 2023
Merged

cleanup(js): factor code-frames in nx #14585

merged 1 commit into from
Feb 5, 2023

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Jan 24, 2023

I recently sent a PR to display nicely formatted JSON errors (#14293) and then realize that there was something similar for JS in the js package - code-frames.

This PR factor the code-frames code in nx so that it is used in both cases (formatting JSON and JS errors).

This PR also clean up unused code in packages/js/src/utils/code-frames/identifiers.ts. It is very unlikely that someone else use the removed code. To make sure I run a query on github an the only usages were from inside nx.

The only difference between formatting a JS error vs a JSON error is that codeFrameColumns use to highlight the JS code passed to it. I have changed that so that the highlighted code is now passed in the options. That is used for JS but not for JSON - we don't highlight JSON code.

The colored test snapshots are not very readable but I made sure all of them are correct in bash:

$ echo  "InvalidCommentToken in JSON at 2:7
      ^[[0m ^[[90m 1 | ^[[39m{^[[0m
      ^[[0m^[[31m^[[1m>^[[22m^[[39m^[[90m 2 | ^[[39m      //\\"test\\": 123,^[[0m
      ^[[0m ^[[90m   | ^[[39m      ^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[31m^[[1m^^[[22m^[[39m^[[0m
      ^[[0m ^[[90m 3 | ^[[39m      \\"nested\\": {^[[0m
      ^[[0m ^[[90m 4 | ^[[39m          \\"test\\": 123^[[0m
      ^[[0m ^[[90m 5 | ^[[39m          /*^[[0m
      "
InvalidCommentToken in JSON at 2:7
        1 | {
      > 2 |       //\test\: 123,
          |       ^^^^^^^^^^^^^^
        3 |       \nested\: {
        4 |           \test\: 123
        5 |           /*     

@vercel
Copy link

vercel bot commented Jan 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 3, 2023 at 5:17PM (UTC)

Copy link
Contributor

@meeroslav meeroslav left a comment

Choose a reason for hiding this comment

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

Left one comment regarding the highlight function, but it's not a show stopper.

packages/nx/src/utils/code-frames.ts Outdated Show resolved Hide resolved
@jaysoo
Copy link
Member

jaysoo commented Feb 3, 2023

Are there any concerns for terminals that don't display colors? Maybe some CI systems?

For local development this makes sense, just want to check if we thought about fallbacks.

Thanks for the PR!

@vicb
Copy link
Contributor Author

vicb commented Feb 3, 2023

@meeroslav great suggestion. I'll update the PR soonish.

@jaysoo my understanding is that chalk handles that. Also this PR does not add colors but only re-use the existing JS error display for JSON.

Thanks to both of you for the feedback

@vicb
Copy link
Contributor Author

vicb commented Feb 3, 2023

I have rebased/updated the PR. Should be ready to go in if the CI is green.

@jaysoo
Copy link
Member

jaysoo commented Feb 5, 2023

Thanks. Let's merge it.

@jaysoo jaysoo merged commit 4f1387d into nrwl:master Feb 5, 2023
@vicb
Copy link
Contributor Author

vicb commented Feb 5, 2023

Thanks!

@vicb vicb deleted the codeFrames branch February 5, 2023 19:26
@github-actions
Copy link

github-actions bot commented Mar 3, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants