@edgeone/nuxt-pages 1.0.16 → 1.1.0-beta.1

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.
@@ -8,7 +8,7 @@ import {
8
8
  RUN_CONFIG_FILE,
9
9
  copyNuxtServerCode,
10
10
  verifyNuxtHandlerDirStructure
11
- } from "../../esm-chunks/chunk-NJ4SUJNF.js";
11
+ } from "../../esm-chunks/chunk-TP3RAVPL.js";
12
12
  import "../../esm-chunks/chunk-V2LFVP3C.js";
13
13
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
@@ -7,8 +7,8 @@
7
7
  import {
8
8
  addNitroBuildOutputConfig,
9
9
  resetNitroConfig
10
- } from "../../esm-chunks/chunk-7X4RPD4I.js";
11
- import "../../esm-chunks/chunk-MONI3XWQ.js";
10
+ } from "../../esm-chunks/chunk-7RNB5RB6.js";
11
+ import "../../esm-chunks/chunk-5JK44IEA.js";
12
12
  import "../../esm-chunks/chunk-V2LFVP3C.js";
13
13
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
@@ -7,8 +7,8 @@
7
7
  import {
8
8
  createServerHandler,
9
9
  patchNitroHandler
10
- } from "../../esm-chunks/chunk-RNEZUAPL.js";
11
- import "../../esm-chunks/chunk-NJ4SUJNF.js";
10
+ } from "../../esm-chunks/chunk-L23O2KDO.js";
11
+ import "../../esm-chunks/chunk-TP3RAVPL.js";
12
12
  import "../../esm-chunks/chunk-V2LFVP3C.js";
13
13
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
@@ -7,8 +7,8 @@
7
7
  import {
8
8
  PluginContext,
9
9
  SERVER_HANDLER_NAME
10
- } from "../esm-chunks/chunk-BZQMVWYQ.js";
11
- import "../esm-chunks/chunk-MONI3XWQ.js";
10
+ } from "../esm-chunks/chunk-Y3YAV6NZ.js";
11
+ import "../esm-chunks/chunk-5JK44IEA.js";
12
12
  import "../esm-chunks/chunk-6BT4RYQJ.js";
13
13
  export {
14
14
  PluginContext,
@@ -6,11 +6,13 @@
6
6
 
7
7
  import {
8
8
  createNuxtApiRoutesMeta,
9
- createNuxtPagesRouteMeta
10
- } from "../esm-chunks/chunk-J25U56II.js";
11
- import "../esm-chunks/chunk-MONI3XWQ.js";
9
+ createNuxtPagesRouteMeta,
10
+ createNuxtRoutesMeta
11
+ } from "../esm-chunks/chunk-FZBQIMQA.js";
12
+ import "../esm-chunks/chunk-5JK44IEA.js";
12
13
  import "../esm-chunks/chunk-6BT4RYQJ.js";
13
14
  export {
14
15
  createNuxtApiRoutesMeta,
15
- createNuxtPagesRouteMeta
16
+ createNuxtPagesRouteMeta,
17
+ createNuxtRoutesMeta
16
18
  };
