From d87d286def1018aba79e69b43b950d6e9d3b5741 Mon Sep 17 00:00:00 2001 From: thomasdraebing Date: Wed, 22 Oct 2025 08:29:53 +0200 Subject: [PATCH] Fix fetching npm packages from git repositories Aspect_rules_js supports fetching a git repository containing an npm package. However, to follow that path, it is required that the URL of the repository is prefixed with `git+`. However, this URL is then also configured as the remote for the git repository. The `git+` prefix is not supported by git and thus fetching fails with: git: 'remote-git+https' ist kein Git-Befehl. Siehe 'git --help'. To prevent this, the `git+`-prefix is now being removed, if it is present before setting it as remote url. --- npm/private/npm_import.bzl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/npm/private/npm_import.bzl b/npm/private/npm_import.bzl index 4ae293c58..82745c7ee 100644 --- a/npm/private/npm_import.bzl +++ b/npm/private/npm_import.bzl @@ -487,6 +487,10 @@ def _fetch_git_repository(rctx): if not rctx.attr.commit: fail("commit required if url is a git repository") + remote_url = str(rctx.attr.url) + if remote_url.startswith("git+"): + remote_url = remote_url[4:] + # Adapted from git_repo helper function used by git_repository in @bazel_tools//tools/build_defs/repo:git_worker.bzl: # https://github.com/bazelbuild/bazel/blob/5bdd2b2ff8d6be4ecbffe82d975983129d459782/tools/build_defs/repo/git_worker.bzl#L34 git_repo = struct( @@ -494,11 +498,11 @@ def _fetch_git_repository(rctx): shallow = "--depth=1", reset_ref = rctx.attr.commit, fetch_ref = rctx.attr.commit, - remote = str(rctx.attr.url), + remote = remote_url, ) rctx.report_progress("Cloning %s of %s" % (git_repo.reset_ref, git_repo.remote)) _git_init(rctx, git_repo) - _git_add_origin(rctx, git_repo, rctx.attr.url) + _git_add_origin(rctx, git_repo, remote_url) _git_fetch(rctx, git_repo) _git_reset(rctx, git_repo) _git_clean(rctx, git_repo)