Skip to content

Commit

Permalink
Migrate to aspect_rules_js
Browse files Browse the repository at this point in the history
Also builds the Grid UI using `esbuild`.

The weird imports in the Grid UI are due to an issue with the way that
`esbuild` interacts with `@mui/material-icons`:

mui/material-ui#31835 (comment)
  • Loading branch information
shs96c committed Feb 22, 2024
1 parent 93c7804 commit fad1cb4
Show file tree
Hide file tree
Showing 46 changed files with 16,211 additions and 35,985 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ dotnet/src/webdriver/obj
java/build/production
java/client/build
java/server/build
javascript/grid-ui/node_modules
javascript/node/selenium-webdriver/node_modules
node_modules
11 changes: 10 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ build --javacopt="--release 11"
build --experimental_strict_java_deps=strict
build --explicit_java_test_deps

# Required for faster TS builds
build --@aspect_rules_ts//ts:skipLibCheck=always
fetch --@aspect_rules_ts//ts:skipLibCheck=always
query --@aspect_rules_ts//ts:skipLibCheck=always

build --@aspect_rules_ts//ts:default_to_tsc_transpiler
fetch --@aspect_rules_ts//ts:default_to_tsc_transpiler
query --@aspect_rules_ts//ts:default_to_tsc_transpiler

# Ensure builds are unpolluted by the user env

build --incompatible_strict_action_env
Expand Down Expand Up @@ -94,7 +103,7 @@ build:remote --remote_cache=grpcs://gypsum.cluster.engflow.com
build:remote -j 50

# Build Without The Bytes
build:remote --remote_download_outputs=minimal
build:remote --remote_download_minimal

build:remote --define=EXECUTOR=remote
build:remote --experimental_inmemory_dotd_files
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ junitvmwatcher*.properties
test-output/
.*.swp
*~
.aspect/
common/build
/build/
cpp/iedriver/IEReturnTypes.h
Expand Down
6 changes: 6 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules). See
# https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock
# documentation for more information.
hoist=false
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//common:browsers.bzl", "chrome_data", "firefox_data")
load("//java:browsers.bzl", "chrome_jvm_flags", "firefox_jvm_flags")
load("//java:defs.bzl", "artifact")

exports_files([
"package.json",
"pnpm-workspace.yaml",
])

npm_link_all_packages(name = "node_modules")

