yarnpkg / berry

šŸ“¦šŸˆ Active development trunk for Yarn āš’
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: yarn info --manifest fails when using link protocol #4238

Open digilist opened 2 years ago

digilist commented 2 years ago

Self-service

Describe the bug

When using yarn info --manifest on a project that uses the link: protocol that doesn't define a package.json in the linked folder, it fails with the following error:

Internal Error: Manifest not found
    at Function.find (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:394:32388)
    at async /home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:501:3767
    at async dm.execute (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:501:5001)
    at async dm.validateAndExecute (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:349:673)
    at async Is.run (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:363:2087)
    at async Is.runExit (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:363:2271)
    at async i (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:448:12669)
    at async r (/home/markus/Projects/urbyo/yarn-link-manifest-error/.yarn/releases/yarn-3.2.0.cjs:448:10887)

The reason is that the linked directory doesn't have a package json. But when I understand the Yarn documentation correctly, this shouldn't be necessary:

Because such destination folders typically don't contain package.json, the link: protocol doesn't even try to read them. It can cause problems when you want to link an identifier to a different package on the disk (similar to what yarn link does) because then the transitive dependencies aren't resolved.

https://yarnpkg.com/features/protocols#whats-the-difference-between-link-and-portal

To reproduce

I've created a repository with a minimal amount of code to reproduce this issue: https://github.com/digilist/yarn-link-manifest-error

  1. Clone the repository
  2. Run yarn info --manifest
  3. See the errror that was reported above.

In a nutshell, a package.json like this is necessary and results in the error, when the src directory doesn't contain a package.json:

{
  "name": "@acme/monorepo",
  "private": true,
  "version": "0.1.0",
  "dependencies": {
    "src": "link:./src"
  },
  "packageManager": "yarn@3.2.0"
}

Or with Sherlock:

Yarn Playground

const fs = require('fs');
fs.mkdirSync('src');

await packageJsonAndInstall({
  "name": "@acme/monorepo",
  "private": true,
  "version": "0.1.0",
  "dependencies": {
    "src": "link:./src"
  },
});

await expect((async () => {
  const output = await yarn(`info`, `--manifest`);
})()).resolves.not.toThrow();

Environment

System:
    OS: Linux 5.16 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
  Binaries:
    Node: 17.7.1 - /tmp/xfs-411d1ede/node
    Yarn: 3.2.0 - /tmp/xfs-411d1ede/yarn
    npm: 8.5.4 - /usr/bin/npm

Additional context

Creating an empty package.json solves the problem.

yarnbot commented 2 years ago

Hi! šŸ‘‹

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! šŸ˜ƒ

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! šŸŒŸ

yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).resolves.not.toThrow()

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

Internal Error: Manifest not found
    at Function.find (/github/workspace/packages/yarnpkg-core/sources/Manifest.ts:115:13)
    at /github/workspace/packages/plugin-essentials/sources/commands/info.ts:242:22
    at InfoCommand.execute (/github/workspace/packages/plugin-essentials/sources/commands/info.ts:340:11)
    at InfoCommand.validateAndExecute (/github/workspace/.yarn/__virtual__/clipanion-virtual-9b3ecfaf21/0/cache/clipanion-npm-3.2.0-rc.10-b702c05bd9-d3b6454c9e.zip/node_modules/clipanion/lib/advanced/Command.js:67:26)
    at Cli.run (/github/workspace/.yarn/__virtual__/clipanion-virtual-9b3ecfaf21/0/cache/clipanion-npm-3.2.0-rc.10-b702c05bd9-d3b6454c9e.zip/node_modules/clipanion/lib/advanced/Cli.js:222:24)
    at Cli.runExit (/github/workspace/.yarn/__virtual__/clipanion-virtual-9b3ecfaf21/0/cache/clipanion-npm-3.2.0-rc.10-b702c05bd9-d3b6454c9e.zip/node_modules/clipanion/lib/advanced/Cli.js:231:28)
    at exec (/github/workspace/packages/yarnpkg-cli/sources/main.ts:159:7)
    at run (/github/workspace/packages/yarnpkg-cli/sources/main.ts:48:7)
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-44ff9ab1e7.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:14:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.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-4061026d74.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-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)