@dokebi/template-inertia 0.4.20 → 0.4.21
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 +41 -4
- package/README.md +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.js +107 -11
- package/dist/options.d.ts +9 -0
- package/dist/options.js +53 -0
- package/dist/pages.d.ts +33 -0
- package/dist/pages.js +82 -0
- package/dist/responder.d.ts +6 -0
- package/dist/responder.js +18 -8
- package/dist/template-build.js +35 -5
- package/dist/template-runtime.d.ts +145 -0
- package/dist/template-runtime.js +723 -0
- package/dist/template-shared.d.ts +6 -0
- package/dist/template-shared.js +36 -2
- package/dist/template.d.ts +1 -1
- package/dist/template.js +1 -1
- package/dist/vite-plugin.js +3 -0
- package/dist/vue-typescript.d.ts +9 -0
- package/dist/vue-typescript.js +68 -0
- package/options.schema.json +79 -1
- package/package.json +1 -1
- package/templates/shared.ts +4 -0
|
@@ -39,6 +39,12 @@ export declare function packageVersion(root: string, module: string): string | n
|
|
|
39
39
|
* in root's node_modules/.cache imports it the way the built server code will.
|
|
40
40
|
*/
|
|
41
41
|
export declare function externalHasDefault(root: string, module: string): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* The version of `module`'s package found from a file it resolved to (an alias such as
|
|
44
|
+
* `resolve.alias: { '@shop/sdk': 'packages/sdk/src/index.ts' }`): the nearest package.json above
|
|
45
|
+
* that file whose `name` is the package's, or null (an alias into the app's own src/ is no package).
|
|
46
|
+
*/
|
|
47
|
+
export declare function versionNear(file: string, module: string): string | null;
|
|
42
48
|
/** The part of Rollup's input options this reads and changes. */
|
|
43
49
|
export interface InputOptionsShape {
|
|
44
50
|
readonly input?: string | readonly string[] | Readonly<Record<string, string>>;
|
package/dist/template-shared.js
CHANGED
|
@@ -71,6 +71,31 @@ export async function externalHasDefault(root, module) {
|
|
|
71
71
|
await rm(probe, { force: true });
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The version of `module`'s package found from a file it resolved to (an alias such as
|
|
76
|
+
* `resolve.alias: { '@shop/sdk': 'packages/sdk/src/index.ts' }`): the nearest package.json above
|
|
77
|
+
* that file whose `name` is the package's, or null (an alias into the app's own src/ is no package).
|
|
78
|
+
*/
|
|
79
|
+
export function versionNear(file, module) {
|
|
80
|
+
const parts = module.split('/');
|
|
81
|
+
const name = module.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
82
|
+
for (let dir = dirname(resolve(file));; dir = dirname(dir)) {
|
|
83
|
+
const candidate = join(dir, 'package.json');
|
|
84
|
+
if (existsSync(candidate)) {
|
|
85
|
+
let json;
|
|
86
|
+
try {
|
|
87
|
+
json = JSON.parse(readFileSync(candidate, 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (json.name === name)
|
|
93
|
+
return typeof json.version === 'string' ? json.version : null;
|
|
94
|
+
}
|
|
95
|
+
if (dirname(dir) === dir || /[\\/]node_modules$/.test(dir))
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
74
99
|
/** The shared entries of one app build (`dokebiInertia({ templates })`). */
|
|
75
100
|
export class SharedEntries {
|
|
76
101
|
#logger;
|
|
@@ -80,6 +105,8 @@ export class SharedEntries {
|
|
|
80
105
|
#base = '/';
|
|
81
106
|
#outDir = 'dist';
|
|
82
107
|
#build = false;
|
|
108
|
+
/** module → the file it resolved to (not an external): its version when no package is installed. */
|
|
109
|
+
#resolved = new Map();
|
|
83
110
|
constructor(logger, options) {
|
|
84
111
|
this.#logger = logger;
|
|
85
112
|
this.#modules = sharedModules(options);
|
|
@@ -160,8 +187,10 @@ export class SharedEntries {
|
|
|
160
187
|
throw new InertiaUsageError('INVALID_TEMPLATE_SHARED', `templates.shared: ${module} cannot be imported from ${this.#root} by Node: ${cause.message}`);
|
|
161
188
|
}
|
|
162
189
|
}
|
|
163
|
-
else
|
|
190
|
+
else {
|
|
191
|
+
this.#resolved.set(module, resolved.id.split('?', 1)[0]);
|
|
164
192
|
withDefault = (await context.load({ id: resolved.id })).exports?.includes('default') === true;
|
|
193
|
+
}
|
|
165
194
|
return `export * from ${spec};\n${withDefault ? `export { default } from ${spec};\n` : ''}`;
|
|
166
195
|
}
|
|
167
196
|
/** `writeBundle`: `dokebi-shared.json` beside the build's manifest. */
|
|
@@ -174,7 +203,12 @@ export class SharedEntries {
|
|
|
174
203
|
if (chunk.type !== 'chunk' || !chunk.isEntry || !facade?.startsWith(PREFIX))
|
|
175
204
|
continue;
|
|
176
205
|
const module = facade.slice(PREFIX.length);
|
|
177
|
-
|
|
206
|
+
const near = this.#resolved.get(module);
|
|
207
|
+
modules[module] = {
|
|
208
|
+
file: chunk.fileName,
|
|
209
|
+
version: packageVersion(this.#root, module) ??
|
|
210
|
+
(near === undefined ? null : versionNear(near, module)),
|
|
211
|
+
};
|
|
178
212
|
}
|
|
179
213
|
const missing = this.modules.filter((module) => modules[module] === undefined);
|
|
180
214
|
if (missing.length)
|
package/dist/template.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { buildTemplateBundle, packageEntry, type TemplateBuildOptions, type TemplateBuildResult, templatePages, } from './template-build.js';
|
|
2
|
-
export { checkTemplateBundle, compatibleLine, type ProvidedShared, SHARED_DEFAULTS, sharedProblems, TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_MAX_BYTES, TEMPLATE_NAME, TEMPLATE_SIGNATURE, type TemplateCheck, type TemplateCheckLimits, type TemplateManifest, type TemplatePage, type TemplateProblem, } from './template-bundle.js';
|
|
2
|
+
export { checkTemplateBundle, compatibleLine, type ProvidedShared, SERVER_ONLY_SHARED, SHARED_DEFAULTS, sharedProblems, TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_MAX_BYTES, TEMPLATE_NAME, TEMPLATE_SIGNATURE, type TemplateCheck, type TemplateCheckLimits, type TemplateManifest, type TemplatePage, type TemplateProblem, } from './template-bundle.js';
|
|
3
3
|
export { type DokebiInertiaTemplateOptions, packageVersion, SHARED_FILE, type SharedFile, sharedEntryName, } from './template-shared.js';
|
package/dist/template.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// `@dokebi/template-inertia/template` (D-0291): template bundles — the format and its check, and
|
|
2
2
|
// the build that `dokebi template build` runs in a template repository.
|
|
3
3
|
export { buildTemplateBundle, packageEntry, templatePages, } from './template-build.js';
|
|
4
|
-
export { checkTemplateBundle, compatibleLine, SHARED_DEFAULTS, sharedProblems, TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_MAX_BYTES, TEMPLATE_NAME, TEMPLATE_SIGNATURE, } from './template-bundle.js';
|
|
4
|
+
export { checkTemplateBundle, compatibleLine, SERVER_ONLY_SHARED, SHARED_DEFAULTS, sharedProblems, TEMPLATE_FORMAT, TEMPLATE_MANIFEST, TEMPLATE_MAX_BYTES, TEMPLATE_NAME, TEMPLATE_SIGNATURE, } from './template-bundle.js';
|
|
5
5
|
export { packageVersion, SHARED_FILE, sharedEntryName, } from './template-shared.js';
|
package/dist/vite-plugin.js
CHANGED
|
@@ -31,6 +31,7 @@ import { ConsoleLogger } from '@dokebi/core';
|
|
|
31
31
|
import { MODULE_PAGES_ID, ModulePagesSource } from './module-pages.js';
|
|
32
32
|
import { SharedEntries, } from './template-shared.js';
|
|
33
33
|
import { DevFilesPolicy, } from './vite-files.js';
|
|
34
|
+
import { registerVueTypeScript } from './vue-typescript.js';
|
|
34
35
|
export { MODULE_PAGES_ID } from './module-pages.js';
|
|
35
36
|
export { SHARED_FILE, } from './template-shared.js';
|
|
36
37
|
export { DEV_FILES_DENY, dokebiDevFiles, } from './vite-files.js';
|
|
@@ -115,6 +116,8 @@ export function dokebiInertia(options = {}) {
|
|
|
115
116
|
},
|
|
116
117
|
configResolved(config) {
|
|
117
118
|
files.configResolved(config);
|
|
119
|
+
// D-0291 follow-up: props types imported from packages need a TypeScript with a JS API.
|
|
120
|
+
registerVueTypeScript(config.root ?? process.cwd(), logger);
|
|
118
121
|
shared?.configResolved({
|
|
119
122
|
root: config.root ?? process.cwd(),
|
|
120
123
|
command: config.command,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '@dokebi/core';
|
|
2
|
+
/** The TypeScript packages tried, in order: the first with a JS API is registered. */
|
|
3
|
+
export declare const VUE_TYPESCRIPT_CANDIDATES: readonly ['typescript', '@typescript/typescript6'];
|
|
4
|
+
/**
|
|
5
|
+
* Registers a TypeScript with a JS API on the project's vue/compiler-sfc (once per root and
|
|
6
|
+
* process). Returns the package registered, `typescript-7` when none has a JS API, or undefined
|
|
7
|
+
* when the project has no vue/compiler-sfc.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerVueTypeScript(root: string, logger: Logger): string | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// D-0291 follow-up: the Vue SFC compiler resolves the props types a page imports from a package
|
|
2
|
+
// (`defineProps<Props>()` with `import type { Props } from '@shop/sdk'`) through TypeScript's JS
|
|
3
|
+
// API (`ts.findConfigFile`, module resolution). vue/compiler-sfc registers `require('typescript')`
|
|
4
|
+
// for that the first time it is imported; TypeScript 7 (the native compiler) has no JS API, so the
|
|
5
|
+
// build fails with "ts2.findConfigFile is not a function". This registers a TypeScript that has
|
|
6
|
+
// one instead: the project's `typescript` when it is 6 or older, else `@typescript/typescript6`
|
|
7
|
+
// (TypeScript 6 as a package beside 7). Without either nothing changes (and only builds whose
|
|
8
|
+
// pages import types from packages need it).
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
/** The TypeScript packages tried, in order: the first with a JS API is registered. */
|
|
12
|
+
export const VUE_TYPESCRIPT_CANDIDATES = ['typescript', '@typescript/typescript6'];
|
|
13
|
+
const done = new Set();
|
|
14
|
+
/**
|
|
15
|
+
* Registers a TypeScript with a JS API on the project's vue/compiler-sfc (once per root and
|
|
16
|
+
* process). Returns the package registered, `typescript-7` when none has a JS API, or undefined
|
|
17
|
+
* when the project has no vue/compiler-sfc.
|
|
18
|
+
*/
|
|
19
|
+
export function registerVueTypeScript(root, logger) {
|
|
20
|
+
const require = createRequire(join(root, 'package.json'));
|
|
21
|
+
let sfc;
|
|
22
|
+
try {
|
|
23
|
+
// Importing it first runs its own registration, which this one then replaces.
|
|
24
|
+
sfc = require('vue/compiler-sfc');
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
logger.log('debug', 'Vue SFC compiler not found; no TypeScript registered for its types', {
|
|
28
|
+
root,
|
|
29
|
+
error: error.message,
|
|
30
|
+
});
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (typeof sfc.registerTS !== 'function')
|
|
34
|
+
return undefined;
|
|
35
|
+
for (const name of VUE_TYPESCRIPT_CANDIDATES) {
|
|
36
|
+
let ts;
|
|
37
|
+
try {
|
|
38
|
+
ts = require(name);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
logger.log('debug', 'TypeScript candidate for the Vue SFC compiler not installed', {
|
|
42
|
+
package: name,
|
|
43
|
+
error: error.message,
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (typeof ts.findConfigFile !== 'function')
|
|
48
|
+
continue;
|
|
49
|
+
if (!done.has(`${root} ${name}`)) {
|
|
50
|
+
done.add(`${root} ${name}`);
|
|
51
|
+
logger.log('debug', 'TypeScript registered for the Vue SFC compiler', {
|
|
52
|
+
code: 'INERTIA_VUE_TYPESCRIPT',
|
|
53
|
+
package: name,
|
|
54
|
+
version: String(ts.version ?? ''),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
sfc.registerTS(() => ts);
|
|
58
|
+
return name;
|
|
59
|
+
}
|
|
60
|
+
if (!done.has(`${root} none`)) {
|
|
61
|
+
done.add(`${root} none`);
|
|
62
|
+
logger.log('debug', 'No TypeScript with a JS API for the Vue SFC compiler (TypeScript 7)', {
|
|
63
|
+
code: 'INERTIA_VUE_TYPESCRIPT',
|
|
64
|
+
fix: 'Pages that import their props types from a package need it: npm install --save-dev @typescript/typescript6',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return 'typescript-7';
|
|
68
|
+
}
|
package/options.schema.json
CHANGED
|
@@ -228,9 +228,87 @@
|
|
|
228
228
|
"pattern": "^[A-Za-z][A-Za-z0-9._-]{0,63}$",
|
|
229
229
|
"x-dokebi-secret": false,
|
|
230
230
|
"description": "Id of the GET <vite base>* routes of the Vite dev server (dokebi dev, one per base); default template-inertia.viteDev"
|
|
231
|
+
},
|
|
232
|
+
"templateFiles": {
|
|
233
|
+
"type": "string",
|
|
234
|
+
"pattern": "^[A-Za-z][A-Za-z0-9._-]{0,63}$",
|
|
235
|
+
"x-dokebi-secret": false,
|
|
236
|
+
"description": "Id of D-0291: the GET /_dokebi/templates/* route of the browser files of template bundles; default template-inertia.templateFiles"
|
|
231
237
|
}
|
|
232
238
|
},
|
|
233
|
-
"description": "Ids of the routes dokebi-template-inertia adds (D-0142), by route key: assets (default template-inertia.assets), viteDev (default template-inertia.viteDev). An id is 1-64 letters, digits, '.', '_' or '-' starting with a letter; an id another route of the same app has fails the start (DUPLICATE_ROUTE_ID)"
|
|
239
|
+
"description": "Ids of the routes dokebi-template-inertia adds (D-0142), by route key: assets (default template-inertia.assets), viteDev (default template-inertia.viteDev), templateFiles (default template-inertia.templateFiles). An id is 1-64 letters, digits, '.', '_' or '-' starting with a letter; an id another route of the same app has fails the start (DUPLICATE_ROUTE_ID)"
|
|
240
|
+
},
|
|
241
|
+
"templates": {
|
|
242
|
+
"type": "object",
|
|
243
|
+
"propertyNames": {
|
|
244
|
+
"pattern": "^[a-z][a-z0-9-]{0,31}$"
|
|
245
|
+
},
|
|
246
|
+
"maxProperties": 64,
|
|
247
|
+
"additionalProperties": {
|
|
248
|
+
"type": "object",
|
|
249
|
+
"propertyNames": {
|
|
250
|
+
"pattern": "^[a-z][a-z0-9-]{0,31}$"
|
|
251
|
+
},
|
|
252
|
+
"maxProperties": 64,
|
|
253
|
+
"additionalProperties": {
|
|
254
|
+
"type": "object",
|
|
255
|
+
"additionalProperties": false,
|
|
256
|
+
"properties": {
|
|
257
|
+
"path": {
|
|
258
|
+
"type": "string",
|
|
259
|
+
"minLength": 1,
|
|
260
|
+
"maxLength": 4096,
|
|
261
|
+
"description": "The bundle folder (dokebi-template.json, browser/, ssr/), absolute or relative to the working directory: a read-only mount is fine"
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
"required": [
|
|
265
|
+
"path"
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
"description": "Template name (dokebi-app domains.<host>.template) → its bundle"
|
|
269
|
+
},
|
|
270
|
+
"default": {},
|
|
271
|
+
"x-dokebi-reloadable": true,
|
|
272
|
+
"description": "D-0291: template bundles built apart from the app (npx dokebi template build), per app and template. A host whose template has a bundle gets its pages (then the app views/<template>, views/default and module pages, as before); a missing, broken or refused bundle leaves the template to the app pages and never stops the start. Not used under dokebi dev (Vite)."
|
|
273
|
+
},
|
|
274
|
+
"templateCheckMs": {
|
|
275
|
+
"type": "integer",
|
|
276
|
+
"minimum": 0,
|
|
277
|
+
"maximum": 3600000,
|
|
278
|
+
"default": 5000,
|
|
279
|
+
"x-dokebi-reloadable": true,
|
|
280
|
+
"description": "D-0291: how often each bundle folder's dokebi-template.json is looked at; a changed bundle is loaded beside the current one and replaces it for the next request. 0: only at start and reloads"
|
|
281
|
+
},
|
|
282
|
+
"templateMaxBytes": {
|
|
283
|
+
"type": "integer",
|
|
284
|
+
"minimum": 1024,
|
|
285
|
+
"maximum": 1073741824,
|
|
286
|
+
"default": 52428800,
|
|
287
|
+
"x-dokebi-reloadable": true,
|
|
288
|
+
"description": "D-0291: the largest template bundle (its files), 50 MiB by default"
|
|
289
|
+
},
|
|
290
|
+
"templateKeep": {
|
|
291
|
+
"type": "integer",
|
|
292
|
+
"minimum": 1,
|
|
293
|
+
"maximum": 16,
|
|
294
|
+
"default": 2,
|
|
295
|
+
"x-dokebi-reloadable": true,
|
|
296
|
+
"description": "D-0291: generations of a template kept in the cache and served (the current one and those before it), so pages opened before a swap still load their files"
|
|
297
|
+
},
|
|
298
|
+
"templateVerifyTimeoutMs": {
|
|
299
|
+
"type": "integer",
|
|
300
|
+
"minimum": 100,
|
|
301
|
+
"maximum": 600000,
|
|
302
|
+
"default": 10000,
|
|
303
|
+
"x-dokebi-reloadable": true,
|
|
304
|
+
"description": "D-0291: how long the entry's verifyTemplate may take for one bundle; past it the bundle is refused"
|
|
305
|
+
},
|
|
306
|
+
"templateCacheDir": {
|
|
307
|
+
"type": "string",
|
|
308
|
+
"minLength": 1,
|
|
309
|
+
"maxLength": 4096,
|
|
310
|
+
"default": ".dokebi/cache/templates",
|
|
311
|
+
"description": "D-0291: where checked copies of the bundles go (relative to the working directory); a writable folder of the process"
|
|
234
312
|
}
|
|
235
313
|
}
|
|
236
314
|
}
|
package/package.json
CHANGED
package/templates/shared.ts
CHANGED
|
@@ -5,3 +5,7 @@ import type { FastifyRequest } from 'fastify';
|
|
|
5
5
|
export async function shared(_request: FastifyRequest) {
|
|
6
6
|
return {};
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
// D-0291: with template bundles (options.dokebi-template-inertia.templates), export
|
|
10
|
+
// verifyTemplate(bundle) here too: it judges a bundle (its signature, each page's meta.contract)
|
|
11
|
+
// before the app uses it; in production a bundle is not used without it (AI.md §4.3).
|