@utoo/web 0.0.1-alpha.14 → 0.0.1-alpha.15
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/index.js +6 -5
- package/esm/serviceWorker.js +13 -14
- package/esm/threadWorker.js +2 -0
- package/esm/type.d.ts +3 -3
- package/esm/utoo/index.js +6 -6
- package/esm/utoo/index_bg.wasm +0 -0
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -19,8 +19,8 @@ export class Project {
|
|
|
19
19
|
constructor(options) {
|
|
20
20
|
var _a, _b;
|
|
21
21
|
_Project_tunnel.set(this, void 0);
|
|
22
|
-
const { cwd, workerUrl, wasmUrl, threadWorkerUrl,
|
|
23
|
-
this.serviceWorkerOptions =
|
|
22
|
+
const { cwd, workerUrl, wasmUrl, threadWorkerUrl, serviceWorker } = options;
|
|
23
|
+
this.serviceWorkerOptions = serviceWorker;
|
|
24
24
|
const { port1, port2 } = new MessageChannel();
|
|
25
25
|
(_a = this.remote) !== null && _a !== void 0 ? _a : (this.remote = comlink.wrap(port1));
|
|
26
26
|
if (!ProjectWorker) {
|
|
@@ -52,11 +52,12 @@ export class Project {
|
|
|
52
52
|
async installServiceWorker() {
|
|
53
53
|
var _a;
|
|
54
54
|
if (this.serviceWorkerOptions) {
|
|
55
|
-
const {
|
|
56
|
-
|
|
55
|
+
const { url, scope } = this.serviceWorkerOptions;
|
|
56
|
+
// Should add "Service-Worker-Allowed": "/" in page root response,
|
|
57
|
+
await navigator.serviceWorker.register(url, { scope: "/" });
|
|
57
58
|
(_a = navigator.serviceWorker.controller) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
58
59
|
[ServiceWorkerHandShake]: true,
|
|
59
|
-
|
|
60
|
+
scope,
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
}
|
package/esm/serviceWorker.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { Project } from ".";
|
|
2
2
|
import { ServiceWorkerHandShake } from "./message";
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
|
|
3
|
+
let _resolve;
|
|
4
|
+
let _promise = new Promise((resolve) => {
|
|
5
|
+
_resolve = resolve;
|
|
6
6
|
});
|
|
7
|
-
let
|
|
8
|
-
let
|
|
7
|
+
let _projectEndpoint;
|
|
8
|
+
let _serviceWorkerScope;
|
|
9
9
|
self.addEventListener("message", (event) => {
|
|
10
10
|
if (event.data && event.data[ServiceWorkerHandShake] === true) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
_serviceWorkerScope = event.data.scope;
|
|
12
|
+
_projectEndpoint = Project.fork(new MessageChannel(), event.source);
|
|
13
|
+
_resolve();
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
self.addEventListener("fetch", async (event) => {
|
|
17
17
|
const { url, referrer } = event.request;
|
|
18
|
-
if (new URL(url).pathname.startsWith(
|
|
19
|
-
(referrer &&
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const projectPath = "." + new URL(url).pathname.replace(`/${proxiedResourcePath}`, "");
|
|
18
|
+
if (new URL(url).pathname.startsWith(_serviceWorkerScope) ||
|
|
19
|
+
(referrer && new URL(referrer).pathname.startsWith(_serviceWorkerScope))) {
|
|
20
|
+
await _promise;
|
|
21
|
+
const projectPath = "." + new URL(url).pathname.replace(_serviceWorkerScope, "");
|
|
23
22
|
event.respondWith(readFileFromProject(projectPath));
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
@@ -28,7 +27,7 @@ self.addEventListener("fetch", async (event) => {
|
|
|
28
27
|
});
|
|
29
28
|
async function readFileFromProject(projectPath) {
|
|
30
29
|
try {
|
|
31
|
-
const content = await
|
|
30
|
+
const content = await _projectEndpoint.readFile(projectPath);
|
|
32
31
|
let mimeType = "application/octet-stream";
|
|
33
32
|
if (projectPath.endsWith(".js")) {
|
|
34
33
|
mimeType = "application/javascript";
|
package/esm/threadWorker.js
CHANGED
package/esm/type.d.ts
CHANGED
|
@@ -29,9 +29,9 @@ export interface ProjectOptions {
|
|
|
29
29
|
workerUrl?: string;
|
|
30
30
|
threadWorkerUrl: string;
|
|
31
31
|
wasmUrl?: string;
|
|
32
|
-
|
|
32
|
+
serviceWorker?: ServiceWorkerOptions;
|
|
33
33
|
}
|
|
34
34
|
export interface ServiceWorkerOptions {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
url: string;
|
|
36
|
+
scope: string;
|
|
37
37
|
}
|
package/esm/utoo/index.js
CHANGED
|
@@ -1150,27 +1150,27 @@ function __wbg_get_imports() {
|
|
|
1150
1150
|
const ret = false;
|
|
1151
1151
|
return ret;
|
|
1152
1152
|
};
|
|
1153
|
-
imports.wbg.
|
|
1153
|
+
imports.wbg.__wbindgen_closure_wrapper163109 = function (arg0, arg1, arg2) {
|
|
1154
1154
|
const ret = makeMutClosure(arg0, arg1, 9521, __wbg_adapter_49);
|
|
1155
1155
|
return addHeapObject(ret);
|
|
1156
1156
|
};
|
|
1157
|
-
imports.wbg.
|
|
1157
|
+
imports.wbg.__wbindgen_closure_wrapper163111 = function (arg0, arg1, arg2) {
|
|
1158
1158
|
const ret = makeMutClosure(arg0, arg1, 1976, __wbg_adapter_49);
|
|
1159
1159
|
return addHeapObject(ret);
|
|
1160
1160
|
};
|
|
1161
|
-
imports.wbg.
|
|
1161
|
+
imports.wbg.__wbindgen_closure_wrapper168917 = function (arg0, arg1, arg2) {
|
|
1162
1162
|
const ret = makeMutClosure(arg0, arg1, 9521, __wbg_adapter_49);
|
|
1163
1163
|
return addHeapObject(ret);
|
|
1164
1164
|
};
|
|
1165
|
-
imports.wbg.
|
|
1165
|
+
imports.wbg.__wbindgen_closure_wrapper168971 = function (arg0, arg1, arg2) {
|
|
1166
1166
|
const ret = makeMutClosure(arg0, arg1, 9524, __wbg_adapter_56);
|
|
1167
1167
|
return addHeapObject(ret);
|
|
1168
1168
|
};
|
|
1169
|
-
imports.wbg.
|
|
1169
|
+
imports.wbg.__wbindgen_closure_wrapper168994 = function (arg0, arg1, arg2) {
|
|
1170
1170
|
const ret = makeMutClosure(arg0, arg1, 9528, __wbg_adapter_46);
|
|
1171
1171
|
return addHeapObject(ret);
|
|
1172
1172
|
};
|
|
1173
|
-
imports.wbg.
|
|
1173
|
+
imports.wbg.__wbindgen_closure_wrapper30059 = function (arg0, arg1, arg2) {
|
|
1174
1174
|
const ret = makeMutClosure(arg0, arg1, 1976, __wbg_adapter_46);
|
|
1175
1175
|
return addHeapObject(ret);
|
|
1176
1176
|
};
|
package/esm/utoo/index_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/web",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.15",
|
|
4
4
|
"module": "esm/index.js",
|
|
5
5
|
"types": "esm/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
},
|
|
31
31
|
"author": "xusd320",
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"repository": "git@github.com:
|
|
33
|
+
"repository": "git@github.com:utooland/utoo.git"
|
|
34
34
|
}
|