Skip to content

Commit a585a16

Browse files
authored
fix(npm): support workspace run_lifecycle_hooks=False (#2063)
Close #2062
1 parent fb00d51 commit a585a16

File tree

17 files changed

+410
-2
lines changed

17 files changed

+410
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
e2e/npm_link_package
4848
e2e/npm_link_package-esm
4949
e2e/npm_translate_lock
50+
e2e/npm_translate_lock_disable_hooks
5051
e2e/npm_translate_lock_empty
5152
e2e/npm_translate_lock_multi
5253
e2e/npm_translate_lock_partial_clone
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.bazeliskrc
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Import Aspect bazelrc presets
2+
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
3+
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
4+
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
5+
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
6+
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
7+
import %workspace%/../../.aspect/bazelrc/performance.bazelrc
8+
9+
### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###
10+
11+
# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
12+
# This file should appear in `.gitignore` so that settings are not shared with team members. This
13+
# should be last statement in this config so the user configuration is able to overwrite flags from
14+
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
15+
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.bazelversion
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
2+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
4+
5+
npm_link_all_packages(name = "node_modules")
6+
7+
build_test(
8+
name = "test",
9+
targets = [
10+
":node_modules",
11+
],
12+
)
13+
14+
genrule(
15+
name = "snapshot-extracted-wksp",
16+
srcs = ["@npm//:repositories.bzl"],
17+
outs = ["snapshot-extracted-wksp.bzl"],
18+
cmd = 'sed "s/system_tar = \\".*\\"/system_tar = \\"<TAR>\\"/" "$<" > "$@"',
19+
# Target names may be different on workspace vs bzlmod
20+
target_compatible_with = select({
21+
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
22+
"//conditions:default": [],
23+
}),
24+
visibility = ["//visibility:private"],
25+
)
26+
27+
write_source_files(
28+
name = "write_npm_translate_lock_wksp",
29+
files = {
30+
"snapshots/wksp/repositories.bzl": ":snapshot-extracted-wksp.bzl",
31+
},
32+
# Target names may be different on bazel versions
33+
tags = ["skip-on-bazel6"],
34+
target_compatible_with = select({
35+
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
36+
"//conditions:default": [],
37+
}),
38+
)
39+
40+
write_source_files(
41+
name = "write_npm_translate_lock_defs",
42+
files = {
43+
"snapshots/defs.bzl": "@npm//:defs.bzl",
44+
"snapshots/aspect_test_c_links_defs.bzl": "@npm__at_aspect-test_c__2.0.0__links//:defs.bzl",
45+
},
46+
# Target names may be different on bazel versions
47+
tags = ["skip-on-bazel6"],
48+
target_compatible_with = select({
49+
"@aspect_bazel_lib//lib:bzlmod": [],
50+
"//conditions:default": ["@platforms//:incompatible"],
51+
}),
52+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bazel_dep(name = "aspect_rules_js", version = "0.0.0", dev_dependency = True)
2+
local_path_override(
3+
module_name = "aspect_rules_js",
4+
path = "../..",
5+
)
6+
7+
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7", dev_dependency = True)
8+
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)
9+
bazel_dep(name = "platforms", version = "0.0.9", dev_dependency = True)
10+
11+
npm = use_extension(
12+
"@aspect_rules_js//npm:extensions.bzl",
13+
"npm",
14+
)
15+
npm.npm_translate_lock(
16+
name = "npm",
17+
data = ["//:package.json"],
18+
pnpm_lock = "//:pnpm-lock.yaml",
19+
run_lifecycle_hooks = False,
20+
)
21+
use_repo(npm, "npm", "npm__at_aspect-test_c__2.0.0__links")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local_repository(
2+
name = "aspect_rules_js",
3+
path = "../..",
4+
)
5+
6+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
7+
8+
rules_js_dependencies()
9+
10+
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")
11+
12+
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)
13+
14+
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
15+
16+
npm_translate_lock(
17+
name = "npm",
18+
data = ["//:package.json"],
19+
pnpm_lock = "//:pnpm-lock.yaml",
20+
run_lifecycle_hooks = False,
21+
)
22+
23+
load("@npm//:repositories.bzl", "npm_repositories")
24+
25+
npm_repositories()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The presence of this file causes WORKSPACE to be ignored when bzlmod is enabled.
2+
# See https://docs.google.com/document/d/1JtXIVnXyFZ4bmbiBCr5gsTH4-opZAFf5DMMb-54kES0/edit#heading=h.y054fjub9max
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"dependencies": {
3+
"@aspect-test/c": "2.0.0"
4+
},
5+
"pnpm": {
6+
"onlyBuiltDependencies": [
7+
"@aspect-test/c"
8+
]
9+
}
10+
}

e2e/npm_translate_lock_disable_hooks/pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- '.'

e2e/npm_translate_lock_disable_hooks/snapshots/aspect_test_c_links_defs.bzl

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)