@edgeone/nuxt-pages 1.0.13 → 1.0.15

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 (38) hide show
  1. package/dist/build/content/static.js +2 -2
  2. package/dist/build/functions/server.js +1 -1
  3. package/dist/build/plugin-context.js +2 -2
  4. package/dist/build/routes.js +2 -2
  5. package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +0 -23
  6. package/dist/esm-chunks/{chunk-7JK67XZ2.js → chunk-BZJ7SD7E.js} +4 -4
  7. package/dist/esm-chunks/{chunk-QG7JLDXY.js → chunk-DOOA3WBA.js} +2 -2
  8. package/dist/esm-chunks/{chunk-3BGGEHKE.js → chunk-ESOQYHZZ.js} +13 -53
  9. package/dist/esm-chunks/{chunk-Y4NVMSL3.js → chunk-KYSZO4TW.js} +4 -1
  10. package/dist/esm-chunks/{chunk-5VJRCUAW.js → chunk-ZG3P7BHA.js} +87 -22
  11. package/dist/index.js +33 -18
  12. package/dist/utils.js +13 -3
  13. package/package.json +1 -1
  14. package/dist/esm-chunks/chunk-5YBUNNZ4.js +0 -81
  15. package/dist/esm-chunks/chunk-HBXUWFGE.js +0 -19
  16. package/dist/esm-chunks/chunk-HY3HNABZ.js +0 -87
  17. package/dist/esm-chunks/chunk-KGYBHZC3.js +0 -1467
  18. package/dist/esm-chunks/chunk-UOPC2N5A.js +0 -69
  19. package/dist/run/config.js +0 -17
  20. package/dist/run/constants.js +0 -17
  21. package/dist/run/handlers/cache.cjs +0 -1410
  22. package/dist/run/handlers/nuxt-cache.cjs +0 -200
  23. package/dist/run/handlers/nuxt-server.js +0 -155
  24. package/dist/run/handlers/request-context.cjs +0 -148
  25. package/dist/run/handlers/server.js +0 -77
  26. package/dist/run/handlers/tags-handler.cjs +0 -177
  27. package/dist/run/handlers/tracer.cjs +0 -1004
  28. package/dist/run/handlers/use-cache-handler.js +0 -220
  29. package/dist/run/handlers/wait-until.cjs +0 -123
  30. package/dist/run/headers.js +0 -17
  31. package/dist/run/revalidate.js +0 -34
  32. package/dist/run/storage/regional-blob-store.cjs +0 -64
  33. package/dist/run/storage/request-scoped-in-memory-cache.cjs +0 -1582
  34. package/dist/run/storage/storage.cjs +0 -191
  35. package/dist/shared/blob-types.cjs +0 -37
  36. package/dist/shared/blobkey.js +0 -25
  37. package/dist/shared/cache-types.cjs +0 -33
  38. package/dist/shared/nuxt-cache-types.cjs +0 -18
@@ -7,9 +7,9 @@
7
7
  import {
8
8
  addNitroBuildOutputConfig,
9
9
  resetNitroConfig
10
- } from "../../esm-chunks/chunk-7JK67XZ2.js";
10
+ } from "../../esm-chunks/chunk-BZJ7SD7E.js";
11
+ import "../../esm-chunks/chunk-ZG3P7BHA.js";
11
12
  import "../../esm-chunks/chunk-V2LFVP3C.js";
12
- import "../../esm-chunks/chunk-5VJRCUAW.js";
13
13
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
15
15
  addNitroBuildOutputConfig,
@@ -8,7 +8,7 @@ import {
8
8
  clearStaleServerHandlers,
9
9
  createServerHandler,
10
10
  patchNitroHandler
11
- } from "../../esm-chunks/chunk-QG7JLDXY.js";
11
+ } from "../../esm-chunks/chunk-DOOA3WBA.js";
12
12
  import "../../esm-chunks/chunk-NJ4SUJNF.js";
13
13
  import "../../esm-chunks/chunk-V2LFVP3C.js";
