@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 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, serviceWorkerOptions } = options;
23
- this.serviceWorkerOptions = 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 { serviceWorkerUrl, proxiedResourcePath } = this.serviceWorkerOptions;
56
- await navigator.serviceWorker.register(serviceWorkerUrl);
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
- proxiedResourcePath,
60
+ scope,
60
61
  });
61
62
  }
62
63
  }
@@ -1,25 +1,24 @@
1
1
  import { Project } from ".";
2
2
  import { ServiceWorkerHandShake } from "./message";
3
- let __resolve__;
4
- let _promise__ = new Promise((resolve) => {
5
- __resolve__ = resolve;
3
+ let _resolve;
4
+ let _promise = new Promise((resolve) => {
5
+ _resolve = resolve;
6
6
  });
7
- let projectEndpoint;
8
- let proxiedResourcePath;
7
+ let _projectEndpoint;
8
+ let _serviceWorkerScope;
9
9
  self.addEventListener("message", (event) => {
10
10
  if (event.data && event.data[ServiceWorkerHandShake] === true) {
11
- proxiedResourcePath = event.data.proxiedResourcePath;
12
- projectEndpoint = Project.fork(new MessageChannel(), event.source);
13
- __resolve__();
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(`/${proxiedResourcePath}`) ||
19
- (referrer &&
20
- new URL(referrer).pathname.startsWith(`/${proxiedResourcePath}`))) {
21
- await _promise__;
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 projectEndpoint.readFile(projectPath);
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";
@@ -1,2 +1,4 @@
1
1
  import initWasm from "./utoo";
2
+ // this is for wasm_thread to spawn new worker thread.
3
+ // see: https://github.com/utooland/wasm_thread/blob/94438ff771ee0a6a55d79e49a655707970acb615/src/wasm32/js/web_worker.js#L10
2
4
  self.wasm_bindgen = initWasm;
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
- serviceWorkerOptions?: ServiceWorkerOptions;
32
+ serviceWorker?: ServiceWorkerOptions;
33
33
  }
34
34
  export interface ServiceWorkerOptions {
35
- serviceWorkerUrl: string;
36
- proxiedResourcePath: string;
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.__wbindgen_closure_wrapper163125 = function (arg0, arg1, arg2) {
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.__wbindgen_closure_wrapper163127 = function (arg0, arg1, arg2) {
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.__wbindgen_closure_wrapper168916 = function (arg0, arg1, arg2) {
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.__wbindgen_closure_wrapper168970 = function (arg0, arg1, arg2) {
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.__wbindgen_closure_wrapper168993 = function (arg0, arg1, arg2) {
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.__wbindgen_closure_wrapper30076 = function (arg0, arg1, arg2) {
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
  };
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/web",
3
- "version": "0.0.1-alpha.14",
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:umijs/mako.git"
33
+ "repository": "git@github.com:utooland/utoo.git"
34
34
  }