@@ -14823,7 +14823,7 @@ function addCodeToGenerateEdgeoneWithAST(code, insertCode) {
14823
14823
  const newOutputConfig = {
14824
14824
  dir: ".edgeone",
14825
14825
  publicDir: ".edgeone/assets",
14826
- serverDir: ".edgeone/server-handler"
14826
+ serverDir: ".edgeone/cloud-functions/ssr-node"
14827
14827
  };
14828
14828
  if (!hasNitro) {
14829
14829
  oldOutputValue = null;
@@ -14832,7 +14832,7 @@ function addCodeToGenerateEdgeoneWithAST(code, insertCode) {
14832
14832
  output: {
14833
14833
  dir: '.edgeone',
14834
14834
  publicDir: '.edgeone/assets',
14835
- serverDir: '.edgeone/server-handler',
14835
+ serverDir: '.edgeone/cloud-functions/ssr-node',
14836
14836
  },
14837
14837
  }`;
14838
14838
  if (existingConfigContent) {
@@ -14871,7 +14871,7 @@ ${nitroConfig}
14871
14871
  const outputConfigStr = ` output: {
14872
14872
  dir: '.edgeone',
14873
14873
  publicDir: '.edgeone/assets',
14874
- serverDir: '.edgeone/server-handler',
14874
+ serverDir: '.edgeone/cloud-functions/ssr-node',
14875
14875
  }`;
14876
14876
  let newNitroContent;
14877
14877
  const properties = [];
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  addCodeToGenerateEdgeoneWithAST,
9
9
  resetNitroConfigWithAST
10
- } from "./chunk-MONI3XWQ.js";
10
+ } from "./chunk-5JK44IEA.js";
11
11
  import {
12
12
  trace,
13
13
  wrapTracer
@@ -35,7 +35,7 @@ var addNitroBuildOutputConfig = async (ctx) => {
35
35
  output: {
36
36
  dir: '.edgeone',
37
37
  publicDir: '.edgeone/assets',
38
- serverDir: '.edgeone/server-handler',
38
+ serverDir: '.edgeone/cloud-functions/ssr-node',
39
39
  },
40
40
  },
41
41
  devtools: { enabled: true },
@@ -57,7 +57,7 @@ var addNitroBuildOutputConfig = async (ctx) => {
57
57
  output: {
58
58
  dir: '.edgeone',
59
59
  publicDir: '.edgeone/assets',
60
- serverDir: '.edgeone/server-handler',
60
+ serverDir: '.edgeone/cloud-functions/ssr-node',
61
61
  },
62
62
  },
63
63
  `);
@@ -0,0 +1,260 @@
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
+ getRouteRulesWithAST
10
+ } from "./chunk-5JK44IEA.js";
11
+
12
+ // src/build/routes.ts
13
+ import * as fs from "fs";
14
+ import * as path from "path";
15
+ var CONFIG_VERSION = 3;
16
+ var CONFIG_FILE_NAME = "config.json";
17
+ function escapeRegExp(str) {
18
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19
+ }
20
+ function normalizeRoutePath(p) {
21
+ if (!p) return "/";
22
+ const clean = p.split("?")[0];
23
+ if (clean === "" || clean === "/") return "/";
24
+ return clean.startsWith("/") ? clean.replace(/\/+$/, "") : `/${clean.replace(/\/+$/, "")}`;
25
+ }
26
+ function ensureServerHandlerDir() {
27
+ const edgeOneDir = path.join(process.cwd(), ".edgeone");
28
+ const serverHandlerDir = path.join(edgeOneDir, "cloud-functions", "ssr-node");
29
+ if (!fs.existsSync(edgeOneDir)) fs.mkdirSync(edgeOneDir, { recursive: true });
30
+ if (!fs.existsSync(serverHandlerDir)) fs.mkdirSync(serverHandlerDir, { recursive: true });
31
+ return serverHandlerDir;
32
+ }
33
+ function getConfigPath() {
34
+ return path.join(ensureServerHandlerDir(), CONFIG_FILE_NAME);
35
+ }
36
+ function writeConfig(config) {
37
+ const configPath = getConfigPath();
38
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
39
+ }
40
+ function normalizeHeaders(headers) {
41
+ if (!headers || typeof headers !== "object") return null;
42
+ const out = {};
43
+ for (const [k, v] of Object.entries(headers)) {
44
+ if (typeof k !== "string" || !k) continue;
45
+ if (typeof v === "string") out[k] = v;
46
+ else if (typeof v === "number" || typeof v === "boolean") out[k] = String(v);
47
+ }
48
+ return Object.keys(out).length ? out : null;
49
+ }
50
+ function extractInlineRuntimeConfigFromNitroMjs(code) {
51
+ if (!code || typeof code !== "string") return null;
52
+ const idx = code.search(/\b_inlineRuntimeConfig\b\s*=\s*\{/);
53
+ if (idx === -1) return null;
54
+ const braceStart = code.indexOf("{", idx);
55
+ if (braceStart === -1) return null;
56
+ let depth = 0;
57
+ let inStr = false;
58
+ let quote = "";
59
+ let escaped = false;
60
+ let end = -1;
61
+ for (let i = braceStart; i < code.length; i++) {
62
+ const ch = code[i];
63
+ if (inStr) {
64
+ if (escaped) {
65
+ escaped = false;
66
+ continue;
67
+ }
68
+ if (ch === "\\") {
69
+ escaped = true;
70
+ continue;
71
+ }
72
+ if (ch === quote) {
73
+ inStr = false;
74
+ quote = "";
75
+ }
76
+ continue;
77
+ }
78
+ if (ch === '"' || ch === "'") {
79
+ inStr = true;
80
+ quote = ch;
81
+ continue;
82
+ }
83
+ if (ch === "{") {
84
+ depth++;
85
+ continue;
86
+ }
87
+ if (ch === "}") {
88
+ depth--;
89
+ if (depth === 0) {
90
+ end = i;
91
+ break;
92
+ }
93
+ continue;
94
+ }
95
+ }
96
+ if (end === -1) return null;
97
+ const objStr = code.slice(braceStart, end + 1);
98
+ try {
99
+ return JSON.parse(objStr);
100
+ } catch {
101
+ return null;
102
+ }
103
+ }
104
+ async function getRouteRulesFromNitroInlineRuntimeConfig(ctx) {
105
+ const nitroMjsPath = resolveNitroMjsPath();
106
+ if (!nitroMjsPath) return null;
107
+ try {
108
+ const nitroContent = fs.readFileSync(nitroMjsPath, "utf-8");
109
+ const inlineCfg = extractInlineRuntimeConfigFromNitroMjs(nitroContent);
110
+ const rr = inlineCfg?.nitro?.routeRules;
111
+ if (rr && typeof rr === "object") return rr;
112
+ } catch {
113
+ }
114
+ return null;
115
+ }
116
+ async function getRouteRulesFromBuildOutput(ctx) {
117
+ const fromNitroMjs = await getRouteRulesFromNitroInlineRuntimeConfig(ctx);
118
+ if (fromNitroMjs) return fromNitroMjs;
119
+ try {
120
+ if (typeof ctx?.getNuxtConfig === "function") {
121
+ const cfg = await ctx.getNuxtConfig();
122
+ const parsed = getRouteRulesWithAST(cfg || "");
123
+ if (parsed && typeof parsed === "object") return parsed;
124
+ }
125
+ } catch {
126
+ }
127
+ return null;
128
+ }
129
+ async function buildHeadersRoutes(ctx) {
130
+ const routeRules = await getRouteRulesFromBuildOutput(ctx);
131
+ if (!routeRules || typeof routeRules !== "object") return [];
132
+ const out = [];
133
+ for (const [srcRaw, rule] of Object.entries(routeRules)) {
134
+ const headers = normalizeHeaders(rule?.headers);
135
+ if (!headers) continue;
136
+ const src = typeof srcRaw === "string" && srcRaw.startsWith("^") ? srcRaw : normalizeRoutePath(String(srcRaw)).replace(/\*\*/g, "(.*)");
137
+ out.push({ src, headers });
138
+ }
139
+ return out;
140
+ }
141
+ async function buildStage1Routes(ctx) {
142
+ const routes = [];
143
+ routes.push({ src: "^/([^.]+[^/.])$", dest: "/$1/", continue: true });
144
+ routes.push(...await buildHeadersRoutes(ctx));
145
+ routes.push({ handle: "filesystem" });
146
+ return routes;
147
+ }
148
+ function resolveNitroMjsPath() {
149
+ const edgeOneDir = path.join(process.cwd(), ".edgeone");
150
+ const defaultNitroPath = path.join(edgeOneDir, "cloud-functions", "ssr-node", "chunks", "nitro", "nitro.mjs");
151
+ const fallbackNitroPath = path.join(edgeOneDir, "cloud-functions", "ssr-node", "chunks", "_", "nitro.mjs");
152
+ const nitroPath = fs.existsSync(defaultNitroPath) ? defaultNitroPath : fallbackNitroPath;
153
+ return fs.existsSync(nitroPath) ? nitroPath : null;
154
+ }
155
+ async function buildExplicitApiRoutes(_ctx) {
156
+ const nitroPath = resolveNitroMjsPath();
157
+ if (!nitroPath) {
158
+ console.error("Nitro entry(nitro.mjs) not found");
159
+ return [];
160
+ }
161
+ try {
162
+ const nitroContent = fs.readFileSync(nitroPath, "utf-8");
163
+ const handlersArray = getHandlersArrayWithAST(nitroContent);
164
+ if (!Array.isArray(handlersArray)) return [];
165
+ const seen = /* @__PURE__ */ new Set();
166
+ const out = [];
167
+ for (const h of handlersArray) {
168
+ const route = typeof h?.route === "string" ? String(h.route) : "";
169
+ if (!route) continue;
170
+ const normalized = normalizeRoutePath(route);
171
+ if (!normalized.startsWith("/api")) continue;
172
+ const rule = route.startsWith("^") ? { src: route } : nuxtRoutePathToRouteRule(normalized);
173
+ const src = rule?.src;
174
+ if (!src || seen.has(src)) continue;
175
+ seen.add(src);
176
+ out.push(rule);
177
+ }
178
+ out.sort((a, b) => String(b.src || "").length - String(a.src || "").length);
179
+ return out;
180
+ } catch (error) {
181
+ console.error("Error parsing nitro.mjs for API routes:", error);
182
+ return [];
183
+ }
184
+ }
185
+ function isCatchAllLikeRoutePath(p) {
186
+ const clean = normalizeRoutePath(p);
187
+ return clean.includes("(.*)") || clean.includes(".*") || clean.includes(":all");
188
+ }
189
+ function nuxtRoutePathToRouteRule(routePath) {
190
+ const p = normalizeRoutePath(routePath);
191
+ if (!p.startsWith("/")) return null;
192
+ if (p === "/") return { src: "^/$" };
193
+ const parts = p.split("/").filter(Boolean);
194
+ const srcParts = [];
195
+ for (const seg of parts) {
196
+ if (seg === "*" || seg === "**") {
197
+ srcParts.push("(.*)");
198
+ continue;
199
+ }
200
+ if (seg.startsWith(":")) {
201
+ const m = seg.match(/^:([A-Za-z_$][\w$]*)(?:\((.*)\))?(\*)?$/);
202
+ const inner = m ? m[2] : null;
203
+ const star = m ? m[3] : null;
204
+ if (star || inner === ".*") {
205
+ srcParts.push("(.*)");
206
+ continue;
207
+ }
208
+ if (!inner || inner.trim() === "") {
209
+ srcParts.push("([^/]+)");
210
+ continue;
211
+ }
212
+ srcParts.push(`((?:${inner}))`);
213
+ continue;
214
+ }
215
+ srcParts.push(escapeRegExp(seg));
216
+ }
217
+ const srcBody = srcParts.join("/");
218
+ return { src: `^/${srcBody}$` };
219
+ }
220
+ async function buildExplicitSsrAndSwrRoutes(ctx) {
221
+ const routesManifest = await ctx.getRoutesManifest();
222
+ const manifestRoutes = Array.isArray(routesManifest?.routes) ? routesManifest.routes : [];
223
+ const seen = /* @__PURE__ */ new Set();
224
+ const tmp = [];
225
+ for (const r of manifestRoutes) {
226
+ const p = typeof r?.path === "string" ? r.path : "";
227
+ if (!p) continue;
228
+ const normalized = normalizeRoutePath(p);
229
+ if (normalized.startsWith("/api")) continue;
230
+ const isSsr = r?.ssr === true;
231
+ const isSwr = r?.swr !== false && r?.swr !== void 0 && r?.swr !== null;
232
+ if (!isSsr && !isSwr) continue;
233
+ const rule = nuxtRoutePathToRouteRule(normalized);
234
+ const src = rule?.src;
235
+ if (!src || seen.has(src)) continue;
236
+ seen.add(src);
237
+ const score = (isCatchAllLikeRoutePath(normalized) ? -1e4 : 0) + normalized.split("/").length;
238
+ tmp.push({ score, rule });
239
+ }
240
+ tmp.sort((a, b) => b.score - a.score);
241
+ return tmp.map((x) => x.rule);
242
+ }
243
+ var createNuxtRoutesMeta = async (ctx) => {
244
+ const routes = await buildStage1Routes(ctx);
245
+ routes.push(...await buildExplicitApiRoutes(ctx));
246
+ routes.push(...await buildExplicitSsrAndSwrRoutes(ctx));
247
+ writeConfig({ version: CONFIG_VERSION, routes });
248
+ };
249
+ var createNuxtPagesRouteMeta = async (ctx) => {
250
+ await createNuxtRoutesMeta(ctx);
251
+ };
252
+ var createNuxtApiRoutesMeta = async (ctx) => {
253
+ await createNuxtRoutesMeta(ctx);
254
+ };
255
+
256
+ export {
257
+ createNuxtRoutesMeta,
258
+ createNuxtPagesRouteMeta,
259
+ createNuxtApiRoutesMeta
260
+ };
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  require_out,
9
9
  verifyNuxtHandlerDirStructure
10
- } from "./chunk-NJ4SUJNF.js";
10
+ } from "./chunk-TP3RAVPL.js";
11
11
  import {
12
12
  __require,
13
13
  __toESM
@@ -101,10 +101,10 @@ var createServerHandler = async (ctx) => {
101
101
  };
102
102
  async function patchNitroHandler(ctx) {
103
103
  const fs = __require("fs");
104
- const defaultNitroMjsPath = ".edgeone/server-handler/chunks/nitro/nitro.mjs";
105
- const fallbackNitroMjsPath = ".edgeone/server-handler/chunks/_/nitro.mjs";
104
+ const defaultNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "nitro", "nitro.mjs");
105
+ const fallbackNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "_", "nitro.mjs");
106
106
  const nitroMjsPath = fs.existsSync(defaultNitroMjsPath) ? defaultNitroMjsPath : fallbackNitroMjsPath;