14
14
  import "../../esm-chunks/chunk-6BT4RYQJ.js";
@@ -8,8 +8,8 @@ import {
8
8
  EDGE_HANDLER_NAME,
9
9
  PluginContext,
10
10
  SERVER_HANDLER_NAME
11
- } from "../esm-chunks/chunk-3BGGEHKE.js";
12
- import "../esm-chunks/chunk-5VJRCUAW.js";
11
+ } from "../esm-chunks/chunk-ESOQYHZZ.js";
12
+ import "../esm-chunks/chunk-ZG3P7BHA.js";
13
13
  import "../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
15
15
  EDGE_HANDLER_NAME,
@@ -8,8 +8,8 @@ import {
8
8
  convertNuxtRoutePattern,
9
9
  createNuxtApiRoutesMeta,
10
10
  createNuxtPagesRouteMeta
11
- } from "../esm-chunks/chunk-Y4NVMSL3.js";
12
- import "../esm-chunks/chunk-5VJRCUAW.js";
11
+ } from "../esm-chunks/chunk-KYSZO4TW.js";
12
+ import "../esm-chunks/chunk-ZG3P7BHA.js";
13
13
  import "../esm-chunks/chunk-6BT4RYQJ.js";
14
14
  export {
15
15
  convertNuxtRoutePattern,
@@ -86,29 +86,6 @@ function handleStaticFile(url) {
86
86
  }
87
87
  }
88
88
  }
89
-
90
- if(cleanUrl.includes('-ssr-functions/_ipx/')) {
91
- let newUrl = '';
92
- const pathSegments = cleanUrl.split('/') // Remove empty segments
93
- if(pathSegments.length === 0) {
94
- return null;
95
- }
96
- // Check each segment for file extension
97
- newUrl = pathSegments.slice(4).join('/');
98
- if(newUrl.includes('http:/') && !newUrl.includes('http://')) {
99
- newUrl = newUrl.replace('http:/', 'http://');
100
- } else if(newUrl.includes('https:/') && !newUrl.includes('https://')) {
101
- newUrl = newUrl.replace('https:/', 'https://');
102
- }
103
-
104
- return {
105
- statusCode: 302,
106
- headers: {
107
- 'from-server': 'true',
108
- location: newUrl
109
- }
110
- }
111
- }
112
89
 
113
90
  // 本地调试寻找文件路径
114
91
  const possiblePaths = [];
@@ -4,14 +4,14 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
+ import {
8
+ addCodeToGenerateEdgeoneWithAST,
9
+ resetNitroConfigWithAST
10
+ } from "./chunk-ZG3P7BHA.js";
7
11
  import {
8
12
  trace,
9
13
  wrapTracer
10
14
  } from "./chunk-V2LFVP3C.js";
11
- import {
12
- addCodeToGenerateEdgeoneWithAST,
13
- resetNitroConfigWithAST
14
- } from "./chunk-5VJRCUAW.js";
15
15
 
16
16
  // src/build/content/static.ts
17
17
  import { existsSync } from "node:fs";
@@ -112,8 +112,8 @@ async function patchNitroHandler(ctx) {
112
112
  const nitroMjsPath = ".edgeone/server-handler/chunks/nitro/nitro.mjs";
113
113
  const handlerTmplPath = ".edgeone/server-handler/handler.js";
114
114
  const nitroCode = fs.readFileSync(nitroMjsPath, "utf-8");
115
- const match = nitroCode.match(/useNitroApp as (\w)/);
116
- if (!match) throw new Error("Cannot find useNitroApp export symbol!");
115
+ 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/);
116
+ if (!match) throw new Error("Cannot find useNitroApp export symbol in nitro.mjs!");
117
117
  const symbol = match[1];
118
118
  let handlerCode = await fs.readFileSync(handlerTmplPath, "utf-8");
119
119
  handlerCode = handlerCode.replace(/{{USE_NITRO_APP_SYMBOL}}/g, symbol);
