@opennextjs/cloudflare 1.0.0-beta.1 → 1.0.0-beta.3
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/dist/api/config.js +2 -0
- package/dist/api/overrides/incremental-cache/kv-incremental-cache.d.ts +8 -7
- package/dist/api/overrides/incremental-cache/kv-incremental-cache.js +50 -90
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.d.ts +9 -0
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.js +22 -9
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +18 -3
- package/dist/api/overrides/incremental-cache/regional-cache.js +55 -18
- package/dist/api/overrides/incremental-cache/static-assets-incremental-cache.d.ts +17 -0
- package/dist/api/overrides/incremental-cache/static-assets-incremental-cache.js +46 -0
- package/dist/api/overrides/{incremental-cache/internal.d.ts → internal.d.ts} +2 -0
- package/dist/api/overrides/internal.js +6 -0
- package/dist/api/overrides/queue/memory-queue.js +3 -2
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.d.ts +1 -1
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.js +9 -13
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +4 -3
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.js +2 -1
- package/dist/cli/build/build.js +4 -3
- package/dist/cli/build/bundle-server.js +1 -42
- package/dist/cli/build/open-next/compile-env-files.js +1 -1
- package/dist/cli/build/open-next/compile-init.d.ts +5 -0
- package/dist/cli/build/open-next/compile-init.js +27 -0
- package/dist/cli/build/open-next/createServerBundle.js +7 -2
- package/dist/cli/build/utils/ensure-cf-config.js +2 -0
- package/dist/cli/commands/populate-cache.d.ts +7 -0
- package/dist/cli/commands/populate-cache.js +114 -46
- package/dist/cli/commands/populate-cache.spec.js +61 -0
- package/dist/cli/commands/upload.d.ts +5 -0
- package/dist/cli/commands/upload.js +9 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/templates/init.d.ts +13 -0
- package/dist/cli/templates/init.js +105 -0
- package/dist/cli/templates/worker.js +5 -53
- package/package.json +2 -2
- package/templates/open-next.config.ts +2 -2
- package/templates/wrangler.jsonc +9 -7
- package/dist/cli/build/open-next/copyCacheAssets.d.ts +0 -2
- package/dist/cli/build/open-next/copyCacheAssets.js +0 -10
- package/dist/cli/build/patches/plugins/next-minimal.d.ts +0 -4
- package/dist/cli/build/patches/plugins/next-minimal.js +0 -86
- package/dist/cli/build/patches/plugins/next-minimal.spec.d.ts +0 -1
- package/dist/cli/build/patches/plugins/next-minimal.spec.js +0 -71
- /package/dist/{api/overrides/incremental-cache/internal.js → cli/commands/populate-cache.spec.d.ts} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialization for the workerd runtime.
|
|
3
|
+
*
|
|
4
|
+
* The file must be imported at the top level the worker.
|
|
5
|
+
*/
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import stream from "node:stream";
|
|
9
|
+
// @ts-expect-error: resolved by wrangler build
|
|
10
|
+
import * as nextEnvVars from "./next-env.mjs";
|
|
11
|
+
const cloudflareContextALS = new AsyncLocalStorage();
|
|
12
|
+
// Note: this symbol needs to be kept in sync with `src/api/get-cloudflare-context.ts`
|
|
13
|
+
Object.defineProperty(globalThis, Symbol.for("__cloudflare-context__"), {
|
|
14
|
+
get() {
|
|
15
|
+
return cloudflareContextALS.getStore();
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Executes the handler with the Cloudflare context.
|
|
20
|
+
*/
|
|
21
|
+
export async function runWithCloudflareRequestContext(request, env, ctx, handler) {
|
|
22
|
+
init(request, env);
|
|
23
|
+
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, handler);
|
|
24
|
+
}
|
|
25
|
+
let initialized = false;
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the runtime on the first call,
|
|
28
|
+
* no-op on subsequent invocations.
|
|
29
|
+
*/
|
|
30
|
+
function init(request, env) {
|
|
31
|
+
if (initialized) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
initialized = true;
|
|
35
|
+
const url = new URL(request.url);
|
|
36
|
+
initRuntime();
|
|
37
|
+
populateProcessEnv(url, env);
|
|
38
|
+
}
|
|
39
|
+
function initRuntime() {
|
|
40
|
+
// Some packages rely on `process.version` and `process.versions.node` (i.e. Jose@4)
|
|
41
|
+
// TODO: Remove when https://github.com/unjs/unenv/pull/493 is merged
|
|
42
|
+
Object.assign(process, { version: process.version || "v22.14.0" });
|
|
43
|
+
// @ts-expect-error Node type does not match workerd
|
|
44
|
+
Object.assign(process.versions, { node: "22.14.0", ...process.versions });
|
|
45
|
+
globalThis.__dirname ??= "";
|
|
46
|
+
globalThis.__filename ??= "";
|
|
47
|
+
// Do not crash on cache not supported
|
|
48
|
+
// https://github.com/cloudflare/workerd/pull/2434
|
|
49
|
+
// compatibility flag "cache_option_enabled" -> does not support "force-cache"
|
|
50
|
+
const __original_fetch = globalThis.fetch;
|
|
51
|
+
globalThis.fetch = (input, init) => {
|
|
52
|
+
if (init) {
|
|
53
|
+
delete init.cache;
|
|
54
|
+
}
|
|
55
|
+
return __original_fetch(input, init);
|
|
56
|
+
};
|
|
57
|
+
const CustomRequest = class extends globalThis.Request {
|
|
58
|
+
constructor(input, init) {
|
|
59
|
+
if (init) {
|
|
60
|
+
delete init.cache;
|
|
61
|
+
// https://github.com/cloudflare/workerd/issues/2746
|
|
62
|
+
// https://github.com/cloudflare/workerd/issues/3245
|
|
63
|
+
Object.defineProperty(init, "body", {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
value: init.body instanceof stream.Readable ? ReadableStream.from(init.body) : init.body,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
super(input, init);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
Object.assign(globalThis, {
|
|
72
|
+
Request: CustomRequest,
|
|
73
|
+
__BUILD_TIMESTAMP_MS__: __BUILD_TIMESTAMP_MS__,
|
|
74
|
+
__NEXT_BASE_PATH__: __NEXT_BASE_PATH__,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Populate process.env with:
|
|
79
|
+
* - the environment variables and secrets from the cloudflare platform
|
|
80
|
+
* - the variables from Next .env* files
|
|
81
|
+
* - the origin resolver information
|
|
82
|
+
*/
|
|
83
|
+
function populateProcessEnv(url, env) {
|
|
84
|
+
for (const [key, value] of Object.entries(env)) {
|
|
85
|
+
if (typeof value === "string") {
|
|
86
|
+
process.env[key] = value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const mode = env.NEXTJS_ENV ?? "production";
|
|
90
|
+
if (nextEnvVars[mode]) {
|
|
91
|
+
for (const key in nextEnvVars[mode]) {
|
|
92
|
+
process.env[key] ??= nextEnvVars[mode][key];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Set the default Origin for the origin resolver.
|
|
96
|
+
// This is only needed for an external middleware bundle
|
|
97
|
+
process.env.OPEN_NEXT_ORIGIN = JSON.stringify({
|
|
98
|
+
default: {
|
|
99
|
+
host: url.hostname,
|
|
100
|
+
protocol: url.protocol.slice(0, -1),
|
|
101
|
+
port: url.port,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/* eslint-enable no-var */
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
// @ts-expect-error: resolved by wrangler build
|
|
4
|
-
import * as nextEnvVars from "./env/next-env.mjs";
|
|
5
|
-
const cloudflareContextALS = new AsyncLocalStorage();
|
|
6
|
-
// Note: this symbol needs to be kept in sync with `src/api/get-cloudflare-context.ts`
|
|
7
|
-
Object.defineProperty(globalThis, Symbol.for("__cloudflare-context__"), {
|
|
8
|
-
get() {
|
|
9
|
-
return cloudflareContextALS.getStore();
|
|
10
|
-
},
|
|
11
|
-
});
|
|
1
|
+
//@ts-expect-error: Will be resolved by wrangler build
|
|
2
|
+
import { runWithCloudflareRequestContext } from "./cloudflare/init.js";
|
|
12
3
|
//@ts-expect-error: Will be resolved by wrangler build
|
|
13
4
|
export { DOQueueHandler } from "./.build/durable-objects/queue.js";
|
|
14
5
|
//@ts-expect-error: Will be resolved by wrangler build
|
|
15
6
|
export { DOShardedTagCache } from "./.build/durable-objects/sharded-tag-cache.js";
|
|
16
|
-
// Populate process.env on the first request
|
|
17
|
-
let processEnvPopulated = false;
|
|
18
7
|
export default {
|
|
19
8
|
async fetch(request, env, ctx) {
|
|
20
|
-
return
|
|
9
|
+
return runWithCloudflareRequestContext(request, env, ctx, async () => {
|
|
21
10
|
const url = new URL(request.url);
|
|
22
|
-
populateProcessEnv(url, env);
|
|
23
11
|
// Serve images in development.
|
|
24
12
|
// Note: "/cdn-cgi/image/..." requests do not reach production workers.
|
|
25
13
|
if (url.pathname.startsWith("/cdn-cgi/image/")) {
|
|
@@ -33,10 +21,10 @@ export default {
|
|
|
33
21
|
: env.ASSETS?.fetch(new URL(`/${imageUrl}`, url));
|
|
34
22
|
}
|
|
35
23
|
// Fallback for the Next default image loader.
|
|
36
|
-
if (url.pathname ===
|
|
24
|
+
if (url.pathname === `${globalThis.__NEXT_BASE_PATH__}/_next/image`) {
|
|
37
25
|
const imageUrl = url.searchParams.get("url") ?? "";
|
|
38
26
|
return imageUrl.startsWith("/")
|
|
39
|
-
? env.ASSETS?.fetch(
|
|
27
|
+
? env.ASSETS?.fetch(`http://assets.local${imageUrl}`)
|
|
40
28
|
: fetch(imageUrl, { cf: { cacheEverything: true } });
|
|
41
29
|
}
|
|
42
30
|
// @ts-expect-error: resolved by wrangler build
|
|
@@ -45,39 +33,3 @@ export default {
|
|
|
45
33
|
});
|
|
46
34
|
},
|
|
47
35
|
};
|
|
48
|
-
/**
|
|
49
|
-
* Populate process.env with:
|
|
50
|
-
* - the environment variables and secrets from the cloudflare platform
|
|
51
|
-
* - the variables from Next .env* files
|
|
52
|
-
* - the origin resolver information
|
|
53
|
-
*/
|
|
54
|
-
function populateProcessEnv(url, env) {
|
|
55
|
-
if (processEnvPopulated) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
// Some packages rely on `process.version` and `process.versions.node` (i.e. Jose@4)
|
|
59
|
-
// TODO: Remove when https://github.com/unjs/unenv/pull/493 is merged
|
|
60
|
-
Object.assign(process, { version: process.version || "v22.14.0" });
|
|
61
|
-
// @ts-expect-error Node type does not match workerd
|
|
62
|
-
Object.assign(process.versions, { node: "22.14.0", ...process.versions });
|
|
63
|
-
processEnvPopulated = true;
|
|
64
|
-
for (const [key, value] of Object.entries(env)) {
|
|
65
|
-
if (typeof value === "string") {
|
|
66
|
-
process.env[key] = value;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const mode = env.NEXTJS_ENV ?? "production";
|
|
70
|
-
if (nextEnvVars[mode]) {
|
|
71
|
-
for (const key in nextEnvVars[mode]) {
|
|
72
|
-
process.env[key] ??= nextEnvVars[mode][key];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Set the default Origin for the origin resolver.
|
|
76
|
-
process.env.OPEN_NEXT_ORIGIN = JSON.stringify({
|
|
77
|
-
default: {
|
|
78
|
-
host: url.hostname,
|
|
79
|
-
protocol: url.protocol.slice(0, -1),
|
|
80
|
-
port: url.port,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opennextjs/cloudflare",
|
|
3
3
|
"description": "Cloudflare builder for next apps",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"opennextjs-cloudflare": "dist/cli/index.js"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@dotenvx/dotenvx": "1.31.0",
|
|
46
|
-
"@opennextjs/aws": "3.5.
|
|
46
|
+
"@opennextjs/aws": "3.5.7",
|
|
47
47
|
"enquirer": "^2.4.1",
|
|
48
48
|
"glob": "^11.0.0",
|
|
49
49
|
"ts-tqdm": "^0.8.6"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// default open-next.config.ts file created by @opennextjs/cloudflare
|
|
2
2
|
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";
|
|
3
|
-
import
|
|
3
|
+
import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache";
|
|
4
4
|
|
|
5
5
|
export default defineCloudflareConfig({
|
|
6
|
-
incrementalCache:
|
|
6
|
+
incrementalCache: r2IncrementalCache,
|
|
7
7
|
});
|
package/templates/wrangler.jsonc
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
"directory": ".open-next/assets",
|
|
9
9
|
"binding": "ASSETS"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
"r2_buckets": [
|
|
12
|
+
// Use R2 incremental cache
|
|
13
|
+
// See https://opennext.js.org/cloudflare/caching
|
|
14
|
+
{
|
|
15
|
+
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
|
16
|
+
// Create a bucket before deploying
|
|
17
|
+
// See https://developers.cloudflare.com/workers/wrangler/commands/#r2-bucket-create
|
|
18
|
+
"bucket_name": "<BUCKET_NAME>"
|
|
19
|
+
}
|
|
18
20
|
]
|
|
19
21
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { cpSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { CACHE_ASSET_DIR } from "../../../api/overrides/incremental-cache/kv-incremental-cache.js";
|
|
4
|
-
export function copyCacheAssets(options) {
|
|
5
|
-
const { outputDir } = options;
|
|
6
|
-
const srcPath = join(outputDir, "cache");
|
|
7
|
-
const dstPath = join(outputDir, "assets", CACHE_ASSET_DIR);
|
|
8
|
-
mkdirSync(dstPath, { recursive: true });
|
|
9
|
-
cpSync(srcPath, dstPath, { recursive: true });
|
|
10
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ContentUpdater, type Plugin } from "@opennextjs/aws/plugins/content-updater.js";
|
|
2
|
-
export declare const abortControllerRule = "\nrule:\n all:\n - kind: lexical_declaration\n pattern: let $VAR = new AbortController\n - precedes:\n kind: function_declaration\n stopBy: end\n has:\n kind: statement_block\n has:\n kind: try_statement\n has:\n kind: catch_clause\n has:\n kind: statement_block\n has:\n kind: return_statement\n all:\n - has:\n stopBy: end\n kind: member_expression\n pattern: $VAR.signal.aborted\n - has:\n stopBy: end\n kind: call_expression\n regex: console.error\\(\"Failed to fetch RSC payload for\n\nfix:\n 'let $VAR = {signal:{aborted: false}};'\n";
|
|
3
|
-
export declare const nextMinimalRule = "\nrule:\n kind: member_expression\n pattern: process.env.NEXT_MINIMAL\n any:\n - inside:\n kind: parenthesized_expression\n stopBy: end\n inside:\n kind: if_statement\n any:\n - inside:\n kind: statement_block\n inside:\n kind: method_definition\n any:\n - has: {kind: property_identifier, field: name, regex: runEdgeFunction}\n - has: {kind: property_identifier, field: name, regex: runMiddleware}\n - has: {kind: property_identifier, field: name, regex: imageOptimizer}\n - has:\n kind: statement_block\n has:\n kind: expression_statement\n pattern: res.statusCode = 400;\nfix:\n 'true'\n";
|
|
4
|
-
export declare function patchNextMinimal(updater: ContentUpdater): Plugin;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
2
|
-
// Remove an instantiation of `AbortController` from the runtime.
|
|
3
|
-
//
|
|
4
|
-
// Solves https://github.com/cloudflare/workerd/issues/3657:
|
|
5
|
-
// - The `AbortController` is meant for the client side, but ends in the server code somehow.
|
|
6
|
-
// That's why we can get ride of it. See https://github.com/vercel/next.js/pull/73975/files.
|
|
7
|
-
// - Top level instantiation of `AbortController` are not supported by workerd as of March, 2025.
|
|
8
|
-
// See https://github.com/cloudflare/workerd/issues/3657
|
|
9
|
-
// - As Next code is not more executed at top level, we do not need to apply this patch
|
|
10
|
-
// See https://github.com/opennextjs/opennextjs-cloudflare/pull/497
|
|
11
|
-
//
|
|
12
|
-
// We try to be as specific as possible to avoid patching the wrong thing here
|
|
13
|
-
export const abortControllerRule = `
|
|
14
|
-
rule:
|
|
15
|
-
all:
|
|
16
|
-
- kind: lexical_declaration
|
|
17
|
-
pattern: let $VAR = new AbortController
|
|
18
|
-
- precedes:
|
|
19
|
-
kind: function_declaration
|
|
20
|
-
stopBy: end
|
|
21
|
-
has:
|
|
22
|
-
kind: statement_block
|
|
23
|
-
has:
|
|
24
|
-
kind: try_statement
|
|
25
|
-
has:
|
|
26
|
-
kind: catch_clause
|
|
27
|
-
has:
|
|
28
|
-
kind: statement_block
|
|
29
|
-
has:
|
|
30
|
-
kind: return_statement
|
|
31
|
-
all:
|
|
32
|
-
- has:
|
|
33
|
-
stopBy: end
|
|
34
|
-
kind: member_expression
|
|
35
|
-
pattern: $VAR.signal.aborted
|
|
36
|
-
- has:
|
|
37
|
-
stopBy: end
|
|
38
|
-
kind: call_expression
|
|
39
|
-
regex: console.error\\("Failed to fetch RSC payload for
|
|
40
|
-
|
|
41
|
-
fix:
|
|
42
|
-
'let $VAR = {signal:{aborted: false}};'
|
|
43
|
-
`;
|
|
44
|
-
// This rule is used instead of defining `process.env.NEXT_MINIMAL` in the `esbuild config.
|
|
45
|
-
// Do we want to entirely replace these functions to reduce the bundle size?
|
|
46
|
-
// In next `renderHTML` is used as a fallback in case of errors, but in minimal mode it just throws the error and the responsibility of handling it is on the infra.
|
|
47
|
-
export const nextMinimalRule = `
|
|
48
|
-
rule:
|
|
49
|
-
kind: member_expression
|
|
50
|
-
pattern: process.env.NEXT_MINIMAL
|
|
51
|
-
any:
|
|
52
|
-
- inside:
|
|
53
|
-
kind: parenthesized_expression
|
|
54
|
-
stopBy: end
|
|
55
|
-
inside:
|
|
56
|
-
kind: if_statement
|
|
57
|
-
any:
|
|
58
|
-
- inside:
|
|
59
|
-
kind: statement_block
|
|
60
|
-
inside:
|
|
61
|
-
kind: method_definition
|
|
62
|
-
any:
|
|
63
|
-
- has: {kind: property_identifier, field: name, regex: runEdgeFunction}
|
|
64
|
-
- has: {kind: property_identifier, field: name, regex: runMiddleware}
|
|
65
|
-
- has: {kind: property_identifier, field: name, regex: imageOptimizer}
|
|
66
|
-
- has:
|
|
67
|
-
kind: statement_block
|
|
68
|
-
has:
|
|
69
|
-
kind: expression_statement
|
|
70
|
-
pattern: res.statusCode = 400;
|
|
71
|
-
fix:
|
|
72
|
-
'true'
|
|
73
|
-
`;
|
|
74
|
-
export function patchNextMinimal(updater) {
|
|
75
|
-
return updater.updateContent("patch-next-minimal", [
|
|
76
|
-
{
|
|
77
|
-
field: {
|
|
78
|
-
filter: /next-server\.(js)$/,
|
|
79
|
-
contentFilter: /.*/,
|
|
80
|
-
callback: ({ contents }) => {
|
|
81
|
-
return patchCode(contents, nextMinimalRule);
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { abortControllerRule } from "./next-minimal";
|
|
4
|
-
const appPageRuntimeProdJs = `let p = new AbortController;
|
|
5
|
-
async function h(e3, t3) {
|
|
6
|
-
let { flightRouterState: r3, nextUrl: a2, prefetchKind: i2 } = t3, u2 = { [n2.hY]: "1", [n2.B]: encodeURIComponent(JSON.stringify(r3)) };
|
|
7
|
-
i2 === o.ob.AUTO && (u2[n2._V] = "1"), a2 && (u2[n2.kO] = a2);
|
|
8
|
-
try {
|
|
9
|
-
var c2;
|
|
10
|
-
let t4 = i2 ? i2 === o.ob.TEMPORARY ? "high" : "low" : "auto";
|
|
11
|
-
"export" === process.env.__NEXT_CONFIG_OUTPUT && ((e3 = new URL(e3)).pathname.endsWith("/") ? e3.pathname += "index.txt" : e3.pathname += ".txt");
|
|
12
|
-
let r4 = await m(e3, u2, t4, p.signal), a3 = d(r4.url), h2 = r4.redirected ? a3 : void 0, g = r4.headers.get("content-type") || "", v = !!(null == (c2 = r4.headers.get("vary")) ? void 0 : c2.includes(n2.kO)), b = !!r4.headers.get(n2.jc), S = r4.headers.get(n2.UK), _ = null !== S ? parseInt(S, 10) : -1, w = g.startsWith(n2.al);
|
|
13
|
-
if ("export" !== process.env.__NEXT_CONFIG_OUTPUT || w || (w = g.startsWith("text/plain")), !w || !r4.ok || !r4.body)
|
|
14
|
-
return e3.hash && (a3.hash = e3.hash), f(a3.toString());
|
|
15
|
-
let k = b ? function(e4) {
|
|
16
|
-
let t5 = e4.getReader();
|
|
17
|
-
return new ReadableStream({ async pull(e5) {
|
|
18
|
-
for (; ; ) {
|
|
19
|
-
let { done: r5, value: n3 } = await t5.read();
|
|
20
|
-
if (!r5) {
|
|
21
|
-
e5.enqueue(n3);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
} });
|
|
27
|
-
}(r4.body) : r4.body, E = await y(k);
|
|
28
|
-
if ((0, l.X)() !== E.b)
|
|
29
|
-
return f(r4.url);
|
|
30
|
-
return { flightData: (0, s.aj)(E.f), canonicalUrl: h2, couldBeIntercepted: v, prerendered: E.S, postponed: b, staleTime: _ };
|
|
31
|
-
} catch (t4) {
|
|
32
|
-
return p.signal.aborted || console.error("Failed to fetch RSC payload for " + e3 + ". Falling back to browser navigation.", t4), { flightData: e3.toString(), canonicalUrl: void 0, couldBeIntercepted: false, prerendered: false, postponed: false, staleTime: -1 };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
describe("Abort controller", () => {
|
|
37
|
-
test("minimal", () => {
|
|
38
|
-
expect(patchCode(appPageRuntimeProdJs, abortControllerRule)).toBe(`let p = {signal:{aborted: false}};
|
|
39
|
-
async function h(e3, t3) {
|
|
40
|
-
let { flightRouterState: r3, nextUrl: a2, prefetchKind: i2 } = t3, u2 = { [n2.hY]: "1", [n2.B]: encodeURIComponent(JSON.stringify(r3)) };
|
|
41
|
-
i2 === o.ob.AUTO && (u2[n2._V] = "1"), a2 && (u2[n2.kO] = a2);
|
|
42
|
-
try {
|
|
43
|
-
var c2;
|
|
44
|
-
let t4 = i2 ? i2 === o.ob.TEMPORARY ? "high" : "low" : "auto";
|
|
45
|
-
"export" === process.env.__NEXT_CONFIG_OUTPUT && ((e3 = new URL(e3)).pathname.endsWith("/") ? e3.pathname += "index.txt" : e3.pathname += ".txt");
|
|
46
|
-
let r4 = await m(e3, u2, t4, p.signal), a3 = d(r4.url), h2 = r4.redirected ? a3 : void 0, g = r4.headers.get("content-type") || "", v = !!(null == (c2 = r4.headers.get("vary")) ? void 0 : c2.includes(n2.kO)), b = !!r4.headers.get(n2.jc), S = r4.headers.get(n2.UK), _ = null !== S ? parseInt(S, 10) : -1, w = g.startsWith(n2.al);
|
|
47
|
-
if ("export" !== process.env.__NEXT_CONFIG_OUTPUT || w || (w = g.startsWith("text/plain")), !w || !r4.ok || !r4.body)
|
|
48
|
-
return e3.hash && (a3.hash = e3.hash), f(a3.toString());
|
|
49
|
-
let k = b ? function(e4) {
|
|
50
|
-
let t5 = e4.getReader();
|
|
51
|
-
return new ReadableStream({ async pull(e5) {
|
|
52
|
-
for (; ; ) {
|
|
53
|
-
let { done: r5, value: n3 } = await t5.read();
|
|
54
|
-
if (!r5) {
|
|
55
|
-
e5.enqueue(n3);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
} });
|
|
61
|
-
}(r4.body) : r4.body, E = await y(k);
|
|
62
|
-
if ((0, l.X)() !== E.b)
|
|
63
|
-
return f(r4.url);
|
|
64
|
-
return { flightData: (0, s.aj)(E.f), canonicalUrl: h2, couldBeIntercepted: v, prerendered: E.S, postponed: b, staleTime: _ };
|
|
65
|
-
} catch (t4) {
|
|
66
|
-
return p.signal.aborted || console.error("Failed to fetch RSC payload for " + e3 + ". Falling back to browser navigation.", t4), { flightData: e3.toString(), canonicalUrl: void 0, couldBeIntercepted: false, prerendered: false, postponed: false, staleTime: -1 };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
`);
|
|
70
|
-
});
|
|
71
|
-
});
|
/package/dist/{api/overrides/incremental-cache/internal.js → cli/commands/populate-cache.spec.d.ts}
RENAMED
|
File without changes
|