@@ -70,6 +70,10 @@ If symlink_node_modules is True, this attribute is ignored since
7070the dependency manager will run in the package.json location.
7171""" ,
7272 ),
73+ "environment" : attr .string_dict (
74+ doc = """Environment variables to set before calling the package manager.""" ,
75+ default = {},
76+ ),
7377 "included_files" : attr .string_list (
7478 doc = """List of file extensions to be included in the npm package targets.
7579
@@ -263,11 +267,17 @@ cd "{root}" && "{npm}" {npm_args}
263267 if result .return_code :
264268 fail ("pre_process_package_json.js failed: \n STDOUT:\n %s\n STDERR:\n %s" % (result .stdout , result .stderr ))
265269
270+ env = dict (repository_ctx .attr .environment )
271+ env_key = "BAZEL_NPM_INSTALL"
272+ if env_key not in env .keys ():
273+ env [env_key ] = "1"
274+
266275 repository_ctx .report_progress ("Running npm install on %s" % repository_ctx .attr .package_json )
267276 result = repository_ctx .execute (
268277 [repository_ctx .path ("_npm.cmd" if is_windows_host else "_npm.sh" )],
269278 timeout = repository_ctx .attr .timeout ,
270279 quiet = repository_ctx .attr .quiet ,
280+ environment = env ,
271281 )
272282
273283 if result .return_code :
@@ -303,7 +313,11 @@ See npm CLI docs https://docs.npmjs.com/cli/install.html for complete list of su
303313 allow_single_file = True ,
304314 ),
305315 }),
306- doc = "Runs npm install during workspace setup." ,
316+ doc = """Runs npm install during workspace setup.
317+
318+ This rule will set the environment variable `BAZEL_NPM_INSTALL` to '1' (unless it
319+ set to another value in the environment attribute). Scripts may use to this to
320+ check if yarn is being run by the `npm_install` repository rule.""" ,
307321 implementation = _npm_install_impl ,
308322)
309323
@@ -390,11 +404,17 @@ cd "{root}" && "{yarn}" {yarn_args}
390404 if result .return_code :
391405 fail ("pre_process_package_json.js failed: \n STDOUT:\n %s\n STDERR:\n %s" % (result .stdout , result .stderr ))
392406
407+ env = dict (repository_ctx .attr .environment )
408+ env_key = "BAZEL_YARN_INSTALL"
409+ if env_key not in env .keys ():
410+ env [env_key ] = "1"
411+
393412 repository_ctx .report_progress ("Running yarn install on %s" % repository_ctx .attr .package_json )
394413 result = repository_ctx .execute (
395414 [repository_ctx .path ("_yarn.cmd" if is_windows_host else "_yarn.sh" )],
396415 timeout = repository_ctx .attr .timeout ,
397416 quiet = repository_ctx .attr .quiet ,
417+ environment = env ,
398418 )
399419 if result .return_code :
400420 fail ("yarn_install failed: %s (%s)" % (result .stdout , result .stderr ))
@@ -435,6 +455,10 @@ to yarn so that the local cache is contained within the external repository.
435455 allow_single_file = True ,
436456 ),
437457 }),
438- doc = "Runs yarn install during workspace setup." ,
458+ doc = """Runs yarn install during workspace setup.
459+
460+ This rule will set the environment variable `BAZEL_YARN_INSTALL` to '1' (unless it
461+ set to another value in the environment attribute). Scripts may use to this to
462+ check if yarn is being run by the `yarn_install` repository rule.""" ,
439463 implementation = _yarn_install_impl ,
440464)
0 commit comments