107
- const handlerTmplPath = ".edgeone/server-handler/handler.js";
107
+ const handlerTmplPath = join(ctx.serverHandlerRootDir, "handler.js");
108
108
  const nitroCode = fs.readFileSync(nitroMjsPath, "utf-8");
109
109
  const match = nitroCode.match(/export\s*\{[^}]*\buseNitroApp\s+as\s+([A-Za-z_$][\w$]*)/) ?? nitroCode.match(/\buseNitroApp\s+as\s+([A-Za-z_$][\w$]*)\b/);
110
110
  if (!match) throw new Error("Cannot find useNitroApp export symbol in nitro.mjs!");
@@ -5520,7 +5520,7 @@ function isError(error) {
5520
5520
  return error instanceof Error;
5521
5521
  }
5522
5522
  var copyNuxtServerCode = async (ctx) => {
5523
- const nuxtServerDir = join(ctx.outputDir, "server-handler");
5523
+ const nuxtServerDir = join(ctx.outputDir, "cloud-functions", "ssr-node");
5524
5524
  try {
5525
5525
  await access(nuxtServerDir);
5526
5526
  } catch (error) {
@@ -9,7 +9,7 @@ import {
9
9
  getPrerenderRoutesWithAST,
10
10
  getRouteRulesWithAST,
11
11
  getRoutesArrayWithAST
12
- } from "./chunk-MONI3XWQ.js";
12
+ } from "./chunk-5JK44IEA.js";
13
13
 
14
14
  // src/build/plugin-context.ts
15
15
  import { existsSync, readFileSync } from "node:fs";
@@ -21,7 +21,7 @@ var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
21
21
  var PLUGIN_DIR = join(MODULE_DIR, "../..");
22
22
  var DEFAULT_BUILD_DIR = ".nuxt";
23
23
  var DEFAULT_OUTPUT_DIR = ".edgeone";
24
- var SERVER_HANDLER_NAME = "server-handler";
24
+ var SERVER_HANDLER_NAME = "cloud-functions/ssr-node";
25
25
  var PluginContext = class {
26
26
  edgeoneConfig;
27
27
  pluginName;
@@ -240,7 +240,7 @@ var PluginContext = class {
240
240
  }
241
241
  /** Detect and locate server.mjs file */
242
242
  detectNuxtServerFile() {
243
- const serverFilePath = this.resolveFromPackagePath(".edgeone", "server-handler", "chunks", "build", "server.mjs");
243
+ const serverFilePath = this.resolveFromPackagePath(".edgeone", "cloud-functions", "ssr-node", "chunks", "build", "server.mjs");
244
244
  if (existsSync(serverFilePath)) {
245
245
  return serverFilePath;
246
246
  }
package/dist/index.js CHANGED
@@ -6,24 +6,23 @@
6
6
 
7
7
  import {
8
8
  PluginContext
9
- } from "./esm-chunks/chunk-BZQMVWYQ.js";
9
+ } from "./esm-chunks/chunk-Y3YAV6NZ.js";
10
10
  import {
11
- createNuxtApiRoutesMeta,
12
- createNuxtPagesRouteMeta
13
- } from "./esm-chunks/chunk-J25U56II.js";
11
+ createNuxtRoutesMeta
12
+ } from "./esm-chunks/chunk-FZBQIMQA.js";
14
13
  import {
15
14
  addNitroBuildOutputConfig,
16
15
  resetNitroConfig
17
- } from "./esm-chunks/chunk-7X4RPD4I.js";
16
+ } from "./esm-chunks/chunk-7RNB5RB6.js";
18
17
  import {
19
18
  resetEdgeOneConfig,
20
19
  useStaticBuild
21
- } from "./esm-chunks/chunk-MONI3XWQ.js";
20
+ } from "./esm-chunks/chunk-5JK44IEA.js";
22
21
  import {
23
22
  createServerHandler,
24
23
  patchNitroHandler
25
- } from "./esm-chunks/chunk-RNEZUAPL.js";
26
- import "./esm-chunks/chunk-NJ4SUJNF.js";
24
+ } from "./esm-chunks/chunk-L23O2KDO.js";
25
+ import "./esm-chunks/chunk-TP3RAVPL.js";
27
26
  import "./esm-chunks/chunk-V2LFVP3C.js";
