@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
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// D-0291 §7: `dokebi template build` — builds a template folder (`views/<template>/` shape:
|
|
2
|
+
// Layout.vue, Pages/**/*.vue, the components and styles they import) into a bundle
|
|
3
|
+
// (template-bundle.ts) apart from any app. Runs in the template repository, with the project's own
|
|
4
|
+
// Vite and @vitejs/plugin-vue: one browser build and one server build, an entry per page, the
|
|
5
|
+
// shared modules (vue, @inertiajs/vue3, the app's SDK, …) left as imports, then the manifest with
|
|
6
|
+
// each page's files, stylesheets, preloads and `meta`, and the sha256 of every file. The bundle
|
|
7
|
+
// is checked like the app will check it before it is returned.
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { lstat, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { ConsoleLogger } from '@dokebi/core';
|
|
13
|
+
import { InertiaError, InertiaUsageError } from './errors.js';
|
|
14
|
+
import { checkTemplateBundle, jsonValue, PAGE_META_MAX_BYTES, SHARED_DEFAULTS, SHARED_SPECIFIER, sha256, TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_MAX_BYTES, TEMPLATE_NAME, TEMPLATE_PAGE, TEMPLATE_VERSION, } from './template-bundle.js';
|
|
15
|
+
import { packageVersion } from './template-shared.js';
|
|
16
|
+
/** The builder written into `builtWith` (scripts/testing/check-metadata.mjs keeps it the package version). */
|
|
17
|
+
const BUILDER = { name: 'dokebi-template-inertia', version: '0.4.20' };
|
|
18
|
+
function defaultLogger() {
|
|
19
|
+
return new ConsoleLogger({ level: 'info' }, { plugin: 'dokebi-template-inertia', process: 'template-build' });
|
|
20
|
+
}
|
|
21
|
+
const usage = (message) => new InertiaUsageError('INVALID_TEMPLATE_BUILD', message);
|
|
22
|
+
/** `a` is `b` or inside it. */
|
|
23
|
+
function within(a, b) {
|
|
24
|
+
const path = relative(b, a);
|
|
25
|
+
return path === '' || (!path.startsWith('..') && !isAbsolute(path));
|
|
26
|
+
}
|
|
27
|
+
/** The ESM entry file of an installed package of the project (exports `.` → import/default, else module/main). */
|
|
28
|
+
export function packageEntry(root, name) {
|
|
29
|
+
for (let dir = resolve(root);; dir = dirname(dir)) {
|
|
30
|
+
const folder = join(dir, 'node_modules', name);
|
|
31
|
+
const file = join(folder, 'package.json');
|
|
32
|
+
if (existsSync(file)) {
|
|
33
|
+
const json = JSON.parse(readFileSync(file, 'utf8'));
|
|
34
|
+
const pick = (value) => {
|
|
35
|
+
if (typeof value === 'string')
|
|
36
|
+
return value;
|
|
37
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
38
|
+
return undefined;
|
|
39
|
+
const record = value;
|
|
40
|
+
if ('.' in record)
|
|
41
|
+
return pick(record['.']);
|
|
42
|
+
return pick(record.import) ?? pick(record.default) ?? pick(record.node);
|
|
43
|
+
};
|
|
44
|
+
const entry = pick(json.exports) ?? json.module ?? json.main ?? 'index.js';
|
|
45
|
+
return join(folder, entry);
|
|
46
|
+
}
|
|
47
|
+
if (dirname(dir) === dir)
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function importPackage(root, name, fix) {
|
|
52
|
+
const entry = packageEntry(root, name);
|
|
53
|
+
if (entry === undefined)
|
|
54
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `${name} is not installed in ${root}`, {
|
|
55
|
+
fix,
|
|
56
|
+
});
|
|
57
|
+
return (await import(pathToFileURL(entry).href));
|
|
58
|
+
}
|
|
59
|
+
/** The pages of a template folder: `Layout` and `Pages/<path>` → their .vue file. */
|
|
60
|
+
export async function templatePages(folder) {
|
|
61
|
+
const pages = new Map();
|
|
62
|
+
const layout = join(folder, 'Layout.vue');
|
|
63
|
+
if (existsSync(layout))
|
|
64
|
+
pages.set('Layout', layout);
|
|
65
|
+
const walk = async (dir) => {
|
|
66
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
67
|
+
const path = join(dir, entry.name);
|
|
68
|
+
if (entry.isDirectory())
|
|
69
|
+
await walk(path);
|
|
70
|
+
else if (entry.isFile() && entry.name.endsWith('.vue')) {
|
|
71
|
+
const key = relative(folder, path).split(sep).join('/').slice(0, -'.vue'.length);
|
|
72
|
+
if (!TEMPLATE_PAGE.test(key))
|
|
73
|
+
throw usage(`${relative(folder, path)} is not a page name: Pages/ paths are letters, digits, _, . and - (at most 16 folders deep)`);
|
|
74
|
+
pages.set(key, path);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (existsSync(join(folder, 'Pages')))
|
|
79
|
+
await walk(join(folder, 'Pages'));
|
|
80
|
+
return pages;
|
|
81
|
+
}
|
|
82
|
+
/** Every file under a folder, relative with `/`. */
|
|
83
|
+
async function listFiles(dir, root = dir, found = []) {
|
|
84
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
85
|
+
const path = join(dir, entry.name);
|
|
86
|
+
if (entry.isDirectory())
|
|
87
|
+
await listFiles(path, root, found);
|
|
88
|
+
else if (entry.isFile())
|
|
89
|
+
found.push(relative(root, path).split(sep).join('/'));
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
const outputs = (result) => (Array.isArray(result) ? result : [result]).flatMap((item) => item.output ?? []);
|
|
94
|
+
/**
|
|
95
|
+
* Builds the template folder `options.dir` of `options.root` into a bundle at `options.out`
|
|
96
|
+
* (D-0291). Throws INVALID_TEMPLATE_BUILD for wrong options and TEMPLATE_BUILD_FAILED for a
|
|
97
|
+
* build that fails, with the cause.
|
|
98
|
+
*/
|
|
99
|
+
export async function buildTemplateBundle(options) {
|
|
100
|
+
const begin = performance.now();
|
|
101
|
+
const logger = options.logger ?? defaultLogger();
|
|
102
|
+
const root = resolve(options.root ?? process.cwd());
|
|
103
|
+
if (typeof options.dir !== 'string' || options.dir === '')
|
|
104
|
+
throw usage('dir is required');
|
|
105
|
+
const folder = resolve(root, options.dir);
|
|
106
|
+
if (!within(folder, root) || folder === root)
|
|
107
|
+
throw usage(`${options.dir} must be a folder inside ${root}, not the project itself`);
|
|
108
|
+
if (!existsSync(folder) || !(await stat(folder)).isDirectory())
|
|
109
|
+
throw usage(`${options.dir} is not a folder`);
|
|
110
|
+
const name = options.name ?? basename(folder);
|
|
111
|
+
if (!TEMPLATE_NAME.test(name))
|
|
112
|
+
throw usage(`${name} is not a template name (^[a-z][a-z0-9-]{0,31}$); pass --name`);
|
|
113
|
+
let version = options.version;
|
|
114
|
+
if (version === undefined) {
|
|
115
|
+
try {
|
|
116
|
+
const own = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
117
|
+
if (typeof own.version === 'string')
|
|
118
|
+
version = own.version;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// No readable package.json: --version is needed (the usage error below says so).
|
|
122
|
+
logger.log('debug', 'Template version not read from package.json', {
|
|
123
|
+
root,
|
|
124
|
+
error: error.message,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (version === undefined || !TEMPLATE_VERSION.test(version))
|
|
129
|
+
throw usage(`the template version ${version === undefined ? 'is missing' : `${version} is not letters, digits, . + -`}: pass --version or set version in package.json`);
|
|
130
|
+
const own = options.shared ?? [];
|
|
131
|
+
for (const module of own)
|
|
132
|
+
if (typeof module !== 'string' || !SHARED_SPECIFIER.test(module))
|
|
133
|
+
throw new InertiaUsageError('INVALID_TEMPLATE_SHARED', `--shared ${String(module)} is not a package name with an optional subpath`);
|
|
134
|
+
const shared = [...new Set([...SHARED_DEFAULTS, ...own])];
|
|
135
|
+
const out = resolve(root, options.out ?? join('dist', 'template', name));
|
|
136
|
+
if (!within(out, root) || within(root, out) || within(folder, out) || within(out, folder))
|
|
137
|
+
throw usage(`--out ${relative(root, out) || '.'} must be a folder inside the project, apart from the template folder (the build imports the server pages from there)`);
|
|
138
|
+
if (existsSync(out)) {
|
|
139
|
+
const info = await lstat(out);
|
|
140
|
+
if (!info.isDirectory())
|
|
141
|
+
throw usage(`--out ${out} is not a folder`);
|
|
142
|
+
const present = await readdir(out);
|
|
143
|
+
if (present.length && !present.includes(TEMPLATE_MANIFEST))
|
|
144
|
+
throw usage(`--out ${out} holds files and no ${TEMPLATE_MANIFEST}: it is not an earlier bundle, so it is not emptied`);
|
|
145
|
+
await rm(out, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
const pages = await templatePages(folder);
|
|
148
|
+
if (pages.size === 0)
|
|
149
|
+
throw usage(`${options.dir} has no Layout.vue and no Pages/**/*.vue`);
|
|
150
|
+
const input = Object.fromEntries(pages);
|
|
151
|
+
const vite = await importPackage(root, 'vite', 'Install Vite in the template repository: npm install --save-dev vite');
|
|
152
|
+
const vue = options.config
|
|
153
|
+
? undefined
|
|
154
|
+
: await importPackage(root, '@vitejs/plugin-vue', 'Install the Vue plugin in the template repository: npm install --save-dev @vitejs/plugin-vue');
|
|
155
|
+
const isShared = (id) => shared.includes(id);
|
|
156
|
+
logger.log('info', 'Template bundle build started', {
|
|
157
|
+
code: 'INERTIA_TEMPLATE_BUILD_STARTED',
|
|
158
|
+
name,
|
|
159
|
+
version,
|
|
160
|
+
dir: relative(root, folder),
|
|
161
|
+
out: relative(root, out),
|
|
162
|
+
pages: pages.size,
|
|
163
|
+
shared,
|
|
164
|
+
});
|
|
165
|
+
const common = {
|
|
166
|
+
root,
|
|
167
|
+
configFile: options.config ? resolve(root, options.config) : false,
|
|
168
|
+
logLevel: 'warn',
|
|
169
|
+
publicDir: false,
|
|
170
|
+
plugins: vue ? [vue.default()] : [],
|
|
171
|
+
};
|
|
172
|
+
const imported = new Set();
|
|
173
|
+
const collect = (items) => {
|
|
174
|
+
for (const item of items)
|
|
175
|
+
for (const id of [...(item.imports ?? []), ...(item.dynamicImports ?? [])])
|
|
176
|
+
if (isShared(id))
|
|
177
|
+
imported.add(id);
|
|
178
|
+
};
|
|
179
|
+
let browserItems;
|
|
180
|
+
let serverItems;
|
|
181
|
+
try {
|
|
182
|
+
browserItems = outputs(await vite.build({
|
|
183
|
+
...common,
|
|
184
|
+
base: './',
|
|
185
|
+
build: {
|
|
186
|
+
outDir: join(out, 'browser'),
|
|
187
|
+
emptyOutDir: true,
|
|
188
|
+
manifest: true,
|
|
189
|
+
cssCodeSplit: true,
|
|
190
|
+
modulePreload: false,
|
|
191
|
+
copyPublicDir: false,
|
|
192
|
+
rollupOptions: {
|
|
193
|
+
input,
|
|
194
|
+
external: isShared,
|
|
195
|
+
preserveEntrySignatures: 'strict',
|
|
196
|
+
output: {
|
|
197
|
+
entryFileNames: 'pages/[name]-[hash].js',
|
|
198
|
+
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
199
|
+
assetFileNames: 'assets/[name]-[hash][extname]',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
204
|
+
serverItems = outputs(await vite.build({
|
|
205
|
+
...common,
|
|
206
|
+
ssr: { noExternal: true },
|
|
207
|
+
build: {
|
|
208
|
+
ssr: true,
|
|
209
|
+
outDir: join(out, 'ssr'),
|
|
210
|
+
emptyOutDir: true,
|
|
211
|
+
copyPublicDir: false,
|
|
212
|
+
rollupOptions: {
|
|
213
|
+
input,
|
|
214
|
+
external: isShared,
|
|
215
|
+
preserveEntrySignatures: 'strict',
|
|
216
|
+
output: {
|
|
217
|
+
format: 'es',
|
|
218
|
+
entryFileNames: 'pages/[name].js',
|
|
219
|
+
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
catch (cause) {
|
|
226
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `The Vite build of ${name} failed`, { cause });
|
|
227
|
+
}
|
|
228
|
+
collect(browserItems);
|
|
229
|
+
collect(serverItems);
|
|
230
|
+
// The browser manifest gives each page its stylesheets and the chunks it imports.
|
|
231
|
+
const manifestPath = join(out, 'browser', '.vite', 'manifest.json');
|
|
232
|
+
const vm = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
233
|
+
await rm(join(out, 'browser', '.vite'), { recursive: true, force: true });
|
|
234
|
+
const byName = new Map();
|
|
235
|
+
for (const entry of Object.values(vm))
|
|
236
|
+
if (entry.isEntry && entry.name)
|
|
237
|
+
byName.set(entry.name, entry);
|
|
238
|
+
const server = new Map();
|
|
239
|
+
for (const item of serverItems)
|
|
240
|
+
if (item.type === 'chunk' && item.isEntry && item.name)
|
|
241
|
+
server.set(item.name, item.fileName);
|
|
242
|
+
const pageEntries = {};
|
|
243
|
+
for (const page of pages.keys()) {
|
|
244
|
+
const entry = byName.get(page);
|
|
245
|
+
const ssrFile = server.get(page);
|
|
246
|
+
if (entry === undefined || ssrFile === undefined)
|
|
247
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `The build has no entry for ${page} (browser ${entry ? 'yes' : 'no'}, server ${ssrFile ? 'yes' : 'no'})`);
|
|
248
|
+
const css = [];
|
|
249
|
+
const preload = [];
|
|
250
|
+
const seen = new Set();
|
|
251
|
+
const visit = (key) => {
|
|
252
|
+
if (seen.has(key))
|
|
253
|
+
return;
|
|
254
|
+
seen.add(key);
|
|
255
|
+
const chunk = vm[key];
|
|
256
|
+
if (!chunk)
|
|
257
|
+
return;
|
|
258
|
+
for (const next of chunk.imports ?? [])
|
|
259
|
+
visit(next);
|
|
260
|
+
if (chunk !== entry)
|
|
261
|
+
preload.push(`browser/${chunk.file}`);
|
|
262
|
+
for (const file of chunk.css ?? [])
|
|
263
|
+
if (!css.includes(`browser/${file}`))
|
|
264
|
+
css.push(`browser/${file}`);
|
|
265
|
+
};
|
|
266
|
+
const key = Object.keys(vm).find((candidate) => vm[candidate] === entry);
|
|
267
|
+
visit(key);
|
|
268
|
+
let meta;
|
|
269
|
+
try {
|
|
270
|
+
const module = (await import(`${pathToFileURL(join(out, 'ssr', ssrFile)).href}?build=${Date.now()}`));
|
|
271
|
+
meta = module.meta;
|
|
272
|
+
}
|
|
273
|
+
catch (cause) {
|
|
274
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `The server module of ${page} could not be imported to read its meta: ${cause.message}`, { cause });
|
|
275
|
+
}
|
|
276
|
+
if (meta !== undefined) {
|
|
277
|
+
if (!jsonValue(meta))
|
|
278
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `${page} exports a meta that is not JSON data`);
|
|
279
|
+
if (Buffer.byteLength(JSON.stringify(meta)) > PAGE_META_MAX_BYTES)
|
|
280
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `${page} exports a meta larger than ${PAGE_META_MAX_BYTES} bytes`);
|
|
281
|
+
}
|
|
282
|
+
pageEntries[page] = {
|
|
283
|
+
browser: `browser/${entry.file}`,
|
|
284
|
+
css,
|
|
285
|
+
preload,
|
|
286
|
+
ssr: `ssr/${ssrFile}`,
|
|
287
|
+
...(meta === undefined ? {} : { meta }),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const files = {};
|
|
291
|
+
for (const top of ['browser', 'ssr'])
|
|
292
|
+
for (const file of await listFiles(join(out, top))) {
|
|
293
|
+
const content = await readFile(join(out, top, file));
|
|
294
|
+
files[`${top}/${file}`] = { bytes: content.length, sha256: sha256(content) };
|
|
295
|
+
}
|
|
296
|
+
const manifest = {
|
|
297
|
+
format: TEMPLATE_FORMAT,
|
|
298
|
+
name,
|
|
299
|
+
version,
|
|
300
|
+
builtWith: BUILDER.version,
|
|
301
|
+
shared: Object.fromEntries([...imported].sort().map((module) => [module, packageVersion(root, module)])),
|
|
302
|
+
pages: pageEntries,
|
|
303
|
+
files,
|
|
304
|
+
};
|
|
305
|
+
await writeFile(join(out, TEMPLATE_MANIFEST), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
306
|
+
const check = await checkTemplateBundle(out, {
|
|
307
|
+
maxBytes: options.maxBytes ?? TEMPLATE_MAX_BYTES,
|
|
308
|
+
});
|
|
309
|
+
if (check.problems.length || check.buildId === undefined)
|
|
310
|
+
throw new InertiaError('TEMPLATE_BUILD_FAILED', `The built bundle does not pass its own check: ${check.problems.map((problem) => problem.message).join('; ')}`);
|
|
311
|
+
const result = {
|
|
312
|
+
out,
|
|
313
|
+
name,
|
|
314
|
+
version,
|
|
315
|
+
buildId: check.buildId,
|
|
316
|
+
pages: Object.keys(pageEntries),
|
|
317
|
+
shared: manifest.shared,
|
|
318
|
+
files: Object.keys(files).length,
|
|
319
|
+
bytes: check.bytes,
|
|
320
|
+
ms: Math.round(performance.now() - begin),
|
|
321
|
+
};
|
|
322
|
+
logger.log('info', 'Template bundle built', {
|
|
323
|
+
code: 'INERTIA_TEMPLATE_BUILT',
|
|
324
|
+
name,
|
|
325
|
+
version,
|
|
326
|
+
buildId: result.buildId,
|
|
327
|
+
out: relative(root, out),
|
|
328
|
+
pages: result.pages.length,
|
|
329
|
+
files: result.files,
|
|
330
|
+
bytes: result.bytes,
|
|
331
|
+
shared: manifest.shared,
|
|
332
|
+
ms: result.ms,
|
|
333
|
+
});
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** The manifest file of a bundle. */
|
|
2
|
+
export declare const TEMPLATE_MANIFEST = "dokebi-template.json";
|
|
3
|
+
/** The signature file of a bundle (optional; its form is the app's). */
|
|
4
|
+
export declare const TEMPLATE_SIGNATURE = "dokebi-template.sig";
|
|
5
|
+
/** The manifest format this version writes and reads. */
|
|
6
|
+
export declare const TEMPLATE_FORMAT = 1;
|
|
7
|
+
/** A template name: the folder name of `views/<template>/` and `domains.<host>.template`. */
|
|
8
|
+
export declare const TEMPLATE_NAME: RegExp;
|
|
9
|
+
/** A template version (the template repository's): 1 to 64 of letters, digits, `.`, `+`, `-`. */
|
|
10
|
+
export declare const TEMPLATE_VERSION: RegExp;
|
|
11
|
+
/** A page of a bundle: `Layout`, or `Pages/<path>` without the `.vue`. */
|
|
12
|
+
export declare const TEMPLATE_PAGE: RegExp;
|
|
13
|
+
/** A shared module specifier: a package name with an optional subpath. */
|
|
14
|
+
export declare const SHARED_SPECIFIER: RegExp;
|
|
15
|
+
/** A page's `meta` (JSON) may take this many bytes. */
|
|
16
|
+
export declare const PAGE_META_MAX_BYTES = 4096;
|
|
17
|
+
/** Default limits of one bundle. */
|
|
18
|
+
export declare const TEMPLATE_MAX_BYTES: number;
|
|
19
|
+
export declare const TEMPLATE_MAX_FILES = 4096;
|
|
20
|
+
/**
|
|
21
|
+
* The shared modules every bundle may import and every app build provides (when it opts in with
|
|
22
|
+
* `dokebiInertia({ templates })`). `vue/server-renderer` is provided by the server build only.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SHARED_DEFAULTS: readonly string[];
|
|
25
|
+
/** The defaults the server build alone provides. */
|
|
26
|
+
export declare const SERVER_ONLY_SHARED: readonly string[];
|
|
27
|
+
/** One page of a bundle. */
|
|
28
|
+
export interface TemplatePage {
|
|
29
|
+
/** The browser entry (`browser/pages/…js`). */
|
|
30
|
+
readonly browser: string;
|
|
31
|
+
/** The stylesheets the page needs (its own and its chunks'), in load order. */
|
|
32
|
+
readonly css: readonly string[];
|
|
33
|
+
/** The chunks the browser entry imports, for `modulepreload`. */
|
|
34
|
+
readonly preload: readonly string[];
|
|
35
|
+
/** The server-render module (`ssr/pages/…js`). */
|
|
36
|
+
readonly ssr: string;
|
|
37
|
+
/** What the page exports as `meta` (JSON, at most 4 KiB): the app judges it (a contract). */
|
|
38
|
+
readonly meta?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** `dokebi-template.json`, format 1. */
|
|
41
|
+
export interface TemplateManifest {
|
|
42
|
+
readonly format: 1;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly version: string;
|
|
45
|
+
/** The @dokebi/template-inertia version that built it. */
|
|
46
|
+
readonly builtWith: string;
|
|
47
|
+
/** The shared modules its code imports → the version of their package when it was built. */
|
|
48
|
+
readonly shared: Readonly<Record<string, string | null>>;
|
|
49
|
+
readonly pages: Readonly<Record<string, TemplatePage>>;
|
|
50
|
+
/** Every file under browser/ and ssr/ → its size and sha256 (hex). */
|
|
51
|
+
readonly files: Readonly<Record<string, {
|
|
52
|
+
readonly bytes: number;
|
|
53
|
+
readonly sha256: string;
|
|
54
|
+
}>>;
|
|
55
|
+
}
|
|
56
|
+
/** What is wrong with a bundle (one entry per problem; the code is stable). */
|
|
57
|
+
export interface TemplateProblem {
|
|
58
|
+
readonly code: 'TEMPLATE_MANIFEST_MISSING' | 'TEMPLATE_MANIFEST_INVALID' | 'TEMPLATE_FORMAT_UNSUPPORTED' | 'TEMPLATE_FILE_MISSING' | 'TEMPLATE_FILE_CHANGED' | 'TEMPLATE_FILE_EXTRA' | 'TEMPLATE_FILE_LINK' | 'TEMPLATE_TOO_LARGE' | 'TEMPLATE_PAGE_FILE_UNKNOWN' | 'TEMPLATE_SHARED_MISSING' | 'TEMPLATE_SHARED_VERSION';
|
|
59
|
+
readonly message: string;
|
|
60
|
+
readonly file?: string;
|
|
61
|
+
readonly page?: string;
|
|
62
|
+
readonly module?: string;
|
|
63
|
+
}
|
|
64
|
+
/** The check of one bundle folder. */
|
|
65
|
+
export interface TemplateCheck {
|
|
66
|
+
/** The manifest, when it could be read and has the right shape. */
|
|
67
|
+
readonly manifest?: TemplateManifest;
|
|
68
|
+
/** The first 12 hex of the manifest's sha256: the same in every process that reads it. */
|
|
69
|
+
readonly buildId?: string;
|
|
70
|
+
/** The bytes of the files under browser/ and ssr/ that were read. */
|
|
71
|
+
readonly bytes: number;
|
|
72
|
+
readonly problems: readonly TemplateProblem[];
|
|
73
|
+
}
|
|
74
|
+
export interface TemplateCheckLimits {
|
|
75
|
+
readonly maxBytes?: number;
|
|
76
|
+
readonly maxFiles?: number;
|
|
77
|
+
}
|
|
78
|
+
/** The JSON `meta` value of a page is plain data (objects, arrays, strings, finite numbers…). */
|
|
79
|
+
export declare function jsonValue(value: unknown, depth?: number): boolean;
|
|
80
|
+
/** The problem of a manifest's shape, or undefined (paths, names, page references). */
|
|
81
|
+
export declare function manifestProblem(value: unknown): string | undefined;
|
|
82
|
+
/** sha256 (hex) of bytes. */
|
|
83
|
+
export declare function sha256(bytes: Uint8Array): string;
|
|
84
|
+
/**
|
|
85
|
+
* Checks one bundle folder: the manifest's shape, every file's size and sha256, no file the
|
|
86
|
+
* manifest does not list (but the manifest and the signature), no link, the limits. Reads only;
|
|
87
|
+
* never throws for what the folder holds (a missing folder is TEMPLATE_MANIFEST_MISSING).
|
|
88
|
+
*/
|
|
89
|
+
export declare function checkTemplateBundle(dir: string, limits?: TemplateCheckLimits): Promise<TemplateCheck>;
|
|
90
|
+
/** A shared module the app build provides (its `dokebi-shared.json` entry). */
|
|
91
|
+
export interface ProvidedShared {
|
|
92
|
+
readonly file: string;
|
|
93
|
+
readonly version: string | null;
|
|
94
|
+
}
|
|
95
|
+
/** The major part of a version for compatibility: `3` of 3.5.1, `0.4` of 0.4.19. */
|
|
96
|
+
export declare function compatibleLine(version: string): string | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The problems of a bundle's shared modules against what an app build provides: a module the app
|
|
99
|
+
* does not provide, or one whose package is another major (0.x: minor) than the bundle was built
|
|
100
|
+
* with. A version unknown on either side (a local alias) is not compared.
|
|
101
|
+
*/
|
|
102
|
+
export declare function sharedProblems(bundle: Readonly<Record<string, string | null>>, provided: Readonly<Record<string, ProvidedShared>>): TemplateProblem[];
|