Skip to content

Commit

Permalink
Switch to capnp-es (#7788)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa authored Jan 28, 2025
1 parent 8bef7ea commit cf4f47a
Show file tree
Hide file tree
Showing 53 changed files with 7,861 additions and 5,240 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-foxes-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"miniflare": patch
---

Switch to `capnp-es` over `capnp-ts`
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ packages/create-cloudflare/templates*/**/*.*
packages/create-cloudflare/templates*/hello-world/**/worker-configuration.d.ts
packages/chrome-devtools-patches/devtools-frontend

packages/vitest-pool-workers/scripts/rtti/rtti.js

# dist-functions are generated in the fixtures/vitest-pool-workers-examples/pages-functions-unit-integration-self folder
dist-functions

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

packages/vite-plugin-cloudflare/playground/**/*.d.ts
packages/vite-plugin-cloudflare/playground/**/*.d.ts
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
},
"patchedDependencies": {
"@cloudflare/component-listbox@1.10.6": "patches/@cloudflare__component-listbox@1.10.6.patch",
"capnp-ts@0.7.0": "patches/capnp-ts@0.7.0.patch",
"pg@8.11.3": "patches/pg@8.11.3.patch",
"toucan-js@3.3.1": "patches/toucan-js@3.3.1.patch"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/miniflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"scripts": {
"build": "node scripts/build.mjs && pnpm run types:build",
"capnp:workerd": "capnpc -o ts src/runtime/config/workerd.capnp",
"capnp:workerd": "node scripts/build-capnp.mjs",
"check:lint": "eslint --max-warnings=0 \"{src,test}/**/*.ts\" \"scripts/**/*.{js,mjs}\" \"types/**/*.ts\"",
"check:type": "tsc",
"clean": "rimraf ./dist ./dist-types",
Expand All @@ -45,7 +45,6 @@
"@cspotcode/source-map-support": "0.8.1",
"acorn": "^8.8.0",
"acorn-walk": "^8.2.0",
"capnp-ts": "^0.7.0",
"exit-hook": "^2.2.1",
"glob-to-regexp": "^0.4.1",
"stoppable": "^1.1.0",
Expand All @@ -61,7 +60,7 @@
"@cloudflare/workers-shared": "workspace:*",
"@cloudflare/workers-types": "^4.20250121.0",
"@cloudflare/workflows-shared": "workspace:*",
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/api-extractor": "7.49.1",
"@types/debug": "^4.1.7",
"@types/estree": "^1.0.0",
"@types/glob-to-regexp": "^0.4.1",
Expand All @@ -74,7 +73,7 @@
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"ava": "^6.0.1",
"capnpc-ts": "^0.7.0",
"capnp-es": "^0.0.7",
"concurrently": "^8.2.2",
"devalue": "^4.3.0",
"devtools-protocol": "^0.0.1182435",
Expand All @@ -92,6 +91,7 @@
"pretty-bytes": "^6.0.0",
"rimraf": "catalog:default",
"source-map": "^0.6.1",
"typescript": "catalog:default",
"which": "^2.0.2"
},
"engines": {
Expand Down
9 changes: 9 additions & 0 deletions packages/miniflare/scripts/build-capnp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { execSync } from "node:child_process";
import { copyFileSync } from "node:fs";

execSync("capnp-es node_modules/workerd/workerd.capnp -ots");

copyFileSync(
"node_modules/workerd/workerd.ts",
"src/runtime/config/generated.ts"
);
12 changes: 0 additions & 12 deletions packages/miniflare/scripts/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,6 @@ function bundleTypes() {

fs.copyFileSync(indexTsPath, indexDtsPath);
try {
fs.copyFileSync(
path.join(pkgRoot, "src", "runtime", "config", "workerd.capnp.d.ts"),
path.join(
pkgRoot,
"dist-types",
"src",
"runtime",
"config",
"workerd.capnp.d.ts"
)
);

const extractorCfg = ExtractorConfig.prepare({
projectFolderLookupToken: pkgRoot,
packageJsonFullPath: path.join(pkgRoot, "package.json"),
Expand Down
11 changes: 7 additions & 4 deletions packages/miniflare/src/http/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { TypedEventTarget } from "../shared";
import { ValueOf, viewToBuffer } from "../workers";

export class MessageEvent extends Event {
readonly data: ArrayBuffer | string;
readonly data: string | ArrayBuffer | Uint8Array<ArrayBuffer>;

constructor(type: "message", init: { data: ArrayBuffer | string }) {
constructor(
type: "message",
init: { data: string | ArrayBuffer | Uint8Array<ArrayBuffer> }
) {
super(type);
this.data = init.data;
}
Expand Down Expand Up @@ -115,7 +118,7 @@ export class WebSocket extends TypedEventTarget<WebSocketEventMap> {
}
}

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

[kSend](message: ArrayBuffer | string): void {
[kSend](message: string | ArrayBuffer | Uint8Array<ArrayBuffer>): void {
// Split from send() so we can queue messages before accept() is called when
// forwarding message events from the client
if (this[kClosedOutgoing]) {
Expand Down
7 changes: 5 additions & 2 deletions packages/miniflare/src/plugins/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const encodeManifest = (manifest: ManifestEntry[]) => {
return assetManifestBytes;
};

const bytesToHex = (buffer: ArrayBufferLike) => {
const bytesToHex = (buffer: Uint8Array<ArrayBuffer>) => {
return [...new Uint8Array(buffer)]
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
Expand All @@ -314,6 +314,9 @@ const bytesToHex = (buffer: ArrayBufferLike) => {
const hashPath = async (path: string) => {
const encoder = new TextEncoder();
const data = encoder.encode(path);
const hashBuffer = await crypto.subtle.digest("SHA-256", data.buffer);
const hashBuffer = await crypto.subtle.digest(
"SHA-256",
data.buffer as ArrayBuffer
);
return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE);
};
Loading

0 comments on commit cf4f47a

Please sign in to comment.