@dokebi/template-inertia 0.4.24 → 0.4.25
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 -0
- package/dist/index.js +1 -1
- package/dist/template-build.js +1 -1
- package/dist/vite-dev.js +82 -60
- package/dist/vite-type-barrels.d.ts +43 -0
- package/dist/vite-type-barrels.js +110 -0
- package/dist/vite-watch.d.ts +2 -0
- package/dist/vite-watch.js +4 -0
- package/package.json +2 -2
package/AI.md
CHANGED
|
@@ -342,6 +342,7 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
342
342
|
- **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.
|
|
343
343
|
- **A module that does not compile answers 500, not 404 (0.4.23, [D-0292](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0292-vite-host-explains-module-404.md))**: in middleware mode Vite's error middleware logs a transform error, sends it to the open pages' overlay and calls `next()` without it, so the host answered an empty 404 (a `[@vue/compiler-sfc] Unresolvable type reference` looked like a missing page). The host keeps the error of each request (an error middleware in a `configureServer` post hook, before Vite's own) and answers it 500: error `INERTIA_VITE_MODULE_FAILED` with `url` and the whole `error`, and a `text/plain` body with the URL and Vite's message on this machine (`500 Internal Server Error\n` alone for a remote host, a `devHosts` tunnel). Vite still logs it and sends the overlay.
|
|
344
344
|
- **A type added to a file a barrel re-exports reaches the pages (0.4.23, D-0292)**: `defineProps<X>()` resolves X through @vue/compiler-sfc's type scopes, cached per file; for `export * from './event'` the compiler copies the source file's types into the barrel's scope, and @vitejs/plugin-vue clears only the changed file. A new type in an existing file that a barrel re-exports was `Unresolvable type reference` in dev until the barrel changed or dev restarted (vue-tsc and the build passed). The Vite host (and `dokebi template preview`) now clears, on every change or removal of a `.ts`/`.tsx`/`.mts`/`.cts` file, the type cache of the files that `export *` or `export type *` from it — in its folder and each folder above it up to its package root (the nearest package.json), and their own re-exporters — through the vue/compiler-sfc plugin-vue resolves from the project root (debug `Vue type caches of re-exporting files cleared` with `barrels`). The host also registers a TypeScript with a JS API on that compiler, as `dokebiInertia()` does, so a vite.config without it resolves imported props types too. The type files that compiler reads (outside node_modules) join the host's comparison with the disk (D-0283, D-0289: the page load, app connect, server render and `DOKEBI_DEV_RESCAN_MS` timer), which before saw only the modules Vite loads: an edit of a type file the watcher reports late or never reaches the pages within that time too (info `INERTIA_VITE_WATCH_MISSED` names it). The host learns them by wrapping the compiler's file access (`script.fs`, through @vitejs/plugin-vue's public `api.options`): its own `fs` when the config gives one, else node:fs with the answers of TypeScript's `ts.sys`.
|
|
345
|
+
- **A props type changed by a checkout reaches the pages at once, and stays (0.4.25, [D-0295](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0295-vite-host-type-changes-after-checkout.md))**: after a `git merge --ff` of many files, a page kept the old props of a type a barrel re-exports until the type file and the page were touched (the dev compiler had rebuilt the barrel from the old cache of the changed file while it cleared the barrels, and kept it). The changed type file's own cache is now cleared first, before the barrels, so a page that compiles meanwhile (a server render, another page of the same checkout) reads the new types. And a request that finds changed type files in the comparison with the disk (app connect, server render, a page loading Vite's client) goes on only once Vite has cleared their caches and invalidated the pages compiled with them (at most 2 s; none with `server.hmr: false`): the first server render after a checkout has the new props, where it used to have the old ones until the next request (debug `Vite handled the changed type files before the request`).
|
|
345
346
|
- **A module URL the host answers 404 says why (0.4.23, [D-0292](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0292-vite-host-explains-module-404.md))**: Vite turns `ERR_LOAD_URL` ("Failed to load url … (resolved id: …) in <importer>") into `next()` without the error, so a module it could not load answered an empty 404 and nothing was logged. Now, when a module request (`GET`/`HEAD` under the base with a module or style extension, `?import`, or `Sec-Fetch-Dest: script`) ends that way, the host asks Vite again in the same process and logs warn `INERTIA_VITE_NOT_LOADED` with `url`, `module` (the module URL without `t` and `import`), `root`, `file`, `exists` (with `missing`: `ENOENT`, `directory`, …), `readable`, `real` (when it is a link), `allowed` (Vite's `isFileLoadingAllowed`), `graph` (the module graph's entry for the URL: `id`, `file`, `stale` when its id names another file, `transformed`, `invalidatedAt`), `cause` (the error of one more `transformRequest`: the message Vite dropped, with its `code`) and `loadsNow`. Once per URL until it is served again; repeats are debug with `repeats`. Vite's static middleware serves a file that is there and allowed even when its transform fails, so an empty 404 means that this process saw the file missing or not allowed; when the diagnosis finds it there, readable and allowed after all (`retry: true`), the host invalidates the module, drops a URL entry whose id names another file and runs the request through Vite once more: the warning then says it was served after invalidating it, and `retried` is the status of that second answer. A page, a folder and a virtual `/@id/` URL keep the plain 404.
|
|
346
347
|
- **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`).
|
|
347
348
|
- 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`).
|
package/dist/index.js
CHANGED
package/dist/template-build.js
CHANGED
|
@@ -15,7 +15,7 @@ import { checkTemplateBundle, jsonValue, PAGE_META_MAX_BYTES, SHARED_DEFAULTS, S
|
|
|
15
15
|
import { packageVersion } from './template-shared.js';
|
|
16
16
|
import { registerVueTypeScript } from './vue-typescript.js';
|
|
17
17
|
/** The builder written into `builtWith` (scripts/testing/check-metadata.mjs keeps it the package version). */
|
|
18
|
-
const BUILDER = { name: 'dokebi-template-inertia', version: '0.4.
|
|
18
|
+
const BUILDER = { name: 'dokebi-template-inertia', version: '0.4.25' };
|
|
19
19
|
function defaultLogger() {
|
|
20
20
|
return new ConsoleLogger({ level: 'info' }, { plugin: 'dokebi-template-inertia', process: 'template-build' });
|
|
21
21
|
}
|
package/dist/vite-dev.js
CHANGED
|
@@ -23,7 +23,7 @@ import { DependencyCache } from './vite-deps.js';
|
|
|
23
23
|
import { ViteRequestErrors } from './vite-dev-errors.js';
|
|
24
24
|
import { DEV_CLIENT_HEADER, dokebiDevFiles } from './vite-files.js';
|
|
25
25
|
import { NotLoadedReporter } from './vite-not-loaded.js';
|
|
26
|
-
import { vueTypeBarrels } from './vite-type-barrels.js';
|
|
26
|
+
import { TypeFileUpdates, vueTypeBarrels } from './vite-type-barrels.js';
|
|
27
27
|
import { ServedFiles, staleEventFilter } from './vite-watch.js';
|
|
28
28
|
import { registerVueTypeScript } from './vue-typescript.js';
|
|
29
29
|
const { describeError } = diagnostics;
|
|
@@ -49,6 +49,11 @@ const HOST_PATH = '/__dokebi/vite-host';
|
|
|
49
49
|
const SSR_PATH = `${HOST_PATH}/ssr`;
|
|
50
50
|
/** Largest server-render request (the page JSON) the host reads. */
|
|
51
51
|
const SSR_BODY_MAX_BYTES = 32 * 1024 * 1024;
|
|
52
|
+
/**
|
|
53
|
+
* D-0295: the longest a request waits for Vite to handle the type files a comparison found
|
|
54
|
+
* changed (clearing type caches takes milliseconds; Vite handles none for `server.hmr: false`).
|
|
55
|
+
*/
|
|
56
|
+
const TYPE_SETTLE_MS = 2000;
|
|
52
57
|
/** Loopback addresses of the host (a browser resolves `*.localhost` to either); never all. */
|
|
53
58
|
const LOOPBACK_HOSTS = ['127.0.0.1', '::1'];
|
|
54
59
|
/** Tries for a port that is free on both loopback addresses. */
|
|
@@ -265,6 +270,69 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
265
270
|
sendJson(response, 500, { error: errorJson(error) });
|
|
266
271
|
}
|
|
267
272
|
};
|
|
273
|
+
/** Hands a request to Vite's middlewares, explaining what Vite answers nothing for. */
|
|
274
|
+
const serve = (request, response, server, cache) => {
|
|
275
|
+
// Vite answers 504 for a pre-bundled file it cannot serve: if the folder changed under it,
|
|
276
|
+
// re-optimize so the next page load gets files that exist (D-0128).
|
|
277
|
+
if (cache)
|
|
278
|
+
response.once('finish', () => {
|
|
279
|
+
if (response.statusCode === 504)
|
|
280
|
+
void cache.ensure('outdated').catch(report('deps'));
|
|
281
|
+
});
|
|
282
|
+
const url = String(request.url ?? '/');
|
|
283
|
+
const reporter = notLoaded;
|
|
284
|
+
if (reporter)
|
|
285
|
+
response.once('finish', () => reporter.served(url, request.method, response.statusCode));
|
|
286
|
+
server.middlewares(request, response, (error) => {
|
|
287
|
+
// D-0292: an error Vite's error middleware dropped (a module that does not compile)
|
|
288
|
+
// answers 500 with it, not an empty 404.
|
|
289
|
+
const failed = failures.take(request);
|
|
290
|
+
if ((error === undefined || error === null) && failed !== undefined && failed !== null) {
|
|
291
|
+
failures.answer(request, response, failed, url);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
// D-0292: a module URL Vite answers nothing for (it drops ERR_LOAD_URL) is explained, and
|
|
295
|
+
// run through Vite once more when the file is there and allowed.
|
|
296
|
+
const subject = reporter && (error === undefined || error === null) && !response.headersSent
|
|
297
|
+
? reporter.subject(url, request.method, request.headers)
|
|
298
|
+
: undefined;
|
|
299
|
+
if (!reporter || !subject) {
|
|
300
|
+
viteFallthrough(response, error, report('vite'));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
void (async () => {
|
|
304
|
+
const diagnosis = await reporter.diagnose(subject);
|
|
305
|
+
if (!diagnosis.retry || response.headersSent) {
|
|
306
|
+
viteFallthrough(response, undefined, report('vite'));
|
|
307
|
+
reporter.report(diagnosis, response.statusCode);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
await reporter.refresh(subject, diagnosis);
|
|
311
|
+
request.url = url;
|
|
312
|
+
response.once('finish', () => reporter.report(diagnosis, response.statusCode));
|
|
313
|
+
server.middlewares(request, response, (again) => {
|
|
314
|
+
const failedAgain = failures.take(request);
|
|
315
|
+
if ((again === undefined || again === null) &&
|
|
316
|
+
failedAgain !== undefined &&
|
|
317
|
+
failedAgain !== null)
|
|
318
|
+
failures.answer(request, response, failedAgain, url);
|
|
319
|
+
else
|
|
320
|
+
viteFallthrough(response, again, report('vite'));
|
|
321
|
+
});
|
|
322
|
+
})().catch((failure) => {
|
|
323
|
+
report('not-loaded')(failure);
|
|
324
|
+
viteFallthrough(response, undefined, report('vite'));
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
// D-0295: a request that asked for the comparison goes on once Vite handled the type files it
|
|
329
|
+
// found changed (their caches cleared, the pages compiled with them invalidated).
|
|
330
|
+
const settle = (found) => {
|
|
331
|
+
const types = found.files.filter((file) => served.has(file, 'types'));
|
|
332
|
+
if (types.length === 0 || started?.config.server.hmr === false)
|
|
333
|
+
return Promise.resolve();
|
|
334
|
+
return typeUpdates.settled(types, TYPE_SETTLE_MS);
|
|
335
|
+
};
|
|
268
336
|
const endpoint = await openLoopback(logger, (request, response) => {
|
|
269
337
|
if (!keyMatches(expected, request.headers[VITE_HOST_KEY_HEADER])) {
|
|
270
338
|
if (logger.isEnabled('debug'))
|
|
@@ -291,10 +359,12 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
291
359
|
if (path === HOST_PATH && !browser) {
|
|
292
360
|
// D-0283: files changed under Vite that the watcher has not reported (a `git pull` that
|
|
293
361
|
// restarted the app) are read again before the app's pages are served.
|
|
294
|
-
served.sweep('client');
|
|
362
|
+
const changed = settle(served.sweep('client'));
|
|
295
363
|
// An app process connects (it started or restarted): it is answered once the pre-bundled
|
|
296
364
|
// dependencies match what Vite serves, so its pages get hashes that load (D-0128).
|
|
297
|
-
void
|
|
365
|
+
void changed
|
|
366
|
+
.then(() => (cache ? cache.ensure('client').catch(report('deps')) : undefined))
|
|
367
|
+
.then(() => sendJson(response, 200, {
|
|
298
368
|
root,
|
|
299
369
|
pid: process.pid,
|
|
300
370
|
// D-0249: where Vite's client sends the HMR socket, when not to the page's origin.
|
|
@@ -303,71 +373,21 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
303
373
|
}
|
|
304
374
|
else if (path === SSR_PATH && request.method === 'POST' && !browser) {
|
|
305
375
|
// D-0283: the server render reads the files as they are on disk.
|
|
306
|
-
|
|
307
|
-
void ssr(request, response, server);
|
|
376
|
+
// D-0295: after Vite handled a changed type file, so the pages get the new props.
|
|
377
|
+
void settle(served.sweep('ssr')).then(() => ssr(request, response, server));
|
|
308
378
|
}
|
|
309
|
-
else {
|
|
379
|
+
else if (browser && path === `${server.config.base}@vite/client`) {
|
|
310
380
|
// D-0283: a page loads Vite's client first; its modules then come as they are on disk.
|
|
311
|
-
|
|
312
|
-
served.sweep('page');
|
|
313
|
-
// Vite answers 504 for a pre-bundled file it cannot serve: if the folder changed under it,
|
|
314
|
-
// re-optimize so the next page load gets files that exist (D-0128).
|
|
315
|
-
if (cache)
|
|
316
|
-
response.once('finish', () => {
|
|
317
|
-
if (response.statusCode === 504)
|
|
318
|
-
void cache.ensure('outdated').catch(report('deps'));
|
|
319
|
-
});
|
|
320
|
-
const url = String(request.url ?? '/');
|
|
321
|
-
const reporter = notLoaded;
|
|
322
|
-
if (reporter)
|
|
323
|
-
response.once('finish', () => reporter.served(url, request.method, response.statusCode));
|
|
324
|
-
server.middlewares(request, response, (error) => {
|
|
325
|
-
// D-0292: an error Vite's error middleware dropped (a module that does not compile)
|
|
326
|
-
// answers 500 with it, not an empty 404.
|
|
327
|
-
const failed = failures.take(request);
|
|
328
|
-
if ((error === undefined || error === null) && failed !== undefined && failed !== null) {
|
|
329
|
-
failures.answer(request, response, failed, url);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
// D-0292: a module URL Vite answers nothing for (it drops ERR_LOAD_URL) is explained, and
|
|
333
|
-
// run through Vite once more when the file is there and allowed.
|
|
334
|
-
const subject = reporter && (error === undefined || error === null) && !response.headersSent
|
|
335
|
-
? reporter.subject(url, request.method, request.headers)
|
|
336
|
-
: undefined;
|
|
337
|
-
if (!reporter || !subject) {
|
|
338
|
-
viteFallthrough(response, error, report('vite'));
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
void (async () => {
|
|
342
|
-
const diagnosis = await reporter.diagnose(subject);
|
|
343
|
-
if (!diagnosis.retry || response.headersSent) {
|
|
344
|
-
viteFallthrough(response, undefined, report('vite'));
|
|
345
|
-
reporter.report(diagnosis, response.statusCode);
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
await reporter.refresh(subject, diagnosis);
|
|
349
|
-
request.url = url;
|
|
350
|
-
response.once('finish', () => reporter.report(diagnosis, response.statusCode));
|
|
351
|
-
server.middlewares(request, response, (again) => {
|
|
352
|
-
const failedAgain = failures.take(request);
|
|
353
|
-
if ((again === undefined || again === null) &&
|
|
354
|
-
failedAgain !== undefined &&
|
|
355
|
-
failedAgain !== null)
|
|
356
|
-
failures.answer(request, response, failedAgain, url);
|
|
357
|
-
else
|
|
358
|
-
viteFallthrough(response, again, report('vite'));
|
|
359
|
-
});
|
|
360
|
-
})().catch((failure) => {
|
|
361
|
-
report('not-loaded')(failure);
|
|
362
|
-
viteFallthrough(response, undefined, report('vite'));
|
|
363
|
-
});
|
|
364
|
-
});
|
|
381
|
+
void settle(served.sweep('page')).then(() => serve(request, response, server, cache));
|
|
365
382
|
}
|
|
383
|
+
else
|
|
384
|
+
serve(request, response, server, cache);
|
|
366
385
|
});
|
|
367
386
|
// Events FSEvents still holds from before the start are no edits (D-0045 addendum 4); the same
|
|
368
387
|
// records find the edits the watcher has not reported (D-0283).
|
|
369
388
|
const served = new ServedFiles(logger);
|
|
370
389
|
served.recordConfig(root);
|
|
390
|
+
const typeUpdates = new TypeFileUpdates(logger);
|
|
371
391
|
const failures = new ViteRequestErrors(logger);
|
|
372
392
|
// D-0292: the Vue compiler resolves imported props types through TypeScript's JS API (with
|
|
373
393
|
// TypeScript 7 only @typescript/typescript6 has one). dokebiInertia() registers it; a vite.config
|
|
@@ -386,6 +406,8 @@ export async function startViteHost(logger, root = process.cwd(), settings = {})
|
|
|
386
406
|
// D-0292: the type files the Vue compiler reads join the comparison with the disk, so an
|
|
387
407
|
// edit the watcher misses reaches the pages like one of a module Vite loads.
|
|
388
408
|
vueTypeBarrels(logger, root, { onTypeFile: (file) => served.record(file, 'types') }),
|
|
409
|
+
// D-0295: after plugin-vue, so a request can wait until Vite handled a changed type file.
|
|
410
|
+
typeUpdates.plugin(),
|
|
389
411
|
],
|
|
390
412
|
server: {
|
|
391
413
|
middlewareMode: true,
|
|
@@ -7,6 +7,49 @@ export declare class TypeBarrels {
|
|
|
7
7
|
/** A TypeScript file changed or went away: clears the type caches of the files re-exporting it. */
|
|
8
8
|
changed(file: string): Promise<string[]>;
|
|
9
9
|
}
|
|
10
|
+
/** A module graph of Vite's (an environment's, or the one of Vite 5), as far as the waiter uses it. */
|
|
11
|
+
interface FileGraph {
|
|
12
|
+
onFileChange?(file: string): void;
|
|
13
|
+
}
|
|
14
|
+
/** The hot update context Vite gives `handleHotUpdate`, as far as the waiter uses it. */
|
|
15
|
+
interface SettledContext {
|
|
16
|
+
readonly file: string;
|
|
17
|
+
readonly modules: readonly {
|
|
18
|
+
readonly file?: string | null;
|
|
19
|
+
}[];
|
|
20
|
+
readonly server: {
|
|
21
|
+
readonly environments?: Record<string, {
|
|
22
|
+
readonly moduleGraph?: FileGraph;
|
|
23
|
+
}>;
|
|
24
|
+
readonly moduleGraph?: FileGraph;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* D-0295: the host's comparison with the disk (D-0283) hands Vite a changed type file as the
|
|
29
|
+
* watcher's `change`. Vite then clears the type caches (vueTypeBarrels, plugin-vue) and plugin-vue
|
|
30
|
+
* names the pages compiled with that file, but all of that is asynchronous: the request that asked
|
|
31
|
+
* for the comparison (a server render, an app connecting, a page loading Vite's client) went on
|
|
32
|
+
* first, and the server render drew the page with the old props (the type changed, the page did
|
|
33
|
+
* not). `settled(files)` resolves once Vite's hot update of each file has passed plugin-vue (the
|
|
34
|
+
* plugin is `enforce: 'post'`). The pages plugin-vue named are invalidated there in every
|
|
35
|
+
* environment, so the request that waited compiles them again.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TypeFileUpdates {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(logger: Logger);
|
|
40
|
+
/**
|
|
41
|
+
* Resolves true once Vite handled every file, false after `ms` (Vite runs no hot update for a
|
|
42
|
+
* config file or with `server.hmr: false`; the request then goes on as before).
|
|
43
|
+
*/
|
|
44
|
+
settled(files: readonly string[], ms: number): Promise<boolean>;
|
|
45
|
+
/** The Vite plugin: the last `handleHotUpdate` of a file someone waits for. */
|
|
46
|
+
plugin(): {
|
|
47
|
+
name: 'dokebi-inertia:vue-type-settled';
|
|
48
|
+
enforce: 'post';
|
|
49
|
+
apply: 'serve';
|
|
50
|
+
handleHotUpdate(context: SettledContext): void;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
10
53
|
/** The file access @vue/compiler-sfc takes as `script.fs` (what it reads type files through). */
|
|
11
54
|
export interface TypeFileSystem {
|
|
12
55
|
fileExists(file: string): boolean;
|
|
@@ -67,6 +67,13 @@ export class TypeBarrels {
|
|
|
67
67
|
if (!invalidate)
|
|
68
68
|
return [];
|
|
69
69
|
const changed = posix(resolve(file));
|
|
70
|
+
// D-0295: the changed file itself first, before the walk below waits on the disk. A page that
|
|
71
|
+
// compiles during the walk (a server render, another page, other files of the same checkout)
|
|
72
|
+
// rebuilds a barrel just cleared from the cache of the file it re-exports: with that cache still
|
|
73
|
+
// old, the barrel kept the old types for good, also after plugin-vue cleared the file (shop dev,
|
|
74
|
+
// 2026-11-30, after a `git merge --ff` of 45 files). Each barrel is cleared after what it
|
|
75
|
+
// re-exports, so one rebuilt in between reads the new types.
|
|
76
|
+
invalidate(changed);
|
|
70
77
|
const cleared = [];
|
|
71
78
|
const seen = new Set([changed]);
|
|
72
79
|
const queue = [changed];
|
|
@@ -144,6 +151,109 @@ export class TypeBarrels {
|
|
|
144
151
|
return found;
|
|
145
152
|
}
|
|
146
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* D-0295: the host's comparison with the disk (D-0283) hands Vite a changed type file as the
|
|
156
|
+
* watcher's `change`. Vite then clears the type caches (vueTypeBarrels, plugin-vue) and plugin-vue
|
|
157
|
+
* names the pages compiled with that file, but all of that is asynchronous: the request that asked
|
|
158
|
+
* for the comparison (a server render, an app connecting, a page loading Vite's client) went on
|
|
159
|
+
* first, and the server render drew the page with the old props (the type changed, the page did
|
|
160
|
+
* not). `settled(files)` resolves once Vite's hot update of each file has passed plugin-vue (the
|
|
161
|
+
* plugin is `enforce: 'post'`). The pages plugin-vue named are invalidated there in every
|
|
162
|
+
* environment, so the request that waited compiles them again.
|
|
163
|
+
*/
|
|
164
|
+
export class TypeFileUpdates {
|
|
165
|
+
#logger;
|
|
166
|
+
#waiting = new Map();
|
|
167
|
+
constructor(logger) {
|
|
168
|
+
this.#logger = logger;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Resolves true once Vite handled every file, false after `ms` (Vite runs no hot update for a
|
|
172
|
+
* config file or with `server.hmr: false`; the request then goes on as before).
|
|
173
|
+
*/
|
|
174
|
+
settled(files, ms) {
|
|
175
|
+
const keys = [...new Set(files.map((file) => posix(resolve(file))))];
|
|
176
|
+
if (keys.length === 0)
|
|
177
|
+
return Promise.resolve(true);
|
|
178
|
+
const begin = performance.now();
|
|
179
|
+
return new Promise((answer) => {
|
|
180
|
+
let left = keys.length;
|
|
181
|
+
let over = false;
|
|
182
|
+
const entries = [];
|
|
183
|
+
const finish = (handled) => {
|
|
184
|
+
if (over)
|
|
185
|
+
return;
|
|
186
|
+
over = true;
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
for (const [key, done] of entries)
|
|
189
|
+
this.#drop(key, done);
|
|
190
|
+
const fields = { files: keys.length, ms: Math.round(performance.now() - begin) };
|
|
191
|
+
if (!handled)
|
|
192
|
+
this.#logger.log('debug', 'Vite dev host went on before Vite handled every changed type file', { ...fields, left });
|
|
193
|
+
else if (this.#logger.isEnabled('debug'))
|
|
194
|
+
this.#logger.log('debug', 'Vite handled the changed type files before the request', fields);
|
|
195
|
+
answer(handled);
|
|
196
|
+
};
|
|
197
|
+
const timer = setTimeout(() => finish(false), ms);
|
|
198
|
+
for (const key of keys) {
|
|
199
|
+
const done = () => {
|
|
200
|
+
this.#drop(key, done);
|
|
201
|
+
left--;
|
|
202
|
+
if (left === 0)
|
|
203
|
+
finish(true);
|
|
204
|
+
};
|
|
205
|
+
entries.push([key, done]);
|
|
206
|
+
let waiting = this.#waiting.get(key);
|
|
207
|
+
if (!waiting) {
|
|
208
|
+
waiting = new Set();
|
|
209
|
+
this.#waiting.set(key, waiting);
|
|
210
|
+
}
|
|
211
|
+
waiting.add(done);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
#drop(key, done) {
|
|
216
|
+
const waiting = this.#waiting.get(key);
|
|
217
|
+
if (!waiting)
|
|
218
|
+
return;
|
|
219
|
+
waiting.delete(done);
|
|
220
|
+
if (waiting.size === 0)
|
|
221
|
+
this.#waiting.delete(key);
|
|
222
|
+
}
|
|
223
|
+
/** The Vite plugin: the last `handleHotUpdate` of a file someone waits for. */
|
|
224
|
+
plugin() {
|
|
225
|
+
return {
|
|
226
|
+
name: 'dokebi-inertia:vue-type-settled',
|
|
227
|
+
enforce: 'post',
|
|
228
|
+
apply: 'serve',
|
|
229
|
+
handleHotUpdate: (context) => {
|
|
230
|
+
const key = posix(resolve(context.file));
|
|
231
|
+
const waiting = this.#waiting.get(key);
|
|
232
|
+
if (!waiting)
|
|
233
|
+
return;
|
|
234
|
+
// The pages compiled with the file (plugin-vue added them): Vite invalidates them only
|
|
235
|
+
// after every plugin, and the waiting request must not get them as compiled before.
|
|
236
|
+
const graphs = context.server.environments
|
|
237
|
+
? Object.values(context.server.environments).map((environment) => environment.moduleGraph)
|
|
238
|
+
: [context.server.moduleGraph];
|
|
239
|
+
const pages = new Set();
|
|
240
|
+
for (const module of context.modules)
|
|
241
|
+
if (typeof module.file === 'string' && posix(module.file) !== key)
|
|
242
|
+
pages.add(module.file);
|
|
243
|
+
for (const page of pages)
|
|
244
|
+
for (const graph of graphs)
|
|
245
|
+
graph?.onFileChange?.(page);
|
|
246
|
+
if (this.#logger.isEnabled('debug'))
|
|
247
|
+
this.#logger.log('debug', 'Vite handled a changed type file a request waits for', {
|
|
248
|
+
file: key,
|
|
249
|
+
pages: [...pages],
|
|
250
|
+
});
|
|
251
|
+
for (const done of [...waiting])
|
|
252
|
+
done();
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
147
257
|
/** What TypeScript's `ts.sys` gives the compiler, on node:fs (no TypeScript needed). */
|
|
148
258
|
const NODE_FS = {
|
|
149
259
|
fileExists: (file) => statSync(file, { throwIfNoEntry: false })?.isFile() === true,
|
package/dist/vite-watch.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ export declare class ServedFiles {
|
|
|
65
65
|
mode?: string;
|
|
66
66
|
configFileDependencies?: readonly string[];
|
|
67
67
|
}): void;
|
|
68
|
+
/** Whether `file` has a record for `environment` (D-0295: `types`, the files Vue's compiler read). */
|
|
69
|
+
has(file: string, environment: string): boolean;
|
|
68
70
|
/** Whether an event for `file` is no change (dropped); a change updates the records. */
|
|
69
71
|
stale(file: string, event: string): boolean;
|
|
70
72
|
/** The Vite whose module graphs and watcher a sweep uses (Vite's `configureServer`). */
|
package/dist/vite-watch.js
CHANGED
|
@@ -116,6 +116,10 @@ export class ServedFiles {
|
|
|
116
116
|
for (const file of config.configFileDependencies ?? [])
|
|
117
117
|
this.record(file, STARTUP);
|
|
118
118
|
}
|
|
119
|
+
/** Whether `file` has a record for `environment` (D-0295: `types`, the files Vue's compiler read). */
|
|
120
|
+
has(file, environment) {
|
|
121
|
+
return this.#records.get(normal(file))?.has(environment) === true;
|
|
122
|
+
}
|
|
119
123
|
/** Whether an event for `file` is no change (dropped); a change updates the records. */
|
|
120
124
|
stale(file, event) {
|
|
121
125
|
const path = normal(file);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/template-inertia",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.25",
|
|
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",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"@dokebi/session": "0.4.11",
|
|
157
157
|
"@dokebi/web": "0.4.27",
|
|
158
158
|
"@dokebi/websocket": "0.4.10",
|
|
159
|
-
"@dokebi/websocket-hub": "0.4.
|
|
159
|
+
"@dokebi/websocket-hub": "0.4.6",
|
|
160
160
|
"@inertiajs/vue3": "3.9.1",
|
|
161
161
|
"vue": "3.5.44"
|
|
162
162
|
},
|