@utoo/web 0.0.1-alpha.3 → 0.0.1-alpha.30

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
package/esm/worker.js CHANGED
@@ -3,33 +3,90 @@ import { HandShake } from "./message";
3
3
  import initWasm, { Project as ProjectInternal } from "./utoo";
4
4
  const projectEndpoint = {
5
5
  projectInternal: undefined,
6
- async mount(cwd) {
7
- await initWasm();
8
- this.projectInternal = new ProjectInternal(cwd);
6
+ wasmInit: undefined,
7
+ // This should be called only once
8
+ async mount(opt) {
9
+ var _a;
10
+ const { cwd, wasmUrl, threadWorkerUrl } = opt;
11
+ (_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
12
+ await this.wasmInit;
13
+ this.projectInternal = new ProjectInternal(cwd, threadWorkerUrl);
14
+ return;
9
15
  },
10
16
  async install(packageLock) {
17
+ await this.wasmInit;
11
18
  await this.projectInternal.install(packageLock);
19
+ return;
12
20
  },
13
21
  async build() {
14
- await this.projectInternal.build();
22
+ await this.wasmInit;
23
+ return await this.projectInternal.build();
15
24
  },
16
- async readFile(path) {
17
- return await this.projectInternal.readFile(path);
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;
18
35
  },
19
- async writeFile(path, content) {
20
- return await this.projectInternal.writeFile(path, content);
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
+ }
21
44
  },
22
45
  async copyFile(src, dst) {
46
+ await this.wasmInit;
23
47
  return await this.projectInternal.copyFile(src, dst);
24
48
  },
25
- async readDir(path) {
26
- return (await this.projectInternal.readDir(path)).map((e) => e.toJSON());
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;
27
64
  },
28
- async createDir(path) {
29
- return await this.projectInternal.createDir(path);
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
+ }
30
73
  },
31
- async createDirAll(path) {
32
- return await this.projectInternal.createDirAll(path);
74
+ async rm(path, options) {
75
+ await this.wasmInit;
76
+ let metadata = (await this.projectInternal.metadata(path)).toJSON();
77
+ switch (metadata.type) {
78
+ case "file":
79
+ return await this.projectInternal.removeFile(path);
80
+ case "directory":
81
+ return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
82
+ default:
83
+ // nothing to remove now
84
+ break;
85
+ }
86
+ },
87
+ async rmdir(path, options) {
88
+ await this.wasmInit;
89
+ return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
33
90
  },
34
91
  };
35
92
  const ConnectedPorts = new Set();
package/package.json CHANGED
@@ -1,20 +1,30 @@
1
1
  {
2
2
  "name": "@utoo/web",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.30",
4
4
  "module": "esm/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "files": [
7
7
  "esm/*"
8
8
  ],
9
9
  "scripts": {
10
- "wasmpack": "wasm-pack build ../../crates/utoo-wasm --out-dir ../../packages/utoo-web/src/utoo --out-name index --no-pack --target web",
11
- "tsx": "rm -rf esm && tsc -p ./tsconfig.json",
12
- "dev": "npm run wasmpack -- --profiling && npm run tsx && cp ./src/utoo/*.wasm ./esm/utoo",
13
- "build": "npm run wasmpack -- --release && npm run tsx && cp ./src/utoo/*.wasm ./esm/utoo",
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/release/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web",
15
+ "bindgen-build:local": "wasm-bindgen ../../target/wasm32-unknown-unknown/release-local/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web",
16
+ "pretsc": "npm run build --workspace @utoo/pack-shared",
17
+ "tsc": "rm -rf esm && tsc -p ./tsconfig.json",
18
+ "dev": "npm run build-wasm -- --profile wasm-dev && npm run bindgen-dev && npm run tsc && cp src/utoo/index_bg.wasm esm/utoo",
19
+ "dev:pm": "npm run build-wasm:pm -- --profile wasm-dev && npm run bindgen-dev && npm run tsc && cp src/utoo/index_bg.wasm esm/utoo",
20
+ "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",
21
+ "build": "npm run build-wasm -- --release && npm run bindgen-build && npm run tsc && npm run wasm-opt",
22
+ "build:local": "npm run build-wasm -- --profile release-local && npm run bindgen-build:local && npm run tsc && cp src/utoo/index_bg.wasm esm/utoo",
14
23
  "prepublishOnly": "npm run build"
15
24
  },
16
25
  "dependencies": {
17
- "comlink": "^4.4.2"
26
+ "comlink": "^4.4.2",
27
+ "@utoo/pack-shared": "^0.0.5"
18
28
  },
19
29
  "devDependencies": {
20
30
  "typescript": "^5.8.3"
@@ -23,5 +33,6 @@
23
33
  "node": ">= 20"
24
34
  },
25
35
  "author": "xusd320",
26
- "license": "MIT"
36
+ "license": "MIT",
37
+ "repository": "git@github.com:utooland/utoo.git"
27
38
  }