Skip to content

Commit cf4f47a

Browse files
authored
Switch to capnp-es (#7788)
1 parent 8bef7ea commit cf4f47a

File tree

53 files changed

+7861
-5240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+7861
-5240
lines changed

.changeset/neat-foxes-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"miniflare": patch
3+
---
4+
5+
Switch to `capnp-es` over `capnp-ts`

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ packages/create-cloudflare/templates*/**/*.*
2626
packages/create-cloudflare/templates*/hello-world/**/worker-configuration.d.ts
2727
packages/chrome-devtools-patches/devtools-frontend
2828

29+
packages/vitest-pool-workers/scripts/rtti/rtti.js
30+
2931
# dist-functions are generated in the fixtures/vitest-pool-workers-examples/pages-functions-unit-integration-self folder
3032
dist-functions
3133

@@ -45,4 +47,4 @@ fixtures/interactive-dev-tests/src/startup-error.ts
4547
fixtures/pages-redirected-config/build/*
4648
fixtures/redirected-config-worker/build/*
4749

48-
packages/vite-plugin-cloudflare/playground/**/*.d.ts
50+
packages/vite-plugin-cloudflare/playground/**/*.d.ts

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
},
8181
"patchedDependencies": {
8282
"@cloudflare/[email protected]": "patches/@[email protected]",
83-
8483
8584
8685
}

packages/miniflare/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"scripts": {
3333
"build": "node scripts/build.mjs && pnpm run types:build",
34-
"capnp:workerd": "capnpc -o ts src/runtime/config/workerd.capnp",
34+
"capnp:workerd": "node scripts/build-capnp.mjs",
3535
"check:lint": "eslint --max-warnings=0 \"{src,test}/**/*.ts\" \"scripts/**/*.{js,mjs}\" \"types/**/*.ts\"",
3636
"check:type": "tsc",
3737
"clean": "rimraf ./dist ./dist-types",
@@ -45,7 +45,6 @@
4545
"@cspotcode/source-map-support": "0.8.1",
4646
"acorn": "^8.8.0",
4747
"acorn-walk": "^8.2.0",
48-
"capnp-ts": "^0.7.0",
4948
"exit-hook": "^2.2.1",
5049
"glob-to-regexp": "^0.4.1",
5150
"stoppable": "^1.1.0",
@@ -61,7 +60,7 @@
6160
"@cloudflare/workers-shared": "workspace:*",
6261
"@cloudflare/workers-types": "^4.20250121.0",
6362
"@cloudflare/workflows-shared": "workspace:*",
64-
"@microsoft/api-extractor": "^7.47.0",
63+
"@microsoft/api-extractor": "7.49.1",
6564
"@types/debug": "^4.1.7",
6665
"@types/estree": "^1.0.0",
6766
"@types/glob-to-regexp": "^0.4.1",
@@ -74,7 +73,7 @@
7473
"@typescript-eslint/eslint-plugin": "^6.9.0",
7574
"@typescript-eslint/parser": "^6.9.0",
7675
"ava": "^6.0.1",
77-
"capnpc-ts": "^0.7.0",
76+
"capnp-es": "^0.0.7",
7877
"concurrently": "^8.2.2",
7978
"devalue": "^4.3.0",
8079
"devtools-protocol": "^0.0.1182435",
@@ -92,6 +91,7 @@
9291
"pretty-bytes": "^6.0.0",
9392
"rimraf": "catalog:default",
9493
"source-map": "^0.6.1",
94+
"typescript": "catalog:default",
9595
"which": "^2.0.2"
9696
},
9797
"engines": {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { execSync } from "node:child_process";
2+
import { copyFileSync } from "node:fs";
3+
4+
execSync("capnp-es node_modules/workerd/workerd.capnp -ots");
5+
6+
copyFileSync(
7+
"node_modules/workerd/workerd.ts",
8+
"src/runtime/config/generated.ts"
9+
);

packages/miniflare/scripts/types.mjs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,6 @@ function bundleTypes() {
148148

149149
fs.copyFileSync(indexTsPath, indexDtsPath);
150150
try {
151-
fs.copyFileSync(
152-
path.join(pkgRoot, "src", "runtime", "config", "workerd.capnp.d.ts"),
153-
path.join(
154-
pkgRoot,
155-
"dist-types",
156-
"src",
157-
"runtime",
158-
"config",
159-
"workerd.capnp.d.ts"
160-
)
161-
);
162-
163151
const extractorCfg = ExtractorConfig.prepare({
164152
projectFolderLookupToken: pkgRoot,
165153
packageJsonFullPath: path.join(pkgRoot, "package.json"),

packages/miniflare/src/http/websocket.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { TypedEventTarget } from "../shared";
55
import { ValueOf, viewToBuffer } from "../workers";
66

77
export class MessageEvent extends Event {
8-
readonly data: ArrayBuffer | string;
8+
readonly data: string | ArrayBuffer | Uint8Array<ArrayBuffer>;
99

10-
constructor(type: "message", init: { data: ArrayBuffer | string }) {
10+
constructor(
11+
type: "message",
12+
init: { data: string | ArrayBuffer | Uint8Array<ArrayBuffer> }
13+
) {
1114
super(type);
1215
this.data = init.data;
1316
}
@@ -115,7 +118,7 @@ export class WebSocket extends TypedEventTarget<WebSocketEventMap> {
115118
}
116119
}
117120

118-
send(message: ArrayBuffer | string): void {
121+
send(message: string | ArrayBuffer | Uint8Array<ArrayBuffer>): void {
119122
if (!this[kAccepted]) {
120123
throw new TypeError(
121124
"You must call accept() on this WebSocket before sending messages."
@@ -124,7 +127,7 @@ export class WebSocket extends TypedEventTarget<WebSocketEventMap> {
124127
this[kSend](message);
125128
}
126129

127-
[kSend](message: ArrayBuffer | string): void {
130+
[kSend](message: string | ArrayBuffer | Uint8Array<ArrayBuffer>): void {
128131
// Split from send() so we can queue messages before accept() is called when
129132
// forwarding message events from the client
130133
if (this[kClosedOutgoing]) {

packages/miniflare/src/plugins/assets/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const encodeManifest = (manifest: ManifestEntry[]) => {
305305
return assetManifestBytes;
306306
};
307307

308-
const bytesToHex = (buffer: ArrayBufferLike) => {
308+
const bytesToHex = (buffer: Uint8Array<ArrayBuffer>) => {
309309
return [...new Uint8Array(buffer)]
310310
.map((b) => b.toString(16).padStart(2, "0"))
311311
.join("");
@@ -314,6 +314,9 @@ const bytesToHex = (buffer: ArrayBufferLike) => {
314314
const hashPath = async (path: string) => {
315315
const encoder = new TextEncoder();
316316
const data = encoder.encode(path);
317-
const hashBuffer = await crypto.subtle.digest("SHA-256", data.buffer);
317+
const hashBuffer = await crypto.subtle.digest(
318+
"SHA-256",
319+
data.buffer as ArrayBuffer
320+
);
318321
return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE);
319322
};

0 commit comments

Comments
 (0)