Open ThePlenkov opened 1 year ago
I'm getting a different output for workspaces. First it prints the workspace name as expected and then it adds json output.
$ npm pkg get name --workspace=<workspace>
"<workspace-name>"
{
"<workspace-name>": "<workspace-name>"
}
Maybe that is related to https://github.com/npm/cli/issues/5508#issuecomment-1326181655
npm: 9.3.1 Node.js: 19.4.0
what about with npm 9.5?
what about with npm 9.5?
I get the same output like https://github.com/npm/cli/issues/5481#issuecomment-1442042779
npm: 9.5.1 Node.js: 19.4.0
The possible bug here is that npm
treats being inside a workspace directory the same as using the --workspace
flag.
Currently npm pkg get
always returns json for workspaces. This is how the command has always worked (outside of some other bugs) so changing that would be a breaking change. For example:
# from root
❯ npm pkg get name
"npm"
❯ npm pkg get name -w mock-registry
{
"@npmcli/mock-registry": "@npmcli/mock-registry"
}
# change to workspace directory
❯ cd mock-registry
❯ npm pkg get name
{
"@npmcli/mock-registry": "@npmcli/mock-registry"
}
I think that second example should return "@npmcli/mock-registry"
the same way running it from the root returns "npm"
. This would require npm to differentiate between the workspace flag and the directory being a workspace.
To my opinion --json option is not consistent across all npm commands. There are so many commands which return not parseable output even using this flag. So the semantics should be very straightforward. If it's --json - always return parseable json, otherwise output formatted response. There should not be difference to my opinion we run npm command for root or workspace - result should be also consistent respecting --json flag too
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
I have a project with packages defined as workspaces
If i run the following command in the root folder - it works as expected
if i run same command for workspace - it always responds with json:
Using --json=false doesn't help. So it looks like somewhere --json is used internally
Expected Behavior
This command should work identically for all packages respecting --json parameter
Steps To Reproduce
npm pkg get name
in the root foldernpm pkg get name
in the workspace folderOutput format is different
Environment