-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactors the CLI spawn #5600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactors the CLI spawn #5600
Conversation
**What's the problem this PR addresses?** <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> Follow-up to #5600. This PR removes `ignoreCwd` because the option was only a broken workaround that doesn't have a use anymore and even still leads to bugs (try running `yarn --cwd=packages exec pwd` on `master`). **How did you fix it?** <!-- A detailed description of your implementation. --> Removed it as an option but still kept it as an ignored env variable as it's set by the parent process which could be anything (including a Yarn version that still sets it). Tests will come in a future PR. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [X] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [X] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [X] I will check that all automated PR checks pass before the PR gets reviewed.
Note that this breaks create-react-app
https://github.com/yarnpkg/berry/actions/runs/5647321283/job/15297186950#step:5:43 Why aren't we letting Clipanion do the CLI argument parsing so that this still works? |
We are, but when it detects Unfortunately, as I described in #5595 (comment), Imagine How can we know whether the command is supposed to run the We can't, due to the dynamic nature of the CLI. Because of this, we have 2 options:
Unfortunately we can't just go in There's also a third option (that I described in that comment):
It might be enough to fix CRA. |
**What's the problem this PR addresses?** <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> The `--cwd` argument is currently resolved using `realpathSync`. This behavior was introduced in #373 as a workaround for a bug caused by symlinks and the recursive `--cwd` logic. **How did you fix it?** <!-- A detailed description of your implementation. --> Removed the unnecessary `realpath` calls. They are no longer needed due to the removal of the recursive logic in #5600. I've also added a few tests, I'll add the rest from #5595 in a future PR. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [X] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [X] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [X] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Maël Nison <[email protected]>
**What's the problem this PR addresses?** - CRA broke when [we started required that `--cwd` be put before any other argument](#5600 (comment)). CRA is mostly deprecated / unmaintained by now, but it has a decent amount of downloads (more than `create-next-app`), so it doesn't cost us much to special-case a fix for the v4 that we can then drop in v5. - When a machine had a hot cache for package X in both cache versions A and B (each variant having its own checksum), when migrating a project cache version from A to B, Yarn would mistakenly try to validate the variant B using the checksum from variant A. - We already have a mechanism to tolerate checksum changes when going from one cache key to the next, but before #5564 we used to retrieve the cache key from the file name, whereas we now retrieve it from the lockfile instead. A branch of code that relied on the assumption that the cache key could be checked later became invalid, hence the problem. **How did you fix it?** - The `--cwd` flag is now allowed (as a special case) at the end of `yarn add`. - I refactored the "is this locator compatible with the current cache key" function outside of `getLocatorPath`. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
What's the problem this PR addresses?
While working on the new website, I find myself in a situation where I need to access Yarn's
cli
instance (I want to use it to tokenize the examples on the website). This is difficult at the moment, as all parts of the CLI initialization are entangled together.How did you fix it?
I extracted our initialization steps into separate functions, each called in sequence. The one breaking change I made is that
--cwd
is now only accepted as very first argument of the command line (this is needed to get rid of the recursive execution which caused various issues) - if it isn't, Yarn will throw an error explaining the problem.Checklist