diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 2d65cfb6d..6ebeab113 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -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 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4ece636c1..e23a9ea32 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/e2e/git_dep_no_tar/.bazelignore b/e2e/git_dep_no_tar/.bazelignore new file mode 100644 index 000000000..c2658d7d1 --- /dev/null +++ b/e2e/git_dep_no_tar/.bazelignore @@ -0,0 +1 @@ +node_modules/ diff --git a/e2e/git_dep_no_tar/.bazelrc b/e2e/git_dep_no_tar/.bazelrc new file mode 100644 index 000000000..d3005fc76 --- /dev/null +++ b/e2e/git_dep_no_tar/.bazelrc @@ -0,0 +1,2 @@ +import %workspace%/../../tools/preset.bazelrc + diff --git a/e2e/git_dep_no_tar/.bazelversion b/e2e/git_dep_no_tar/.bazelversion new file mode 120000 index 000000000..96cf94962 --- /dev/null +++ b/e2e/git_dep_no_tar/.bazelversion @@ -0,0 +1 @@ +../../.bazelversion \ No newline at end of file diff --git a/e2e/git_dep_no_tar/.npmrc b/e2e/git_dep_no_tar/.npmrc new file mode 100644 index 000000000..5de6efae1 --- /dev/null +++ b/e2e/git_dep_no_tar/.npmrc @@ -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 diff --git a/e2e/git_dep_no_tar/BUILD.bazel b/e2e/git_dep_no_tar/BUILD.bazel new file mode 100644 index 000000000..031a61bcd --- /dev/null +++ b/e2e/git_dep_no_tar/BUILD.bazel @@ -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", + ], +) diff --git a/e2e/git_dep_no_tar/MODULE.bazel b/e2e/git_dep_no_tar/MODULE.bazel new file mode 100644 index 000000000..765c79dd9 --- /dev/null +++ b/e2e/git_dep_no_tar/MODULE.bazel @@ -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") diff --git a/e2e/git_dep_no_tar/README.md b/e2e/git_dep_no_tar/README.md new file mode 100644 index 000000000..f4510d03d --- /dev/null +++ b/e2e/git_dep_no_tar/README.md @@ -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. diff --git a/e2e/git_dep_no_tar/WORKSPACE b/e2e/git_dep_no_tar/WORKSPACE new file mode 100644 index 000000000..8346ae081 --- /dev/null +++ b/e2e/git_dep_no_tar/WORKSPACE @@ -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() diff --git a/e2e/git_dep_no_tar/WORKSPACE.bzlmod b/e2e/git_dep_no_tar/WORKSPACE.bzlmod new file mode 100644 index 000000000..3a956c2b7 --- /dev/null +++ b/e2e/git_dep_no_tar/WORKSPACE.bzlmod @@ -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 diff --git a/e2e/git_dep_no_tar/no_git_tar_test.sh b/e2e/git_dep_no_tar/no_git_tar_test.sh new file mode 100755 index 000000000..217405f14 --- /dev/null +++ b/e2e/git_dep_no_tar/no_git_tar_test.sh @@ -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 diff --git a/e2e/git_dep_no_tar/package.json b/e2e/git_dep_no_tar/package.json new file mode 100644 index 000000000..edb04befe --- /dev/null +++ b/e2e/git_dep_no_tar/package.json @@ -0,0 +1,9 @@ +{ + "name": "image", + "pnpm": { + "onlyBuiltDependencies": [] + }, + "dependencies": { + "highlightjs-ttcn3": "https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git#6daccff309fca1e7561a43984d42fa4f829ce06d" + } +} diff --git a/e2e/git_dep_no_tar/pnpm-lock.yaml b/e2e/git_dep_no_tar/pnpm-lock.yaml new file mode 100644 index 000000000..6ad117f8c --- /dev/null +++ b/e2e/git_dep_no_tar/pnpm-lock.yaml @@ -0,0 +1,28 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +dependencies: + highlightjs-ttcn3: + specifier: https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git#6daccff309fca1e7561a43984d42fa4f829ce06d + version: gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git#6daccff309fca1e7561a43984d42fa4f829ce06d + +packages: + + /highlight.js@11.11.1: + resolution: {integrity: sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w==} + engines: {node: '>=12.0.0'} + dev: false + + gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git#6daccff309fca1e7561a43984d42fa4f829ce06d: + resolution: + type: git + repo: git+https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git + commit: 6daccff309fca1e7561a43984d42fa4f829ce06d + name: highlightjs-ttcn3 + version: 0.0.1 + dependencies: + highlight.js: 11.11.1 + dev: false diff --git a/e2e/git_dep_no_tar/pnpm-workspace.yaml b/e2e/git_dep_no_tar/pnpm-workspace.yaml new file mode 100644 index 000000000..2cce0eb74 --- /dev/null +++ b/e2e/git_dep_no_tar/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - '.' diff --git a/npm/private/npm_import.bzl b/npm/private/npm_import.bzl index d4360be35..ca1182a5e 100644 --- a/npm/private/npm_import.bzl +++ b/npm/private/npm_import.bzl @@ -493,6 +493,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( @@ -500,11 +504,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)