@edgeone/opennextjs-pages 0.0.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.
Files changed (35) hide show
  1. package/dist/build/advanced-api-routes.js +147 -0
  2. package/dist/build/cache.js +36 -0
  3. package/dist/build/content/next-shims/telemetry-storage.cjs +55 -0
  4. package/dist/build/content/prerendered.js +292 -0
  5. package/dist/build/content/server.js +236 -0
  6. package/dist/build/content/static.js +119 -0
  7. package/dist/build/functions/server.js +133 -0
  8. package/dist/build/plugin-context.js +367 -0
  9. package/dist/build/routes.js +127 -0
  10. package/dist/build/templates/handler-monorepo.tmpl.js +210 -0
  11. package/dist/build/templates/handler.tmpl.js +206 -0
  12. package/dist/esm-chunks/chunk-5J3FID2N.js +5551 -0
  13. package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
  14. package/dist/esm-chunks/chunk-FKDTZJRV.js +832 -0
  15. package/dist/esm-chunks/chunk-TLQCAGE2.js +1921 -0
  16. package/dist/index.js +50 -0
  17. package/dist/run/config.js +37 -0
  18. package/dist/run/constants.js +19 -0
  19. package/dist/run/handlers/cache.cjs +369 -0
  20. package/dist/run/handlers/request-context.cjs +148 -0
  21. package/dist/run/handlers/server.js +3213 -0
  22. package/dist/run/handlers/tags-handler.cjs +92 -0
  23. package/dist/run/handlers/tracer.cjs +916 -0
  24. package/dist/run/handlers/use-cache-handler.js +1538 -0
  25. package/dist/run/handlers/wait-until.cjs +39 -0
  26. package/dist/run/headers.js +81 -0
  27. package/dist/run/next.cjs +100 -0
  28. package/dist/run/revalidate.js +34 -0
  29. package/dist/run/storage/regional-blob-store.cjs +64 -0
  30. package/dist/run/storage/request-scoped-in-memory-cache.cjs +1496 -0
  31. package/dist/run/storage/storage.cjs +37 -0
  32. package/dist/shared/blob-types.cjs +37 -0
  33. package/dist/shared/blobkey.js +25 -0
  34. package/dist/shared/cache-types.cjs +33 -0
  35. package/package.json +55 -0
