@utoo/web 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1 @@
1
+ export {};
package/esm/worker.js ADDED
@@ -0,0 +1,82 @@
1
+ import * as comlink from "comlink";
2
+ import { HandShake } from "./message";
3
+ import initWasm, { Project as ProjectInternal } from "./utoo";
4
+ const projectEndpoint = {
5
+ projectInternal: undefined,
6
+ wasmInit: undefined,
7
+ // This should be called only once
8
+ async mount(opt) {
9
+ var _a;
10
+ const { cwd, wasmUrl } = opt;
11
+ (_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
12
+ await this.wasmInit;
13
+ this.projectInternal = new ProjectInternal(cwd);
14
+ return;
15
+ },
16
+ async install(packageLock) {
17
+ await this.wasmInit;
18
+ await this.projectInternal.install(packageLock);
19
+ return;
20
+ },
21
+ async build() {
22
+ await this.wasmInit;
23
+ return await this.projectInternal.build();
24
+ },
25
+ async readFile(path, encoding) {
26
+ await this.wasmInit;
27
+ let ret;
28
+ if (encoding === "utf8") {
29
+ ret = await this.projectInternal.readToString(path);
30
+ }
31
+ else {
32
+ ret = await this.projectInternal.read(path);
33
+ }
34
+ return ret;
35
+ },
36
+ async writeFile(path, content, _encoding) {
37
+ await this.wasmInit;
38
+ if (typeof content === "string") {
39
+ return await this.projectInternal.writeString(path, content);
40
+ }
41
+ else {
42
+ return await this.projectInternal.write(path, content);
43
+ }
44
+ },
45
+ async copyFile(src, dst) {
46
+ await this.wasmInit;
47
+ return await this.projectInternal.copyFile(src, dst);
48
+ },
49
+ async readdir(path, options) {
50
+ await this.wasmInit;
51
+ const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
52
+ ? await this.projectInternal.readDir(path)
53
+ : // TODO: support recursive readDirAll
54
+ await this.projectInternal.readDir(path);
55
+ const rawDirents = dirEntries.map((e) => {
56
+ const dir = e.toJSON();
57
+ return {
58
+ name: dir.name,
59
+ type: dir.type,
60
+ };
61
+ });
62
+ // WARN: This is a hack, functions can not be structurally cloned
63
+ return rawDirents;
64
+ },
65
+ async mkdir(path, options) {
66
+ await this.wasmInit;
67
+ if (options === null || options === void 0 ? void 0 : options.recursive) {
68
+ return await this.projectInternal.createDirAll(path);
69
+ }
70
+ else {
71
+ return await this.projectInternal.createDir(path);
72
+ }
73
+ },
74
+ };
75
+ const ConnectedPorts = new Set();
76
+ self.addEventListener("message", (e) => {
77
+ const port = e.ports[0];
78
+ if (e.data === HandShake && !ConnectedPorts.has(port)) {
79
+ comlink.expose(projectEndpoint, port);
80
+ ConnectedPorts.add(port);
81
+ }
82
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@utoo/web",
3
+ "version": "0.0.1-alpha.10",
4
+ "module": "esm/index.js",
5
+ "types": "esm/index.d.ts",
6
+ "files": [
7
+ "esm/*"
8
+ ],
9
+ "scripts": {
10
+ "install-toolchain": "cargo install wasm-bindgen-cli && brew install binaryen",
11
+ "build-wasm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown -Z build-std=panic_abort,std",
12
+ "build-wasm:pm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown --no-default-features -Z build-std=panic_abort,std",
13
+ "bindgen-dev": "wasm-bindgen ../../target/wasm32-unknown-unknown/wasm-dev/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web --debug --keep-debug --no-demangle",
14
+ "bindgen-build": "wasm-bindgen ../../target/wasm32-unknown-unknown/wasm-release/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web",
15
+ "tsx": "rm -rf esm && tsc -p ./tsconfig.json",
16
+ "dev": "npm run build-wasm -- --profile wasm-dev && npm run bindgen-dev && npm run tsx && cp src/utoo/index_bg.wasm esm/utoo",
17
+ "dev:pm": "npm run build-wasm:pm -- --profile wasm-dev && npm run bindgen-dev && npm run tsx && cp src/utoo/index_bg.wasm esm/utoo",
18
+ "wasm-opt": "wasm-opt src/utoo/index_bg.wasm -o esm/utoo/index_bg.wasm --enable-threads --enable-bulk-memory --enable-nontrapping-float-to-int -Oz",
19
+ "build": "npm run build-wasm -- --profile wasm-release && npm run bindgen-build && npm run tsx && npm run wasm-opt",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "dependencies": {
23
+ "comlink": "^4.4.2"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "^5.8.3"
27
+ },
28
+ "engines": {
29
+ "node": ">= 20"
30
+ },
31
+ "author": "xusd320",
32
+ "license": "MIT",
33
+ "repository": "git@github.com:umijs/mako.git"
34
+ }