filegroup(
name = "license",
srcs = [
Expand Down
82 changes: 71 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ load("@maven//:defs.bzl", "pinned_maven_install")

pinned_maven_install()

# Stop `aspect_rules_js` and `rules_dotnet` from fighting over `aspect_bazel_lib`
http_archive(
name = "aspect_bazel_lib",
sha256 = "4d6010ca5e3bb4d7045b071205afa8db06ec11eb24de3f023d74d77cca765f66",
strip_prefix = "bazel-lib-1.39.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.39.0/bazel-lib-v1.39.0.tar.gz",
)

http_archive(
name = "rules_dotnet",
sha256 = "d01b0f44e58224deeb8ac81afe8701385d41b16c8028709d3a4ed5b46f1c48a0",
Expand Down Expand Up @@ -220,26 +228,78 @@ load("@crates//:defs.bzl", "crate_repositories")
crate_repositories()

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "709cc0dcb51cf9028dd57c268066e5bc8f03a119ded410a13b5c3925d6e43c48",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.4/rules_nodejs-5.8.4.tar.gz"],
name = "aspect_rules_js",
sha256 = "a2f941e27f02e84521c2d47fd530c66d57dd6d6e44b4a4f1496fe304851d8e48",
strip_prefix = "rules_js-1.35.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.35.0/rules_js-v1.35.0.tar.gz",
)

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

build_bazel_rules_nodejs_dependencies()
rules_js_dependencies()

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

node_repositories(
nodejs_register_toolchains(
name = "nodejs",
node_version = "18.17.0",
)

npm_install(
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
symlink_node_modules = False,
data = [
"@//:package.json",
"@//:pnpm-workspace.yaml",
"@//javascript/grid-ui:package.json",
"@//javascript/node/selenium-webdriver:package.json",
],
generate_bzl_library_targets = True,
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
update_pnpm_lock = True,
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()

http_archive(
name = "aspect_rules_ts",
sha256 = "bd3e7b17e677d2b8ba1bac3862f0f238ab16edb3e43fb0f0b9308649ea58a2ad",
strip_prefix = "rules_ts-2.1.0",
url = "https://github.com/aspect-build/rules_ts/releases/download/v2.1.0/rules_ts-v2.1.0.tar.gz",
)

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(
ts_version = "4.9.5",
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

http_archive(
name = "aspect_rules_esbuild",
sha256 = "999349afef62875301f45ec8515189ceaf2e85b1e67a17e2d28b95b30e1d6c0b",
strip_prefix = "rules_esbuild-0.18.0",
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.18.0/rules_esbuild-v0.18.0.tar.gz",
)

load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")

rules_esbuild_dependencies()

# Register a toolchain containing esbuild npm package and native bindings
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")

esbuild_register_toolchains(
name = "esbuild",
esbuild_version = "0.19.9",
)

http_archive(
Expand Down
15 changes: 14 additions & 1 deletion java/src/org/openqa/selenium/grid/commands/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,20 @@ protected Handlers createHandlers(Config config) {
httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck));
Node node = createNode(config, bus, distributor, combinedHandler);

return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node, subPath));
HttpHandler delegate = httpHandler;

HttpHandler loggingHandler = req -> {
try {
HttpResponse res = delegate.execute(req);
LOG.info(String.format("%s %s -> %s", req.getMethod(), req.getUri(), res.getStatus()));
return res;
} catch (RuntimeException e) {
LOG.info(String.format("%s %s -> %s", req.getMethod(), req.getUri(), e.getMessage()));
throw e;
}
};

return new Handlers(loggingHandler, new ProxyNodeWebsockets(clientFactory, node, subPath));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
}

String query = (String) inputs.get("query");

@SuppressWarnings("unchecked")
Map<String, Object> variables =
inputs.get("variables") instanceof Map
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/grid/web/GridUiRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GridUiRoute implements Routable {

private static final Logger LOG = Logger.getLogger("selenium");

private static final String GRID_RESOURCE = "javascript/grid-ui/build";
private static final String GRID_RESOURCE = "grid-ui";
private static final String GRID_RESOURCE_WITH_PREFIX = String.format("/%s", GRID_RESOURCE);

private final Route routes;
Expand All @@ -50,7 +50,7 @@ public GridUiRoute(String prefix) {
if (uiRoot != null) {
ResourceHandler uiHandler = new ResourceHandler(new ClassPathResource(uiRoot, GRID_RESOURCE));
HttpResponse uiRedirect =
new HttpResponse().setStatus(HTTP_MOVED_TEMP).addHeader("Location", prefix.concat("/ui"));
new HttpResponse().setStatus(HTTP_MOVED_TEMP).addHeader("Location", prefix.concat("/ui/"));

Supplier<HttpHandler> redirectHandler = () -> req -> uiRedirect;

Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/grid/web/NoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.net.MediaType.JSON_UTF_8;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openqa.selenium.remote.ErrorCodes.UNKNOWN_COMMAND;
import static org.openqa.selenium.remote.http.Contents.bytes;

import com.google.common.collect.ImmutableMap;
Expand All @@ -47,7 +46,6 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
// We're not using ImmutableMap for the outer map because it disallows null values.
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("sessionId", null);
responseMap.put("status", UNKNOWN_COMMAND);
responseMap.put(
"value",
ImmutableMap.of(
Expand Down
17 changes: 17 additions & 0 deletions javascript/grid-ui/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"jsc": {
"baseUrl": "./src",
"parser": {
"jsx": true,
"syntax": "ecmascript"
},
"transform": {
"react": {
"runtime": "automatic"
}
}
},
"module": {
"type": "commonjs"
}
}
Loading

0 comments on commit fad1cb4

Please sign in to comment.