@@ -0,0 +1,147 @@
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
9
+ } from "../esm-chunks/chunk-6BT4RYQJ.js";
10
+
11
+ // src/build/advanced-api-routes.ts
12
+ import { existsSync } from "node:fs";
13
+ import { readFile } from "node:fs/promises";
14
+ import { join } from "node:path";
15
+ var ApiRouteType = /* @__PURE__ */ ((ApiRouteType2) => {
16
+ ApiRouteType2["SCHEDULED"] = "experimental-scheduled";
17
+ ApiRouteType2["BACKGROUND"] = "experimental-background";
18
+ return ApiRouteType2;
19
+ })(ApiRouteType || {});
20
+ async function getAPIRoutesConfigs(ctx) {
21
+ const uniqueApiRoutes = /* @__PURE__ */ new Set();
22
+ const functionsConfigManifestPath = join(
23
+ ctx.publishDir,
24
+ "server",
25
+ "functions-config-manifest.json"
26
+ );
27
+ if (existsSync(functionsConfigManifestPath)) {
28
+ const functionsConfigManifest = JSON.parse(
29
+ await readFile(functionsConfigManifestPath, "utf-8")
30
+ );
31
+ for (const apiRoute of Object.keys(functionsConfigManifest.functions)) {
32
+ uniqueApiRoutes.add(apiRoute);
33
+ }
34
+ }
35
+ const pagesManifestPath = join(ctx.publishDir, "server", "pages-manifest.json");
36
+ if (existsSync(pagesManifestPath)) {
37
+ const pagesManifest = JSON.parse(await readFile(pagesManifestPath, "utf-8"));
38
+ for (const route of Object.keys(pagesManifest)) {
39
+ if (route.startsWith("/api/")) {
40
+ uniqueApiRoutes.add(route);
41
+ }
42
+ }
43
+ }
44
+ if (uniqueApiRoutes.size === 0) {
45
+ return [];
46
+ }
47
+ const appDir = ctx.resolveFromSiteDir(".");
48
+ const pagesDir = join(appDir, "pages");
49
+ const srcPagesDir = join(appDir, "src", "pages");
50
+ const { pageExtensions } = ctx.requiredServerFiles.config;
51
+ return Promise.all(
52
+ [...uniqueApiRoutes].map(async (apiRoute) => {
53
+ const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir], pageExtensions);
54
+ const sharedFields = {
55
+ apiRoute,
56
+ filePath,
57
+ config: {}
58
+ };
59
+ if (filePath) {
60
+ const config = await extractConfigFromFile(filePath, appDir);
61
+ return {
62
+ ...sharedFields,
63
+ config
64
+ };
65
+ }
66
+ return sharedFields;
67
+ })
68
+ );
69
+ }
70
+ var SOURCE_FILE_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
71
+ var getSourceFileForPage = (page, roots, pageExtensions = SOURCE_FILE_EXTENSIONS) => {
72
+ for (const root of roots) {
73
+ for (const extension of pageExtensions) {
74
+ const file = join(root, `${page}.${extension}`);
75
+ if (existsSync(file)) {
76
+ return file;
77
+ }
78
+ const fileAtFolderIndex = join(root, page, `index.${extension}`);
79
+ if (existsSync(fileAtFolderIndex)) {
80
+ return fileAtFolderIndex;
81
+ }
82
+ }
83
+ }
84
+ };
85
+ var findModuleFromBase = ({
86
+ paths,
87
+ candidates
88
+ }) => {
89
+ for (const candidate of candidates) {
90
+ try {
91
+ const modulePath = __require.resolve(candidate, { paths });
92
+ if (modulePath) {
93
+ return modulePath;
94
+ }
95
+ } catch {
96
+ }
97
+ }
98
+ for (const candidate of candidates) {
99
+ try {
100
+ const modulePath = __require.resolve(candidate);
101
+ if (modulePath) {
102
+ return modulePath;
103
+ }
104
+ } catch {
105
+ }
106
+ }
107
+ return null;
108
+ };
109
+ var extractConstValue;
110
+ var parseModule;
111
+ var extractConfigFromFile = async (apiFilePath, appDir) => {
112
+ if (!apiFilePath || !existsSync(apiFilePath)) {
113
+ return {};
114
+ }
115
+ const extractConstValueModulePath = findModuleFromBase({
116
+ paths: [appDir],
117
+ candidates: ["next/dist/build/analysis/extract-const-value"]
118
+ });
119
+ const parseModulePath = findModuleFromBase({
120
+ paths: [appDir],
121
+ candidates: ["next/dist/build/analysis/parse-module"]
122
+ });
123
+ if (!extractConstValueModulePath || !parseModulePath) {
124
+ return {};
125
+ }
126
+ if (!extractConstValue && extractConstValueModulePath) {
127
+ extractConstValue = __require(extractConstValueModulePath);
128
+ }
129
+ if (!parseModule && parseModulePath) {
130
+ parseModule = __require(parseModulePath).parseModule;
131
+ }
132
+ const { extractExportedConstValue } = extractConstValue;
133
+ const fileContent = await readFile(apiFilePath, "utf8");
134
+ if (!fileContent.includes("config")) {
135
+ return {};
136
+ }
137
+ const ast = await parseModule(apiFilePath, fileContent);
138
+ try {
139
+ return extractExportedConstValue(ast, "config");
140
+ } catch {
141
+ return {};
142
+ }
143
+ };
144
+ export {
145
+ ApiRouteType,
146
+ getAPIRoutesConfigs
147
+ };
@@ -0,0 +1,36 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import "../esm-chunks/chunk-6BT4RYQJ.js";
8
+
9
+ // src/build/cache.ts
10
+ import { existsSync } from "node:fs";
11
+ import { rm } from "node:fs/promises";
12
+ import { join } from "node:path";
13
+ var saveBuildCache = async (ctx) => {
14
+ const { cache } = ctx.utils;
15
+ const cacheDir = join(ctx.publishDir, "cache");
16
+ if (existsSync(cacheDir)) {
17
+ await rm(join(cacheDir, "fetch-cache"), { recursive: true, force: true });
18
+ await cache.save(cacheDir);
19
+ console.log("Next.js cache saved");
20
+ } else {
21
+ console.log("No Next.js cache to save");
22
+ }
23
+ };
24
+ var restoreBuildCache = async (ctx) => {
25
+ const { cache } = ctx.utils;
26
+ const cacheDir = join(ctx.publishDir, "cache");
27
+ if (await cache.restore(cacheDir)) {
28
+ console.log("Next.js cache restored");
29
+ } else {
30
+ console.log("No Next.js cache to restore");
31
+ }
32
+ };
33
+ export {
34
+ restoreBuildCache,
35
+ saveBuildCache
36
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/build/content/next-shims/telemetry-storage.cts
21
+ var telemetry_storage_exports = {};
22
+ __export(telemetry_storage_exports, {
23
+ TelemetryShim: () => TelemetryShim
24
+ });
25
+ module.exports = __toCommonJS(telemetry_storage_exports);
26
+ var TelemetryShim = class {
27
+ sessionId = "shim";
28
+ get anonymousId() {
29
+ return "shim";
30
+ }
31
+ get salt() {
32
+ return "shim";
33
+ }
34
+ setEnabled() {
35
+ return null;
36
+ }
37
+ get isEnabled() {
38
+ return false;
39
+ }
40
+ oneWayHash() {
41
+ return "shim";
42
+ }
43
+ record() {
44
+ return Promise.resolve({ isFulfilled: true, isRejected: false });
45
+ }
46
+ flush() {
47
+ return Promise.resolve(null);
48
+ }
49
+ flushDetached() {
50
+ }
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ TelemetryShim
55
+ });
@@ -0,0 +1,292 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ trace,
9
+ wrapTracer
10
+ } from "../../esm-chunks/chunk-FKDTZJRV.js";
11
+ import {
12
+ require_semver
13
+ } from "../../esm-chunks/chunk-TLQCAGE2.js";
14
+ import {
15
+ __toESM
16
+ } from "../../esm-chunks/chunk-6BT4RYQJ.js";
17
+
18
+ // src/build/content/prerendered.ts
19
+ import { existsSync } from "node:fs";
20
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
21
+ import path, { join } from "node:path";
22
+
23
+ // node_modules/yocto-queue/index.js
24
+ var Node = class {
25
+ value;
26
+ next;
27
+ constructor(value) {
28
+ this.value = value;
29
+ }
30
+ };
31
+ var Queue = class {
32
+ #head;
33
+ #tail;
34
+ #size;
35
+ constructor() {
36
+ this.clear();
37
+ }
38
+ enqueue(value) {
39
+ const node = new Node(value);
40
+ if (this.#head) {
41
+ this.#tail.next = node;
42
+ this.#tail = node;
43
+ } else {
44
+ this.#head = node;
45
+ this.#tail = node;
46
+ }
47
+ this.#size++;
48
+ }
49
+ dequeue() {
50
+ const current = this.#head;
51
+ if (!current) {
52
+ return;
53
+ }
54
+ this.#head = this.#head.next;
55
+ this.#size--;
56
+ return current.value;
57
+ }
58
+ peek() {
59
+ if (!this.#head) {
60
+ return;
61
+ }
62
+ return this.#head.value;
63
+ }
64
+ clear() {
65
+ this.#head = void 0;
66
+ this.#tail = void 0;
67
+ this.#size = 0;
68
+ }
69
+ get size() {
70
+ return this.#size;
71
+ }
72
+ *[Symbol.iterator]() {
73
+ let current = this.#head;
74
+ while (current) {
75
+ yield current.value;
76
+ current = current.next;
77
+ }
78
+ }
79
+ *drain() {
80
+ while (this.#head) {
81
+ yield this.dequeue();
82
+ }
83
+ }
84
+ };
85
+
86
+ // node_modules/p-limit/index.js
87
+ function pLimit(concurrency) {
88
+ validateConcurrency(concurrency);
89
+ const queue = new Queue();
90
+ let activeCount = 0;
91
+ const resumeNext = () => {
92
+ if (activeCount < concurrency && queue.size > 0) {
93
+ queue.dequeue()();
94
+ activeCount++;
95
+ }
96
+ };
97
+ const next = () => {
98
+ activeCount--;
99
+ resumeNext();
100
+ };
101
+ const run = async (function_, resolve, arguments_) => {
102
+ const result = (async () => function_(...arguments_))();
103
+ resolve(result);
104
+ try {
105
+ await result;
106
+ } catch {
107
+ }
108
+ next();
109
+ };
110
+ const enqueue = (function_, resolve, arguments_) => {
111
+ new Promise((internalResolve) => {
112
+ queue.enqueue(internalResolve);
113
+ }).then(
114
+ run.bind(void 0, function_, resolve, arguments_)
115
+ );
116
+ (async () => {
117
+ await Promise.resolve();
118
+ if (activeCount < concurrency) {
119
+ resumeNext();
120
+ }
121
+ })();
122
+ };
123
+ const generator = (function_, ...arguments_) => new Promise((resolve) => {
124
+ enqueue(function_, resolve, arguments_);
125
+ });
126
+ Object.defineProperties(generator, {
127
+ activeCount: {
128
+ get: () => activeCount
129
+ },
130
+ pendingCount: {
131
+ get: () => queue.size
132
+ },
133
+ clearQueue: {
134
+ value() {
135
+ queue.clear();
136
+ }
137
+ },
138
+ concurrency: {
139
+ get: () => concurrency,
140
+ set(newConcurrency) {
141
+ validateConcurrency(newConcurrency);
142
+ concurrency = newConcurrency;
143
+ queueMicrotask(() => {
144
+ while (activeCount < concurrency && queue.size > 0) {
145
+ resumeNext();
146
+ }
147
+ });
148
+ }
149
+ }
150
+ });
151
+ return generator;
152
+ }
153
+ function validateConcurrency(concurrency) {
154
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
155
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
156
+ }
157
+ }
158
+
159
+ // src/build/content/prerendered.ts
160
+ var import_semver = __toESM(require_semver(), 1);
161
+ var tracer = wrapTracer(trace.getTracer("Next runtime"));
162
+ var routeToFilePath = (path2) => {
163
+ if (path2 === "/") {
164
+ return "/index";
165
+ }
166
+ if (path2.startsWith("/")) {
167
+ return path2;
168
+ }
169
+ return `/${path2}`;
170
+ };
171
+ var buildPagesCacheValue = async (ctx, key) => {
172
+ const buildId = await readFile(join(ctx.publishDir, "BUILD_ID"), "utf-8");
173
+ const pagePath = join(ctx.publishDir, "server/pages", key);
174
+ const htmlSrc = `${pagePath}.html`;
175
+ const jsonSrc = `${pagePath}.json`;
176
+ const htmlDest = join(ctx.staticDir, `${key}.html`);
177
+ const jsonDest = join(ctx.staticDir, `_next/data/${buildId}`, `${key}.json`);
178
+ if (existsSync(htmlSrc)) {
179
+ await mkdir(path.dirname(htmlDest), { recursive: true });
180
+ await writeFile(htmlDest, await readFile(htmlSrc));
181
+ }
182
+ if (existsSync(jsonSrc)) {
183
+ await mkdir(path.dirname(jsonDest), { recursive: true });
184
+ await writeFile(jsonDest, await readFile(jsonSrc));
185
+ }
186
+ };
187
+ var buildAppCacheValue = async (ctx, key) => {
188
+ const appPath = join(ctx.publishDir, "server/app", key);
189
+ const htmlAppSrc = `${appPath}.html`;
190
+ const metaAppSrc = `${appPath}.meta`;
191
+ const rscAppSrc = `${appPath}.rsc`;
192
+ const prefetchRscAppSrc = `${appPath}.prefetch.rsc`;
193
+ const htmlAppDest = join(ctx.staticDir, `${key}.html`);
194
+ const metaAppDest = join(ctx.staticDir, `${key}.meta`);
195
+ const rscAppDest = join(ctx.staticDir, `${key}.rsc`);
196
+ const prefetchRscAppDest = join(ctx.staticDir, `${key}.prefetch.rsc`);
197
+ if (existsSync(htmlAppSrc)) {
198
+ await mkdir(path.dirname(htmlAppDest), { recursive: true });
199
+ await writeFile(htmlAppDest, await readFile(htmlAppSrc));
200
+ }
201
+ if (existsSync(metaAppSrc)) {
202
+ await mkdir(path.dirname(metaAppDest), { recursive: true });
203
+ await writeFile(metaAppDest, await readFile(metaAppSrc));
204
+ }
205
+ if (existsSync(rscAppSrc)) {
206
+ await mkdir(path.dirname(rscAppDest), { recursive: true });
207
+ await writeFile(rscAppDest, await readFile(rscAppSrc));
208
+ } else if (existsSync(prefetchRscAppSrc)) {
209
+ await mkdir(path.dirname(prefetchRscAppDest), {
210
+ recursive: true
211
+ });
212
+ await writeFile(prefetchRscAppDest, await readFile(prefetchRscAppSrc));
213
+ }
214
+ };
215
+ var buildRouteCacheValue = async (ctx, key) => {
216
+ const routePath = join(ctx.publishDir, "server/app", key);
217
+ const bodySrc = `${routePath}.body`;
218
+ const metaSrc = `${routePath}.meta`;
219
+ const bodyDest = join(ctx.staticDir, `${key}`);
220
+ const metaDest = join(ctx.staticDir, `${key}.meta`);
221
+ if (existsSync(bodySrc)) {
222
+ await mkdir(path.dirname(bodyDest), { recursive: true });
223
+ await writeFile(bodyDest, await readFile(bodySrc));
224
+ }
225
+ if (existsSync(metaSrc)) {
226
+ await mkdir(path.dirname(metaDest), { recursive: true });
227
+ await writeFile(metaDest, await readFile(metaSrc));
228
+ }
229
+ };
230
+ var copyPrerenderedContent = async (ctx) => {
231
+ return tracer.withActiveSpan("copyPrerenderedContent", async () => {
232
+ try {
233
+ const manifest = await ctx.getPrerenderManifest();
234
+ const limitConcurrentPrerenderContentHandling = pLimit(10);
235
+ const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(
236
+ ctx.nextVersion,
237
+ ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0",
238
+ {
239
+ includePrerelease: true
240
+ }
241
+ ) : false;
242
+ const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(
243
+ ctx.nextVersion,
244
+ ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0",
245
+ {
246
+ includePrerelease: true
247
+ }
248
+ ) : false;
249
+ await Promise.all([
250
+ ...Object.entries(manifest.routes).map(
251
+ ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
252
+ const key = routeToFilePath(route);
253
+ switch (true) {
254
+ // Parallel route default layout has no prerendered page
255
+ case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(
256
+ join(ctx.publishDir, "server/app", `${key}.html`)
257
+ )):
258
+ return;
259
+ case meta.dataRoute?.endsWith(".json"):
260
+ if (manifest.notFoundRoutes.includes(route)) {
261
+ return;
262
+ }
263
+ await buildPagesCacheValue(ctx, key);
264
+ break;
265
+ case meta.dataRoute?.endsWith(".rsc"):
266
+ await buildAppCacheValue(ctx, key);
267
+ break;
268
+ case meta.dataRoute === null:
269
+ await buildRouteCacheValue(ctx, key);
270
+ break;
271
+ default:
272
+ throw new Error(`Unrecognized content: ${route}`);
273
+ }
274
+ })
275
+ ),
276
+ ...ctx.getFallbacks(manifest).map(async (route) => {
277
+ const key = routeToFilePath(route);
278
+ await buildPagesCacheValue(ctx, key);
279
+ })
280
+ ]);
281
+ if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
282
+ const key = "/404";
283
+ await buildAppCacheValue(ctx, key);
284
+ }
285
+ } catch (error) {
286
+ ctx.failBuild("Failed assembling prerendered content for upload", error);
287
+ }
288
+ });
289
+ };
290
+ export {
291
+ copyPrerenderedContent
292
+ };