@vesk/adapter 0.2.43 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"client-bundle.d.ts","sourceRoot":"","sources":["../src/client-bundle.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,EAAmF,MAAM,yBAAyB,CAAC;AAoCnL;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA8BhE;AAED;;;;;GAKG;AACH,UAAU,YAAY;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC7B,EAAE,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,IAAI,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE;gBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;IACtH,WAAW,CAAC,EAAE;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1C,YAAY,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,CAAC,EAAE;gBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,MAAM,CAAC,EA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@@ -5,7 +5,8 @@ import { tmpdir } from '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';
@@ -728,7 +729,9 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
728
729
  // One parse/IR pass feeds both client modes AND the component-name
729
730
  // lookup — the dev hot path pays the acorn+TS parse once per edit
730
731
  // instead of three times.
731
- const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths } = 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);
732
735
  // Cache keeps the import-carrying codes so a warm build can re-fold them
733
736
  // into its own fresh accumulator; the emitted codes are import-stripped.
734
737
  // The bodies/specs/scoped artifacts are cached too so warm replay never
@@ -797,6 +800,11 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
797
800
  }
798
801
  const codeSplit = !!(options?.codeSplit);
799
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();
800
808
  /** Run every active plugin's `onTransformJS` over an emitted bundle/chunk source. */
801
809
  async function applyTransformPlugins(code, filePath) {
802
810
  if (transformPlugins.length === 0)
@@ -969,6 +977,7 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
969
977
  for (const chunk of chunks) {
970
978
  transformedChunks.push({ ...chunk, code: await applyTransformPlugins(chunk.code, chunk.name) });
971
979
  }
980
+ componentOwners.report('client bundle');
972
981
  return { main: await applyTransformPlugins(main, 'client.js'), chunks: transformedChunks, cachedFileHits, compiledFiles, mainFromCache, editedSources, editedNames };
973
982
  }
974
983
  else {
@@ -982,6 +991,8 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
982
991
  seen.add(filePath);
983
992
  const src = readFileSync(filePath, 'utf-8');
984
993
  resolveVskImports(filePath, (p, n) => compileFileMono(p, n || ''));
994
+ for (const cn of vskComponentNames(src, filePath))
995
+ componentOwners.claim(cn, filePath);
985
996
  // Share one name allocator so the comp and hyd contributions (which are
986
997
  // joined into a single scoped block below) never reuse `$n` names.
987
998
  const monoAlloc = nameAllocFor(filePath);
@@ -1038,6 +1049,7 @@ export async function generateClientBundle(routeTree, appDir, componentMap, opti
1038
1049
  componentLines, hydratorLines, aliasLines, hydratorAliasLines,
1039
1050
  }, !!options?.hmr, !!options?.importRuntime, runtimeImportNames, options?.routeDataCache);
1040
1051
  // Mono (non-codeSplit) builds are the production path — no incremental cache.
1052
+ componentOwners.report('client bundle');
1041
1053
  return { main: await applyTransformPlugins(main, 'client.js'), chunks: [] };
1042
1054
  }
1043
1055
  }
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;I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BAAwB;IACvC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,wBAA6B,GAClC,eAAe,CAsGjB;AAoSD,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC;IACD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClE,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvH,WAAW,EAAE,MAAM,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CACnD,CA6KA"}
package/dist/hmr.js CHANGED
@@ -355,6 +355,14 @@ function regenerateSsrFunction(routeNode, appDir, outDir, componentMap, options)
355
355
  let 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
- " for (let _i = _layoutSrcList.length - 1; _i > 0; _i--) {",
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
- ' if (err && (err.name === \'NotFoundError\' || err.name === \'Redirect\')) throw err;',
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,CAoYtD"}
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"}
@@ -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
- ' } finally {',
245
- ' const __dnToken = globalThis.__vsk_ssr_token;',
246
- ' delete globalThis.__vsk_ssr;',
247
- ' if (__dnToken) delete globalThis[`__vsk_ssr_data_${__dnToken}`];',
248
- ' delete globalThis.__vsk_ssr_token;',
249
- ' delete globalThis.__vsk_ssr_data;',
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
- ' try {',
256
- ' let dataPage;',
257
- ' try {',
258
- " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
259
- ' } catch (err) {',
260
- " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
261
- ' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
262
- ` 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' } });`,
263
- ' }',
264
- ' let _dataHead = dataPage.head || \'\';',
265
- ' for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {',
266
- " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
267
- ' _dataHead = (_dl.head || \'\') + _dataHead;',
268
- ' }',
269
- " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
270
- " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
271
- ' });',
272
- ...dataNavCleanup,
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
- ' try {',
281
- ' let dataPage;',
282
- ' try {',
283
- " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
284
- ' } catch (err) {',
285
- " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
286
- ' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
287
- ` 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' } });`,
288
- ' }',
289
- " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: dataPage.head || '' }), {",
290
- " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
291
- ' });',
292
- ...dataNavCleanup,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/adapter",
3
- "version": "0.2.43",
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.43",
27
- "@vesk/runtime": "^0.2.43",
28
- "@vesk/types": "^0.2.43"
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",