@opennextjs/cloudflare 0.5.12 → 0.6.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.
- package/README.md +8 -8
- package/dist/api/cloudflare-context.d.ts +16 -5
- package/dist/api/config.d.ts +16 -43
- package/dist/api/config.js +21 -19
- package/dist/api/durable-objects/queue.d.ts +32 -0
- package/dist/api/durable-objects/queue.js +234 -0
- package/dist/api/durable-objects/queue.spec.js +290 -0
- package/dist/api/durable-objects/sharded-tag-cache.d.ts +7 -0
- package/dist/api/durable-objects/sharded-tag-cache.js +22 -0
- package/dist/api/durable-objects/sharded-tag-cache.spec.js +37 -0
- package/dist/api/overrides/incremental-cache/internal.d.ts +5 -0
- package/dist/api/{kv-cache.d.ts → overrides/incremental-cache/kv-incremental-cache.d.ts} +1 -1
- package/dist/api/{kv-cache.js → overrides/incremental-cache/kv-incremental-cache.js} +5 -5
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.d.ts +17 -0
- package/dist/api/overrides/incremental-cache/r2-incremental-cache.js +61 -0
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +51 -0
- package/dist/api/overrides/incremental-cache/regional-cache.js +111 -0
- package/dist/api/overrides/queue/do-queue.d.ts +6 -0
- package/dist/api/overrides/queue/do-queue.js +15 -0
- package/dist/api/{memory-queue.d.ts → overrides/queue/memory-queue.d.ts} +3 -3
- package/dist/api/{memory-queue.js → overrides/queue/memory-queue.js} +18 -14
- package/dist/api/overrides/queue/memory-queue.spec.d.ts +1 -0
- package/dist/api/{memory-queue.spec.js → overrides/queue/memory-queue.spec.js} +20 -14
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.d.ts +13 -0
- package/dist/api/overrides/tag-cache/d1-next-tag-cache.js +61 -0
- package/dist/api/{d1-tag-cache.d.ts → overrides/tag-cache/d1-tag-cache.d.ts} +3 -5
- package/dist/api/{d1-tag-cache.js → overrides/tag-cache/d1-tag-cache.js} +22 -29
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.d.ts +122 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +247 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.d.ts +1 -0
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.spec.js +322 -0
- package/dist/cli/args.d.ts +13 -2
- package/dist/cli/args.js +44 -29
- package/dist/cli/build/build.d.ts +5 -1
- package/dist/cli/build/build.js +9 -19
- package/dist/cli/build/bundle-server.js +5 -13
- package/dist/cli/build/open-next/compile-cache-assets-manifest.d.ts +1 -1
- package/dist/cli/build/open-next/compile-cache-assets-manifest.js +4 -6
- package/dist/cli/build/open-next/compileDurableObjects.d.ts +2 -0
- package/dist/cli/build/open-next/compileDurableObjects.js +30 -0
- package/dist/cli/build/open-next/copyCacheAssets.js +1 -1
- package/dist/cli/build/open-next/createServerBundle.d.ts +9 -1
- package/dist/cli/build/open-next/createServerBundle.js +28 -9
- package/dist/cli/build/patches/ast/patch-vercel-og-library.js +1 -1
- package/dist/cli/build/patches/ast/vercel-og.d.ts +5 -5
- package/dist/cli/build/patches/ast/vercel-og.js +1 -1
- package/dist/cli/build/patches/ast/vercel-og.spec.js +1 -1
- package/dist/cli/build/patches/ast/webpack-runtime.js +1 -1
- package/dist/cli/build/patches/ast/webpack-runtime.spec.js +1 -1
- package/dist/cli/build/patches/plugins/build-id.d.ts +2 -2
- package/dist/cli/build/patches/plugins/build-id.js +12 -5
- package/dist/cli/build/patches/plugins/build-id.spec.js +1 -1
- package/dist/cli/build/patches/plugins/dynamic-requires.d.ts +1 -2
- package/dist/cli/build/patches/plugins/dynamic-requires.js +21 -11
- package/dist/cli/build/patches/plugins/eval-manifest.d.ts +2 -2
- package/dist/cli/build/patches/plugins/eval-manifest.js +12 -5
- package/dist/cli/build/patches/plugins/find-dir.d.ts +2 -2
- package/dist/cli/build/patches/plugins/find-dir.js +10 -5
- package/dist/cli/build/patches/plugins/instrumentation.d.ts +2 -5
- package/dist/cli/build/patches/plugins/instrumentation.js +19 -3
- package/dist/cli/build/patches/plugins/instrumentation.spec.js +1 -1
- package/dist/cli/build/patches/plugins/load-manifest.d.ts +2 -2
- package/dist/cli/build/patches/plugins/load-manifest.js +12 -5
- package/dist/cli/build/patches/plugins/next-minimal.d.ts +4 -7
- package/dist/cli/build/patches/plugins/next-minimal.js +31 -15
- package/dist/cli/build/patches/plugins/next-minimal.spec.js +1 -1
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.d.ts +2 -2
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.js +10 -2
- package/dist/cli/build/patches/plugins/patch-depd-deprecations.spec.js +1 -1
- package/dist/cli/build/patches/plugins/require.d.ts +2 -2
- package/dist/cli/build/patches/plugins/require.js +43 -35
- package/dist/cli/build/patches/plugins/res-revalidate.d.ts +3 -0
- package/dist/cli/build/patches/plugins/res-revalidate.js +77 -0
- package/dist/cli/build/patches/plugins/res-revalidate.spec.d.ts +1 -0
- package/dist/cli/build/patches/plugins/res-revalidate.spec.js +141 -0
- package/dist/cli/build/utils/create-config-files.d.ts +2 -2
- package/dist/cli/build/utils/create-config-files.js +3 -3
- package/dist/cli/build/utils/ensure-cf-config.js +3 -13
- package/dist/cli/commands/deploy.d.ts +5 -0
- package/dist/cli/commands/deploy.js +9 -0
- package/dist/cli/commands/populate-cache.d.ts +7 -0
- package/dist/cli/commands/populate-cache.js +78 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.js +9 -0
- package/dist/cli/index.js +36 -9
- package/dist/cli/project-options.d.ts +5 -1
- package/dist/cli/templates/worker.d.ts +3 -4
- package/dist/cli/templates/worker.js +30 -18
- package/dist/cli/utils/run-wrangler.d.ts +18 -0
- package/dist/cli/utils/run-wrangler.js +41 -0
- package/package.json +7 -9
- package/templates/open-next.config.ts +1 -1
- package/templates/wrangler.jsonc +2 -2
- package/dist/api/kvCache.d.ts +0 -5
- package/dist/api/kvCache.js +0 -5
- package/dist/cli/build/patches/ast/util.d.ts +0 -50
- package/dist/cli/build/patches/ast/util.js +0 -65
- package/dist/cli/build/patches/ast/util.spec.js +0 -43
- package/dist/cli/build/patches/plugins/content-updater.d.ts +0 -44
- package/dist/cli/build/patches/plugins/content-updater.js +0 -55
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.d.ts +0 -14
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.js +0 -40
- package/dist/cli/build/patches/plugins/fetch-cache-wait-until.spec.js +0 -453
- package/dist/cli/templates/shims/node-fs.d.ts +0 -17
- package/dist/cli/templates/shims/node-fs.js +0 -51
- package/dist/cli/templates/shims/throw.d.ts +0 -0
- package/dist/cli/templates/shims/throw.js +0 -2
- /package/dist/api/{memory-queue.spec.d.ts → durable-objects/queue.spec.d.ts} +0 -0
- /package/dist/{cli/build/patches/ast/util.spec.d.ts → api/durable-objects/sharded-tag-cache.spec.d.ts} +0 -0
- /package/dist/{cli/build/patches/plugins/fetch-cache-wait-until.spec.d.ts → api/overrides/incremental-cache/internal.js} +0 -0
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { patchCode } from "../ast/util.js";
|
|
3
|
-
import { rule } from "./fetch-cache-wait-until.js";
|
|
4
|
-
describe("patchFetchCacheSetMissingWaitUntil", () => {
|
|
5
|
-
test("on minified code", () => {
|
|
6
|
-
const code = `
|
|
7
|
-
{
|
|
8
|
-
let [o4, a2] = (0, d2.cloneResponse)(e3);
|
|
9
|
-
return o4.arrayBuffer().then(async (e4) => {
|
|
10
|
-
var a3;
|
|
11
|
-
let i4 = Buffer.from(e4), s3 = { headers: Object.fromEntries(o4.headers.entries()), body: i4.toString("base64"), status: o4.status, url: o4.url };
|
|
12
|
-
null == $ || null == (a3 = $.serverComponentsHmrCache) || a3.set(n2, s3), F && await H.set(n2, { kind: c2.CachedRouteKind.FETCH, data: s3, revalidate: t5 }, { fetchCache: true, revalidate: r4, fetchUrl: _, fetchIdx: q, tags: A2 });
|
|
13
|
-
}).catch((e4) => console.warn("Failed to set fetch cache", u4, e4)).finally(X), a2;
|
|
14
|
-
}`;
|
|
15
|
-
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
|
|
16
|
-
"{
|
|
17
|
-
let [o4, a2] = (0, d2.cloneResponse)(e3);
|
|
18
|
-
return globalThis.__openNextAls?.getStore()?.waitUntil?.(o4.arrayBuffer().then(async (e4) => {
|
|
19
|
-
var a3;
|
|
20
|
-
let i4 = Buffer.from(e4), s3 = { headers: Object.fromEntries(o4.headers.entries()), body: i4.toString("base64"), status: o4.status, url: o4.url };
|
|
21
|
-
null == $ || null == (a3 = $.serverComponentsHmrCache) || a3.set(n2, s3), F && await H.set(n2, { kind: c2.CachedRouteKind.FETCH, data: s3, revalidate: t5 }, { fetchCache: true, revalidate: r4, fetchUrl: _, fetchIdx: q, tags: A2 });
|
|
22
|
-
}).catch((e4) => console.warn("Failed to set fetch cache", u4, e4)).finally(X))
|
|
23
|
-
, a2;
|
|
24
|
-
}"
|
|
25
|
-
`);
|
|
26
|
-
});
|
|
27
|
-
describe("on non-minified code", () => {
|
|
28
|
-
test("15.1.0", () => {
|
|
29
|
-
// source: https://github.com/vercel/next.js/blob/fe45b74fdac83d3/packages/next/src/server/lib/patch-fetch.ts#L627-L732
|
|
30
|
-
const code = `if (
|
|
31
|
-
res.status === 200 &&
|
|
32
|
-
incrementalCache &&
|
|
33
|
-
cacheKey &&
|
|
34
|
-
(isCacheableRevalidate ||
|
|
35
|
-
useCacheOrRequestStore?.serverComponentsHmrCache)
|
|
36
|
-
) {
|
|
37
|
-
const normalizedRevalidate =
|
|
38
|
-
finalRevalidate >= INFINITE_CACHE
|
|
39
|
-
? CACHE_ONE_YEAR
|
|
40
|
-
: finalRevalidate
|
|
41
|
-
const externalRevalidate =
|
|
42
|
-
finalRevalidate >= INFINITE_CACHE ? false : finalRevalidate
|
|
43
|
-
|
|
44
|
-
if (workUnitStore && workUnitStore.type === 'prerender') {
|
|
45
|
-
// We are prerendering at build time or revalidate time with dynamicIO so we need to
|
|
46
|
-
// buffer the response so we can guarantee it can be read in a microtask
|
|
47
|
-
const bodyBuffer = await res.arrayBuffer()
|
|
48
|
-
|
|
49
|
-
const fetchedData = {
|
|
50
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
51
|
-
body: Buffer.from(bodyBuffer).toString('base64'),
|
|
52
|
-
status: res.status,
|
|
53
|
-
url: res.url,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// We can skip checking the serverComponentsHmrCache because we aren't in
|
|
57
|
-
// dev mode.
|
|
58
|
-
|
|
59
|
-
await incrementalCache.set(
|
|
60
|
-
cacheKey,
|
|
61
|
-
{
|
|
62
|
-
kind: CachedRouteKind.FETCH,
|
|
63
|
-
data: fetchedData,
|
|
64
|
-
revalidate: normalizedRevalidate,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
fetchCache: true,
|
|
68
|
-
revalidate: externalRevalidate,
|
|
69
|
-
fetchUrl,
|
|
70
|
-
fetchIdx,
|
|
71
|
-
tags,
|
|
72
|
-
}
|
|
73
|
-
)
|
|
74
|
-
await handleUnlock()
|
|
75
|
-
|
|
76
|
-
// We return a new Response to the caller.
|
|
77
|
-
return new Response(bodyBuffer, {
|
|
78
|
-
headers: res.headers,
|
|
79
|
-
status: res.status,
|
|
80
|
-
statusText: res.statusText,
|
|
81
|
-
})
|
|
82
|
-
} else {
|
|
83
|
-
// We're cloning the response using this utility because there
|
|
84
|
-
// exists a bug in the undici library around response cloning.
|
|
85
|
-
// See the following pull request for more details:
|
|
86
|
-
// https://github.com/vercel/next.js/pull/73274
|
|
87
|
-
|
|
88
|
-
const [cloned1, cloned2] = cloneResponse(res)
|
|
89
|
-
|
|
90
|
-
// We are dynamically rendering including dev mode. We want to return
|
|
91
|
-
// the response to the caller as soon as possible because it might stream
|
|
92
|
-
// over a very long time.
|
|
93
|
-
cloned1
|
|
94
|
-
.arrayBuffer()
|
|
95
|
-
.then(async (arrayBuffer) => {
|
|
96
|
-
const bodyBuffer = Buffer.from(arrayBuffer)
|
|
97
|
-
|
|
98
|
-
const fetchedData = {
|
|
99
|
-
headers: Object.fromEntries(cloned1.headers.entries()),
|
|
100
|
-
body: bodyBuffer.toString('base64'),
|
|
101
|
-
status: cloned1.status,
|
|
102
|
-
url: cloned1.url,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
useCacheOrRequestStore?.serverComponentsHmrCache?.set(
|
|
106
|
-
cacheKey,
|
|
107
|
-
fetchedData
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
if (isCacheableRevalidate) {
|
|
111
|
-
await incrementalCache.set(
|
|
112
|
-
cacheKey,
|
|
113
|
-
{
|
|
114
|
-
kind: CachedRouteKind.FETCH,
|
|
115
|
-
data: fetchedData,
|
|
116
|
-
revalidate: normalizedRevalidate,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
fetchCache: true,
|
|
120
|
-
revalidate: externalRevalidate,
|
|
121
|
-
fetchUrl,
|
|
122
|
-
fetchIdx,
|
|
123
|
-
tags,
|
|
124
|
-
}
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
.catch((error) =>
|
|
129
|
-
console.warn(\`Failed to set fetch cache\`, input, error)
|
|
130
|
-
)
|
|
131
|
-
.finally(handleUnlock)
|
|
132
|
-
|
|
133
|
-
return cloned2
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
`;
|
|
137
|
-
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
|
|
138
|
-
"if (
|
|
139
|
-
res.status === 200 &&
|
|
140
|
-
incrementalCache &&
|
|
141
|
-
cacheKey &&
|
|
142
|
-
(isCacheableRevalidate ||
|
|
143
|
-
useCacheOrRequestStore?.serverComponentsHmrCache)
|
|
144
|
-
) {
|
|
145
|
-
const normalizedRevalidate =
|
|
146
|
-
finalRevalidate >= INFINITE_CACHE
|
|
147
|
-
? CACHE_ONE_YEAR
|
|
148
|
-
: finalRevalidate
|
|
149
|
-
const externalRevalidate =
|
|
150
|
-
finalRevalidate >= INFINITE_CACHE ? false : finalRevalidate
|
|
151
|
-
|
|
152
|
-
if (workUnitStore && workUnitStore.type === 'prerender') {
|
|
153
|
-
// We are prerendering at build time or revalidate time with dynamicIO so we need to
|
|
154
|
-
// buffer the response so we can guarantee it can be read in a microtask
|
|
155
|
-
const bodyBuffer = await res.arrayBuffer()
|
|
156
|
-
|
|
157
|
-
const fetchedData = {
|
|
158
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
159
|
-
body: Buffer.from(bodyBuffer).toString('base64'),
|
|
160
|
-
status: res.status,
|
|
161
|
-
url: res.url,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// We can skip checking the serverComponentsHmrCache because we aren't in
|
|
165
|
-
// dev mode.
|
|
166
|
-
|
|
167
|
-
await incrementalCache.set(
|
|
168
|
-
cacheKey,
|
|
169
|
-
{
|
|
170
|
-
kind: CachedRouteKind.FETCH,
|
|
171
|
-
data: fetchedData,
|
|
172
|
-
revalidate: normalizedRevalidate,
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
fetchCache: true,
|
|
176
|
-
revalidate: externalRevalidate,
|
|
177
|
-
fetchUrl,
|
|
178
|
-
fetchIdx,
|
|
179
|
-
tags,
|
|
180
|
-
}
|
|
181
|
-
)
|
|
182
|
-
await handleUnlock()
|
|
183
|
-
|
|
184
|
-
// We return a new Response to the caller.
|
|
185
|
-
return new Response(bodyBuffer, {
|
|
186
|
-
headers: res.headers,
|
|
187
|
-
status: res.status,
|
|
188
|
-
statusText: res.statusText,
|
|
189
|
-
})
|
|
190
|
-
} else {
|
|
191
|
-
// We're cloning the response using this utility because there
|
|
192
|
-
// exists a bug in the undici library around response cloning.
|
|
193
|
-
// See the following pull request for more details:
|
|
194
|
-
// https://github.com/vercel/next.js/pull/73274
|
|
195
|
-
|
|
196
|
-
const [cloned1, cloned2] = cloneResponse(res)
|
|
197
|
-
|
|
198
|
-
// We are dynamically rendering including dev mode. We want to return
|
|
199
|
-
// the response to the caller as soon as possible because it might stream
|
|
200
|
-
// over a very long time.
|
|
201
|
-
globalThis.__openNextAls?.getStore()?.waitUntil?.(cloned1
|
|
202
|
-
.arrayBuffer()
|
|
203
|
-
.then(async (arrayBuffer) => {
|
|
204
|
-
const bodyBuffer = Buffer.from(arrayBuffer)
|
|
205
|
-
|
|
206
|
-
const fetchedData = {
|
|
207
|
-
headers: Object.fromEntries(cloned1.headers.entries()),
|
|
208
|
-
body: bodyBuffer.toString('base64'),
|
|
209
|
-
status: cloned1.status,
|
|
210
|
-
url: cloned1.url,
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
useCacheOrRequestStore?.serverComponentsHmrCache?.set(
|
|
214
|
-
cacheKey,
|
|
215
|
-
fetchedData
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
if (isCacheableRevalidate) {
|
|
219
|
-
await incrementalCache.set(
|
|
220
|
-
cacheKey,
|
|
221
|
-
{
|
|
222
|
-
kind: CachedRouteKind.FETCH,
|
|
223
|
-
data: fetchedData,
|
|
224
|
-
revalidate: normalizedRevalidate,
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
fetchCache: true,
|
|
228
|
-
revalidate: externalRevalidate,
|
|
229
|
-
fetchUrl,
|
|
230
|
-
fetchIdx,
|
|
231
|
-
tags,
|
|
232
|
-
}
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
.catch((error) =>
|
|
237
|
-
console.warn(\`Failed to set fetch cache\`, input, error)
|
|
238
|
-
)
|
|
239
|
-
.finally(handleUnlock))
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return cloned2
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
"
|
|
246
|
-
`);
|
|
247
|
-
});
|
|
248
|
-
test("Next.js 15.0.4", () => {
|
|
249
|
-
// source: https://github.com/vercel/next.js/blob/d6a6aa14069/packages/next/src/server/lib/patch-fetch.ts#L627-L725
|
|
250
|
-
const code = `if (
|
|
251
|
-
res.status === 200 &&
|
|
252
|
-
incrementalCache &&
|
|
253
|
-
cacheKey &&
|
|
254
|
-
(isCacheableRevalidate || requestStore?.serverComponentsHmrCache)
|
|
255
|
-
) {
|
|
256
|
-
const normalizedRevalidate =
|
|
257
|
-
finalRevalidate >= INFINITE_CACHE
|
|
258
|
-
? CACHE_ONE_YEAR
|
|
259
|
-
: finalRevalidate
|
|
260
|
-
const externalRevalidate =
|
|
261
|
-
finalRevalidate >= INFINITE_CACHE ? false : finalRevalidate
|
|
262
|
-
|
|
263
|
-
if (workUnitStore && workUnitStore.type === 'prerender') {
|
|
264
|
-
// We are prerendering at build time or revalidate time with dynamicIO so we need to
|
|
265
|
-
// buffer the response so we can guarantee it can be read in a microtask
|
|
266
|
-
const bodyBuffer = await res.arrayBuffer()
|
|
267
|
-
|
|
268
|
-
const fetchedData = {
|
|
269
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
270
|
-
body: Buffer.from(bodyBuffer).toString('base64'),
|
|
271
|
-
status: res.status,
|
|
272
|
-
url: res.url,
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// We can skip checking the serverComponentsHmrCache because we aren't in
|
|
276
|
-
// dev mode.
|
|
277
|
-
|
|
278
|
-
await incrementalCache.set(
|
|
279
|
-
cacheKey,
|
|
280
|
-
{
|
|
281
|
-
kind: CachedRouteKind.FETCH,
|
|
282
|
-
data: fetchedData,
|
|
283
|
-
revalidate: normalizedRevalidate,
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
fetchCache: true,
|
|
287
|
-
revalidate: externalRevalidate,
|
|
288
|
-
fetchUrl,
|
|
289
|
-
fetchIdx,
|
|
290
|
-
tags,
|
|
291
|
-
}
|
|
292
|
-
)
|
|
293
|
-
await handleUnlock()
|
|
294
|
-
|
|
295
|
-
// We we return a new Response to the caller.
|
|
296
|
-
return new Response(bodyBuffer, {
|
|
297
|
-
headers: res.headers,
|
|
298
|
-
status: res.status,
|
|
299
|
-
statusText: res.statusText,
|
|
300
|
-
})
|
|
301
|
-
} else {
|
|
302
|
-
// We are dynamically rendering including dev mode. We want to return
|
|
303
|
-
// the response to the caller as soon as possible because it might stream
|
|
304
|
-
// over a very long time.
|
|
305
|
-
res
|
|
306
|
-
.clone()
|
|
307
|
-
.arrayBuffer()
|
|
308
|
-
.then(async (arrayBuffer) => {
|
|
309
|
-
const bodyBuffer = Buffer.from(arrayBuffer)
|
|
310
|
-
|
|
311
|
-
const fetchedData = {
|
|
312
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
313
|
-
body: bodyBuffer.toString('base64'),
|
|
314
|
-
status: res.status,
|
|
315
|
-
url: res.url,
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
requestStore?.serverComponentsHmrCache?.set(
|
|
319
|
-
cacheKey,
|
|
320
|
-
fetchedData
|
|
321
|
-
)
|
|
322
|
-
|
|
323
|
-
if (isCacheableRevalidate) {
|
|
324
|
-
await incrementalCache.set(
|
|
325
|
-
cacheKey,
|
|
326
|
-
{
|
|
327
|
-
kind: CachedRouteKind.FETCH,
|
|
328
|
-
data: fetchedData,
|
|
329
|
-
revalidate: normalizedRevalidate,
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
fetchCache: true,
|
|
333
|
-
revalidate: externalRevalidate,
|
|
334
|
-
fetchUrl,
|
|
335
|
-
fetchIdx,
|
|
336
|
-
tags,
|
|
337
|
-
}
|
|
338
|
-
)
|
|
339
|
-
}
|
|
340
|
-
})
|
|
341
|
-
.catch((error) =>
|
|
342
|
-
console.warn(\`Failed to set fetch cache\`, input, error)
|
|
343
|
-
)
|
|
344
|
-
.finally(handleUnlock)
|
|
345
|
-
|
|
346
|
-
return res
|
|
347
|
-
}
|
|
348
|
-
}`;
|
|
349
|
-
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
|
|
350
|
-
"if (
|
|
351
|
-
res.status === 200 &&
|
|
352
|
-
incrementalCache &&
|
|
353
|
-
cacheKey &&
|
|
354
|
-
(isCacheableRevalidate || requestStore?.serverComponentsHmrCache)
|
|
355
|
-
) {
|
|
356
|
-
const normalizedRevalidate =
|
|
357
|
-
finalRevalidate >= INFINITE_CACHE
|
|
358
|
-
? CACHE_ONE_YEAR
|
|
359
|
-
: finalRevalidate
|
|
360
|
-
const externalRevalidate =
|
|
361
|
-
finalRevalidate >= INFINITE_CACHE ? false : finalRevalidate
|
|
362
|
-
|
|
363
|
-
if (workUnitStore && workUnitStore.type === 'prerender') {
|
|
364
|
-
// We are prerendering at build time or revalidate time with dynamicIO so we need to
|
|
365
|
-
// buffer the response so we can guarantee it can be read in a microtask
|
|
366
|
-
const bodyBuffer = await res.arrayBuffer()
|
|
367
|
-
|
|
368
|
-
const fetchedData = {
|
|
369
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
370
|
-
body: Buffer.from(bodyBuffer).toString('base64'),
|
|
371
|
-
status: res.status,
|
|
372
|
-
url: res.url,
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// We can skip checking the serverComponentsHmrCache because we aren't in
|
|
376
|
-
// dev mode.
|
|
377
|
-
|
|
378
|
-
await incrementalCache.set(
|
|
379
|
-
cacheKey,
|
|
380
|
-
{
|
|
381
|
-
kind: CachedRouteKind.FETCH,
|
|
382
|
-
data: fetchedData,
|
|
383
|
-
revalidate: normalizedRevalidate,
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
fetchCache: true,
|
|
387
|
-
revalidate: externalRevalidate,
|
|
388
|
-
fetchUrl,
|
|
389
|
-
fetchIdx,
|
|
390
|
-
tags,
|
|
391
|
-
}
|
|
392
|
-
)
|
|
393
|
-
await handleUnlock()
|
|
394
|
-
|
|
395
|
-
// We we return a new Response to the caller.
|
|
396
|
-
return new Response(bodyBuffer, {
|
|
397
|
-
headers: res.headers,
|
|
398
|
-
status: res.status,
|
|
399
|
-
statusText: res.statusText,
|
|
400
|
-
})
|
|
401
|
-
} else {
|
|
402
|
-
// We are dynamically rendering including dev mode. We want to return
|
|
403
|
-
// the response to the caller as soon as possible because it might stream
|
|
404
|
-
// over a very long time.
|
|
405
|
-
globalThis.__openNextAls?.getStore()?.waitUntil?.(res
|
|
406
|
-
.clone()
|
|
407
|
-
.arrayBuffer()
|
|
408
|
-
.then(async (arrayBuffer) => {
|
|
409
|
-
const bodyBuffer = Buffer.from(arrayBuffer)
|
|
410
|
-
|
|
411
|
-
const fetchedData = {
|
|
412
|
-
headers: Object.fromEntries(res.headers.entries()),
|
|
413
|
-
body: bodyBuffer.toString('base64'),
|
|
414
|
-
status: res.status,
|
|
415
|
-
url: res.url,
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
requestStore?.serverComponentsHmrCache?.set(
|
|
419
|
-
cacheKey,
|
|
420
|
-
fetchedData
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
if (isCacheableRevalidate) {
|
|
424
|
-
await incrementalCache.set(
|
|
425
|
-
cacheKey,
|
|
426
|
-
{
|
|
427
|
-
kind: CachedRouteKind.FETCH,
|
|
428
|
-
data: fetchedData,
|
|
429
|
-
revalidate: normalizedRevalidate,
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
fetchCache: true,
|
|
433
|
-
revalidate: externalRevalidate,
|
|
434
|
-
fetchUrl,
|
|
435
|
-
fetchIdx,
|
|
436
|
-
tags,
|
|
437
|
-
}
|
|
438
|
-
)
|
|
439
|
-
}
|
|
440
|
-
})
|
|
441
|
-
.catch((error) =>
|
|
442
|
-
console.warn(\`Failed to set fetch cache\`, input, error)
|
|
443
|
-
)
|
|
444
|
-
.finally(handleUnlock))
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
return res
|
|
448
|
-
}
|
|
449
|
-
}"
|
|
450
|
-
`);
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const nodeFs: {
|
|
2
|
-
existsSync: typeof existsSync;
|
|
3
|
-
readFile: typeof readFile;
|
|
4
|
-
readFileSync: typeof readFileSync;
|
|
5
|
-
writeFile: typeof writeFile;
|
|
6
|
-
mkdir: typeof mkdir;
|
|
7
|
-
stat: typeof stat;
|
|
8
|
-
};
|
|
9
|
-
declare function existsSync(path: string): boolean;
|
|
10
|
-
declare function readFile(path: string, options: unknown): Promise<unknown>;
|
|
11
|
-
declare function readFileSync(path: string, options: unknown): unknown;
|
|
12
|
-
declare function writeFile(file: string, data: unknown): Promise<boolean>;
|
|
13
|
-
declare function mkdir(dir: string): Promise<void>;
|
|
14
|
-
declare function stat(file: string): Promise<{
|
|
15
|
-
mtime: Date;
|
|
16
|
-
}>;
|
|
17
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/node-fs-methods.ts
|
|
2
|
-
export const nodeFs = {
|
|
3
|
-
existsSync,
|
|
4
|
-
readFile,
|
|
5
|
-
readFileSync,
|
|
6
|
-
writeFile,
|
|
7
|
-
mkdir,
|
|
8
|
-
stat,
|
|
9
|
-
};
|
|
10
|
-
const FILES = new Map();
|
|
11
|
-
const MTIME = Date.now();
|
|
12
|
-
function existsSync(path) {
|
|
13
|
-
console.log("existsSync", path, new Error().stack?.split("\n").slice(1).join("\n"));
|
|
14
|
-
return FILES.has(path);
|
|
15
|
-
}
|
|
16
|
-
async function readFile(path, options) {
|
|
17
|
-
console.log("readFile", { path, options }
|
|
18
|
-
// new Error().stack.split("\n").slice(1).join("\n"),
|
|
19
|
-
);
|
|
20
|
-
if (!FILES.has(path)) {
|
|
21
|
-
throw new Error(path + "does not exist");
|
|
22
|
-
}
|
|
23
|
-
return FILES.get(path);
|
|
24
|
-
}
|
|
25
|
-
function readFileSync(path, options) {
|
|
26
|
-
console.log("readFileSync", { path, options }
|
|
27
|
-
// new Error().stack.split("\n").slice(1).join("\n"),
|
|
28
|
-
);
|
|
29
|
-
if (!FILES.has(path)) {
|
|
30
|
-
throw new Error(path + "does not exist");
|
|
31
|
-
}
|
|
32
|
-
return FILES.get(path);
|
|
33
|
-
}
|
|
34
|
-
async function writeFile(file, data) {
|
|
35
|
-
console.log("writeFile", { file, data }
|
|
36
|
-
// new Error().stack.split("\n").slice(1).join("\n"),
|
|
37
|
-
);
|
|
38
|
-
FILES.set(file, data);
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
async function mkdir(dir) {
|
|
42
|
-
console.log("mkdir", dir
|
|
43
|
-
//new Error().stack.split("\n").slice(1).join("\n"),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
async function stat(file) {
|
|
47
|
-
console.log("stat", file
|
|
48
|
-
// new Error().stack.split("\n").slice(1).join("\n"),
|
|
49
|
-
);
|
|
50
|
-
return { mtime: new Date(MTIME) };
|
|
51
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|