Skip to content

fix: fail when yarn.lock is updated in workspaces when --frozen-lockfile is used#6554

Open
robin-drexler wants to merge 1 commit intoyarnpkg:masterfrom
robin-drexler:fix-frozen-workspace
Open

fix: fail when yarn.lock is updated in workspaces when --frozen-lockfile is used#6554
robin-drexler wants to merge 1 commit intoyarnpkg:masterfrom
robin-drexler:fix-frozen-workspace

Conversation

@robin-drexler
Copy link
Copy Markdown

@robin-drexler robin-drexler commented Oct 18, 2018

Summary
This PR is an attempt to fix that yarn does not fail when yarn.lock is updated in a workspace project although --frozen-lockfile is used

The current PR version is meant as a starting point as I might have missed something.

The issue seems to be caused because the patterns passed to the integrityChecker only include the root's dependencies. So it never checks if dependencies of workspaces are missing in the lockfile.

I wonder if always setting includeWorkspaceDeps to true in the installation cli command is the right thing to do, especially since those patterns are referred to as topLevelPatterns at a later point, which might indicate that the workspaces dependencies are missing on purpose.

Another idea I had (and that I tried before I found the flag), was to pass all patterns to the integrityChecker, but otherwise leave them as is.

Basically to add:

const dependencies = Array.from(
  this.resolver.getAllDependencyNamesByLevelOrder(patterns)
);

const allPatterns = dependencies.reduce((allPatterns, dependency) => {
  const allInfo = this.resolver.getAllInfoForPackageName(dependency);
  allInfo.forEach(({ _reference: { patterns } }) => {
    for (const pattern of patterns) {
      allPatterns.add(pattern);
    }
  });
  return allPatterns;
}, new Set());

before: https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L457 and use allPatterns in place of patterns as argument.

If anybody could point me in the right direction, I'd be happy to continue working on a fix.

Thanks a lot in advance! :)

@robin-drexler
Copy link
Copy Markdown
Author

Hey, is there anything that I can do to push things forward? :)

@kachkaev
Copy link
Copy Markdown

kachkaev commented Feb 22, 2019

ping folks 👋 🙏

The current behaviour of the --frozen-lockfile argument does match what the docs are saying. Because of that, CI pipelines for PRs succeed even if somebody updated package.json, but did not update yarn.lock. Inconsistent sets of packages land the master branch and cause a lot of confusion down the line.

@nevir
Copy link
Copy Markdown

nevir commented Mar 21, 2019

Same question here: what can we do to help get this in?

@kachkaev
Copy link
Copy Markdown

kachkaev commented Mar 21, 2019

Some workarounds for CI can be found in #5840

@arcanis
Copy link
Copy Markdown
Member

arcanis commented Sep 18, 2019

Hey, sorry for now pinging back sooner.

The change appears sound, but we're currently working on the v2 (scheduled before the end of the year) and I'm somewhat worried about introducing subtle bugs right before releasing the next major (the way I see it, the current v1 is, despite its shortcomings, relatively stable).

One question in particular I'd need to see answered is why isn't includeWorkspaceDeps always on by default? What does it imply to enable it for every install? I don't remember why it got implemented. Maybe @jgoz would remember (#4654)?

@jgoz
Copy link
Copy Markdown
Contributor

jgoz commented Sep 18, 2019

I think I remember why it got implemented in the first place. It’s because running certain commands inside a child workspace needed to consider dependencies across the entire workspace (outdated, upgrade-interactive), mainly because it made more sense from the user’s perspective (maybe? It’s been a long time since I looked at this).

I haven’t fully considered this current change but a safer approach might be to only enable includeWorkspaceDeps when —frozen-lockfile is specified, rather than always enabling it.

I should also note that we long ago switched to using —pure-lockfile in our CI because after reading the docs more carefully, it was the flag we actually wanted.

cowboyd added a commit to thefrontside/bigtest that referenced this pull request Sep 3, 2020
It looks like the yarn.lock file had gotten out of sync with
dependencies, so I updated it.

It looks like the `--frozen-lockfile` option, which is specifically
designed to prevent this [does not actually work with workspaces][1]
and so this may happen from time to time. If we can figure out a
cross-platform workaround, then maybe we can apply that at some
point. Otherwise, this will remain a bug until we take a shot at yarn
v2

[1]: yarnpkg/yarn#6554
wincent added a commit to liferay/liferay-frontend-projects that referenced this pull request Nov 16, 2020
This should ensure that we don't run into the kind of issue mentioned
here:

    #233 (comment)

Note that `--frozen-lockfile` is supposed to take care of this for us,
but it is a known issue that it doesn't work properly in monorepos:

    yarnpkg/yarn#5840

There is a fix for it:

    yarnpkg/yarn#6554

But the issue is nearly two years old and the PR is almost as old. Maintainer replies here:

    yarnpkg/yarn#6554 (comment)

that:

> The change appears sound, but we're currently working on the v2
> (scheduled before the end of the year) and I'm somewhat worried about
> introducing subtle bugs right before releasing the next major (the
> way I see it, the current v1 is, despite its shortcomings, relatively
> stable)."

We face a similar concern in liferay-portal and have a ticket for that:

    https://issues.liferay.com/browse/LPS-110313
wincent added a commit to liferay/liferay-frontend-projects that referenced this pull request Nov 16, 2020
This should ensure that we don't run into the kind of issue mentioned
here:

    #233 (comment)

Note that `--frozen-lockfile` is supposed to take care of this for us,
but it is a known issue that it doesn't work properly in monorepos:

    yarnpkg/yarn#5840

There is a fix for it:

    yarnpkg/yarn#6554

But the issue is nearly two years old and the PR is almost as old. Maintainer replies here:

    yarnpkg/yarn#6554 (comment)

that:

> The change appears sound, but we're currently working on the v2
> (scheduled before the end of the year) and I'm somewhat worried about
> introducing subtle bugs right before releasing the next major (the
> way I see it, the current v1 is, despite its shortcomings, relatively
> stable)."

We face a similar concern in liferay-portal and have a ticket for that:

    https://issues.liferay.com/browse/LPS-110313
@robin-drexler
Copy link
Copy Markdown
Author

robin-drexler commented Mar 26, 2021

👋 I know, it's been a while, but is there any chance that this PR could be merged since it got an approval? :)

Thanks a lot!

@NMinhNguyen
Copy link
Copy Markdown

NMinhNguyen commented Mar 26, 2021

👋 I know, it's been a while, but is there any chance that this PR could be merged since it got an approval? :)

I don't think the approval was from a core maintainer 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

yarn install --frozen-lockfile is not failing as expected

7 participants