Skip to content

Commit

Permalink
fix(npm): support workspace run_lifecycle_hooks=False
Browse files Browse the repository at this point in the history
Close #2062
  • Loading branch information
jbedard committed Jan 8, 2025
1 parent 08fe920 commit 69b008f
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
e2e/npm_link_package
e2e/npm_link_package-esm
e2e/npm_translate_lock
e2e/npm_translate_lock_disable_hooks
e2e/npm_translate_lock_empty
e2e/npm_translate_lock_multi
e2e/npm_translate_lock_partial_clone
Expand Down
1 change: 1 addition & 0 deletions e2e/npm_translate_lock_disable_hooks/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions e2e/npm_translate_lock_disable_hooks/.bazeliskrc
15 changes: 15 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Import Aspect bazelrc presets
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
import %workspace%/../../.aspect/bazelrc/performance.bazelrc

### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###

# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
# This file should appear in `.gitignore` so that settings are not shared with team members. This
# should be last statement in this config so the user configuration is able to overwrite flags from
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc
1 change: 1 addition & 0 deletions e2e/npm_translate_lock_disable_hooks/.bazelversion
52 changes: 52 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

build_test(
name = "test",
targets = [
":node_modules",
],
)

genrule(
name = "snapshot-extracted-wksp",
srcs = ["@npm//:repositories.bzl"],
outs = ["snapshot-extracted-wksp.bzl"],
cmd = 'sed "s/system_tar = \\".*\\"/system_tar = \\"<TAR>\\"/" "$<" > "$@"',
# Target names may be different on workspace vs bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
)

write_source_files(
name = "write_npm_translate_lock_wksp",
files = {
"snapshots/wksp/repositories.bzl": ":snapshot-extracted-wksp.bzl",
},
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

write_source_files(
name = "write_npm_translate_lock_defs",
files = {
"snapshots/defs.bzl": "@npm//:defs.bzl",
"snapshots/aspect_test_c_links_defs.bzl": "@npm__at_aspect-test_c__2.0.0__links//:defs.bzl",
},
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
21 changes: 21 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/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 = "aspect_bazel_lib", version = "2.7.7", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.9", dev_dependency = True)

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
)
npm.npm_translate_lock(
name = "npm",
data = ["//:package.json"],
pnpm_lock = "//:pnpm-lock.yaml",
run_lifecycle_hooks = False,
)
use_repo(npm, "npm", "npm__at_aspect-test_c__2.0.0__links")
25 changes: 25 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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)

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

npm_translate_lock(
name = "npm",
data = ["//:package.json"],
pnpm_lock = "//:pnpm-lock.yaml",
run_lifecycle_hooks = False,
)

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

npm_repositories()
2 changes: 2 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/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
10 changes: 10 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": {
"@aspect-test/c": "2.0.0"
},
"pnpm": {
"onlyBuiltDependencies": [
"@aspect-test/c"
]
}
}
24 changes: 24 additions & 0 deletions e2e/npm_translate_lock_disable_hooks/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/npm_translate_lock_disable_hooks/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- '.'

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

Loading

0 comments on commit 69b008f

Please sign in to comment.