28
27
  import "./esm-chunks/chunk-6BT4RYQJ.js";
29
28
 
@@ -47,6 +46,7 @@ var removeIndexMJS = async (ctx) => {
47
46
  var recordOldNitroConfig = null;
48
47
  var recordOldEdgeOneConfig = -1;
49
48
  var onPreBuild = async (options) => {
49
+ console.log("\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C}\u{1F62C} ======= new nuxt pages 1.1.0+ ============");
50
50
  try {
51
51
  const ctx = new PluginContext(options);
52
52
  recordOldNitroConfig = await addNitroBuildOutputConfig(ctx);
@@ -67,8 +67,7 @@ var onBuild = async (options) => {
67
67
  await removeServerHandler(ctx);
68
68
  return;
69
69
  }
70
- await createServerHandler(ctx), await createNuxtPagesRouteMeta(ctx);
71
- await createNuxtApiRoutesMeta(ctx);
70
+ await createServerHandler(ctx), await createNuxtRoutesMeta(ctx);
72
71
  await patchNitroHandler(ctx);
73
72
  };
74
73
  var onPostBuild = async (options) => {
package/dist/utils.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  resetEdgeOneConfig,
15
15
  resetNitroConfigWithAST,
16
16
  useStaticBuild
17
- } from "./esm-chunks/chunk-MONI3XWQ.js";
17
+ } from "./esm-chunks/chunk-5JK44IEA.js";
18
18
  import "./esm-chunks/chunk-6BT4RYQJ.js";
19
19
  export {
20
20
  addCodeToGenerateEdgeoneWithAST,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@edgeone/nuxt-pages",
3
- "version": "1.0.16",
3
+ "version": "1.1.0-beta.1",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
- "test": "ts-node src/test.ts",
6
+ "test": "vitest run --passWithNoTests",
7
7
  "build": "node ./tools/build.js",
8
8
  "build:watch": "node ./tools/build.js --watch",
9
9
  "start": "node dist/index.js",
@@ -1,213 +0,0 @@
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-MONI3XWQ.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.prerender !== void 0) {
64
- routeMap[route].isStatic = routeInfo.prerender;
65
- }
66
- if (routeInfo.swr !== void 0 && routeInfo.swr) {
67
- routeMap[route].isr = routeInfo.swr;
68
- }
69
- if (routeInfo.isr !== void 0 && routeInfo.isr) {
70
- routeMap[route].isr = routeInfo.isr;
71
- }
72
- }
73
- }
74
- }
75
- const convertedRouteMap = {};
76
- const pathsToDelete = [];
77
- for (const [routePath, routeConfig] of Object.entries(routeMap)) {
78
- const convertedPath = convertNuxtRoutePattern(routePath);
79
- if (convertedPath !== routePath) {
80
- pathsToDelete.push(routePath);
81
- convertedRouteMap[convertedPath] = routeConfig;
82
- }
83
- }
84
- for (const pathToDelete of pathsToDelete) {
85
- delete routeMap[pathToDelete];
86
- }
87
- Object.assign(routeMap, convertedRouteMap);
88
- const routesArray = Object.entries(routeMap).map(([path2, config]) => ({
89
- path: path2,
90
- ...config
91
- }));
92
- const edgeOneDir = path.join(process.cwd(), ".edgeone");
93
- if (!fs.existsSync(edgeOneDir)) {
94
- fs.mkdirSync(edgeOneDir, { recursive: true });
95
- }
96
- const metaFilePath = path.join(edgeOneDir, "server-handler", "meta.json");
97
- let existingMetaData = {};
98
- if (fs.existsSync(metaFilePath)) {
99
- try {
100
- const existingContent = fs.readFileSync(metaFilePath, "utf-8");
101
- existingMetaData = JSON.parse(existingContent);
102
- } catch (error2) {
103
- console.warn("Failed to parse existing meta.json:", error2);
104
- }
105
- }
106
- const mergedMetaData = {
107
- ...existingMetaData,
108
- routes: routesArray
109
- };
110
- await fs.writeFileSync(
111
- metaFilePath,
112
- JSON.stringify(mergedMetaData, null, 2),
113
- "utf-8"
114
- );
115
- };
116
- var createNuxtApiRoutesMeta = async (ctx) => {
117
- const edgeOneDir = path.join(process.cwd(), ".edgeone");
118
- if (!fs.existsSync(edgeOneDir)) {
119
- console.error("Failed to create .edgeone directory:", error);
120
- return;
121
- }
122
- const metaFilePath = path.join(edgeOneDir, "server-handler", "meta.json");
123
- if (!fs.existsSync(metaFilePath)) {
124
- console.error("Failed to create meta.json file:", error);
125
- return;
126
- }
127
- const existingContent = await fs.readFileSync(metaFilePath, "utf-8");
128
- const existingMetaData = JSON.parse(existingContent);
129
- const defaultNitroPath = path.join(edgeOneDir, "server-handler", "chunks", "nitro", "nitro.mjs");
130
- const fallbackNitroPath = path.join(edgeOneDir, "server-handler", "chunks", "_", "nitro.mjs");
131
- const nitroPath = fs.existsSync(defaultNitroPath) ? defaultNitroPath : fallbackNitroPath;
132
- let apiRoutes = [];
133
- if (fs.existsSync(nitroPath)) {
134
- try {
135
- const nitroContent = fs.readFileSync(nitroPath, "utf-8");
136
- const handlersArray = getHandlersArrayWithAST(nitroContent);
137
- if (Array.isArray(handlersArray)) {
138
- for (const handler of handlersArray) {
139
- if (handler && typeof handler === "object") {
140
- let routePath = null;
141
- if (handler.route && typeof handler.route === "string") {
142
- routePath = handler.route;
143
- if (existingMetaData.routes.some((route) => route.path === routePath)) {
144
- continue;
145
- }
146
- apiRoutes.push({
147
- path: routePath,
148
- handler
149
- });
150
- }
151
- }
152
- }
153
- }
154
- } catch (error2) {
155
- console.error("Error parsing nitro.mjs for API routes:", error2);
156
- }
157
- }
158
- const mergedMetaData = {
159
- frameworkRoutes: existingMetaData.routes.concat(apiRoutes.map((route) => ({ path: route.path })))
160
- };
161
- const excludeRoutes = ["/**"];
162
- let processedRoutes = mergedMetaData.frameworkRoutes.filter((route) => !excludeRoutes.includes(route.path)).map((route) => {
163
- if (!route.path || route.path === "/**") {
164
- return {
165
- ...route,
166
- path: "/"
167
- };
168
- }
169
- if (route.path && route.path.includes("**:")) {
170
- route.path = route.path.replaceAll("**:", ":");
171
- }
172
- if (route.path && route.path.includes("**")) {
173
- let regexPath = route.path.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
174
- regexPath = `^${regexPath}$`;
175
- if (route.path.startsWith("/_ipx")) {
176
- regexPath = `/_ipx/:path*`;
177
- }
178
- return {
179
- ...route,
180
- path: regexPath
181
- // Keep original path
182
- };
183
- } else if (route.path && route.path.includes("(.*)*")) {
184
- let regexPath = route.path.replace(/\(\.\*\)\*/g, "*");
185
- regexPath = `${regexPath}`;
186
- return {
187
- ...route,
188
- path: regexPath
189
- // Keep original path
190
- };
191
- }
192
- return route;
193
- });
194
- processedRoutes = processedRoutes.map((route) => {
195
- if (route.hasOwnProperty("ssr")) {
196
- Reflect.deleteProperty(route, "ssr");
197
- }
198
- route.path = route.path.replace(/\(/g, "").replace(/\)/g, "");
199
- return route;
200
- });
201
- const finalMetaData = {
202
- frameworkRoutes: processedRoutes,
203
- conf: {
204
- ssr404: true
205
- }
206
- };
207
- await fs.writeFileSync(metaFilePath, JSON.stringify(finalMetaData, null, 2));
208
- };
209
-
210
- export {
211
- createNuxtPagesRouteMeta,
212
- createNuxtApiRoutesMeta
213
- };