Skip to content

Commit 765917a

Browse files
authored
refactor: improve the npmrc-exists handling (#2399)
### Changes are visible to end-users: yes Minor tweaks for Windows users, presumably in a positive way Sadly this won't work on bazel 6.5 because it enforces `rctx.path` points to an existing file, and we are using it to check existence. This is fixed in 7.x ### Test plan existing tests
1 parent ddec036 commit 765917a

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

npm/private/npm_translate_lock_state.bzl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ WARNING: `update_pnpm_lock` attribute in `npm_translate_lock(name = "{rctx_name}
5959
if _should_update_pnpm_lock(priv):
6060
_init_importer_labels(priv, label_store)
6161

62-
_init_npmrc(priv, rctx, attr, label_store, is_windows)
62+
_init_npmrc(priv, rctx, attr, label_store)
6363

6464
_copy_common_input_files(priv, rctx, attr, label_store, pnpm_lock_exists)
6565

@@ -216,25 +216,21 @@ def _init_root_package(priv, rctx, attr, label_store):
216216
priv["root_package_json"] = {}
217217

218218
################################################################################
219-
def _init_npmrc(priv, rctx, attr, label_store, is_windows):
219+
def _init_npmrc(priv, rctx, attr, label_store):
220220
if not label_store.has("npmrc"):
221221
# check for a .npmrc next to the pnpm-lock.yaml file
222-
_maybe_npmrc(priv, rctx, attr, label_store, "sibling_npmrc", is_windows)
222+
_maybe_npmrc(priv, rctx, attr, label_store, "sibling_npmrc")
223223

224224
if label_store.has("npmrc"):
225225
_load_npmrc(priv, rctx, label_store.path("npmrc"))
226226

227227
if attr.use_home_npmrc:
228-
_load_home_npmrc(priv, rctx, is_windows)
228+
_load_home_npmrc(priv, rctx)
229229

230230
################################################################################
231-
def _maybe_npmrc(priv, rctx, attr, label_store, key, is_windows):
232-
if is_windows:
233-
# TODO(windows): utils.exists is not yet support on Windows
234-
return
235-
if utils.exists(rctx, label_store.path(key)):
236-
npmrc_label = label_store.label(key)
237-
231+
def _maybe_npmrc(priv, rctx, attr, label_store, key):
232+
npmrc_label = label_store.label(key)
233+
if rctx.path(npmrc_label).exists:
238234
# buildifier: disable=print
239235
print("""
240236
WARNING: Implicitly using .npmrc file `{npmrc}`.
@@ -450,7 +446,7 @@ def _load_npmrc(priv, rctx, npmrc_path):
450446
priv["npm_auth"].update(auth)
451447

452448
################################################################################
453-
def _load_home_npmrc(priv, rctx, is_windows):
449+
def _load_home_npmrc(priv, rctx):
454450
home_directory = repo_utils.get_home_directory(rctx)
455451
if not home_directory:
456452
# buildifier: disable=print
@@ -461,8 +457,7 @@ WARNING: Cannot determine home directory in order to load home `.npmrc` file in
461457

462458
home_npmrc_path = "{}/{}".format(home_directory, NPM_RC_FILENAME)
463459

464-
# TODO(windows): utils.exists is not yet support on Windows
465-
if is_windows or utils.exists(rctx, home_npmrc_path):
460+
if rctx.path(home_npmrc_path).exists:
466461
_load_npmrc(priv, rctx, home_npmrc_path)
467462

468463
################################################################################

0 commit comments

Comments
 (0)