@@ -813,25 +813,43 @@ def _yarn_install_impl(repository_ctx):
813
813
is_windows_host = is_windows_os (repository_ctx )
814
814
node = repository_ctx .path (get_node_label (repository_ctx ))
815
815
yarn = get_yarn_label (repository_ctx )
816
+ result = repository_ctx .execute (
817
+ [repository_ctx .path (yarn ), "--version" ],
818
+ timeout = repository_ctx .attr .timeout ,
819
+ quiet = repository_ctx .attr .quiet ,
820
+ )
821
+ if result .return_code :
822
+ fail ("yarn --version failed: %s (%s)" % (result .stdout , result .stderr ))
823
+ if result .stdout .startswith ("1." ):
824
+ yarn_version = "classic"
825
+ else :
826
+ yarn_version = "berry"
816
827
817
828
yarn_args = []
818
829
819
830
# Set frozen lockfile as default install to install the exact version from the yarn.lock
820
831
# file. To perform an yarn install use the vendord yarn binary with:
821
832
# `bazel run @nodejs//:yarn install` or `bazel run @nodejs//:yarn install -- -D <dep-name>`
822
833
if repository_ctx .attr .frozen_lockfile :
823
- yarn_args .append ("--frozen-lockfile" )
834
+ if yarn_version == "classic" :
835
+ yarn_args .append ("--frozen-lockfile" )
836
+ else :
837
+ fail ("--frozen-lockfile should not be used with yarn 2+. Just pass arguments like --immutable." )
824
838
825
839
if not repository_ctx .attr .use_global_yarn_cache :
826
840
yarn_args .extend (["--cache-folder" , str (repository_ctx .path ("_yarn_cache" ))])
827
- else :
841
+ elif yarn_version == "classic" :
828
842
# Multiple yarn rules cannot run simultaneously using a shared cache.
829
843
# See https://github.com/yarnpkg/yarn/issues/683
830
844
# The --mutex option ensures only one yarn runs at a time, see
831
845
# https://yarnpkg.com/en/docs/cli#toc-concurrency-and-mutex
832
846
# The shared cache is not necessarily hermetic, but we need to cache downloaded
833
847
# artifacts somewhere, so we rely on yarn to be correct.
834
848
yarn_args .extend (["--mutex" , "network" ])
849
+ else :
850
+ # Can't tell from documentation if Yarn Berry has any replacement for the --mutex
851
+ # flag. We'll have to assume it's safe to run concurrently.
852
+ pass
835
853
yarn_args .extend (repository_ctx .attr .args )
836
854
837
855
# Run the package manager in the package.json folder
@@ -936,12 +954,17 @@ yarn_install = repository_rule(
936
954
"args" : attr .string_list (
937
955
doc = """Arguments passed to yarn install.
938
956
939
- See yarn CLI docs https://yarnpkg.com/en/docs/cli/install for complete list of supported arguments.""" ,
957
+ See yarn CLI docs for complete list of supported arguments.
958
+ Yarn 1: https://yarnpkg.com/en/docs/cli/install
959
+ Yarn 2+ (Berry): https://yarnpkg.com/cli/install
960
+ """ ,
940
961
default = [],
941
962
),
942
963
"frozen_lockfile" : attr .bool (
943
964
default = True ,
944
- doc = """Use the `--frozen-lockfile` flag for yarn.
965
+ doc = """Use the `--frozen-lockfile` flag for yarn 1
966
+
967
+ Users of Yarn 2+ (Berry) should just pass `--immutable` to the `args` attribute.
945
968
946
969
Don't generate a `yarn.lock` lockfile and fail if an update is needed.
947
970
@@ -964,9 +987,11 @@ have bugs.
964
987
Disabling this attribute causes every run of yarn to have a unique
965
988
cache_directory.
966
989
967
- If True, this rule will pass `--mutex network` to yarn to ensure that
990
+ If True and using Yarn 1 , this rule will pass `--mutex network` to yarn to ensure that
968
991
the global cache can be shared by parallelized yarn_install rules.
969
992
993
+ The True value has no effect on Yarn 2+ (Berry).
994
+
970
995
If False, this rule will pass `--cache-folder /path/to/external/repository/__yarn_cache`
971
996
to yarn so that the local cache is contained within the external repository.
972
997
""" ,
0 commit comments