@edgeone/nuxt-pages 1.1.0-beta.3 → 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.
- package/dist/build/content/{static.js → module-inject.js} +8 -7
- package/dist/build/content/server.js +1 -2
- package/dist/build/functions/server.js +2 -3
- package/dist/build/plugin-context.js +3 -2
- package/dist/build/routes.js +7 -4
- package/dist/esm-chunks/chunk-3HA3DZ3G.js +261 -0
- package/dist/esm-chunks/chunk-AZLY3JO2.js +299 -0
- package/dist/esm-chunks/{chunk-NJ4SUJNF.js → chunk-K5VT7O2H.js} +844 -19
- package/dist/esm-chunks/{chunk-RNEZUAPL.js → chunk-PJWA566S.js} +4 -4
- package/dist/esm-chunks/{chunk-MONI3XWQ.js → chunk-VCJ5U4PV.js} +24 -541
- package/dist/esm-chunks/{chunk-BZQMVWYQ.js → chunk-VDBASNGL.js} +3 -3
- package/dist/esm-chunks/chunk-ZR3DYEBK.js +180 -0
- package/dist/index.js +28 -25
- package/dist/utils.js +2 -5
- package/package.json +3 -2
- package/dist/esm-chunks/chunk-7X4RPD4I.js +0 -131
- package/dist/esm-chunks/chunk-J25U56II.js +0 -213
- package/dist/esm-chunks/chunk-V2LFVP3C.js +0 -838
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getPrerenderRoutesWithAST,
|
|
10
10
|
getRouteRulesWithAST,
|
|
11
11
|
getRoutesArrayWithAST
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-AZLY3JO2.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 = "
|
|
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", "
|
|
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
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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/build/content/module-inject.ts
|
|
15
|
+
var parser = __toESM(require_lib(), 1);
|
|
16
|
+
import { existsSync } from "node:fs";
|
|
17
|
+
import { readFile, writeFile, rm } from "node:fs/promises";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { createRequire } from "node:module";
|
|
20
|
+
var require2 = createRequire(import.meta.url);
|
|
21
|
+
var traverse = require2("@babel/traverse").default;
|
|
22
|
+
var generate = require2("@babel/generator").default;
|
|
23
|
+
var TEMP_MODULE_FILENAME = ".edgeone-nitro-config.mjs";
|
|
24
|
+
function generateModuleContent() {
|
|
25
|
+
return `// Auto-generated by @edgeone/nuxt-pages \u2014 DO NOT EDIT
|
|
26
|
+
// This file will be removed after build completes.
|
|
27
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
28
|
+
|
|
29
|
+
export default defineNuxtModule({
|
|
30
|
+
meta: { name: 'edgeone-nitro-config' },
|
|
31
|
+
setup(_options, nuxt) {
|
|
32
|
+
nuxt.hook('nitro:config', (nitroConfig) => {
|
|
33
|
+
// Store original values for reference
|
|
34
|
+
const originalOutput = nitroConfig.output ? { ...nitroConfig.output } : null
|
|
35
|
+
const originalPreset = nitroConfig.preset
|
|
36
|
+
|
|
37
|
+
// Override output directories for EdgeOne deployment
|
|
38
|
+
nitroConfig.output = nitroConfig.output || {}
|
|
39
|
+
nitroConfig.output.dir = '.edgeone'
|
|
40
|
+
nitroConfig.output.publicDir = '.edgeone/assets'
|
|
41
|
+
nitroConfig.output.serverDir = '.edgeone/cloud-functions/ssr-node'
|
|
42
|
+
|
|
43
|
+
// Remove preset to use default node-server
|
|
44
|
+
if (nitroConfig.preset && nitroConfig.preset !== 'node-server') {
|
|
45
|
+
delete nitroConfig.preset
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
async function writeTempModule(projectRoot) {
|
|
53
|
+
const modulePath = join(projectRoot, TEMP_MODULE_FILENAME);
|
|
54
|
+
await writeFile(modulePath, generateModuleContent(), "utf-8");
|
|
55
|
+
console.log(`Created temporary EdgeOne module: ${modulePath}`);
|
|
56
|
+
return modulePath;
|
|
57
|
+
}
|
|
58
|
+
async function removeTempModule(projectRoot) {
|
|
59
|
+
const modulePath = join(projectRoot, TEMP_MODULE_FILENAME);
|
|
60
|
+
if (existsSync(modulePath)) {
|
|
61
|
+
await rm(modulePath, { force: true });
|
|
62
|
+
console.log(`Removed temporary EdgeOne module: ${modulePath}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function addModuleToConfig(code, moduleRef) {
|
|
66
|
+
try {
|
|
67
|
+
const ast = parser.parse(code, {
|
|
68
|
+
sourceType: "module",
|
|
69
|
+
plugins: ["typescript"]
|
|
70
|
+
});
|
|
71
|
+
let configObjectNode = null;
|
|
72
|
+
let modulesArrayNode = null;
|
|
73
|
+
traverse(ast, {
|
|
74
|
+
CallExpression(path) {
|
|
75
|
+
const { node } = path;
|
|
76
|
+
if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig" && node.arguments.length > 0) {
|
|
77
|
+
let arg = node.arguments[0];
|
|
78
|
+
while (arg.type === "TSAsExpression" || arg.type === "TSSatisfiesExpression" || arg.type === "TSTypeAssertion") {
|
|
79
|
+
arg = arg.expression;
|
|
80
|
+
}
|
|
81
|
+
if (arg.type !== "ObjectExpression") return;
|
|
82
|
+
configObjectNode = arg;
|
|
83
|
+
for (const prop of configObjectNode.properties) {
|
|
84
|
+
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "modules" && prop.value.type === "ArrayExpression") {
|
|
85
|
+
modulesArrayNode = prop.value;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
path.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (!configObjectNode) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const originalCode = code;
|
|
97
|
+
if (modulesArrayNode) {
|
|
98
|
+
const stringLiteral = {
|
|
99
|
+
type: "StringLiteral",
|
|
100
|
+
value: moduleRef
|
|
101
|
+
};
|
|
102
|
+
modulesArrayNode.elements.unshift(stringLiteral);
|
|
103
|
+
} else {
|
|
104
|
+
const modulesProp = {
|
|
105
|
+
type: "ObjectProperty",
|
|
106
|
+
key: { type: "Identifier", name: "modules" },
|
|
107
|
+
value: {
|
|
108
|
+
type: "ArrayExpression",
|
|
109
|
+
elements: [{ type: "StringLiteral", value: moduleRef }]
|
|
110
|
+
},
|
|
111
|
+
computed: false,
|
|
112
|
+
shorthand: false
|
|
113
|
+
};
|
|
114
|
+
configObjectNode.properties.unshift(modulesProp);
|
|
115
|
+
}
|
|
116
|
+
const output = generate(ast, { retainLines: true }, code);
|
|
117
|
+
return { newCode: output.code, originalCode };
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error("Failed to inject module into nuxt config:", e);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function injectEdgeoneModule(configPath, projectRoot) {
|
|
124
|
+
const result = {
|
|
125
|
+
success: false,
|
|
126
|
+
originalConfigContent: null,
|
|
127
|
+
configPath,
|
|
128
|
+
projectRoot
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
await writeTempModule(projectRoot);
|
|
132
|
+
if (!configPath || !existsSync(configPath)) {
|
|
133
|
+
const defaultConfig = `export default defineNuxtConfig({
|
|
134
|
+
modules: ['./${TEMP_MODULE_FILENAME}'],
|
|
135
|
+
})`;
|
|
136
|
+
const newConfigPath = join(projectRoot, "nuxt.config.ts");
|
|
137
|
+
await writeFile(newConfigPath, defaultConfig, "utf-8");
|
|
138
|
+
console.log(`Created nuxt.config.ts with EdgeOne module at: ${newConfigPath}`);
|
|
139
|
+
result.configPath = newConfigPath;
|
|
140
|
+
result.originalConfigContent = null;
|
|
141
|
+
result.success = true;
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
const configContent = await readFile(configPath, "utf-8");
|
|
145
|
+
const moduleRef = `./${TEMP_MODULE_FILENAME}`;
|
|
146
|
+
const astResult = addModuleToConfig(configContent, moduleRef);
|
|
147
|
+
if (astResult) {
|
|
148
|
+
await writeFile(configPath, astResult.newCode, "utf-8");
|
|
149
|
+
console.log(`Injected EdgeOne module into: ${configPath}`);
|
|
150
|
+
result.originalConfigContent = astResult.originalCode;
|
|
151
|
+
result.success = true;
|
|
152
|
+
} else {
|
|
153
|
+
console.error("Failed to inject module via AST, cleaning up temp module file");
|
|
154
|
+
await removeTempModule(projectRoot);
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error("injectEdgeoneModule failed:", error);
|
|
158
|
+
await removeTempModule(projectRoot).catch(() => {
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
async function cleanupEdgeoneModule(injectionResult) {
|
|
164
|
+
try {
|
|
165
|
+
const { originalConfigContent, configPath, projectRoot } = injectionResult;
|
|
166
|
+
if (originalConfigContent !== null && existsSync(configPath)) {
|
|
167
|
+
await writeFile(configPath, originalConfigContent, "utf-8");
|
|
168
|
+
console.log(`Restored nuxt config: ${configPath}`);
|
|
169
|
+
}
|
|
170
|
+
await removeTempModule(projectRoot);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error("cleanupEdgeoneModule failed:", error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
removeTempModule,
|
|
178
|
+
injectEdgeoneModule,
|
|
179
|
+
cleanupEdgeoneModule
|
|
180
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -6,25 +6,25 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
PluginContext
|
|
9
|
-
} from "./esm-chunks/chunk-
|
|
9
|
+
} from "./esm-chunks/chunk-VDBASNGL.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./esm-chunks/chunk-J25U56II.js";
|
|
14
|
-
import {
|
|
15
|
-
createServerHandler,
|
|
16
|
-
patchNitroHandler
|
|
17
|
-
} from "./esm-chunks/chunk-RNEZUAPL.js";
|
|
18
|
-
import "./esm-chunks/chunk-NJ4SUJNF.js";
|
|
19
|
-
import {
|
|
20
|
-
addNitroBuildOutputConfig,
|
|
21
|
-
resetNitroConfig
|
|
22
|
-
} from "./esm-chunks/chunk-7X4RPD4I.js";
|
|
11
|
+
createNuxtRoutesMeta
|
|
12
|
+
} from "./esm-chunks/chunk-3HA3DZ3G.js";
|
|
23
13
|
import {
|
|
24
14
|
resetEdgeOneConfig,
|
|
25
15
|
useStaticBuild
|
|
26
|
-
} from "./esm-chunks/chunk-
|
|
27
|
-
import
|
|
16
|
+
} from "./esm-chunks/chunk-AZLY3JO2.js";
|
|
17
|
+
import {
|
|
18
|
+
cleanupEdgeoneModule,
|
|
19
|
+
injectEdgeoneModule,
|
|
20
|
+
removeTempModule
|
|
21
|
+
} from "./esm-chunks/chunk-ZR3DYEBK.js";
|
|
22
|
+
import "./esm-chunks/chunk-VCJ5U4PV.js";
|
|
23
|
+
import {
|
|
24
|
+
createServerHandler,
|
|
25
|
+
patchNitroHandler
|
|
26
|
+
} from "./esm-chunks/chunk-PJWA566S.js";
|
|
27
|
+
import "./esm-chunks/chunk-K5VT7O2H.js";
|
|
28
28
|
import "./esm-chunks/chunk-6BT4RYQJ.js";
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
@@ -44,17 +44,18 @@ var removeIndexMJS = async (ctx) => {
|
|
|
44
44
|
await rm(join(ctx.serverHandlerDir, "index.mjs"), { force: true });
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
var
|
|
47
|
+
var moduleInjectionResult = null;
|
|
48
48
|
var recordOldEdgeOneConfig = -1;
|
|
49
49
|
var onPreBuild = async (options) => {
|
|
50
50
|
try {
|
|
51
51
|
const ctx = new PluginContext(options);
|
|
52
|
-
recordOldNitroConfig = await addNitroBuildOutputConfig(ctx);
|
|
53
52
|
const packagePath = ctx.resolveFromPackagePath("");
|
|
54
|
-
const
|
|
53
|
+
const projectRoot = packagePath || process.cwd();
|
|
54
|
+
const configPath = ctx.nuxtConfigPath || "";
|
|
55
|
+
moduleInjectionResult = await injectEdgeoneModule(configPath, projectRoot);
|
|
55
56
|
if (await checkModules(ctx, "@nuxt/content")) {
|
|
56
57
|
console.warn("\u26A0\uFE0F @nuxt/content detected, switching to static deployment.");
|
|
57
|
-
recordOldEdgeOneConfig = useStaticBuild(
|
|
58
|
+
recordOldEdgeOneConfig = useStaticBuild(projectRoot);
|
|
58
59
|
}
|
|
59
60
|
} catch (error) {
|
|
60
61
|
console.error("onPreBuild failed:", error);
|
|
@@ -67,20 +68,22 @@ var onBuild = async (options) => {
|
|
|
67
68
|
await removeServerHandler(ctx);
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
|
-
await createServerHandler(ctx), await
|
|
71
|
-
await createNuxtApiRoutesMeta(ctx);
|
|
71
|
+
await createServerHandler(ctx), await createNuxtRoutesMeta(ctx);
|
|
72
72
|
await patchNitroHandler(ctx);
|
|
73
73
|
};
|
|
74
74
|
var onPostBuild = async (options) => {
|
|
75
75
|
const ctx = new PluginContext(options);
|
|
76
76
|
const packagePath = ctx.resolveFromPackagePath("");
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
await
|
|
77
|
+
const projectRoot = packagePath || process.cwd();
|
|
78
|
+
if (moduleInjectionResult) {
|
|
79
|
+
await cleanupEdgeoneModule(moduleInjectionResult);
|
|
80
80
|
await removeIndexMJS(ctx);
|
|
81
|
+
} else {
|
|
82
|
+
await removeTempModule(projectRoot).catch(() => {
|
|
83
|
+
});
|
|
81
84
|
}
|
|
82
85
|
if (recordOldEdgeOneConfig !== -1) {
|
|
83
|
-
resetEdgeOneConfig(
|
|
86
|
+
resetEdgeOneConfig(projectRoot, recordOldEdgeOneConfig);
|
|
84
87
|
}
|
|
85
88
|
};
|
|
86
89
|
export {
|
package/dist/utils.js
CHANGED
|
@@ -5,25 +5,22 @@
|
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
addCodeToGenerateEdgeoneWithAST,
|
|
9
8
|
getHandlersArrayWithAST,
|
|
10
9
|
getModulesWithAST,
|
|
11
10
|
getPrerenderRoutesWithAST,
|
|
12
11
|
getRouteRulesWithAST,
|
|
13
12
|
getRoutesArrayWithAST,
|
|
14
13
|
resetEdgeOneConfig,
|
|
15
|
-
resetNitroConfigWithAST,
|
|
16
14
|
useStaticBuild
|
|
17
|
-
} from "./esm-chunks/chunk-
|
|
15
|
+
} from "./esm-chunks/chunk-AZLY3JO2.js";
|
|
16
|
+
import "./esm-chunks/chunk-VCJ5U4PV.js";
|
|
18
17
|
import "./esm-chunks/chunk-6BT4RYQJ.js";
|
|
19
18
|
export {
|
|
20
|
-
addCodeToGenerateEdgeoneWithAST,
|
|
21
19
|
getHandlersArrayWithAST,
|
|
22
20
|
getModulesWithAST,
|
|
23
21
|
getPrerenderRoutesWithAST,
|
|
24
22
|
getRouteRulesWithAST,
|
|
25
23
|
getRoutesArrayWithAST,
|
|
26
24
|
resetEdgeOneConfig,
|
|
27
|
-
resetNitroConfigWithAST,
|
|
28
25
|
useStaticBuild
|
|
29
26
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgeone/nuxt-pages",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "
|
|
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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"license": "ISC",
|
|
37
37
|
"description": "",
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@babel/generator": "^7.28.4",
|
|
39
40
|
"@babel/parser": "^7.28.4",
|
|
40
41
|
"@babel/traverse": "^7.28.4",
|
|
41
42
|
"@babel/types": "^7.28.4",
|
|
@@ -1,131 +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
|
-
addCodeToGenerateEdgeoneWithAST,
|
|
9
|
-
resetNitroConfigWithAST
|
|
10
|
-
} from "./chunk-MONI3XWQ.js";
|
|
11
|
-
import {
|
|
12
|
-
trace,
|
|
13
|
-
wrapTracer
|
|
14
|
-
} from "./chunk-V2LFVP3C.js";
|
|
15
|
-
|
|
16
|
-
// src/build/content/static.ts
|
|
17
|
-
import { existsSync } from "node:fs";
|
|
18
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
19
|
-
var tracer = wrapTracer(trace.getTracer("Nuxt runtime"));
|
|
20
|
-
var addNitroBuildOutputConfig = async (ctx) => {
|
|
21
|
-
return tracer.withActiveSpan(
|
|
22
|
-
"addNitroBuildOutputConfig",
|
|
23
|
-
async (span) => {
|
|
24
|
-
const result = {
|
|
25
|
-
success: false,
|
|
26
|
-
message: ""
|
|
27
|
-
};
|
|
28
|
-
try {
|
|
29
|
-
const nitroConfigDir = ctx.nuxtConfigPath;
|
|
30
|
-
if (!nitroConfigDir || !existsSync(nitroConfigDir)) {
|
|
31
|
-
console.log("Nuxt config file not found, creating nuxt.config.ts...");
|
|
32
|
-
const defaultNuxtConfig = `export default defineNuxtConfig({
|
|
33
|
-
srcDir: 'app',
|
|
34
|
-
nitro: {
|
|
35
|
-
output: {
|
|
36
|
-
dir: '.edgeone',
|
|
37
|
-
publicDir: '.edgeone/assets',
|
|
38
|
-
serverDir: '.edgeone/server-handler',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
devtools: { enabled: true },
|
|
42
|
-
})`;
|
|
43
|
-
const configPath = ctx.resolveFromPackagePath("nuxt.config.ts");
|
|
44
|
-
await writeFile(configPath, defaultNuxtConfig, "utf-8");
|
|
45
|
-
console.log(`Created nuxt.config.ts at: ${configPath}`);
|
|
46
|
-
Object.assign(result, {
|
|
47
|
-
success: true,
|
|
48
|
-
message: `Created nuxt.config.ts at: ${configPath}`,
|
|
49
|
-
configPath,
|
|
50
|
-
newCode: defaultNuxtConfig
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
console.log("Nuxt config file found, adding nitro.output config...");
|
|
54
|
-
const configContent = await readFile(nitroConfigDir, "utf-8");
|
|
55
|
-
const astResult = addCodeToGenerateEdgeoneWithAST(configContent, `
|
|
56
|
-
nitro: {
|
|
57
|
-
output: {
|
|
58
|
-
dir: '.edgeone',
|
|
59
|
-
publicDir: '.edgeone/assets',
|
|
60
|
-
serverDir: '.edgeone/server-handler',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
`);
|
|
64
|
-
if (astResult?.newCode) {
|
|
65
|
-
await writeFile(nitroConfigDir, astResult.newCode, "utf-8");
|
|
66
|
-
console.log(`Successfully updated nuxt config file: ${nitroConfigDir}`);
|
|
67
|
-
Object.assign(result, {
|
|
68
|
-
success: true,
|
|
69
|
-
message: `Successfully updated nuxt config file: ${nitroConfigDir}`,
|
|
70
|
-
configPath: nitroConfigDir,
|
|
71
|
-
oldOutput: astResult.oldOutput,
|
|
72
|
-
oldPreset: astResult.oldPreset,
|
|
73
|
-
newCode: astResult.newCode
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
console.log("Failed to generate new config code");
|
|
77
|
-
Object.assign(result, {
|
|
78
|
-
success: false,
|
|
79
|
-
message: "Failed to generate new config code",
|
|
80
|
-
configPath: nitroConfigDir
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
span.end();
|
|
86
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
87
|
-
ctx.failBuild("Failed copying static assets", error);
|
|
88
|
-
Object.assign(result, {
|
|
89
|
-
success: false,
|
|
90
|
-
message: `Error: ${errorMessage}`
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
var resetNitroConfig = async (oldOutput, oldPreset) => {
|
|
98
|
-
try {
|
|
99
|
-
const possiblePaths = [
|
|
100
|
-
process.cwd() + "/nuxt.config.ts",
|
|
101
|
-
process.cwd() + "/nuxt.config.js",
|
|
102
|
-
process.cwd() + "/nuxt.config.mjs"
|
|
103
|
-
];
|
|
104
|
-
let configPath = null;
|
|
105
|
-
for (const path of possiblePaths) {
|
|
106
|
-
if (existsSync(path)) {
|
|
107
|
-
configPath = path;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (!configPath) {
|
|
112
|
-
console.warn("nuxt.config.ts not found, cannot reset config");
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const configContent = await readFile(configPath, "utf-8");
|
|
116
|
-
const restoredCode = resetNitroConfigWithAST(configContent, oldOutput, oldPreset);
|
|
117
|
-
if (restoredCode) {
|
|
118
|
-
await writeFile(configPath, restoredCode, "utf-8");
|
|
119
|
-
console.log(`Successfully restored nuxt config file: ${configPath}`);
|
|
120
|
-
} else {
|
|
121
|
-
console.warn("Failed to restore nuxt.config.ts using AST");
|
|
122
|
-
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
console.error("Error restoring nuxt.config.ts:", error);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export {
|
|
129
|
-
addNitroBuildOutputConfig,
|
|
130
|
-
resetNitroConfig
|
|
131
|
-
};
|
|
@@ -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
|
-
};
|