@edgeone/nuxt-pages 1.0.13 → 1.0.14

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 (36) hide show
  1. package/dist/build/content/static.js +2 -2
  2. package/dist/build/plugin-context.js +2 -2
  3. package/dist/build/routes.js +2 -2
  4. package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +0 -23
  5. package/dist/esm-chunks/{chunk-7JK67XZ2.js → chunk-7X4RPD4I.js} +4 -4
  6. package/dist/esm-chunks/{chunk-5VJRCUAW.js → chunk-MONI3XWQ.js} +64 -21
  7. package/dist/esm-chunks/{chunk-3BGGEHKE.js → chunk-PI5G55N3.js} +1 -48
  8. package/dist/esm-chunks/{chunk-Y4NVMSL3.js → chunk-YSIAQCXW.js} +4 -1
  9. package/dist/index.js +34 -11
  10. package/dist/utils.js +7 -3
  11. package/package.json +1 -1
  12. package/dist/esm-chunks/chunk-5YBUNNZ4.js +0 -81
  13. package/dist/esm-chunks/chunk-HBXUWFGE.js +0 -19
  14. package/dist/esm-chunks/chunk-HY3HNABZ.js +0 -87
  15. package/dist/esm-chunks/chunk-KGYBHZC3.js +0 -1467
  16. package/dist/esm-chunks/chunk-UOPC2N5A.js +0 -69
  17. package/dist/run/config.js +0 -17
  18. package/dist/run/constants.js +0 -17
  19. package/dist/run/handlers/cache.cjs +0 -1410
  20. package/dist/run/handlers/nuxt-cache.cjs +0 -200
  21. package/dist/run/handlers/nuxt-server.js +0 -155
  22. package/dist/run/handlers/request-context.cjs +0 -148
  23. package/dist/run/handlers/server.js +0 -77
  24. package/dist/run/handlers/tags-handler.cjs +0 -177
  25. package/dist/run/handlers/tracer.cjs +0 -1004
  26. package/dist/run/handlers/use-cache-handler.js +0 -220
  27. package/dist/run/handlers/wait-until.cjs +0 -123
  28. package/dist/run/headers.js +0 -17
  29. package/dist/run/revalidate.js +0 -34
  30. package/dist/run/storage/regional-blob-store.cjs +0 -64
  31. package/dist/run/storage/request-scoped-in-memory-cache.cjs +0 -1582
  32. package/dist/run/storage/storage.cjs +0 -191
  33. package/dist/shared/blob-types.cjs +0 -37
  34. package/dist/shared/blobkey.js +0 -25
  35. package/dist/shared/cache-types.cjs +0 -33
  36. 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-7X4RPD4I.js";
11
+ import "../../esm-chunks/chunk-MONI3XWQ.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,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-PI5G55N3.js";
12
+ import "../esm-chunks/chunk-MONI3XWQ.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-YSIAQCXW.js";
12
+ import "../esm-chunks/chunk-MONI3XWQ.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-MONI3XWQ.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";
@@ -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
  }
@@ -15053,6 +15094,8 @@ function getModulesWithAST(code) {
15053
15094
  }
15054
15095
 
15055
15096
  export {
15097
+ useStaticBuild,
15098
+ resetEdgeOneConfig,
15056
15099
  getRouteRulesWithAST,
15057
15100
  getPrerenderRoutesWithAST,
15058
15101
  getRoutesArrayWithAST,
@@ -9,7 +9,7 @@ import {
9
9
  getPrerenderRoutesWithAST,
10
10
  getRouteRulesWithAST,
11
11
  getRoutesArrayWithAST
12
- } from "./chunk-5VJRCUAW.js";
12
+ } from "./chunk-MONI3XWQ.js";
13
13
 
14
14
  // src/build/plugin-context.ts
15
15
  import { existsSync, readFileSync } from "node:fs";
