vite-comlink-loader 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +159 -2
- package/client.d.ts +23 -0
- package/dist/index.cjs +345 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +320 -0
- package/dist/index.js.map +1 -0
- package/dist/symbol.cjs +33 -0
- package/dist/symbol.cjs.map +1 -0
- package/dist/symbol.d.cts +4 -0
- package/dist/symbol.d.ts +4 -0
- package/dist/symbol.js +8 -0
- package/dist/symbol.js.map +1 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zeto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vite-comlink-loader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Vite-native port of [`comlink-loader`](https://github.com/GoogleChromeLabs/comlink-loader). It moves an ES module into a Web Worker and exposes all of its runtime exports through [Comlink](https://github.com/GoogleChromeLabs/comlink).
|
|
4
|
+
|
|
5
|
+
It supports Vite development and production builds, TypeScript workers, lazy worker chunks, factory and singleton modes, SharedWorkers, inline workers, HMR cleanup, and access to the underlying endpoint.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install comlink
|
|
11
|
+
npm install --save-dev vite-comlink-loader
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// vite.config.ts
|
|
16
|
+
import { defineConfig } from 'vite';
|
|
17
|
+
import comlinkLoader from 'vite-comlink-loader';
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [comlinkLoader()],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The plugin installs its worker-side companion automatically. Do not add it again to `worker.plugins`.
|
|
25
|
+
|
|
26
|
+
By default, files named `*.worker.js`, `*.worker.jsx`, `*.worker.ts`, and `*.worker.tsx` (including `cjs`, `mjs`, `cts`, and `mts` variants) are handled. Native Vite imports such as `?worker`, `?sharedworker`, `?url`, and `?raw` remain untouched.
|
|
27
|
+
|
|
28
|
+
## Factory mode
|
|
29
|
+
|
|
30
|
+
Factory mode matches the original loader's default behavior:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// math.ts
|
|
34
|
+
export function add(a: number, b: number) {
|
|
35
|
+
return a + b;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Counter {
|
|
39
|
+
constructor(private value = 0) {}
|
|
40
|
+
increment() {
|
|
41
|
+
return ++this.value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
/// <reference types="vite-comlink-loader/client" />
|
|
48
|
+
|
|
49
|
+
import MathWorker from './math.ts?comlink';
|
|
50
|
+
|
|
51
|
+
type MathApi = typeof import('./math');
|
|
52
|
+
|
|
53
|
+
// `new` always creates a new Worker.
|
|
54
|
+
const first = new MathWorker<MathApi>();
|
|
55
|
+
const second = new MathWorker<MathApi>();
|
|
56
|
+
|
|
57
|
+
// Calling without `new` lazily creates and reuses one Worker.
|
|
58
|
+
const shared = MathWorker<MathApi>();
|
|
59
|
+
|
|
60
|
+
console.log(await first.add(20, 22));
|
|
61
|
+
const counter = await new first.Counter(4);
|
|
62
|
+
console.log(await counter.increment());
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Use `singleton: false` to make both call styles create a fresh worker:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
comlinkLoader({ singleton: false });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The same override is available per import:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import MathWorker from './math.ts?comlink&singleton=false';
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For TypeScript factory imports, the explicit `?comlink` syntax is recommended because it provides the generic worker factory type.
|
|
78
|
+
|
|
79
|
+
## Singleton mode
|
|
80
|
+
|
|
81
|
+
Singleton mode eagerly creates one worker and mirrors the source module's named runtime exports:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// vite.config.ts
|
|
85
|
+
comlinkLoader({ singleton: true });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// greetings.worker.ts
|
|
90
|
+
export async function greet(subject: string) {
|
|
91
|
+
return `Hello, ${subject}!`;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { greet } from './greetings.worker.ts';
|
|
97
|
+
|
|
98
|
+
console.log(await greet('dog'));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Type-only exports are omitted, and `export * from` chains are followed. The default import is the complete remote module namespace:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import api from './greetings.worker.ts';
|
|
105
|
+
console.log(await api.greet('cat'));
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Singleton mode can also be selected per import with `?comlink&singleton` or `?comlink=singleton`.
|
|
109
|
+
|
|
110
|
+
## Options
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
interface ComlinkLoaderOptions {
|
|
114
|
+
include?: string | RegExp | Array<string | RegExp>;
|
|
115
|
+
exclude?: string | RegExp | Array<string | RegExp>;
|
|
116
|
+
singleton?: boolean;
|
|
117
|
+
shared?: boolean;
|
|
118
|
+
inline?: boolean;
|
|
119
|
+
workerOptions?: WorkerOptions;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- `include` and `exclude` control automatic imports. Explicit `?comlink` imports are always handled.
|
|
124
|
+
- `singleton` selects singleton (`true`), always-new factory (`false`), or compatible hybrid mode (omitted).
|
|
125
|
+
- `shared` uses a `SharedWorker` and connects Comlink to its port.
|
|
126
|
+
- `inline` asks Vite to inline the worker bundle.
|
|
127
|
+
- `workerOptions` supplies defaults such as the worker `name`. Per-construction options override these defaults.
|
|
128
|
+
|
|
129
|
+
Per-import flags override plugin defaults:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import InlineWorker from './task?comlink&inline';
|
|
133
|
+
import SharedApi from './shared?comlink&shared&singleton';
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Native endpoint and Comlink utilities
|
|
137
|
+
|
|
138
|
+
All normal Comlink transfer handlers and helpers can be used. To access or terminate the native endpoint, use `endpointSymbol`:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { endpointSymbol } from 'vite-comlink-loader/symbol';
|
|
142
|
+
import TaskWorker from './task?comlink';
|
|
143
|
+
|
|
144
|
+
const api = new TaskWorker<typeof import('./task')>();
|
|
145
|
+
const endpoint = api[endpointSymbol];
|
|
146
|
+
if (endpoint instanceof globalThis.Worker) endpoint.terminate();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Workers created by a module are released and terminated when that module is disposed by Vite HMR.
|
|
150
|
+
|
|
151
|
+
## Notes
|
|
152
|
+
|
|
153
|
+
- RPC calls and remote property reads are asynchronous. Use `await` as required by Comlink.
|
|
154
|
+
- Values crossing the worker boundary must be structured-cloneable unless a Comlink transfer handler is used.
|
|
155
|
+
- Worker modules must have statically discoverable ESM exports for singleton named imports. If analysis is not possible, the default remote namespace remains available.
|
|
156
|
+
- This plugin targets browser Web Workers. It does not instantiate workers during SSR by itself, but importing an eager singleton from server-executed code is not supported.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare module '*?comlink' {
|
|
2
|
+
const factory: import('vite-comlink-loader').ComlinkWorkerFactory;
|
|
3
|
+
export default factory;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module '*?comlink&singleton=false' {
|
|
7
|
+
const factory: import('vite-comlink-loader').ComlinkWorkerFactory;
|
|
8
|
+
export default factory;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '*?comlink&singleton' {
|
|
12
|
+
const remote: import('vite-comlink-loader').ComlinkRemote<
|
|
13
|
+
Record<string, unknown>
|
|
14
|
+
>;
|
|
15
|
+
export default remote;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module '*?comlink&singleton=true' {
|
|
19
|
+
const remote: import('vite-comlink-loader').ComlinkRemote<
|
|
20
|
+
Record<string, unknown>
|
|
21
|
+
>;
|
|
22
|
+
export default remote;
|
|
23
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
comlink: () => comlink,
|
|
24
|
+
comlinkLoader: () => comlinkLoader,
|
|
25
|
+
default: () => index_default,
|
|
26
|
+
endpointSymbol: () => endpointSymbol
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_promises = require("fs/promises");
|
|
30
|
+
var import_node_crypto = require("crypto");
|
|
31
|
+
var import_node_path = require("path");
|
|
32
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
33
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
34
|
+
var import_vite = require("vite");
|
|
35
|
+
|
|
36
|
+
// src/symbol.ts
|
|
37
|
+
var endpointSymbol = /* @__PURE__ */ Symbol.for(
|
|
38
|
+
"vite-comlink-loader.endpoint"
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// src/index.ts
|
|
42
|
+
var PLUGIN_NAME = "vite-comlink-loader";
|
|
43
|
+
var PROXY_PREFIX = "\0vite-comlink-loader:proxy:";
|
|
44
|
+
var ENTRY_MARKER = ".vite-comlink-loader-entry.";
|
|
45
|
+
var SOURCE_QUERY = "vite-comlink-loader-source";
|
|
46
|
+
var CONTROL_PARAMS = /* @__PURE__ */ new Set([
|
|
47
|
+
"comlink",
|
|
48
|
+
"comlink-loader",
|
|
49
|
+
"singleton",
|
|
50
|
+
"shared",
|
|
51
|
+
"inline"
|
|
52
|
+
]);
|
|
53
|
+
var defaultInclude = /\.worker\.[cm]?[jt]sx?$/i;
|
|
54
|
+
var identifierName = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
|
|
55
|
+
function cleanUrl(id) {
|
|
56
|
+
return id.replace(/[?#].*$/, "");
|
|
57
|
+
}
|
|
58
|
+
function encode(value) {
|
|
59
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
60
|
+
}
|
|
61
|
+
function decode(id, prefix) {
|
|
62
|
+
const encoded = cleanUrl(id).slice(prefix.length);
|
|
63
|
+
return JSON.parse(Buffer.from(encoded, "base64url").toString());
|
|
64
|
+
}
|
|
65
|
+
function entryId(payload, entries) {
|
|
66
|
+
const serialized = JSON.stringify(payload);
|
|
67
|
+
const key = (0, import_node_crypto.createHash)("sha256").update(serialized).digest("hex").slice(0, 16);
|
|
68
|
+
entries.set(key, payload);
|
|
69
|
+
return `${cleanUrl(payload.source)}${ENTRY_MARKER}${key}.js`;
|
|
70
|
+
}
|
|
71
|
+
function isEntryId(id) {
|
|
72
|
+
return cleanUrl(id).includes(ENTRY_MARKER);
|
|
73
|
+
}
|
|
74
|
+
function decodeEntry(id, entries) {
|
|
75
|
+
const file = cleanUrl(id);
|
|
76
|
+
const marker = file.lastIndexOf(ENTRY_MARKER);
|
|
77
|
+
const key = file.slice(marker + ENTRY_MARKER.length, -".js".length);
|
|
78
|
+
const payload = entries.get(key);
|
|
79
|
+
if (!payload) {
|
|
80
|
+
throw new Error(`${PLUGIN_NAME}: unknown worker entry ${JSON.stringify(id)}`);
|
|
81
|
+
}
|
|
82
|
+
return payload;
|
|
83
|
+
}
|
|
84
|
+
function queryOf(source) {
|
|
85
|
+
const queryStart = source.indexOf("?");
|
|
86
|
+
if (queryStart < 0) return new URLSearchParams();
|
|
87
|
+
const hashStart = source.indexOf("#", queryStart);
|
|
88
|
+
return new URLSearchParams(
|
|
89
|
+
source.slice(queryStart + 1, hashStart < 0 ? void 0 : hashStart)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function withoutControlParams(source) {
|
|
93
|
+
const hashStart = source.indexOf("#");
|
|
94
|
+
const hash = hashStart < 0 ? "" : source.slice(hashStart);
|
|
95
|
+
const request = hashStart < 0 ? source : source.slice(0, hashStart);
|
|
96
|
+
const queryStart = request.indexOf("?");
|
|
97
|
+
if (queryStart < 0) return request + hash;
|
|
98
|
+
const params = new URLSearchParams(request.slice(queryStart + 1));
|
|
99
|
+
for (const key of CONTROL_PARAMS) params.delete(key);
|
|
100
|
+
const query = params.toString();
|
|
101
|
+
return request.slice(0, queryStart) + (query ? `?${query}` : "") + hash;
|
|
102
|
+
}
|
|
103
|
+
function withSourceQuery(source) {
|
|
104
|
+
const hashStart = source.indexOf("#");
|
|
105
|
+
const hash = hashStart < 0 ? "" : source.slice(hashStart);
|
|
106
|
+
const request = hashStart < 0 ? source : source.slice(0, hashStart);
|
|
107
|
+
const separator = request.includes("?") ? "&" : "?";
|
|
108
|
+
return `${request}${separator}${SOURCE_QUERY}${hash}`;
|
|
109
|
+
}
|
|
110
|
+
function isViteWorkerRequest(params) {
|
|
111
|
+
return params.has("worker") || params.has("sharedworker") || params.has("url") || params.has("raw");
|
|
112
|
+
}
|
|
113
|
+
function isWorkerConstructorRequest(id) {
|
|
114
|
+
const params = queryOf(id);
|
|
115
|
+
return params.has("worker") || params.has("sharedworker");
|
|
116
|
+
}
|
|
117
|
+
function optionMode(value) {
|
|
118
|
+
return value === true ? "singleton" : value === false ? "factory" : "hybrid";
|
|
119
|
+
}
|
|
120
|
+
function requestMode(params, fallback) {
|
|
121
|
+
const comlinkValue = params.get("comlink") ?? params.get("comlink-loader");
|
|
122
|
+
if (comlinkValue === "singleton") return "singleton";
|
|
123
|
+
if (comlinkValue === "factory" || comlinkValue === "multiple") return "factory";
|
|
124
|
+
if (!params.has("singleton")) return fallback;
|
|
125
|
+
const singleton = params.get("singleton");
|
|
126
|
+
return singleton === "false" || singleton === "0" ? "factory" : "singleton";
|
|
127
|
+
}
|
|
128
|
+
function esbuildLoader(file) {
|
|
129
|
+
switch ((0, import_node_path.extname)(cleanUrl(file)).toLowerCase()) {
|
|
130
|
+
case ".ts":
|
|
131
|
+
case ".mts":
|
|
132
|
+
case ".cts":
|
|
133
|
+
return "ts";
|
|
134
|
+
case ".tsx":
|
|
135
|
+
return "tsx";
|
|
136
|
+
case ".jsx":
|
|
137
|
+
return "jsx";
|
|
138
|
+
default:
|
|
139
|
+
return "js";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function exportedNames(context, id, seen = /* @__PURE__ */ new Set()) {
|
|
143
|
+
const file = cleanUrl(id);
|
|
144
|
+
if (file.startsWith("\0") || seen.has(file)) return [];
|
|
145
|
+
seen.add(file);
|
|
146
|
+
const source = await (0, import_promises.readFile)(file, "utf8");
|
|
147
|
+
const transformed = await (0, import_vite.transformWithEsbuild)(source, file, {
|
|
148
|
+
loader: esbuildLoader(file),
|
|
149
|
+
target: "esnext",
|
|
150
|
+
sourcemap: false
|
|
151
|
+
});
|
|
152
|
+
await import_es_module_lexer.init;
|
|
153
|
+
const [imports, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
|
|
154
|
+
const names = /* @__PURE__ */ new Set();
|
|
155
|
+
for (const item of exports2) {
|
|
156
|
+
const name = typeof item === "string" ? item : item.n;
|
|
157
|
+
if (name && name !== "default" && name !== "__esModule") names.add(name);
|
|
158
|
+
}
|
|
159
|
+
for (const imported of imports) {
|
|
160
|
+
if (!imported.n) continue;
|
|
161
|
+
const statement = transformed.code.slice(imported.ss, imported.se);
|
|
162
|
+
if (!/^\s*export\s*\*\s*from\b/.test(statement)) continue;
|
|
163
|
+
const resolved = await context.resolve(imported.n, file, { skipSelf: true });
|
|
164
|
+
if (!resolved || resolved.external) continue;
|
|
165
|
+
for (const name of await exportedNames(context, resolved.id, seen)) {
|
|
166
|
+
names.add(name);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return [...names].sort();
|
|
170
|
+
}
|
|
171
|
+
function workerEntryCode(payload) {
|
|
172
|
+
const source = JSON.stringify(withSourceQuery(payload.source));
|
|
173
|
+
if (payload.shared) {
|
|
174
|
+
return `
|
|
175
|
+
import { expose as __expose } from "comlink";
|
|
176
|
+
import * as __api from ${source};
|
|
177
|
+
self.addEventListener("connect", (__event) => {
|
|
178
|
+
const __port = __event.ports[0];
|
|
179
|
+
if (__port) __expose(__api, __port);
|
|
180
|
+
});
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
return `
|
|
184
|
+
import { expose as __expose } from "comlink";
|
|
185
|
+
import * as __api from ${source};
|
|
186
|
+
__expose(__api);
|
|
187
|
+
`;
|
|
188
|
+
}
|
|
189
|
+
function proxyCode(payload, entries) {
|
|
190
|
+
const workerEntryId = entryId(
|
|
191
|
+
{
|
|
192
|
+
shared: payload.shared,
|
|
193
|
+
source: payload.source
|
|
194
|
+
},
|
|
195
|
+
entries
|
|
196
|
+
);
|
|
197
|
+
const workerQuery = payload.shared ? "sharedworker" : "worker";
|
|
198
|
+
const workerRequest = `${workerEntryId}?${workerQuery}${payload.inline ? "&inline" : ""}`;
|
|
199
|
+
const defaults = JSON.stringify(payload.workerOptions ?? {});
|
|
200
|
+
const endpoint = payload.shared ? "__worker.port" : "__worker";
|
|
201
|
+
const namedExports = [];
|
|
202
|
+
if (payload.mode === "singleton") {
|
|
203
|
+
payload.exports.forEach((name, index) => {
|
|
204
|
+
if (!identifierName.test(name)) return;
|
|
205
|
+
namedExports.push(
|
|
206
|
+
`const __export${index} = __singleton[${JSON.stringify(name)}];
|
|
207
|
+
export { __export${index} as ${name} };`
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const factory = payload.mode === "singleton" ? `const __singleton = __create();
|
|
212
|
+
export default __singleton;` : payload.mode === "factory" ? `function ComlinkWorker(options) { return __create(options); }
|
|
213
|
+
export default ComlinkWorker;` : `let __singleton;
|
|
214
|
+
function ComlinkWorker(options) {
|
|
215
|
+
if (new.target) return __create(options);
|
|
216
|
+
return __singleton || (__singleton = __create(options));
|
|
217
|
+
}
|
|
218
|
+
export default ComlinkWorker;`;
|
|
219
|
+
return `
|
|
220
|
+
import { releaseProxy as __releaseProxy, wrap as __wrap } from "comlink";
|
|
221
|
+
import __Worker from ${JSON.stringify(workerRequest)};
|
|
222
|
+
|
|
223
|
+
const __endpointSymbol = Symbol.for("vite-comlink-loader.endpoint");
|
|
224
|
+
const __defaults = ${defaults};
|
|
225
|
+
const __active = new Set();
|
|
226
|
+
|
|
227
|
+
function __create(options) {
|
|
228
|
+
const __worker = new __Worker(Object.assign({}, __defaults, options));
|
|
229
|
+
const __remote = __wrap(${endpoint});
|
|
230
|
+
const __proxy = new Proxy(__remote, {
|
|
231
|
+
get(target, property, receiver) {
|
|
232
|
+
if (property === __endpointSymbol) return __worker;
|
|
233
|
+
return Reflect.get(target, property, receiver);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
__active.add({ endpoint: __worker, remote: __remote });
|
|
237
|
+
return __proxy;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
${factory}
|
|
241
|
+
${namedExports.join("\n")}
|
|
242
|
+
|
|
243
|
+
if (import.meta.hot) {
|
|
244
|
+
import.meta.hot.dispose(() => {
|
|
245
|
+
for (const { endpoint, remote } of __active) {
|
|
246
|
+
try { remote[__releaseProxy](); } catch {}
|
|
247
|
+
try { endpoint.port?.close(); } catch {}
|
|
248
|
+
try { endpoint.terminate?.(); } catch {}
|
|
249
|
+
}
|
|
250
|
+
__active.clear();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
}
|
|
255
|
+
function entryPlugin(entries) {
|
|
256
|
+
return {
|
|
257
|
+
name: `${PLUGIN_NAME}:worker-entry`,
|
|
258
|
+
enforce: "pre",
|
|
259
|
+
resolveId(id) {
|
|
260
|
+
if (isEntryId(id)) return id;
|
|
261
|
+
return null;
|
|
262
|
+
},
|
|
263
|
+
load(id) {
|
|
264
|
+
if (!isEntryId(id) || isWorkerConstructorRequest(id)) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return workerEntryCode(decodeEntry(id, entries));
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function appendWorkerPlugin(config, plugin) {
|
|
272
|
+
const previous = config.worker?.plugins;
|
|
273
|
+
const plugins = (...args) => {
|
|
274
|
+
const existing = typeof previous === "function" ? previous(...args) : previous;
|
|
275
|
+
const values = existing == null ? [] : Array.isArray(existing) ? existing : [existing];
|
|
276
|
+
return [...values, plugin];
|
|
277
|
+
};
|
|
278
|
+
config.worker ??= {};
|
|
279
|
+
config.worker.plugins = plugins;
|
|
280
|
+
}
|
|
281
|
+
function comlinkLoader(options = {}) {
|
|
282
|
+
const filter = (0, import_pluginutils.createFilter)(options.include ?? defaultInclude, options.exclude);
|
|
283
|
+
const fallbackMode = optionMode(options.singleton);
|
|
284
|
+
const entries = /* @__PURE__ */ new Map();
|
|
285
|
+
const workerPlugin = entryPlugin(entries);
|
|
286
|
+
return {
|
|
287
|
+
name: PLUGIN_NAME,
|
|
288
|
+
enforce: "pre",
|
|
289
|
+
config(config) {
|
|
290
|
+
appendWorkerPlugin(config, workerPlugin);
|
|
291
|
+
},
|
|
292
|
+
async resolveId(source, importer) {
|
|
293
|
+
if (source.startsWith(PROXY_PREFIX) || isEntryId(source)) {
|
|
294
|
+
return source;
|
|
295
|
+
}
|
|
296
|
+
const params = queryOf(source);
|
|
297
|
+
if (params.has(SOURCE_QUERY)) return null;
|
|
298
|
+
const explicit = params.has("comlink") || params.has("comlink-loader");
|
|
299
|
+
if (!explicit && isViteWorkerRequest(params)) return null;
|
|
300
|
+
const request = explicit ? withoutControlParams(source) : source;
|
|
301
|
+
const resolved = await this.resolve(request, importer, { skipSelf: true });
|
|
302
|
+
if (!resolved || resolved.external) return null;
|
|
303
|
+
if (!explicit && !filter(cleanUrl(resolved.id))) return null;
|
|
304
|
+
const mode = requestMode(params, fallbackMode);
|
|
305
|
+
let exports2 = [];
|
|
306
|
+
if (mode === "singleton") {
|
|
307
|
+
try {
|
|
308
|
+
exports2 = await exportedNames(this, resolved.id);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
this.warn(
|
|
311
|
+
`Could not inspect exports of ${cleanUrl(resolved.id)}; the default singleton export remains available. ${String(error)}`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const payload = {
|
|
316
|
+
explicit,
|
|
317
|
+
source: resolved.id,
|
|
318
|
+
mode,
|
|
319
|
+
shared: params.has("shared") ? params.get("shared") !== "false" : !!options.shared,
|
|
320
|
+
inline: params.has("inline") ? params.get("inline") !== "false" : !!options.inline,
|
|
321
|
+
exports: exports2,
|
|
322
|
+
workerOptions: options.workerOptions
|
|
323
|
+
};
|
|
324
|
+
return `${PROXY_PREFIX}${encode(payload)}`;
|
|
325
|
+
},
|
|
326
|
+
load(id) {
|
|
327
|
+
if (id.startsWith(PROXY_PREFIX)) {
|
|
328
|
+
return proxyCode(decode(id, PROXY_PREFIX), entries);
|
|
329
|
+
}
|
|
330
|
+
if (isEntryId(id) && !isWorkerConstructorRequest(id)) {
|
|
331
|
+
return workerEntryCode(decodeEntry(id, entries));
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
var comlink = comlinkLoader;
|
|
338
|
+
var index_default = comlinkLoader;
|
|
339
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
340
|
+
0 && (module.exports = {
|
|
341
|
+
comlink,
|
|
342
|
+
comlinkLoader,
|
|
343
|
+
endpointSymbol
|
|
344
|
+
});
|
|
345
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/symbol.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { createHash } from 'node:crypto';\nimport { extname } from 'node:path';\nimport { createFilter, type FilterPattern } from '@rollup/pluginutils';\nimport type { Remote } from 'comlink';\nimport { init, parse } from 'es-module-lexer';\nimport {\n transformWithEsbuild,\n type Plugin,\n type PluginOption,\n type UserConfig,\n} from 'vite';\nimport { endpointSymbol } from './symbol.js';\n\nexport { endpointSymbol };\n\nexport type ComlinkRemote<T extends object> = Remote<T> & {\n readonly [endpointSymbol]: Worker | SharedWorker;\n};\n\nexport interface ComlinkWorkerFactory {\n new <T extends object = Record<string, unknown>>(\n options?: WorkerOptions,\n ): ComlinkRemote<T>;\n <T extends object = Record<string, unknown>>(\n options?: WorkerOptions,\n ): ComlinkRemote<T>;\n}\n\nconst PLUGIN_NAME = 'vite-comlink-loader';\nconst PROXY_PREFIX = '\\0vite-comlink-loader:proxy:';\n// Vite's dev worker URL converter treats `\\0` IDs as filesystem paths. Worker\n// entries therefore use a physical-looking ID next to their source file.\nconst ENTRY_MARKER = '.vite-comlink-loader-entry.';\nconst SOURCE_QUERY = 'vite-comlink-loader-source';\nconst CONTROL_PARAMS = new Set([\n 'comlink',\n 'comlink-loader',\n 'singleton',\n 'shared',\n 'inline',\n]);\n\ntype Mode = 'hybrid' | 'factory' | 'singleton';\n\nexport interface ComlinkLoaderOptions {\n /** Modules handled automatically. Defaults to `.worker.js` / `.worker.ts` variants. */\n include?: FilterPattern;\n /** Modules that must never be handled automatically. */\n exclude?: FilterPattern;\n /**\n * `true` exposes one eagerly-created proxy; `false` makes every call create a\n * worker. If omitted, calling the factory reuses one worker while `new`\n * always creates a fresh worker, matching comlink-loader.\n */\n singleton?: boolean;\n /** Generate SharedWorkers instead of dedicated Workers. */\n shared?: boolean;\n /** Ask Vite to inline the generated worker. */\n inline?: boolean;\n /** Default options passed to Vite's generated Worker constructor. */\n workerOptions?: WorkerOptions;\n}\n\ninterface RequestOptions {\n explicit: boolean;\n inline: boolean;\n mode: Mode;\n shared: boolean;\n source: string;\n}\n\ninterface ProxyPayload extends RequestOptions {\n exports: string[];\n workerOptions?: WorkerOptions;\n}\n\ninterface EntryPayload {\n shared: boolean;\n source: string;\n}\n\ninterface ExportResolveContext {\n resolve(\n source: string,\n importer?: string,\n options?: { skipSelf?: boolean },\n ): Promise<{ external?: boolean | string; id: string } | null>;\n}\n\nconst defaultInclude = /\\.worker\\.[cm]?[jt]sx?$/i;\nconst identifierName = /^[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*$/u;\n\nfunction cleanUrl(id: string): string {\n return id.replace(/[?#].*$/, '');\n}\n\nfunction encode(value: unknown): string {\n return Buffer.from(JSON.stringify(value)).toString('base64url');\n}\n\nfunction decode<T>(id: string, prefix: string): T {\n const encoded = cleanUrl(id).slice(prefix.length);\n return JSON.parse(Buffer.from(encoded, 'base64url').toString()) as T;\n}\n\nfunction entryId(\n payload: EntryPayload,\n entries: Map<string, EntryPayload>,\n): string {\n const serialized = JSON.stringify(payload);\n const key = createHash('sha256').update(serialized).digest('hex').slice(0, 16);\n entries.set(key, payload);\n return `${cleanUrl(payload.source)}${ENTRY_MARKER}${key}.js`;\n}\n\nfunction isEntryId(id: string): boolean {\n return cleanUrl(id).includes(ENTRY_MARKER);\n}\n\nfunction decodeEntry(\n id: string,\n entries: Map<string, EntryPayload>,\n): EntryPayload {\n const file = cleanUrl(id);\n const marker = file.lastIndexOf(ENTRY_MARKER);\n const key = file.slice(marker + ENTRY_MARKER.length, -'.js'.length);\n const payload = entries.get(key);\n if (!payload) {\n throw new Error(`${PLUGIN_NAME}: unknown worker entry ${JSON.stringify(id)}`);\n }\n return payload;\n}\n\nfunction queryOf(source: string): URLSearchParams {\n const queryStart = source.indexOf('?');\n if (queryStart < 0) return new URLSearchParams();\n const hashStart = source.indexOf('#', queryStart);\n return new URLSearchParams(\n source.slice(queryStart + 1, hashStart < 0 ? undefined : hashStart),\n );\n}\n\nfunction withoutControlParams(source: string): string {\n const hashStart = source.indexOf('#');\n const hash = hashStart < 0 ? '' : source.slice(hashStart);\n const request = hashStart < 0 ? source : source.slice(0, hashStart);\n const queryStart = request.indexOf('?');\n if (queryStart < 0) return request + hash;\n\n const params = new URLSearchParams(request.slice(queryStart + 1));\n for (const key of CONTROL_PARAMS) params.delete(key);\n const query = params.toString();\n return request.slice(0, queryStart) + (query ? `?${query}` : '') + hash;\n}\n\nfunction withSourceQuery(source: string): string {\n const hashStart = source.indexOf('#');\n const hash = hashStart < 0 ? '' : source.slice(hashStart);\n const request = hashStart < 0 ? source : source.slice(0, hashStart);\n const separator = request.includes('?') ? '&' : '?';\n return `${request}${separator}${SOURCE_QUERY}${hash}`;\n}\n\nfunction isViteWorkerRequest(params: URLSearchParams): boolean {\n return (\n params.has('worker') ||\n params.has('sharedworker') ||\n params.has('url') ||\n params.has('raw')\n );\n}\n\nfunction isWorkerConstructorRequest(id: string): boolean {\n const params = queryOf(id);\n return params.has('worker') || params.has('sharedworker');\n}\n\nfunction optionMode(value: boolean | undefined): Mode {\n return value === true ? 'singleton' : value === false ? 'factory' : 'hybrid';\n}\n\nfunction requestMode(params: URLSearchParams, fallback: Mode): Mode {\n const comlinkValue = params.get('comlink') ?? params.get('comlink-loader');\n if (comlinkValue === 'singleton') return 'singleton';\n if (comlinkValue === 'factory' || comlinkValue === 'multiple') return 'factory';\n if (!params.has('singleton')) return fallback;\n const singleton = params.get('singleton');\n return singleton === 'false' || singleton === '0' ? 'factory' : 'singleton';\n}\n\nfunction esbuildLoader(file: string): 'js' | 'jsx' | 'ts' | 'tsx' {\n switch (extname(cleanUrl(file)).toLowerCase()) {\n case '.ts':\n case '.mts':\n case '.cts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n case '.jsx':\n return 'jsx';\n default:\n return 'js';\n }\n}\n\nasync function exportedNames(\n context: ExportResolveContext,\n id: string,\n seen = new Set<string>(),\n): Promise<string[]> {\n const file = cleanUrl(id);\n if (file.startsWith('\\0') || seen.has(file)) return [];\n seen.add(file);\n\n const source = await readFile(file, 'utf8');\n const transformed = await transformWithEsbuild(source, file, {\n loader: esbuildLoader(file),\n target: 'esnext',\n sourcemap: false,\n });\n await init;\n const [imports, exports] = parse(transformed.code);\n const names = new Set<string>();\n\n for (const item of exports) {\n const name = typeof item === 'string' ? item : item.n;\n if (name && name !== 'default' && name !== '__esModule') names.add(name);\n }\n\n for (const imported of imports) {\n if (!imported.n) continue;\n const statement = transformed.code.slice(imported.ss, imported.se);\n if (!/^\\s*export\\s*\\*\\s*from\\b/.test(statement)) continue;\n const resolved = await context.resolve(imported.n, file, { skipSelf: true });\n if (!resolved || resolved.external) continue;\n for (const name of await exportedNames(context, resolved.id, seen)) {\n names.add(name);\n }\n }\n\n return [...names].sort();\n}\n\nfunction workerEntryCode(payload: EntryPayload): string {\n const source = JSON.stringify(withSourceQuery(payload.source));\n if (payload.shared) {\n return `\nimport { expose as __expose } from \"comlink\";\nimport * as __api from ${source};\nself.addEventListener(\"connect\", (__event) => {\n const __port = __event.ports[0];\n if (__port) __expose(__api, __port);\n});\n`;\n }\n\n return `\nimport { expose as __expose } from \"comlink\";\nimport * as __api from ${source};\n__expose(__api);\n`;\n}\n\nfunction proxyCode(\n payload: ProxyPayload,\n entries: Map<string, EntryPayload>,\n): string {\n const workerEntryId = entryId(\n {\n shared: payload.shared,\n source: payload.source,\n },\n entries,\n );\n const workerQuery = payload.shared ? 'sharedworker' : 'worker';\n const workerRequest = `${workerEntryId}?${workerQuery}${payload.inline ? '&inline' : ''}`;\n const defaults = JSON.stringify(payload.workerOptions ?? {});\n const endpoint = payload.shared ? '__worker.port' : '__worker';\n const namedExports: string[] = [];\n\n if (payload.mode === 'singleton') {\n payload.exports.forEach((name, index) => {\n if (!identifierName.test(name)) return;\n namedExports.push(\n `const __export${index} = __singleton[${JSON.stringify(name)}];\\n` +\n `export { __export${index} as ${name} };`,\n );\n });\n }\n\n const factory =\n payload.mode === 'singleton'\n ? `const __singleton = __create();\\nexport default __singleton;`\n : payload.mode === 'factory'\n ? `function ComlinkWorker(options) { return __create(options); }\\nexport default ComlinkWorker;`\n : `let __singleton;\\nfunction ComlinkWorker(options) {\\n if (new.target) return __create(options);\\n return __singleton || (__singleton = __create(options));\\n}\\nexport default ComlinkWorker;`;\n\n return `\nimport { releaseProxy as __releaseProxy, wrap as __wrap } from \"comlink\";\nimport __Worker from ${JSON.stringify(workerRequest)};\n\nconst __endpointSymbol = Symbol.for(\"vite-comlink-loader.endpoint\");\nconst __defaults = ${defaults};\nconst __active = new Set();\n\nfunction __create(options) {\n const __worker = new __Worker(Object.assign({}, __defaults, options));\n const __remote = __wrap(${endpoint});\n const __proxy = new Proxy(__remote, {\n get(target, property, receiver) {\n if (property === __endpointSymbol) return __worker;\n return Reflect.get(target, property, receiver);\n }\n });\n __active.add({ endpoint: __worker, remote: __remote });\n return __proxy;\n}\n\n${factory}\n${namedExports.join('\\n')}\n\nif (import.meta.hot) {\n import.meta.hot.dispose(() => {\n for (const { endpoint, remote } of __active) {\n try { remote[__releaseProxy](); } catch {}\n try { endpoint.port?.close(); } catch {}\n try { endpoint.terminate?.(); } catch {}\n }\n __active.clear();\n });\n}\n`;\n}\n\nfunction entryPlugin(entries: Map<string, EntryPayload>): Plugin {\n return {\n name: `${PLUGIN_NAME}:worker-entry`,\n enforce: 'pre',\n resolveId(id) {\n if (isEntryId(id)) return id;\n return null;\n },\n load(id) {\n if (!isEntryId(id) || isWorkerConstructorRequest(id)) {\n return null;\n }\n return workerEntryCode(decodeEntry(id, entries));\n },\n };\n}\n\nfunction appendWorkerPlugin(config: UserConfig, plugin: Plugin): void {\n const previous = config.worker?.plugins;\n const plugins = (...args: unknown[]): PluginOption[] => {\n const existing = typeof previous === 'function'\n ? (previous as (...values: unknown[]) => PluginOption[])(...args)\n : previous;\n const values = existing == null\n ? []\n : Array.isArray(existing)\n ? existing\n : [existing];\n return [...values, plugin];\n };\n\n config.worker ??= {};\n config.worker.plugins = plugins;\n}\n\n/** Create the Vite-native comlink-loader plugin. */\nexport function comlinkLoader(options: ComlinkLoaderOptions = {}): Plugin {\n const filter = createFilter(options.include ?? defaultInclude, options.exclude);\n const fallbackMode = optionMode(options.singleton);\n const entries = new Map<string, EntryPayload>();\n const workerPlugin = entryPlugin(entries);\n\n return {\n name: PLUGIN_NAME,\n enforce: 'pre',\n\n config(config) {\n appendWorkerPlugin(config, workerPlugin);\n },\n\n async resolveId(source, importer) {\n if (source.startsWith(PROXY_PREFIX) || isEntryId(source)) {\n return source;\n }\n\n const params = queryOf(source);\n if (params.has(SOURCE_QUERY)) return null;\n const explicit = params.has('comlink') || params.has('comlink-loader');\n if (!explicit && isViteWorkerRequest(params)) return null;\n\n const request = explicit ? withoutControlParams(source) : source;\n const resolved = await this.resolve(request, importer, { skipSelf: true });\n if (!resolved || resolved.external) return null;\n if (!explicit && !filter(cleanUrl(resolved.id))) return null;\n\n const mode = requestMode(params, fallbackMode);\n let exports: string[] = [];\n if (mode === 'singleton') {\n try {\n exports = await exportedNames(this, resolved.id);\n } catch (error) {\n this.warn(\n `Could not inspect exports of ${cleanUrl(resolved.id)}; ` +\n `the default singleton export remains available. ${String(error)}`,\n );\n }\n }\n\n const payload: ProxyPayload = {\n explicit,\n source: resolved.id,\n mode,\n shared: params.has('shared') ? params.get('shared') !== 'false' : !!options.shared,\n inline: params.has('inline') ? params.get('inline') !== 'false' : !!options.inline,\n exports,\n workerOptions: options.workerOptions,\n };\n return `${PROXY_PREFIX}${encode(payload)}`;\n },\n\n load(id) {\n if (id.startsWith(PROXY_PREFIX)) {\n return proxyCode(decode<ProxyPayload>(id, PROXY_PREFIX), entries);\n }\n if (isEntryId(id) && !isWorkerConstructorRequest(id)) {\n return workerEntryCode(decodeEntry(id, entries));\n }\n return null;\n },\n };\n}\n\n/** Short alias, mirroring other Comlink integrations. */\nexport const comlink = comlinkLoader;\n\nexport default comlinkLoader;\n","/** Access the native Worker or SharedWorker behind a Comlink proxy. */\nexport const endpointSymbol: unique symbol = Symbol.for(\n 'vite-comlink-loader.endpoint',\n) as typeof endpointSymbol;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAyB;AACzB,yBAA2B;AAC3B,uBAAwB;AACxB,yBAAiD;AAEjD,6BAA4B;AAC5B,kBAKO;;;ACVA,IAAM,iBAAgC,uBAAO;AAAA,EAClD;AACF;;;AD0BA,IAAM,cAAc;AACpB,IAAM,eAAe;AAGrB,IAAM,eAAe;AACrB,IAAM,eAAe;AACrB,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAiDD,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAEvB,SAAS,SAAS,IAAoB;AACpC,SAAO,GAAG,QAAQ,WAAW,EAAE;AACjC;AAEA,SAAS,OAAO,OAAwB;AACtC,SAAO,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC,EAAE,SAAS,WAAW;AAChE;AAEA,SAAS,OAAU,IAAY,QAAmB;AAChD,QAAM,UAAU,SAAS,EAAE,EAAE,MAAM,OAAO,MAAM;AAChD,SAAO,KAAK,MAAM,OAAO,KAAK,SAAS,WAAW,EAAE,SAAS,CAAC;AAChE;AAEA,SAAS,QACP,SACA,SACQ;AACR,QAAM,aAAa,KAAK,UAAU,OAAO;AACzC,QAAM,UAAM,+BAAW,QAAQ,EAAE,OAAO,UAAU,EAAE,OAAO,KAAK,EAAE,MA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ils';
|
|
2
|
+
import { Remote } from 'comlink';
|
|
3
|
+
import { Plugin } from 'vite';
|
|
4
|
+
import { endpointSymbol } from './symbol.cjs';
|
|
5
|
+
|
|
6
|
+
type ComlinkRemote<T extends object> = Remote<T> & {
|
|
7
|
+
readonly [endpointSymbol]: Worker | SharedWorker;
|
|
8
|
+
};
|
|
9
|
+
interface ComlinkWorkerFactory {
|
|
10
|
+
new <T extends object = Record<string, unknown>>(options?: WorkerOptions): ComlinkRemote<T>;
|
|
11
|
+
<T extends object = Record<string, unknown>>(options?: WorkerOptions): ComlinkRemote<T>;
|
|
12
|
+
}
|
|
13
|
+
interface ComlinkLoaderOptions {
|
|
14
|
+
/** Modules handled automatically. Defaults to `.worker.js` / `.worker.ts` variants. */
|
|
15
|
+
include?: FilterPattern;
|
|
16
|
+
/** Modules that must never be handled automatically. */
|
|
17
|
+
exclude?: FilterPattern;
|
|
18
|
+
/**
|
|
19
|
+
* `true` exposes one eagerly-created proxy; `false` makes every call create a
|
|
20
|
+
* worker. If omitted, calling the factory reuses one worker while `new`
|
|
21
|
+
* always creates a fresh worker, matching comlink-loader.
|
|
22
|
+
*/
|
|
23
|
+
singleton?: boolean;
|
|
24
|
+
/** Generate SharedWorkers instead of dedicated Workers. */
|
|
25
|
+
shared?: boolean;
|
|
26
|
+
/** Ask Vite to inline the generated worker. */
|
|
27
|
+
inline?: boolean;
|
|
28
|
+
/** Default options passed to Vite's generated Worker constructor. */
|
|
29
|
+
workerOptions?: WorkerOptions;
|
|
30
|
+
}
|
|
31
|
+
/** Create the Vite-native comlink-loader plugin. */
|
|
32
|
+
declare function comlinkLoader(options?: ComlinkLoaderOptions): Plugin;
|
|
33
|
+
/** Short alias, mirroring other Comlink integrations. */
|
|
34
|
+
declare const comlink: typeof comlinkLoader;
|
|
35
|
+
|
|
36
|
+
export { type ComlinkLoaderOptions, type ComlinkRemote, type ComlinkWorkerFactory, comlink, comlinkLoader, comlinkLoader as default, endpointSymbol };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
+
import { Remote } from 'comlink';
|
|
3
|
+
import { Plugin } from 'vite';
|
|
4
|
+
import { endpointSymbol } from './symbol.js';
|
|
5
|
+
|
|
6
|
+
type ComlinkRemote<T extends object> = Remote<T> & {
|
|
7
|
+
readonly [endpointSymbol]: Worker | SharedWorker;
|
|
8
|
+
};
|
|
9
|
+
interface ComlinkWorkerFactory {
|
|
10
|
+
new <T extends object = Record<string, unknown>>(options?: WorkerOptions): ComlinkRemote<T>;
|
|
11
|
+
<T extends object = Record<string, unknown>>(options?: WorkerOptions): ComlinkRemote<T>;
|
|
12
|
+
}
|
|
13
|
+
interface ComlinkLoaderOptions {
|
|
14
|
+
/** Modules handled automatically. Defaults to `.worker.js` / `.worker.ts` variants. */
|
|
15
|
+
include?: FilterPattern;
|
|
16
|
+
/** Modules that must never be handled automatically. */
|
|
17
|
+
exclude?: FilterPattern;
|
|
18
|
+
/**
|
|
19
|
+
* `true` exposes one eagerly-created proxy; `false` makes every call create a
|
|
20
|
+
* worker. If omitted, calling the factory reuses one worker while `new`
|
|
21
|
+
* always creates a fresh worker, matching comlink-loader.
|
|
22
|
+
*/
|
|
23
|
+
singleton?: boolean;
|
|
24
|
+
/** Generate SharedWorkers instead of dedicated Workers. */
|
|
25
|
+
shared?: boolean;
|
|
26
|
+
/** Ask Vite to inline the generated worker. */
|
|
27
|
+
inline?: boolean;
|
|
28
|
+
/** Default options passed to Vite's generated Worker constructor. */
|
|
29
|
+
workerOptions?: WorkerOptions;
|
|
30
|
+
}
|
|
31
|
+
/** Create the Vite-native comlink-loader plugin. */
|
|
32
|
+
declare function comlinkLoader(options?: ComlinkLoaderOptions): Plugin;
|
|
33
|
+
/** Short alias, mirroring other Comlink integrations. */
|
|
34
|
+
declare const comlink: typeof comlinkLoader;
|
|
35
|
+
|
|
36
|
+
export { type ComlinkLoaderOptions, type ComlinkRemote, type ComlinkWorkerFactory, comlink, comlinkLoader, comlinkLoader as default, endpointSymbol };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
import { extname } from "path";
|
|
5
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
6
|
+
import { init, parse } from "es-module-lexer";
|
|
7
|
+
import {
|
|
8
|
+
transformWithEsbuild
|
|
9
|
+
} from "vite";
|
|
10
|
+
|
|
11
|
+
// src/symbol.ts
|
|
12
|
+
var endpointSymbol = /* @__PURE__ */ Symbol.for(
|
|
13
|
+
"vite-comlink-loader.endpoint"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var PLUGIN_NAME = "vite-comlink-loader";
|
|
18
|
+
var PROXY_PREFIX = "\0vite-comlink-loader:proxy:";
|
|
19
|
+
var ENTRY_MARKER = ".vite-comlink-loader-entry.";
|
|
20
|
+
var SOURCE_QUERY = "vite-comlink-loader-source";
|
|
21
|
+
var CONTROL_PARAMS = /* @__PURE__ */ new Set([
|
|
22
|
+
"comlink",
|
|
23
|
+
"comlink-loader",
|
|
24
|
+
"singleton",
|
|
25
|
+
"shared",
|
|
26
|
+
"inline"
|
|
27
|
+
]);
|
|
28
|
+
var defaultInclude = /\.worker\.[cm]?[jt]sx?$/i;
|
|
29
|
+
var identifierName = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
|
|
30
|
+
function cleanUrl(id) {
|
|
31
|
+
return id.replace(/[?#].*$/, "");
|
|
32
|
+
}
|
|
33
|
+
function encode(value) {
|
|
34
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
35
|
+
}
|
|
36
|
+
function decode(id, prefix) {
|
|
37
|
+
const encoded = cleanUrl(id).slice(prefix.length);
|
|
38
|
+
return JSON.parse(Buffer.from(encoded, "base64url").toString());
|
|
39
|
+
}
|
|
40
|
+
function entryId(payload, entries) {
|
|
41
|
+
const serialized = JSON.stringify(payload);
|
|
42
|
+
const key = createHash("sha256").update(serialized).digest("hex").slice(0, 16);
|
|
43
|
+
entries.set(key, payload);
|
|
44
|
+
return `${cleanUrl(payload.source)}${ENTRY_MARKER}${key}.js`;
|
|
45
|
+
}
|
|
46
|
+
function isEntryId(id) {
|
|
47
|
+
return cleanUrl(id).includes(ENTRY_MARKER);
|
|
48
|
+
}
|
|
49
|
+
function decodeEntry(id, entries) {
|
|
50
|
+
const file = cleanUrl(id);
|
|
51
|
+
const marker = file.lastIndexOf(ENTRY_MARKER);
|
|
52
|
+
const key = file.slice(marker + ENTRY_MARKER.length, -".js".length);
|
|
53
|
+
const payload = entries.get(key);
|
|
54
|
+
if (!payload) {
|
|
55
|
+
throw new Error(`${PLUGIN_NAME}: unknown worker entry ${JSON.stringify(id)}`);
|
|
56
|
+
}
|
|
57
|
+
return payload;
|
|
58
|
+
}
|
|
59
|
+
function queryOf(source) {
|
|
60
|
+
const queryStart = source.indexOf("?");
|
|
61
|
+
if (queryStart < 0) return new URLSearchParams();
|
|
62
|
+
const hashStart = source.indexOf("#", queryStart);
|
|
63
|
+
return new URLSearchParams(
|
|
64
|
+
source.slice(queryStart + 1, hashStart < 0 ? void 0 : hashStart)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function withoutControlParams(source) {
|
|
68
|
+
const hashStart = source.indexOf("#");
|
|
69
|
+
const hash = hashStart < 0 ? "" : source.slice(hashStart);
|
|
70
|
+
const request = hashStart < 0 ? source : source.slice(0, hashStart);
|
|
71
|
+
const queryStart = request.indexOf("?");
|
|
72
|
+
if (queryStart < 0) return request + hash;
|
|
73
|
+
const params = new URLSearchParams(request.slice(queryStart + 1));
|
|
74
|
+
for (const key of CONTROL_PARAMS) params.delete(key);
|
|
75
|
+
const query = params.toString();
|
|
76
|
+
return request.slice(0, queryStart) + (query ? `?${query}` : "") + hash;
|
|
77
|
+
}
|
|
78
|
+
function withSourceQuery(source) {
|
|
79
|
+
const hashStart = source.indexOf("#");
|
|
80
|
+
const hash = hashStart < 0 ? "" : source.slice(hashStart);
|
|
81
|
+
const request = hashStart < 0 ? source : source.slice(0, hashStart);
|
|
82
|
+
const separator = request.includes("?") ? "&" : "?";
|
|
83
|
+
return `${request}${separator}${SOURCE_QUERY}${hash}`;
|
|
84
|
+
}
|
|
85
|
+
function isViteWorkerRequest(params) {
|
|
86
|
+
return params.has("worker") || params.has("sharedworker") || params.has("url") || params.has("raw");
|
|
87
|
+
}
|
|
88
|
+
function isWorkerConstructorRequest(id) {
|
|
89
|
+
const params = queryOf(id);
|
|
90
|
+
return params.has("worker") || params.has("sharedworker");
|
|
91
|
+
}
|
|
92
|
+
function optionMode(value) {
|
|
93
|
+
return value === true ? "singleton" : value === false ? "factory" : "hybrid";
|
|
94
|
+
}
|
|
95
|
+
function requestMode(params, fallback) {
|
|
96
|
+
const comlinkValue = params.get("comlink") ?? params.get("comlink-loader");
|
|
97
|
+
if (comlinkValue === "singleton") return "singleton";
|
|
98
|
+
if (comlinkValue === "factory" || comlinkValue === "multiple") return "factory";
|
|
99
|
+
if (!params.has("singleton")) return fallback;
|
|
100
|
+
const singleton = params.get("singleton");
|
|
101
|
+
return singleton === "false" || singleton === "0" ? "factory" : "singleton";
|
|
102
|
+
}
|
|
103
|
+
function esbuildLoader(file) {
|
|
104
|
+
switch (extname(cleanUrl(file)).toLowerCase()) {
|
|
105
|
+
case ".ts":
|
|
106
|
+
case ".mts":
|
|
107
|
+
case ".cts":
|
|
108
|
+
return "ts";
|
|
109
|
+
case ".tsx":
|
|
110
|
+
return "tsx";
|
|
111
|
+
case ".jsx":
|
|
112
|
+
return "jsx";
|
|
113
|
+
default:
|
|
114
|
+
return "js";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function exportedNames(context, id, seen = /* @__PURE__ */ new Set()) {
|
|
118
|
+
const file = cleanUrl(id);
|
|
119
|
+
if (file.startsWith("\0") || seen.has(file)) return [];
|
|
120
|
+
seen.add(file);
|
|
121
|
+
const source = await readFile(file, "utf8");
|
|
122
|
+
const transformed = await transformWithEsbuild(source, file, {
|
|
123
|
+
loader: esbuildLoader(file),
|
|
124
|
+
target: "esnext",
|
|
125
|
+
sourcemap: false
|
|
126
|
+
});
|
|
127
|
+
await init;
|
|
128
|
+
const [imports, exports] = parse(transformed.code);
|
|
129
|
+
const names = /* @__PURE__ */ new Set();
|
|
130
|
+
for (const item of exports) {
|
|
131
|
+
const name = typeof item === "string" ? item : item.n;
|
|
132
|
+
if (name && name !== "default" && name !== "__esModule") names.add(name);
|
|
133
|
+
}
|
|
134
|
+
for (const imported of imports) {
|
|
135
|
+
if (!imported.n) continue;
|
|
136
|
+
const statement = transformed.code.slice(imported.ss, imported.se);
|
|
137
|
+
if (!/^\s*export\s*\*\s*from\b/.test(statement)) continue;
|
|
138
|
+
const resolved = await context.resolve(imported.n, file, { skipSelf: true });
|
|
139
|
+
if (!resolved || resolved.external) continue;
|
|
140
|
+
for (const name of await exportedNames(context, resolved.id, seen)) {
|
|
141
|
+
names.add(name);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return [...names].sort();
|
|
145
|
+
}
|
|
146
|
+
function workerEntryCode(payload) {
|
|
147
|
+
const source = JSON.stringify(withSourceQuery(payload.source));
|
|
148
|
+
if (payload.shared) {
|
|
149
|
+
return `
|
|
150
|
+
import { expose as __expose } from "comlink";
|
|
151
|
+
import * as __api from ${source};
|
|
152
|
+
self.addEventListener("connect", (__event) => {
|
|
153
|
+
const __port = __event.ports[0];
|
|
154
|
+
if (__port) __expose(__api, __port);
|
|
155
|
+
});
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
return `
|
|
159
|
+
import { expose as __expose } from "comlink";
|
|
160
|
+
import * as __api from ${source};
|
|
161
|
+
__expose(__api);
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
function proxyCode(payload, entries) {
|
|
165
|
+
const workerEntryId = entryId(
|
|
166
|
+
{
|
|
167
|
+
shared: payload.shared,
|
|
168
|
+
source: payload.source
|
|
169
|
+
},
|
|
170
|
+
entries
|
|
171
|
+
);
|
|
172
|
+
const workerQuery = payload.shared ? "sharedworker" : "worker";
|
|
173
|
+
const workerRequest = `${workerEntryId}?${workerQuery}${payload.inline ? "&inline" : ""}`;
|
|
174
|
+
const defaults = JSON.stringify(payload.workerOptions ?? {});
|
|
175
|
+
const endpoint = payload.shared ? "__worker.port" : "__worker";
|
|
176
|
+
const namedExports = [];
|
|
177
|
+
if (payload.mode === "singleton") {
|
|
178
|
+
payload.exports.forEach((name, index) => {
|
|
179
|
+
if (!identifierName.test(name)) return;
|
|
180
|
+
namedExports.push(
|
|
181
|
+
`const __export${index} = __singleton[${JSON.stringify(name)}];
|
|
182
|
+
export { __export${index} as ${name} };`
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const factory = payload.mode === "singleton" ? `const __singleton = __create();
|
|
187
|
+
export default __singleton;` : payload.mode === "factory" ? `function ComlinkWorker(options) { return __create(options); }
|
|
188
|
+
export default ComlinkWorker;` : `let __singleton;
|
|
189
|
+
function ComlinkWorker(options) {
|
|
190
|
+
if (new.target) return __create(options);
|
|
191
|
+
return __singleton || (__singleton = __create(options));
|
|
192
|
+
}
|
|
193
|
+
export default ComlinkWorker;`;
|
|
194
|
+
return `
|
|
195
|
+
import { releaseProxy as __releaseProxy, wrap as __wrap } from "comlink";
|
|
196
|
+
import __Worker from ${JSON.stringify(workerRequest)};
|
|
197
|
+
|
|
198
|
+
const __endpointSymbol = Symbol.for("vite-comlink-loader.endpoint");
|
|
199
|
+
const __defaults = ${defaults};
|
|
200
|
+
const __active = new Set();
|
|
201
|
+
|
|
202
|
+
function __create(options) {
|
|
203
|
+
const __worker = new __Worker(Object.assign({}, __defaults, options));
|
|
204
|
+
const __remote = __wrap(${endpoint});
|
|
205
|
+
const __proxy = new Proxy(__remote, {
|
|
206
|
+
get(target, property, receiver) {
|
|
207
|
+
if (property === __endpointSymbol) return __worker;
|
|
208
|
+
return Reflect.get(target, property, receiver);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
__active.add({ endpoint: __worker, remote: __remote });
|
|
212
|
+
return __proxy;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
${factory}
|
|
216
|
+
${namedExports.join("\n")}
|
|
217
|
+
|
|
218
|
+
if (import.meta.hot) {
|
|
219
|
+
import.meta.hot.dispose(() => {
|
|
220
|
+
for (const { endpoint, remote } of __active) {
|
|
221
|
+
try { remote[__releaseProxy](); } catch {}
|
|
222
|
+
try { endpoint.port?.close(); } catch {}
|
|
223
|
+
try { endpoint.terminate?.(); } catch {}
|
|
224
|
+
}
|
|
225
|
+
__active.clear();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
`;
|
|
229
|
+
}
|
|
230
|
+
function entryPlugin(entries) {
|
|
231
|
+
return {
|
|
232
|
+
name: `${PLUGIN_NAME}:worker-entry`,
|
|
233
|
+
enforce: "pre",
|
|
234
|
+
resolveId(id) {
|
|
235
|
+
if (isEntryId(id)) return id;
|
|
236
|
+
return null;
|
|
237
|
+
},
|
|
238
|
+
load(id) {
|
|
239
|
+
if (!isEntryId(id) || isWorkerConstructorRequest(id)) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return workerEntryCode(decodeEntry(id, entries));
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function appendWorkerPlugin(config, plugin) {
|
|
247
|
+
const previous = config.worker?.plugins;
|
|
248
|
+
const plugins = (...args) => {
|
|
249
|
+
const existing = typeof previous === "function" ? previous(...args) : previous;
|
|
250
|
+
const values = existing == null ? [] : Array.isArray(existing) ? existing : [existing];
|
|
251
|
+
return [...values, plugin];
|
|
252
|
+
};
|
|
253
|
+
config.worker ??= {};
|
|
254
|
+
config.worker.plugins = plugins;
|
|
255
|
+
}
|
|
256
|
+
function comlinkLoader(options = {}) {
|
|
257
|
+
const filter = createFilter(options.include ?? defaultInclude, options.exclude);
|
|
258
|
+
const fallbackMode = optionMode(options.singleton);
|
|
259
|
+
const entries = /* @__PURE__ */ new Map();
|
|
260
|
+
const workerPlugin = entryPlugin(entries);
|
|
261
|
+
return {
|
|
262
|
+
name: PLUGIN_NAME,
|
|
263
|
+
enforce: "pre",
|
|
264
|
+
config(config) {
|
|
265
|
+
appendWorkerPlugin(config, workerPlugin);
|
|
266
|
+
},
|
|
267
|
+
async resolveId(source, importer) {
|
|
268
|
+
if (source.startsWith(PROXY_PREFIX) || isEntryId(source)) {
|
|
269
|
+
return source;
|
|
270
|
+
}
|
|
271
|
+
const params = queryOf(source);
|
|
272
|
+
if (params.has(SOURCE_QUERY)) return null;
|
|
273
|
+
const explicit = params.has("comlink") || params.has("comlink-loader");
|
|
274
|
+
if (!explicit && isViteWorkerRequest(params)) return null;
|
|
275
|
+
const request = explicit ? withoutControlParams(source) : source;
|
|
276
|
+
const resolved = await this.resolve(request, importer, { skipSelf: true });
|
|
277
|
+
if (!resolved || resolved.external) return null;
|
|
278
|
+
if (!explicit && !filter(cleanUrl(resolved.id))) return null;
|
|
279
|
+
const mode = requestMode(params, fallbackMode);
|
|
280
|
+
let exports = [];
|
|
281
|
+
if (mode === "singleton") {
|
|
282
|
+
try {
|
|
283
|
+
exports = await exportedNames(this, resolved.id);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
this.warn(
|
|
286
|
+
`Could not inspect exports of ${cleanUrl(resolved.id)}; the default singleton export remains available. ${String(error)}`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const payload = {
|
|
291
|
+
explicit,
|
|
292
|
+
source: resolved.id,
|
|
293
|
+
mode,
|
|
294
|
+
shared: params.has("shared") ? params.get("shared") !== "false" : !!options.shared,
|
|
295
|
+
inline: params.has("inline") ? params.get("inline") !== "false" : !!options.inline,
|
|
296
|
+
exports,
|
|
297
|
+
workerOptions: options.workerOptions
|
|
298
|
+
};
|
|
299
|
+
return `${PROXY_PREFIX}${encode(payload)}`;
|
|
300
|
+
},
|
|
301
|
+
load(id) {
|
|
302
|
+
if (id.startsWith(PROXY_PREFIX)) {
|
|
303
|
+
return proxyCode(decode(id, PROXY_PREFIX), entries);
|
|
304
|
+
}
|
|
305
|
+
if (isEntryId(id) && !isWorkerConstructorRequest(id)) {
|
|
306
|
+
return workerEntryCode(decodeEntry(id, entries));
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
var comlink = comlinkLoader;
|
|
313
|
+
var index_default = comlinkLoader;
|
|
314
|
+
export {
|
|
315
|
+
comlink,
|
|
316
|
+
comlinkLoader,
|
|
317
|
+
index_default as default,
|
|
318
|
+
endpointSymbol
|
|
319
|
+
};
|
|
320
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/symbol.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { createHash } from 'node:crypto';\nimport { extname } from 'node:path';\nimport { createFilter, type FilterPattern } from '@rollup/pluginutils';\nimport type { Remote } from 'comlink';\nimport { init, parse } from 'es-module-lexer';\nimport {\n transformWithEsbuild,\n type Plugin,\n type PluginOption,\n type UserConfig,\n} from 'vite';\nimport { endpointSymbol } from './symbol.js';\n\nexport { endpointSymbol };\n\nexport type ComlinkRemote<T extends object> = Remote<T> & {\n readonly [endpointSymbol]: Worker | SharedWorker;\n};\n\nexport interface ComlinkWorkerFactory {\n new <T extends object = Record<string, unknown>>(\n options?: WorkerOptions,\n ): ComlinkRemote<T>;\n <T extends object = Record<string, unknown>>(\n options?: WorkerOptions,\n ): ComlinkRemote<T>;\n}\n\nconst PLUGIN_NAME = 'vite-comlink-loader';\nconst PROXY_PREFIX = '\\0vite-comlink-loader:proxy:';\n// Vite's dev worker URL converter treats `\\0` IDs as filesystem paths. Worker\n// entries therefore use a physical-looking ID next to their source file.\nconst ENTRY_MARKER = '.vite-comlink-loader-entry.';\nconst SOURCE_QUERY = 'vite-comlink-loader-source';\nconst CONTROL_PARAMS = new Set([\n 'comlink',\n 'comlink-loader',\n 'singleton',\n 'shared',\n 'inline',\n]);\n\ntype Mode = 'hybrid' | 'factory' | 'singleton';\n\nexport interface ComlinkLoaderOptions {\n /** Modules handled automatically. Defaults to `.worker.js` / `.worker.ts` variants. */\n include?: FilterPattern;\n /** Modules that must never be handled automatically. */\n exclude?: FilterPattern;\n /**\n * `true` exposes one eagerly-created proxy; `false` makes every call create a\n * worker. If omitted, calling the factory reuses one worker while `new`\n * always creates a fresh worker, matching comlink-loader.\n */\n singleton?: boolean;\n /** Generate SharedWorkers instead of dedicated Workers. */\n shared?: boolean;\n /** Ask Vite to inline the generated worker. */\n inline?: boolean;\n /** Default options passed to Vite's generated Worker constructor. */\n workerOptions?: WorkerOptions;\n}\n\ninterface RequestOptions {\n explicit: boolean;\n inline: boolean;\n mode: Mode;\n shared: boolean;\n source: string;\n}\n\ninterface ProxyPayload extends RequestOptions {\n exports: string[];\n workerOptions?: WorkerOptions;\n}\n\ninterface EntryPayload {\n shared: boolean;\n source: string;\n}\n\ninterface ExportResolveContext {\n resolve(\n source: string,\n importer?: string,\n options?: { skipSelf?: boolean },\n ): Promise<{ external?: boolean | string; id: string } | null>;\n}\n\nconst defaultInclude = /\\.worker\\.[cm]?[jt]sx?$/i;\nconst identifierName = /^[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*$/u;\n\nfunction cleanUrl(id: string): string {\n return id.replace(/[?#].*$/, '');\n}\n\nfunction encode(value: unknown): string {\n return Buffer.from(JSON.stringify(value)).toString('base64url');\n}\n\nfunction decode<T>(id: string, prefix: string): T {\n const encoded = cleanUrl(id).slice(prefix.length);\n return JSON.parse(Buffer.from(encoded, 'base64url').toString()) as T;\n}\n\nfunction entryId(\n payload: EntryPayload,\n entries: Map<string, EntryPayload>,\n): string {\n const serialized = JSON.stringify(payload);\n const key = createHash('sha256').update(serialized).digest('hex').slice(0, 16);\n entries.set(key, payload);\n return `${cleanUrl(payload.source)}${ENTRY_MARKER}${key}.js`;\n}\n\nfunction isEntryId(id: string): boolean {\n return cleanUrl(id).includes(ENTRY_MARKER);\n}\n\nfunction decodeEntry(\n id: string,\n entries: Map<string, EntryPayload>,\n): EntryPayload {\n const file = cleanUrl(id);\n const marker = file.lastIndexOf(ENTRY_MARKER);\n const key = file.slice(marker + ENTRY_MARKER.length, -'.js'.length);\n const payload = entries.get(key);\n if (!payload) {\n throw new Error(`${PLUGIN_NAME}: unknown worker entry ${JSON.stringify(id)}`);\n }\n return payload;\n}\n\nfunction queryOf(source: string): URLSearchParams {\n const queryStart = source.indexOf('?');\n if (queryStart < 0) return new URLSearchParams();\n const hashStart = source.indexOf('#', queryStart);\n return new URLSearchParams(\n source.slice(queryStart + 1, hashStart < 0 ? undefined : hashStart),\n );\n}\n\nfunction withoutControlParams(source: string): string {\n const hashStart = source.indexOf('#');\n const hash = hashStart < 0 ? '' : source.slice(hashStart);\n const request = hashStart < 0 ? source : source.slice(0, hashStart);\n const queryStart = request.indexOf('?');\n if (queryStart < 0) return request + hash;\n\n const params = new URLSearchParams(request.slice(queryStart + 1));\n for (const key of CONTROL_PARAMS) params.delete(key);\n const query = params.toString();\n return request.slice(0, queryStart) + (query ? `?${query}` : '') + hash;\n}\n\nfunction withSourceQuery(source: string): string {\n const hashStart = source.indexOf('#');\n const hash = hashStart < 0 ? '' : source.slice(hashStart);\n const request = hashStart < 0 ? source : source.slice(0, hashStart);\n const separator = request.includes('?') ? '&' : '?';\n return `${request}${separator}${SOURCE_QUERY}${hash}`;\n}\n\nfunction isViteWorkerRequest(params: URLSearchParams): boolean {\n return (\n params.has('worker') ||\n params.has('sharedworker') ||\n params.has('url') ||\n params.has('raw')\n );\n}\n\nfunction isWorkerConstructorRequest(id: string): boolean {\n const params = queryOf(id);\n return params.has('worker') || params.has('sharedworker');\n}\n\nfunction optionMode(value: boolean | undefined): Mode {\n return value === true ? 'singleton' : value === false ? 'factory' : 'hybrid';\n}\n\nfunction requestMode(params: URLSearchParams, fallback: Mode): Mode {\n const comlinkValue = params.get('comlink') ?? params.get('comlink-loader');\n if (comlinkValue === 'singleton') return 'singleton';\n if (comlinkValue === 'factory' || comlinkValue === 'multiple') return 'factory';\n if (!params.has('singleton')) return fallback;\n const singleton = params.get('singleton');\n return singleton === 'false' || singleton === '0' ? 'factory' : 'singleton';\n}\n\nfunction esbuildLoader(file: string): 'js' | 'jsx' | 'ts' | 'tsx' {\n switch (extname(cleanUrl(file)).toLowerCase()) {\n case '.ts':\n case '.mts':\n case '.cts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n case '.jsx':\n return 'jsx';\n default:\n return 'js';\n }\n}\n\nasync function exportedNames(\n context: ExportResolveContext,\n id: string,\n seen = new Set<string>(),\n): Promise<string[]> {\n const file = cleanUrl(id);\n if (file.startsWith('\\0') || seen.has(file)) return [];\n seen.add(file);\n\n const source = await readFile(file, 'utf8');\n const transformed = await transformWithEsbuild(source, file, {\n loader: esbuildLoader(file),\n target: 'esnext',\n sourcemap: false,\n });\n await init;\n const [imports, exports] = parse(transformed.code);\n const names = new Set<string>();\n\n for (const item of exports) {\n const name = typeof item === 'string' ? item : item.n;\n if (name && name !== 'default' && name !== '__esModule') names.add(name);\n }\n\n for (const imported of imports) {\n if (!imported.n) continue;\n const statement = transformed.code.slice(imported.ss, imported.se);\n if (!/^\\s*export\\s*\\*\\s*from\\b/.test(statement)) continue;\n const resolved = await context.resolve(imported.n, file, { skipSelf: true });\n if (!resolved || resolved.external) continue;\n for (const name of await exportedNames(context, resolved.id, seen)) {\n names.add(name);\n }\n }\n\n return [...names].sort();\n}\n\nfunction workerEntryCode(payload: EntryPayload): string {\n const source = JSON.stringify(withSourceQuery(payload.source));\n if (payload.shared) {\n return `\nimport { expose as __expose } from \"comlink\";\nimport * as __api from ${source};\nself.addEventListener(\"connect\", (__event) => {\n const __port = __event.ports[0];\n if (__port) __expose(__api, __port);\n});\n`;\n }\n\n return `\nimport { expose as __expose } from \"comlink\";\nimport * as __api from ${source};\n__expose(__api);\n`;\n}\n\nfunction proxyCode(\n payload: ProxyPayload,\n entries: Map<string, EntryPayload>,\n): string {\n const workerEntryId = entryId(\n {\n shared: payload.shared,\n source: payload.source,\n },\n entries,\n );\n const workerQuery = payload.shared ? 'sharedworker' : 'worker';\n const workerRequest = `${workerEntryId}?${workerQuery}${payload.inline ? '&inline' : ''}`;\n const defaults = JSON.stringify(payload.workerOptions ?? {});\n const endpoint = payload.shared ? '__worker.port' : '__worker';\n const namedExports: string[] = [];\n\n if (payload.mode === 'singleton') {\n payload.exports.forEach((name, index) => {\n if (!identifierName.test(name)) return;\n namedExports.push(\n `const __export${index} = __singleton[${JSON.stringify(name)}];\\n` +\n `export { __export${index} as ${name} };`,\n );\n });\n }\n\n const factory =\n payload.mode === 'singleton'\n ? `const __singleton = __create();\\nexport default __singleton;`\n : payload.mode === 'factory'\n ? `function ComlinkWorker(options) { return __create(options); }\\nexport default ComlinkWorker;`\n : `let __singleton;\\nfunction ComlinkWorker(options) {\\n if (new.target) return __create(options);\\n return __singleton || (__singleton = __create(options));\\n}\\nexport default ComlinkWorker;`;\n\n return `\nimport { releaseProxy as __releaseProxy, wrap as __wrap } from \"comlink\";\nimport __Worker from ${JSON.stringify(workerRequest)};\n\nconst __endpointSymbol = Symbol.for(\"vite-comlink-loader.endpoint\");\nconst __defaults = ${defaults};\nconst __active = new Set();\n\nfunction __create(options) {\n const __worker = new __Worker(Object.assign({}, __defaults, options));\n const __remote = __wrap(${endpoint});\n const __proxy = new Proxy(__remote, {\n get(target, property, receiver) {\n if (property === __endpointSymbol) return __worker;\n return Reflect.get(target, property, receiver);\n }\n });\n __active.add({ endpoint: __worker, remote: __remote });\n return __proxy;\n}\n\n${factory}\n${namedExports.join('\\n')}\n\nif (import.meta.hot) {\n import.meta.hot.dispose(() => {\n for (const { endpoint, remote } of __active) {\n try { remote[__releaseProxy](); } catch {}\n try { endpoint.port?.close(); } catch {}\n try { endpoint.terminate?.(); } catch {}\n }\n __active.clear();\n });\n}\n`;\n}\n\nfunction entryPlugin(entries: Map<string, EntryPayload>): Plugin {\n return {\n name: `${PLUGIN_NAME}:worker-entry`,\n enforce: 'pre',\n resolveId(id) {\n if (isEntryId(id)) return id;\n return null;\n },\n load(id) {\n if (!isEntryId(id) || isWorkerConstructorRequest(id)) {\n return null;\n }\n return workerEntryCode(decodeEntry(id, entries));\n },\n };\n}\n\nfunction appendWorkerPlugin(config: UserConfig, plugin: Plugin): void {\n const previous = config.worker?.plugins;\n const plugins = (...args: unknown[]): PluginOption[] => {\n const existing = typeof previous === 'function'\n ? (previous as (...values: unknown[]) => PluginOption[])(...args)\n : previous;\n const values = existing == null\n ? []\n : Array.isArray(existing)\n ? existing\n : [existing];\n return [...values, plugin];\n };\n\n config.worker ??= {};\n config.worker.plugins = plugins;\n}\n\n/** Create the Vite-native comlink-loader plugin. */\nexport function comlinkLoader(options: ComlinkLoaderOptions = {}): Plugin {\n const filter = createFilter(options.include ?? defaultInclude, options.exclude);\n const fallbackMode = optionMode(options.singleton);\n const entries = new Map<string, EntryPayload>();\n const workerPlugin = entryPlugin(entries);\n\n return {\n name: PLUGIN_NAME,\n enforce: 'pre',\n\n config(config) {\n appendWorkerPlugin(config, workerPlugin);\n },\n\n async resolveId(source, importer) {\n if (source.startsWith(PROXY_PREFIX) || isEntryId(source)) {\n return source;\n }\n\n const params = queryOf(source);\n if (params.has(SOURCE_QUERY)) return null;\n const explicit = params.has('comlink') || params.has('comlink-loader');\n if (!explicit && isViteWorkerRequest(params)) return null;\n\n const request = explicit ? withoutControlParams(source) : source;\n const resolved = await this.resolve(request, importer, { skipSelf: true });\n if (!resolved || resolved.external) return null;\n if (!explicit && !filter(cleanUrl(resolved.id))) return null;\n\n const mode = requestMode(params, fallbackMode);\n let exports: string[] = [];\n if (mode === 'singleton') {\n try {\n exports = await exportedNames(this, resolved.id);\n } catch (error) {\n this.warn(\n `Could not inspect exports of ${cleanUrl(resolved.id)}; ` +\n `the default singleton export remains available. ${String(error)}`,\n );\n }\n }\n\n const payload: ProxyPayload = {\n explicit,\n source: resolved.id,\n mode,\n shared: params.has('shared') ? params.get('shared') !== 'false' : !!options.shared,\n inline: params.has('inline') ? params.get('inline') !== 'false' : !!options.inline,\n exports,\n workerOptions: options.workerOptions,\n };\n return `${PROXY_PREFIX}${encode(payload)}`;\n },\n\n load(id) {\n if (id.startsWith(PROXY_PREFIX)) {\n return proxyCode(decode<ProxyPayload>(id, PROXY_PREFIX), entries);\n }\n if (isEntryId(id) && !isWorkerConstructorRequest(id)) {\n return workerEntryCode(decodeEntry(id, entries));\n }\n return null;\n },\n };\n}\n\n/** Short alias, mirroring other Comlink integrations. */\nexport const comlink = comlinkLoader;\n\nexport default comlinkLoader;\n","/** Access the native Worker or SharedWorker behind a Comlink proxy. */\nexport const endpointSymbol: unique symbol = Symbol.for(\n 'vite-comlink-loader.endpoint',\n) as typeof endpointSymbol;\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,oBAAwC;AAEjD,SAAS,MAAM,aAAa;AAC5B;AAAA,EACE;AAAA,OAIK;;;ACVA,IAAM,iBAAgC,uBAAO;AAAA,EAClD;AACF;;;AD0BA,IAAM,cAAc;AACpB,IAAM,eAAe;AAGrB,IAAM,eAAe;AACrB,IAAM,eAAe;AACrB,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAiDD,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAEvB,SAAS,SAAS,IAAoB;AACpC,SAAO,GAAG,QAAQ,WAAW,EAAE;AACjC;AAEA,SAAS,OAAO,OAAwB;AACtC,SAAO,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC,EAAE,SAAS,WAAW;AAChE;AAEA,SAAS,OAAU,IAAY,QA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,2BAA2B,EAAE,GAAG;AACpD,eAAO,gBAAgB,YAAY,IAAI,OAAO,CAAC;AAAA,MACjD;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,IAAM,UAAU;AAEvB,IAAO,gBAAQ;","names":[]}
|
package/dist/symbol.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/symbol.ts
|
|
21
|
+
var symbol_exports = {};
|
|
22
|
+
__export(symbol_exports, {
|
|
23
|
+
endpointSymbol: () => endpointSymbol
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(symbol_exports);
|
|
26
|
+
var endpointSymbol = /* @__PURE__ */ Symbol.for(
|
|
27
|
+
"vite-comlink-loader.endpoint"
|
|
28
|
+
);
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
endpointSymbol
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=symbol.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/symbol.ts"],"sourcesContent":["/** Access the native Worker or SharedWorker behind a Comlink proxy. */\nexport const endpointSymbol: unique symbol = Symbol.for(\n 'vite-comlink-loader.endpoint',\n) as typeof endpointSymbol;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,iBAAgC,uBAAO;AAAA,EAClD;AACF;","names":[]}
|
package/dist/symbol.d.ts
ADDED
package/dist/symbol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/symbol.ts"],"sourcesContent":["/** Access the native Worker or SharedWorker behind a Comlink proxy. */\nexport const endpointSymbol: unique symbol = Symbol.for(\n 'vite-comlink-loader.endpoint',\n) as typeof endpointSymbol;\n"],"mappings":";AACO,IAAM,iBAAgC,uBAAO;AAAA,EAClD;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-comlink-loader",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A Vite-native port of comlink-loader",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"client.d.ts",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"types": "./client.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./symbol": {
|
|
26
|
+
"types": "./dist/symbol.d.ts",
|
|
27
|
+
"import": "./dist/symbol.js",
|
|
28
|
+
"require": "./dist/symbol.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"check": "tsc --noEmit",
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:all": "npm run check && npm run test && npm run build"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"vite",
|
|
41
|
+
"comlink",
|
|
42
|
+
"web-worker",
|
|
43
|
+
"worker",
|
|
44
|
+
"plugin"
|
|
45
|
+
],
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/ihasq/vite-comlink-loader.git"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@rollup/pluginutils": "^5.1.4",
|
|
53
|
+
"es-module-lexer": "^1.6.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"comlink": "^4.4.2",
|
|
57
|
+
"vite": ">=5.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^22.10.1",
|
|
61
|
+
"comlink": "^4.4.2",
|
|
62
|
+
"tsup": "^8.3.6",
|
|
63
|
+
"typescript": "^5.7.2",
|
|
64
|
+
"vite": "^8.3.4",
|
|
65
|
+
"vitest": "^5.0.4"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18.0.0"
|
|
69
|
+
},
|
|
70
|
+
"overrides": {
|
|
71
|
+
"esbuild": "^0.28.2"
|
|
72
|
+
}
|
|
73
|
+
}
|