vike-lite 1.0.20 → 1.1.0

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,2 +1,2 @@
1
- import { t as matchRoute } from "../matchRoute-BONrLRYy.mjs";
1
+ import { t as matchRoute } from "../matchRoute-BF9hAXiF.mjs";
2
2
  export { matchRoute };
@@ -0,0 +1,38 @@
1
+ //#region src/shared/matchRoute.ts
2
+ const regexCache = /* @__PURE__ */ new Map();
3
+ function matchRoute(urlPathname, routes) {
4
+ for (const route of routes) {
5
+ if (!route.path.includes(":")) {
6
+ if (route.path === urlPathname || route.path + "/" === urlPathname) return {
7
+ route,
8
+ routeParams: {}
9
+ };
10
+ continue;
11
+ }
12
+ let compiled = regexCache.get(route.path);
13
+ if (!compiled) {
14
+ const paramNames = [];
15
+ const regexPath = route.path.replace(/:([^/]+)/g, (_, name) => {
16
+ paramNames.push(name);
17
+ return "([^/]+)";
18
+ });
19
+ compiled = {
20
+ regex: new RegExp(`^${regexPath}/?$`),
21
+ paramNames
22
+ };
23
+ regexCache.set(route.path, compiled);
24
+ }
25
+ const match = urlPathname.match(compiled.regex);
26
+ if (match) {
27
+ const routeParams = {};
28
+ for (let i = 0; i < compiled.paramNames.length; i++) routeParams[compiled.paramNames[i]] = match[i + 1];
29
+ return {
30
+ route,
31
+ routeParams
32
+ };
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ //#endregion
38
+ export { matchRoute as t };
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as matchRoute } from "./matchRoute-BONrLRYy.mjs";
1
+ import { t as matchRoute } from "./matchRoute-BF9hAXiF.mjs";
2
2
  import { n as store } from "./store-CfUB1COP.mjs";
3
3
  //#region src/utils/serializeContext.ts
4
4
  const ESCAPE_LOOKUP = {
@@ -95,7 +95,7 @@ async function buildPageContext(urlPathname, urlOriginal, isJsonRequest) {
95
95
  LayoutModule
96
96
  };
97
97
  }
98
- async function renderErrorPage(req, status, originalPathname, error) {
98
+ async function renderErrorPage(req, status, urlPathname, error) {
99
99
  if (!store.errorRoute) return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
100
100
  try {
101
101
  const { default: onRenderHtml } = await store.config.onRenderHtml();
@@ -106,7 +106,7 @@ async function renderErrorPage(req, status, originalPathname, error) {
106
106
  ]);
107
107
  const pageContext = {
108
108
  urlOriginal: req.url,
109
- urlPathname: originalPathname,
109
+ urlPathname,
110
110
  routeParams: {},
111
111
  is404: status === 404,
112
112
  is500: status === 500,
package/dist/vite.mjs CHANGED
@@ -76,9 +76,10 @@ async function injectFOUCStyles(server, html) {
76
76
  if (headEndIndex === -1) return html;
77
77
  return `${html.slice(0, headEndIndex)}<style type="text/css" data-vite-dev-fouc>${cssContent}</style>${html.slice(headEndIndex)}`;
78
78
  }
79
- function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", apiPrefix = "/api" } = {}) {
79
+ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPrefix = "/api" } = {}) {
80
80
  const isProd = process.env.NODE_ENV === "production";
81
81
  let viteConfigRoot;
82
+ let outDir;
82
83
  const virtualModuleId = "virtual:routes";
83
84
  const virtualManifestId = "virtual:client-manifest";
84
85
  const virtualAdapterId = "virtual:vike-lite-solid";
@@ -92,13 +93,15 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
92
93
  const resolvedVirtualEntryServerId = "\0virtual:entry-server";
93
94
  return {
94
95
  name: "vike-lite",
95
- config() {
96
+ config(config) {
97
+ outDir = config.build?.outDir ?? "dist";
98
+ const emptyOutDir = config.build?.emptyOutDir;
96
99
  return {
97
100
  appType: "custom",
98
101
  environments: {
99
102
  client: { build: {
100
- outDir: "../dist/client",
101
- emptyOutDir: true,
103
+ outDir: path.join(outDir, "client"),
104
+ emptyOutDir: emptyOutDir ?? true,
102
105
  cssMinify: true,
103
106
  manifest: true,
104
107
  rolldownOptions: {
@@ -116,8 +119,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
116
119
  } },
117
120
  ssr: { build: {
118
121
  target: "esnext",
119
- outDir: "../dist/server",
120
- emptyOutDir: true,
122
+ outDir: path.join(outDir, "server"),
123
+ emptyOutDir: emptyOutDir ?? true,
121
124
  rolldownOptions: {
122
125
  input: virtualEntryServerId,
123
126
  output: {
@@ -170,7 +173,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
170
173
  }
171
174
  if (id === resolvedVirtualManifestId) {
172
175
  if (!isProd || !options?.ssr) return "export default {}";
173
- const manifestPath = path.join(viteConfigRoot, "../dist/client/.vite/manifest.json");
176
+ const manifestPath = path.join(viteConfigRoot, outDir, "client/.vite/manifest.json");
174
177
  return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
175
178
  }
176
179
  if (id === resolvedVirtualEntryClientId) return `import { routes, errorRoute } from '${virtualModuleId}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.0.20",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -56,7 +56,7 @@
56
56
  "vite": ">=8"
57
57
  },
58
58
  "engines": {
59
- "node": ">=22"
59
+ "node": "^20.19.0 || >=22.12.0"
60
60
  },
61
61
  "packageManager": "yarn@4.17.0"
62
62
  }
@@ -1,24 +0,0 @@
1
- //#region src/shared/matchRoute.ts
2
- function matchRoute(urlPathname, routes) {
3
- for (const route of routes) {
4
- const paramNames = [];
5
- const regexPath = route.path.replaceAll(/:([^/]+)/g, (_, paramName) => {
6
- paramNames.push(paramName);
7
- return "([^/]+)";
8
- });
9
- const regex = new RegExp(`^${regexPath}/?$`);
10
- const match = urlPathname.match(regex);
11
- if (match) {
12
- let index = 0;
13
- const routeParams = {};
14
- for (const name of paramNames) routeParams[name] = match[++index];
15
- return {
16
- route,
17
- routeParams
18
- };
19
- }
20
- }
21
- return null;
22
- }
23
- //#endregion
24
- export { matchRoute as t };