@edgeone/nuxt-pages 1.0.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.
- package/README.md +255 -0
- package/dist/build/content/server.js +18 -0
- package/dist/build/content/static.js +17 -0
- package/dist/build/functions/server.js +17 -0
- package/dist/build/plugin-context.js +16 -0
- package/dist/build/routes.js +18 -0
- package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +260 -0
- package/dist/esm-chunks/chunk-5JK44IEA.js +15106 -0
- package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
- package/dist/esm-chunks/chunk-7RNB5RB6.js +131 -0
- package/dist/esm-chunks/chunk-L23O2KDO.js +120 -0
- package/dist/esm-chunks/chunk-TP3RAVPL.js +5635 -0
- package/dist/esm-chunks/chunk-UFRAZNP3.js +261 -0
- package/dist/esm-chunks/chunk-V2LFVP3C.js +838 -0
- package/dist/esm-chunks/chunk-Y3YAV6NZ.js +439 -0
- package/dist/index.js +89 -0
- package/dist/types/options.js +6 -0
- package/dist/utils.js +29 -0
- package/package.json +58 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
14
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
15
|
+
}) : x)(function(x) {
|
|
16
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
17
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
|
+
});
|
|
19
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
20
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(from))
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
+
}
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
__require,
|
|
41
|
+
__commonJS,
|
|
42
|
+
__toESM
|
|
43
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
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-5JK44IEA.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/cloud-functions/ssr-node',
|
|
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/cloud-functions/ssr-node',
|
|
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
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
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_out,
|
|
9
|
+
verifyNuxtHandlerDirStructure
|
|
10
|
+
} from "./chunk-TP3RAVPL.js";
|
|
11
|
+
import {
|
|
12
|
+
__require,
|
|
13
|
+
__toESM
|
|
14
|
+
} from "./chunk-6BT4RYQJ.js";
|
|
15
|
+
|
|
16
|
+
// src/build/functions/server.ts
|
|
17
|
+
var import_fast_glob = __toESM(require_out(), 1);
|
|
18
|
+
import { cp, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
19
|
+
import { join, relative } from "node:path";
|
|
20
|
+
import { join as posixJoin } from "node:path/posix";
|
|
21
|
+
var copyHandlerDependencies = async (ctx) => {
|
|
22
|
+
const promises = [];
|
|
23
|
+
const { included_files: includedFiles = [] } = {};
|
|
24
|
+
includedFiles.push(
|
|
25
|
+
posixJoin(ctx.relativeAppDir, ".env"),
|
|
26
|
+
posixJoin(ctx.relativeAppDir, ".env.production"),
|
|
27
|
+
posixJoin(ctx.relativeAppDir, ".env.local"),
|
|
28
|
+
posixJoin(ctx.relativeAppDir, ".env.production.local")
|
|
29
|
+
);
|
|
30
|
+
const resolvedFiles = await Promise.all(
|
|
31
|
+
includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
|
|
32
|
+
);
|
|
33
|
+
for (const filePath of resolvedFiles.flat()) {
|
|
34
|
+
promises.push(
|
|
35
|
+
cp(
|
|
36
|
+
join(process.cwd(), filePath),
|
|
37
|
+
// the serverHandlerDir is aware of the dist dir.
|
|
38
|
+
// The distDir must not be the package path therefore we need to rely on the
|
|
39
|
+
// serverHandlerDir instead of the serverHandlerRootDir
|
|
40
|
+
// therefore we need to remove the package path from the filePath
|
|
41
|
+
join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
|
|
42
|
+
{
|
|
43
|
+
recursive: true,
|
|
44
|
+
force: true
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
promises.push(
|
|
50
|
+
writeFile(
|
|
51
|
+
join(ctx.serverHandlerRuntimeModulesDir, "package.json"),
|
|
52
|
+
JSON.stringify({ type: "module" })
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
|
|
56
|
+
for (const filePath of fileList) {
|
|
57
|
+
promises.push(
|
|
58
|
+
cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerRuntimeModulesDir, filePath), {
|
|
59
|
+
recursive: true,
|
|
60
|
+
force: true
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
await Promise.all(promises);
|
|
65
|
+
};
|
|
66
|
+
var applyTemplateVariables = (template, variables) => {
|
|
67
|
+
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
68
|
+
return acc.replaceAll(key, value);
|
|
69
|
+
}, template);
|
|
70
|
+
};
|
|
71
|
+
var getHandlerFile = async (ctx) => {
|
|
72
|
+
const templatesDir = join(ctx.pluginDir, "dist/build/templates");
|
|
73
|
+
const templateVariables = {
|
|
74
|
+
"{{useRegionalBlobs}}": ctx.useRegionalBlobs.toString()
|
|
75
|
+
};
|
|
76
|
+
if (ctx.relativeAppDir.length !== 0) {
|
|
77
|
+
const templateName2 = "nuxt-handler-monorepo.tmpl.js";
|
|
78
|
+
const template = await readFile(join(templatesDir, templateName2), "utf-8");
|
|
79
|
+
console.log("Lambda working directory:", ctx.lambdaWorkingDirectory);
|
|
80
|
+
console.log("Server handler path:", ctx.nuxtServerHandler);
|
|
81
|
+
templateVariables["{{cwd}}"] = posixJoin(ctx.lambdaWorkingDirectory);
|
|
82
|
+
templateVariables["{{nuxtServerHandler}}"] = posixJoin(ctx.nuxtServerHandler);
|
|
83
|
+
return applyTemplateVariables(template, templateVariables);
|
|
84
|
+
}
|
|
85
|
+
const templateName = "nuxt-handler.tmpl.js";
|
|
86
|
+
console.log(`Using 'Nuxt' handler template: ${templateName}`);
|
|
87
|
+
return applyTemplateVariables(
|
|
88
|
+
await readFile(join(templatesDir, templateName), "utf-8"),
|
|
89
|
+
templateVariables
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
var writeHandlerFile = async (ctx) => {
|
|
93
|
+
const handler = await getHandlerFile(ctx);
|
|
94
|
+
await writeFile(join(ctx.serverHandlerRootDir, `handler.js`), handler);
|
|
95
|
+
};
|
|
96
|
+
var createServerHandler = async (ctx) => {
|
|
97
|
+
await mkdir(join(ctx.serverHandlerRuntimeModulesDir), { recursive: true });
|
|
98
|
+
await copyHandlerDependencies(ctx);
|
|
99
|
+
await writeHandlerFile(ctx);
|
|
100
|
+
await verifyNuxtHandlerDirStructure(ctx);
|
|
101
|
+
};
|
|
102
|
+
async function patchNitroHandler(ctx) {
|
|
103
|
+
const fs = __require("fs");
|
|
104
|
+
const defaultNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "nitro", "nitro.mjs");
|
|
105
|
+
const fallbackNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "_", "nitro.mjs");
|
|
106
|
+
const nitroMjsPath = fs.existsSync(defaultNitroMjsPath) ? defaultNitroMjsPath : fallbackNitroMjsPath;
|
|
107
|
+
const handlerTmplPath = join(ctx.serverHandlerRootDir, "handler.js");
|
|
108
|
+
const nitroCode = fs.readFileSync(nitroMjsPath, "utf-8");
|
|
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
|
+
if (!match) throw new Error("Cannot find useNitroApp export symbol in nitro.mjs!");
|
|
111
|
+
const symbol = match[1];
|
|
112
|
+
let handlerCode = await fs.readFileSync(handlerTmplPath, "utf-8");
|
|
113
|
+
handlerCode = handlerCode.replace(/{{USE_NITRO_APP_SYMBOL}}/g, symbol);
|
|
114
|
+
await fs.writeFileSync(handlerTmplPath, handlerCode);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
createServerHandler,
|
|
119
|
+
patchNitroHandler
|
|
120
|
+
};
|