@vesk/adapter 0.2.35 → 0.2.37

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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EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAmDD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAKzD;AAkCD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAyBlD;AA4MD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmC5D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYxD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,GAAG,MAAM,CAwBnG;AAED,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,SAAS,EAAE,EACtB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CAma7B;AAMD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA+B3D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAUlE;AAoCD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/F"}
@@ -1,6 +1,7 @@
1
- import { readFileSync, existsSync, writeFileSync, unlinkSync, statSync, rmSync, mkdtempSync } from 'node:fs';
1
+ import { readFileSync, existsSync, writeFileSync, unlinkSync, statSync, rmSync, mkdtempSync, mkdirSync } from 'node:fs';
2
2
  import { resolve, join, dirname, relative, sep } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { tmpdir } from 'node:os';
4
5
  import { build } from './esbuild-fallback.js';
5
6
  import { stripCodeTypes } from '@vesk/compiler/src/strip-ts';
6
7
  import { parse } from '@vesk/compiler/src/parser';
@@ -1035,6 +1036,27 @@ let runtimeEntryId = 0;
1035
1036
  * every time).
1036
1037
  */
1037
1038
  const RUNTIME_ENTRY = '.runtime-tree-entry.mjs';
1039
+ /**
1040
+ * esbuild resolves entry points and absolute import specifiers with forward
1041
+ * slashes; a native Windows path (`C:\...`) is not resolvable.
1042
+ */
1043
+ function esbuildPath(p) {
1044
+ return sep === '/' ? p : p.split(sep).join('/');
1045
+ }
1046
+ /**
1047
+ * The tree-shake entry is written outside the project tree on purpose. It used
1048
+ * to be written into `node_modules/@vesk/runtime/dist`, which (a) tripped the
1049
+ * dev watcher on every build — an endless rebuild loop on Windows, where
1050
+ * `fs.watch` reports backslash paths that slipped past the `node_modules/`
1051
+ * skip check — and (b) raced concurrent builds, so one build could delete the
1052
+ * entry while another was still resolving it (`Could not resolve …`). The
1053
+ * entry now lives in a temp dir and imports the runtime by absolute path.
1054
+ */
1055
+ function runtimeTreeShakeEntry() {
1056
+ return join(tmpdir(), 'vesk-runtime-tree-shake', RUNTIME_ENTRY);
1057
+ }
1058
+ /** Serializes tree-shake builds so concurrent callers never share the entry file. */
1059
+ let treeShakeQueue = Promise.resolve();
1038
1060
  /**
1039
1061
  * Builds a single self-contained runtime module for the given used names.
1040
1062
  *
@@ -1044,7 +1066,12 @@ const RUNTIME_ENTRY = '.runtime-tree-entry.mjs';
1044
1066
  * const bindings. This replaces the old regex-based file concatenation, which
1045
1067
  * leaked runtime module-scope names into the page scope.
1046
1068
  */