@@ -9,14 +9,13 @@ import {
9
9
  getPrerenderRoutesWithAST,
10
10
  getRouteRulesWithAST,
11
11
  getRoutesArrayWithAST
12
- } from "./chunk-5VJRCUAW.js";
12
+ } from "./chunk-ZG3P7BHA.js";
13
13
 
14
14
  // src/build/plugin-context.ts
15
15
  import { existsSync, readFileSync } from "node:fs";
16
16
  import { readFile } from "node:fs/promises";
17
- import { createRequire } from "node:module";
17
+ import { execSync } from "node:child_process";
18
18
  import { join, relative, resolve } from "node:path";
19
- import { join as posixJoin } from "node:path/posix";
20
19
  import { fileURLToPath } from "node:url";
21
20
  var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
22
21
  var PLUGIN_DIR = join(MODULE_DIR, "../..");
@@ -178,10 +177,6 @@ var PluginContext = class {
178
177
  resolveFromPackagePath(...args) {
179
178
  return resolve(this.constants.PACKAGE_PATH || "", ...args);
180
179
  }
181
- /** Resolves a path correctly from site directory */
182
- resolveFromSiteDir(...args) {
183
- return resolve(this.buildManifest?.buildDir || process.cwd(), ...args);
184
- }
185
180
  /** Get the nuxt routes manifest */
186
181
  async getRoutesManifest() {
187
182
  try {
@@ -446,49 +441,6 @@ var PluginContext = class {
446
441
  });
447
442
  return result;
448
443
  }
449
- /** Extract _routes array from server.mjs content */
450
- extractRoutesFromServerMjs(content) {
451
- try {
452
- const routesArray = getRoutesArrayWithAST(content);
453
- if (!routesArray) {
454
- console.log("_routes array not found in server.mjs");
455
- return null;
456
- }
457
- console.log("Found _routes array with", routesArray.length, "routes");
458
- return routesArray;
459
- } catch (error) {
460
- console.error("Error extracting routes from server.mjs:", error);
461
- return null;
462
- }
463
- }
464
- /**
465
- * Get Nuxt assets manifest from the build output
466
- * This handles the asset optimization routes for Nuxt
467
- */
468
- async getAssetsManifest() {
469
- const clientManifestPath = join(this.nuxtBuildDir, "dist/client/manifest.json");
470
- const publicManifestPath = join(this.outputDir, "public/_nuxt/manifest.json");
471
- const fallbackPath = join(this.publishDir, "assets-manifest.json");
472
- try {
473
- let manifestPath;
474
- if (existsSync(clientManifestPath)) {
475
- manifestPath = clientManifestPath;
476
- } else if (existsSync(publicManifestPath)) {
477
- manifestPath = publicManifestPath;
478
- } else if (existsSync(fallbackPath)) {
479
- manifestPath = fallbackPath;
480
- } else {
481
- return {};
482
- }
483
- const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
484
- if (manifest && typeof manifest === "object") {
485
- return manifest;
486
- }
487
- return {};
488
- } catch (error) {
489
- return {};
490
- }
491
- }
492
444
  #nuxtVersion = void 0;
493
445
  /**
494
446
  * Get Nuxt version that was used to build the site
@@ -496,9 +448,17 @@ var PluginContext = class {
496
448
  get nuxtVersion() {
497
449
  if (this.#nuxtVersion === void 0) {
498
450
  try {
499
- const serverHandlerRequire = createRequire(posixJoin(this.outputRootDir, ":internal:"));
500
- const { version } = serverHandlerRequire("nuxt/package.json");
501
- this.#nuxtVersion = version;
451
+ const output = execSync("npx nuxt info", {
452
+ encoding: "utf-8",
453
+ cwd: process.cwd(),
454
+ stdio: ["pipe", "pipe", "pipe"]
455
+ });
456
+ const versionMatch = output.match(/(?:nuxt|version)[:\s]+(\d+\.\d+\.\d+)/i);
457
+ if (versionMatch && versionMatch[1]) {
458
+ this.#nuxtVersion = versionMatch[1];
459
+ } else {
460
+ this.#nuxtVersion = null;
461
+ }
502
462
  } catch {
503
463
  this.#nuxtVersion = null;
504
464
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  getHandlersArrayWithAST
9
- } from "./chunk-5VJRCUAW.js";
9
+ } from "./chunk-ZG3P7BHA.js";
10
10
 
11
11
  // src/build/routes.ts
12
12
  import * as fs from "fs";
@@ -164,6 +164,9 @@ var createNuxtApiRoutesMeta = async (ctx) => {
164
164
  path: "/"
165
165
  };
166
166
  }
167
+ if (route.path && route.path.includes("**:")) {
168
+ route.path = route.path.replaceAll("**:", ":");
169
+ }
167
170
  if (route.path && route.path.includes("**")) {
168
171
  let regexPath = route.path.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
169
172
  regexPath = `^${regexPath}$`;
@@ -14588,8 +14588,49 @@ var require_lib = __commonJS({
14588
14588
  // src/utils.ts
14589
14589
  var parser = __toESM(require_lib(), 1);
14590
14590
  import { createRequire } from "node:module";
14591
+ import * as fs from "fs";
14592
+ import * as path from "path";
14591
14593
  var require2 = createRequire(import.meta.url);
14592
14594
  var traverse = require2("@babel/traverse").default;
14595
+ function useStaticBuild(cwd) {
14596
+ const edgeoneJsonPath = path.join(cwd, "edgeone.json");
14597
+ let originalEdgeOneConfig = null;
14598
+ let config = {};
14599
+ if (!fs.existsSync(edgeoneJsonPath)) {
14600
+ fs.writeFileSync(edgeoneJsonPath, "{}", "utf-8");
14601
+ config = {};
14602
+ } else {
14603
+ try {
14604
+ const fileContent = fs.readFileSync(edgeoneJsonPath, "utf-8");
14605
+ originalEdgeOneConfig = fileContent;
14606
+ config = JSON.parse(fileContent);
14607
+ } catch (error) {
14608
+ console.error("\u8BFB\u53D6 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14609
+ config = {};
14610
+ }
14611
+ }
14612
+ config.buildCommand = "npm run generate";
14613
+ try {
14614
+ fs.writeFileSync(edgeoneJsonPath, JSON.stringify(config, null, 2), "utf-8");
14615
+ } catch (error) {
14616
+ console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14617
+ throw error;
14618
+ }
14619
+ return originalEdgeOneConfig;
14620
+ }
14621
+ function resetEdgeOneConfig(cwd, originalEdgeOneConfig) {
14622
+ const edgeoneJsonPath = path.join(cwd, "edgeone.json");
14623
+ try {
14624
+ if (originalEdgeOneConfig == null) {
14625
+ fs.rmSync(edgeoneJsonPath, { recursive: true, force: true });
14626
+ return;
14627
+ }
14628
+ fs.writeFileSync(edgeoneJsonPath, originalEdgeOneConfig, "utf-8");
14629
+ } catch (error) {
14630
+ console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14631
+ throw error;
14632
+ }
14633
+ }
14593
14634
  function astNodeToObject(node) {
14594
14635
  if (node.type === "ObjectExpression") {
14595
14636
  const obj = {};
@@ -14621,15 +14662,15 @@ function getRouteRulesWithAST(code) {
14621
14662
  let routeRulesObject = null;
14622
14663
  traverse(ast, {
14623
14664
  // We're looking for a function call
14624
- CallExpression(path) {
14625
- const { node } = path;
14665
+ CallExpression(path2) {
14666
+ const { node } = path2;
14626
14667
  if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14627
14668
  if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14628
14669
  const configObjectNode = node.arguments[0];
14629
14670
  for (const prop of configObjectNode.properties) {
14630
14671
  if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "routeRules") {
14631
14672
  routeRulesObject = astNodeToObject(prop.value);
14632
- path.stop();
14673
+ path2.stop();
14633
14674
  break;
14634
14675
  }
14635
14676
  }
@@ -14652,8 +14693,8 @@ function getPrerenderRoutesWithAST(code) {
14652
14693
  let prerenderRoutes = [];
14653
14694
  traverse(ast, {
14654
14695
  // We're looking for a function call
14655
- CallExpression(path) {
14656
- const { node } = path;
14696
+ CallExpression(path2) {
14697
+ const { node } = path2;
14657
14698
  if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14658
14699
  if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14659
14700
  const configObjectNode = node.arguments[0];
@@ -14667,7 +14708,7 @@ function getPrerenderRoutesWithAST(code) {
14667
14708
  if (Array.isArray(routesArray)) {
14668
14709
  prerenderRoutes = routesArray.filter((route) => typeof route === "string");
14669
14710
  }
14670
- path.stop();
14711
+ path2.stop();
14671
14712
  return;
14672
14713
  }
14673
14714
  }
@@ -14694,13 +14735,13 @@ function getRoutesArrayWithAST(code) {
14694
14735
  let routesArray = null;
14695
14736
  traverse(ast, {
14696
14737
  // We're looking for a variable declaration
14697
- VariableDeclaration(path) {
14698
- const { node } = path;
14738
+ VariableDeclaration(path2) {
14739
+ const { node } = path2;
14699
14740
  for (const declarator of node.declarations) {
14700
14741
  if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "_routes") {
14701
14742
  if (declarator.init && declarator.init.type === "ArrayExpression") {
14702
14743
  routesArray = astNodeToObjectForRoutes(declarator.init);
14703
- path.stop();
14744
+ path2.stop();
14704
14745
  break;
14705
14746
  }
14706
14747
  }
@@ -14722,13 +14763,13 @@ function getHandlersArrayWithAST(code) {
14722
14763
  let handlersArray = [];
14723
14764
  traverse(ast, {
14724
14765
  // We're looking for a variable declaration
14725
- VariableDeclaration(path) {
14726
- const { node } = path;
14766
+ VariableDeclaration(path2) {
14767
+ const { node } = path2;
14727
14768
  for (const declarator of node.declarations) {
14728
14769
  if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "handlers") {
14729
14770
  if (declarator.init && declarator.init.type === "ArrayExpression") {
14730
14771
  handlersArray = astNodeToObjectForRoutes(declarator.init);
14731
- path.stop();
14772
+ path2.stop();
14732
14773
  break;
14733
14774
  }
14734
14775
  }
@@ -14755,8 +14796,8 @@ function addCodeToGenerateEdgeoneWithAST(code, insertCode) {
14755
14796
  let hasNitro = false;
14756
14797
  let presetValue = null;
14757
14798
  traverse(ast, {
14758
- CallExpression(path) {
14759
- const { node } = path;
14799
+ CallExpression(path2) {
14800
+ const { node } = path2;
14760
14801
  if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14761
14802
  if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14762
14803
  configObjectNode = node.arguments[0];
@@ -14769,7 +14810,7 @@ function addCodeToGenerateEdgeoneWithAST(code, insertCode) {
14769
14810
  break;
14770
14811
  }
14771
14812
  }
14772
- path.stop();
14813
+ path2.stop();
14773
14814
  }
14774
14815
  }
14775
14816
  }
@@ -14925,8 +14966,8 @@ function resetNitroConfigWithAST(code, oldOutput, oldPreset) {
14925
14966
  let nitroProperty = null;
14926
14967
  let hasNitro = false;
14927
14968
  traverse(ast, {
14928
- CallExpression(path) {
14929
- const { node } = path;
14969
+ CallExpression(path2) {
14970
+ const { node } = path2;
14930
14971
  if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14931
14972
  if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14932
14973
  configObjectNode = node.arguments[0];
@@ -14939,7 +14980,7 @@ function resetNitroConfigWithAST(code, oldOutput, oldPreset) {
14939
14980
  break;
14940
14981
  }
14941
14982
  }
14942
- path.stop();
14983
+ path2.stop();
14943
14984
  }
14944
14985
  }
14945
14986
  }
@@ -15016,8 +15057,8 @@ function getModulesWithAST(code) {
15016
15057
  });
15017
15058
  let modulesArray = [];
15018
15059
  traverse(ast, {
15019
- CallExpression(path) {
15020
- const { node } = path;
15060
+ CallExpression(path2) {
15061
+ const { node } = path2;
15021
15062
  if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
15022
15063
  if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
15023
15064
  const configObject = node.arguments[0];
@@ -15037,7 +15078,7 @@ function getModulesWithAST(code) {
15037
15078
  }
15038
15079
  }
15039
15080
  }
15040
- path.stop();
15081
+ path2.stop();
15041
15082
  return;
15042
15083
  }
15043
15084
  }
@@ -15051,13 +15092,37 @@ function getModulesWithAST(code) {
15051
15092
  return [];
15052
15093
  }
15053
15094
  }
15095
+ function checkModules(modules) {
15096
+ const excludeModules = ["@nuxt/image"];
15097
+ const invalidModules = modules.filter((module) => excludeModules.includes(module));
15098
+ if (invalidModules.length > 0) {
15099
+ console.error("\x1B[31mThe following modules are not supported: \x1B[0m", invalidModules.join(", "));
15100
+ console.log("Further optimizations and adaptations are under development...");
15101
+ process.exit(1);
15102
+ }
15103
+ }
15104
+ function checkNuxtVersion(version) {
15105
+ const versionData = version.split(".");
15106
+ if (versionData.length === 3 && Number(versionData[0]) < 3) {
15107
+ console.error("Nuxt version must be greater than 3.16.0. Compatibility for lower versions is under development...");
15108
+ process.exit(1);
15109
+ }
15110
+ }
15111
+ var removeServerHandler = async (ctx) => {
15112
+ await rm(ctx.serverHandlerDir, { recursive: true, force: true });
15113
+ };
15054
15114
 
15055
15115
  export {
15116
+ useStaticBuild,
15117
+ resetEdgeOneConfig,
15056
15118
  getRouteRulesWithAST,
15057
15119
  getPrerenderRoutesWithAST,
15058
15120
  getRoutesArrayWithAST,
15059
15121
  getHandlersArrayWithAST,
15060
15122
  addCodeToGenerateEdgeoneWithAST,
15061
15123
  resetNitroConfigWithAST,
15062
- getModulesWithAST
15124
+ getModulesWithAST,
15125
+ checkModules,
15126
+ checkNuxtVersion,
15127
+ removeServerHandler
15063
15128
  };
package/dist/index.js CHANGED
@@ -4,36 +4,40 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
+ import {
8
+ PluginContext
9
+ } from "./esm-chunks/chunk-ESOQYHZZ.js";
10
+ import {
11
+ createNuxtApiRoutesMeta,
12
+ createNuxtPagesRouteMeta
13
+ } from "./esm-chunks/chunk-KYSZO4TW.js";
7
14
  import {
8
15
  addNitroBuildOutputConfig,
9
16
  resetNitroConfig
10
- } from "./esm-chunks/chunk-7JK67XZ2.js";
17
+ } from "./esm-chunks/chunk-BZJ7SD7E.js";
18
+ import {
19
+ resetEdgeOneConfig,
20
+ useStaticBuild
21
+ } from "./esm-chunks/chunk-ZG3P7BHA.js";
11
22
  import {
12
23
  createServerHandler,
13
24
  patchNitroHandler
14
- } from "./esm-chunks/chunk-QG7JLDXY.js";
25
+ } from "./esm-chunks/chunk-DOOA3WBA.js";
15
26
  import "./esm-chunks/chunk-NJ4SUJNF.js";
16
27
  import "./esm-chunks/chunk-V2LFVP3C.js";
17
- import {
18
- PluginContext
19
- } from "./esm-chunks/chunk-3BGGEHKE.js";
20
- import {
21
- createNuxtApiRoutesMeta,
22
- createNuxtPagesRouteMeta
23
- } from "./esm-chunks/chunk-Y4NVMSL3.js";
24
- import "./esm-chunks/chunk-5VJRCUAW.js";
25
28
  import "./esm-chunks/chunk-6BT4RYQJ.js";
26
29
 
27
30
  // src/index.ts
28
- import { rm } from "node:fs/promises";
31
+ import { rm, cp, mkdir } from "node:fs/promises";
29
32
  import { join } from "node:path";
30
33
  import { existsSync } from "node:fs";
31
- function checkNuxtVersion(version) {
32
- const versionData = version.split(".");
33
- if (versionData.length === 3 && Number(versionData[0]) < 3) {
34
- console.error("Nuxt version must be greater than 3.16.0. Compatibility for lower versions is under development...");
35
- process.exit(1);
36
- }
34
+ import { exec } from "child_process";
35
+ import { promisify } from "util";
36
+ var execAsync = promisify(exec);
37
+ async function checkModules(ctx, targetModules) {
38
+ const modules = await ctx.nuxtModules();
39
+ if (!modules) return false;
40
+ return modules.includes(targetModules);
37
41
  }
38
42
  var removeServerHandler = async (ctx) => {
39
43
  await rm(ctx.serverHandlerDir, { recursive: true, force: true });
@@ -44,11 +48,17 @@ var removeIndexMJS = async (ctx) => {
44
48
  }
45
49
  };
46
50
  var recordOldNitroConfig = null;
51
+ var recordOldEdgeOneConfig = -1;
47
52
  var onPreBuild = async (options) => {
48
53
  try {
49
54
  const ctx = new PluginContext(options);
50
- checkNuxtVersion(ctx.nuxtVersion || "1.0.0");
51
55
  recordOldNitroConfig = await addNitroBuildOutputConfig(ctx);
56
+ const packagePath = ctx.resolveFromPackagePath("");
57
+ const cwd = packagePath || process.cwd();
58
+ if (await checkModules(ctx, "@nuxt/content")) {
59
+ console.warn("\u26A0\uFE0F @nuxt/content detected, switching to static deployment.");
60
+ recordOldEdgeOneConfig = useStaticBuild(cwd);
61
+ }
52
62
  } catch (error) {
53
63
  console.error("onPreBuild failed:", error);
54
64
  }
@@ -66,10 +76,15 @@ var onBuild = async (options) => {
66
76
  };
67
77
  var onPostBuild = async (options) => {
68
78
  const ctx = new PluginContext(options);
79
+ const packagePath = ctx.resolveFromPackagePath("");
80
+ const cwd = packagePath || process.cwd();
69
81
  if (recordOldNitroConfig) {
70
82
  await resetNitroConfig(recordOldNitroConfig.oldOutput, recordOldNitroConfig.oldPreset);
71
83
  await removeIndexMJS(ctx);
72
84
  }
85
+ if (recordOldEdgeOneConfig !== -1) {
86
+ resetEdgeOneConfig(cwd, recordOldEdgeOneConfig);
87
+ }
73
88
  };
74
89
  export {
75
90
  onBuild,
package/dist/utils.js CHANGED
@@ -6,20 +6,30 @@
6
6
 
7
7
  import {
8
8
  addCodeToGenerateEdgeoneWithAST,
9
+ checkModules,
10
+ checkNuxtVersion,
9
11
  getHandlersArrayWithAST,
10
12
  getModulesWithAST,
11
13
  getPrerenderRoutesWithAST,
12
14
  getRouteRulesWithAST,
13
15
  getRoutesArrayWithAST,
14
- resetNitroConfigWithAST
15
- } from "./esm-chunks/chunk-5VJRCUAW.js";
16
+ removeServerHandler,
17
+ resetEdgeOneConfig,
18
+ resetNitroConfigWithAST,
19
+ useStaticBuild
20
+ } from "./esm-chunks/chunk-ZG3P7BHA.js";
16
21
  import "./esm-chunks/chunk-6BT4RYQJ.js";
17
22
  export {
18
23
  addCodeToGenerateEdgeoneWithAST,
24
+ checkModules,
25
+ checkNuxtVersion,
19
26
  getHandlersArrayWithAST,
20
27
  getModulesWithAST,
21
28
  getPrerenderRoutesWithAST,
22
29
  getRouteRulesWithAST,
23
30
  getRoutesArrayWithAST,
24
- resetNitroConfigWithAST
31
+ removeServerHandler,
32
+ resetEdgeOneConfig,
33
+ resetNitroConfigWithAST,
34
+ useStaticBuild
25
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgeone/nuxt-pages",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "test": "ts-node src/test.ts",
@@ -1,81 +0,0 @@
1
-
2
- var require = await (async () => {
3
- var { createRequire } = await import("node:module");
4
- return createRequire(import.meta.url);
5
- })();
6
-
7
-
8
- // src/run/headers.ts
9
- var getHeaderValueArray = (header) => {
10
- return header.split(",").map((value) => value.trim()).filter(Boolean);
11
- };
12
- var omitHeaderValues = (header, values) => {
13
- const headerValues = getHeaderValueArray(header);
14
- const filteredValues = headerValues.filter(
15
- (value) => !values.some((val) => value.startsWith(val))
16
- );
17
- return filteredValues.join(", ");
18
- };
19
- function setCacheControlFromRequestContext(headers, revalidate) {
20
- const cdnCacheControl = (
21
- // if we are serving already stale response, instruct edge to not attempt to cache that response
22
- headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${revalidate || 31536e3}, stale-while-revalidate=31536000, durable`
23
- );
24
- headers.set("eo-cdn-cache-control", cdnCacheControl);
25
- }
26
- var setCacheControlHeaders = ({ headers, status }, request, requestContext) => {
27
- if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control")) {
28
- setCacheControlFromRequestContext(headers, requestContext.routeHandlerRevalidate);
29
- return;
30
- }
31
- if (status === 404) {
32
- if (request.url.endsWith(".php")) {
33
- headers.set("cache-control", "public, max-age=0, must-revalidate");
34
- headers.set("eo-cdn-cache-control", `max-age=31536000, durable`);
35
- return;
36
- }
37
- if (process.env.CACHE_404_PAGE && request.url.endsWith("/404") && ["GET", "HEAD"].includes(request.method)) {
38
- setCacheControlFromRequestContext(headers, requestContext.pageHandlerRevalidate);
39
- return;
40
- }
41
- }
42
- const cacheControl = headers.get("cache-control");
43
- if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control")) {
44
- const browserCacheControl = omitHeaderValues(cacheControl, [
45
- "s-maxage",
46
- "stale-while-revalidate"
47
- ]);
48
- const cdnCacheControl = (
49
- // if we are serving already stale response, instruct edge to not attempt to cache that response
50
- headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
51
- ...getHeaderValueArray(cacheControl).map(
52
- (value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
53
- ),
54
- "durable"
55
- ].join(", ")
56
- );
57
- headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
58
- headers.set("eo-cdn-cache-control", cdnCacheControl);
59
- return;
60
- }
61
- if (cacheControl === null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control") && requestContext.usedFsReadForNonFallback && !requestContext.didPagesRouterOnDemandRevalidate) {
62
- headers.set("cache-control", "public, max-age=0, must-revalidate");
63
- headers.set("eo-cdn-cache-control", `max-age=31536000, durable`);
64
- }
65
- };
66
- var setCacheTagsHeaders = (headers, requestContext) => {
67
- if (!headers.has("cache-control")) {
68
- return;
69
- }
70
- };
71
- var setCacheStatusHeader = (headers, nextCache) => {
72
- if (headers.has("x-nextjs-cache")) {
73
- headers.delete("x-nextjs-cache");
74
- }
75
- };
76
-
77
- export {
78
- setCacheControlHeaders,
79
- setCacheTagsHeaders,
80
- setCacheStatusHeader
81
- };