@dokebi/template-inertia 0.4.29 → 0.4.30
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 +3 -2
- package/dist/index.js +7 -3
- package/dist/template-build.js +1 -1
- package/dist/template-runtime.d.ts +4 -1
- package/dist/template-runtime.js +10 -3
- package/dist/vite-dev.d.ts +1 -0
- package/dist/vite-dev.js +5 -5
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -216,7 +216,7 @@ route.get('/notices/:id', async (request, reply, page) =>
|
|
|
216
216
|
|
|
217
217
|
With `vite`, the manifest (at most `viteManifestMaxBytes`, 4 MiB) is read once in setup, and the files reachable from the entry (static and dynamic chunks, CSS, assets) are served at the exact path `<base><file>` (`cache-control: public, max-age=31536000, immutable`). Each file is read on its first request and kept in memory (files above `assetCacheMaxBytes`, 4 MiB, are streamed per request), so rebuild with new hashed names and restart instead of changing a served file in place. A missing manifest fails the start (`Vite manifest not found: … Build the views first (npm run build).`), and so does a missing entry.
|
|
218
218
|
|
|
219
|
-
**Rolling deploys (two builds at once).** During `rollingRestart` (or any deploy that replaces workers one by one) old and new workers answer side by side: a page of the new build loads its chunks from workers that read the old manifest, and the other way round. So every worker also serves **the other files of the folders its manifest's files sit in** (`<base>assets/*` for Vite's default `assets/`), streamed from disk: regular files only, inside that folder (no `..`, no hidden name, no symbolic link out of it), never a source map (`*.map`: the manifest names none, and `build.sourcemap: 'hidden'` writes them there for error tracking only); a content-hashed name (`app-3fa8c1d2.js`) gets the immutable header, any other `no-cache`; a name that is not there is 404. The manifest, `.vite/`, `dist/ssr/` and files directly in `outDir` are never served. For this to work the deploy must **keep the chunks of the previous build**: build with `build.emptyOutDir: false` (Vite's default `true` deletes them, and pages of the old build then miss their chunks on every worker). Remove the old chunks with `pruneBuildFiles` of `@dokebi/template-inertia/prune`, after a deploy or daily, on every host that has its own `dist/`: `node -e "import('@dokebi/template-inertia/prune').then(async (m) => console.log(await m.pruneBuildFiles({ manifest: 'dist/.vite/manifest.json' })))"` (also as a `prune:build` script in package.json). The current manifest decides, not the age alone: every file it names (and the source map of one) stays however old it is; a content-hashed file of the manifest's folders that it does not name goes once it is unchanged for `olderThanMs` (default 7 days, the time a page of an earlier build may stay open; 0 removes them all). Unhashed names (`robots.txt`), hidden names, links and the files directly in `outDir` (`.vite/`, `dist/ssr/`) are never touched. A manifest that is missing (`VITE_MANIFEST_MISSING`), not an object of chunks, larger than `maxManifestBytes` (4 MiB) or naming no file (`VITE_MANIFEST_INVALID`) removes nothing. `dryRun: true` lists what would go; the result is `{ folders, removed, kept }`. Do not use an age-only cleanup such as `find dist/assets -type f -mtime +7 -delete`: when no deploy comes for a week it removes the current build's files too (a page then misses its chunks: 404). Server rendering stays on the manifest and bundle a worker read at start: an old worker renders the old build until it is replaced. Its SSR bundle may still import chunks of its own lazily (a dynamic `import()`, a non-eager `import.meta.glob`) at its first render of a page, so build the SSR side with `emptyOutDir: false` too; an emptied `dist/ssr/` makes that render fail (`INERTIA_SSR_FAILED`, the client-rendered fallback). Debug logs: `Vite build folder served` (url, folder), per request `Vite built file served from its folder`.
|
|
219
|
+
**Rolling deploys (two builds at once).** During `rollingRestart` (or any deploy that replaces workers one by one) old and new workers answer side by side: a page of the new build loads its chunks from workers that read the old manifest, and the other way round. So every worker also serves **the other files of the folders its manifest's files sit in** (`<base>assets/*` for Vite's default `assets/`), streamed from disk: regular files only, inside that folder (no `..`, no hidden name, no symbolic link out of it), never a source map (`*.map`: the manifest names none, and `build.sourcemap: 'hidden'` writes them there for error tracking only); a content-hashed name (`app-3fa8c1d2.js`) gets the immutable header, any other `no-cache`; a name that is not there is web's 404 with `Cache-Control: no-store` (0.4.30, [D-0302](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0302-missing-files-never-cached.md)), so a CDN or the browser never keeps the miss of a chunk a worker of the other build has: the next try gets it. The manifest, `.vite/`, `dist/ssr/` and files directly in `outDir` are never served. For this to work the deploy must **keep the chunks of the previous build**: build with `build.emptyOutDir: false` (Vite's default `true` deletes them, and pages of the old build then miss their chunks on every worker). Remove the old chunks with `pruneBuildFiles` of `@dokebi/template-inertia/prune`, after a deploy or daily, on every host that has its own `dist/`: `node -e "import('@dokebi/template-inertia/prune').then(async (m) => console.log(await m.pruneBuildFiles({ manifest: 'dist/.vite/manifest.json' })))"` (also as a `prune:build` script in package.json). The current manifest decides, not the age alone: every file it names (and the source map of one) stays however old it is; a content-hashed file of the manifest's folders that it does not name goes once it is unchanged for `olderThanMs` (default 7 days, the time a page of an earlier build may stay open; 0 removes them all). Unhashed names (`robots.txt`), hidden names, links and the files directly in `outDir` (`.vite/`, `dist/ssr/`) are never touched. A manifest that is missing (`VITE_MANIFEST_MISSING`), not an object of chunks, larger than `maxManifestBytes` (4 MiB) or naming no file (`VITE_MANIFEST_INVALID`) removes nothing. `dryRun: true` lists what would go; the result is `{ folders, removed, kept }`. Do not use an age-only cleanup such as `find dist/assets -type f -mtime +7 -delete`: when no deploy comes for a week it removes the current build's files too (a page then misses its chunks: 404). Server rendering stays on the manifest and bundle a worker read at start: an old worker renders the old build until it is replaced. Its SSR bundle may still import chunks of its own lazily (a dynamic `import()`, a non-eager `import.meta.glob`) at its first render of a page, so build the SSR side with `emptyOutDir: false` too; an emptied `dist/ssr/` makes that render fail (`INERTIA_SSR_FAILED`, the client-rendered fallback). Debug logs: `Vite build folder served` (url, folder), per request `Vite built file served from its folder`.
|
|
220
220
|
|
|
221
221
|
### 4.1 The Vite plugin (`@dokebi/template-inertia/vite`, D-0062 addendum 2026-10-20)
|
|
222
222
|
|
|
@@ -295,7 +295,7 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
295
295
|
}
|
|
296
296
|
```
|
|
297
297
|
A refused page answers with the app's page; a refused bundle leaves the template to the app. It may take `templateVerifyTimeoutMs`. **In production (`NODE_ENV=production`) a bundle without `verifyTemplate` is not used** (error `INERTIA_TEMPLATE_UNVERIFIED`): its server modules run in the app's process. In development it is used with a warning.
|
|
298
|
-
- **The first HTML** of such a host carries an import map (with the CSP nonce) from the shared modules to the app build's files of them, so the bundle's `import 'vue'` is the app's vue in the browser too; the bundle's page table (`<script type="application/json" id="dokebi-template">`); the stylesheets and `modulepreload` links of the layout and the page. The bundle's browser files are served at `/_dokebi/templates/<app>/<template>/<buildId>/…` (immutable; the `templateKeep` generations). No CSP change is needed for the bundle itself: same origin (`'self'`), and the bundle's modules are imported by the app's own trusted script (`'strict-dynamic'`).
|
|
298
|
+
- **The first HTML** of such a host carries an import map (with the CSP nonce) from the shared modules to the app build's files of them, so the bundle's `import 'vue'` is the app's vue in the browser too; the bundle's page table (`<script type="application/json" id="dokebi-template">`); the stylesheets and `modulepreload` links of the layout and the page. The bundle's browser files are served at `/_dokebi/templates/<app>/<template>/<buildId>/…` (immutable; the `templateKeep` generations); any other path there is web's 404 with `Cache-Control: no-store` (0.4.30, D-0302). No CSP change is needed for the bundle itself: same origin (`'self'`), and the bundle's modules are imported by the app's own trusted script (`'strict-dynamic'`).
|
|
299
299
|
- **Other origins a template uses (0.4.27, D-0297, web 0.4.28):** a template folder's **`csp.json`** declares them: `{ "connect-src": ["https://api.widget.example"], "font-src": ["https://fonts.example"], "frame-src": ["https://player.example"] }`. Directives: `script-src`, `style-src`, `connect-src`, `font-src`, `img-src`, `frame-src`; at most 32 sources each; each an `https://` origin (host with an optional `*.` in front, optional port and path; `wss://` in `connect-src`) — no keyword, nonce, bare scheme (`https:`, `data:`), `*` or `http://`. `template build` checks it (`INVALID_TEMPLATE_BUILD`; not JSON: `TEMPLATE_BUILD_FAILED`) and writes it, sorted, into the manifest as `csp` (covered by the signature; `template build` and `template check` show it). When the app loads the bundle, `verifyTemplate` sees `bundle.manifest.csp` and may answer `{ accept: true, csp: { … } }`: only the declared sources it lists are used (the rest: warn `INERTIA_TEMPLATE_CSP_REFUSED` with `refused`); without `csp` in the answer (and in development without `verifyTemplate`) every declared source is used. The first HTML of a host whose template has that bundle gets them added to its `Content-Security-Policy` (`web.addCsp`); other hosts and Inertia visits (JSON) do not change, and a new bundle changes them with no restart (its 409 reloads open pages). `templateState` gives `csp` (what is used) and `cspRefused`; `INERTIA_TEMPLATE_LOADED` has `csp`. Under a nonce policy browsers ignore host sources in `script-src` beside `'strict-dynamic'`; a script the page's code loads runs anyway, so declare `script-src` for apps without a nonce. With a web before 0.4.28 the sources are not used (warn `INERTIA_TEMPLATE_CSP_UNSUPPORTED`). Apps before 0.4.27 ignore `csp`.
|
|
300
300
|
- **Asset version:** `<the app's version>+<template>@<buildId>`. A new bundle changes it, so an open page reloads at its next visit (409).
|
|
301
301
|
- **Server rendering** uses the same generation (an AsyncLocalStorage store; `templatePages()` reads it through a global registry, no imports). The bundle's server modules import the shared modules through a resolve hook that answers only importers inside the cache folder: the app build's server entries of them, the same instances as the app's own pages.
|
|
@@ -357,6 +357,7 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
357
357
|
- **A template declares the other origins it uses (0.4.27, [D-0297](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0297-template-csp-sources.md), web 0.4.28)**: the template folder's `csp.json` goes into the bundle's manifest; the app's `verifyTemplate` may narrow it; the first HTML drawn with the bundle adds those sources to its Content-Security-Policy, and only that host's pages do. `template preview --csp <app setting>` draws the pages under the same policy and lists what it blocks (§4.3).
|
|
358
358
|
- **The template's look is in the first HTML; a template may have no page (0.4.27, [D-0298](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0298-template-styles-and-pageless-bundles.md))**: `dokebi template build --style theme.css` lists the template's stylesheets in the manifest (`styles`), and the app links them, in order and with the nonce, in the head of every first HTML of that template, where a template's stylesheet used to arrive after the first paint. A folder of stylesheets and carried files alone builds into a bundle without pages (§4.3).
|
|
359
359
|
- **The preview follows the folder's pages (0.4.27, [D-0299](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0299-preview-follows-pages.md))**: a page added or removed while `dokebi template preview` runs is listed and drawn at once (the open pages reload), where the preview fixed its pages at start; it also starts without any page.
|
|
360
|
+
- **A missing file is never cached (0.4.30, [D-0302](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0302-missing-files-never-cached.md))**: the 404 of the build folder route (`<base>assets/*`) and of the bundle route (`/_dokebi/templates/…`) is web's 404 with `Cache-Control: no-store` (it was `{ error: 'NOT_FOUND' }` without the header, and a CDN kept it: during a rolling deploy a page waited on a chunk the edge remembered as missing, for up to 4 hours). The dev Vite fallthrough's 404 and 500 carry `no-store` too.
|
|
360
361
|
- **The preview checks the template's words as the app does (0.4.29, [D-0301](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0301-preview-checks-template-words.md))**: `template preview --words <app catalogs>` refuses words the app would refuse (a key the app does not have in that language, other placeholders), naming every line, and `--missing error` draws with the app's missing policy; a template that GAON's app refused (PageI18nError) passed the preview before. A page request that failed in the preview (a broken `<Page>.preview.json`) now answers 500 instead of no answer (§4.3).
|
|
361
362
|
- **The preview offers every language (0.4.28, [D-0300](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0300-preview-languages.md))**: `template preview --locales ko,en --locale ko [--words <app catalogs>]`: the app's language buttons show in the preview and switch the page, where the preview sent one language without the switch's settings (§4.3).
|
|
362
363
|
- **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.
|
package/dist/index.js
CHANGED
|
@@ -984,8 +984,12 @@ class InertiaRuntime {
|
|
|
984
984
|
config: publicAsset(routeIds, 'assets'),
|
|
985
985
|
handler: async (request, reply) => {
|
|
986
986
|
const file = await builtFolderFile(folder, request.params['*']);
|
|
987
|
-
|
|
988
|
-
|
|
987
|
+
// D-0302: web's 404 (Cache-Control: no-store): a chunk of a build this worker has not
|
|
988
|
+
// yet (a rolling deploy) must not be kept by a CDN or the browser.
|
|
989
|
+
if (!file) {
|
|
990
|
+
reply.callNotFound();
|
|
991
|
+
return reply;
|
|
992
|
+
}
|
|
989
993
|
if (logger.isEnabled('debug'))
|
|
990
994
|
logger.log('debug', 'Vite built file served from its folder', {
|
|
991
995
|
url: request.url.split('?', 1)[0]?.slice(0, 200),
|
|
@@ -1248,7 +1252,7 @@ class InertiaRuntime {
|
|
|
1248
1252
|
}
|
|
1249
1253
|
export const createPlugin = definePlugin({
|
|
1250
1254
|
name: 'dokebi-template-inertia',
|
|
1251
|
-
version: '0.4.
|
|
1255
|
+
version: '0.4.30',
|
|
1252
1256
|
core: '^0.4.2',
|
|
1253
1257
|
options,
|
|
1254
1258
|
entry: parseEntry,
|
package/dist/template-build.js
CHANGED
|
@@ -15,7 +15,7 @@ import { checkTemplateBundle, cspDeclarationProblem, jsonValue, PAGE_META_MAX_BY
|
|
|
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.30' };
|
|
19
19
|
/** D-0296: carried files go under this folder of the bundle (served like the pages' files). */
|
|
20
20
|
export const TEMPLATE_CARRY_FOLDER = 'browser';
|
|
21
21
|
/** The folders Vite writes under browser/: a carried file never takes them (any case). */
|
|
@@ -236,7 +236,10 @@ export declare class TemplateBundles {
|
|
|
236
236
|
current(app: string, template: string | undefined): TemplateGeneration | undefined;
|
|
237
237
|
/** The use of one request: undefined when its template has no bundle. */
|
|
238
238
|
use(app: string, template: string | undefined, baseVersion: string): TemplateUse | undefined;
|
|
239
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* `GET /_dokebi/templates/<app>/<template>/<buildId>/browser/…` of a kept generation. Anything
|
|
241
|
+
* else is web's 404 (D-0302: `Cache-Control: no-store`, so a CDN or browser never keeps it).
|
|
242
|
+
*/
|
|
240
243
|
serve(path: string, reply: FastifyReply): Promise<FastifyReply>;
|
|
241
244
|
/** For tests and describe: the loaded generations. */
|
|
242
245
|
generations(): ReadonlyArray<{
|
package/dist/template-runtime.js
CHANGED
|
@@ -923,8 +923,15 @@ export class TemplateBundles {
|
|
|
923
923
|
},
|
|
924
924
|
};
|
|
925
925
|
}
|
|
926
|
-
/**
|
|
926
|
+
/**
|
|
927
|
+
* `GET /_dokebi/templates/<app>/<template>/<buildId>/browser/…` of a kept generation. Anything
|
|
928
|
+
* else is web's 404 (D-0302: `Cache-Control: no-store`, so a CDN or browser never keeps it).
|
|
929
|
+
*/
|
|
927
930
|
async serve(path, reply) {
|
|
931
|
+
const notFound = () => {
|
|
932
|
+
reply.callNotFound();
|
|
933
|
+
return reply;
|
|
934
|
+
};
|
|
928
935
|
const parts = path.split('/');
|
|
929
936
|
const [app, template, buildId, ...rest] = parts;
|
|
930
937
|
const file = rest.join('/');
|
|
@@ -933,10 +940,10 @@ export class TemplateBundles {
|
|
|
933
940
|
if (!generation ||
|
|
934
941
|
!file.startsWith('browser/') ||
|
|
935
942
|
!Object.hasOwn(generation.manifest.files, file))
|
|
936
|
-
return
|
|
943
|
+
return notFound();
|
|
937
944
|
const absolute = join(generation.dir, ...file.split('/'));
|
|
938
945
|
if (!absolute.startsWith(generation.dir + sep) || isAbsolute(file))
|
|
939
|
-
return
|
|
946
|
+
return notFound();
|
|
940
947
|
return reply
|
|
941
948
|
.type(CONTENT_TYPES[extname(file).toLowerCase()] ?? 'application/octet-stream')
|
|
942
949
|
.header('cache-control', 'public, max-age=31536000, immutable')
|
package/dist/vite-dev.d.ts
CHANGED
package/dist/vite-dev.js
CHANGED
|
@@ -33,13 +33,13 @@ export const viteDevRequested = () => process.env.DOKEBI_VITE_DEV === '1';
|
|
|
33
33
|
* reported (logged by the caller) and answered 500, never dropped (D-0047).
|
|
34
34
|
*/
|
|
35
35
|
export function viteFallthrough(response, error, report) {
|
|
36
|
-
if (error !== undefined && error !== null)
|
|
36
|
+
if (error !== undefined && error !== null)
|
|
37
37
|
report(error);
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (!response.headersSent) {
|
|
39
|
+
response.statusCode = error !== undefined && error !== null ? 500 : 404;
|
|
40
|
+
// D-0302: never kept by a CDN in front of a dev tunnel, or by the browser.
|
|
41
|
+
response.setHeader('cache-control', 'no-store');
|
|
40
42
|
}
|
|
41
|
-
else if (!response.headersSent)
|
|
42
|
-
response.statusCode = 404;
|
|
43
43
|
response.end();
|
|
44
44
|
}
|
|
45
45
|
/** Header that carries the host key; the host answers no HTTP request without it. */
|
package/package.json
CHANGED