@utoo/web 0.0.1 → 1.0.0

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,109 @@ 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, logFilter } = opt;
11
+ // Set global log filter before wasm init
12
+ if (logFilter) {
13
+ globalThis.__UTOO_LOG_FILTER__ = logFilter;
14
+ }
15
+ (_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
16
+ await this.wasmInit;
17
+ // Pass logFilter to thread worker via URL query string
18
+ let finalThreadWorkerUrl = threadWorkerUrl;
19
+ if (logFilter) {
20
+ const url = new URL(threadWorkerUrl, self.location.href);
21
+ url.searchParams.set("logFilter", logFilter);
22
+ finalThreadWorkerUrl = url.toString();
23
+ }
24
+ this.projectInternal = new ProjectInternal(cwd, finalThreadWorkerUrl);
25
+ return;
9
26
  },
10
- async install(packageLock) {
11
- await this.projectInternal.install(packageLock);
27
+ async install(packageLock, maxConcurrentDownloads) {
28
+ await this.wasmInit;
29
+ await this.projectInternal.install(packageLock, maxConcurrentDownloads);
30
+ return;
12
31
  },
13
32
  async build() {
14
- await this.projectInternal.build();
33
+ await this.wasmInit;
34
+ return await this.projectInternal.build();
15
35
  },
16
- async readFile(path) {
17
- return await this.projectInternal.readFile(path);
36
+ async readFile(path, encoding) {
37
+ await this.wasmInit;
38
+ let ret;
39
+ if (encoding === "utf8") {
40
+ ret = await this.projectInternal.readToString(path);
41
+ }
42
+ else {
43
+ ret = await this.projectInternal.read(path);
44
+ }
45
+ return ret;
18
46
  },
19
- async writeFile(path, content) {
20
- return await this.projectInternal.writeFile(path, content);
47
+ async writeFile(path, content, _encoding) {
48
+ await this.wasmInit;
49
+ if (typeof content === "string") {
50
+ return await this.projectInternal.writeString(path, content);
51
+ }
52
+ else {
53
+ return await this.projectInternal.write(path, content);
54
+ }
21
55
  },
22
56
  async copyFile(src, dst) {
57
+ await this.wasmInit;
23
58
  return await this.projectInternal.copyFile(src, dst);
24
59
  },
25
- async readDir(path) {
26
- return await this.projectInternal.readDir(path);
60
+ async readdir(path, options) {
61
+ await this.wasmInit;
62
+ const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
63
+ ? await this.projectInternal.readDir(path)
64
+ : // TODO: support recursive readDirAll
65
+ await this.projectInternal.readDir(path);
66
+ const rawDirents = dirEntries.map((e) => {
67
+ const dir = e.toJSON();
68
+ return {
69
+ name: dir.name,
70
+ type: dir.type,
71
+ };
72
+ });
73
+ // WARN: This is a hack, functions can not be structurally cloned
74
+ return rawDirents;
27
75
  },
28
- async createDir(path) {
29
- return await this.projectInternal.createDir(path);
76
+ async mkdir(path, options) {
77
+ await this.wasmInit;
78
+ if (options === null || options === void 0 ? void 0 : options.recursive) {
79
+ return await this.projectInternal.createDirAll(path);
80
+ }
81
+ else {
82
+ return await this.projectInternal.createDir(path);
83
+ }
30
84
  },
31
- async createDirAll(path) {
32
- return await this.projectInternal.createDirAll(path);
85
+ async rm(path, options) {
86
+ await this.wasmInit;
87
+ let metadata = (await this.projectInternal.metadata(path)).toJSON();
88
+ switch (metadata.type) {
89
+ case "file":
90
+ return await this.projectInternal.removeFile(path);
91
+ case "directory":
92
+ return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
93
+ default:
94
+ // nothing to remove now
95
+ break;
96
+ }
97
+ },
98
+ async rmdir(path, options) {
99
+ await this.wasmInit;
100
+ return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
101
+ },
102
+ async gzip(files) {
103
+ await this.wasmInit;
104
+ return await this.projectInternal.gzip(files);
105
+ },
106
+ async sigMd5(content) {
107
+ await this.wasmInit;
108
+ return await this.projectInternal.sigMd5(content);
33
109
  },
34
110
  };
35
111
  const ConnectedPorts = new Set();
package/package.json CHANGED
@@ -1,20 +1,30 @@
1
1
  {
2
2
  "name": "@utoo/web",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
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 -- --dev && 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.7"
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
  }