@isoloop/vite 0.0.0-next.4da23df
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/client.d.ts +20 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +134 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sabin Pandelovitch
|
|
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/client.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Types for the modules `@isoloop/vite` provides. Reference it from the app:
|
|
2
|
+
// `/// <reference types="@isoloop/vite/client" />`.
|
|
3
|
+
|
|
4
|
+
/** `KernelConfig.workers`: the bootstrap's URL, and the bus worker's unless `bus: false`. */
|
|
5
|
+
declare module 'virtual:isoloop/workers' {
|
|
6
|
+
const workers: { isolateBootstrap: string; bus?: string };
|
|
7
|
+
export default workers;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** URLs of the isolates listed in `isoloop({ isolates })`, by name. */
|
|
11
|
+
declare module 'virtual:isoloop/isolates' {
|
|
12
|
+
const isolates: Record<string, string>;
|
|
13
|
+
export default isolates;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The URL of an isolate module (or the contracts module), for `spawn({ src })`. */
|
|
17
|
+
declare module '*?isolate' {
|
|
18
|
+
const url: string;
|
|
19
|
+
export default url;
|
|
20
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
export declare const ISOLATES_ID = "virtual:isoloop/isolates";
|
|
3
|
+
export declare const MANIFEST = "isoloop-manifest.json";
|
|
4
|
+
type BuildOptions = {
|
|
5
|
+
/** Isolate entries by name, relative to the Vite root. */
|
|
6
|
+
isolates?: Readonly<Record<string, string>>;
|
|
7
|
+
/** Build only the isolates (library mode), not an app. Needs `isolates`. */
|
|
8
|
+
library?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** What `isoloop-manifest.json` holds: each isolate's file, relative to the output directory. */
|
|
11
|
+
type IsolateManifest = {
|
|
12
|
+
isolates: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
export declare const WORKERS_ID = "virtual:isoloop/workers";
|
|
15
|
+
type HeaderOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* The Content-Security-Policy to send, or `false` for none. Default: the
|
|
18
|
+
* hosting guide's policy, with `isolateOrigins` in `script-src` and
|
|
19
|
+
* `connect-src`, plus what Vite's dev server needs (its HMR socket and
|
|
20
|
+
* injected styles).
|
|
21
|
+
*/
|
|
22
|
+
csp?: string | false;
|
|
23
|
+
/** Origins that serve isolate modules or the contracts module. */
|
|
24
|
+
isolateOrigins?: readonly string[];
|
|
25
|
+
/** Sends COOP `same-origin` and COEP `require-corp`, for `SharedArrayBuffer`. Default false. */
|
|
26
|
+
crossOriginIsolated?: boolean;
|
|
27
|
+
};
|
|
28
|
+
type WorkersOptions = {
|
|
29
|
+
/** Include the bus worker's URL. Default true; an app without `contracts` can drop it. */
|
|
30
|
+
bus?: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** The policy for the dev server: the hosting guide's, plus Vite's HMR socket and injected styles. */
|
|
33
|
+
export declare function devCsp(origins?: readonly string[]): string;
|
|
34
|
+
export declare function headersFor(o: HeaderOptions): Record<string, string>;
|
|
35
|
+
export type IsoloopOptions = HeaderOptions & WorkersOptions & BuildOptions;
|
|
36
|
+
export declare function isoloop(o?: IsoloopOptions): Plugin[];
|
|
37
|
+
export type { BuildOptions, HeaderOptions, IsolateManifest, WorkersOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { relative, resolve } from "node:path";
|
|
2
|
+
// src/build.ts
|
|
3
|
+
const QUERY = "?isolate";
|
|
4
|
+
const PREFIX = "\0isolate:";
|
|
5
|
+
const ISOLATES_ID = "virtual:isoloop/isolates";
|
|
6
|
+
const RESOLVED$1 = `\0${ISOLATES_ID}`;
|
|
7
|
+
const MANIFEST = "isoloop-manifest.json";
|
|
8
|
+
function buildPlugin(o) {
|
|
9
|
+
const isolates = o.isolates ?? {};
|
|
10
|
+
let root = process.cwd();
|
|
11
|
+
let serve = false;
|
|
12
|
+
/** Emitted chunk refs by isolate name (app builds). */
|
|
13
|
+
const refs = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
name: "isoloop:build",
|
|
16
|
+
enforce: "pre",
|
|
17
|
+
config() {
|
|
18
|
+
if (!o.library) return void 0;
|
|
19
|
+
if (Object.keys(isolates).length === 0) throw new Error("@isoloop/vite: library mode needs `isolates`");
|
|
20
|
+
return { build: { lib: {
|
|
21
|
+
entry: { ...isolates },
|
|
22
|
+
formats: ["es"],
|
|
23
|
+
fileName: (_format, name) => `${name}.js`
|
|
24
|
+
} } };
|
|
25
|
+
},
|
|
26
|
+
configResolved(c) {
|
|
27
|
+
root = c.root;
|
|
28
|
+
serve = c.command === "serve";
|
|
29
|
+
},
|
|
30
|
+
buildStart() {
|
|
31
|
+
if (serve || o.library) return;
|
|
32
|
+
for (const [name, entry] of Object.entries(isolates)) refs.set(name, this.emitFile({
|
|
33
|
+
type: "chunk",
|
|
34
|
+
id: resolve(root, entry),
|
|
35
|
+
name,
|
|
36
|
+
preserveSignature: "strict"
|
|
37
|
+
}));
|
|
38
|
+
},
|
|
39
|
+
async resolveId(source, importer) {
|
|
40
|
+
if (source === "virtual:isoloop/isolates") return RESOLVED$1;
|
|
41
|
+
if (!source.endsWith(QUERY)) return null;
|
|
42
|
+
const r = await this.resolve(source.slice(0, -8), importer);
|
|
43
|
+
return r ? PREFIX + r.id : null;
|
|
44
|
+
},
|
|
45
|
+
load(id) {
|
|
46
|
+
if (id === RESOLVED$1) {
|
|
47
|
+
const names = Object.keys(isolates);
|
|
48
|
+
return [...names.map((n, i) => `import u${i} from ${JSON.stringify(`${resolve(root, isolates[n] ?? "")}${QUERY}`)};`), `export default { ${names.map((n, i) => `${JSON.stringify(n)}: u${i}`).join(", ")} };`].join("\n");
|
|
49
|
+
}
|
|
50
|
+
if (!id.startsWith(PREFIX)) return null;
|
|
51
|
+
const file = id.slice(9);
|
|
52
|
+
if (serve) {
|
|
53
|
+
const rel = relative(root, file);
|
|
54
|
+
const url = rel.startsWith("..") ? `/@fs${file}` : `/${rel.split("\\").join("/")}`;
|
|
55
|
+
return `export default ${JSON.stringify(url)};`;
|
|
56
|
+
}
|
|
57
|
+
return `export default import.meta.ROLLUP_FILE_URL_${this.emitFile({
|
|
58
|
+
type: "chunk",
|
|
59
|
+
id: file,
|
|
60
|
+
preserveSignature: "strict"
|
|
61
|
+
})};`;
|
|
62
|
+
},
|
|
63
|
+
generateBundle(_opts, bundle) {
|
|
64
|
+
if (Object.keys(isolates).length === 0) return;
|
|
65
|
+
const manifest = { isolates: {} };
|
|
66
|
+
if (o.library) {
|
|
67
|
+
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry && chunk.name in isolates) manifest.isolates[chunk.name] = chunk.fileName;
|
|
68
|
+
} else for (const [name, ref] of refs) manifest.isolates[name] = this.getFileName(ref);
|
|
69
|
+
this.emitFile({
|
|
70
|
+
type: "asset",
|
|
71
|
+
fileName: MANIFEST,
|
|
72
|
+
source: `${JSON.stringify(manifest, null, 2)}\n`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// src/dev.ts
|
|
78
|
+
const WORKERS_ID = "virtual:isoloop/workers";
|
|
79
|
+
const RESOLVED = `\0${WORKERS_ID}`;
|
|
80
|
+
/** The policy for the dev server: the hosting guide's, plus Vite's HMR socket and injected styles. */
|
|
81
|
+
function devCsp(origins = []) {
|
|
82
|
+
const extra = origins.length > 0 ? ` ${origins.join(" ")}` : "";
|
|
83
|
+
return [
|
|
84
|
+
"default-src 'self'",
|
|
85
|
+
"worker-src 'self'",
|
|
86
|
+
`script-src 'self'${extra}`,
|
|
87
|
+
`connect-src 'self' ws: wss:${extra}`,
|
|
88
|
+
"style-src 'self' 'unsafe-inline'"
|
|
89
|
+
].join("; ");
|
|
90
|
+
}
|
|
91
|
+
function headersFor(o) {
|
|
92
|
+
const headers = {};
|
|
93
|
+
const csp = o.csp ?? devCsp(o.isolateOrigins);
|
|
94
|
+
if (csp !== false) headers["Content-Security-Policy"] = csp;
|
|
95
|
+
if (o.crossOriginIsolated) {
|
|
96
|
+
headers["Cross-Origin-Opener-Policy"] = "same-origin";
|
|
97
|
+
headers["Cross-Origin-Embedder-Policy"] = "require-corp";
|
|
98
|
+
}
|
|
99
|
+
return headers;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `virtual:isoloop/workers` (the two worker entries go through Vite's own
|
|
103
|
+
* `?worker&url`, so dev serves them and a build emits them), and the headers.
|
|
104
|
+
*/
|
|
105
|
+
function devPlugin(o) {
|
|
106
|
+
const headers = headersFor(o);
|
|
107
|
+
const use = (server) => {
|
|
108
|
+
server.middlewares.use((_req, res, next) => {
|
|
109
|
+
for (const [k, v] of Object.entries(headers)) res.setHeader(k, v);
|
|
110
|
+
next();
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
name: "isoloop:dev",
|
|
115
|
+
config: () => ({ worker: { format: "es" } }),
|
|
116
|
+
resolveId: (id) => id === "virtual:isoloop/workers" ? RESOLVED : null,
|
|
117
|
+
load(id) {
|
|
118
|
+
if (id !== RESOLVED) return null;
|
|
119
|
+
const bus = o.bus ?? true;
|
|
120
|
+
return [
|
|
121
|
+
"import isolateBootstrap from '@isoloop/runtime/bootstrap?worker&url';",
|
|
122
|
+
...bus ? ["import bus from '@isoloop/bus/worker?worker&url';"] : [],
|
|
123
|
+
`export default { isolateBootstrap${bus ? ", bus" : ""} };`
|
|
124
|
+
].join("\n");
|
|
125
|
+
},
|
|
126
|
+
configureServer: use,
|
|
127
|
+
configurePreviewServer: use
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
// src/index.ts
|
|
131
|
+
function isoloop(o = {}) {
|
|
132
|
+
return [buildPlugin(o), ...o.library ? [] : [devPlugin(o)]];
|
|
133
|
+
}
|
|
134
|
+
export { ISOLATES_ID, MANIFEST, WORKERS_ID, devCsp, headersFor, isoloop };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@isoloop/vite",
|
|
3
|
+
"version": "0.0.0-next.4da23df",
|
|
4
|
+
"description": "Vite plugin for Isoloop apps: the bootstrap and bus worker URLs, dev headers, and isolate builds.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/isoloop/isoloop.git",
|
|
11
|
+
"directory": "packages/vite"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"client.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"types": "./client.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"vite": "^8"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@isoloop/bus": "0.0.0-next.4da23df",
|
|
31
|
+
"@isoloop/runtime": "0.0.0-next.4da23df",
|
|
32
|
+
"@types/node": "26.6.6",
|
|
33
|
+
"typescript": "7.0.2",
|
|
34
|
+
"vite": "8.3.5"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown --platform node --dts --no-fixed-extension",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|