-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add npm_translate_lock_replace_packages (#1888)
- Loading branch information
Showing
28 changed files
with
394 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,17 +206,13 @@ npm.npm_translate_lock( | |
# other direct dependencies in the `examples/npm_deps/package.json`. | ||
"[email protected]": ["examples/npm_deps"], | ||
}, | ||
replace_packages = { | ||
"[email protected]": "@chalk_501//:pkg", | ||
}, | ||
update_pnpm_lock = True, | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
verify_patches = "//examples/npm_deps/patches:patches", | ||
) | ||
use_repo( | ||
npm, | ||
"npm", | ||
"npm__chalk__5.0.1__links", | ||
"npm__fsevents__2.3.2__links", | ||
"npm__rollup__2.70.2", | ||
"npm__rollup__2.70.2__links", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,9 +159,6 @@ npm_translate_lock( | |
# other direct dependencies in the `examples/npm_deps/package.json`. | ||
"[email protected]": ["examples/npm_deps"], | ||
}, | ||
replace_packages = { | ||
"[email protected]": "@chalk_501//:pkg", | ||
}, | ||
update_pnpm_lock = True, | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
verify_patches = "//examples/npm_deps/patches:patches", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../.bazelversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") | ||
load("@aspect_rules_js//js:defs.bzl", "js_test") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
js_test( | ||
name = "test", | ||
data = [ | ||
"package.json", | ||
":node_modules", | ||
], | ||
entry_point = "main.js", | ||
) | ||
|
||
npm_package( | ||
name = "npm-pkg", | ||
srcs = [ | ||
"main.js", | ||
"package.json", | ||
], | ||
) | ||
|
||
build_test( | ||
name = "node_modules_test", | ||
targets = [ | ||
":node_modules", | ||
":npm-pkg", | ||
], | ||
) | ||
|
||
# Strip the system-dependent 'system_tar' attribute from the generated repositories.bzl | ||
genrule( | ||
name = "npm_translate_lock_wksp-repositories", | ||
srcs = ["@npm//:repositories.bzl"], | ||
outs = ["wksp_repos_stripped.bzl"], | ||
cmd = 'sed "s/system_tar = .*,/system_tar = \\"xxx\\",/" "$<" > "$@"', | ||
target_compatible_with = select({ | ||
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
) | ||
|
||
write_source_files( | ||
name = "write_npm_translate_lock_wksp", | ||
files = { | ||
"snapshots/wksp/npm_defs.bzl": "@npm//:defs.bzl", | ||
"snapshots/wksp/repositories.bzl": ":npm_translate_lock_wksp-repositories", | ||
}, | ||
target_compatible_with = select({ | ||
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
) | ||
|
||
write_source_files( | ||
name = "write_npm_translate_lock_bzlmod", | ||
files = { | ||
# NOTE: @npm//:repositories.bzl not generated for bzlmod | ||
"snapshots/bzlmod/npm_defs.bzl": "@npm//:defs.bzl", | ||
}, | ||
target_compatible_with = select({ | ||
"@aspect_bazel_lib//lib:bzlmod": [], | ||
"//conditions:default": ["@platforms//:incompatible"], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module( | ||
name = "e2e_npm_translate_lock_replace_packages", | ||
version = "0.0.0", | ||
compatibility_level = 1, | ||
) | ||
|
||
bazel_dep(name = "platforms", version = "0.0.5") | ||
bazel_dep(name = "aspect_rules_js", version = "0.0.0") | ||
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7") | ||
bazel_dep(name = "bazel_skylib", version = "1.5.0") | ||
|
||
local_path_override( | ||
module_name = "aspect_rules_js", | ||
path = "../..", | ||
) | ||
|
||
npm = use_extension( | ||
"@aspect_rules_js//npm:extensions.bzl", | ||
"npm", | ||
dev_dependency = True, | ||
) | ||
npm.npm_translate_lock( | ||
name = "npm", | ||
npmrc = "//:.npmrc", | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
replace_packages = { | ||
"[email protected]": "@chalk_501//:pkg", | ||
}, | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
) | ||
|
||
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "chalk_501", | ||
build_file = "//:chalk-5.0.1.BUILD", | ||
dev_dependency = True, | ||
integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", | ||
url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", | ||
) | ||
|
||
use_repo(npm, "npm") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local_repository( | ||
name = "aspect_rules_js", | ||
path = "../..", | ||
) | ||
|
||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
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"], | ||
npmrc = "//:.npmrc", | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
replace_packages = { | ||
"[email protected]": "@chalk_501//:pkg", | ||
}, | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
) | ||
|
||
load("@npm//:repositories.bzl", "npm_repositories") | ||
|
||
npm_repositories() | ||
|
||
http_archive( | ||
name = "chalk_501", | ||
build_file = "//:chalk-5.0.1.BUILD", | ||
integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", | ||
url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import chalk from 'chalk' | ||
import { readFileSync } from 'fs' | ||
|
||
const packageJsonDep = JSON.parse(readFileSync('./package.json', 'utf-8')) | ||
.dependencies['chalk'] | ||
if (packageJsonDep !== '5.3.0') { | ||
throw new Error( | ||
`Expected chalk version 5.3.0 declared in package.json, but got ${pkgDep}` | ||
) | ||
} | ||
|
||
const actualDep = JSON.parse( | ||
readFileSync('./node_modules/chalk/package.json', 'utf-8') | ||
).version | ||
if (actualDep !== '5.0.1') { | ||
throw new Error( | ||
`Expected chalk to be replaced with version 5.0.1, but got ${actualDep}` | ||
) | ||
} | ||
|
||
console.log(chalk.blue(`Hello world! The meaning of life is... 42`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
"dependencies": { | ||
"chalk": "5.3.0" | ||
}, | ||
"pnpm": { | ||
"onlyBuiltDependencies": [] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- '.' |
Empty file.
62 changes: 62 additions & 0 deletions
62
e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/npm_defs.bzl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Oops, something went wrong.