@dokebi/template-inertia 0.4.18 → 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 CHANGED
@@ -266,6 +266,7 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
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
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).
269
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.
270
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`).
271
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
@@ -1107,7 +1107,7 @@ class InertiaRuntime {
1107
1107
  }
1108
1108
  export const createPlugin = definePlugin({
1109
1109
  name: 'dokebi-template-inertia',
1110
- version: '0.4.18',
1110
+ version: '0.4.19',
1111
1111
  core: '^0.4.2',
1112
1112
  options,
1113
1113
  entry: parseEntry,
@@ -2,6 +2,7 @@
2
2
  export type ModulePagesAnswer = {
3
3
  readonly kind: 'sources';
4
4
  readonly sources: unknown;
5
+ readonly files?: readonly string[];
5
6
  } | {
6
7
  readonly kind: 'unsupported';
7
8
  } | {
@@ -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
- return { kind: 'sources', sources: list() };
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) };
@@ -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 {};
@@ -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.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
  }
@@ -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
@@ -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();
@@ -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
- /** Records the config files of `root` before Vite reads them. */
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`). */
@@ -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
- /** Records the config files of `root` before Vite reads them. */
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.18",
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",