Skip to content

Commit 6a43b08

Browse files
authored
Migrate to Aspect Typescript and Javascript rules. (#104)
* Migrate to Aspect Typescript and Javascript rules. * Add Renovate configuration (#102) * Install pnpm and libnss3-dev in image. (#105) * Migrate from npm to pnpm. Fix dependency paths for external modules. * Include transitive runfiles in NODE_PATH * Remove stale reference to _node_paths
1 parent 6197aca commit 6a43b08

File tree

13 files changed

+567
-1360
lines changed

13 files changed

+567
-1360
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_gazelle//:def.bzl", "gazelle")
2+
load("@npm//:defs.bzl", "npm_link_all_packages")
23
load("@io_bazel_rules_go//go:def.bzl", "TOOLS_NOGO", "nogo")
34
load("@rules_pkg//:pkg.bzl", "pkg_zip")
45

@@ -51,6 +52,8 @@ exports_files([
5152
"package-lock.json",
5253
])
5354

55+
npm_link_all_packages(name = "node_modules")
56+
5457
pkg_zip(
5558
name = "chrome-ssh-agent",
5659
srcs = [

WORKSPACE

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ http_archive(
1919
)
2020

2121
http_archive(
22-
name = "build_bazel_rules_nodejs",
23-
sha256 = "ee3280a7f58aa5c1caa45cb9e08cbb8f4d74300848c508374daf37314d5390d6",
24-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.1/rules_nodejs-5.5.1.tar.gz"],
22+
name = "aspect_rules_js",
23+
sha256 = "9fadde0ae6e0101755b8aedabf7d80b166491a8de297c60f6a5179cd0d0fea58",
24+
strip_prefix = "rules_js-1.20.0",
25+
url = "https://github.com/aspect-build/rules_js/releases/download/v1.20.0/rules_js-v1.20.0.tar.gz",
26+
)
27+
28+
http_archive(
29+
name = "aspect_rules_ts",
30+
sha256 = "db77d904284d21121ae63dbaaadfd8c75ff6d21ad229f92038b415c1ad5019cc",
31+
strip_prefix = "rules_ts-1.3.0",
32+
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.3.0/rules_ts-v1.3.0.tar.gz",
33+
)
34+
35+
http_archive(
36+
name = "aspect_rules_esbuild",
37+
sha256 = "3e074ee7be579ceb4f0a664f6ae88fa68926e8eec65ffa067624c5d98c9552f6",
38+
strip_prefix = "rules_esbuild-0.13.5",
39+
url = "https://github.com/aspect-build/rules_esbuild/archive/refs/tags/v0.13.5.tar.gz",
2540
)
2641

2742
http_archive(
@@ -124,25 +139,47 @@ go_dependencies()
124139

125140
gazelle_dependencies()
126141

127-
# NodeJS support. Required for testing and publishing.
128-
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
142+
# Javascript support.
143+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
129144

130-
build_bazel_rules_nodejs_dependencies()
145+
rules_js_dependencies()
131146

132-
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
147+
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "node_repositories", "nodejs_register_toolchains")
148+
149+
nodejs_register_toolchains(
150+
name = "nodejs",
151+
node_version = DEFAULT_NODE_VERSION,
152+
)
133153

134-
node_repositories()
154+
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
135155

136-
npm_install(
156+
npm_translate_lock(
137157
name = "npm",
138-
package_json = "//:package.json",
139-
package_lock_json = "//:package-lock.json",
158+
pnpm_lock = "//:pnpm-lock.yaml",
159+
verify_node_modules_ignored = "//:.bazelignore",
140160
)
141161

142-
# Enable esbuild for merging Javascript/Typescript.
143-
load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories")
162+
load("@npm//:repositories.bzl", "npm_repositories")
144163

145-
esbuild_repositories(npm_repository = "npm")
164+
npm_repositories()
165+
166+
# Typescript support.
167+
load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")
168+
169+
rules_ts_dependencies(ts_version = LATEST_VERSION)
170+
171+
# esbuild support.
172+
173+
load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")
174+
175+
rules_esbuild_dependencies()
176+
177+
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains")
178+
179+
esbuild_register_toolchains(
180+
name = "esbuild",
181+
esbuild_version = LATEST_VERSION,
182+
)
146183

147184
# Skylib for helpful utilities in custom rules.
148185

build_defs/wasm.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@io_bazel_rules_go//go/private:providers.bzl", "GoLibrary", "GoPath", "GoA
22
load("@io_bazel_rules_go//go:def.bzl", "go_test", "go_library", "go_binary")
33
load("@bazel_skylib//lib:paths.bzl", "paths")
44

5+
56
def _go_wasm_test_impl(ctx):
67
node_info = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
78
node_path = node_info.target_tool_path
@@ -16,8 +17,7 @@ def _go_wasm_test_impl(ctx):
1617
'#!/bin/bash -eu',
1718
# Ensure 'node' binary is on the PATH.
1819
'export PATH="${{PWD}}/{0}:${{PATH}}"'.format(paths.dirname(node_path)),
19-
# TODO: Replace with proper way to discover directory
20-
'export NODE_PATH="${PWD}/external/npm/node_modules"',
20+
'export NODE_PATH="${PWD}/node_modules"',
2121
# Wrapping executes a subprocess and uses pipe() for communication;
2222
# pipe() is unsupported under node.js and WASM.
2323
'export GO_TEST_WRAP=0',
@@ -31,8 +31,10 @@ def _go_wasm_test_impl(ctx):
3131

3232
runfiles = ctx.runfiles(files=(
3333
[runner, test_executable, ctx.executable.run_wasm]
34-
+ node_inputs + ctx.files.node_deps
34+
+ node_inputs
3535
))
36+
for nd in ctx.attr.node_deps:
37+
runfiles = runfiles.merge(nd[DefaultInfo].default_runfiles)
3638
runfiles = runfiles.merge(test_runfiles)
3739

3840
return [DefaultInfo(

go/dom/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ go_wasm_test(
2020
],
2121
embed = [":dom"],
2222
node_deps = [
23-
"@npm//jsdom",
24-
"@npm//@ungap/url-search-params",
23+
"//:node_modules/jsdom",
24+
"//:node_modules/@ungap/url-search-params",
2525
],
2626
deps = [
2727
"//go/dom/testing",

go/keys/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ go_wasm_test(
2929
],
3030
embed = [":keys"],
3131
node_deps = [
32-
"@npm//web-locks",
33-
"@npm//mem-storage-area",
32+
"//:node_modules/web-locks",
33+
"//:node_modules/mem-storage-area",
3434
],
3535
deps = [
3636
"//go/jsutil/testing",

go/lock/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ go_wasm_test(
1414
srcs = ["lock_test.go"],
1515
embed = [":lock"],
1616
node_deps = [
17-
"@npm//web-locks",
17+
"//:node_modules/web-locks",
1818
],
1919
deps = [
2020
"//go/dom/testing",

go/optionsui/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ go_wasm_test(
2323
],
2424
embed = [":optionsui"],
2525
node_deps = [
26-
"@npm//web-locks",
27-
"@npm//mem-storage-area",
28-
"@npm//jsdom",
26+
"//:node_modules/web-locks",
27+
"//:node_modules/mem-storage-area",
28+
"//:node_modules/jsdom",
2929
],
3030
deps = [
3131
"//go/dom",

go/storage/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ go_wasm_test(
3030
],
3131
embed = [":storage"],
3232
node_deps = [
33-
"@npm//web-locks",
34-
"@npm//mem-storage-area",
33+
"//:node_modules/web-locks",
34+
"//:node_modules/mem-storage-area",
3535
],
3636
deps = [
3737
"//go/jsutil/testing",

html/BUILD.bazel

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
2-
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
3-
load("@npm//@bazel/esbuild:index.bzl", "esbuild")
1+
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
3+
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
44
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
55

66
# Typescript compiler inputs must be within our package. Copy it over.
@@ -20,39 +20,48 @@ js_library(
2020
],
2121
)
2222

23+
ts_config(
24+
name = "tsconfig",
25+
src = "tsconfig.json",
26+
)
27+
2328
ts_project(
2429
name = "app",
2530
srcs = ["app.ts"],
31+
tsconfig = ":tsconfig",
2632
declaration = True,
2733
deps = [
2834
":wasm_exec",
29-
"@npm//@types/chrome",
35+
"//:node_modules/@types/chrome",
3036
],
3137
)
3238

3339
ts_project(
3440
name = "background",
3541
srcs = ["background.ts"],
42+
tsconfig = ":tsconfig",
3643
declaration = True,
3744
deps = [
3845
":app",
39-
"@npm//@types/chrome",
46+
"//:node_modules/@types/chrome",
4047
],
4148
)
4249

4350
esbuild(
4451
name = "background-bundle",
52+
data = [":tsconfig"],
4553
entry_point = "background.ts",
4654
deps = [":background"],
4755
)
4856

4957
ts_project(
5058
name = "options",
5159
srcs = ["options.ts"],
60+
tsconfig = ":tsconfig",
5261
declaration = True,
5362
deps = [
5463
":app",
55-
"@npm//@types/chrome",
64+
"//:node_modules/@types/chrome",
5665
],
5766
)
5867

0 commit comments

Comments
 (0)