Migrate plugin and test builds to current Gerrit tooling

The frontend build still references legacy TypeScript rules, npm
repository labels and a compiler target that no longer exists in
Gerrit. It also imports polygerrit_plugin from Gerrit after that macro
moved to Bazlets.

Load polygerrit_plugin from Bazlets and use aspect_rules_ts for both
production and test sources. Replace the old npm labels with Gerrit's
linked node_modules targets and remove the obsolete compiler overrides.

Use the copied base tsconfig and set rootDir to the web directory,
leaving output directory selection to the Bazel targets.

Also remove not needed playbooks/setup-package.yaml file.

Change-Id: Id2e3ad4f9a780331c1d213d890e86abc3a71882b
diff --git a/.zuul.yaml b/.zuul.yaml
index e75e16f..0fd481d 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -5,7 +5,6 @@
       bazelisk_artifacts:
         - "bazel-bin/plugins/{{ gerrit_plugin }}/{{ gerrit_plugin }}.js"
       bazelisk_test_targets: ""
-    pre-run: playbooks/setup-package.yaml
 
 - project:
     description: |
diff --git a/BUILD b/BUILD
index 067f856..325401f 100644
--- a/BUILD
+++ b/BUILD
@@ -1,4 +1,4 @@
-load("//tools/bzl:js.bzl", "polygerrit_plugin")
+load("@com_googlesource_gerrit_bazlets//js:defs.bzl", "polygerrit_plugin")
 
 polygerrit_plugin(
     name = "image-diff",
diff --git a/playbooks/setup-package.yaml b/playbooks/setup-package.yaml
deleted file mode 100644
index cb20107..0000000
--- a/playbooks/setup-package.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-- hosts: all
-  tasks:
-    - name: symlink
-      command: "cp -f plugins/image-diff/package.json plugins/package.json"
-      args:
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/{{ zuul.projects["gerrit.googlesource.com/gerrit"].src_dir }}'
diff --git a/web/BUILD b/web/BUILD
index 01494fc..0c0f505 100644
--- a/web/BUILD
+++ b/web/BUILD
@@ -1,5 +1,6 @@
-load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
-load("//tools/bzl:js.bzl", "gerrit_js_bundle", "web_test_runner")
+load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
+load("@com_googlesource_gerrit_bazlets//js:defs.bzl", "gerrit_js_bundle")
+load("//tools/bzl:js.bzl", "web_test_runner")
 load("//tools/js:eslint.bzl", "plugin_eslint")
 
 package_group(
@@ -13,7 +14,7 @@
     name = "tsconfig",
     src = "tsconfig.json",
     deps = [
-        "//plugins:tsconfig-plugins-base.json",
+        "//plugins:tsconfig-plugins-base",
     ],
 )
 
@@ -25,11 +26,9 @@
     ),
     incremental = True,
     out_dir = "_bazel_ts_out",
-    tsc = "//tools/node_tools:tsc-bin",
     tsconfig = ":tsconfig",
     deps = [
-        "@plugins_npm//@gerritcodereview/typescript-api",
-        "@plugins_npm//lit",
+        "//plugins:node_modules",
     ],
 )
 
@@ -38,12 +37,11 @@
     srcs = glob(["**/*.ts"]),
     incremental = True,
     out_dir = "_bazel_ts_out_tests",
-    tsc = "//tools/node_tools:tsc-bin",
     tsconfig = ":tsconfig",
     visibility = ["//visibility:public"],
     deps = [
-        "@plugins_npm//:node_modules",
-        "@ui_dev_npm//:node_modules",
+        "//plugins:node_modules",
+        "//polygerrit-ui:node_modules",
     ],
 )
 
@@ -54,13 +52,13 @@
 )
 
 web_test_runner(
-    name = "karma_test",
-    srcs = ["karma_test.sh"],
+    name = "web_test_runner",
+    srcs = ["web_test_runner.sh"],
     data = [
         ":image-diff-ts-tests",
         ":tsconfig",
-        "@plugins_npm//:node_modules",
-        "@ui_dev_npm//:node_modules",
+        "//plugins:node_modules",
+        "//polygerrit-ui:node_modules",
     ],
 )
 
diff --git a/web/karma_test.sh b/web/karma_test.sh
deleted file mode 100755
index 8d4a34d..0000000
--- a/web/karma_test.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-export PATH="/opt/homebrew/bin:$PATH"
-set -euo pipefail
-./$1 --config $2 \
-  --test-files 'plugins/image-diff/web/_bazel_ts_out_tests/**/*_test.js' \
-  --ts-config="plugins/image-diff/web/tsconfig.json"
diff --git a/web/tsconfig.json b/web/tsconfig.json
index d8ebe28..65940e1 100644
--- a/web/tsconfig.json
+++ b/web/tsconfig.json
@@ -1,7 +1,7 @@
 {
   "extends": "../../tsconfig-plugins-base.json",
   "compilerOptions": {
-    "outDir": "../../../.ts-out/plugins/image-diff" /* overridden by bazel */
+    "rootDir": "."
   },
   "include": [
     "**/*.ts"
diff --git a/web/web_test_runner.sh b/web/web_test_runner.sh
new file mode 100755
index 0000000..3358b63
--- /dev/null
+++ b/web/web_test_runner.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -euo pipefail
+./$1 --config $2 \
+  --dir 'plugins/image-diff/web/_bazel_ts_out_tests' \
+  --test-files 'plugins/image-diff/web/_bazel_ts_out_tests/*_test.js' \
+  --ts-config="plugins/image-diff/web/tsconfig.json"