vike-lite 1.6.0 → 1.6.2

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.
@@ -2,8 +2,8 @@ import { t as Config } from "../index-Dt5n1zWh.mjs";
2
2
 
3
3
  //#region src/server/store.d.ts
4
4
  interface VikeState {
5
- routes: typeof import('virtual:routes')['routes'];
6
- errorRoute: typeof import('virtual:routes')['errorRoute'] | null;
5
+ routes: any[];
6
+ errorRoute: any | null;
7
7
  config: Config | null;
8
8
  manifest: Manifest | undefined;
9
9
  }
package/dist/server.mjs CHANGED
@@ -74,8 +74,8 @@ async function buildPageContext(urlPathname, urlOriginal, isJsonRequest) {
74
74
  urlPathname
75
75
  };
76
76
  const [dataMod, titleMod, PageModule, HeadModule, LayoutModule] = await Promise.all([
77
- route.Data?.() ?? null,
78
- route.Title?.() ?? null,
77
+ route.data?.() ?? null,
78
+ route.title?.() ?? null,
79
79
  isJsonRequest ? null : route.Page(),
80
80
  isJsonRequest ? null : route.Head?.() ?? null,
81
81
  isJsonRequest ? null : route.Layout?.() ?? null
package/dist/vite.mjs CHANGED
@@ -4,11 +4,6 @@ import { Readable } from "node:stream";
4
4
  import { pipeline } from "node:stream/promises";
5
5
  import { loadEnv } from "vite";
6
6
  //#region src/utils/generateRoutes.ts
7
- const pageExtensions = [".ts", ".js"];
8
- const pageExtensionsX = [".tsx", ".jsx"];
9
- function findFile(files, basename, extensions) {
10
- return files.find((file) => extensions.some((ext) => file === `${basename}${ext}`));
11
- }
12
7
  function generateRoutes(viteRoot, pagesDir) {
13
8
  const pagesAbsPath = path.resolve(viteRoot, pagesDir);
14
9
  if (!fs.existsSync(pagesAbsPath)) return { routes: [] };
@@ -17,20 +12,15 @@ function generateRoutes(viteRoot, pagesDir) {
17
12
  function walk(dir, routePath, parentLayout, parentHead) {
18
13
  const files = fs.readdirSync(dir);
19
14
  const importPath = path.relative(viteRoot, dir).replaceAll("\\", "/");
20
- const layoutFile = findFile(files, "+Layout", pageExtensionsX);
21
- const currentLayout = layoutFile ? `${importPath}/${layoutFile}` : parentLayout;
22
- const headFile = findFile(files, "+Head", pageExtensionsX);
23
- const currentHead = headFile ? `${importPath}/${headFile}` : parentHead;
24
- const pageFile = findFile(files, "+Page", pageExtensionsX);
25
- if (pageFile) {
15
+ const currentLayout = files.includes("+Layout.tsx") ? `${importPath}/+Layout.tsx` : parentLayout;
16
+ const currentHead = files.includes("+Head.tsx") ? `${importPath}/+Head.tsx` : parentHead;
17
+ if (files.includes("+Page.tsx")) {
26
18
  const route = {
27
19
  path: routePath || "/",
28
- page: `${importPath}/${pageFile}`
20
+ page: `${importPath}/+Page.tsx`,
21
+ hasData: files.includes("+data.ts"),
22
+ hasTitle: files.includes("+title.ts")
29
23
  };
30
- const dataFile = findFile(files, "+data", pageExtensions);
31
- if (dataFile) route.data = `${importPath}/${dataFile}`;
32
- const titleFile = findFile(files, "+title", pageExtensions);
33
- if (titleFile) route.title = `${importPath}/${titleFile}`;
34
24
  if (currentLayout) route.layout = currentLayout;
35
25
  if (currentHead) route.head = currentHead;
36
26
  routes.push(route);
@@ -39,10 +29,9 @@ function generateRoutes(viteRoot, pagesDir) {
39
29
  const fullPath = path.join(dir, file);
40
30
  if (!fs.statSync(fullPath).isDirectory()) continue;
41
31
  if (file === "_error") {
42
- const errorPageFile = findFile(fs.readdirSync(fullPath), "+Page", pageExtensionsX);
43
- if (errorPageFile) errorRoute = {
32
+ if (fs.readdirSync(fullPath).includes("+Page.tsx")) errorRoute = {
44
33
  path: "_error",
45
- page: `${importPath}/_error/${errorPageFile}`,
34
+ page: `${importPath}/_error/+Page.tsx`,
46
35
  layout: currentLayout,
47
36
  head: currentHead
48
37
  };
@@ -183,11 +172,10 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
183
172
  code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('/${r.page}'),`;
184
173
  if (r.head) code += `head:'${r.head}',Head:()=>import('/${r.head}'),`;
185
174
  if (r.layout) code += `layout:'${r.layout}',Layout:()=>import('/${r.layout}'),`;
186
- if (r.data) code += `data:'${r.data}',`;
187
- if (r.title) code += `title:'${r.title}',`;
175
+ code += `hasData:${r.hasData},hasTitle:${r.hasTitle},`;
188
176
  if (isSSR) {
189
- if (r.data) code += `Data:()=>import('/${r.data}'),`;
190
- if (r.title) code += `Title:()=>import('/${r.title}'),`;
177
+ if (r.hasData) code += `data:()=>import('/${r.page.replace("+Page.tsx", "+data.ts")}'),`;
178
+ if (r.hasTitle) code += `title:()=>import('/${r.page.replace("+Page.tsx", "+title.ts")}'),`;
191
179
  }
192
180
  code += "},";
193
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",