-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Do you want to request a feature or report a bug?
It's a feature-request due to a default behavior that leads to unexpected behavior during:
yarn install
What is the current behavior?
On yarn install
the default behavior is that the yarn.lock file is mutated if package.json
and yarn.lock
are out of sync:
yarn init
yarn add moment
npm install --save lodash
The yarn.lock
contains:
moment@^2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
Now if one runs
yarn install
the yarn.lock
will be unexpectedly updated with an unknown future version of a dependency, only defined by the range of the provided semvar potentially breaking the build in the future, esp. if run on a build machine (jenkins):
$ yarn install v0.27.5
warning ../package.json: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.53s.
The yarn.lock
now contains the following on the build machine, yet the version of lodash
is not locked in and prone to change in the future:
lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
moment@^2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
What is the expected behavior?
The one that the frozen-lockfile
provides, as it yields an error. This is quite helpful on build machine, i.e. Jenkins as those builds should fail. It is up to the developer on how to resolve the dependencies.
$ yarn install --frozen-lockfile
yarn install v0.27.5
warning ../package.json: No license field
[1/4] Resolving packages...
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
As @BYK pointed out it would also be already helpful if yarn detects if it is running are in CI mode.
My in detail rationale for the change of the default behavior was posted in the already closed issue making a case for pure-lockfile.
Here's the gist of it:
Only commands like
add
,remove
, andupgrade
should mutate theyarn.lock
.
yarn install
should just do that, namely either install the dependencies in their locked in version or fail if it detects a mismatch between thepackage.json
andyarn.lock
. (The only exception being if there's noyarn.lock
in the first place. Then, and only then, it may create one, yet it never, ever should touch it again.)
NOTE: The highest-rated comment's solution has its own problems: #4570