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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ coverage --deleted_packages=js/private/test/image/non_ascii
# 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
try-import %workspace%/.bazelrc.user
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ e2e/rules_foo/npm_repositories.bzl linguist-generated=true
**/snapshots/** linguist-generated=true
js/private/coverage/coverage.js linguist-generated=true
js/private/js_image_layer.mjs linguist-generated=true
*.bat.tpl text eol=crlf
8 changes: 2 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ jobs:
ASPECT_NPM_AUTH_TOKEN: ${{ secrets.ASPECT_NPM_AUTH_TOKEN }}
- id: os
name: Prepare 'os' matrix axis
# Only run MacOS and Windows on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
# Only run MacOS on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
run: |
a=( ubuntu )
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"macos"* ]]; then
a+=( macos )
fi
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"windows"* ]]; then
a+=( windows )
fi
a+=( windows )
printf -v j '"%s",' "${a[@]}"
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
outputs:
Expand All @@ -124,8 +122,6 @@ jobs:
os: ${{ fromJSON(needs.matrix-prep.outputs.os) }}
folder: ${{ fromJSON(needs.matrix-prep.outputs.folder) }}
exclude:
# Exclude Windows default, will opt-in to includes
- os: windows
# Exclude MacOS by default, will opt-in to includes
- os: macos
# Don't run bzlmod smoke test under workspace
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules/
.bazelbsp/
.vscode
.DS_Store
.bazelrc.user

# Bazel's MODULE lockfile isn't ready to check in yet as of Bazel 7.1.
# Do allow for it to be created, however, since it gives a performance boost for local development.
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ module(

# Lower-bounds (minimum) versions for direct runtime dependencies.
# Do not bump these unless rules_js requires a newer version to function.
bazel_dep(name = "aspect_bazel_lib", version = "2.14.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.21.0")
bazel_dep(name = "aspect_tools_telemetry", version = "0.2.8")
bazel_dep(name = "bazel_features", version = "1.9.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_nodejs", version = "6.3.0")
bazel_dep(name = "tar.bzl", version = "0.5.5")

tel = use_extension("@aspect_tools_telemetry//:extension.bzl", "telemetry")
use_repo(tel, "aspect_tools_telemetry_report")
Expand Down
2 changes: 0 additions & 2 deletions e2e/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ assert_contains(
name = "check_styles",
actual = "my.css",
expected = ".box,\n.bar {\n width: 100px;",
# assert_contains currently requires runfiles; needs fixing upstream
target_compatible_with = not_windows,
)

jasmine_bin.jasmine_test(
Expand Down
5 changes: 5 additions & 0 deletions examples/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ js_test(
],
entry_point = "test.js",
tags = ["skip-on-bazel8"],
# Error: could not resolve module aspect_rules_js/examples/runfiles/test_fixture.md
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

# Path of file must start similar to `test_fixture.md` in order to regression-test a
Expand Down
1 change: 1 addition & 0 deletions js/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package(default_visibility = ["//visibility:public"])
exports_files(glob(["*.bzl"]))

exports_files([
"js_binary.bat.tpl",
"js_binary.sh.tpl",
"node_wrapper.bat",
"node_wrapper.sh",
Expand Down
30 changes: 2 additions & 28 deletions js/private/bash.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
# NB: If this can be generalized fully in the future and not depend on logf_fatal
# then it could be hoisted to bazel-lib where we have other bash snippets.
BASH_INITIALIZE_RUNFILES = r"""
# It helps to determine if we are running on a Windows environment (excludes WSL as it acts like Unix)
case "$(uname -s)" in
CYGWIN*) _IS_WINDOWS=1 ;;
MINGW*) _IS_WINDOWS=1 ;;
MSYS_NT*) _IS_WINDOWS=1 ;;
*) _IS_WINDOWS=0 ;;
esac
# It helps to normalizes paths when running on Windows.
#
# Example:
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C
function _normalize_path {
if [ "$_IS_WINDOWS" -eq "1" ]; then
# Apply the followings paths transformations to normalize paths on Windows
# -process driver letter
# -convert path separator
sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' <<<"$1"
else
echo "$1"
fi
return
}
# Set a RUNFILES environment variable to the root of the runfiles tree
# since RUNFILES_DIR is not set by Bazel in all contexts.
# For example, `RUNFILES=/path/to/my_js_binary.sh.runfiles`.
Expand All @@ -57,9 +33,9 @@ function _normalize_path {
# Case 6a is handled like case 3.
if [ "${TEST_SRCDIR:-}" ]; then
# Case 4, bazel has identified runfiles for us.
RUNFILES=$(_normalize_path "$TEST_SRCDIR")
RUNFILES=$TEST_SRCDIR
elif [ "${RUNFILES_MANIFEST_FILE:-}" ]; then
RUNFILES=$(_normalize_path "$RUNFILES_MANIFEST_FILE")
RUNFILES=$RUNFILES_MANIFEST_FILE
if [[ "${RUNFILES}" == *.runfiles_manifest ]]; then
# Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest.
# For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the
Expand Down Expand Up @@ -105,8 +81,6 @@ else
logf_fatal "RUNFILES environment variable is not set"
exit 1
fi
RUNFILES=$(_normalize_path "$RUNFILES")
fi
if [ "${RUNFILES:0:1}" != "/" ]; then
# Ensure RUNFILES set above is an absolute path. It may be a path relative
Expand Down
142 changes: 142 additions & 0 deletions js/private/bat.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"Windows Batch snippets for js rules"

# TODO: Instead of setting a new RUNFILES env; just set RUNFILES_DIR if it is not set;
# needs testing to know if RUNFILES_DIR is set always set to the same value as RUNFILES
# when it is set.
# Batch snippet to initialize the RUNFILES environment variable.
# Depends on there being a logf_fatal function defined.
# NB: If this can be generalized fully in the future and not depend on logf_fatal
# then it could be hoisted to bazel-lib where we have other batch snippets.
BAT_INITIALIZE_RUNFILES = r"""
rem Initialize RUNFILES environment variable for Windows batch
rem This is the Windows batch equivalent of the bash runfiles initialization
:init_runfiles
rem Set a RUNFILES environment variable to the root of the runfiles tree
rem since RUNFILES_DIR is not set by Bazel in all contexts.
rem For example, `RUNFILES=C:\path\to\my_js_binary.bat.runfiles`.
rem
rem Call this program X. X was generated by a genrule and may be invoked
rem in many ways:
rem 1a) directly by a user, with %0 in the output tree
rem 1b) via 'bazel run' (similar to case 1a)
rem 2) directly by a user, with %0 in X's runfiles
rem 3) by another program Y which has a data dependency on X, with %0 in Y's
rem runfiles
rem 4a) via 'bazel test'
rem 4b) case 3 in the context of a test
rem 5a) by a genrule cmd, with %0 in the output tree
rem 6a) case 3 in the context of a genrule
rem
rem For case 1, %0 will be a regular file, and the runfiles will be
rem at %0.runfiles.
rem For case 2 or 3, %0 will be a symlink to the file seen in case 1.
rem For case 4, %TEST_SRCDIR% should already be set to the runfiles by
rem bazel.
rem Case 5a is handled like case 1.
rem Case 6a is handled like case 3.
if defined TEST_SRCDIR (
rem Case 4, bazel has identified runfiles for us.
set "RUNFILES=%TEST_SRCDIR%"
rem Convert forward slashes to backslashes
set "RUNFILES=!RUNFILES:/=\!"
) else if defined RUNFILES_MANIFEST_FILE (
set "RUNFILES=%RUNFILES_MANIFEST_FILE%"
rem Convert forward slashes to backslashes
set "RUNFILES=!RUNFILES:/=\!"
rem Check if RUNFILES ends with .runfiles_manifest
if "!RUNFILES:~-17!"==".runfiles_manifest" (
rem Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest.
rem For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the
rem runfiles directory and named my_binary.runfiles_manifest
set "RUNFILES=!RUNFILES:~0,-17!"
) else (
rem Check if RUNFILES ends with \MANIFEST
echo !RUNFILES! | findstr /c:"\MANIFEST" >nul
if !errorlevel! equ 0 (
rem Older versions of Bazel put the manifest file named MANIFEST in the runfiles directory
set "RUNFILES=!RUNFILES:\MANIFEST=!"
) else (
call :logf_fatal "Unexpected RUNFILES_MANIFEST_FILE value %RUNFILES_MANIFEST_FILE%"
exit /b 1
)
)
) else (
rem Determine the full path of the current script
set "self=%~f0"
:resolve_runfiles_loop
rem Check if .runfiles directory exists next to the script
if exist "!self!.runfiles" (
set "RUNFILES=!self!.runfiles"
goto :runfiles_found
)
rem Check if we're inside a .runfiles directory
echo !self! | findstr /c:".runfiles\" >nul
if !errorlevel! equ 0 (
rem Extract the runfiles directory path
for /f "tokens=1 delims=" %%a in ('echo !self! ^| findstr /o /c:".runfiles\"') do set "pos_info=%%a"
for /f "tokens=1 delims=:" %%b in ("!pos_info!") do set "pos=%%b"
set /a "end_pos=!pos!+9"
for /f %%c in ('echo !self! ^| findstr /c:".runfiles\"') do (
for /f "tokens=1 delims=\" %%d in ("%%c") do (
set "base_part=%%d"
)
)
rem Find the .runfiles directory by going back from current position
for /f "delims=" %%e in ('echo !self!') do (
set "temp_path=%%e"
for /f "tokens=1,* delims=\" %%f in ("!temp_path!") do (
if "%%g"=="" (
if exist "%%f.runfiles" set "RUNFILES=%%f.runfiles"
) else (
call :extract_runfiles_path "%%e"
)
)
)
rem This is a last resort for case 6b - don't exit the loop yet
)
rem For Windows, we don't need to resolve symlinks like in bash since
rem Windows batch files don't typically use symlinks in the same way
rem If we reach here and haven't found runfiles, we'll fail below
:runfiles_found
if not defined RUNFILES (
call :logf_fatal "RUNFILES environment variable is not set"
exit /b 1
)
rem Convert forward slashes to backslashes
set "RUNFILES=!RUNFILES:/=\!"
)
rem Ensure RUNFILES is an absolute path
echo !RUNFILES! | findstr "^[A-Za-z]:" >nul
if !errorlevel! neq 0 (
rem RUNFILES is not absolute, make it relative to current directory
set "RUNFILES=%CD%\!RUNFILES!"
)
goto :runfiles_init_done
:extract_runfiles_path
set "input_path=%~1"
rem Simple approach to find .runfiles directory in path
for /f "tokens=*" %%a in ('echo %input_path% ^| findstr /c:".runfiles"') do (
set "temp=%%a"
for /f "tokens=1 delims=\" %%b in ('echo !temp! ^| findstr /o /c:".runfiles"') do (
set "match_info=%%b"
for /f "tokens=1 delims=:" %%c in ("!match_info!") do (
set "match_pos=%%c"
set /a "runfiles_end=!match_pos!+8"
set "RUNFILES=!input_path:~0,%runfiles_end%!"
)
)
)
exit /b 0
:runfiles_init_done
"""
Loading