@@ -26,6 +26,10 @@ load("//internal/common:os_name.bzl", "is_windows_os")
2626load ("//internal/node:node_labels.bzl" , "get_node_label" , "get_npm_label" , "get_yarn_label" )
2727
2828COMMON_ATTRIBUTES = dict (dict (), ** {
29+ "timeout" : attr .int (
30+ default = 3600 ,
31+ doc = """Maximum duration of the package manager execution in seconds.""" ,
32+ ),
2933 "always_hide_bazel_files" : attr .bool (
3034 doc = """Always hide Bazel build files such as `BUILD` and BUILD.bazel` by prefixing them with `_`.
3135
@@ -101,10 +105,6 @@ fine grained npm dependencies.
101105 mandatory = True ,
102106 allow_single_file = True ,
103107 ),
104- "prod_only" : attr .bool (
105- default = False ,
106- doc = "Don't install devDependencies" ,
107- ),
108108 "quiet" : attr .bool (
109109 default = True ,
110110 doc = "If stdout and stderr should be printed to the terminal." ,
@@ -207,10 +207,7 @@ def _npm_install_impl(repository_ctx):
207207 is_windows_host = is_windows_os (repository_ctx )
208208 node = repository_ctx .path (get_node_label (repository_ctx ))
209209 npm = get_npm_label (repository_ctx )
210- npm_args = ["install" ]
211-
212- if repository_ctx .attr .prod_only :
213- npm_args .append ("--production" )
210+ npm_args = ["install" ] + repository_ctx .attr .args
214211
215212 # If symlink_node_modules is true then run the package manager
216213 # in the package.json folder; otherwise, run it in the root of
@@ -294,10 +291,11 @@ cd "{root}" && "{npm}" {npm_args}
294291
295292npm_install = repository_rule (
296293 attrs = dict (COMMON_ATTRIBUTES , ** {
297- "timeout" : attr .int (
298- default = 3600 ,
299- doc = """Maximum duration of the command "npm install" in seconds
300- (default is 3600 seconds).""" ,
294+ "args" : attr .string_list (
295+ doc = """Arguments passed to npm install.
296+
297+ See npm CLI docs https://docs.npmjs.com/cli/install.html for complete list of supported arguments.""" ,
298+ default = [],
301299 ),
302300 "package_lock_json" : attr .label (
303301 mandatory = True ,
@@ -345,15 +343,8 @@ def _yarn_install_impl(repository_ctx):
345343 repository_ctx .path (yarn ),
346344 "--cwd" ,
347345 root ,
348- "--network-timeout" ,
349- str (repository_ctx .attr .network_timeout * 1000 ), # in ms
350346 ]
351347
352- if repository_ctx .attr .frozen_lockfile :
353- args .append ("--frozen-lockfile" )
354-
355- if repository_ctx .attr .prod_only :
356- args .append ("--prod" )
357348 if not repository_ctx .attr .use_global_yarn_cache :
358349 args .extend (["--cache-folder" , repository_ctx .path ("_yarn_cache" )])
359350 else :
@@ -365,6 +356,8 @@ def _yarn_install_impl(repository_ctx):
365356 # artifacts somewhere, so we rely on yarn to be correct.
366357 args .extend (["--mutex" , "network" ])
367358
359+ args .extend (repository_ctx .attr .args )
360+
368361 repository_ctx .report_progress ("Running yarn install on %s" % repository_ctx .attr .package_json )
369362 result = repository_ctx .execute (
370363 args ,
@@ -381,23 +374,11 @@ def _yarn_install_impl(repository_ctx):
381374
382375yarn_install = repository_rule (
383376 attrs = dict (COMMON_ATTRIBUTES , ** {
384- "timeout" : attr .int (
385- default = 3600 ,
386- doc = """Maximum duration of the command "yarn install" in seconds
387- (default is 3600 seconds).""" ,
388- ),
389- "frozen_lockfile" : attr .bool (
390- default = False ,
391- doc = """Passes the --frozen-lockfile flag to prevent updating yarn.lock.
377+ "args" : attr .string_list (
378+ doc = """Arguments passed to yarn install.
392379
393- Note that enabling this option will require that you run yarn outside of Bazel
394- when making changes to package.json.
395- """ ,
396- ),
397- "network_timeout" : attr .int (
398- default = 300 ,
399- doc = """Maximum duration of a network request made by yarn in seconds
400- (default is 300 seconds).""" ,
380+ See yarn CLI docs https://yarnpkg.com/en/docs/cli/install for complete list of supported arguments.""" ,
381+ default = [],
401382 ),
402383 "use_global_yarn_cache" : attr .bool (
403384 default = True ,
@@ -406,8 +387,15 @@ when making changes to package.json.
406387The cache lets you avoid downloading packages multiple times.
407388However, it can introduce non-hermeticity, and the yarn cache can
408389have bugs.
390+
409391Disabling this attribute causes every run of yarn to have a unique
410392cache_directory.
393+
394+ If True, this rule will pass `--mutex network` to yarn to ensure that
395+ the global cache can be shared by parallelized yarn_install rules.
396+
397+ If False, this rule will pass `--cache-folder /path/to/external/repository/__yarn_cache`
398+ to yarn so that the local cache is contained within the external repository.
411399""" ,
412400 ),
413401 "yarn_lock" : attr .label (
0 commit comments