@gravity-ui/app-builder 0.8.1 → 0.8.3
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/README.md
CHANGED
|
@@ -299,7 +299,7 @@ declare module '*.worker.ts' {
|
|
|
299
299
|
```ts
|
|
300
300
|
import {Worker} from '@gravity-ui/app-builder/worker';
|
|
301
301
|
|
|
302
|
-
const MyWorker = new Worker(new URL('./my.worker'
|
|
302
|
+
const MyWorker = new Worker(new URL('./my.worker', import.meta.url));
|
|
303
303
|
```
|
|
304
304
|
|
|
305
305
|
To use the web worker in your main script, you need to communicate with it using the postMessage and onmessage methods. For example:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SharedWorkerPolyfill } from '@okikio/sharedworker';
|
|
2
|
+
declare class WebWorker extends Worker {
|
|
3
|
+
constructor(url: string | URL, options?: WorkerOptions);
|
|
4
|
+
}
|
|
5
|
+
declare class SharedWebWorker extends SharedWorkerPolyfill {
|
|
6
|
+
constructor(url: string | URL, options?: string | WorkerOptions);
|
|
7
|
+
}
|
|
8
|
+
export { WebWorker as Worker, SharedWebWorker as SharedWorker };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @ts-expect-error ts does not find types in @okikio/sharedworker/@types/index.d.ts
|
|
2
|
+
import { SharedWorkerPolyfill } from '@okikio/sharedworker';
|
|
3
|
+
class WebWorker extends Worker {
|
|
4
|
+
constructor(url, options) {
|
|
5
|
+
const objectURL = generateWorkerLoader(url);
|
|
6
|
+
super(objectURL, options);
|
|
7
|
+
URL.revokeObjectURL(objectURL);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class SharedWebWorker extends SharedWorkerPolyfill {
|
|
11
|
+
constructor(url, options) {
|
|
12
|
+
const objectURL = generateWorkerLoader(url);
|
|
13
|
+
super(objectURL, options);
|
|
14
|
+
URL.revokeObjectURL(objectURL);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { WebWorker as Worker, SharedWebWorker as SharedWorker };
|
|
18
|
+
function generateWorkerLoader(url) {
|
|
19
|
+
// eslint-disable-next-line camelcase
|
|
20
|
+
const publicPath = __webpack_public_path__;
|
|
21
|
+
const workerPublicPath = publicPath.match(/^https?:\/\//)
|
|
22
|
+
? publicPath
|
|
23
|
+
: new URL(publicPath, window.location.href).toString();
|
|
24
|
+
const objectURL = URL.createObjectURL(new Blob([
|
|
25
|
+
[
|
|
26
|
+
`self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
|
|
27
|
+
`importScripts(${JSON.stringify(url.toString())});`,
|
|
28
|
+
].join('\n'),
|
|
29
|
+
], {
|
|
30
|
+
type: 'application/javascript',
|
|
31
|
+
}));
|
|
32
|
+
return objectURL;
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
"./worker": {
|
|
11
|
-
"types": "./dist/common/webpack/worker/web-worker.d.
|
|
12
|
-
"default": "./dist/common/webpack/worker/web-worker.
|
|
11
|
+
"types": "./dist/common/webpack/worker/web-worker.d.mts",
|
|
12
|
+
"default": "./dist/common/webpack/worker/web-worker.mjs"
|
|
13
13
|
},
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"./dist/index.d.ts"
|
|
23
23
|
],
|
|
24
24
|
"worker": [
|
|
25
|
-
"./dist/common/webpack/worker/web-worker.d.
|
|
25
|
+
"./dist/common/webpack/worker/web-worker.d.mts"
|
|
26
26
|
]
|
|
27
27
|
}
|
|
28
28
|
},
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"@babel/preset-react": "^7.22.0",
|
|
69
69
|
"@babel/preset-typescript": "^7.22.0",
|
|
70
70
|
"@babel/runtime": "^7.22.0",
|
|
71
|
+
"@okikio/sharedworker": "^1.0.4",
|
|
71
72
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
72
73
|
"@sentry/webpack-plugin": "^2.7.1",
|
|
73
74
|
"@statoscope/webpack-plugin": "^5.27.0",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Worker = void 0;
|
|
4
|
-
class WebWorker extends Worker {
|
|
5
|
-
constructor(url, options) {
|
|
6
|
-
// eslint-disable-next-line camelcase
|
|
7
|
-
const publicPath = __webpack_public_path__;
|
|
8
|
-
const workerPublicPath = publicPath.match(/^https?:\/\//)
|
|
9
|
-
? publicPath
|
|
10
|
-
: new URL(publicPath, window.location.href).toString();
|
|
11
|
-
const objectURL = URL.createObjectURL(new Blob([
|
|
12
|
-
[
|
|
13
|
-
`self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
|
|
14
|
-
`importScripts(${JSON.stringify(url.toString())});`,
|
|
15
|
-
].join('\n'),
|
|
16
|
-
], {
|
|
17
|
-
type: 'application/javascript',
|
|
18
|
-
}));
|
|
19
|
-
super(objectURL, options);
|
|
20
|
-
URL.revokeObjectURL(objectURL);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.Worker = WebWorker;
|