1047
- export async function buildTreeShakenRuntime(runtimeDir, usedNames) {
1069
+ export function buildTreeShakenRuntime(runtimeDir, usedNames) {
1070
+ const run = treeShakeQueue.then(() => buildTreeShakenRuntimeNow(runtimeDir, usedNames));
1071
+ treeShakeQueue = run.catch(() => undefined);
1072
+ return run;
1073
+ }
1074
+ async function buildTreeShakenRuntimeNow(runtimeDir, usedNames) {
1048
1075
  const unique = [...new Set(usedNames)];
1049
1076
  const available = runtimeExportNames(runtimeDir);
1050
1077
  const missing = unique.filter((n) => !available.has(n));
@@ -1052,15 +1079,20 @@ export async function buildTreeShakenRuntime(runtimeDir, usedNames) {
1052
1079
  console.error(`vesk: runtime names not exported — ${missing.join(', ')}; falling back to full runtime`);
1053
1080
  return buildRuntimeCode(runtimeDir);
1054
1081
  }
1055
- const entry = join(runtimeDir, RUNTIME_ENTRY);
1082
+ const entry = runtimeTreeShakeEntry();
1083
+ const indexClient = esbuildPath(join(runtimeDir, 'index-client.js'));
1056
1084
  try {
1085
+ try {
1086
+ mkdirSync(dirname(entry), { recursive: true });
1087
+ }
1088
+ catch { /* exists */ }
1057
1089
  try {
1058
1090
  rmSync(entry);
1059
1091
  }
1060
1092
  catch { /* not present yet */ }
1061
- writeFileSync(entry, `export { ${unique.join(', ')} } from './index-client.js';\n`);
1093
+ writeFileSync(entry, `export { ${unique.join(', ')} } from ${JSON.stringify(indexClient)};\n`);
1062
1094
  const result = await build({
1063
- entryPoints: [entry],
1095
+ entryPoints: [esbuildPath(entry)],
1064
1096
  bundle: true,
1065
1097
  format: 'iife',
1066
1098
  globalName: '__veskRuntime',
@@ -1135,6 +1167,12 @@ async function buildMainBundle(routeTree, runtimeDir, codeSplit, mono, hmr, impo
1135
1167
  '\t\tconst p = nodes[0].parentNode;\n' +
1136
1168
  '\t\tp.insertBefore(start, nodes[0]);\n' +
1137
1169
  '\t\tp.insertBefore(end, nodes[nodes.length - 1].nextSibling);\n' +
1170
+ '\t\t// Client-surplus nodes (SSR rendered fewer items than the client data)\n' +
1171
+ '\t\t// are freshly claimed and still detached — move them into the region in\n' +
1172
+ '\t\t// client order before `end`, instead of stranding them off-parent.\n' +
1173
+ '\t\tfor (let i = 0; i < nodes.length; i++) {\n' +
1174
+ '\t\t\tif (nodes[i].parentNode === null) p.insertBefore(nodes[i], end);\n' +
1175
+ '\t\t}\n' +
1138
1176
  '\t\treturn;\n' +
1139
1177
  '\t}\n' +
1140
1178
  '\tfallback.appendChild(start);\n' +
package/dist/css.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  export declare const GLOBAL_CSS_URL = "/_vesk/static/global.css";
2
- /** Resolve the project's user stylesheet source (`src/global.css`, then `src/app.css`). */
2
+ /**
3
+ * Resolve the project's user stylesheet source. The app-directory convention
4
+ * (`app/global.css`, i.e. `resolve(appDir, 'global.css')`) is checked first;
5
+ * the legacy `src/global.css` and `src/app.css` locations are still honoured
6
+ * so existing projects keep working without a file move.
7
+ */
3
8
  export declare function resolveUserCssPath(appDir: string): string | null;
4
- /** True when the project has a user stylesheet source (`src/global.css` or `src/app.css`). */
9
+ /** True when the project has a user stylesheet source (`app/global.css`, `src/global.css` or `src/app.css`). */
5
10
  export declare function hasUserCss(appDir: string): boolean;
6
11
  /** True when a non-empty `global.css` was produced for the build (prod disk output). */
7
12
  export declare function hasBuiltGlobalCss(outDir: string): boolean;
package/dist/css.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAEzD,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMhE;AAED,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAE9F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,EAAE,CAGpE"}
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQhE;AAED,gHAAgH;AAChH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAE9F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,EAAE,CAGpE"}
package/dist/css.js CHANGED
@@ -6,17 +6,26 @@
6
6
  * several ad-hoc copies.
7
7
  *
8
8
  * Vesk follows the single-file CSS convention used by other frameworks
9
- * (Next.js/Remix/SvelteKit): a single `src/global.css` is the stylesheet
10
- * source. When the Tailwind plugin is active the whole file is compiled into
11
- * one `/_vesk/static/global.css`; otherwise the user CSS is served as-is from
12
- * the same URL. There is no separate `_tailwind.css` anymore — user rules and
13
- * the compiled Tailwind output live in the same file, in one `<link>`.
9
+ * (Next.js/Remix/SvelteKit): a single `global.css` in the app directory
10
+ * (`app/global.css`) is the stylesheet source. When the Tailwind plugin is
11
+ * active the whole file is compiled into one `/_vesk/static/global.css`;
12
+ * otherwise the user CSS is served as-is from the same URL. There is no
13
+ * separate `_tailwind.css` anymore — user rules and the compiled Tailwind
14
+ * output live in the same file, in one `<link>`.
14
15
  */
15
16
  import { readFileSync, existsSync } from 'node:fs';
16
17
  import { resolve } from 'node:path';
17
18
  export const GLOBAL_CSS_URL = '/_vesk/static/global.css';
18
- /** Resolve the project's user stylesheet source (`src/global.css`, then `src/app.css`). */
19
+ /**
20
+ * Resolve the project's user stylesheet source. The app-directory convention
21
+ * (`app/global.css`, i.e. `resolve(appDir, 'global.css')`) is checked first;
22
+ * the legacy `src/global.css` and `src/app.css` locations are still honoured
23
+ * so existing projects keep working without a file move.
24
+ */
19
25
  export function resolveUserCssPath(appDir) {
26
+ const appCssSrc = resolve(appDir, 'global.css');
27
+ if (existsSync(appCssSrc))
28
+ return appCssSrc;
20
29
  const cssSrc = resolve(appDir, '..', 'src', 'global.css');
21
30
  if (existsSync(cssSrc))
22
31
  return cssSrc;
@@ -25,7 +34,7 @@ export function resolveUserCssPath(appDir) {
25
34
  return altCssSrc;
26
35
  return null;
27
36
  }
28
- /** True when the project has a user stylesheet source (`src/global.css` or `src/app.css`). */
37
+ /** True when the project has a user stylesheet source (`app/global.css`, `src/global.css` or `src/app.css`). */
29
38
  export function hasUserCss(appDir) {
30
39
  return resolveUserCssPath(appDir) !== null;
31
40
  }
@@ -964,7 +964,7 @@ export async function addPluginToConfig(projectDir, pkg) {
964
964
  let source;
965
965
  if (!path) {
966
966
  const importName = importNameForPackage(pkg);
967
- const entry = pkg === '@vesk/plugin-tailwind' ? `${importName}({ entry: 'src/global.css', appDir: 'app' })` : `${importName}()`;
967
+ const entry = pkg === '@vesk/plugin-tailwind' ? `${importName}({ entry: 'app/global.css', appDir: 'app' })` : `${importName}()`;
968
968
  source = `import { defineConfig } from '@vesk/compiler'\nimport ${importName} from '${pkg}'\n\nexport default defineConfig({\n\tplugins: [\n\t\t${entry}\n\t]\n})\n`;
969
969
  target = resolve(projectDir, 'vesk.config.ts');
970
970
  await writeConfigSource(projectDir, source);
@@ -1043,7 +1043,7 @@ export async function addPluginToConfig(projectDir, pkg) {
1043
1043
  source = importLine + source;
1044
1044
  }
1045
1045
  }
1046
- const entry = pkg === '@vesk/plugin-tailwind' ? `${importName}({ entry: 'src/global.css', appDir: 'app' })` : `${importName}()`;
1046
+ const entry = pkg === '@vesk/plugin-tailwind' ? `${importName}({ entry: 'app/global.css', appDir: 'app' })` : `${importName}()`;
1047
1047
  const newSource = insertIntoPluginsArray(source, entry);
1048
1048
  if (newSource === source)
1049
1049
  return;
package/dist/hmr.js CHANGED
@@ -344,7 +344,7 @@ function regenerateSsrFunction(routeNode, appDir, outDir, componentMap, options)
344
344
  for (const [compName, compPath] of compMap) {
345
345
  const compSrc = readFileSync(compPath, 'utf-8');
346
346
  const escapedSrc = escapeSource(compSrc);
347
- compRegEntries.push(` registry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n const _src = \`${escapedSrc}\`;\n const _comp = ${JSON.stringify(compName)};\n const _compiled = (() => { try { setVskHydrate(true); return compileFile(_src, { sourcePath: ${JSON.stringify(compPath)} }); } catch { return null; } finally { setVskHydrate(false); } })();\n const result = await renderPage(_src, _comp, props, __registry, { hydrate: true, cached: _compiled, sourcePath: ${JSON.stringify(compPath)} });\n return result.body;\n })`);
347
+ compRegEntries.push(` __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n const _src = \`${escapedSrc}\`;\n const _comp = ${JSON.stringify(compName)};\n const _compiled = (() => { try { setVskHydrate(true); return compileFile(_src, { sourcePath: ${JSON.stringify(compPath)} }); } catch { return null; } finally { setVskHydrate(false); } })();\n const result = await renderPage(_src, _comp, props, __registry, { hydrate: true, cached: _compiled, sourcePath: ${JSON.stringify(compPath)} });\n return result.body;\n })`);
348
348
  }
349
349
  if (compRegEntries.length > 0) {
350
350
  registryCode = `const __componentRegistry = new Map();\n{\n${compRegEntries.join('\n')}\n}\n`;
@@ -1 +1 @@
1
- {"version":3,"file":"platform-handler.d.ts","sourceRoot":"","sources":["../src/platform-handler.ts"],"names":[],"mappings":"AAGA,OAA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BAAoB;IACnC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAgBD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAwLjF;AAED,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsFzF;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -82,6 +82,30 @@ ${prerenderedList}
82
82
  ${isrCache}
83
83
  const __routes = [${routeEntries.join(',\n')}];
84
84
 
85
+ async function __invokeRoute(route, request) {
86
+ try {
87
+ return await route.handler(request);
88
+ } catch (e) {
89
+ if (e && typeof e === 'object' && e.name === 'Redirect') {
90
+ return new Response(null, {
91
+ status: Number(e.status) || 302,
92
+ headers: { Location: String(e.url || '/') },
93
+ });
94
+ }
95
+ if (e && typeof e === 'object' && e.name === 'NotFoundError') {
96
+ return new Response('<!DOCTYPE html><html><body><h1>404</h1><p>Not Found</p></body></html>', {
97
+ status: 404,
98
+ headers: { 'Content-Type': 'text/html' },
99
+ });
100
+ }
101
+ throw e;
102
+ }
103
+ }
104
+
105
+ function __escapeScript(json) {
106
+ return json.split('<').join('\\u003c').split('\\u2028').join('\\u2028').split('\\u2029').join('\\u2029');
107
+ }
108
+
85
109
  function __matchPath(pattern, pathname) {
86
110
  const patternParts = pattern.split('/').filter(Boolean);
87
111
  const pathParts = pathname.split('/').filter(Boolean);
@@ -112,6 +136,24 @@ ${serverStoreLine}
112
136
  return new Response(null, { status: 308, headers: { Location: '/_vesk/static/public' + (pathname.endsWith('/') ? pathname + 'index.html' : pathname + '.html') } });
113
137
  }
114
138
 
139
+ // Serve the SSR-data handoff the page references (script tag /ssr-data.js?t=...).
140
+ // The render stashed the payload in the shared global store — mirror the node
141
+ // prod/dev servers so edge/serverless hydration never re-fetches resources that
142
+ // SSR already resolved. Entry is consumed on read (bound store).
143
+ if (pathname === '/ssr-data.js') {
144
+ const dataToken = url.searchParams.get('t') || '';
145
+ const dataStore = (globalThis.__vsk_ssr_data_store || {});
146
+ const payload = dataStore[dataToken];
147
+ if (payload) delete dataStore[dataToken];
148
+ const dataLines = [];
149
+ if (payload && payload.props) dataLines.push('globalThis.__vesk_props = ' + __escapeScript(JSON.stringify(payload.props)) + ';');
150
+ if (payload && payload.ssrData) dataLines.push('globalThis.__vsk_ssr_data = ' + __escapeScript(JSON.stringify(payload.ssrData)) + ';');
151
+ return new Response(dataLines.join('\\n') || '// no ssr data', {
152
+ status: 200,
153
+ headers: { 'Content-Type': 'application/javascript', 'Cache-Control': 'no-store' },
154
+ });
155
+ }
156
+
115
157
  ${eventsStartLine}
116
158
  let mwCtx = { params: {}, url, locals: ${localsSeed}, cookies: {}, request, resolveUrl(u) { return new URL(u, request.url).href; }, set() {}, get() { return undefined; } };
117
159
  if (${hasMwLiteral}) {
@@ -141,7 +183,7 @@ ${eventsRequestLine}
141
183
  if (!params) continue;
142
184
 
143
185
  if (route.type === 'api') {
144
- return await route.handler(request);
186
+ return await __invokeRoute(route, request);
145
187
  }
146
188
 
147
189
  if (route.revalidate && route.revalidate > 0 && !isDataRequest) {
@@ -154,7 +196,7 @@ ${eventsRequestLine}
154
196
  }
155
197
  }
156
198
 
157
- const response = await route.handler(request);
199
+ const response = await __invokeRoute(route, request);
158
200
 
159
201
  if (route.revalidate && route.revalidate > 0 && !isDataRequest) {
160
202
  const html = await response.clone().text();
@@ -1 +1 @@
1
- {"version":3,"file":"prod-server.d.ts","sourceRoot":"","sources":["../src/prod-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2D,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AA8CjG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAIzE;AA+FD,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAwbxI"}
1
+ {"version":3,"file":"prod-server.d.ts","sourceRoot":"","sources":["../src/prod-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2D,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AA8CjG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAIzE;AA+FD,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA8bxI"}
@@ -486,6 +486,12 @@ export async function startProdServer(outDir, options) {
486
486
  }
487
487
  catch (e) {
488
488
  const err = e instanceof Error ? e : new Error(String(e));
489
+ if (err.name === 'Redirect') {
490
+ const redirect = err;
491
+ res.writeHead(Number(redirect.status) || 302, { Location: typeof redirect.url === 'string' ? redirect.url : '/' });
492
+ res.end();
493
+ return;
494
+ }
489
495
  if (err.name === 'NotFoundError') {
490
496
  res.writeHead(404, { 'Content-Type': 'text/html' });
491
497
  res.end(notFoundHtml || '<!DOCTYPE html><html><body><h1>404</h1><p>Not Found</p></body></html>');
@@ -141,7 +141,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
141
141
  const compMap = componentMap || new Map();
142
142
  for (const [compName, compPath] of compMap) {
143
143
  const plan = precompilePlan(compPath);
144
- compRegEntries.push(` (() => {\n const _compiled = (() => { try { return hydratePrecompile(${plan}); } catch { return null; } })();\n registry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });\n return result.body;\n });\n })();`);
144
+ compRegEntries.push(` (() => {\n const _compiled = (() => { try { return hydratePrecompile(${plan}); } catch { return null; } })();\n __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });\n return result.body;\n });\n })();`);
145
145
  }
146
146
  if (compRegEntries.length > 0) {
147
147
  registryCode = 'const __componentRegistry = new Map();\n{\n' + compRegEntries.join('\n') + '\n}\n';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/adapter",
3
- "version": "0.2.35",
3
+ "version": "0.2.37",
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.35",
27
- "@vesk/runtime": "^0.2.35",
28
- "@vesk/types": "^0.2.35"
26
+ "@vesk/compiler": "^0.2.37",
27
+ "@vesk/runtime": "^0.2.37",
28
+ "@vesk/types": "^0.2.37"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/ws": "^8.18.1",