Skip to content

Commit 1316586

Browse files
[build] Fix Bazel JSDocs implementation (#16949)
* [build] fix bazel jsdocs implementation --------- Co-authored-by: Copilot <[email protected]>
1 parent 9df0888 commit 1316586

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

javascript/private/jsdoc.bzl

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,77 @@
1-
"""Rule for running jsdoc using Bazel-managed Node.js."""
1+
"""Rule for running jsdoc using Bazel-managed Node.js.
2+
3+
This rule creates a wrapper script that:
4+
1. Runs jsdoc from the bazel-managed npm package
5+
2. Outputs to the workspace build directory
6+
3. Ignores jsdoc exit code (it exits 1 on type warnings) but verifies output was generated
7+
"""
28

39
def _jsdoc_impl(ctx):
10+
jsdoc_bin = ctx.attr.jsdoc_binary[DefaultInfo].files_to_run.executable
411
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
512

613
if is_windows:
714
script = ctx.actions.declare_file(ctx.label.name + ".bat")
815
ctx.actions.write(script, _WINDOWS_TEMPLATE.format(
916
config = ctx.file.config.basename,
17+
jsdoc_bin = jsdoc_bin.short_path.replace("/", "\\\\"),
1018
), is_executable = True)
1119
else:
1220
script = ctx.actions.declare_file(ctx.label.name + ".sh")
1321
ctx.actions.write(script, _UNIX_TEMPLATE.format(
1422
config = ctx.file.config.basename,
23+
jsdoc_bin = jsdoc_bin.short_path,
1524
), is_executable = True)
1625

1726
runfiles = ctx.runfiles(files = ctx.files.data + [ctx.file.config])
27+
runfiles = runfiles.merge(ctx.attr.jsdoc_binary[DefaultInfo].default_runfiles)
1828
return [DefaultInfo(executable = script, runfiles = runfiles)]
1929

2030
_UNIX_TEMPLATE = """#!/usr/bin/env bash
2131
set -euo pipefail
2232
cd "$BUILD_WORKSPACE_DIRECTORY/javascript/selenium-webdriver"
23-
exec "$BUILD_WORKSPACE_DIRECTORY/bazel-selenium/javascript/selenium-webdriver/node_modules/.bin/jsdoc" \\
24-
--configure {config} "$@"
33+
DEST="$BUILD_WORKSPACE_DIRECTORY/build/docs/api/javascript"
34+
TEMPLATE="$0.runfiles/_main/javascript/selenium-webdriver/node_modules/clean-jsdoc-theme"
35+
36+
# Set BAZEL_BINDIR to suppress rules_js error for non-build actions
37+
export BAZEL_BINDIR="."
38+
39+
# Clean destination to prevent stale files
40+
rm -rf "$DEST"
41+
mkdir -p "$DEST"
42+
43+
# Run jsdoc - ignore exit code since it fails on type warnings
44+
"$0.runfiles/_main/{jsdoc_bin}" --configure {config} --destination "$DEST" --template "$TEMPLATE" "$@" || true
45+
46+
# Verify docs were generated
47+
if [[ -f "$DEST/index.html" ]]; then
48+
echo "Documentation generated successfully at $DEST"
49+
else
50+
echo "ERROR: Documentation was not generated"
51+
exit 1
52+
fi
2553
"""
2654

2755
_WINDOWS_TEMPLATE = """@echo off
2856
cd /d "%BUILD_WORKSPACE_DIRECTORY%\\javascript\\selenium-webdriver"
29-
"%BUILD_WORKSPACE_DIRECTORY%\\bazel-selenium\\javascript\\selenium-webdriver\\node_modules\\.bin\\jsdoc" ^
30-
--configure {config} %*
57+
set DEST=%BUILD_WORKSPACE_DIRECTORY%\\build\\docs\\api\\javascript
58+
set TEMPLATE=%~dp0.runfiles\\_main\\javascript\\selenium-webdriver\\node_modules\\clean-jsdoc-theme
59+
set BAZEL_BINDIR=.
60+
61+
if exist "%DEST%" rmdir /s /q "%DEST%"
62+
mkdir "%DEST%"
63+
64+
"%~dp0.runfiles\\_main\\{jsdoc_bin}" --configure {config} --destination "%DEST%" --template "%TEMPLATE%" %*
65+
if %ERRORLEVEL% neq 0 (
66+
echo jsdoc exited with warnings, checking output...
67+
)
68+
69+
if exist "%DEST%\\index.html" (
70+
echo Documentation generated successfully at %DEST%
71+
) else (
72+
echo ERROR: Documentation was not generated
73+
exit /b 1
74+
)
3175
"""
3276

3377
jsdoc = rule(
@@ -41,6 +85,12 @@ jsdoc = rule(
4185
"data": attr.label_list(
4286
allow_files = True,
4387
),
88+
"jsdoc_binary": attr.label(
89+
mandatory = True,
90+
executable = True,
91+
cfg = "target",
92+
doc = "The jsdoc binary target from npm",
93+
),
4494
"_windows_constraint": attr.label(
4595
default = "@platforms//os:windows",
4696
),

javascript/selenium-webdriver/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@aspect_rules_js//js:defs.bzl", "js_library")
33
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
44
load("@npm//:defs.bzl", "npm_link_all_packages")
55
load("@npm//javascript/selenium-webdriver:eslint/package_json.bzl", eslint_bin = "bin")
6+
load("@npm//javascript/selenium-webdriver:jsdoc/package_json.bzl", jsdoc_bin = "bin")
67
load("@npm//javascript/selenium-webdriver:prettier/package_json.bzl", prettier_bin = "bin")
78
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
89
load("//common:defs.bzl", "copy_file")
@@ -286,11 +287,21 @@ copy_to_bin(
286287
srcs = [".prettierignore"],
287288
)
288289

290+
# Internal jsdoc binary from npm - used by the docs rule
291+
jsdoc_bin.jsdoc_binary(
292+
name = "jsdoc_bin",
293+
visibility = ["//visibility:private"],
294+
)
295+
296+
# Documentation generator that wraps jsdoc and handles:
297+
# - Output to workspace build directory
298+
# - Ignoring jsdoc type warning exit codes
289299
jsdoc(
290300
name = "docs",
291301
config = "jsdoc_conf.json",
292302
data = [
293303
":node_modules/clean-jsdoc-theme",
294304
":prod-src-files",
295305
],
306+
jsdoc_binary = ":jsdoc_bin",
296307
)

javascript/selenium-webdriver/bidi/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Storage {
4444
*
4545
* @param {CookieFilter} [filter] - The filter to apply to the cookies.
4646
* @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to retrieve cookies from.
47-
* @returns {Promise<{ cookies: Cookie[], partitionKey?: PartitionKey }>} - A promise that resolves to an object containing the retrieved cookies and an optional partition key.
47+
* @returns {Promise<{ cookies: Cookie[], partitionKey: (PartitionKey|undefined) }>} - A promise that resolves to an object containing the retrieved cookies and an optional partition key.
4848
* @throws {Error} If the filter parameter is provided but is not an instance of CookieFilter.
4949
* @throws {Error} If the partition parameter is provided but is not an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor.
5050
*/

0 commit comments

Comments
 (0)