-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(bazel): stamp targets to build, test, and serve aio against
first party deps Architect is not compatible with disabling the rules_nodejs linker so these targets must use npm_link to link first party deps
- Loading branch information
1 parent
7a134cf
commit 22a317d
Showing
27 changed files
with
168 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
load("//:packages.bzl", "ALL_PACKAGES", "to_package_label") | ||
load("@build_bazel_rules_nodejs//internal/linker:npm_link.bzl", "npm_link") | ||
|
||
def link_local_packages(deps): | ||
"""Stamp npm_link targets for packages in deps that has a local package equivalent. | ||
Args: | ||
deps: list of npm dependency labels | ||
""" | ||
for dep in deps: | ||
label = Label(dep) | ||
if label.package in ALL_PACKAGES: | ||
npm_link( | ||
name = _npm_link_name(dep), | ||
target = to_package_label(label.package), | ||
package_name = label.package, | ||
package_path = native.package_name(), | ||
tags = ["manual"], | ||
) | ||
|
||
def substitute_local_packages(deps): | ||
"""Substitute npm dependencies for their local npm_link equivalent. | ||
Assumes that link_local_packages() was already called on these dependencies. | ||
Dependencies that are not associated with a local package are left alone. | ||
Args: | ||
deps: list of npm dependency labels | ||
Returns: | ||
substituted list of dependencies | ||
""" | ||
substituted = [] | ||
for dep in deps: | ||
label = Label(dep) | ||
if label.package in ALL_PACKAGES: | ||
substituted.append(_npm_link_name(dep)) | ||
else: | ||
substituted.append(dep) | ||
return substituted | ||
|
||
def _npm_link_name(dep): | ||
label = Label(dep) | ||
return "local_%s" % label.package.replace("@", "_").replace("/", "_") |
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 |
---|---|---|
@@ -1,49 +1,68 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _nodejs_test = "nodejs_test") | ||
|
||
def nodejs_binary(data = [], env = {}, templated_args = [], **kwargs): | ||
def nodejs_binary(data = [], env = {}, templated_args = [], chdir = "", enable_linker = False, **kwargs): | ||
data = data + [ | ||
"//aio/tools/esm-loader", | ||
"//aio/tools/esm-loader:esm-loader.mjs", | ||
] | ||
|
||
env = dict(env, **{"NODE_MODULES_WORKSPACE_NAME": "aio_npm"}) | ||
|
||
if not enable_linker: | ||
templated_args = templated_args + [ | ||
# Disable the linker and rely on patched resolution which works better on Windows | ||
# and is less prone to race conditions when targets build concurrently. | ||
"--nobazel_run_linker", | ||
] | ||
|
||
templated_args = templated_args + [ | ||
# Disable the linker and rely on patched resolution which works better on Windows | ||
# and is less prone to race conditions when targets build concurrently. | ||
"--nobazel_run_linker", | ||
# Provide a custom esm loader to resolve third-party depenencies. Unlike for cjs | ||
# modules, rules_nodejs doesn't patch imports when the linker is disabled. | ||
"--node_options=--loader=./$(rootpath //aio/tools/esm-loader:esm-loader.mjs)", | ||
"--node_options=--loader=%s" % _esm_loader_path(chdir), | ||
] | ||
|
||
_nodejs_binary( | ||
data = data, | ||
env = env, | ||
templated_args = templated_args, | ||
chdir = chdir, | ||
**kwargs | ||
) | ||
|
||
def nodejs_test(data = [], env = {}, templated_args = [], **kwargs): | ||
def nodejs_test(data = [], env = {}, templated_args = [], chdir = "", enable_linker = False, **kwargs): | ||
data = data + [ | ||
"//aio/tools/esm-loader", | ||
"//aio/tools/esm-loader:esm-loader.mjs", | ||
] | ||
|
||
env = dict(env, **{"NODE_MODULES_WORKSPACE_NAME": "aio_npm"}) | ||
|
||
if not enable_linker: | ||
templated_args = templated_args + [ | ||
# Disable the linker and rely on patched resolution which works better on Windows | ||
# and is less prone to race conditions when targets build concurrently. | ||
"--nobazel_run_linker", | ||
] | ||
|
||
templated_args = templated_args + [ | ||
# Disable the linker and rely on patched resolution which works better on Windows | ||
# and is less prone to race conditions when targets build concurrently. | ||
"--nobazel_run_linker", | ||
# Provide a custom esm loader to resolve third-party depenencies. Unlike for cjs | ||
# modules, rules_nodejs doesn't patch imports when the linker is disabled. | ||
"--node_options=--loader=./$(rootpath //aio/tools/esm-loader:esm-loader.mjs)", | ||
"--node_options=--loader=%s" % _esm_loader_path(chdir), | ||
] | ||
|
||
_nodejs_test( | ||
data = data, | ||
env = env, | ||
templated_args = templated_args, | ||
chdir = chdir, | ||
**kwargs | ||
) | ||
|
||
def _esm_loader_path(chdir): | ||
"""Adjust the path provided for the esm loader node option which | ||
depends on the value of chdir.""" | ||
esm_loader_path_prefix = "./" | ||
if chdir and len(chdir) > 0: | ||
esm_loader_path_prefix = "".join(["../" for segment in chdir.split("/")]) | ||
|
||
return "%s$(rootpath //aio/tools/esm-loader:esm-loader.mjs)" % esm_loader_path_prefix |
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
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
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
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
Oops, something went wrong.