Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .aspect/workflows/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ workspaces:
e2e/gyp_no_install_script:
icon: npm
tasks: *e2e_tasks
e2e/js_binary_workspace:
icon: js
tasks: *e2e_tasks
# rules_docker not compatible with Bazel 7.
# See https://github.com/bazelbuild/bazel/issues/20494#issuecomment-1852401451.
# e2e/js_image_docker:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
.
e2e/bzlmod
e2e/gyp_no_install_script
e2e/js_binary_workspace
e2e/js_image_docker
e2e/js_image_oci
e2e/js_run_devserver
Expand Down
4 changes: 4 additions & 0 deletions contrib/nextjs/next.bazel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if (nextjsStandaloneConfig.startsWith(process.env.BAZEL_BINDIR)) {
process.env.BAZEL_BINDIR.length + 1
)
}

// Support invocation from another workspace: strip "external/<repo>/" if present
nextjsStandaloneConfig = nextjsStandaloneConfig.replace(/^external\/[^/]+\//, '')

if (!nextjsStandaloneConfig.startsWith(bazelPackage)) {
throw new Error(
`Next.js config must be relative to the app root: ${nextjsStandaloneConfig}`
Expand Down
1 change: 1 addition & 0 deletions e2e/js_binary_workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import %workspace%/../../tools/preset.bazelrc
16 changes: 16 additions & 0 deletions e2e/js_binary_workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

js_run_binary(
name = "run_workspace_bin",
stdout = "out.txt",
tool = "@workspace//:bin",
)

build_test(
name = "test",
targets = [
":run_workspace_bin",
"@workspace//:run_bin",
],
)
16 changes: 16 additions & 0 deletions e2e/js_binary_workspace/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module(name = "js_binary_workspace")

bazel_dep(name = "aspect_rules_js", version = "0.0.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.8.1", dev_dependency = True)

local_path_override(
module_name = "aspect_rules_js",
path = "../..",
)

# Add the subject module as a local repository so we can run it as an external dep
bazel_dep(name = "workspace")
local_path_override(
module_name = "workspace",
path = "workspace",
)
20 changes: 20 additions & 0 deletions e2e/js_binary_workspace/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# WORKSPACE mode setup for Bazel 7 when bzlmod is disabled.

local_repository(
name = "aspect_rules_js",
path = "../..",
)

local_repository(
name = "workspace",
path = "workspace",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//js:toolchains.bzl", "rules_js_register_toolchains")

# Use default Node toolchain registration suitable for CI.
rules_js_register_toolchains()
2 changes: 2 additions & 0 deletions e2e/js_binary_workspace/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
15 changes: 15 additions & 0 deletions e2e/js_binary_workspace/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary")

js_binary(
name = "bin",
chdir = package_name(),
entry_point = "index.js",
visibility = ["//visibility:public"],
)

js_run_binary(
name = "run_bin",
stdout = "out_workspace.txt",
tool = ":bin",
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions e2e/js_binary_workspace/workspace/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module(name = "workspace")

bazel_dep(name = "aspect_rules_js", version = "0.0.0")
local_path_override(
module_name = "aspect_rules_js",
path = "../../..",
)
2 changes: 2 additions & 0 deletions e2e/js_binary_workspace/workspace/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Stub WORKSPACE required for Bazel 6 when a module is referenced via a local_repository override.
workspace(name = "workspace")
2 changes: 2 additions & 0 deletions e2e/js_binary_workspace/workspace/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
2 changes: 2 additions & 0 deletions e2e/js_binary_workspace/workspace/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log('Running within directory:', process.cwd())
process.exit(0)
18 changes: 17 additions & 1 deletion js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,23 @@ def _bash_launcher(ctx, nodeinfo, entry_point_path, log_prefix_rule_set, log_pre

if ctx.attr.chdir:
# Set chdir env if not already set to allow js_run_binary to override
envs.append(_ENV_SET_IFF_NOT_SET.format(var = "JS_BINARY__CHDIR", value = _expand_env_if_needed(ctx, ctx.attr.chdir)))
chdir_value = _expand_env_if_needed(ctx, ctx.attr.chdir)

# Normalize workspace-relative chdir for external repositories to avoid requiring
# callers to manually prefix with "external/<repo>/".
if (
ctx.label.repo_name and
not (chdir_value.startswith("external/") or chdir_value.startswith("/")) and
not chdir_value.startswith("@")
):
if chdir_value == ".":
normalized_chdir = "external/{}".format(ctx.label.repo_name)
else:
normalized_chdir = "external/{}/{}".format(ctx.label.repo_name, chdir_value)
else:
normalized_chdir = chdir_value

envs.append(_ENV_SET_IFF_NOT_SET.format(var = "JS_BINARY__CHDIR", value = normalized_chdir))

# Set log envs iff not already set to allow js_run_binary to override
for env in envs_for_log_level(ctx.attr.log_level):
Expand Down
5 changes: 4 additions & 1 deletion js/private/js_binary.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ fi
# Change directory to user specified package if set
if [ "${JS_BINARY__CHDIR:-}" ]; then
logf_debug "changing directory to user specified package %s" "$JS_BINARY__CHDIR"
cd "$JS_BINARY__CHDIR"
case "$JS_BINARY__CHDIR" in
external/*) cd "$(resolve_execroot_bin_path "$JS_BINARY__CHDIR")" ;;
*) cd "$JS_BINARY__CHDIR" ;;
esac
fi

# Gather node options
Expand Down
18 changes: 17 additions & 1 deletion js/private/js_run_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,23 @@ WARNING: js_library 'include_declarations' is deprecated. Use 'include_types' in

# Configure working directory to `chdir` is set
if chdir:
fixed_env["JS_BINARY__CHDIR"] = chdir
normalized_chdir = chdir
repo = native.repo_name()

# Normalize workspace-relative chdir for external repositories so callers can pass
# native.package_name() without worrying about external/ prefixing.
# - Leave absolute paths and already-external paths untouched.
# - For external repos, prefix with "external/<repo>/".
if (
repo and
not (chdir.startswith("external/") or chdir.startswith("/")) and
not chdir.startswith("@")
):
if chdir == ".":
normalized_chdir = "external/{}".format(repo)
else:
normalized_chdir = "external/{}/{}".format(repo, chdir)
fixed_env["JS_BINARY__CHDIR"] = normalized_chdir

# Configure capturing stdout, stderr and/or the exit code
extra_outs = []
Expand Down
2 changes: 1 addition & 1 deletion js/private/test/image/asserts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("//js:defs.bzl", "js_image_layer")
# buildifier: disable=function-docstring
def assert_tar_listing(name, actual, expected):
# Either of these two file sizes may be observed on a file like /js/private/test/image/bin
sanitize_cmd = "sed -E 's/239[0-9]{2}/xxxxx/g'"
sanitize_cmd = "sed -E 's/239[0-9]{2}|24[0-9]{3}/xxxxx/g'"
actual_listing = "_{}_listing".format(name)
native.genrule(
name = actual_listing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/
-r-xr-xr-x 0 0 0 24076 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/
Expand All @@ -14,7 +14,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/
-r-xr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/ㅑㅕㅣㅇ.ㄴㅅ
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/
-r-xr-xr-x 0 0 0 24076 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/bin2
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/bin2
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_node_bin/
-r-xr-xr-x 0 0 0 133 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_node_bin/node
-r-xr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/empty empty.ㄴㅅ
Expand Down
5 changes: 4 additions & 1 deletion js/private/test/snapshots/launcher.sh

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

Loading