Migrate from rules_nodejs to rules_js
This patch is huge because I can't easily break it into smaller
pieces. This is largely because a few things are changing with the
migration.
Firstly, we're upgrading the angular libraries and our version of
typescript. This is actually not too disruptive. It required some
changes in the top-level `package.json` file.
Secondly, the new rules have this concept of copying everything into
the `bazel-bin` directory and executing out of there. This makes the
various tools like node and angular happy, but means that a few file
paths are changing. For example, the `common.css` file can't have the
same path in the source tree as it does in the `bazel-bin` tree, so I
moved it to a `common` directory inside the `bazel-bin` tree. You can
read more about this here:
https://docs.aspect.build/rules/aspect_rules_js#running-nodejs-programs
Thirdly, I couldn't find a simple way to support Protractor in
rules_js. Protractor is the end-to-end testing framework we use for
the scouting application. Since protractor is getting deprecated and
won't receive any more updates, it's time to move to something else.
We settled on Cypress because it appears to be popular and should make
debugging easier for the students. For example, it takes screenshots
of the browser when an assertion fails. It would have been ideal to
switch to Cypress before this migration, but I couldn't find a simple
way to make that work with rules_nodejs. In other words, this
migration patch is huge in part because we are also switching testing
frameworks at the same time. I wanted to split it out, but it was more
difficult than I would have liked.
Fourthly, I also needed to migrate the flatbuffer rules. This I think
is relatively low impact, but it again means that this patch is bigger
than I wanted it to be.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I6674874f985952f2e3ef40274da0a2fb9e5631a7
diff --git a/third_party/flatbuffers/BUILD.bazel b/third_party/flatbuffers/BUILD.bazel
index 6f92eec..657ec86 100644
--- a/third_party/flatbuffers/BUILD.bazel
+++ b/third_party/flatbuffers/BUILD.bazel
@@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
+load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
licenses(["notice"])
@@ -6,6 +7,16 @@
default_visibility = ["//visibility:public"],
)
+npm_link_package(
+ name = "node_modules/flatbuffers",
+ src = "@com_github_google_flatbuffers//ts:flatbuffers",
+)
+
+npm_link_package(
+ name = "node_modules/flatbuffers_reflection",
+ src = "@com_github_google_flatbuffers//reflection:flatbuffers_reflection",
+)
+
exports_files([
"LICENSE",
"tsconfig.json",
diff --git a/third_party/flatbuffers/build_defs.bzl b/third_party/flatbuffers/build_defs.bzl
index 90eb77c..c1e568f 100644
--- a/third_party/flatbuffers/build_defs.bzl
+++ b/third_party/flatbuffers/build_defs.bzl
@@ -8,8 +8,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust//rust:rust_common.bzl", "CrateInfo")
-load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
-load("@npm//@bazel/typescript:index.bzl", "ts_project")
+load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@rules_cc//cc:defs.bzl", "cc_library")
flatc_path = "@com_github_google_flatbuffers//:flatc"
diff --git a/third_party/flatbuffers/reflection/BUILD.bazel b/third_party/flatbuffers/reflection/BUILD.bazel
index 6e50dc4..1d58bb3 100644
--- a/third_party/flatbuffers/reflection/BUILD.bazel
+++ b/third_party/flatbuffers/reflection/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("//:build_defs.bzl", "flatbuffer_rust_library")
load("//:typescript.bzl", "flatbuffer_ts_library")
@@ -9,12 +10,19 @@
flatbuffer_ts_library(
name = "reflection_ts_fbs",
- package_name = "flatbuffers_reflection",
srcs = ["reflection.fbs"],
include_reflection = False,
visibility = ["//visibility:public"],
)
+npm_package(
+ name = "flatbuffers_reflection",
+ srcs = [":reflection_ts_fbs_ts"],
+ include_external_repositories = ["*"],
+ package = "flatbuffers_reflection",
+ visibility = ["//visibility:public"],
+)
+
flatbuffer_rust_library(
name = "reflection_rust_fbs",
srcs = ["reflection.fbs"],
diff --git a/third_party/flatbuffers/ts/BUILD.bazel b/third_party/flatbuffers/ts/BUILD.bazel
index 6e8a10b..5f78892 100644
--- a/third_party/flatbuffers/ts/BUILD.bazel
+++ b/third_party/flatbuffers/ts/BUILD.bazel
@@ -1,5 +1,6 @@
-load("@npm//@bazel/typescript:index.bzl", "ts_project")
-load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
+load("@aspect_rules_js//js:defs.bzl", "js_library")
+load("@aspect_rules_js//npm:defs.bzl", "npm_package")
ts_project(
name = "flatbuffers_ts",
@@ -28,12 +29,13 @@
},
},
visibility = ["//visibility:public"],
- deps = ["@npm//@types/node"],
+ deps = ["@//:node_modules/@types/node"],
)
-js_library(
+npm_package(
name = "flatbuffers",
- package_name = "flatbuffers",
+ srcs = [":flatbuffers_ts"],
+ include_external_repositories = ["*"],
+ package = "flatbuffers",
visibility = ["//visibility:public"],
- deps = [":flatbuffers_ts"],
)
diff --git a/third_party/flatbuffers/typescript.bzl b/third_party/flatbuffers/typescript.bzl
index 39c1e04..f00c550 100644
--- a/third_party/flatbuffers/typescript.bzl
+++ b/third_party/flatbuffers/typescript.bzl
@@ -2,8 +2,8 @@
Rules for building typescript flatbuffers with Bazel.
"""
-load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
-load("@npm//@bazel/typescript:index.bzl", "ts_project")
+load("@aspect_rules_js//js:defs.bzl", "js_library")
+load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load(":build_defs.bzl", "DEFAULT_INCLUDE_PATHS", "flatbuffer_library_public")
DEFAULT_FLATC_TS_ARGS = [
@@ -93,6 +93,7 @@
compatible_with = compatible_with,
restricted_to = restricted_to,
target_compatible_with = target_compatible_with,
+ supports_workers = False,
tsconfig = {
"compilerOptions": {
"declaration": True,
@@ -107,7 +108,12 @@
"types": ["node"],
},
},
- deps = deps + ["@com_github_google_flatbuffers//ts:flatbuffers"] + (["@com_github_google_flatbuffers//reflection:reflection_ts_fbs"] if include_reflection else []),
+ deps = deps + [
+ "@//:node_modules/flatbuffers",
+ # TODO(phil): Figure out why @types/node isn't being picked up as a
+ # transitivie dependencies.
+ "@//:node_modules/@types/node",
+ ] + (["@//:node_modules/flatbuffers_reflection"] if include_reflection else []),
)
js_library(
name = name,
@@ -115,8 +121,7 @@
compatible_with = compatible_with,
restricted_to = restricted_to,
target_compatible_with = target_compatible_with,
- deps = [name + "_ts"],
- package_name = package_name,
+ srcs = [name + "_ts"],
)
native.filegroup(
name = "%s_includes" % (name),
diff --git a/third_party/rules_rollup/0001-Fix-resolving-files.patch b/third_party/rules_rollup/0001-Fix-resolving-files.patch
new file mode 100644
index 0000000..a81a656
--- /dev/null
+++ b/third_party/rules_rollup/0001-Fix-resolving-files.patch
@@ -0,0 +1,24 @@
+From fd6dd080ea58fd71c70ce2303873feab1abda760 Mon Sep 17 00:00:00 2001
+From: Philipp Schrader <philipp.schrader@gmail.com>
+Date: Sun, 19 Feb 2023 14:18:11 -0800
+Subject: [PATCH] Fix resolving files
+
+I don't really know what the underlying problem is, but returning a
+File instead of a path is causing us grief.
+---
+ rollup/private/rollup_bundle.bzl | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/rollup/private/rollup_bundle.bzl b/rollup/private/rollup_bundle.bzl
+index 32aaad4..a2061dd 100644
+--- a/rollup/private/rollup_bundle.bzl
++++ b/rollup/private/rollup_bundle.bzl
+@@ -186,7 +186,7 @@ def _resolve_js_input(f, inputs):
+ for i in inputs:
+ if i.extension == "js" or i.extension == "mjs":
+ if _no_ext(i) == no_ext:
+- return i
++ return i.short_path
+ fail("Could not find corresponding javascript entry point for %s. Add the %s.js to your deps." % (f.path, no_ext))
+
+ def _rollup_outs(sourcemap, name, entry_point, entry_points, output_dir):
diff --git a/third_party/rules_webtesting/rules_webtesting.patch b/third_party/rules_webtesting/rules_webtesting.patch
deleted file mode 100644
index 90b7716..0000000
--- a/third_party/rules_webtesting/rules_webtesting.patch
+++ /dev/null
@@ -1,56 +0,0 @@
-diff --git a/BUILD.bazel b/BUILD.bazel
-index ab52bbb..5f9f4c3 100644
---- a/BUILD.bazel
-+++ b/BUILD.bazel
-@@ -24,3 +24,17 @@ gazelle(
- name = "gazelle",
- prefix = "github.com/bazelbuild/rules_webtesting",
- )
-+
-+genrule(
-+ name = "generate_error_bin",
-+ outs = ["error_bin.sh"],
-+ cmd = "echo 'exit 1' > $(OUTS)",
-+ executable = True,
-+)
-+
-+sh_binary(
-+ name = "error_bin",
-+ srcs = ["error_bin.sh"],
-+ visibility = ["//visibility:public"],
-+ target_compatible_with = ["@platforms//:incompatible"],
-+)
-diff --git a/third_party/chromedriver/BUILD.bazel b/third_party/chromedriver/BUILD.bazel
-index 3d794d4..3644474 100644
---- a/third_party/chromedriver/BUILD.bazel
-+++ b/third_party/chromedriver/BUILD.bazel
-@@ -30,6 +30,7 @@ alias(
- "//common/conditions:macos_x64": "@org_chromium_chromedriver_macos_x64//:metadata",
- "//common/conditions:macos_arm64": "@org_chromium_chromedriver_macos_arm64//:metadata",
- "//common/conditions:windows_x64": "@org_chromium_chromedriver_windows_x64//:metadata",
-+ "//conditions:default": "//:error_bin",
- }),
- visibility = ["//browsers:__subpackages__"],
- )
-diff --git a/third_party/chromium/BUILD.bazel b/third_party/chromium/BUILD.bazel
-index 6d8c6e0..7702fb9 100644
---- a/third_party/chromium/BUILD.bazel
-+++ b/third_party/chromium/BUILD.bazel
-@@ -26,6 +26,7 @@ alias(
- "//common/conditions:macos_x64": "@org_chromium_chromium_macos_x64//:metadata",
- "//common/conditions:macos_arm64": "@org_chromium_chromium_macos_arm64//:metadata",
- "//common/conditions:windows_x64": "@org_chromium_chromium_windows_x64//:metadata",
-+ "//conditions:default": "//:error_bin",
- }),
- visibility = ["//browsers:__subpackages__"],
- )
-diff --git a/web/internal/executable_name.bzl b/web/internal/executable_name.bzl
-index b103868..12df0cc 100644
---- a/web/internal/executable_name.bzl
-+++ b/web/internal/executable_name.bzl
-@@ -26,4 +26,5 @@ def get_platform_executable_name():
- "//common/conditions:macos_x64": "main_darwin_x64",
- "//common/conditions:macos_arm64": "main_darwin_arm64",
- "//common/conditions:windows_x64": "main_windows_x64.exe",
-+ "//conditions:default": "//:error_bin",
- })