@opennextjs/cloudflare 1.0.0-beta.2 → 1.0.0-beta.4
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 +5 -0
- package/dist/api/overrides/incremental-cache/kv-incremental-cache.js +10 -3
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.d.ts +6 -0
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.js +11 -2
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +17 -2
- package/dist/api/overrides/incremental-cache/regional-cache.js +52 -16
- package/dist/api/overrides/incremental-cache/static-assets-incremental-cache.js +0 -1
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.d.ts +0 -1
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.js +3 -8
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.d.ts +1 -1
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +13 -10
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.js +2 -4
- package/dist/api/overrides/tag-cache/tag-cache-filter.d.ts +26 -0
- package/dist/api/overrides/tag-cache/tag-cache-filter.js +41 -0
- package/dist/api/overrides/tag-cache/tag-cache-filter.spec.js +96 -0
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.js +2 -1
- package/dist/cli/build/build.js +4 -1
- package/dist/cli/build/bundle-server.js +3 -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/patches/plugins/pages-router-context.d.ts +11 -0
- package/dist/cli/build/patches/plugins/pages-router-context.js +32 -0
- 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 +51 -23
- package/dist/cli/commands/populate-cache.spec.d.ts +1 -0
- 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.d.ts +3 -1
- package/dist/cli/templates/worker.js +5 -53
- package/package.json +3 -3
- package/templates/open-next.config.ts +2 -2
- package/templates/wrangler.jsonc +9 -7
- 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.js +0 -71
- /package/dist/{cli/build/patches/plugins/next-minimal.spec.d.ts → api/overrides/tag-cache/tag-cache-filter.spec.d.ts} +0 -0
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.4",
|
|
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"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"vitest": "^2.1.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"wrangler": "^
|
|
71
|
+
"wrangler": "^4.7.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"clean": "rimraf dist",
|
|
@@ -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,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,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
|
-
});
|