[Bug] workspaces list result is not json
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
run yarn workspaces list -v --json
in a workspace, but the received output is not a valid JSON string
To Reproduce
const {promises: {writeFile, mkdir}} = require(`fs`);
await mkdir('packages');
await mkdir('packages/a');
await writeFile('packages/a/package.json', JSON.stringify({
name: 'a',
}));
await mkdir('packages/b');
await writeFile('packages/b/package.json', JSON.stringify({
name: 'b'
}));
await packageJsonAndInstall({
workspaces: {
packages: [
"packages/*"
]
},
});
const output = await yarn(`workspaces`, `list`, `-v`, `--json`);
expect(output).not.toContain(`yarn`);
expect(output).toContain(`yarn`);
expect(() => JSON.parse(output)).not.toThrow();
Output:
Error: [2mexpect([22m[31mreceived[39m[2m).[22mtoContain[2m([22m[32mexpected[39m[2m) // indexOf[22m
Expected substring: [32m"yarn"[39m
Received string: [31m"{\"location\":\".\",\"name\":null,\"workspaceDependencies\":[],\"mismatchedWorkspaceDependencies\":[]}[39m
[31m{\"location\":\"packages/a\",\"name\":\"a\",\"workspaceDependencies\":[],\"mismatchedWorkspaceDependencies\":[]}[39m
[31m{\"location\":\"packages/b\",\"name\":\"b\",\"workspaceDependencies\":[],\"mismatchedWorkspaceDependencies\":[]}[39m
[31m"[39m
at module.exports (evalmachine.<anonymous>:31:16)
at process._tickCallback (internal/process/next_tick.js:68:7)
Screenshots
Environment if relevant (please complete the following information):
- OS: OSX
- Node version 12
- Yarn version 2.4.0
Additional context
yarn 1 outputs a object text:
{
"a": {
location: "packages/a",
workspaceDependencies: [],
mismatchedWorkspaceDependencies: []
},
"b": {
location: "packages/b",
workspaceDependencies: [],
mismatchedWorkspaceDependencies: []
}
}
IMO, yarn workspaces list -v --json
should output either
- the same structure when it does in yarn 1
or 2. a valid JSON string, which can be safely
JSON.parse(output)
at least, even structure diff from yarn 1
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
My vscode workspace does not load properly: currently ...
I ran touch /workspaces/GITHUB_USERID/.devcontainer.json where GITHUB_USERID was my own ... However it says "No such file or directory".
Read more >describe-workspaces — AWS CLI 1.27.37 Command Reference
Describes the specified WorkSpaces. You can filter the results by using the bundle identifier, directory identifier, or owner, but you can specify only...
Read more >Angular workspace configuration
The angular.json file at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults.
Read more >package.json - npm Docs
It must be actual JSON, not just a JavaScript object literal. ... instead of an object. If a url is provided, it will...
Read more >Manage workspaces in portal or Python SDK (v2) - Azure ...
Learn how to manage Azure Machine Learning workspaces in the Azure portal or ... From parameters: There's no need to have a config.json...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the reply.
For those who run into this issue, try the following util function:
The Project class has all the information about the workspaces, to list workspaces you can look at the code for the
workspaces list
command https://github.com/yarnpkg/berry/blob/9f8256807f406229333a6f45294ac2d5ca0a941c/packages/plugin-essentials/sources/commands/workspaces/list.ts#L24If you need help consuming the API I suggest joining the discord channel and asking there