@vesk/adapter 0.2.42 → 0.2.44
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/dist/client-bundle.d.ts +13 -0
- package/dist/client-bundle.d.ts.map +1 -1
- package/dist/client-bundle.js +83 -7
- package/dist/hmr.d.ts.map +1 -1
- package/dist/hmr.js +14 -3
- package/dist/ssr-function.d.ts.map +1 -1
- package/dist/ssr-function.js +54 -38
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/client-bundle.d.ts
CHANGED
|
@@ -67,6 +67,19 @@ interface CompiledNode {
|
|
|
67
67
|
* eval runs against a live chunk scope where those already exist.
|
|
68
68
|
*/
|
|
69
69
|
export declare function isSnippetDrop(node: CompiledNode): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* When a chunk's esbuild bundle fails to resolve bare specifiers, the
|
|
72
|
+
* historical fallback strips every import, leaving dangling free identifiers
|
|
73
|
+
* that surface as a baffling `ReferenceError: X is not defined` at render
|
|
74
|
+
* time. Native-only `@vesk/*` library imports can NEVER resolve in the
|
|
75
|
+
* browser dev preview — make that a first-class, readable failure by emitting
|
|
76
|
+
* a throwing proxy for every binding those imports declare: the binding reads
|
|
77
|
+
* as a function, so `typeof` stays truthful, and the throw carries the
|
|
78
|
+
* library, the binding, and the remedy. Other bare specifiers (e.g. `motion`,
|
|
79
|
+
* dev-preview-provided) are left dangling — genuinely missing packages still
|
|
80
|
+
* fail as ReferenceErrors, which is honest. AST-only; never a text scan.
|
|
81
|
+
*/
|
|
82
|
+
export declare function nativeLibraryImportStubs(code: string): string;
|
|
70
83
|
/**
|
|
71
84
|
* Demotes surviving value exports to plain declarations (`export const x`
|
|
72
85
|
* becomes `const x`) and drops bare re-export lists (`export { x }`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-bundle.d.ts","sourceRoot":"","sources":["../src/client-bundle.ts"],"names":[],"mappings":"
|
|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 'node:os';
|
|
|
5
5
|
import { build } from './esbuild-fallback.js';
|
|
6
6
|
import { stripCodeTypes } from '@vesk/compiler/src/strip-ts';
|
|
7
7
|
import { parse } from '@vesk/compiler/src/parser';
|
|
8
|
-
import { compileClient, compileClientBoth, nameAllocFor } from '@vesk/compiler/src/client-codegen';
|
|
8
|
+
import { compileClient, compileClientBoth, nameAllocFor, vskComponentNames } from '@vesk/compiler/src/client-codegen';
|
|
9
|
+
import { VskComponentOwners } from '@vesk/compiler/src/vsk-collision';
|
|
9
10
|
import { resolveComponentName } from '@vesk/compiler/src/server-codegen';
|
|
10
11
|
import { collectVskImportPaths, vskImportLines } from '@vesk/compiler/src/vsk-imports';
|
|
11
12
|
import { inlineMdContentAttrs, guessProjectRoots } from '@vesk/compiler/src/md-inline';
|
|
@@ -174,6 +175,52 @@ function isModuleLevel(node) {
|
|
|
174
175
|
|| node.type === 'ExportNamedDeclaration'
|
|
175
176
|
|| node.type === 'ExportDefaultDeclaration';
|
|
176
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* When a chunk's esbuild bundle fails to resolve bare specifiers, the
|
|
180
|
+
* historical fallback strips every import, leaving dangling free identifiers
|
|
181
|
+
* that surface as a baffling `ReferenceError: X is not defined` at render
|
|
182
|
+
* time. Native-only `@vesk/*` library imports can NEVER resolve in the
|
|
183
|
+
* browser dev preview — make that a first-class, readable failure by emitting
|
|
184
|
+
* a throwing proxy for every binding those imports declare: the binding reads
|
|
185
|
+
* as a function, so `typeof` stays truthful, and the throw carries the
|
|
186
|
+
* library, the binding, and the remedy. Other bare specifiers (e.g. `motion`,
|
|
187
|
+
* dev-preview-provided) are left dangling — genuinely missing packages still
|
|
188
|
+
* fail as ReferenceErrors, which is honest. AST-only; never a text scan.
|
|
189
|
+
*/
|
|
190
|
+
export function nativeLibraryImportStubs(code) {
|
|
191
|
+
let ast;
|
|
192
|
+
try {
|
|
193
|
+
ast = parse(code);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return '';
|
|
197
|
+
}
|
|
198
|
+
const body = ast.body ?? [];
|
|
199
|
+
const bindings = [];
|
|
200
|
+
for (const node of body) {
|
|
201
|
+
if (node?.type !== 'ImportDeclaration')
|
|
202
|
+
continue;
|
|
203
|
+
const src = node.source?.value;
|
|
204
|
+
if (typeof src !== 'string' || !src.startsWith('@vesk/') || src.startsWith('@vesk/runtime'))
|
|
205
|
+
continue;
|
|
206
|
+
for (const spec of node.specifiers ?? []) {
|
|
207
|
+
if (typeof spec?.local?.name === 'string')
|
|
208
|
+
bindings.push([spec.local.name, src]);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (bindings.length === 0)
|
|
212
|
+
return '';
|
|
213
|
+
const lines = bindings.map(([local, spec]) => {
|
|
214
|
+
const message = `web preview: native library "${spec}" has no browser equivalent on the web ` +
|
|
215
|
+
`(dev-only) — binding "${local}" cannot be provided in vesk dev --web. Build for Android to use it.`;
|
|
216
|
+
const thrower = `throw Object.assign(new Error(${JSON.stringify(message)}), { __veskPreviewMissing: ${JSON.stringify(spec)} })`;
|
|
217
|
+
return (`const ${local} = new Proxy(function () {}, { ` +
|
|
218
|
+
`get: function () { ${thrower}; }, ` +
|
|
219
|
+
`apply: function () { ${thrower}; }, ` +
|
|
220
|
+
`construct: function () { ${thrower}; } });`);
|
|
221
|
+
});
|
|
222
|
+
return lines.join('\n') + '\n\n';
|
|
223
|
+
}
|
|
177
224
|
/**
|
|
178
225
|
* Demotes surviving value exports to plain declarations (`export const x`
|
|
179
226
|
* becomes `const x`) and drops bare re-export lists (`export { x }`,
|
|
@@ -682,7 +729,9 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
682
729
|
// One parse/IR pass feeds both client modes AND the component-name
|
|
683
730
|
// lookup — the dev hot path pays the acorn+TS parse once per edit
|
|
684
731
|
// instead of three times.
|
|
685
|
-
const { comp: rawComp, hyd: rawHyd, name: actualName } = compileClientBoth(src, null, filePath);
|
|
732
|
+
const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths, componentNames } = compileClientBoth(src, null, filePath);
|
|
733
|
+
for (const cn of componentNames || [])
|
|
734
|
+
componentOwners.claim(cn, filePath);
|
|
686
735
|
// Cache keeps the import-carrying codes so a warm build can re-fold them
|
|
687
736
|
// into its own fresh accumulator; the emitted codes are import-stripped.
|
|
688
737
|
// The bodies/specs/scoped artifacts are cached too so warm replay never
|
|
@@ -715,6 +764,17 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
715
764
|
output.push(`Object.defineProperty(__components, ${JSON.stringify(resolvedName)}, { get: () => __components[${JSON.stringify(actualName)}], configurable: true });`);
|
|
716
765
|
output.push(`Object.defineProperty(__hydrators, ${JSON.stringify(resolvedName)}, { get: () => __hydrators[${JSON.stringify(actualName)}], configurable: true });`);
|
|
717
766
|
}
|
|
767
|
+
// `.vsk` export/import aliases (`export { A as B }`, `import { A as B }`):
|
|
768
|
+
// nothing is emitted for them, so register lazy getters that resolve to
|
|
769
|
+
// the canonical name. Lazy because the target may be contributed later.
|
|
770
|
+
for (const alias of aliases || []) {
|
|
771
|
+
output.push(`Object.defineProperty(__components, ${JSON.stringify(alias.exported)}, { get: () => __components[${JSON.stringify(alias.local)}], configurable: true });`);
|
|
772
|
+
output.push(`Object.defineProperty(__hydrators, ${JSON.stringify(alias.exported)}, { get: () => __hydrators[${JSON.stringify(alias.local)}], configurable: true });`);
|
|
773
|
+
}
|
|
774
|
+
// `export * from './x.vsk'` / `export { A } from './x.vsk'`: the target is
|
|
775
|
+
// not reachable through an import statement, so compile it here.
|
|
776
|
+
for (const reexportPath of reexportPaths || [])
|
|
777
|
+
compileFile(reexportPath, null, output, imports);
|
|
718
778
|
if (cache && namesBefore) {
|
|
719
779
|
const st = statSync(filePath);
|
|
720
780
|
cache.files.set(filePath, {
|
|
@@ -740,6 +800,11 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
740
800
|
}
|
|
741
801
|
const codeSplit = !!(options?.codeSplit);
|
|
742
802
|
const transformPlugins = options?.plugins || [];
|
|
803
|
+
// Every `.vsk` component in the bundle shares ONE registry keyed by declared
|
|
804
|
+
// name, so two files declaring `component X` silently resolve to whichever
|
|
805
|
+
// compiled last. Warn once per build — see vsk-collision.ts for why this is
|
|
806
|
+
// a warning and not an error.
|
|
807
|
+
const componentOwners = new VskComponentOwners();
|
|
743
808
|
/** Run every active plugin's `onTransformJS` over an emitted bundle/chunk source. */
|
|
744
809
|
async function applyTransformPlugins(code, filePath) {
|
|
745
810
|
if (transformPlugins.length === 0)
|
|
@@ -863,10 +928,12 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
863
928
|
const err = e;
|
|
864
929
|
console.error('[vesk] chunk bundle failed', entry.name, err?.errors?.map((x) => x.text).join(' | ') || err?.message || String(e));
|
|
865
930
|
// Fall back to the historical behavior: strip every import so the
|
|
866
|
-
// classic script at least parses
|
|
867
|
-
//
|
|
931
|
+
// classic script at least parses. Bindings imported from native-only
|
|
932
|
+
// `@vesk/*` libraries get throwing stubs (a readable degradation
|
|
933
|
+
// instead of a baffling `X is not defined`); every other stripped
|
|
934
|
+
// name stays dangling, which is the pre-existing failure mode.
|
|
868
935
|
const stripped = demoteExports(removeCompiledNodes(entry.code, isAnyImport));
|
|
869
|
-
finalCode = chunkIIFE(stripped);
|
|
936
|
+
finalCode = chunkIIFE(nativeLibraryImportStubs(entry.code) + stripped);
|
|
870
937
|
}
|
|
871
938
|
finally {
|
|
872
939
|
try {
|
|
@@ -876,7 +943,12 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
876
943
|
}
|
|
877
944
|
}
|
|
878
945
|
else {
|
|
879
|
-
|
|
946
|
+
// No-import chunk: wrap the compiled source in the registry IIFE. The
|
|
947
|
+
// compiler still emits module-level `export const pageProps` / re-export
|
|
948
|
+
// lists, and a classic script cannot carry an `export` — demote value
|
|
949
|
+
// exports to bindings and drop bare re-export lists (components resolve
|
|
950
|
+
// via the __components / __hydrators registries, matching the mono path).
|
|
951
|
+
finalCode = chunkIIFE(demoteExports(entry.code));
|
|
880
952
|
}
|
|
881
953
|
chunks.push({ name: entry.name, code: finalCode });
|
|
882
954
|
}
|
|
@@ -905,6 +977,7 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
905
977
|
for (const chunk of chunks) {
|
|
906
978
|
transformedChunks.push({ ...chunk, code: await applyTransformPlugins(chunk.code, chunk.name) });
|
|
907
979
|
}
|
|
980
|
+
componentOwners.report('client bundle');
|
|
908
981
|
return { main: await applyTransformPlugins(main, 'client.js'), chunks: transformedChunks, cachedFileHits, compiledFiles, mainFromCache, editedSources, editedNames };
|
|
909
982
|
}
|
|
910
983
|
else {
|
|
@@ -918,6 +991,8 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
918
991
|
seen.add(filePath);
|
|
919
992
|
const src = readFileSync(filePath, 'utf-8');
|
|
920
993
|
resolveVskImports(filePath, (p, n) => compileFileMono(p, n || ''));
|
|
994
|
+
for (const cn of vskComponentNames(src, filePath))
|
|
995
|
+
componentOwners.claim(cn, filePath);
|
|
921
996
|
// Share one name allocator so the comp and hyd contributions (which are
|
|
922
997
|
// joined into a single scoped block below) never reuse `$n` names.
|
|
923
998
|
const monoAlloc = nameAllocFor(filePath);
|
|
@@ -974,6 +1049,7 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
|
|
|
974
1049
|
componentLines, hydratorLines, aliasLines, hydratorAliasLines,
|
|
975
1050
|
}, !!options?.hmr, !!options?.importRuntime, runtimeImportNames, options?.routeDataCache);
|
|
976
1051
|
// Mono (non-codeSplit) builds are the production path — no incremental cache.
|
|
1052
|
+
componentOwners.report('client bundle');
|
|
977
1053
|
return { main: await applyTransformPlugins(main, 'client.js'), chunks: [] };
|
|
978
1054
|
}
|
|
979
1055
|
}
|
|
@@ -1142,7 +1218,7 @@ function appendHmrGlobals(code) {
|
|
|
1142
1218
|
"};\n";
|
|
1143
1219
|
}
|
|
1144
1220
|
async function buildMainBundle(routeTree, runtimeDir, codeSplit, mono, hmr, importRuntime, runtimeImportNames, routeDataCache) {
|
|
1145
|
-
const baseRuntimeImports = ['createFileRouter', 'get', 'set', 'effect', 'track', 'destroy_block', 'getActiveComponent', 'setActiveComponent', 'NavLink', 'Link', 'reactiveProps', 'matchRoute', 'ensureChunk'];
|
|
1221
|
+
const baseRuntimeImports = ['createFileRouter', 'get', 'set', 'effect', 'track', 'destroy_block', 'getActiveComponent', 'setActiveComponent', 'NavLink', 'Link', 'reactiveProps', 'matchRoute', 'ensureChunk', 'toDomNode', 'rerenderNode'];
|
|
1146
1222
|
const allRuntimeImports = runtimeImportNames && runtimeImportNames.size > 0
|
|
1147
1223
|
? [...new Set([...baseRuntimeImports, ...runtimeImportNames])]
|
|
1148
1224
|
: baseRuntimeImports;
|
package/dist/hmr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAUxC,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEvG,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AAIzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gFAA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renderCode;
|
|
356
356
|
if (layoutDecls.length > 0) {
|
|
357
357
|
renderCode = [
|
|
358
|
+
// One store per request, mirroring ssr-function.ts. The page, every
|
|
359
|
+
// nested layout and the document must share a single SSR token: each
|
|
360
|
+
// `renderPage`/`renderFullPage` call below resolves
|
|
361
|
+
// `globalThis.__vsk_ssr_token` for its data slot, and outside a scope that
|
|
362
|
+
// global is undefined — so `useFetch` settled under one token would be
|
|
363
|
+
// serialized by `renderFullPage` under another and the page would ship
|
|
364
|
+
// with no ssr-data script.
|
|
365
|
+
' return withSsrStore(async () => {',
|
|
358
366
|
' let page;',
|
|
359
367
|
' let caughtError = null;',
|
|
360
368
|
' try {',
|
|
@@ -368,22 +376,24 @@ function regenerateSsrFunction(routeNode, appDir, outDir, componentMap, options)
|
|
|
368
376
|
' }',
|
|
369
377
|
" let _body = (caughtError ? '<!--vesk-ssr-error:' + (caughtError && typeof caughtError === 'object' && 'message' in caughtError ? encodeURIComponent(String(caughtError.message)) : '') + '-->' : '') + page.body;",
|
|
370
378
|
" let _head = page.head || '';",
|
|
371
|
-
|
|
379
|
+
' for (let _i = _layoutSrcList.length - 1; _i > 0; _i--) {',
|
|
372
380
|
" const _inner = await renderPage(_layoutSrcList[_i], _layoutCompList[_i], { params, children: _body }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i], sourcePath: _layoutPathList[_i] });",
|
|
373
381
|
' _body = _inner.body;',
|
|
374
382
|
" if (_inner.head) _head = _inner.head + _head;",
|
|
375
383
|
' }',
|
|
376
384
|
" const html = await renderFullPage(_layoutSrcList[0], _layoutCompList[0], { params, children: _body }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[0]" + bakedOptions + clientScriptOption + dataScriptOption + ', pageHead: _head, sourcePath: _layoutPathList[0] });',
|
|
377
385
|
" return new Response(html, { headers: { 'Content-Type': 'text/html' }, status: caughtError ? 500 : 200 });",
|
|
386
|
+
' });',
|
|
378
387
|
].join('\n');
|
|
379
388
|
}
|
|
380
389
|
else {
|
|
381
390
|
renderCode = [
|
|
391
|
+
' return withSsrStore(async () => {',
|
|
382
392
|
' let stream;',
|
|
383
393
|
' try {',
|
|
384
394
|
' stream = renderPageStream(_src, _comp, { params }, __componentRegistry, { hydrate: true, cached: _srcCompiled' + bakedOptions + clientScriptOption + dataScriptOption + ", sourcePath: _srcPath });",
|
|
385
395
|
' } catch (err) {',
|
|
386
|
-
|
|
396
|
+
" if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
|
|
387
397
|
' if (!_errorSrc) throw err;',
|
|
388
398
|
" const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
|
|
389
399
|
" const stack = err && typeof err === 'object' && 'stack' in err ? String(err.stack) : '';",
|
|
@@ -399,6 +409,7 @@ function regenerateSsrFunction(routeNode, appDir, outDir, componentMap, options)
|
|
|
399
409
|
' controller.close();',
|
|
400
410
|
' },',
|
|
401
411
|
" }), { headers: { 'Content-Type': 'text/html' } });",
|
|
412
|
+
' });',
|
|
402
413
|
].join('\n');
|
|
403
414
|
}
|
|
404
415
|
const errorBodyFnCode = [
|
|
@@ -413,7 +424,7 @@ function regenerateSsrFunction(routeNode, appDir, outDir, componentMap, options)
|
|
|
413
424
|
'}',
|
|
414
425
|
].join('\n');
|
|
415
426
|
const funcCode = [
|
|
416
|
-
"import { renderFullPage, renderPageStream, renderPage, compileFile, setVskHydrate, storeDataScriptGlobal } from '../runtime.js';",
|
|
427
|
+
"import { renderFullPage, renderPageStream, renderPage, compileFile, setVskHydrate, storeDataScriptGlobal, withSsrStore } from '../runtime.js';",
|
|
417
428
|
'', registryCode, src, '',
|
|
418
429
|
errorBodyFnCode,
|
|
419
430
|
'',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI7F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAgED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI7F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAgED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoZtD"}
|
package/dist/ssr-function.js
CHANGED
|
@@ -241,35 +241,49 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
241
241
|
// the next full-page render can't reuse the stale token and serialize the
|
|
242
242
|
// previous nav's SSR data into its page (ssr-data leak).
|
|
243
243
|
const dataNavCleanup = [
|
|
244
|
-
'
|
|
245
|
-
'
|
|
246
|
-
'
|
|
247
|
-
'
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
244
|
+
' } finally {',
|
|
245
|
+
' const __dnToken = globalThis.__vsk_ssr_token;',
|
|
246
|
+
' delete globalThis.__vsk_ssr;',
|
|
247
|
+
' if (__dnToken) delete globalThis[`__vsk_ssr_data_${__dnToken}`];',
|
|
248
|
+
// NOT `delete globalThis.__vsk_ssr_token`: that global is a
|
|
249
|
+
// configurable AsyncLocalStorage accessor (ssr-store.ts), so `delete`
|
|
250
|
+
// removes the property definition and the process silently reverts to a
|
|
251
|
+
// process-global token — the cross-request data-slot race, for good. The
|
|
252
|
+
// token dies with the withSsrStore scope wrapped around this block instead.
|
|
253
|
+
' delete globalThis.__vsk_ssr_data;',
|
|
254
|
+
' }',
|
|
255
|
+
];
|
|
256
|
+
// The data-nav branch never runs renderFullPage/renderPageStream, so it needs
|
|
257
|
+
// its own request scope — otherwise its renderPage mints a token that is
|
|
258
|
+
// still live when the full-page render starts and the two share a data slot.
|
|
259
|
+
const dataNavWrap = (body) => [
|
|
260
|
+
' return withSsrStore(async () => {',
|
|
261
|
+
...body.map((l) => (l ? ' ' + l : l)),
|
|
262
|
+
' });',
|
|
251
263
|
];
|
|
252
264
|
if (layoutDecls.length > 0) {
|
|
253
265
|
dataCode = [
|
|
254
266
|
" if (request.headers.get('x-vesk-data') === '1') {",
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
267
|
+
...dataNavWrap([
|
|
268
|
+
' try {',
|
|
269
|
+
' let dataPage;',
|
|
270
|
+
' try {',
|
|
271
|
+
" dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
|
|
272
|
+
' } catch (err) {',
|
|
273
|
+
" if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
|
|
274
|
+
' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
|
|
275
|
+
` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
|
|
276
|
+
' }',
|
|
277
|
+
' let _dataHead = dataPage.head || \'\';',
|
|
278
|
+
' for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {',
|
|
279
|
+
" const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
|
|
280
|
+
' _dataHead = (_dl.head || \'\') + _dataHead;',
|
|
281
|
+
' }',
|
|
282
|
+
" return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
|
|
283
|
+
" headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
|
|
284
|
+
' });',
|
|
285
|
+
...dataNavCleanup,
|
|
286
|
+
]),
|
|
273
287
|
' }',
|
|
274
288
|
' return __renderHtml(params, url.href);',
|
|
275
289
|
].join('\n');
|
|
@@ -277,19 +291,21 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
277
291
|
else {
|
|
278
292
|
dataCode = [
|
|
279
293
|
" if (request.headers.get('x-vesk-data') === '1') {",
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
294
|
+
...dataNavWrap([
|
|
295
|
+
' try {',
|
|
296
|
+
' let dataPage;',
|
|
297
|
+
' try {',
|
|
298
|
+
" dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
|
|
299
|
+
' } catch (err) {',
|
|
300
|
+
" if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
|
|
301
|
+
' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
|
|
302
|
+
` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
|
|
303
|
+
' }',
|
|
304
|
+
" return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: dataPage.head || '' }), {",
|
|
305
|
+
" headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
|
|
306
|
+
' });',
|
|
307
|
+
...dataNavCleanup,
|
|
308
|
+
]),
|
|
293
309
|
' }',
|
|
294
310
|
' return __renderHtml(params, url.href);',
|
|
295
311
|
].join('\n');
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { RouteNode, ApiRouteNode, VeskPlugin, ServerEventContext, VeskEventHandlers, VeskSecurity, VeskCors, VeskRateLimit, VeskSecurityPreset, SecurityConfig, MiddlewareChainItem, MiddlewareExtractResult, AncestorLayout, BuildOptions, DevServerOptions, ProdServerOptions, SsrFunctionOptions, ApiFunctionOptions, ClientBundleOptions, ClientBundleFileEntry, ClientBundleChunkSpec, ClientBundleCache, ChunkEntry, ClientBundleResult, MonolithicBundleParts, Manifest, ManifestRouteEntry, ManifestActionEntry, ManifestPrerenderedEntry, SsgRouteResult, BuildResult, ImageRef, ImageResult, SeoCheckIssue, SeoAuditResult, CombinedPageInfo, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, VeskRequest, VeskResponse, SetCookieOptions, CookieStore, ServerRequest, SsrDataSink, MdProps, MdConfig, MdHtmlMode, MarkdownOptions, MdHtmlWarning, } from '@vesk/types';
|
|
1
|
+
export type { RouteNode, ApiRouteNode, VeskPlugin, ServerEventContext, VeskEventHandlers, VeskSecurity, VeskCors, VeskRateLimit, VeskSecurityPreset, SecurityConfig, MiddlewareChainItem, MiddlewareExtractResult, AncestorLayout, BuildOptions, DevServerOptions, ProdServerOptions, SsrFunctionOptions, ApiFunctionOptions, ClientBundleOptions, ClientBundleFileEntry, ClientBundleChunkSpec, ClientBundleCache, ChunkEntry, ClientBundleResult, MonolithicBundleParts, Manifest, ManifestRouteEntry, ManifestActionEntry, ManifestPrerenderedEntry, SsgRouteResult, BuildResult, ImageRef, ImageResult, SeoCheckIssue, SeoAuditResult, CombinedPageInfo, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, VeskRequest, VeskResponse, SetCookieOptions, CookieStore, ServerRequest, SsrDataSink, MdProps, MdConfig, MdHtmlMode, MarkdownOptions, MdHtmlWarning, VeskLeafComponent, VeskPrimitiveComponent, VeskTaggedLeafComponent, VeskComponentRegistry, VeskScope, } from '@vesk/types';
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,SAAS,GACV,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/adapter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk adapter — builds deployable .vesk/ output for Deno and Node serverless",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"sharp": "^0.35.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@vesk/compiler": "^0.2.
|
|
27
|
-
"@vesk/runtime": "^0.2.
|
|
28
|
-
"@vesk/types": "^0.2.
|
|
26
|
+
"@vesk/compiler": "^0.2.44",
|
|
27
|
+
"@vesk/runtime": "^0.2.44",
|
|
28
|
+
"@vesk/types": "^0.2.44"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/ws": "^8.18.1",
|