yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: Listing workspaces produces names that don't work for workspace commands #3505

Open stof opened 3 years ago

stof commented 3 years ago

Self-service

Describe the bug

It looks like yarn workspaces list is listing the location of workspaces rather than their names, which is quite confusing as yarn workspace expects a name and not a location.

To reproduce

await packageJson({
    name: "@repro/sub"
}, { cwd: "packages/sub/"});

await packageJson({
    name: "root",
    private: true,
    workspaces: ["packages/*"]
});

const workspaceListing = await yarn('workspaces', 'list');
const displayedName = /YN0000: ([^\n]{2,})/.exec(workspaceListing)[1];

await expect(yarn('workspace', displayedName, 'info')).resolves.toBeTruthy();

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  Binaries:
    Node: 14.17.6 - /tmp/xfs-5138fbd6/node
    Yarn: 3.0.0-git.20210727.hash-3cbbb672 - /tmp/xfs-5138fbd6/yarn
    npm: 7.22.0 - ~/.local/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3

Additional context

No response

yarnbot commented 3 years ago

This issue reproduces on master:

Error: expect(received).resolves.toBeTruthy()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js workspace packages/sub info

Usage Error: Workspace 'packages/sub' not found. Did you mean any of the following:
  - @repro/sub
  - root?

$ yarn workspace <workspaceName> <commandName> ...
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0c0da74930.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:15:7)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
castastrophe commented 2 years ago

Perhaps a flag on yarn workspaces list to print package names rather than pathing? If you combine -v and --json you can parse for the package name with jq (yarn workspaces list -v --json | jq '.name'), but a more straightforward flag might be beneficial.

yarn workspaces list --name