@@ -178,10 +178,6 @@ var PluginContext = class {
178
178
  resolveFromPackagePath(...args) {
179
179
  return resolve(this.constants.PACKAGE_PATH || "", ...args);
180
180
  }
181
- /** Resolves a path correctly from site directory */
182
- resolveFromSiteDir(...args) {
183
- return resolve(this.buildManifest?.buildDir || process.cwd(), ...args);
184
- }
185
181
  /** Get the nuxt routes manifest */
186
182
  async getRoutesManifest() {
187
183
  try {
@@ -446,49 +442,6 @@ var PluginContext = class {
446
442
  });
447
443
  return result;
448
444
  }
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
445
  #nuxtVersion = void 0;
493
446
  /**
494
447
  * Get Nuxt version that was used to build the site
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  getHandlersArrayWithAST
9
- } from "./chunk-5VJRCUAW.js";
9
+ } from "./chunk-MONI3XWQ.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}$`;
package/dist/index.js CHANGED
@@ -5,29 +5,35 @@
5
5
  })();
6
6
 
7
7
  import {
8
- addNitroBuildOutputConfig,
9
- resetNitroConfig
10
- } from "./esm-chunks/chunk-7JK67XZ2.js";
8
+ PluginContext
9
+ } from "./esm-chunks/chunk-PI5G55N3.js";
10
+ import {
11
+ createNuxtApiRoutesMeta,
12
+ createNuxtPagesRouteMeta
13
+ } from "./esm-chunks/chunk-YSIAQCXW.js";
11
14
  import {
12
15
  createServerHandler,
13
16
  patchNitroHandler
14
17
  } from "./esm-chunks/chunk-QG7JLDXY.js";
15
18
  import "./esm-chunks/chunk-NJ4SUJNF.js";
16
- import "./esm-chunks/chunk-V2LFVP3C.js";
17
19
  import {
18
- PluginContext
19
- } from "./esm-chunks/chunk-3BGGEHKE.js";
20
+ addNitroBuildOutputConfig,
21
+ resetNitroConfig
22
+ } from "./esm-chunks/chunk-7X4RPD4I.js";
20
23
  import {
21
- createNuxtApiRoutesMeta,
22
- createNuxtPagesRouteMeta
23
- } from "./esm-chunks/chunk-Y4NVMSL3.js";
24
- import "./esm-chunks/chunk-5VJRCUAW.js";
24
+ resetEdgeOneConfig,
25
+ useStaticBuild
26
+ } from "./esm-chunks/chunk-MONI3XWQ.js";
27
+ import "./esm-chunks/chunk-V2LFVP3C.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";
34
+ import { exec } from "child_process";
35
+ import { promisify } from "util";
36
+ var execAsync = promisify(exec);
31
37
  function checkNuxtVersion(version) {
32
38
  const versionData = version.split(".");
33
39
  if (versionData.length === 3 && Number(versionData[0]) < 3) {
@@ -35,6 +41,11 @@ function checkNuxtVersion(version) {
35
41
  process.exit(1);
36
42
  }
37
43
  }
44
+ async function checkModules(ctx, targetModules) {
45
+ const modules = await ctx.nuxtModules();
46
+ if (!modules) return false;
47
+ return modules.includes(targetModules);
48
+ }
38
49
  var removeServerHandler = async (ctx) => {
39
50
  await rm(ctx.serverHandlerDir, { recursive: true, force: true });
40
51
  };
@@ -44,11 +55,18 @@ var removeIndexMJS = async (ctx) => {
44
55
  }
45
56
  };
46
57
  var recordOldNitroConfig = null;
58
+ var recordOldEdgeOneConfig = -1;
47
59
  var onPreBuild = async (options) => {
48
60
  try {
49
61
  const ctx = new PluginContext(options);
50
62
  checkNuxtVersion(ctx.nuxtVersion || "1.0.0");
51
63
  recordOldNitroConfig = await addNitroBuildOutputConfig(ctx);
64
+ const packagePath = ctx.resolveFromPackagePath("");
65
+ const cwd = packagePath || process.cwd();
66
+ if (await checkModules(ctx, "@nuxt/content")) {
67
+ console.warn("\u26A0\uFE0F @nuxt/content detected, switching to static deployment.");
68
+ recordOldEdgeOneConfig = useStaticBuild(cwd);
69
+ }
52
70
  } catch (error) {
53
71
  console.error("onPreBuild failed:", error);
54
72
  }
@@ -66,10 +84,15 @@ var onBuild = async (options) => {
66
84
  };
67
85
  var onPostBuild = async (options) => {
68
86
  const ctx = new PluginContext(options);
87
+ const packagePath = ctx.resolveFromPackagePath("");
88
+ const cwd = packagePath || process.cwd();
69
89
  if (recordOldNitroConfig) {
70
90
  await resetNitroConfig(recordOldNitroConfig.oldOutput, recordOldNitroConfig.oldPreset);
71
91
  await removeIndexMJS(ctx);
72
92
  }
93
+ if (recordOldEdgeOneConfig !== -1) {
94
+ resetEdgeOneConfig(cwd, recordOldEdgeOneConfig);
95
+ }
73
96
  };
74
97
  export {
75
98
  onBuild,
package/dist/utils.js CHANGED
@@ -11,8 +11,10 @@ import {
11
11
  getPrerenderRoutesWithAST,
12
12
  getRouteRulesWithAST,
13
13
  getRoutesArrayWithAST,
14
- resetNitroConfigWithAST
15
- } from "./esm-chunks/chunk-5VJRCUAW.js";
14
+ resetEdgeOneConfig,
15
+ resetNitroConfigWithAST,
16
+ useStaticBuild
17
+ } from "./esm-chunks/chunk-MONI3XWQ.js";
16
18
  import "./esm-chunks/chunk-6BT4RYQJ.js";
17
19
  export {
18
20
  addCodeToGenerateEdgeoneWithAST,
@@ -21,5 +23,7 @@ export {
21
23
  getPrerenderRoutesWithAST,
22
24
  getRouteRulesWithAST,
23
25
  getRoutesArrayWithAST,
24
- resetNitroConfigWithAST
26
+ resetEdgeOneConfig,
27
+ resetNitroConfigWithAST,
28
+ useStaticBuild
25
29
  };
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.14",
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
- };
@@ -1,19 +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/constants.ts
9
- import { resolve } from "node:path";
10
- import { fileURLToPath } from "node:url";
11
- var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
12
- var PLUGIN_DIR = resolve(`${MODULE_DIR}../../..`);
13
- var RUN_CONFIG_FILE = "run-config.json";
14
-
15
- export {
16
- MODULE_DIR,
17
- PLUGIN_DIR,
18
- RUN_CONFIG_FILE
19
- };
@@ -1,87 +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
- PLUGIN_DIR,
9
- RUN_CONFIG_FILE
10
- } from "./chunk-HBXUWFGE.js";
11
-
12
- // src/run/config.ts
13
- import { existsSync } from "node:fs";
14
- import { readFile } from "node:fs/promises";
15
- import { join, resolve } from "node:path";
16
-
17
- // src/run/storage/request-scoped-in-memory-cache.cts
18
- var NullValue = Symbol.for("null-value");
19
- var IN_MEMORY_CACHE_MAX_SIZE = Symbol.for("nf-in-memory-cache-max-size");
20
- var IN_MEMORY_LRU_CACHE = Symbol.for("nf-in-memory-lru-cache");
21
- var extendedGlobalThis = globalThis;
22
- var DEFAULT_FALLBACK_MAX_SIZE = 50 * 1024 * 1024;
23
- function setInMemoryCacheMaxSizeFromNuxtConfig(size) {
24
- if (typeof size === "number") {
25
- extendedGlobalThis[IN_MEMORY_CACHE_MAX_SIZE] = size;
26
- }
27
- }
28
-
29
- // src/run/storage/regional-blob-store.cts
30
- var FETCH_BEFORE_NUXT_PATCHED_IT = Symbol.for("nf-not-patched-fetch");
31
- var extendedGlobalThis2 = globalThis;
32
- function attemptToGetOriginalFetch(fetch) {
33
- return fetch._nuxtOriginalFetch ?? fetch;
34
- }
35
- function forceOptOutOfUsingDataCache(fetch) {
36
- return (input, init) => {
37
- return fetch(input, {
38
- ...init,
39
- next: {
40
- ...init?.next,
41
- // setting next.internal = true should prevent from trying to use data cache
42
- // https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L174
43
- // https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L210-L213
44
- // this is last line of defense in case we didn't manage to get unpatched fetch that will not affect
45
- // fetch if it's unpatched so it should be safe to apply always if we aren't sure if we use patched fetch
46
- // @ts-expect-error - this is an internal field that Next.js doesn't add to its global
47
- // type overrides for RequestInit type (like `next.revalidate` or `next.tags`)
48
- internal: true
49
- }
50
- });
51
- };
52
- }
53
- var setFetchBeforeNuxtPatchedIt = (fetch) => {
54
- extendedGlobalThis2[FETCH_BEFORE_NUXT_PATCHED_IT] = forceOptOutOfUsingDataCache(
55
- attemptToGetOriginalFetch(fetch)
56
- );
57
- };
58
- var fetchBeforeNuxtPatchedItFallback = forceOptOutOfUsingDataCache(
59
- attemptToGetOriginalFetch(globalThis.fetch)
60
- );
61
-
62
- // src/run/config.ts
63
- var getRunConfig = async () => {
64
- return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG_FILE), "utf-8"));
65
- };
66
- var setRunConfig = (config) => {
67
- const cacheHandler = join(PLUGIN_DIR, ".edgeone/dist/run/handlers/cache.cjs");
68
- if (!existsSync(cacheHandler)) {
69
- throw new Error(`Cache handler not found at ${cacheHandler}`);
70
- }
71
- config.experimental = {
72
- ...config.experimental,
73
- // Before Next.js 14.1.0 path to the cache handler was in experimental section, see NextConfigForMultipleVersions type
74
- incrementalCacheHandlerPath: cacheHandler
75
- };
76
- config.cacheHandler = cacheHandler;
77
- setInMemoryCacheMaxSizeFromNuxtConfig(
78
- config.cacheMaxMemorySize ?? config.experimental?.isrMemoryCacheSize
79
- );
80
- process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
81
- };
82
-
83
- export {
84
- setFetchBeforeNuxtPatchedIt,
85
- getRunConfig,
86
- setRunConfig
87
- };