@edgeone/nuxt-pages 1.1.0-beta.2 → 1.1.0-beta.4

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.
@@ -5,13 +5,14 @@
5
5
  })();
6
6
 
7
7
  import {
8
- addNitroBuildOutputConfig,
9
- resetNitroConfig
10
- } from "../../esm-chunks/chunk-7RNB5RB6.js";
11
- import "../../esm-chunks/chunk-5JK44IEA.js";
12
- import "../../esm-chunks/chunk-V2LFVP3C.js";
8
+ cleanupEdgeoneModule,
9
+ injectEdgeoneModule,
10
+ removeTempModule
11
+ } from "../../esm-chunks/chunk-ZR3DYEBK.js";
12
+ import "../../esm-chunks/chunk-VCJ5U4PV.js";
13
13
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
15
- addNitroBuildOutputConfig,
16
- resetNitroConfig
15
+ cleanupEdgeoneModule,
16
+ injectEdgeoneModule,
17
+ removeTempModule
17
18
  };
@@ -8,8 +8,7 @@ import {
8
8
  RUN_CONFIG_FILE,
9
9
  copyNuxtServerCode,
10
10
  verifyNuxtHandlerDirStructure
11
- } from "../../esm-chunks/chunk-TP3RAVPL.js";
12
- import "../../esm-chunks/chunk-V2LFVP3C.js";
11
+ } from "../../esm-chunks/chunk-K5VT7O2H.js";
13
12
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
13
  export {
15
14
  RUN_CONFIG_FILE,
@@ -7,9 +7,8 @@
7
7
  import {
8
8
  createServerHandler,
9
9
  patchNitroHandler
10
- } from "../../esm-chunks/chunk-L23O2KDO.js";
11
- import "../../esm-chunks/chunk-TP3RAVPL.js";
12
- import "../../esm-chunks/chunk-V2LFVP3C.js";
10
+ } from "../../esm-chunks/chunk-PJWA566S.js";
11
+ import "../../esm-chunks/chunk-K5VT7O2H.js";
13
12
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
13
  export {
15
14
  createServerHandler,
@@ -7,8 +7,9 @@
7
7
  import {
8
8
  PluginContext,
9
9
  SERVER_HANDLER_NAME
10
- } from "../esm-chunks/chunk-Y3YAV6NZ.js";
11
- import "../esm-chunks/chunk-5JK44IEA.js";
10
+ } from "../esm-chunks/chunk-VDBASNGL.js";
11
+ import "../esm-chunks/chunk-AZLY3JO2.js";
12
+ import "../esm-chunks/chunk-VCJ5U4PV.js";
12
13
  import "../esm-chunks/chunk-6BT4RYQJ.js";
13
14
  export {
14
15
  PluginContext,
@@ -8,8 +8,9 @@ import {
8
8
  createNuxtApiRoutesMeta,
9
9
  createNuxtPagesRouteMeta,
10
10
  createNuxtRoutesMeta
11
- } from "../esm-chunks/chunk-UFRAZNP3.js";
12
- import "../esm-chunks/chunk-5JK44IEA.js";
11
+ } from "../esm-chunks/chunk-3HA3DZ3G.js";
12
+ import "../esm-chunks/chunk-AZLY3JO2.js";
13
+ import "../esm-chunks/chunk-VCJ5U4PV.js";
13
14
  import "../esm-chunks/chunk-6BT4RYQJ.js";
14
15
  export {
15
16
  createNuxtApiRoutesMeta,
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  getHandlersArrayWithAST,
9
9
  getRouteRulesWithAST
10
- } from "./chunk-5JK44IEA.js";
10
+ } from "./chunk-AZLY3JO2.js";
11
11
 
12
12
  // src/build/routes.ts
13
13
  import * as fs from "fs";
