-
Notifications
You must be signed in to change notification settings - Fork 12
Fix cloudflare workers #437
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
slinkydeveloper
merged 3 commits into
restatedev:main
from
slinkydeveloper:fix-cloudflare-workers
Oct 1, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"name": "@restatedev/restate-sdk-cloudflare-workers", | ||
"version": "1.3.1", | ||
"description": "Typescript SDK for Restate", | ||
"author": "Restate Developers", | ||
"license": "MIT", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/restatedev/sdk-typescript#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/restatedev/sdk-typescript.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/restatedev/sdk-typescript/issues" | ||
}, | ||
"type": "module", | ||
"sideEffects": false, | ||
"main": "./dist/cjs/src/public_api.js", | ||
"module": "./dist/esm/src/public_api.js", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/src/public_api.d.ts", | ||
"default": "./dist/esm/src/public_api.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/src/public_api.d.ts", | ||
"default": "./dist/cjs/src/public_api.js" | ||
} | ||
}, | ||
"./fetch": { | ||
"import": { | ||
"types": "./dist/esm/src/fetch.d.ts", | ||
"default": "./dist/esm/src/fetch.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/src/fetch.d.ts", | ||
"default": "./dist/cjs/src/fetch.js" | ||
} | ||
}, | ||
"./lambda": { | ||
"import": { | ||
"types": "./dist/esm/src/lambda.d.ts", | ||
"default": "./dist/esm/src/lambda.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/src/lambda.d.ts", | ||
"default": "./dist/cjs/src/lambda.js" | ||
} | ||
} | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"fetch": [ | ||
"dist/cjs/src/fetch.d.ts" | ||
], | ||
"lambda": [ | ||
"dist/cjs/src/lambda.d.ts" | ||
] | ||
} | ||
}, | ||
"types": "./dist/cjs/src/public_api.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "./patch_sdk_cf_workers.sh", | ||
"release": "release-it" | ||
}, | ||
"dependencies": { | ||
"@restatedev/restate-sdk-core": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.115" | ||
}, | ||
"engines": { | ||
"node": ">= 18.13" | ||
}, | ||
"publishConfig": { | ||
"@restatedev:registry": "https://registry.npmjs.org" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/restate-sdk-cloudflare-workers/patch_sdk_cf_workers.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ ! -d ../restate-sdk/dist ]]; then | ||
echo "ERROR - You need to build the restate-sdk module first!" | ||
exit 1 | ||
fi | ||
|
||
cp -r ../restate-sdk/dist . | ||
slinkydeveloper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rm -r dist/cjs | ||
|
||
# Copy fetch.js | ||
cp patches/fetch.js dist/esm/src/fetch.js | ||
|
||
# Copy vm | ||
rm -r dist/esm/src/endpoint/handlers/vm | ||
cp -r patches/vm dist/esm/src/endpoint/handlers | ||
|
||
# Copy vm entrypoint | ||
cp patches/sdk_shared_core_wasm_bindings.js dist/esm/src/endpoint/handlers/vm |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
packages/restate-sdk-cloudflare-workers/patches/sdk_shared_core_wasm_bindings.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as imports from "./sdk_shared_core_wasm_bindings_bg.js"; | ||
|
||
// switch between both syntax for node and for workerd | ||
import wkmod from "./sdk_shared_core_wasm_bindings_bg.wasm"; | ||
|
||
const instance = new WebAssembly.Instance(wkmod, { | ||
"./sdk_shared_core_wasm_bindings_bg.js": imports, | ||
}); | ||
imports.__wbg_set_wasm(instance.exports); | ||
|
||
export * from "./sdk_shared_core_wasm_bindings_bg.js"; | ||
|
||
instance.exports.__wbindgen_start(); | ||
|
||
export function cloudflareWorkersBundlerPatch() { | ||
// This is the result of many hours of debugging. | ||
// The patch described here https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen | ||
// won't "just work", because the CF worker bundler has some bug that will eliminate this file. | ||
// To prevent the elimination, we call this empty function from the fetch.js file, which is the user entrypoint of the SDK. | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be under
./scripts/
?