@edgeone/opennextjs-pages 0.2.5 → 0.2.7

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.
@@ -214,7 +214,7 @@ var PluginContext = class {
214
214
  async getPagesManifest() {
215
215
  return JSON.parse(await readFile(join(this.publishDir, "server/pages-manifest.json"), "utf-8"));
216
216
  }
217
- // 获取 next api manifest
217
+ // 获取 next api manifest
218
218
  async getAppPathRoutesManifest() {
219
219
  const manifestPath = join(this.publishDir, "app-path-routes-manifest.json");
220
220
  try {
@@ -226,6 +226,17 @@ var PluginContext = class {
226
226
  return {};
227
227
  }
228
228
  }
229
+ async getAppPathsManifest() {
230
+ const manifestPath = join(this.publishDir, "server/app-paths-manifest.json");
231
+ try {
232
+ if (!existsSync(manifestPath)) {
233
+ return null;
234
+ }
235
+ return JSON.parse(await readFile(manifestPath, "utf-8"));
236
+ } catch (error) {
237
+ return null;
238
+ }
239
+ }
229
240
  /**
230
241
  * Uses various heuristics to try to find the .next dir.
231
242
  * Works by looking for BUILD_ID, so requires the site to have been built
@@ -119,18 +119,45 @@ function getServerRoutes(staticRoutes, prerenderManifest, basePath = "") {
119
119
  }
120
120
  return routes;
121
121
  }
122
- function getApiRoutes(appPathsManifest, basePath = "") {
122
+ function getAppRoutes(appPathsManifest, basePath = "", existingPaths = /* @__PURE__ */ new Set()) {
123
123
  if (!appPathsManifest) {
124
124
  return [];
125
125
  }
126
126
  const routes = [];
127
+ const emitted = /* @__PURE__ */ new Set();
127
128
  for (const routePath of Object.keys(appPathsManifest)) {
128
- if (routePath.includes("/api/") && routePath.endsWith("/route")) {
129
- const apiPath = routePath.replace(/\/route$/, "");
130
- const escapedPath = apiPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
131
- const src = `^${basePath}${escapedPath}$`;
132
- routes.push({ src });
129
+ if (routePath.startsWith("/_")) {
130
+ continue;
131
+ }
132
+ let pagePath;
133
+ if (routePath.endsWith("/route")) {
134
+ pagePath = routePath.replace(/\/route$/, "");
135
+ } else if (routePath.endsWith("/page")) {
136
+ pagePath = routePath.replace(/\/page$/, "") || "/";
137
+ } else {
138
+ continue;
139
+ }
140
+ pagePath = pagePath.replace(/\/\([^)]+\)/g, "");
141
+ if (!pagePath) pagePath = "/";
142
+ if (pagePath.includes("@")) {
143
+ continue;
144
+ }
145
+ if (pagePath.includes("[")) {
146
+ continue;
147
+ }
148
+ if (pagePath === "/") {
149
+ continue;
150
+ }
151
+ if (existingPaths.has(pagePath)) {
152
+ continue;
153
+ }
154
+ if (emitted.has(pagePath)) {
155
+ continue;
133
156
  }
157
+ emitted.add(pagePath);
158
+ const escapedPath = pagePath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
159
+ const src = `^${basePath}${escapedPath}(?:/)?$`;
160
+ routes.push({ src });
134
161
  }
135
162
  return routes;
136
163
  }
@@ -342,9 +369,10 @@ var createRouteMeta = async (ctx) => {
342
369
  if (dataRoutes.length > 0) {
343
370
  routes.push(...getDataRoutes(dataRoutes, basePath));
344
371
  }
345
- const apiRoutes = getApiRoutes(appPathsManifest, basePath);
346
- if (apiRoutes.length > 0) {
347
- routes.push(...apiRoutes);
372
+ const existingPaths = new Set(staticRoutes.map((r) => r.page));
373
+ const appRoutes = getAppRoutes(appPathsManifest, basePath, existingPaths);
374
+ if (appRoutes.length > 0) {
375
+ routes.push(...appRoutes);
348
376
  }
349
377
  routes.push({
350
378
  src: `^${basePath}/.*$`
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(tags_handler_exports);
28
28
 
29
29
  // package.json
30
30
  var name = "@edgeone/opennextjs-pages";
31
- var version = "0.2.5";
31
+ var version = "0.2.7";
32
32
 
33
33
  // src/run/handlers/tags-handler.cts
34
34
  var import_request_context = require("./request-context.cjs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgeone/opennextjs-pages",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",