-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rules_js_external_packages example
- Loading branch information
1 parent
a677fa4
commit 2eeffc2
Showing
35 changed files
with
407 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
packages/vega/node_modules | ||
packages/rigel/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 @@ | ||
../bazelrc/.bazeliskrc |
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,5 @@ | ||
# 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 @@ | ||
../bazelrc/.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,2 @@ | ||
node_modules | ||
/bazel-* |
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,6 @@ | ||
# 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). See | ||
# https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock | ||
# documentation for more information. | ||
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,3 @@ | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "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,48 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
local_repository( | ||
name = "other", | ||
path = "../other", | ||
) | ||
|
||
http_archive( | ||
name = "aspect_bazel_lib", | ||
sha256 = "cbf473d630ab67b36461d83b38fdc44e56f45b78d03c405e4958280211124d79", | ||
strip_prefix = "bazel-lib-1.36.0", | ||
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.36.0/bazel-lib-v1.36.0.tar.gz", | ||
) | ||
|
||
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") | ||
|
||
aspect_bazel_lib_dependencies() | ||
|
||
http_archive( | ||
name = "aspect_rules_js", | ||
sha256 = "7ab9776bcca823af361577a1a2ebb9a30d2eb5b94ecc964b8be360f443f714b2", | ||
strip_prefix = "rules_js-1.32.6", | ||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.32.6/rules_js-v1.32.6.tar.gz", | ||
) | ||
|
||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") | ||
|
||
rules_js_dependencies() | ||
|
||
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") | ||
|
||
nodejs_register_toolchains( | ||
name = "nodejs", | ||
node_version = DEFAULT_NODE_VERSION, | ||
) | ||
|
||
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") | ||
|
||
npm_translate_lock( | ||
name = "npm", | ||
npmrc = "//:.npmrc", | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
) | ||
|
||
load("@npm//:repositories.bzl", "npm_repositories") | ||
|
||
npm_repositories() |
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,6 @@ | ||
{ | ||
"name": "rules_js_external_packages", | ||
"dependencies": { | ||
"vega": "workspace:*" | ||
} | ||
} |
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 @@ | ||
load(":sync_npm_packages.bzl", "sync_npm_packages") | ||
load("@other//packages:packages.bzl", OTHER_PACKAGES = "PACKAGES") | ||
|
||
sync_npm_packages(packages = OTHER_PACKAGES) |
41 changes: 41 additions & 0 deletions
41
rules_js_external_packages/main/packages/rigel/BUILD.bazel
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,41 @@ | ||
load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
npm_package( | ||
name = "rigel", | ||
srcs = [ | ||
"index.mjs", | ||
"package.json", | ||
], | ||
# This is a perf improvement; the default will be flipped to False in rules_js 2.0 | ||
include_runfiles = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
js_binary( | ||
name = "rigel_bin", | ||
data = [":node_modules"], | ||
entry_point = "index.mjs", | ||
) | ||
|
||
js_run_binary( | ||
name = "run_rigel_bin", | ||
stdout = "run_rigel_bin_stdout", | ||
tool = ":rigel_bin", | ||
) | ||
|
||
assert_contains( | ||
name = "contains_rigel", | ||
actual = ":run_rigel_bin_stdout", | ||
expected = "rigel", | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**/*"]), | ||
visibility = ["//visibility:public"], | ||
) |
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,7 @@ | ||
import chalk from 'chalk'; | ||
|
||
export function whoami() { | ||
return 'rigel'; | ||
} | ||
|
||
console.log(chalk.blue(whoami())); |
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,7 @@ | ||
{ | ||
"name": "rigel", | ||
"dependencies": { | ||
"chalk": "5.2.0" | ||
}, | ||
"main": "index.mjs" | ||
} |
26 changes: 26 additions & 0 deletions
26
rules_js_external_packages/main/packages/sync_npm_packages.bzl
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,26 @@ | ||
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") | ||
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") | ||
|
||
def sync_npm_packages(packages): | ||
""" | ||
Sync npm packages from @other to this bazel package | ||
Args: | ||
packages: A list of package names to sync | ||
""" | ||
files = {} | ||
|
||
for p in packages: | ||
copy_to_directory( | ||
name = "copy_{}".format(p), | ||
srcs = ["@other//packages/{}:srcs".format(p)], | ||
include_external_repositories = ["other"], | ||
root_paths = [], | ||
replace_prefixes = {"packages/{}/".format(p): ""}, | ||
) | ||
files[":{}".format(p)] = "copy_{}".format(p) | ||
|
||
write_source_files( | ||
name = "other_packages", | ||
files = files, | ||
) |
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,47 @@ | ||
load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
npm_package( | ||
name = "vega", | ||
srcs = [ | ||
"index.mjs", | ||
"package.json", | ||
], | ||
# This is a perf improvement; the default will be flipped to False in rules_js 2.0 | ||
include_runfiles = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
js_binary( | ||
name = "vega_bin", | ||
data = [":node_modules"], | ||
entry_point = "index.mjs", | ||
) | ||
|
||
js_run_binary( | ||
name = "run_vega_bin", | ||
stdout = "run_vega_bin_stdout", | ||
tool = ":vega_bin", | ||
) | ||
|
||
assert_contains( | ||
name = "contains_vega", | ||
actual = ":run_vega_bin_stdout", | ||
expected = "vega", | ||
) | ||
|
||
assert_contains( | ||
name = "contains_rigel", | ||
actual = ":run_vega_bin_stdout", | ||
expected = "rigel", | ||
) | ||
|
||
assert_contains( | ||
name = "contains_upper_rigel", | ||
actual = ":run_vega_bin_stdout", | ||
expected = "RIGEL", | ||
) |
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,9 @@ | ||
import chalk from 'chalk'; | ||
import { whoami as whoisrigel } from 'rigel'; | ||
|
||
export function whoami() { | ||
return chalk.green('vega'); | ||
} | ||
|
||
console.log(whoami()); | ||
console.log(whoisrigel().toUpperCase()); |
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,7 @@ | ||
{ | ||
"name": "vega", | ||
"dependencies": { | ||
"chalk": "5.3.0", | ||
"rigel": "workspace:*" | ||
} | ||
} |
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: | ||
- 'packages/*' |
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 @@ | ||
node_modules | ||
packages/rigel/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 @@ | ||
../bazelrc/.bazeliskrc |
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,5 @@ | ||
# 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 @@ | ||
../bazelrc/.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,2 @@ | ||
node_modules | ||
/bazel-* |
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,6 @@ | ||
# 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). See | ||
# https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock | ||
# documentation for more information. | ||
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,3 @@ | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "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,32 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "aspect_rules_js", | ||
sha256 = "7ab9776bcca823af361577a1a2ebb9a30d2eb5b94ecc964b8be360f443f714b2", | ||
strip_prefix = "rules_js-1.32.6", | ||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.32.6/rules_js-v1.32.6.tar.gz", | ||
) | ||
|
||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") | ||
|
||
rules_js_dependencies() | ||
|
||
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") | ||
|
||
nodejs_register_toolchains( | ||
name = "nodejs", | ||
node_version = DEFAULT_NODE_VERSION, | ||
) | ||
|
||
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") | ||
|
||
npm_translate_lock( | ||
name = "npm", | ||
npmrc = "//:.npmrc", | ||
pnpm_lock = "//:pnpm-lock.yaml", | ||
verify_node_modules_ignored = "//:.bazelignore", | ||
) | ||
|
||
load("@npm//:repositories.bzl", "npm_repositories") | ||
|
||
npm_repositories() |
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,6 @@ | ||
{ | ||
"name": "rules_js_external_packages", | ||
"dependencies": { | ||
"rigel": "workspace:*" | ||
} | ||
} |
Empty file.
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 @@ | ||
PACKAGES = ["rigel"] |
41 changes: 41 additions & 0 deletions
41
rules_js_external_packages/other/packages/rigel/BUILD.bazel
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,41 @@ | ||
load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
npm_package( | ||
name = "rigel", | ||
srcs = [ | ||
"index.mjs", | ||
"package.json", | ||
], | ||
# This is a perf improvement; the default will be flipped to False in rules_js 2.0 | ||
include_runfiles = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
js_binary( | ||
name = "rigel_bin", | ||
data = [":node_modules"], | ||
entry_point = "index.mjs", | ||
) | ||
|
||
js_run_binary( | ||
name = "run_rigel_bin", | ||
stdout = "run_rigel_bin_stdout", | ||
tool = ":rigel_bin", | ||
) | ||
|
||
assert_contains( | ||
name = "contains_rigel", | ||
actual = ":run_rigel_bin_stdout", | ||
expected = "rigel", | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**/*"]), | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.