Skip to content

Commit 0c296ed

Browse files
committed
Migrate from capnp-ts to capnp-es
1 parent 1732bcf commit 0c296ed

26 files changed

+1016
-1081
lines changed

BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
33
load("@bazel_skylib//lib:selects.bzl", "selects")
44
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
55
load("@capnp-cpp//src/capnp:cc_capnp_library.bzl", "cc_capnp_library")
6-
load("@npm//:capnpc-ts/package_json.bzl", capnpc_ts_bin = "bin")
6+
load("@npm//:capnp-es/package_json.bzl", capnp_es_binary = "bin")
77
load("@npm//:defs.bzl", "npm_link_all_packages")
88

99
cc_capnp_library(
@@ -23,8 +23,8 @@ npm_link_package(
2323
package = "@workerd/jsg",
2424
)
2525

26-
capnpc_ts_bin.capnpc_ts_binary(
27-
name = "capnpc_ts",
26+
capnp_es_binary.capnp_es_binary(
27+
name = "capnpc_es",
2828
visibility = ["//visibility:public"],
2929
)
3030

WORKSPACE

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ deps_gen()
1818
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
1919
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
2020

21-
NODE_VERSION = "22.11.0"
21+
NODE_VERSION = "22.14.0"
2222

2323
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
2424

@@ -212,13 +212,6 @@ load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
212212
npm_translate_lock(
213213
name = "npm",
214214
npmrc = "//:.npmrc",
215-
patch_args = {
216-
"[email protected]": ["-p1"],
217-
},
218-
# Patches required for `capnp-ts` to type-check
219-
patches = {
220-
221-
},
222215
pnpm_lock = "//:pnpm-lock.yaml",
223216
)
224217

build/deps/gen/dep_rules_nodejs.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
load("@//:build/http.bzl", "http_archive")
44

5-
TAG_NAME = "v6.3.4"
6-
URL = "https://github.com/bazel-contrib/rules_nodejs/releases/download/v6.3.4/rules_nodejs-v6.3.4.tar.gz"
7-
STRIP_PREFIX = "rules_nodejs-6.3.4"
8-
SHA256 = "b361863788b15d9d0cebf6803c22e8d1afa689a0eefef96dec46bcce30527090"
5+
TAG_NAME = "v6.3.5"
6+
URL = "https://github.com/bazel-contrib/rules_nodejs/releases/download/v6.3.5/rules_nodejs-v6.3.5.tar.gz"
7+
STRIP_PREFIX = "rules_nodejs-6.3.5"
8+
SHA256 = "164f1bd7e2a67ab3f6caf5b49b53c7dd625d293513154fa720e30d39eaa8285f"
99
TYPE = "tgz"
1010

1111
def dep_rules_nodejs():

build/js_capnp_library.bzl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _capnp_gen_impl(ctx):
3535
if src_prefix != "":
3636
out_dir = out_dir + "/" + src_prefix
3737

38-
js_out = "-o%s:%s" % (ctx.executable._capnpc_ts.path, out_dir)
38+
js_out = "-o%s:%s" % (ctx.executable._capnpc_es.path, out_dir)
3939
args = ctx.actions.args()
4040
args.add_all(["compile", "--verbose", js_out])
4141
args.add_all(["-I" + inc for inc in includes])
@@ -46,8 +46,8 @@ def _capnp_gen_impl(ctx):
4646
args.add_all([s for s in ctx.files.srcs])
4747

4848
ctx.actions.run(
49-
inputs = inputs + ctx.files._capnpc_ts + ctx.files._capnpc_capnp + ctx.files._capnp_system,
50-
tools = [ctx.executable._capnpc_ts], # Include required js_binary runfiles
49+
inputs = inputs + ctx.files._capnpc_es + ctx.files._capnpc_capnp + ctx.files._capnp_system,
50+
tools = [ctx.executable._capnpc_es], # Include required js_binary runfiles
5151
outputs = ctx.outputs.outs,
5252
executable = ctx.executable._capnpc,
5353
arguments = [args],
@@ -70,7 +70,7 @@ _capnp_gen = rule(
7070
"outs": attr.output_list(),
7171
"src_prefix": attr.string(),
7272
"_capnpc": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "@capnp-cpp//src/capnp:capnp_tool"),
73-
"_capnpc_ts": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "//:capnpc_ts"),
73+
"_capnpc_es": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "//:capnpc_es"),
7474
"_capnpc_capnp": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "@capnp-cpp//src/capnp:capnpc-capnp"),
7575
"_capnp_system": attr.label(default = "@capnp-cpp//src/capnp:capnp_system_library"),
7676
},
@@ -82,6 +82,7 @@ def js_capnp_library(
8282
name,
8383
srcs = [],
8484
data = [],
85+
outs = [],
8586
deps = [],
8687
src_prefix = "",
8788
visibility = None,
@@ -94,30 +95,28 @@ def js_capnp_library(
9495
srcs: list of files to compile
9596
data: additional files to provide to the compiler - data files and includes that need not to
9697
be compiled
98+
outs: expected output files
9799
deps: other js_capnp_library rules to depend on
98100
src_prefix: src_prefix for capnp compiler to the source root
99101
visibility: rule visibility
100102
target_compatible_with: target compatibility
101103
**kwargs: rest of the arguments to js_library rule
102104
"""
103105

104-
js_files = [s + ".js" for s in srcs]
105-
d_ts_files = [s + ".d.ts" for s in srcs]
106-
107106
_capnp_gen(
108107
name = name + "_gen",
109108
srcs = srcs,
110109
deps = [s + "_gen" for s in deps],
111110
data = data,
112-
outs = js_files + d_ts_files,
111+
outs = outs,
113112
src_prefix = src_prefix,
114113
visibility = visibility,
115114
target_compatible_with = target_compatible_with,
116115
)
117116
js_library(
118117
name = name,
119-
srcs = js_files + d_ts_files,
120-
deps = deps + ["//:node_modules/capnp-ts"],
118+
srcs = outs,
119+
deps = deps + ["//:node_modules/capnp-es"],
121120
visibility = visibility,
122121
target_compatible_with = target_compatible_with,
123122
**kwargs

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
"format": "prettier"
77
},
88
"dependencies": {
9-
"capnp-ts": "^0.7.0",
109
"prettier": "^3.5.1",
1110
"typescript": "5.6.2"
1211
},
1312
"devDependencies": {
1413
"@eslint/js": "^9.20.0",
1514
"@types/debug": "^4.1.12",
16-
"@types/node": "^22.7.5",
17-
"capnpc-ts": "^0.7.0",
15+
"@types/node": "^22.14.0",
16+
"capnp-es": "^0.0.9",
1817
"chrome-remote-interface": "^0.33.3",
1918
"esbuild": "^0.25.0",
2019
"eslint": "^9.20.1",
2120
"expect-type": "^1.1.0",
2221
"typescript-eslint": "^8.23.0"
2322
},
2423
"pnpm": {
25-
"overrides": {
26-
"capnpc-ts>typescript": "4.7.4"
27-
},
28-
"onlyBuiltDependencies": []
24+
"onlyBuiltDependencies": [],
25+
"patchedDependencies": {
26+
"capnp-es": "patches/capnp-es.patch"
27+
}
2928
},
3029
"packageManager": "[email protected]+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247"
3130
}

patches/capnp-es.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/dist/compiler/main.mjs b/dist/compiler/main.mjs
2+
index 6999c0e0c50570efd51959661ffc611f561bd31b..c37f97d5d786e4fc316acd4f5780e8e3976b21dd 100755
3+
--- a/dist/compiler/main.mjs
4+
+++ b/dist/compiler/main.mjs
5+
@@ -38,7 +38,7 @@ Options:
6+
`;
7+
const sources = [];
8+
const options = [];
9+
-let outFormats = ["js"];
10+
+let outFormats = ["ts","js"];
11+
let outDir;
12+
for (const arg of process.argv.slice(2)) {
13+
if (arg === "--help") {
14+
diff --git a/dist/shared/capnp-es.C3d1NAZK.mjs b/dist/shared/capnp-es.C3d1NAZK.mjs
15+
index 08c44dc210d976e80cac085de9443068b367b2ff..61d6af8c4917d09ed7157a5098504eb28f85d729 100644
16+
--- a/dist/shared/capnp-es.C3d1NAZK.mjs
17+
+++ b/dist/shared/capnp-es.C3d1NAZK.mjs
18+
@@ -2128,7 +2128,7 @@ async function compileAll(buff, opts) {
19+
}
20+
if (!opts?.ts) {
21+
for (const [fileName] of files) {
22+
- if (fileName.endsWith(".ts")) {
23+
+ if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
24+
files.delete(fileName);
25+
}
26+
}

patches/[email protected]

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)