@dokebi/template-inertia 0.4.17 → 0.4.19
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 +2 -0
- package/dist/dev-rescan.d.ts +12 -0
- package/dist/dev-rescan.js +28 -0
- package/dist/index.js +43 -1
- package/dist/module-pages-worker.d.ts +1 -0
- package/dist/module-pages-worker.js +25 -1
- package/dist/module-pages.d.ts +2 -0
- package/dist/module-pages.js +120 -1
- package/dist/vite-dev.d.ts +7 -0
- package/dist/vite-dev.js +26 -0
- package/dist/vite-plugin.d.ts +2 -0
- package/dist/vite-plugin.js +4 -0
- package/dist/vite-watch.d.ts +20 -1
- package/dist/vite-watch.js +31 -2
- package/package.json +3 -3
package/AI.md
CHANGED
|
@@ -265,6 +265,8 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
|
|
|
265
265
|
- The same host check as the dev routes runs first (loopback names, IPs, @dokebi/app domains, `devHosts`; others get `403`). Behind a tunnel set dokebi-web `trustProxy` so the tunnel's host is seen (@dokebi/web AI.md §2.6). A host that cannot reach Vite is logged at error `INERTIA_VITE_DEV_FAILED` once per window.
|
|
266
266
|
- Vite's token check (protection against cross-site WebSocket hijacking) stays. Upgrades that are not Vite's subprotocols are cut. Closing the host closes its port and connections, and a host whose Vite fails to start closes its port.
|
|
267
267
|
- **Late file events are no edits (D-0045 addendum 4, 0.4.3)**: on macOS, FSEvents also delivers events for writes made before the watch started (`dokebi init`, `dokebi add`, `npm install`, a checkout), minutes late when fseventsd is busy. The host records each module file's state (device, inode, size, modification time) when Vite first loads it in an environment (before Vite reads it) and the `vite.config.*` files before Vite starts, and drops a watcher `change`, `add` or `unlink` whose file state equals every recorded one, so such an event invalidates nothing, sends no reload or update (a reload was buffered for the first page that connected) and restarts nothing. Any other event goes on at once. Files Vite never loaded through its plugin pipeline are not filtered. A save that changes nothing but the modification time is still an edit.
|
|
268
|
+
- **The drain ends the open HMR sockets (0.4.18, [D-0288](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0288-dev-kills-after-the-apps-stop-deadlines.md))**: the Vite host outlives a `dokebi dev` restart, so nothing else closes a socket the app joined to it; next to @dokebi/websocket each one is a hijacked request web's drain waits for, and an open page held every restart to the drain deadline (center dev: `Web drain started pending: 2` for one tab, then the process was killed). On drain they end (debug `INERTIA_VITE_HMR_ENDED` with the count) and an HMR upgrade after that is answered 503; the page's Vite client reconnects to the next app and reloads, as it did when the process ended.
|
|
269
|
+
- **The host compares with the disk on a timer too (0.4.19, [D-0289](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0289-vite-host-rescans-and-env-records.md))**: FSEvents delivers edits seconds late (measured: 2.8 s median, 6 s at worst on an idle Mac; far more under load), so the comparison below also runs every `DOKEBI_DEV_RESCAN_MS` (the variable `dokebi dev` uses for src/, default 2000, `0` off, 250–600000; `.env` works, dev passes it on): an open page gets its HMR update within that time without a page load (info `INERTIA_VITE_WATCH_MISSED` with `trigger: 'timer'` when it found something; an empty pass says nothing). The module page tables follow the disk the same way: the files the worker read for a table (the app file, the module list, the definitions) and the `.vue` listing of its folders are compared and a difference reloads the browser (info `INERTIA_MODULE_PAGES_MISSED`). The filter of unchanged files also records the env files Vite restarts for (`.env`, `.env.local`, `.env.<mode>`, `.env.<mode>.local`, and the config's dependencies): a late event for one written before the start no longer restarts Vite (a request then under way got 504).
|
|
268
270
|
- **Edits the watcher missed are read anyway (D-0283, 0.4.17)**: FSEvents can report an edit a minute late, or not before the next page load (a `git pull` that restarted the app while the host kept serving the old `.vue`, and the page broke on its new locales). The same records serve a comparison: when an app process connects (`trigger` `client`), before a server render (`ssr`) and when a page loads `<base>@vite/client` (`page`), the host compares every file Vite read with its state on disk. A file that changed is invalidated in every module graph at once and handed to Vite as the watcher's `change` (`unlink` when it is gone), so plugins, HMR updates and reloads run as for the watcher's own event, and the request that follows gets the file as it is; the watcher's late event then changes nothing and is dropped. Each find is info `INERTIA_VITE_WATCH_MISSED` (`trigger`, `files`, `sample` of at most 5, `compared`, `ms`). Open pages still get their immediate HMR from the watcher; the comparison guarantees that a reloaded page or a restarted app gets the files on disk.
|
|
269
271
|
- **Pre-bundled dependencies that load (D-0128, 0.4.4)**: Vite keeps what its dependency optimizer wrote (each dependency's file under `node_modules/.vite/deps` and the `?v=` hash pages get) in memory, and at start trusts `_metadata.json` whenever the lockfile and config hashes match; it never looks at the files again, and it answers a file that is gone with 504 "Outdated Optimize Dep". A folder changed under it (two Vite optimizers on one folder — two `dokebi dev` sessions, a host still closing while the next starts — or a reinstall) therefore left every page blank through app restarts and dev restarts, until `rm -rf node_modules/.vite`. The host now compares its optimizer's files and metadata hashes with the folder when it starts, whenever an app process connects (every app or worker start) and after it answered a 504; when they differ it removes the deps folder and restarts its Vite (warn `INERTIA_VITE_DEPS_STALE` with `trigger` `start`, `client` or `outdated`, `drift` `missing` or `rewritten`, and a sample of the missing files), and the app process is answered after the repair. Open pages reconnect HMR and reload; a new page load gets the new hashes. At most one repair per `devDepsRepairIntervalMs`; faster changes are reported with warn `INERTIA_VITE_DEPS_CHANGING`. The host records its pid in `<cacheDir>/.dokebi/vite-host.json` and warns `INERTIA_VITE_HOST_SHARED` when another live host recorded itself there (stop one of the two `dokebi dev`). App processes pass Vite's status text on (`504 Outdated Optimize Dep`).
|
|
270
272
|
- SSR: the host runs `ssrLoadModule(<source entry>)` and `render(page)` per request. The app process asks on connections of its own (a render that waits never holds the connections module requests are forwarded on) and cuts the request at `ssr.timeoutMs`, so renders that never finish do not pile up on the host. The source entry is `ssr.entry` (for example `src/apps/admin/views/ssr.js`), otherwise `ssr.js` in the folder of `vite.entry`. When neither exists the start fails (`SSR_ENTRY_MISSING`).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The variable `dokebi dev` reads for its own comparison of the watched paths (D-0264). */
|
|
2
|
+
export declare const RESCAN_VARIABLE = "DOKEBI_DEV_RESCAN_MS";
|
|
3
|
+
export declare const RESCAN_DEFAULT_MS = 2000;
|
|
4
|
+
/**
|
|
5
|
+
* The interval DOKEBI_DEV_RESCAN_MS asks for, as dokebi dev reads it: 0 turns the comparison off,
|
|
6
|
+
* a whole number of milliseconds from 250 to 600000 sets it, nothing is the default (2000).
|
|
7
|
+
* Anything else keeps the default and is answered as `problem` for the caller to log.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rescanInterval(value: string | undefined): {
|
|
10
|
+
ms: number;
|
|
11
|
+
problem?: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// D-0289: how often the Vite dev host compares what it read with the disk, besides its watcher.
|
|
2
|
+
// FSEvents can deliver an edit seconds late, or a minute late when fseventsd is busy (measured on
|
|
3
|
+
// a developer Mac, 2026-11-27: median 2.8 s, up to 6.2 s, on an idle machine), so HMR and the
|
|
4
|
+
// module page table waited for it. The host takes the same knob as `dokebi dev`'s own comparison
|
|
5
|
+
// of src/ (D-0264): DOKEBI_DEV_RESCAN_MS in the environment or .env (dokebi dev passes .env on).
|
|
6
|
+
/** The variable `dokebi dev` reads for its own comparison of the watched paths (D-0264). */
|
|
7
|
+
export const RESCAN_VARIABLE = 'DOKEBI_DEV_RESCAN_MS';
|
|
8
|
+
export const RESCAN_DEFAULT_MS = 2000;
|
|
9
|
+
const RESCAN_MIN_MS = 250;
|
|
10
|
+
const RESCAN_MAX_MS = 600_000;
|
|
11
|
+
/**
|
|
12
|
+
* The interval DOKEBI_DEV_RESCAN_MS asks for, as dokebi dev reads it: 0 turns the comparison off,
|
|
13
|
+
* a whole number of milliseconds from 250 to 600000 sets it, nothing is the default (2000).
|
|
14
|
+
* Anything else keeps the default and is answered as `problem` for the caller to log.
|
|
15
|
+
*/
|
|
16
|
+
export function rescanInterval(value) {
|
|
17
|
+
if (value === undefined || value.trim() === '')
|
|
18
|
+
return { ms: RESCAN_DEFAULT_MS };
|
|
19
|
+
const ms = Number(value);
|
|
20
|
+
if (ms === 0)
|
|
21
|
+
return { ms: 0 };
|
|
22
|
+
if (Number.isSafeInteger(ms) && ms >= RESCAN_MIN_MS && ms <= RESCAN_MAX_MS)
|
|
23
|
+
return { ms };
|
|
24
|
+
return {
|
|
25
|
+
ms: RESCAN_DEFAULT_MS,
|
|
26
|
+
problem: `${RESCAN_VARIABLE}=${value.slice(0, 40)} is not 0 (off) or whole milliseconds from ${RESCAN_MIN_MS} to ${RESCAN_MAX_MS}; using ${RESCAN_DEFAULT_MS}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -364,10 +364,45 @@ function parseEntry(input) {
|
|
|
364
364
|
class InertiaRuntime {
|
|
365
365
|
settings;
|
|
366
366
|
entry;
|
|
367
|
+
/** D-0288: the Vite dev connection once opened (development only), for the drain. */
|
|
368
|
+
#devServer;
|
|
369
|
+
/** D-0288: set when the app drains; an HMR upgrade after it is not joined (503). */
|
|
370
|
+
#dev = { draining: false };
|
|
367
371
|
constructor(settings, entry) {
|
|
368
372
|
this.settings = settings;
|
|
369
373
|
this.entry = entry;
|
|
370
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* D-0288: the HMR sockets joined to the Vite dev host end when the app drains. The host
|
|
377
|
+
* outlives a `dokebi dev` restart, so nothing else closes them: through a WebSocket plugin each
|
|
378
|
+
* is a hijacked request web's drain counted until its deadline (center dev: "Web drain started
|
|
379
|
+
* pending: 2" for one open page, then the process was killed). The page's Vite client
|
|
380
|
+
* reconnects to the next app and reloads, as it did when the process ended.
|
|
381
|
+
*/
|
|
382
|
+
async drain(context) {
|
|
383
|
+
this.#dev.draining = true;
|
|
384
|
+
const opened = this.#devServer?.();
|
|
385
|
+
if (!opened)
|
|
386
|
+
return;
|
|
387
|
+
let vite;
|
|
388
|
+
try {
|
|
389
|
+
vite = await opened;
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
// It never opened (its failure was said where it was awaited): nothing was joined.
|
|
393
|
+
if (context.logger.isEnabled('debug'))
|
|
394
|
+
context.logger.log('debug', 'Vite HMR sockets: the dev server never opened', {
|
|
395
|
+
error: describeError(error),
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const sockets = vite.endUpgrades();
|
|
400
|
+
if (sockets > 0)
|
|
401
|
+
context.logger.log('debug', 'Vite HMR sockets ended for the drain', {
|
|
402
|
+
code: 'INERTIA_VITE_HMR_ENDED',
|
|
403
|
+
sockets,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
371
406
|
async setup(context) {
|
|
372
407
|
const server = context.getDependency(web);
|
|
373
408
|
const logger = context.logger;
|
|
@@ -561,6 +596,8 @@ class InertiaRuntime {
|
|
|
561
596
|
const routeIds = this.settings.routeIds;
|
|
562
597
|
const repeats = new Repeats({ intervalMs: limits.logRepeatWindowMs });
|
|
563
598
|
let devServer;
|
|
599
|
+
this.#devServer = () => devServer;
|
|
600
|
+
const dev = this.#dev;
|
|
564
601
|
const devBases = new Set();
|
|
565
602
|
// Vite refuses hosts it does not know (DNS rebinding). Its check is off (one Vite serves
|
|
566
603
|
// every app); instead the dev routes check the host themselves: loopback names, IPs, the
|
|
@@ -604,6 +641,11 @@ class InertiaRuntime {
|
|
|
604
641
|
};
|
|
605
642
|
/** Joins one Vite upgrade to the host after the dev routes' host check. */
|
|
606
643
|
const joinUpgrade = (request, socket, head, base) => {
|
|
644
|
+
// D-0288: the app drains; the page's client tries again and reaches the next app.
|
|
645
|
+
if (dev.draining) {
|
|
646
|
+
socket.end('HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\nContent-Length: 0\r\n\r\n');
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
607
649
|
const host = hostName(request);
|
|
608
650
|
if (!devHosts.allows(host)) {
|
|
609
651
|
if (logger.isEnabled('debug'))
|
|
@@ -1065,7 +1107,7 @@ class InertiaRuntime {
|
|
|
1065
1107
|
}
|
|
1066
1108
|
export const createPlugin = definePlugin({
|
|
1067
1109
|
name: 'dokebi-template-inertia',
|
|
1068
|
-
version: '0.4.
|
|
1110
|
+
version: '0.4.19',
|
|
1069
1111
|
core: '^0.4.2',
|
|
1070
1112
|
options,
|
|
1071
1113
|
entry: parseEntry,
|
|
@@ -3,9 +3,26 @@
|
|
|
3
3
|
// writes, the modules' own definitions) are loaded as they are now; the Vite host lives for the
|
|
4
4
|
// whole `dokebi dev` session, and its own cache would keep the modules of its first read (a module
|
|
5
5
|
// added while it ran stayed out of the page table and its folder answered 403).
|
|
6
|
+
//
|
|
7
|
+
// D-0289: the worker also answers which project files it read (the app file, the module list, the
|
|
8
|
+
// definitions), so the dev server compares them with the disk besides its watcher.
|
|
9
|
+
import nodeModule from 'node:module';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
6
11
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
7
12
|
import { diagnostics } from '@dokebi/core/libraries';
|
|
8
13
|
const PAGES_KEY = Symbol.for('dokebi.app.modulePages');
|
|
14
|
+
/** Project files this worker loaded (file: URLs outside node_modules), when Node can say. */
|
|
15
|
+
const loaded = new Set();
|
|
16
|
+
const registerHooks = nodeModule.registerHooks;
|
|
17
|
+
// Node 22.15 / 23.5 and later; without it the dev server keeps its watcher alone for these files.
|
|
18
|
+
registerHooks?.({
|
|
19
|
+
resolve(specifier, context, next) {
|
|
20
|
+
const resolved = next(specifier, context);
|
|
21
|
+
if (resolved.url.startsWith('file:') && !resolved.url.includes('/node_modules/'))
|
|
22
|
+
loaded.add(resolved.url);
|
|
23
|
+
return resolved;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
9
26
|
async function read(url) {
|
|
10
27
|
try {
|
|
11
28
|
const definition = (await import(url)).default;
|
|
@@ -15,7 +32,14 @@ async function read(url) {
|
|
|
15
32
|
if (typeof list !== 'function')
|
|
16
33
|
return { kind: 'unsupported' };
|
|
17
34
|
// Plain data (module names, folders, set names): it crosses to the main thread as it is.
|
|
18
|
-
|
|
35
|
+
const sources = list();
|
|
36
|
+
return {
|
|
37
|
+
kind: 'sources',
|
|
38
|
+
sources,
|
|
39
|
+
files: [url, ...loaded]
|
|
40
|
+
.filter((item, at, all) => all.indexOf(item) === at)
|
|
41
|
+
.map((item) => fileURLToPath(item)),
|
|
42
|
+
};
|
|
19
43
|
}
|
|
20
44
|
catch (error) {
|
|
21
45
|
return { kind: 'error', error: diagnostics.describeError(error) };
|
package/dist/module-pages.d.ts
CHANGED
|
@@ -37,5 +37,7 @@ export declare class ModulePagesSource {
|
|
|
37
37
|
load(id: string): Promise<string | null>;
|
|
38
38
|
/** The dev server: page files added or removed in a module folder reload the browser. */
|
|
39
39
|
configureServer(server: PagesDevServer): void;
|
|
40
|
+
/** Ends the comparison (the dev server closed or configures again). */
|
|
41
|
+
stop(): void;
|
|
40
42
|
}
|
|
41
43
|
export {};
|
package/dist/module-pages.js
CHANGED
|
@@ -6,12 +6,15 @@
|
|
|
6
6
|
// `Symbol.for('dokebi.app.modulePages')`, @dokebi/app 0.4.9) and writes one static import per page
|
|
7
7
|
// file. Pages of sets the app did not choose (`Pages/<set>/**`) are left out. In the dev server it
|
|
8
8
|
// watches the module folders and the app file: a page added or removed reloads the browser.
|
|
9
|
-
import { existsSync } from 'node:fs';
|
|
9
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
10
10
|
import { readdir } from 'node:fs/promises';
|
|
11
11
|
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
12
12
|
import { pathToFileURL } from 'node:url';
|
|
13
13
|
import { Worker } from 'node:worker_threads';
|
|
14
|
+
import { diagnostics } from '@dokebi/core/libraries';
|
|
15
|
+
import { RESCAN_VARIABLE, rescanInterval } from './dev-rescan.js';
|
|
14
16
|
import { InertiaError } from './errors.js';
|
|
17
|
+
const { describeError } = diagnostics;
|
|
15
18
|
/** The specifier views/app.js and views/ssr.js import. */
|
|
16
19
|
export const MODULE_PAGES_ID = 'virtual:dokebi/module-pages';
|
|
17
20
|
/** Vite's mark of a virtual module, then the app file the module is for. */
|
|
@@ -70,6 +73,35 @@ async function pageFiles(source, appViews) {
|
|
|
70
73
|
}
|
|
71
74
|
return found;
|
|
72
75
|
}
|
|
76
|
+
/** A file's state for the comparison (D-0289): inode, size and time, or absent. */
|
|
77
|
+
function fileState(path) {
|
|
78
|
+
try {
|
|
79
|
+
const stats = statSync(path);
|
|
80
|
+
return `${stats.ino}:${stats.size}:${stats.mtimeMs}`;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const code = error.code;
|
|
84
|
+
return code === 'ENOENT' || code === 'ENOTDIR' ? 'absent' : `unreadable:${code ?? '?'}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The .vue files below the folders, sorted (a page added or removed changes it). */
|
|
88
|
+
function pageListing(folders) {
|
|
89
|
+
const lines = [];
|
|
90
|
+
for (const folder of folders) {
|
|
91
|
+
let names;
|
|
92
|
+
try {
|
|
93
|
+
names = readdirSync(folder, { recursive: true, encoding: 'utf8' });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
lines.push(`${folder}:${error.code ?? '?'}`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
for (const name of names)
|
|
100
|
+
if (name.endsWith('.vue'))
|
|
101
|
+
lines.push(join(folder, name));
|
|
102
|
+
}
|
|
103
|
+
return lines.sort().join('\n');
|
|
104
|
+
}
|
|
73
105
|
/** The build: the app file in this process (one read per build). */
|
|
74
106
|
async function readHere(app) {
|
|
75
107
|
let definition;
|
|
@@ -132,6 +164,13 @@ export class ModulePagesSource {
|
|
|
132
164
|
/** Virtual id → the folders and the app file a change of which reloads it. */
|
|
133
165
|
#watched = new Map();
|
|
134
166
|
#allow;
|
|
167
|
+
/**
|
|
168
|
+
* D-0289: per virtual id, the state of every file its table was read from (the app file, the
|
|
169
|
+
* module list, the definitions: what the worker loaded) and the page listing of its folders,
|
|
170
|
+
* compared every DOKEBI_DEV_RESCAN_MS besides the watcher (whose events can come late).
|
|
171
|
+
*/
|
|
172
|
+
#tracked = new Map();
|
|
173
|
+
#rescanTimer;
|
|
135
174
|
/** `allow` hands each module views folder to the dev file policy (D-0129). */
|
|
136
175
|
constructor(logger, allow) {
|
|
137
176
|
this.#logger = logger;
|
|
@@ -217,6 +256,8 @@ export class ModulePagesSource {
|
|
|
217
256
|
limit: MAX_FILES,
|
|
218
257
|
});
|
|
219
258
|
this.#watch(id, app, sources);
|
|
259
|
+
if (this.#serve)
|
|
260
|
+
this.#track(id, read.kind === 'sources' ? (read.files ?? []) : []);
|
|
220
261
|
this.#logger.log('debug', 'Inertia module pages gathered', {
|
|
221
262
|
app,
|
|
222
263
|
modules: counts,
|
|
@@ -235,6 +276,13 @@ export class ModulePagesSource {
|
|
|
235
276
|
/** The dev server: page files added or removed in a module folder reload the browser. */
|
|
236
277
|
configureServer(server) {
|
|
237
278
|
this.#server = server;
|
|
279
|
+
// D-0289: the comparison besides the watcher (one per source: a restart configures again).
|
|
280
|
+
this.stop();
|
|
281
|
+
const rescan = rescanInterval(process.env[RESCAN_VARIABLE]);
|
|
282
|
+
if (rescan.ms > 0) {
|
|
283
|
+
this.#rescanTimer = setInterval(() => this.#rescan(), rescan.ms);
|
|
284
|
+
this.#rescanTimer.unref();
|
|
285
|
+
}
|
|
238
286
|
const changed = (event) => (path) => {
|
|
239
287
|
for (const [id, watched] of this.#watched) {
|
|
240
288
|
const page = event !== 'change' &&
|
|
@@ -246,6 +294,11 @@ export class ModulePagesSource {
|
|
|
246
294
|
const definition = DEFINITION.test(basename(path)) && within(path, watched.sources);
|
|
247
295
|
if (!page && !definition && path !== watched.app && !watched.files.includes(path))
|
|
248
296
|
continue;
|
|
297
|
+
// A file or page the comparison follows, already at the state it took (or no change):
|
|
298
|
+
// nothing to do. Any other file (a definition no table was read from) goes on as before.
|
|
299
|
+
const followed = page || this.#tracked.get(id)?.states.has(path) === true;
|
|
300
|
+
if (followed && this.#current(id, watched.folders))
|
|
301
|
+
continue;
|
|
249
302
|
this.#invalidate(id, event, path);
|
|
250
303
|
}
|
|
251
304
|
};
|
|
@@ -253,6 +306,72 @@ export class ModulePagesSource {
|
|
|
253
306
|
server.watcher?.on('unlink', changed('unlink'));
|
|
254
307
|
server.watcher?.on('change', changed('change'));
|
|
255
308
|
}
|
|
309
|
+
/** Ends the comparison (the dev server closed or configures again). */
|
|
310
|
+
stop() {
|
|
311
|
+
clearInterval(this.#rescanTimer);
|
|
312
|
+
this.#rescanTimer = undefined;
|
|
313
|
+
}
|
|
314
|
+
/** Records what the table of `id` was read from (D-0289). */
|
|
315
|
+
#track(id, loaded) {
|
|
316
|
+
const watched = this.#watched.get(id);
|
|
317
|
+
if (!watched)
|
|
318
|
+
return;
|
|
319
|
+
const states = new Map();
|
|
320
|
+
for (const path of new Set([watched.app, ...watched.files, ...loaded]))
|
|
321
|
+
states.set(path, fileState(path));
|
|
322
|
+
this.#tracked.set(id, { states, listing: pageListing(watched.folders) });
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Whether every recorded file and the page listing of `id` are as they are now; when not, the
|
|
326
|
+
* records take the state now (so the change is handled once, by whoever sees it first) and the
|
|
327
|
+
* first path that differs is answered. Undefined: nothing recorded (the watcher decides).
|
|
328
|
+
*/
|
|
329
|
+
#current(id, folders) {
|
|
330
|
+
const tracked = this.#tracked.get(id);
|
|
331
|
+
if (!tracked)
|
|
332
|
+
return undefined;
|
|
333
|
+
return this.#differs(tracked, folders) === undefined;
|
|
334
|
+
}
|
|
335
|
+
#differs(tracked, folders) {
|
|
336
|
+
let first;
|
|
337
|
+
for (const [path, state] of tracked.states) {
|
|
338
|
+
const now = fileState(path);
|
|
339
|
+
if (now === state)
|
|
340
|
+
continue;
|
|
341
|
+
tracked.states.set(path, now);
|
|
342
|
+
first ??= path;
|
|
343
|
+
}
|
|
344
|
+
const listing = pageListing(folders);
|
|
345
|
+
if (listing !== tracked.listing) {
|
|
346
|
+
tracked.listing = listing;
|
|
347
|
+
first ??= folders[0] ?? 'views';
|
|
348
|
+
}
|
|
349
|
+
return first;
|
|
350
|
+
}
|
|
351
|
+
/** D-0289: what the watcher has not reported yet reloads the table now. */
|
|
352
|
+
#rescan() {
|
|
353
|
+
for (const [id, tracked] of this.#tracked) {
|
|
354
|
+
const watched = this.#watched.get(id);
|
|
355
|
+
if (!watched)
|
|
356
|
+
continue;
|
|
357
|
+
let path;
|
|
358
|
+
try {
|
|
359
|
+
path = this.#differs(tracked, watched.folders);
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
this.#logger.log('warn', 'Inertia module pages could not be compared with the disk', {
|
|
363
|
+
code: 'INERTIA_MODULE_PAGES_RESCAN_FAILED',
|
|
364
|
+
app: watched.app,
|
|
365
|
+
error: describeError(error),
|
|
366
|
+
});
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (path === undefined)
|
|
370
|
+
continue;
|
|
371
|
+
this.#logger.log('info', 'Inertia module pages found a change on disk its watcher had not reported; the browser reloads', { code: 'INERTIA_MODULE_PAGES_MISSED', app: watched.app, path });
|
|
372
|
+
this.#invalidate(id, 'rescan', path);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
256
375
|
#watch(id, app, sources) {
|
|
257
376
|
// The app's own views too: a page added or removed there changes which module pages it hides.
|
|
258
377
|
const folders = [join(dirname(app), 'views'), ...sources.map((source) => source.folder)];
|
package/dist/vite-dev.d.ts
CHANGED
|
@@ -60,6 +60,13 @@ export interface ViteDev {
|
|
|
60
60
|
* the page's own origin (a tunnel, a proxy), never the host's loopback port.
|
|
61
61
|
*/
|
|
62
62
|
upgrade(request: IncomingMessage, socket: Duplex, head: Buffer, report: (error: unknown) => void): void;
|
|
63
|
+
/**
|
|
64
|
+
* D-0288: ends the HMR sockets joined so far (each with its connection to the host) and
|
|
65
|
+
* answers how many. Called when the app drains: the host outlives a `dokebi dev` restart, so
|
|
66
|
+
* nothing else ends them, and a socket a WebSocket plugin routed through Fastify is a hijacked
|
|
67
|
+
* request web's drain waits for. The page's Vite client reconnects to the next app.
|
|
68
|
+
*/
|
|
69
|
+
endUpgrades(): number;
|
|
63
70
|
/** Releases this process's connections (and its own host, when it started one). */
|
|
64
71
|
close(): Promise<void>;
|
|
65
72
|
}
|
package/dist/vite-dev.js
CHANGED
|
@@ -17,6 +17,7 @@ import { connect as connectNet, createServer as createNetServer, } from 'node:ne
|
|
|
17
17
|
import { dirname, join } from 'node:path';
|
|
18
18
|
import { pathToFileURL } from 'node:url';
|
|
19
19
|
import { diagnostics } from '@dokebi/core/libraries';
|
|
20
|
+
import { RESCAN_VARIABLE, rescanInterval } from './dev-rescan.js';
|
|
20
21
|
import { InertiaError } from './errors.js';
|
|
21
22
|
import { DependencyCache } from './vite-deps.js';
|
|
22
23
|
import { DEV_CLIENT_HEADER, dokebiDevFiles } from './vite-files.js';
|
|
@@ -361,10 +362,23 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
361
362
|
throw error;
|
|
362
363
|
}
|
|
363
364
|
deps = cache;
|
|
365
|
+
// D-0289: the same comparison every DOKEBI_DEV_RESCAN_MS (2 s), so an edit the watcher reports
|
|
366
|
+
// late (FSEvents: seconds, a minute when fseventsd is busy) reaches HMR and the next request
|
|
367
|
+
// within that time, without a page load. A sweep stats the files Vite read (a few ms for a
|
|
368
|
+
// thousand); the watcher's own late event then finds nothing changed and is dropped.
|
|
369
|
+
const rescan = rescanInterval(process.env[RESCAN_VARIABLE]);
|
|
370
|
+
if (rescan.problem)
|
|
371
|
+
logger.log('warn', 'Vite dev host rescan interval ignored', {
|
|
372
|
+
code: 'INERTIA_VITE_RESCAN_INVALID',
|
|
373
|
+
problem: rescan.problem,
|
|
374
|
+
});
|
|
375
|
+
const rescanTimer = rescan.ms > 0 ? setInterval(() => served.sweep('timer'), rescan.ms) : undefined;
|
|
376
|
+
rescanTimer?.unref();
|
|
364
377
|
logger.log('debug', 'Vite dev host started', {
|
|
365
378
|
port: endpoint.port,
|
|
366
379
|
hosts: endpoint.hosts,
|
|
367
380
|
root,
|
|
381
|
+
rescanMs: rescan.ms,
|
|
368
382
|
ms: Math.round(performance.now() - begin),
|
|
369
383
|
});
|
|
370
384
|
let closing;
|
|
@@ -374,6 +388,7 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
374
388
|
port: endpoint.port,
|
|
375
389
|
hosts: endpoint.hosts,
|
|
376
390
|
close: () => (closing ??= (async () => {
|
|
391
|
+
clearInterval(rescanTimer);
|
|
377
392
|
try {
|
|
378
393
|
await server.close();
|
|
379
394
|
}
|
|
@@ -523,6 +538,8 @@ export async function connectViteDev(logger, url, key) {
|
|
|
523
538
|
logger.log('debug', 'Vite dev host connected', { url: target.origin, hmr: sources });
|
|
524
539
|
/** HMR sockets joined to the host, ended by close(). */
|
|
525
540
|
const joined = new Set();
|
|
541
|
+
/** The end of each joined upgrade (D-0288: the drain ends them). */
|
|
542
|
+
const ends = new Set();
|
|
526
543
|
return {
|
|
527
544
|
hmrSources: Object.freeze(sources),
|
|
528
545
|
upgrade(request, socket, head, report) {
|
|
@@ -534,11 +551,13 @@ export async function connectViteDev(logger, url, key) {
|
|
|
534
551
|
if (ended)
|
|
535
552
|
return;
|
|
536
553
|
ended = true;
|
|
554
|
+
ends.delete(end);
|
|
537
555
|
joined.delete(socket);
|
|
538
556
|
joined.delete(upstream);
|
|
539
557
|
socket.destroy();
|
|
540
558
|
upstream.destroy();
|
|
541
559
|
};
|
|
560
|
+
ends.add(end);
|
|
542
561
|
upstream.once('connect', () => {
|
|
543
562
|
// The handshake as the browser sent it (rawHeaders keeps names, order and repeats; Node
|
|
544
563
|
// refused any line break in them): Vite checks the token and the subprotocol itself.
|
|
@@ -627,6 +646,12 @@ export async function connectViteDev(logger, url, key) {
|
|
|
627
646
|
return answer.result;
|
|
628
647
|
throw remoteError(answer.error ?? { message: `Vite dev host answered ${status}` });
|
|
629
648
|
},
|
|
649
|
+
endUpgrades: () => {
|
|
650
|
+
const count = ends.size;
|
|
651
|
+
for (const end of [...ends])
|
|
652
|
+
end();
|
|
653
|
+
return count;
|
|
654
|
+
},
|
|
630
655
|
close: async () => {
|
|
631
656
|
agent.destroy();
|
|
632
657
|
renders.destroy();
|
|
@@ -667,6 +692,7 @@ export async function openViteDev(logger, environment = process.env, root = proc
|
|
|
667
692
|
forward: client.forward,
|
|
668
693
|
render: client.render,
|
|
669
694
|
upgrade: client.upgrade,
|
|
695
|
+
endUpgrades: client.endUpgrades,
|
|
670
696
|
close: async () => {
|
|
671
697
|
try {
|
|
672
698
|
await client.close();
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export interface DokebiInertiaVitePlugin {
|
|
|
62
62
|
} | string | null;
|
|
63
63
|
load(id: string): string | null | Promise<string | null>;
|
|
64
64
|
configureServer(server: DevServerShape): void;
|
|
65
|
+
/** Vite calls it when the dev server closes (or restarts) and after a build. */
|
|
66
|
+
closeBundle(): void;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* The plugin for `plugins: [vue(), dokebiInertia()]` of an Inertia app's vite.config.ts: imports
|
package/dist/vite-plugin.js
CHANGED
|
@@ -156,6 +156,10 @@ export function dokebiInertia(options = {}) {
|
|
|
156
156
|
return null;
|
|
157
157
|
return `throw new Error(${JSON.stringify(`${id} is answered by the dokebi-inertia middleware with export * from "${served}"; Vite served its placeholder instead`)});\n`;
|
|
158
158
|
},
|
|
159
|
+
closeBundle() {
|
|
160
|
+
// D-0289: the module pages' comparison ends with its dev server.
|
|
161
|
+
pages.stop();
|
|
162
|
+
},
|
|
159
163
|
configureServer(server) {
|
|
160
164
|
// D-0129: the file policy judges every request first, before the re-export and Vite.
|
|
161
165
|
const guard = files.middleware();
|
package/dist/vite-watch.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export interface SweepResult {
|
|
|
23
23
|
export interface StaleEventPlugin {
|
|
24
24
|
name: string;
|
|
25
25
|
enforce: 'pre';
|
|
26
|
+
configResolved(config: {
|
|
27
|
+
envDir?: string | false;
|
|
28
|
+
mode?: string;
|
|
29
|
+
configFileDependencies?: readonly string[];
|
|
30
|
+
}): void;
|
|
26
31
|
configureServer(server: WatchedServer): void;
|
|
27
32
|
load(this: {
|
|
28
33
|
environment?: {
|
|
@@ -44,8 +49,22 @@ export declare class ServedFiles {
|
|
|
44
49
|
get dropped(): number;
|
|
45
50
|
/** Records the state of `file` for `environment` unless it has one (a missing file: none). */
|
|
46
51
|
record(file: string, environment: string): void;
|
|
47
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Records the config files of `root` before Vite reads them, and the env files Vite reads from
|
|
54
|
+
* it in development (D-0289: Vite restarts for an event of `.env`, `.env.local`,
|
|
55
|
+
* `.env.development` or `.env.development.local`, and a late FSEvents event for one written
|
|
56
|
+
* before the start restarted it: a request then under way got 504, ERR_CLOSED_SERVER).
|
|
57
|
+
*/
|
|
48
58
|
recordConfig(root: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* The env files and config dependencies of the resolved config (D-0289): an `envDir`, a `mode`
|
|
61
|
+
* or files the config imports that recordConfig() could not know. Recorded once Vite read them.
|
|
62
|
+
*/
|
|
63
|
+
recordResolved(config: {
|
|
64
|
+
envDir?: string | false;
|
|
65
|
+
mode?: string;
|
|
66
|
+
configFileDependencies?: readonly string[];
|
|
67
|
+
}): void;
|
|
49
68
|
/** Whether an event for `file` is no change (dropped); a change updates the records. */
|
|
50
69
|
stale(file: string, event: string): boolean;
|
|
51
70
|
/** The Vite whose module graphs and watcher a sweep uses (Vite's `configureServer`). */
|
package/dist/vite-watch.js
CHANGED
|
@@ -34,6 +34,13 @@ const CONFIG_FILES = [
|
|
|
34
34
|
'vite.config.mts',
|
|
35
35
|
'vite.config.cts',
|
|
36
36
|
];
|
|
37
|
+
/** The env files Vite reads for `mode` (its getEnvFilesForMode), relative to the env folder. */
|
|
38
|
+
const envFiles = (mode) => [
|
|
39
|
+
'.env',
|
|
40
|
+
'.env.local',
|
|
41
|
+
`.env.${mode}`,
|
|
42
|
+
`.env.${mode}.local`,
|
|
43
|
+
];
|
|
37
44
|
/** The record that stands for "read before Vite started" (config files). */
|
|
38
45
|
const STARTUP = 'startup';
|
|
39
46
|
/** Watcher events that make Vite reload, update or restart. */
|
|
@@ -88,11 +95,27 @@ export class ServedFiles {
|
|
|
88
95
|
}
|
|
89
96
|
records.set(environment, state);
|
|
90
97
|
}
|
|
91
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Records the config files of `root` before Vite reads them, and the env files Vite reads from
|
|
100
|
+
* it in development (D-0289: Vite restarts for an event of `.env`, `.env.local`,
|
|
101
|
+
* `.env.development` or `.env.development.local`, and a late FSEvents event for one written
|
|
102
|
+
* before the start restarted it: a request then under way got 504, ERR_CLOSED_SERVER).
|
|
103
|
+
*/
|
|
92
104
|
recordConfig(root) {
|
|
93
|
-
for (const name of CONFIG_FILES)
|
|
105
|
+
for (const name of [...CONFIG_FILES, ...envFiles('development')])
|
|
94
106
|
this.record(join(root, name), STARTUP);
|
|
95
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* The env files and config dependencies of the resolved config (D-0289): an `envDir`, a `mode`
|
|
110
|
+
* or files the config imports that recordConfig() could not know. Recorded once Vite read them.
|
|
111
|
+
*/
|
|
112
|
+
recordResolved(config) {
|
|
113
|
+
if (typeof config.envDir === 'string')
|
|
114
|
+
for (const name of envFiles(config.mode ?? 'development'))
|
|
115
|
+
this.record(join(config.envDir, name), STARTUP);
|
|
116
|
+
for (const file of config.configFileDependencies ?? [])
|
|
117
|
+
this.record(file, STARTUP);
|
|
118
|
+
}
|
|
96
119
|
/** Whether an event for `file` is no change (dropped); a change updates the records. */
|
|
97
120
|
stale(file, event) {
|
|
98
121
|
const path = normal(file);
|
|
@@ -177,6 +200,9 @@ export class ServedFiles {
|
|
|
177
200
|
}
|
|
178
201
|
const ms = Math.round((performance.now() - begin) * 10) / 10;
|
|
179
202
|
const files = missed.map((item) => item.path);
|
|
203
|
+
// D-0289: the periodic sweep says only what it found (it runs every 2 s).
|
|
204
|
+
if (files.length === 0 && trigger === 'timer')
|
|
205
|
+
return { files, compared, ms };
|
|
180
206
|
if (files.length > 0)
|
|
181
207
|
this.#logger.log('info', 'Vite dev host found files changed on disk that its watcher had not reported; Vite reads them again', {
|
|
182
208
|
code: 'INERTIA_VITE_WATCH_MISSED',
|
|
@@ -229,6 +255,9 @@ export function staleEventFilter(files, logger) {
|
|
|
229
255
|
return {
|
|
230
256
|
name: 'dokebi:stale-watch-events',
|
|
231
257
|
enforce: 'pre',
|
|
258
|
+
configResolved(config) {
|
|
259
|
+
files.recordResolved(config);
|
|
260
|
+
},
|
|
232
261
|
configureServer(server) {
|
|
233
262
|
files.attach(server);
|
|
234
263
|
const watcher = server.watcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/template-inertia",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
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",
|
|
@@ -144,8 +144,8 @@
|
|
|
144
144
|
},
|
|
145
145
|
"devDependencies": {
|
|
146
146
|
"@dokebi/i18n": "0.2.9",
|
|
147
|
-
"@dokebi/session": "0.4.
|
|
148
|
-
"@dokebi/web": "0.4.
|
|
147
|
+
"@dokebi/session": "0.4.11",
|
|
148
|
+
"@dokebi/web": "0.4.26",
|
|
149
149
|
"@dokebi/websocket": "0.4.10",
|
|
150
150
|
"@dokebi/websocket-hub": "0.4.5",
|
|
151
151
|
"@inertiajs/vue3": "3.9.1",
|