@@ -33,7 +33,7 @@ WARNING: `update_pnpm_lock` attribute in `npm_translate_lock(name = "{rctx_name}
3333
3434 _init_external_repository_action_cache (priv , attr )
3535
36- _init_common_labels (priv , rctx , attr , label_store , is_windows )
36+ _init_common_labels (priv , attr , label_store )
3737
3838 _init_patches_labels (priv , rctx , attr , label_store )
3939
@@ -49,9 +49,10 @@ WARNING: `update_pnpm_lock` attribute in `npm_translate_lock(name = "{rctx_name}
4949
5050 # parse the pnpm lock file incase since we need the importers list for additional init
5151 # TODO(windows): utils.exists is not yet support on Windows
52- pnpm_lock_exists = is_windows or utils .exists (rctx , label_store .path ("pnpm_lock" ))
52+ pnpm_lock_path = label_store .path ("pnpm_lock" )
53+ pnpm_lock_exists = is_windows or utils .exists (rctx , pnpm_lock_path )
5354 if pnpm_lock_exists :
54- _load_lockfile (priv , rctx , label_store )
55+ _load_lockfile (priv , rctx , attr , pnpm_lock_path , is_windows )
5556 _init_patched_dependencies_labels (priv , rctx , attr , label_store )
5657
5758 # May depend on lockfile state
@@ -60,7 +61,7 @@ WARNING: `update_pnpm_lock` attribute in `npm_translate_lock(name = "{rctx_name}
6061 if _should_update_pnpm_lock (priv ):
6162 _init_importer_labels (priv , label_store )
6263
63- _init_npmrc (priv , rctx , attr , label_store )
64+ _init_npmrc (priv , rctx , attr , label_store , is_windows )
6465
6566 _copy_common_input_files (priv , rctx , attr , label_store , pnpm_lock_exists )
6667
@@ -78,7 +79,7 @@ def _validate_attrs(attr, is_windows):
7879 fail ("only one of npm_package_lock or yarn_lock may be set" )
7980
8081################################################################################
81- def _init_common_labels (priv , rctx , attr , label_store , is_windows ):
82+ def _init_common_labels (priv , attr , label_store ):
8283 # data files
8384 # only initialize if update_pnpm_lock is set since data files are unused otherwise
8485 if _should_update_pnpm_lock (priv ):
@@ -114,9 +115,6 @@ def _init_common_labels(priv, rctx, attr, label_store, is_windows):
114115 # pnpm-workspace.yaml file
115116 label_store .add_sibling ("lock" , "pnpm_workspace" , PNPM_WORKSPACE_FILENAME )
116117
117- # yq is used for parsing the pnpm lock file
118- label_store .add ("host_yq" , Label ("@{}_{}//:yq{}" .format (attr .yq_toolchain_prefix , repo_utils .platform (rctx ), ".exe" if is_windows else "" )))
119-
120118################################################################################
121119def _init_pnpm_labels (priv , rctx , attr , label_store ):
122120 # Note that we must reference the node binary under the platform-specific node
@@ -225,20 +223,19 @@ def _init_root_package(priv, rctx, attr, label_store):
225223 priv ["root_package_json" ] = {}
226224
227225################################################################################
228- def _init_npmrc (priv , rctx , attr , label_store ):
226+ def _init_npmrc (priv , rctx , attr , label_store , is_windows ):
229227 if not label_store .has ("npmrc" ):
230228 # check for a .npmrc next to the pnpm-lock.yaml file
231- _maybe_npmrc (priv , rctx , attr , label_store , "sibling_npmrc" )
229+ _maybe_npmrc (priv , rctx , attr , label_store , "sibling_npmrc" , is_windows )
232230
233231 if label_store .has ("npmrc" ):
234232 _load_npmrc (priv , rctx , label_store .path ("npmrc" ))
235233
236234 if attr .use_home_npmrc :
237- _load_home_npmrc (priv , rctx )
235+ _load_home_npmrc (priv , rctx , is_windows )
238236
239237################################################################################
240- def _maybe_npmrc (priv , rctx , attr , label_store , key ):
241- is_windows = repo_utils .is_windows (rctx )
238+ def _maybe_npmrc (priv , rctx , attr , label_store , key , is_windows ):
242239 if is_windows :
243240 # TODO(windows): utils.exists is not yet support on Windows
244241 return
@@ -460,7 +457,7 @@ def _load_npmrc(priv, rctx, npmrc_path):
460457 priv ["npm_auth" ].update (auth )
461458
462459################################################################################
463- def _load_home_npmrc (priv , rctx ):
460+ def _load_home_npmrc (priv , rctx , is_windows ):
464461 home_directory = repo_utils .get_home_directory (rctx )
465462 if not home_directory :
466463 # buildifier: disable=print
@@ -472,21 +469,21 @@ WARNING: Cannot determine home directory in order to load home `.npmrc` file in
472469 home_npmrc_path = "{}/{}" .format (home_directory , NPM_RC_FILENAME )
473470
474471 # TODO(windows): utils.exists is not yet support on Windows
475- is_windows = repo_utils .is_windows (rctx )
476472 if is_windows or utils .exists (rctx , home_npmrc_path ):
477473 _load_npmrc (priv , rctx , home_npmrc_path )
478474
479475################################################################################
480- def _load_lockfile (priv , rctx , label_store ):
476+ def _load_lockfile (priv , rctx , attr , pnpm_lock_path , is_windows ):
481477 importers = {}
482478 packages = {}
483479 patched_dependencies = {}
484480 lock_version = None
485481 lock_parse_err = None
486482
483+ host_yq = Label ("@{}_{}//:yq{}" .format (attr .yq_toolchain_prefix , repo_utils .platform (rctx ), ".exe" if is_windows else "" ))
487484 yq_args = [
488- str (label_store .path (" host_yq" )),
489- str (label_store . path ( "pnpm_lock" ) ),
485+ str (rctx .path (host_yq )),
486+ str (pnpm_lock_path ),
490487 "-o=json" ,
491488 ]
492489 result = rctx .execute (yq_args )
0 commit comments