@dokebi/template-inertia 0.4.18 → 0.4.20
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 +22 -0
- package/README.md +4 -0
- package/dist/dev-rescan.d.ts +12 -0
- package/dist/dev-rescan.js +28 -0
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +3 -0
- package/dist/index.js +1 -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/template-build.d.ts +43 -0
- package/dist/template-build.js +335 -0
- package/dist/template-bundle.d.ts +102 -0
- package/dist/template-bundle.js +344 -0
- package/dist/template-shared.d.ts +93 -0
- package/dist/template-shared.js +197 -0
- package/dist/template.d.ts +3 -0
- package/dist/template.js +5 -0
- package/dist/vite-dev.js +15 -0
- package/dist/vite-plugin.d.ts +22 -2
- package/dist/vite-plugin.js +28 -0
- package/dist/vite-watch.d.ts +20 -1
- package/dist/vite-watch.js +31 -2
- package/package.json +6 -2
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
|
}
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type Logger } from '@dokebi/core';
|
|
2
2
|
import { type PagesDevServer } from './module-pages.js';
|
|
3
|
+
import { type DokebiInertiaTemplateOptions, type InputOptionsShape } from './template-shared.js';
|
|
3
4
|
import { type DevFilesOptions, type DevFilesPatch, type DevMiddleware, type ResolvedFilesShape } from './vite-files.js';
|
|
4
5
|
export { MODULE_PAGES_ID } from './module-pages.js';
|
|
6
|
+
export { type DokebiInertiaTemplateOptions, SHARED_FILE, type SharedFile, } from './template-shared.js';
|
|
5
7
|
export { DEV_FILES_DENY, type DevFilesOptions, type DokebiDevFilesPlugin, dokebiDevFiles, } from './vite-files.js';
|
|
6
8
|
/** Specifier → the URL the app serves it at (@dokebi/seal, `GET /dokebi/seal/*`). */
|
|
7
9
|
export declare const SERVED_MODULES: Readonly<Record<string, string>>;
|
|
@@ -13,9 +15,21 @@ export interface DokebiInertiaViteOptions extends DevFilesOptions {
|
|
|
13
15
|
* `DOKEBI_LOG_LEVEL` (`info` when unset), the level `dokebi dev` passes to its processes.
|
|
14
16
|
*/
|
|
15
17
|
readonly logger?: Logger;
|
|
18
|
+
/**
|
|
19
|
+
* D-0291: provide the shared modules of template bundles (vue, @inertiajs/vue3,
|
|
20
|
+
* @dokebi/template-inertia/{i18n,pages} and `shared`, the app's SDK) as entries of this build,
|
|
21
|
+
* listed in `<outDir>/.vite/dokebi-shared.json`. Give the same value in the browser and the
|
|
22
|
+
* server vite config. Without it the build is as before.
|
|
23
|
+
*/
|
|
24
|
+
readonly templates?: DokebiInertiaTemplateOptions;
|
|
16
25
|
}
|
|
17
26
|
/** The part of Vite's resolved config this plugin reads. */
|
|
18
|
-
type ResolvedConfigShape = ResolvedFilesShape
|
|
27
|
+
type ResolvedConfigShape = ResolvedFilesShape & {
|
|
28
|
+
readonly build?: {
|
|
29
|
+
readonly ssr?: unknown;
|
|
30
|
+
readonly outDir?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
19
33
|
/** The part of Vite's dev server this plugin uses (connect middlewares). */
|
|
20
34
|
interface DevServerShape extends PagesDevServer {
|
|
21
35
|
readonly middlewares: {
|
|
@@ -60,8 +74,14 @@ export interface DokebiInertiaVitePlugin {
|
|
|
60
74
|
id: string;
|
|
61
75
|
external: true | 'absolute';
|
|
62
76
|
} | string | null;
|
|
63
|
-
load(id: string): string | null | Promise<string | null>;
|
|
77
|
+
load(this: unknown, id: string): string | null | Promise<string | null>;
|
|
78
|
+
/** Rollup's input options (D-0291: the shared entries join the inputs). */
|
|
79
|
+
options(input: InputOptionsShape): InputOptionsShape | null;
|
|
80
|
+
/** D-0291: writes dokebi-shared.json after a build. */
|
|
81
|
+
writeBundle(output: unknown, bundle: Readonly<Record<string, never>>): Promise<void>;
|
|
64
82
|
configureServer(server: DevServerShape): void;
|
|
83
|
+
/** Vite calls it when the dev server closes (or restarts) and after a build. */
|
|
84
|
+
closeBundle(): void;
|
|
65
85
|
}
|
|
66
86
|
/**
|
|
67
87
|
* The plugin for `plugins: [vue(), dokebiInertia()]` of an Inertia app's vite.config.ts: imports
|
package/dist/vite-plugin.js
CHANGED
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
// remote hosts), so an upgrade of this package secures every vite.config that uses it.
|
|
30
30
|
import { ConsoleLogger } from '@dokebi/core';
|
|
31
31
|
import { MODULE_PAGES_ID, ModulePagesSource } from './module-pages.js';
|
|
32
|
+
import { SharedEntries, } from './template-shared.js';
|
|
32
33
|
import { DevFilesPolicy, } from './vite-files.js';
|
|
33
34
|
export { MODULE_PAGES_ID } from './module-pages.js';
|
|
35
|
+
export { SHARED_FILE, } from './template-shared.js';
|
|
34
36
|
export { DEV_FILES_DENY, dokebiDevFiles, } from './vite-files.js';
|
|
35
37
|
/** Specifier → the URL the app serves it at (@dokebi/seal, `GET /dokebi/seal/*`). */
|
|
36
38
|
export const SERVED_MODULES = Object.freeze({
|
|
@@ -92,6 +94,8 @@ export function dokebiInertia(options = {}) {
|
|
|
92
94
|
const dev = new Map(Object.values(SERVED_MODULES).map((served) => [devId(served), served]));
|
|
93
95
|
/** Request path (with and without `base`) → the module text the dev server answers. */
|
|
94
96
|
const answers = new Map();
|
|
97
|
+
// D-0291: the shared modules of template bundles, when the app opts in.
|
|
98
|
+
const shared = options.templates ? new SharedEntries(logger, options.templates) : undefined;
|
|
95
99
|
return {
|
|
96
100
|
name: 'dokebi-inertia',
|
|
97
101
|
enforce: 'pre',
|
|
@@ -111,6 +115,15 @@ export function dokebiInertia(options = {}) {
|
|
|
111
115
|
},
|
|
112
116
|
configResolved(config) {
|
|
113
117
|
files.configResolved(config);
|
|
118
|
+
shared?.configResolved({
|
|
119
|
+
root: config.root ?? process.cwd(),
|
|
120
|
+
command: config.command,
|
|
121
|
+
base: config.base,
|
|
122
|
+
build: {
|
|
123
|
+
ssr: config.build?.ssr,
|
|
124
|
+
outDir: config.build?.outDir ?? 'dist',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
114
127
|
command = config.command;
|
|
115
128
|
pages.command = command;
|
|
116
129
|
base = config.base || '/';
|
|
@@ -126,9 +139,18 @@ export function dokebiInertia(options = {}) {
|
|
|
126
139
|
modules: SERVED_MODULES,
|
|
127
140
|
});
|
|
128
141
|
},
|
|
142
|
+
options(input) {
|
|
143
|
+
return shared ? shared.options(input) : null;
|
|
144
|
+
},
|
|
145
|
+
async writeBundle(_output, bundle) {
|
|
146
|
+
await shared?.writeBundle(bundle);
|
|
147
|
+
},
|
|
129
148
|
resolveId(source, importer, resolveOptions) {
|
|
130
149
|
if (source === MODULE_PAGES_ID)
|
|
131
150
|
return pages.resolve(source, importer);
|
|
151
|
+
const entry = shared?.resolveId(source);
|
|
152
|
+
if (entry)
|
|
153
|
+
return entry;
|
|
132
154
|
const served = SERVED_MODULES[source];
|
|
133
155
|
if (served === undefined)
|
|
134
156
|
return null;
|
|
@@ -148,6 +170,8 @@ export function dokebiInertia(options = {}) {
|
|
|
148
170
|
load(id) {
|
|
149
171
|
if (id.startsWith('\0dokebi-module-pages:'))
|
|
150
172
|
return pages.load(id);
|
|
173
|
+
if (shared && id.startsWith('\0dokebi-shared:'))
|
|
174
|
+
return shared.load(this, id);
|
|
151
175
|
// Vite pre-transforms the imports it sees, the dev re-export too. The middleware below
|
|
152
176
|
// answers its URL before Vite does, so this text only fills Vite's module graph; were it
|
|
153
177
|
// ever served, the page would fail loudly instead of running without the served module.
|
|
@@ -156,6 +180,10 @@ export function dokebiInertia(options = {}) {
|
|
|
156
180
|
return null;
|
|
157
181
|
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
182
|
},
|
|
183
|
+
closeBundle() {
|
|
184
|
+
// D-0289: the module pages' comparison ends with its dev server.
|
|
185
|
+
pages.stop();
|
|
186
|
+
},
|
|
159
187
|
configureServer(server) {
|
|
160
188
|
// D-0129: the file policy judges every request first, before the re-export and Vite.
|
|
161
189
|
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.20",
|
|
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",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/pages.d.ts",
|
|
39
39
|
"import": "./dist/pages.js"
|
|
40
40
|
},
|
|
41
|
+
"./template": {
|
|
42
|
+
"types": "./dist/template.d.ts",
|
|
43
|
+
"default": "./dist/template.js"
|
|
44
|
+
},
|
|
41
45
|
"./module-pages": {
|
|
42
46
|
"types": "./module-pages.d.ts"
|
|
43
47
|
}
|
|
@@ -145,7 +149,7 @@
|
|
|
145
149
|
"devDependencies": {
|
|
146
150
|
"@dokebi/i18n": "0.2.9",
|
|
147
151
|
"@dokebi/session": "0.4.11",
|
|
148
|
-
"@dokebi/web": "0.4.
|
|
152
|
+
"@dokebi/web": "0.4.27",
|
|
149
153
|
"@dokebi/websocket": "0.4.10",
|
|
150
154
|
"@dokebi/websocket-hub": "0.4.5",
|
|
151
155
|
"@inertiajs/vue3": "3.9.1",
|