mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Remove npm/rules_js dependency for C++ only use cases (#7990)
When flatbuffers is being used from a project that has no use for
JavaScript, users encounter an error similar to the following:
ERROR: Skipping '@com_github_google_flatbuffers//:flatbuffers': error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined.
WARNING: Target pattern parsing failed.
ERROR: error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined.
INFO: Elapsed time: 0.023s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
currently loading: @com_github_google_flatbuffers//
That's not ideal. Users that only care about C++ for example
shouldn't be forced to deal with rules_js and friends.
This patch attempts to fix that by moving the rules_js-specific things
into the `ts` and `tests/ts` directories. This should allow
non-JavaScript projects to ignore rules_js and friends completely.
Here I basically followed the `rules_foo` example from rules_js:
https://github.com/aspect-build/rules_js/tree/main/e2e/rules_foo
The idea is that flatbuffers has its own npm dependencies regardless
of what other projects may have. This means we should not force the
user to import flatbuffers's npm dependencies. The new
`ts/repositories.bzl` file is used by dependents to import
flatbuffers's dependencies. They can still import their own
dependencies. This cleanup allowed me to move all
JavaScript-specific stuff from the top-level directory into
subdirectories.
There should be no changes in this patch in terms of functionality.
It's just a refactor of the rules_js call sites. Users will have to
add a call to the function in `ts/repositories.bzl` in their own
`WORKSPACE` file. They can use
`tests/ts/bazel_repository_test/WORKSPACE` as an example.
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
23
ts/repositories.bzl
Normal file
23
ts/repositories.bzl
Normal file
@@ -0,0 +1,23 @@
|
||||
"""WORKSPACE macro to load flatbuffers's npm package list."""
|
||||
|
||||
load("@aspect_rules_js//npm:npm_import.bzl", _npm_translate_lock = "npm_translate_lock")
|
||||
|
||||
def flatbuffers_npm(name):
|
||||
_npm_translate_lock(
|
||||
name = name,
|
||||
npmrc = "@com_github_google_flatbuffers//:.npmrc",
|
||||
pnpm_lock = "@com_github_google_flatbuffers//:pnpm-lock.yaml",
|
||||
# Override the Bazel package where pnpm-lock.yaml is located and link
|
||||
# to the specified package instead.
|
||||
root_package = "ts",
|
||||
# Set this to True when the lock file needs to be updated, commit the
|
||||
# changes, then set to False again.
|
||||
# Alternatively, run:
|
||||
# $ bazel run -- @pnpm//:pnpm --dir $PWD install --lockfile-only
|
||||
update_pnpm_lock = False,
|
||||
verify_node_modules_ignored = "@com_github_google_flatbuffers//:.bazelignore",
|
||||
defs_bzl_filename = "npm_link_all_packages.bzl",
|
||||
data = [
|
||||
"@com_github_google_flatbuffers//:package.json",
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user