@dokebi/template-inertia 0.4.12 → 0.4.13
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/AI.md +1 -1
- package/dist/index.js +27 -11
- package/dist/vite-dev.d.ts +14 -0
- package/dist/vite-dev.js +36 -3
- package/package.json +2 -2
package/AI.md
CHANGED
|
@@ -272,7 +272,7 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
|
|
|
272
272
|
- Cluster apps run one worker under `dokebi dev` (@dokebi/cluster); `DOKEBI_DEV_WORKERS` asks for more, which also works on a cold cache.
|
|
273
273
|
- When a build marks absolute-path imports as `external`, the dev server prefixes those paths with `<base>`. In the dev server use a Vite plugin that resolves them to real files (see the playground's `vite.config.ts`).
|
|
274
274
|
- Production (no `DOKEBI_VITE_DEV`) is unaffected. Never set this variable on a production server.
|
|
275
|
-
- **Content-Security-Policy** (dokebi-web security headers, [D-0149](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0149-security-headers.md)):
|
|
275
|
+
- **Content-Security-Policy** (dokebi-web security headers, [D-0149](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0149-security-headers.md)): Vite's HMR socket connects to the page's own origin and `<base>` (`ws://localhost:<app port>/build/`, or `wss://<public host>/build/` through a tunnel; §5.1), which `connect-src 'self'` allows (CSP3), so nothing is added for it (0.4.13, [D-0249](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0249-dev-hmr-csp-self.md); before, `ws://*:* wss://*:*`). Only a project whose Vite config sends the socket elsewhere — `server.ws` (or the older `server.hmr`) with `host`, `protocol`, `port` or `clientPort` — gets that origin added in development, exactly: the scheme (both `ws:` and `wss:` when the page decides), the host (`*` when it is the page's) and the port (`clientPort`, else `port`; `*` when it is the page's), e.g. `clientPort: 5174` → `ws://*:5174 wss://*:5174`. The dev host reports it when an app process connects (debug `Vite HMR socket origin added to connect-src`). In development this plugin also adds `worker-src 'self' blob:` for the `blob:` SharedWorker Vite's client pings a restarted dev host from (without it the page never reconnects); production adds nothing. Pages load their scripts from `'self'` (the page data is JSON, not a script); keep `'unsafe-inline'` in a policy of your own when a Vite framework plugin adds inline scripts in development.
|
|
276
276
|
- **Nonce policy** (0.4.12, [D-0247](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0247-csp-nonce.md); web 0.4.19 `contentSecurityPolicy: { nonce: true, styleNonce?: true }`): the first HTML — plain, sealed or server rendered, built or in development — writes the request's nonce (`web.cspNonce(request)`) on every module script and on the boot fallback's `<style>` and `<script>`, and adds `<meta property="csp-nonce" nonce="…">`, which Vite's client (development `<style>` of imported CSS) and its preload helper read. The page data block (`type="application/json"`) is never run and needs none. What the entry imports or creates is trusted by `'strict-dynamic'`. Inertia's own progress bar and error dialog styles take the nonce from `createInertiaApp({ nonce: document.querySelector('meta[property="csp-nonce"]')?.nonce || undefined })` (the generated `views/app.js` does; add it to an older entry before `styleNonce`). Checked in Chromium: a built Vue app with SSR and navigation (example 24), a seal host with server-rendered public pages and a framed page (example 80), and the Vite dev page with imported CSS, a dynamic import and the HMR client (`tests/dev-files.test.ts`).
|
|
277
277
|
- The host answers a Vite middleware error with 500 (error log `INERTIA_VITE_HOST_FAILED`); 404 only when Vite has nothing for the URL. A host that does not answer is a 502 with error `INERTIA_VITE_DEV_FAILED` (once per 10 seconds, `repeated`); a host that cannot be reached at start is `VITE_DEV_UNAVAILABLE`.
|
|
278
278
|
- Debug logs (D-0047): `Inertia settings resolved`, `Vite dev server ready` (ms, `shared`), `Vite dev route registered`, `Vite manifest read`, `Inertia SSR bundle loaded`, `Inertia SSR render deadline` (`timeoutMs`), `Inertia SSR render finished after its deadline` (a cut render that ended later), `Inertia SSR renders the source through Vite` (the source used), `Inertia scope created`, `Vite dev uses the host of dokebi dev`, `Vite dev starts a host in this process`, `Vite dev host connected` / `disconnected`; in the host `Vite dev host listening` (`port`, `hosts`), `Vite dev host started` (ms), `Vite dev host closed` (`connections`), `Vite dev host listens on IPv4 loopback only`, `Vite dev host port is taken on ::1, trying another`, `Vite dev host filters watcher events of unchanged files`, `Vite dev host ignored an event for a file that did not change` (the first and every 100th, `dropped`); `Vite dev host settings read` (`depsRepairIntervalMs`), `Vite dev host recorded itself in the cache folder` (`shared`), `Vite dev host re-optimized its dependencies` (`trigger`, `ms`, `repairs`), and per check only when debug is on `Vite dev host dependency cache matches` (`trigger`, `files`); per real file event, only when debug is on, `Vite dev host passes a file change`. A file whose state cannot be read is warn `INERTIA_VITE_WATCH_STAT_FAILED` (the event goes on). Per request, only when debug is on: `Vite dev route refused a host`, `Vite dev host closed an upgrade that is not Vite`, `Vite dev host refused a request without its key`, `Vite dev request ended by the browser`. Host listener and request failures are error `INERTIA_VITE_HOST_FAILED`.
|
package/dist/index.js
CHANGED
|
@@ -520,17 +520,15 @@ class InertiaRuntime {
|
|
|
520
520
|
// Development (D-0045): one Vite for every scope, reached by the first `vite` (the host of
|
|
521
521
|
// `dokebi dev`, shared by every worker, or one started in this process).
|
|
522
522
|
const develop = viteDevRequested();
|
|
523
|
-
//
|
|
524
|
-
//
|
|
525
|
-
//
|
|
526
|
-
//
|
|
523
|
+
// When the dev host restarts, Vite's client pings it from a `blob:` SharedWorker, which
|
|
524
|
+
// script-src would block without worker-src (community request A4). The HMR socket itself
|
|
525
|
+
// goes to the page's own origin, which connect-src 'self' allows; a Vite config that sends it
|
|
526
|
+
// elsewhere gets that origin added below (D-0249; it was ws://*:* wss://*:* before).
|
|
527
|
+
// Development only.
|
|
527
528
|
if (develop)
|
|
528
529
|
server.contentSecurityPolicy({
|
|
529
530
|
plugin: 'dokebi-template-inertia',
|
|
530
|
-
directives: {
|
|
531
|
-
'connect-src': ['ws://*:*', 'wss://*:*'],
|
|
532
|
-
'worker-src': ["'self'", 'blob:'],
|
|
533
|
-
},
|
|
531
|
+
directives: { 'worker-src': ["'self'", 'blob:'] },
|
|
534
532
|
});
|
|
535
533
|
logger.log('debug', 'Inertia settings resolved', {
|
|
536
534
|
develop,
|
|
@@ -652,7 +650,7 @@ class InertiaRuntime {
|
|
|
652
650
|
nodeServer?.removeListener('upgrade', onUpgrade);
|
|
653
651
|
});
|
|
654
652
|
}
|
|
655
|
-
const
|
|
653
|
+
const openDev = () => {
|
|
656
654
|
if (!devServer) {
|
|
657
655
|
const begin = performance.now();
|
|
658
656
|
// A start failure reaches setup or the request that awaits the server.
|
|
@@ -669,7 +667,10 @@ class InertiaRuntime {
|
|
|
669
667
|
code: 'INERTIA_VITE_DEV',
|
|
670
668
|
});
|
|
671
669
|
}
|
|
672
|
-
|
|
670
|
+
return devServer;
|
|
671
|
+
};
|
|
672
|
+
const viteDev = (base) => {
|
|
673
|
+
const current = openDev();
|
|
673
674
|
if (!devBases.has(base)) {
|
|
674
675
|
devBases.add(base);
|
|
675
676
|
// Modules, pre-bundled dependencies and @vite/client, under the Vite base.
|
|
@@ -732,6 +733,21 @@ class InertiaRuntime {
|
|
|
732
733
|
}
|
|
733
734
|
return current;
|
|
734
735
|
};
|
|
736
|
+
// D-0249: the HMR socket's origin is the page's own unless the project's Vite config names
|
|
737
|
+
// another (server.ws / server.hmr host, protocol, port or clientPort): only the dev host
|
|
738
|
+
// knows, so it is asked now, while CSP sources may still be added (web freezes them at start).
|
|
739
|
+
if (develop && context.runtime.describing !== true) {
|
|
740
|
+
const opened = await openDev();
|
|
741
|
+
if (opened.hmrSources.length) {
|
|
742
|
+
server.contentSecurityPolicy({
|
|
743
|
+
plugin: 'dokebi-template-inertia',
|
|
744
|
+
directives: { 'connect-src': [...opened.hmrSources] },
|
|
745
|
+
});
|
|
746
|
+
logger.log('debug', 'Vite HMR socket origin added to connect-src', {
|
|
747
|
+
sources: opened.hmrSources,
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
735
751
|
// Built files are served at their exact URL (no wildcard), once even if apps share chunks.
|
|
736
752
|
const served = new Set();
|
|
737
753
|
const loaded = new Set();
|
|
@@ -1037,7 +1053,7 @@ class InertiaRuntime {
|
|
|
1037
1053
|
}
|
|
1038
1054
|
export const createPlugin = definePlugin({
|
|
1039
1055
|
name: 'dokebi-template-inertia',
|
|
1040
|
-
version: '0.4.
|
|
1056
|
+
version: '0.4.13',
|
|
1041
1057
|
core: '^0.4.2',
|
|
1042
1058
|
options,
|
|
1043
1059
|
entry: parseEntry,
|
package/dist/vite-dev.d.ts
CHANGED
|
@@ -39,6 +39,12 @@ export interface ViteHost {
|
|
|
39
39
|
}
|
|
40
40
|
/** What an app process uses: the host's files for `<base>*` and server rendering. */
|
|
41
41
|
export interface ViteDev {
|
|
42
|
+
/**
|
|
43
|
+
* D-0249: the CSP sources of the HMR socket when the project's Vite config sends it somewhere
|
|
44
|
+
* other than the page's own origin (`server.ws` / `server.hmr` with `host`, `protocol`, `port`
|
|
45
|
+
* or `clientPort`); empty when it connects to the page's origin, which `'self'` allows.
|
|
46
|
+
*/
|
|
47
|
+
readonly hmrSources: readonly string[];
|
|
42
48
|
/** Answers a dev route request from the host (status, headers and body as Vite sent them). */
|
|
43
49
|
forward(request: IncomingMessage, response: ServerResponse, report: (error: unknown) => void): void;
|
|
44
50
|
/**
|
|
@@ -91,6 +97,14 @@ export declare function destroyRequest(outgoing: ClientRequest, error?: Error):
|
|
|
91
97
|
* Connects this process to a Vite host and checks that it answers with the key. Requests share
|
|
92
98
|
* keep-alive connections; `close` ends them (the host keeps running).
|
|
93
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* D-0249: the CSP sources of an HMR socket Vite's client sends elsewhere than the page's origin,
|
|
102
|
+
* from the resolved `server.ws` (Vite 8; `server.hmr` is folded into it): the scheme (both when
|
|
103
|
+
* the config leaves it to the page), the host (`*` when the page's host is used) and the port
|
|
104
|
+
* (`clientPort`, else `port`; `*` when the page's port is used). None when the config names none
|
|
105
|
+
* of them: the client then connects to the page's own origin and `<base>`.
|
|
106
|
+
*/
|
|
107
|
+
export declare function hmrSources(ws: unknown): string[];
|
|
94
108
|
export declare function connectViteDev(logger: Logger, url: string, key: string): Promise<ViteDev>;
|
|
95
109
|
/**
|
|
96
110
|
* The Vite of this process: the host of `dokebi dev` when `DOKEBI_VITE_DEV_URL` and
|
package/dist/vite-dev.js
CHANGED
|
@@ -285,7 +285,12 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
285
285
|
if (path === HOST_PATH && !browser) {
|
|
286
286
|
// An app process connects (it started or restarted): it is answered once the pre-bundled
|
|
287
287
|
// dependencies match what Vite serves, so its pages get hashes that load (D-0128).
|
|
288
|
-
void (cache ? cache.ensure('client').catch(report('deps')) : Promise.resolve()).then(() => sendJson(response, 200, {
|
|
288
|
+
void (cache ? cache.ensure('client').catch(report('deps')) : Promise.resolve()).then(() => sendJson(response, 200, {
|
|
289
|
+
root,
|
|
290
|
+
pid: process.pid,
|
|
291
|
+
// D-0249: where Vite's client sends the HMR socket, when not to the page's origin.
|
|
292
|
+
hmr: hmrSources(server.config.server.ws),
|
|
293
|
+
}));
|
|
289
294
|
}
|
|
290
295
|
else if (path === SSR_PATH && request.method === 'POST' && !browser)
|
|
291
296
|
void ssr(request, response, server);
|
|
@@ -422,6 +427,27 @@ export function destroyRequest(outgoing, error) {
|
|
|
422
427
|
* Connects this process to a Vite host and checks that it answers with the key. Requests share
|
|
423
428
|
* keep-alive connections; `close` ends them (the host keeps running).
|
|
424
429
|
*/
|
|
430
|
+
/**
|
|
431
|
+
* D-0249: the CSP sources of an HMR socket Vite's client sends elsewhere than the page's origin,
|
|
432
|
+
* from the resolved `server.ws` (Vite 8; `server.hmr` is folded into it): the scheme (both when
|
|
433
|
+
* the config leaves it to the page), the host (`*` when the page's host is used) and the port
|
|
434
|
+
* (`clientPort`, else `port`; `*` when the page's port is used). None when the config names none
|
|
435
|
+
* of them: the client then connects to the page's own origin and `<base>`.
|
|
436
|
+
*/
|
|
437
|
+
export function hmrSources(ws) {
|
|
438
|
+
if (ws === null || typeof ws !== 'object')
|
|
439
|
+
return [];
|
|
440
|
+
const { host, protocol, port, clientPort } = ws;
|
|
441
|
+
const reach = clientPort ?? port;
|
|
442
|
+
const named = (value) => value !== undefined && value !== null && value !== '';
|
|
443
|
+
if (!named(host) && !named(protocol) && !named(reach))
|
|
444
|
+
return [];
|
|
445
|
+
const name = named(host) ? String(host) : '*';
|
|
446
|
+
const hostPart = name.includes(':') && !name.startsWith('[') ? `[${name}]` : name;
|
|
447
|
+
const portPart = named(reach) ? `:${Number(reach)}` : ':*';
|
|
448
|
+
const schemes = named(protocol) ? [String(protocol)] : ['ws', 'wss'];
|
|
449
|
+
return schemes.map((scheme) => `${scheme}://${hostPart}${portPart}`);
|
|
450
|
+
}
|
|
425
451
|
export async function connectViteDev(logger, url, key) {
|
|
426
452
|
const target = hostUrl(url);
|
|
427
453
|
const host = target.hostname.replace(/^\[(.*)\]$/, '$1');
|
|
@@ -467,10 +493,15 @@ export async function connectViteDev(logger, url, key) {
|
|
|
467
493
|
}
|
|
468
494
|
outgoing.end(body);
|
|
469
495
|
});
|
|
496
|
+
let sources = [];
|
|
470
497
|
try {
|
|
471
|
-
const { status } = await call('GET', HOST_PATH);
|
|
498
|
+
const { status, text } = await call('GET', HOST_PATH);
|
|
472
499
|
if (status !== 200)
|
|
473
500
|
throw new InertiaError('VITE_DEV_UNAVAILABLE', `The Vite dev host at ${target.origin} answered ${status} (wrong DOKEBI_VITE_DEV_KEY?)`);
|
|
501
|
+
// D-0249: a host before it sends no `hmr`: its socket is the page's origin, as before.
|
|
502
|
+
const answer = JSON.parse(text);
|
|
503
|
+
if (Array.isArray(answer.hmr))
|
|
504
|
+
sources = answer.hmr.filter((source) => typeof source === 'string');
|
|
474
505
|
}
|
|
475
506
|
catch (cause) {
|
|
476
507
|
agent.destroy();
|
|
@@ -479,10 +510,11 @@ export async function connectViteDev(logger, url, key) {
|
|
|
479
510
|
throw cause;
|
|
480
511
|
throw new InertiaError('VITE_DEV_UNAVAILABLE', `The Vite dev host at ${target.origin} cannot be reached`, { cause });
|
|
481
512
|
}
|
|
482
|
-
logger.log('debug', 'Vite dev host connected', { url: target.origin });
|
|
513
|
+
logger.log('debug', 'Vite dev host connected', { url: target.origin, hmr: sources });
|
|
483
514
|
/** HMR sockets joined to the host, ended by close(). */
|
|
484
515
|
const joined = new Set();
|
|
485
516
|
return {
|
|
517
|
+
hmrSources: Object.freeze(sources),
|
|
486
518
|
upgrade(request, socket, head, report) {
|
|
487
519
|
const upstream = connectNet({ host, port });
|
|
488
520
|
joined.add(socket);
|
|
@@ -621,6 +653,7 @@ export async function openViteDev(logger, environment = process.env, root = proc
|
|
|
621
653
|
throw error;
|
|
622
654
|
}
|
|
623
655
|
return {
|
|
656
|
+
hmrSources: client.hmrSources,
|
|
624
657
|
forward: client.forward,
|
|
625
658
|
render: client.render,
|
|
626
659
|
upgrade: client.upgrade,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/template-inertia",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Inertia v3 server adapter for Dokebi: page JSON, Vite manifest assets and optional server-side rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dokebi",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"devDependencies": {
|
|
146
146
|
"@dokebi/i18n": "0.2.8",
|
|
147
147
|
"@dokebi/session": "0.4.9",
|
|
148
|
-
"@dokebi/web": "0.4.
|
|
148
|
+
"@dokebi/web": "0.4.20",
|
|
149
149
|
"@dokebi/websocket": "0.4.9",
|
|
150
150
|
"@dokebi/websocket-hub": "0.4.5",
|
|
151
151
|
"@inertiajs/vue3": "3.9.1",
|