Skip to content

Conversation

@ilyichv
Copy link
Contributor

@ilyichv ilyichv commented Jul 10, 2025

Add --format option to workspace.list. It can be set to:

  • pretty (default) - retains the current behavior
  • json - outputs the following format:
{
  "projects": {
    "count": 1,
    "projects": [
      {
        "app": "core",
        "path": "packages/core"
      }
    ]
  },
  "workspace_path": "/Users/user/Workspace/myworkspace"
}

This feature was inspired by Turborepo’s approach, and in my opinion, it can take this library a step further toward being more useful in CI environments.

@pnezis
Copy link
Member

pnezis commented Jul 10, 2025

Thanks @ilyichv, workspace.list already has support for json through the --json flag. If you wish it to be printed instead of saved we can update the --json option to also print it on the console. WDYT?

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

Of course! What do you think of --inline option?

@pnezis
Copy link
Member

pnezis commented Jul 10, 2025

I prefer the --format option of your PR, it matches also the option of workspace.graph. I would say to do the following:

  • Add the --format option with pretty and json, as you have already done, defaults to pretty
  • If format=json is passed we execute the same code as --json currently does (no formatters needed) and print the output of Workspace.Export.to_json (we may need to extend it a bit to keep only the valid packages)
  • We can mark --json as deprecated (to avoid confusion). We can remove the default value from --output and if set, we also save the file. WDYT?

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

Yeah, i'd say also that we can remove --json and in general what concern saving files. Once you have a formatted json you can just
pipe into a file and the magic is done

workspace.list --format json > out.json

@pnezis
Copy link
Member

pnezis commented Jul 10, 2025

Pipe is not guaranteed to yield a valid json file, if something needs to be compiled first it will also include the compilation output.

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

Agreed, i'll proceed as you suggested then!

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

@pnezis Done! I soft-deprecated --json by marking it in the docs and logging a warn when used. I also added a couple of tests that ensure that everything works properly. LMK what do you think :)

Copy link
Member

@pnezis pnezis left a comment

Choose a reason for hiding this comment

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

Looks good @ilyichv, a few nits and we are good to merge.

May I ask how a json output in the console will help your CI pipeline?

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

Looks good @ilyichv, a few nits and we are good to merge.

May I ask how a json output in the console will help your CI pipeline?

We're building a pipeline that leverages on affected packages.
The pipeline was working even with saved file but it looked like a nice improvement. That's the old version

 - name: Detect changes
    id: changes
    run: |
          mix workspace.list --show-status --json --tag scope:app --base "HEAD" --head "HEAD~1"
          echo "workspace.json: $(cat workspace.json)"
          CHANGED_APPS=$(jq -c '[.projects[] | select(.status == "affected" or .status == "modified") | .app]' workspace.json)
          echo "changed-apps=$CHANGED_APPS" >> $GITHUB_OUTPUT

Since we fixed --affected and we'll have the --format this will be more concise.

Besides that I was about to open a discussion in this repo but we may chat on X.
I had something in mind similar to what Turborepo does with prune command, in order to implement that having --format json is essential.

In any case having a convo about that would be great!

@pnezis pnezis merged commit c82a6d1 into sportradar:main Jul 10, 2025
3 checks passed
@pnezis
Copy link
Member

pnezis commented Jul 10, 2025

Thanks for the explanation, makes sense.

Besides that I was about to open a discussion in this repo but we may chat on X. I had something in mind similar to what Turborepo does with prune command, in order to implement that having --format json is essential.

In any case having a convo about that would be great!

Glad to discuss about it (both X or here is fine)

@ilyichv
Copy link
Contributor Author

ilyichv commented Jul 10, 2025

Thanks for the explanation, makes sense.

Besides that I was about to open a discussion in this repo but we may chat on X. I had something in mind similar to what Turborepo does with prune command, in order to implement that having --format json is essential.
In any case having a convo about that would be great!

Glad to discuss about it (both X or here is fine)

I just texted you on X!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants