@edgeone/nuxt-pages 1.0.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.
Files changed (47) hide show
  1. package/README.md +275 -0
  2. package/dist/build/content/server.js +18 -0
  3. package/dist/build/content/static.js +17 -0
  4. package/dist/build/functions/server.js +19 -0
  5. package/dist/build/plugin-context.js +18 -0
  6. package/dist/build/routes.js +18 -0
  7. package/dist/build/templates/nuxt-handler-backup.js +305 -0
  8. package/dist/build/templates/nuxt-handler-monorepo.tmpl-ipx_backup.js +511 -0
  9. package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +243 -0
  10. package/dist/build/templates/nuxt-handler.tmpl.js +212 -0
  11. package/dist/esm-chunks/chunk-5YBUNNZ4.js +81 -0
  12. package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
  13. package/dist/esm-chunks/chunk-6YERJDAJ.js +208 -0
  14. package/dist/esm-chunks/chunk-GX4Z7KQX.js +15065 -0
  15. package/dist/esm-chunks/chunk-HBXUWFGE.js +19 -0
  16. package/dist/esm-chunks/chunk-HY3HNABZ.js +87 -0
  17. package/dist/esm-chunks/chunk-KGYBHZC3.js +1467 -0
  18. package/dist/esm-chunks/chunk-MMMRMLH2.js +132 -0
  19. package/dist/esm-chunks/chunk-NJ4SUJNF.js +5635 -0
  20. package/dist/esm-chunks/chunk-QG7JLDXY.js +127 -0
  21. package/dist/esm-chunks/chunk-RPSYO4VM.js +562 -0
  22. package/dist/esm-chunks/chunk-UOPC2N5A.js +69 -0
  23. package/dist/esm-chunks/chunk-V2LFVP3C.js +838 -0
  24. package/dist/index.js +61 -0
  25. package/dist/run/config.js +17 -0
  26. package/dist/run/constants.js +17 -0
  27. package/dist/run/handlers/cache.cjs +1410 -0
  28. package/dist/run/handlers/nuxt-cache.cjs +200 -0
  29. package/dist/run/handlers/nuxt-server.js +156 -0
  30. package/dist/run/handlers/request-context.cjs +148 -0
  31. package/dist/run/handlers/server.js +77 -0
  32. package/dist/run/handlers/tags-handler.cjs +177 -0
  33. package/dist/run/handlers/tracer.cjs +1004 -0
  34. package/dist/run/handlers/use-cache-handler.js +220 -0
  35. package/dist/run/handlers/wait-until.cjs +123 -0
  36. package/dist/run/headers.js +17 -0
  37. package/dist/run/revalidate.js +34 -0
  38. package/dist/run/storage/regional-blob-store.cjs +64 -0
  39. package/dist/run/storage/request-scoped-in-memory-cache.cjs +1582 -0
  40. package/dist/run/storage/storage.cjs +191 -0
  41. package/dist/shared/blob-types.cjs +37 -0
  42. package/dist/shared/blobkey.js +25 -0
  43. package/dist/shared/cache-types.cjs +33 -0
  44. package/dist/shared/nuxt-cache-types.cjs +18 -0
  45. package/dist/types/options.js +6 -0
  46. package/dist/utils.js +25 -0
  47. package/package.json +58 -0
@@ -0,0 +1,208 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ getHandlersArrayWithAST
9
+ } from "./chunk-GX4Z7KQX.js";
10
+
11
+ // src/build/routes.ts
12
+ import * as fs from "fs";
13
+ import * as path from "path";
14
+ var convertNuxtRoutePattern = (path2) => {
15
+ if (!path2.includes("[") && !path2.includes("_")) {
16
+ return path2;
17
+ }
18
+ let convertedPath = path2;
19
+ const catchAllMatch = path2.match(/\[\.\.\.([^\]]+)\]/);
20
+ if (catchAllMatch) {
21
+ const paramName = catchAllMatch[1];
22
+ convertedPath = convertedPath.replace(/\[\.\.\.([^\]]+)\]/g, `:${paramName}*`);
23
+ }
24
+ const dynamicMatch = path2.match(/\[([^\]]+)\]/);
25
+ if (dynamicMatch) {
26
+ const paramName = dynamicMatch[1];
27
+ convertedPath = convertedPath.replace(/\[([^\]]+)\]/g, `:${paramName}`);
28
+ }
29
+ const underscoreMatch = path2.match(/_([^\/\.]+)/);
30
+ if (underscoreMatch) {
31
+ const paramName = underscoreMatch[1];
32
+ convertedPath = convertedPath.replace(/_([^\/\.]+)/g, `:${paramName}`);
33
+ }
34
+ return convertedPath;
35
+ };
36
+ var createNuxtPagesRouteMeta = async (ctx) => {
37
+ const routeMap = {};
38
+ const prerenderRoutes = await ctx.getPrerenderRoutes();
39
+ if (prerenderRoutes && Array.isArray(prerenderRoutes)) {
40
+ for (const route of prerenderRoutes) {
41
+ routeMap[route] = {
42
+ isStatic: true
43
+ };
44
+ }
45
+ }
46
+ const staticPages = await ctx.getStaticPages();
47
+ if (staticPages && Array.isArray(staticPages)) {
48
+ for (const page of staticPages) {
49
+ if (!routeMap[page]) {
50
+ routeMap[page] = {};
51
+ }
52
+ routeMap[page].isStatic = true;
53
+ }
54
+ }
55
+ const routesManifest = await ctx.getRoutesManifest();
56
+ if (routesManifest) {
57
+ if (routesManifest.routes) {
58
+ for (let [route, routeInfo] of Object.entries(routesManifest.routes)) {
59
+ route = routeInfo.path;
60
+ if (!routeMap[route]) {
61
+ routeMap[route] = {};
62
+ }
63
+ if (routeInfo.ssr !== void 0 && routeInfo.ssr) {
64
+ routeMap[route].ssr = routeInfo.ssr;
65
+ }
66
+ if (routeInfo.prerender !== void 0) {
67
+ routeMap[route].isStatic = routeInfo.prerender;
68
+ }
69
+ if (routeInfo.swr !== void 0 && routeInfo.swr) {
70
+ routeMap[route].isr = routeInfo.swr;
71
+ }
72
+ if (routeInfo.isr !== void 0 && routeInfo.isr) {
73
+ routeMap[route].isr = routeInfo.isr;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ const convertedRouteMap = {};
79
+ const pathsToDelete = [];
80
+ for (const [routePath, routeConfig] of Object.entries(routeMap)) {
81
+ const convertedPath = convertNuxtRoutePattern(routePath);
82
+ if (convertedPath !== routePath) {
83
+ pathsToDelete.push(routePath);
84
+ convertedRouteMap[convertedPath] = routeConfig;
85
+ }
86
+ }
87
+ for (const pathToDelete of pathsToDelete) {
88
+ delete routeMap[pathToDelete];
89
+ }
90
+ Object.assign(routeMap, convertedRouteMap);
91
+ const routesArray = Object.entries(routeMap).map(([path2, config]) => ({
92
+ path: path2,
93
+ ...config
94
+ }));
95
+ const edgeOneDir = path.join(process.cwd(), ".edgeone");
96
+ if (!fs.existsSync(edgeOneDir)) {
97
+ fs.mkdirSync(edgeOneDir, { recursive: true });
98
+ }
99
+ const metaFilePath = path.join(edgeOneDir, "server-handler", "meta.json");
100
+ let existingMetaData = {};
101
+ if (fs.existsSync(metaFilePath)) {
102
+ try {
103
+ const existingContent = fs.readFileSync(metaFilePath, "utf-8");
104
+ existingMetaData = JSON.parse(existingContent);
105
+ } catch (error2) {
106
+ console.warn("Failed to parse existing meta.json:", error2);
107
+ }
108
+ }
109
+ const mergedMetaData = {
110
+ ...existingMetaData,
111
+ routes: routesArray
112
+ };
113
+ await fs.writeFileSync(
114
+ metaFilePath,
115
+ JSON.stringify(mergedMetaData, null, 2),
116
+ "utf-8"
117
+ );
118
+ };
119
+ var createNuxtApiRoutesMeta = async (ctx) => {
120
+ const edgeOneDir = path.join(process.cwd(), ".edgeone");
121
+ if (!fs.existsSync(edgeOneDir)) {
122
+ console.error("Failed to create .edgeone directory:", error);
123
+ return;
124
+ }
125
+ const metaFilePath = path.join(edgeOneDir, "server-handler", "meta.json");
126
+ if (!fs.existsSync(metaFilePath)) {
127
+ console.error("Failed to create meta.json file:", error);
128
+ return;
129
+ }
130
+ const existingContent = await fs.readFileSync(metaFilePath, "utf-8");
131
+ const existingMetaData = JSON.parse(existingContent);
132
+ const nitroPath = path.join(edgeOneDir, "server-handler", "chunks", "nitro", "nitro.mjs");
133
+ let apiRoutes = [];
134
+ if (fs.existsSync(nitroPath)) {
135
+ try {
136
+ const nitroContent = fs.readFileSync(nitroPath, "utf-8");
137
+ const handlersArray = getHandlersArrayWithAST(nitroContent);
138
+ if (Array.isArray(handlersArray)) {
139
+ for (const handler of handlersArray) {
140
+ if (handler && typeof handler === "object") {
141
+ let routePath = null;
142
+ if (handler.route && typeof handler.route === "string") {
143
+ routePath = handler.route;
144
+ if (existingMetaData.routes.some((route) => route.path === routePath)) {
145
+ continue;
146
+ }
147
+ apiRoutes.push({
148
+ path: routePath,
149
+ handler
150
+ });
151
+ }
152
+ }
153
+ }
154
+ }
155
+ } catch (error2) {
156
+ console.error("Error parsing nitro.mjs for API routes:", error2);
157
+ }
158
+ }
159
+ const mergedMetaData = {
160
+ frameworkRoutes: existingMetaData.routes.concat(apiRoutes.map((route) => ({ path: route.path })))
161
+ };
162
+ const excludeRoutes = ["/**"];
163
+ const processedRoutes = mergedMetaData.frameworkRoutes.filter((route) => !excludeRoutes.includes(route.path)).map((route) => {
164
+ if (!route.path || route.path === "/**") {
165
+ return {
166
+ ...route,
167
+ path: "/"
168
+ };
169
+ }
170
+ if (route.path && route.path.includes("**")) {
171
+ let regexPath = route.path.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
172
+ regexPath = `^${regexPath}$`;
173
+ if (route.path.startsWith("/_ipx")) {
174
+ regexPath = `/_ipx/:path*`;
175
+ }
176
+ return {
177
+ ...route,
178
+ path: regexPath
179
+ // Keep original path
180
+ };
181
+ } else if (route.path && route.path.includes("(.*)*")) {
182
+ let regexPath = route.path.replace(/\(\.\*\)\*/g, "*");
183
+ regexPath = `${regexPath}`;
184
+ return {
185
+ ...route,
186
+ path: regexPath
187
+ // Keep original path
188
+ };
189
+ }
190
+ return route;
191
+ });
192
+ processedRoutes.push({
193
+ path: ".*-ssr-functions/:path*"
194
+ });
195
+ const finalMetaData = {
196
+ frameworkRoutes: processedRoutes,
197
+ conf: {
198
+ ssr404: true
199
+ }
200
+ };
201
+ await fs.writeFileSync(metaFilePath, JSON.stringify(finalMetaData, null, 2));
202
+ };
203
+
204
+ export {
205
+ convertNuxtRoutePattern,
206
+ createNuxtPagesRouteMeta,
207
+ createNuxtApiRoutesMeta
208
+ };