@utoo/web 1.0.0 → 1.0.2
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.
- package/esm/internalProject.d.ts +29 -0
- package/esm/internalProject.js +185 -0
- package/esm/project.d.ts +3 -2
- package/esm/project.js +4 -4
- package/esm/threadWorker.js +0 -6
- package/esm/type.d.ts +4 -2
- package/esm/utoo/index.d.ts +78 -0
- package/esm/utoo/index.js +248 -83
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/loaders/lessLoader/index.d.ts +3 -0
- package/esm/webpackLoaders/loaders/lessLoader/index.js +103 -0
- package/esm/webpackLoaders/loaders/lessLoader/options.json +67 -0
- package/esm/webpackLoaders/loaders/lessLoader/utils.d.ts +14 -0
- package/esm/webpackLoaders/loaders/lessLoader/utils.js +217 -0
- package/esm/webpackLoaders/worker/cjs.d.ts +2 -0
- package/esm/webpackLoaders/worker/cjs.js +77 -0
- package/esm/webpackLoaders/worker/index.d.ts +2 -0
- package/esm/webpackLoaders/worker/index.js +31 -0
- package/esm/webpackLoaders/worker/nodePolyFills.d.ts +14 -0
- package/esm/webpackLoaders/worker/nodePolyFills.js +24 -0
- package/esm/webpackLoaders/worker/type.d.ts +11 -0
- package/esm/webpackLoaders/worker/type.js +1 -0
- package/esm/webpackLoaders/workerContent.d.ts +2 -0
- package/esm/webpackLoaders/workerContent.js +1 -0
- package/esm/worker.js +2 -109
- package/package.json +15 -5
package/esm/worker.js
CHANGED
|
@@ -1,118 +1,11 @@
|
|
|
1
1
|
import * as comlink from "comlink";
|
|
2
|
+
import { internalEndpoint } from "./internalProject";
|
|
2
3
|
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, 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;
|
|
26
|
-
},
|
|
27
|
-
async install(packageLock, maxConcurrentDownloads) {
|
|
28
|
-
await this.wasmInit;
|
|
29
|
-
await this.projectInternal.install(packageLock, maxConcurrentDownloads);
|
|
30
|
-
return;
|
|
31
|
-
},
|
|
32
|
-
async build() {
|
|
33
|
-
await this.wasmInit;
|
|
34
|
-
return await this.projectInternal.build();
|
|
35
|
-
},
|
|
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;
|
|
46
|
-
},
|
|
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
|
-
}
|
|
55
|
-
},
|
|
56
|
-
async copyFile(src, dst) {
|
|
57
|
-
await this.wasmInit;
|
|
58
|
-
return await this.projectInternal.copyFile(src, dst);
|
|
59
|
-
},
|
|
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;
|
|
75
|
-
},
|
|
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
|
-
}
|
|
84
|
-
},
|
|
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);
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
4
|
const ConnectedPorts = new Set();
|
|
112
5
|
self.addEventListener("message", (e) => {
|
|
113
6
|
const port = e.ports[0];
|
|
114
7
|
if (e.data === HandShake && !ConnectedPorts.has(port)) {
|
|
115
|
-
comlink.expose(
|
|
8
|
+
comlink.expose(internalEndpoint, port);
|
|
116
9
|
ConnectedPorts.add(port);
|
|
117
10
|
}
|
|
118
11
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/web",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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
|
-
"install-toolchain": "cargo install wasm-bindgen-cli && brew install binaryen",
|
|
10
|
+
"install-toolchain": "cargo install wasm-bindgen-cli@0.2.104 && brew install binaryen",
|
|
11
11
|
"build-wasm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown -Z build-std=panic_abort,std",
|
|
12
12
|
"build-wasm:pm": "cargo build -p utoo-wasm --target wasm32-unknown-unknown --no-default-features -Z build-std=panic_abort,std",
|
|
13
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",
|
|
@@ -18,16 +18,26 @@
|
|
|
18
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
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
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",
|
|
21
|
+
"build": "npm run build-wasm -- --release && npm run bindgen-build && npm run build-loaderWorker && 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 && npm run build-loaderWorker",
|
|
23
|
+
"build-loaderWorker": "node cli/umd.js -e ./src/webpackLoaders/worker/index.ts -o ./src/webpackLoaders/workerContent.js -t webworker --se true",
|
|
23
24
|
"prepublishOnly": "npm run build"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"comlink": "^4.4.2",
|
|
28
|
+
"systemjs": "^6.15.1",
|
|
29
|
+
"loader-runner": "^4.3.0",
|
|
30
|
+
"less": "^4.0.0",
|
|
27
31
|
"@utoo/pack-shared": "^0.0.7"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"typescript": "^5.8.3"
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"@types/systemjs": "^6.15.1",
|
|
36
|
+
"webpack": "^5.0.0",
|
|
37
|
+
"webpack-merge": "^6.0.1",
|
|
38
|
+
"node-stdlib-browser": "^1.3.1",
|
|
39
|
+
"ts-loader": "^9.5.2",
|
|
40
|
+
"yargs": "^18.0.0"
|
|
31
41
|
},
|
|
32
42
|
"engines": {
|
|
33
43
|
"node": ">= 20"
|