@@ -0,0 +1,299 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ require_lib
9
+ } from "./chunk-VCJ5U4PV.js";
10
+ import {
11
+ __toESM
12
+ } from "./chunk-6BT4RYQJ.js";
13
+
14
+ // src/utils.ts
15
+ var parser = __toESM(require_lib(), 1);
16
+ import { createRequire } from "node:module";
17
+ import * as fs from "fs";
18
+ import * as path from "path";
19
+ var require2 = createRequire(import.meta.url);
20
+ var traverse = require2("@babel/traverse").default;
21
+ function useStaticBuild(cwd) {
22
+ const edgeoneJsonPath = path.join(cwd, "edgeone.json");
23
+ let originalEdgeOneConfig = null;
24
+ let config = {};
25
+ if (!fs.existsSync(edgeoneJsonPath)) {
26
+ fs.writeFileSync(edgeoneJsonPath, "{}", "utf-8");
27
+ config = {};
28
+ } else {
29
+ try {
30
+ const fileContent = fs.readFileSync(edgeoneJsonPath, "utf-8");
31
+ originalEdgeOneConfig = fileContent;
32
+ config = JSON.parse(fileContent);
33
+ } catch (error) {
34
+ console.error("\u8BFB\u53D6 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
35
+ config = {};
36
+ }
37
+ }
38
+ config.buildCommand = "npm run generate";
39
+ try {
40
+ fs.writeFileSync(edgeoneJsonPath, JSON.stringify(config, null, 2), "utf-8");
41
+ } catch (error) {
42
+ console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
43
+ throw error;
44
+ }
45
+ return originalEdgeOneConfig;
46
+ }
47
+ function resetEdgeOneConfig(cwd, originalEdgeOneConfig) {
48
+ const edgeoneJsonPath = path.join(cwd, "edgeone.json");
49
+ try {
50
+ if (originalEdgeOneConfig == null) {
51
+ fs.rmSync(edgeoneJsonPath, { recursive: true, force: true });
52
+ return;
53
+ }
54
+ fs.writeFileSync(edgeoneJsonPath, originalEdgeOneConfig, "utf-8");
55
+ } catch (error) {
56
+ console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
57
+ throw error;
58
+ }
59
+ }
60
+ function astNodeToObject(node) {
61
+ if (node.type === "ObjectExpression") {
62
+ const obj = {};
63
+ for (const prop of node.properties) {
64
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
65
+ obj[prop.key.name] = astNodeToObject(prop.value);
66
+ } else if (prop.type === "ObjectProperty" && prop.key.type === "StringLiteral") {
67
+ obj[prop.key.value] = astNodeToObject(prop.value);
68
+ }
69
+ }
70
+ return obj;
71
+ } else if (node.type === "ArrayExpression") {
72
+ return node.elements.map((element) => element ? astNodeToObject(element) : null);
73
+ } else if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
74
+ return node.value;
75
+ } else if (node.type === "NullLiteral") {
76
+ return null;
77
+ } else {
78
+ console.warn(`Unsupported node type in astNodeToObject: ${node.type}`);
79
+ return void 0;
80
+ }
81
+ }
82
+ function getRouteRulesWithAST(code) {
83
+ try {
84
+ const ast = parser.parse(code, {
85
+ sourceType: "module",
86
+ plugins: ["typescript"]
87
+ });
88
+ let routeRulesObject = null;
89
+ traverse(ast, {
90
+ // We're looking for a function call
91
+ CallExpression(path2) {
92
+ const { node } = path2;
93
+ if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
94
+ if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
95
+ const configObjectNode = node.arguments[0];
96
+ for (const prop of configObjectNode.properties) {
97
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "routeRules") {
98
+ routeRulesObject = astNodeToObject(prop.value);
99
+ path2.stop();
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ });
107
+ return routeRulesObject;
108
+ } catch (e) {
109
+ console.error("AST parsing or traversal failed:", e);
110
+ return null;
111
+ }
112
+ }
113
+ function getPrerenderRoutesWithAST(code) {
114
+ try {
115
+ const ast = parser.parse(code, {
116
+ sourceType: "module",
117
+ plugins: ["typescript"]
118
+ });
119
+ let prerenderRoutes = [];
120
+ traverse(ast, {
121
+ // We're looking for a function call
122
+ CallExpression(path2) {
123
+ const { node } = path2;
124
+ if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
125
+ if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
126
+ const configObjectNode = node.arguments[0];
127
+ for (const prop of configObjectNode.properties) {
128
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "nitro" && prop.value.type === "ObjectExpression") {
129
+ for (const nitroProp of prop.value.properties) {
130
+ if (nitroProp.type === "ObjectProperty" && nitroProp.key.type === "Identifier" && nitroProp.key.name === "prerender" && nitroProp.value.type === "ObjectExpression") {
131
+ for (const prerenderProp of nitroProp.value.properties) {
132
+ if (prerenderProp.type === "ObjectProperty" && prerenderProp.key.type === "Identifier" && prerenderProp.key.name === "routes" && prerenderProp.value.type === "ArrayExpression") {
133
+ const routesArray = astNodeToObject(prerenderProp.value);
134
+ if (Array.isArray(routesArray)) {
135
+ prerenderRoutes = routesArray.filter((route) => typeof route === "string");
136
+ }
137
+ path2.stop();
138
+ return;
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ });
149
+ return prerenderRoutes;
150
+ } catch (e) {
151
+ console.error("AST parsing or traversal failed:", e);
152
+ return [];
153
+ }
154
+ }
155
+ function getRoutesArrayWithAST(code) {
156
+ try {
157
+ const ast = parser.parse(code, {
158
+ sourceType: "module",
159
+ plugins: ["typescript"]
160
+ });
161
+ let routesArray = null;
162
+ traverse(ast, {
163
+ // We're looking for a variable declaration
164
+ VariableDeclaration(path2) {
165
+ const { node } = path2;
166
+ for (const declarator of node.declarations) {
167
+ if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "_routes") {
168
+ if (declarator.init && declarator.init.type === "ArrayExpression") {
169
+ routesArray = astNodeToObjectForRoutes(declarator.init);
170
+ path2.stop();
171
+ break;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ });
177
+ return routesArray;
178
+ } catch (e) {
179
+ console.error("AST parsing or traversal failed:", e);
180
+ return null;
181
+ }
182
+ }
183
+ function getHandlersArrayWithAST(code) {
184
+ try {
185
+ const ast = parser.parse(code, {
186
+ sourceType: "module",
187
+ plugins: ["typescript"]
188
+ });
189
+ let handlersArray = [];
190
+ traverse(ast, {
191
+ // We're looking for a variable declaration
192
+ VariableDeclaration(path2) {
193
+ const { node } = path2;
194
+ for (const declarator of node.declarations) {
195
+ if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "handlers") {
196
+ if (declarator.init && declarator.init.type === "ArrayExpression") {
197
+ handlersArray = astNodeToObjectForRoutes(declarator.init);
198
+ path2.stop();
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ });
205
+ return handlersArray;
206
+ } catch (e) {
207
+ console.error("AST parsing or traversal failed:", e);
208
+ return [];
209
+ }
210
+ }
211
+ function astNodeToObjectForRoutes(node) {
212
+ if (node.type === "ObjectExpression") {
213
+ const obj = {};
214
+ for (const prop of node.properties) {
215
+ if (prop.type === "ObjectProperty") {
216
+ let key;
217
+ if (prop.key.type === "Identifier") {
218
+ key = prop.key.name;
219
+ } else if (prop.key.type === "StringLiteral") {
220
+ key = prop.key.value;
221
+ } else {
222
+ continue;
223
+ }
224
+ if (prop.value.type === "ArrowFunctionExpression") {
225
+ if (prop.value.body.type === "CallExpression" && prop.value.body.callee.type === "Import" && prop.value.body.arguments.length > 0 && prop.value.body.arguments[0].type === "StringLiteral") {
226
+ const importPath = prop.value.body.arguments[0].value;
227
+ obj[key] = `() => import('${importPath}')`;
228
+ } else {
229
+ obj[key] = "[Function]";
230
+ }
231
+ } else {
232
+ obj[key] = astNodeToObjectForRoutes(prop.value);
233
+ }
234
+ }
235
+ }
236
+ return obj;
237
+ } else if (node.type === "ArrayExpression") {
238
+ return node.elements.map((element) => element ? astNodeToObjectForRoutes(element) : null);
239
+ } else if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
240
+ return node.value;
241
+ } else if (node.type === "NullLiteral") {
242
+ return null;
243
+ } else {
244
+ return `[${node.type}]`;
245
+ }
246
+ }
247
+ function getModulesWithAST(code) {
248
+ try {
249
+ const ast = parser.parse(code, {
250
+ sourceType: "module",
251
+ plugins: ["typescript"]
252
+ });
253
+ let modulesArray = [];
254
+ traverse(ast, {
255
+ CallExpression(path2) {
256
+ const { node } = path2;
257
+ if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
258
+ if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
259
+ const configObject = node.arguments[0];
260
+ for (const prop of configObject.properties) {
261
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "modules") {
262
+ if (prop.value.type === "ArrayExpression") {
263
+ for (const element of prop.value.elements) {
264
+ if (element) {
265
+ if (element.type === "StringLiteral") {
266
+ modulesArray.push(element.value);
267
+ } else if (element.type === "ArrayExpression" && element.elements.length > 0) {
268
+ const firstElement = element.elements[0];
269
+ if (firstElement && firstElement.type === "StringLiteral") {
270
+ modulesArray.push(firstElement.value);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+ path2.stop();
277
+ return;
278
+ }
279
+ }
280
+ }
281
+ }
282
+ }
283
+ });
284
+ return modulesArray;
285
+ } catch (e) {
286
+ console.error("AST parsing or traversal failed:", e);
287
+ return [];
288
+ }
289
+ }
290
+
291
+ export {
292
+ useStaticBuild,
293
+ resetEdgeOneConfig,
294
+ getRouteRulesWithAST,
295
+ getPrerenderRoutesWithAST,
296
+ getRoutesArrayWithAST,
297
+ getHandlersArrayWithAST,
298
+ getModulesWithAST
299
+ };