Skip to content

Commit 00de254

Browse files
committed
add embed script to sys bundle, update embedded HTTP client
1 parent ca8b3b5 commit 00de254

5 files changed

Lines changed: 535 additions & 453 deletions

File tree

packages/config-bundles/sys/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"scripts": {
1515
"build": "rimraf ./build && tsc",
1616
"build:docs": "yarn doc-snippets combine",
17+
"embed:wraps": "ts-node ./scripts/embed-wraps.ts",
1718
"lint": "eslint --color -c ../../../.eslintrc.js src/"
1819
},
1920
"dependencies": {
@@ -29,6 +30,7 @@
2930
"devDependencies": {
3031
"doc-snippets": "~1.0.0",
3132
"rimraf": "3.0.2",
33+
"ts-node": "10.9.1",
3234
"typescript": "4.9.5"
3335
},
3436
"publishConfig": {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { WasmPackage } from "@polywrap/wasm-js";
4+
5+
async function main() {
6+
7+
const embedsDir = path.join(__dirname, "../src/embeds");
8+
const embedsDirents = fs.readdirSync(embedsDir, { withFileTypes: true });
9+
10+
const wrapperDirs: string[] = [];
11+
12+
for (const dirent of embedsDirents) {
13+
if (dirent.isDirectory()) {
14+
wrapperDirs.push(path.join(embedsDir, dirent.name));
15+
}
16+
}
17+
18+
for (const wrapperDir of wrapperDirs) {
19+
const wasmBytes = fs.readFileSync(
20+
path.join(wrapperDir, "wrap.wasm")
21+
);
22+
const infoBytes = fs.readFileSync(
23+
path.join(wrapperDir, "wrap.info")
24+
);
25+
26+
try {
27+
// Make sure we can load the wasm module
28+
const tryLoad = WasmPackage.from(
29+
infoBytes,
30+
wasmBytes
31+
);
32+
const result = await tryLoad.getManifest();
33+
if (!result.ok) throw result.error;
34+
} catch (err) {
35+
throw Error(`Unable to load wrapper at ${wrapperDir}`);
36+
}
37+
38+
fs.writeFileSync(
39+
path.join(wrapperDir, "wrap.ts"),
40+
`// NOTE: This file is auto-generated, do not modify by hand!
41+
// See: ./scripts/embed-wrappers.ts
42+
import { WasmPackage } from "@polywrap/wasm-js";
43+
import toUint8Array from "base64-to-uint8array";
44+
45+
const wrap_wasm = toUint8Array(
46+
"${wasmBytes.toString("base64")}"
47+
);
48+
49+
const wrap_info = toUint8Array(
50+
"${infoBytes.toString("base64")}"
51+
);
52+
53+
export const wasmPackage = WasmPackage.from(
54+
wrap_info,
55+
wrap_wasm
56+
);
57+
`
58+
);
59+
}
60+
}
61+
62+
main()
63+
.then(() => {
64+
process.exit();
65+
})
66+
.catch((err) => {
67+
console.error(err);
68+
process.abort();
69+
});

packages/config-bundles/sys/src/embeds/http-resolver/wrap.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
1.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)