Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add repositories.bzl snapshot tests for each lockfile version #2050

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ npm = use_extension(
# Deep with many peers
"lock-%s__at_rollup_plugin-typescript__8.2.1_%s" % (
version,
"ommloj5qql5ba6x5wuiluawhoi" if version == "v54" else "1662662592" if version == "v90" else "1813138439",
"3vgsug3mjv7wvue74swjdxifxy" if version == "v54" else "626159424" if version == "v90" else "1813138439",
),

# Dep with patch
Expand Down
4 changes: 2 additions & 2 deletions e2e/pnpm_lockfiles/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@aspect-test/b": "5.0.2",
"@types/node": "16.18.11",
"@types/archiver": "5.3.1",
"alias-only-sizzle": "npm:@types/sizzle@~2.3.8",
"alias-types-node": "npm:@types/node@~16.18.11"
"alias-only-sizzle": "npm:@types/sizzle@2.3.8",
"alias-types-node": "npm:@types/node@16.18.11"
},
"optionalDependencies": {
"@aspect-test/c": "2.0.0"
Expand Down
49 changes: 45 additions & 4 deletions e2e/pnpm_lockfiles/lockfile-test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PNPM_LOCK_VERSIONS = [
"v90",
]

BZL_FILES = {
BZLMOD_FILES = {
# global
"defs.bzl": "@REPO_NAME//:defs.bzl",

Expand All @@ -29,6 +29,10 @@ BZL_FILES = {
"rollup3_package_json.bzl": "@REPO_NAME__rollup__3.29.4//VERSION:package_json.bzl",
}

WKSP_FILES = {
"repositories.bzl": "@REPO_NAME//:repositories.bzl",
}

def lockfile_test(name = None):
"""
Tests for a lockfile and associated targets + files generated by rules_js.
Expand Down Expand Up @@ -102,7 +106,7 @@ def lockfile_test(name = None):
# npm: alias to a package that has many peers
":node_modules/rollup-plugin-with-peers",
# underlying repo for the many-peers package
"@%s__at_rollup_plugin-typescript__8.2.1_%s//:pkg" % (lock_repo, "ommloj5qql5ba6x5wuiluawhoi" if lock_version == "v54" else "1662662592" if lock_version == "v90" else "1813138439"),
"@%s__at_rollup_plugin-typescript__8.2.1_%s//:pkg" % (lock_repo, "3vgsug3mjv7wvue74swjdxifxy" if lock_version == "v54" else "626159424" if lock_version == "v90" else "1813138439"),

# uuv 'hasBin'
":node_modules/uvu",
Expand Down Expand Up @@ -195,7 +199,7 @@ def lockfile_test(name = None):
cmd = 'sed "s/{}/<LOCKVERSION>/g" "$<" > "$@"'.format(lock_version),
visibility = ["//visibility:private"],
)
for (out, what) in BZL_FILES.items()
for (out, what) in BZLMOD_FILES.items()
]

write_source_files(
Expand All @@ -206,7 +210,7 @@ def lockfile_test(name = None):
"snapshots/%s" % f,
":extract-%s" % f,
)
for f in BZL_FILES.keys()
for f in BZLMOD_FILES.keys()
],
),
# Target names may be different on workspace vs bzlmod
Expand All @@ -217,3 +221,40 @@ def lockfile_test(name = None):
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
)

# buildifier: disable=no-effect
[
native.genrule(
name = "extract-%s" % out,
srcs = [what.replace("VERSION", lock_version).replace("REPO_NAME", lock_repo)],
outs = ["snapshot-extracted-%s" % out],
cmd = 'sed "s/{}/<LOCKVERSION>/g" "$<" > "$@"'.format(lock_version),
visibility = ["//visibility:private"],
# Target names may be different on workspace vs bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
for (out, what) in WKSP_FILES.items()
]

write_source_files(
name = "wksp-repos",
files = dict(
[
(
"snapshots/%s" % f,
":extract-%s" % f,
)
for f in WKSP_FILES.keys()
],
),
# Target names may be different on workspace vs bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
)
5 changes: 4 additions & 1 deletion e2e/pnpm_lockfiles/projects/a/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "@scoped/a",
"private": true
"private": true,
"dependencies": {
"@types/node": "16.18.11"
}
}
5 changes: 5 additions & 0 deletions e2e/pnpm_lockfiles/update-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ bazel run @@//v54:repos
bazel run @@//v60:repos
bazel run @@//v61:repos
bazel run @@//v90:repos

bazel run --enable_bzlmod=false @@//v54:wksp-repos
bazel run --enable_bzlmod=false @@//v60:wksp-repos
bazel run --enable_bzlmod=false @@//v61:wksp-repos
bazel run --enable_bzlmod=false @@//v90:wksp-repos
41 changes: 22 additions & 19 deletions e2e/pnpm_lockfiles/v54/pnpm-lock.yaml

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

23 changes: 17 additions & 6 deletions e2e/pnpm_lockfiles/v54/snapshots/defs.bzl

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

Loading
Loading