Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .aspect/workflows/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ workspaces:
e2e/git_dep_metadata:
icon: npm
tasks: *e2e_tasks
e2e/git_dep_no_tar:
icon: npm
tasks: *e2e_tasks
e2e/gyp_no_install_script:
icon: npm
tasks: *e2e_tasks
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
a=(
.
e2e/bzlmod
e2e/git_dep_no_tar
e2e/gyp_no_install_script
e2e/js_image_docker
e2e/js_image_oci
Expand Down
1 change: 1 addition & 0 deletions e2e/git_dep_no_tar/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions e2e/git_dep_no_tar/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import %workspace%/../../tools/preset.bazelrc

1 change: 1 addition & 0 deletions e2e/git_dep_no_tar/.bazelversion
4 changes: 4 additions & 0 deletions e2e/git_dep_no_tar/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
hoist=false
17 changes: 17 additions & 0 deletions e2e/git_dep_no_tar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

npm_link_all_packages(name = "node_modules")

# Test that a package imported directly from a git repository has its
# .git folder removed.
sh_test(
name = "no_git_tar_test",
srcs = ["no_git_tar_test.sh"],
args = [
"$(rootpaths //:node_modules/highlightjs-ttcn3)",
],
data = [
":node_modules/highlightjs-ttcn3",
],
)
21 changes: 21 additions & 0 deletions e2e/git_dep_no_tar/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bazel_dep(name = "aspect_rules_js", version = "0.0.0", dev_dependency = True)
local_path_override(
module_name = "aspect_rules_js",
path = "../..",
)

bazel_dep(name = "rules_shell", version = "0.6.1", dev_dependency = True)

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
dev_dependency = True,
)
npm.npm_translate_lock(
name = "npm",
data = ["//:package.json"],
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")
2 changes: 2 additions & 0 deletions e2e/git_dep_no_tar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This e2e tests checks whether the import of a dependent git repository works,
if the git server does not provide a tar-archive of the repository.
47 changes: 47 additions & 0 deletions e2e/git_dep_no_tar/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "aspect_rules_js",
path = "../..",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

http_archive(
name = "rules_shell",
sha256 = "e6b87c89bd0b27039e3af2c5da01147452f240f75d505f5b6880874f31036307",
strip_prefix = "rules_shell-0.6.1",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.6.1/rules_shell-v0.6.1.tar.gz",
)

load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
lifecycle_hooks_envs = {
"*": [
"aspect_test_id=testc",
"BUILD_VERSION=1",
],
# Without APPDATA environment variable, sharp install will fail because of the binary can not
# be copied to ~/.npm folder which is readonly for bazel.
"sharp": ["APPDATA=."],
},
lifecycle_hooks_execution_requirements = {
"sharp": ["requires-network"],
},
npm_package_target_name = "{dirname}_pkg",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
2 changes: 2 additions & 0 deletions e2e/git_dep_no_tar/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The presence of this file causes WORKSPACE to be ignored when bzlmod is enabled.
# See https://docs.google.com/document/d/1JtXIVnXyFZ4bmbiBCr5gsTH4-opZAFf5DMMb-54kES0/edit#heading=h.y054fjub9max
9 changes: 9 additions & 0 deletions e2e/git_dep_no_tar/no_git_tar_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

PACKAGE_DIR1="$1"

if [ ! -f "$PACKAGE_DIR1/package.json" ]; then
echo "Expected $PACKAGE_DIR1/package.json to be present."
exit 1
fi
9 changes: 9 additions & 0 deletions e2e/git_dep_no_tar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "image",
"pnpm": {
"onlyBuiltDependencies": []
},
"dependencies": {
"highlightjs-ttcn3": "https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git#6daccff309fca1e7561a43984d42fa4f829ce06d"
}
}
28 changes: 28 additions & 0 deletions e2e/git_dep_no_tar/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions e2e/git_dep_no_tar/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- '.'
8 changes: 6 additions & 2 deletions npm/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,22 @@ 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(
directory = rctx.path(_EXTRACT_TO_DIRNAME),
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)
Expand Down