Skip to content

Switch to capnp-es #7788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this cast now necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of this involved upgrading TS to 5.7 from 5.6 for the Miniflare package—I can probably remove that, but it was causing some issues with capnp-es

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

);
return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE);
};
Loading
Loading