@opennextjs/cloudflare 1.6.5 → 1.7.0
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.d.ts +3 -3
- package/dist/api/durable-objects/bucket-cache-purge.js +1 -1
- package/dist/api/durable-objects/queue.d.ts +1 -1
- package/dist/api/overrides/asset-resolver/index.d.ts +1 -1
- package/dist/api/overrides/cache-purge/index.d.ts +1 -1
- package/dist/api/overrides/cache-purge/index.js +1 -1
- package/dist/api/overrides/incremental-cache/regional-cache.d.ts +9 -0
- package/dist/api/overrides/incremental-cache/regional-cache.js +14 -1
- package/dist/api/overrides/queue/do-queue.d.ts +1 -1
- package/dist/api/overrides/queue/do-queue.js +1 -1
- package/dist/api/overrides/queue/memory-queue.js +2 -2
- package/dist/api/overrides/queue/queue-cache.d.ts +1 -1
- package/dist/api/overrides/tag-cache/do-sharded-tag-cache.js +2 -2
- package/dist/api/overrides/tag-cache/tag-cache-filter.d.ts +1 -1
- package/dist/cli/build/build.js +2 -1
- package/dist/cli/build/bundle-server.js +0 -2
- package/dist/cli/build/open-next/compile-skew-protection.d.ts +1 -1
- package/dist/cli/build/open-next/createServerBundle.js +1 -0
- package/dist/cli/build/utils/needs-experimental-react.d.ts +1 -1
- package/dist/cli/commands/skew-protection.d.ts +1 -1
- package/dist/cli/templates/worker.js +1 -1
- package/package.json +2 -2
- package/dist/cli/build/patches/plugins/node-environment.d.ts +0 -9
- package/dist/cli/build/patches/plugins/node-environment.js +0 -26
package/dist/api/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BuildOptions } from "@opennextjs/aws/build/helper";
|
|
2
|
-
import { BaseOverride, LazyLoadedOverride, OpenNextConfig as AwsOpenNextConfig, type RoutePreloadingBehavior } from "@opennextjs/aws/types/open-next";
|
|
3
|
-
import type { CDNInvalidationHandler, IncrementalCache, Queue, TagCache } from "@opennextjs/aws/types/overrides";
|
|
1
|
+
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
2
|
+
import { BaseOverride, LazyLoadedOverride, OpenNextConfig as AwsOpenNextConfig, type RoutePreloadingBehavior } from "@opennextjs/aws/types/open-next.js";
|
|
3
|
+
import type { CDNInvalidationHandler, IncrementalCache, Queue, TagCache } from "@opennextjs/aws/types/overrides.js";
|
|
4
4
|
export type Override<T extends BaseOverride> = "dummy" | T | LazyLoadedOverride<T>;
|
|
5
5
|
/**
|
|
6
6
|
* Cloudflare specific overrides.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DurableObject } from "cloudflare:workers";
|
|
2
|
-
import { internalPurgeCacheByTags } from "../overrides/internal";
|
|
2
|
+
import { internalPurgeCacheByTags } from "../overrides/internal.js";
|
|
3
3
|
const DEFAULT_BUFFER_TIME_IN_SECONDS = 5;
|
|
4
4
|
// https://developers.cloudflare.com/cache/how-to/purge-cache/#hostname-tag-prefix-url-and-purge-everything-limits
|
|
5
5
|
const MAX_NUMBER_OF_TAGS_PER_PURGE = 100;
|
|
@@ -6,7 +6,7 @@ export declare const purgeCache: ({ type }: PurgeOptions) => {
|
|
|
6
6
|
invalidatePaths(paths: {
|
|
7
7
|
initialPath: string;
|
|
8
8
|
rawPath: string;
|
|
9
|
-
resolvedRoutes: import("@opennextjs/aws/types/open-next").ResolvedRoute[];
|
|
9
|
+
resolvedRoutes: import("@opennextjs/aws/types/open-next.js").ResolvedRoute[];
|
|
10
10
|
}[]): Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCloudflareContext } from "../../cloudflare-context";
|
|
1
|
+
import { getCloudflareContext } from "../../cloudflare-context.js";
|
|
2
2
|
import { debugCache, internalPurgeCacheByTags } from "../internal.js";
|
|
3
3
|
export const purgeCache = ({ type = "direct" }) => {
|
|
4
4
|
return {
|
|
@@ -23,6 +23,14 @@ type Options = {
|
|
|
23
23
|
* @default `false` for the `short-lived` mode, and `true` for the `long-lived` mode.
|
|
24
24
|
*/
|
|
25
25
|
shouldLazilyUpdateOnCacheHit?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether on cache hits the tagCache should be skipped or not. Skipping the tagCache allows requests to be
|
|
28
|
+
* handled faster, the downside of this is that you need to make sure that the cache gets correctly purged
|
|
29
|
+
* either by enabling the auto cache purging feature or doing that manually.
|
|
30
|
+
*
|
|
31
|
+
* @default `true` if the auto cache purging is enabled, `false` otherwise.
|
|
32
|
+
*/
|
|
33
|
+
bypassTagCacheOnCacheHit?: boolean;
|
|
26
34
|
};
|
|
27
35
|
interface PutToCacheInput {
|
|
28
36
|
key: string;
|
|
@@ -33,6 +41,7 @@ interface PutToCacheInput {
|
|
|
33
41
|
* Wrapper adding a regional cache on an `IncrementalCache` implementation
|
|
34
42
|
*/
|
|
35
43
|
declare class RegionalCache implements IncrementalCache {
|
|
44
|
+
#private;
|
|
36
45
|
private store;
|
|
37
46
|
private opts;
|
|
38
47
|
name: string;
|
|
@@ -21,6 +21,15 @@ class RegionalCache {
|
|
|
21
21
|
this.name = this.store.name;
|
|
22
22
|
this.opts.shouldLazilyUpdateOnCacheHit ??= this.opts.mode === "long-lived";
|
|
23
23
|
}
|
|
24
|
+
get #bypassTagCacheOnCacheHit() {
|
|
25
|
+
if (this.opts.bypassTagCacheOnCacheHit !== undefined) {
|
|
26
|
+
// If the bypassTagCacheOnCacheHit option is set we return that one
|
|
27
|
+
return this.opts.bypassTagCacheOnCacheHit;
|
|
28
|
+
}
|
|
29
|
+
// Otherwise we default to whether the automatic cache purging is enabled or not
|
|
30
|
+
const hasAutomaticCachePurging = !!getCloudflareContext().env.NEXT_CACHE_DO_PURGE;
|
|
31
|
+
return hasAutomaticCachePurging;
|
|
32
|
+
}
|
|
24
33
|
async get(key, cacheType) {
|
|
25
34
|
try {
|
|
26
35
|
const cache = await this.getCacheInstance();
|
|
@@ -38,7 +47,11 @@ class RegionalCache {
|
|
|
38
47
|
}
|
|
39
48
|
}));
|
|
40
49
|
}
|
|
41
|
-
|
|
50
|
+
const responseJson = await cachedResponse.json();
|
|
51
|
+
return {
|
|
52
|
+
...responseJson,
|
|
53
|
+
shouldBypassTagCache: this.#bypassTagCacheOnCacheHit,
|
|
54
|
+
};
|
|
42
55
|
}
|
|
43
56
|
const rawEntry = await this.store.get(key, cacheType);
|
|
44
57
|
const { value, lastModified } = rawEntry ?? {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
|
|
2
|
-
import { getCloudflareContext } from "../../cloudflare-context";
|
|
2
|
+
import { getCloudflareContext } from "../../cloudflare-context.js";
|
|
3
3
|
export default {
|
|
4
4
|
name: "durable-queue",
|
|
5
5
|
send: async (msg) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { error } from "@opennextjs/aws/adapters/logger.js";
|
|
2
2
|
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
|
|
3
|
-
import { getCloudflareContext } from "../../cloudflare-context";
|
|
4
|
-
import { debugCache } from "../internal";
|
|
3
|
+
import { getCloudflareContext } from "../../cloudflare-context.js";
|
|
4
|
+
import { debugCache } from "../internal.js";
|
|
5
5
|
export const DEFAULT_REVALIDATION_TIMEOUT_MS = 10_000;
|
|
6
6
|
/**
|
|
7
7
|
* The Memory Queue offers basic ISR revalidation by directly requesting a revalidation of a route.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { debug, error } from "@opennextjs/aws/adapters/logger.js";
|
|
2
2
|
import { generateShardId } from "@opennextjs/aws/core/routing/queue.js";
|
|
3
3
|
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
|
|
4
|
-
import { getCloudflareContext } from "../../cloudflare-context";
|
|
5
|
-
import { debugCache, purgeCacheByTags } from "../internal";
|
|
4
|
+
import { getCloudflareContext } from "../../cloudflare-context.js";
|
|
5
|
+
import { debugCache, purgeCacheByTags } from "../internal.js";
|
|
6
6
|
export const DEFAULT_WRITE_RETRIES = 3;
|
|
7
7
|
export const DEFAULT_NUM_SHARDS = 4;
|
|
8
8
|
export const NAME = "do-sharded-tag-cache";
|
package/dist/cli/build/build.js
CHANGED
|
@@ -35,6 +35,8 @@ export async function build(options, config, projectOpts, wranglerConfig) {
|
|
|
35
35
|
const { aws, cloudflare } = getVersion();
|
|
36
36
|
logger.info(`@opennextjs/cloudflare version: ${cloudflare}`);
|
|
37
37
|
logger.info(`@opennextjs/aws version: ${aws}`);
|
|
38
|
+
// Clean the output directory before building the Next app.
|
|
39
|
+
buildHelper.initOutputDir(options);
|
|
38
40
|
if (projectOpts.skipNextBuild) {
|
|
39
41
|
logger.warn("Skipping Next.js build");
|
|
40
42
|
}
|
|
@@ -46,7 +48,6 @@ export async function build(options, config, projectOpts, wranglerConfig) {
|
|
|
46
48
|
}
|
|
47
49
|
// Generate deployable bundle
|
|
48
50
|
printHeader("Generating bundle");
|
|
49
|
-
buildHelper.initOutputDir(options);
|
|
50
51
|
compileCache(options);
|
|
51
52
|
compileEnvFiles(options);
|
|
52
53
|
compileInit(options, wranglerConfig);
|
|
@@ -13,7 +13,6 @@ import { inlineFindDir } from "./patches/plugins/find-dir.js";
|
|
|
13
13
|
import { patchInstrumentation } from "./patches/plugins/instrumentation.js";
|
|
14
14
|
import { inlineLoadManifest } from "./patches/plugins/load-manifest.js";
|
|
15
15
|
import { patchNextServer } from "./patches/plugins/next-server.js";
|
|
16
|
-
import { patchNodeEnvironment } from "./patches/plugins/node-environment.js";
|
|
17
16
|
import { patchResolveCache } from "./patches/plugins/open-next.js";
|
|
18
17
|
import { handleOptionalDependencies } from "./patches/plugins/optional-deps.js";
|
|
19
18
|
import { patchPagesRouterContext } from "./patches/plugins/pages-router-context.js";
|
|
@@ -91,7 +90,6 @@ export async function bundleServer(buildOpts, projectOpts) {
|
|
|
91
90
|
patchRouteModules(updater, buildOpts),
|
|
92
91
|
patchDepdDeprecations(updater),
|
|
93
92
|
patchResolveCache(updater, buildOpts),
|
|
94
|
-
patchNodeEnvironment(updater),
|
|
95
93
|
// Apply updater updates, must be the last plugin
|
|
96
94
|
updater.plugin,
|
|
97
95
|
],
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
2
|
-
import type { OpenNextConfig } from "../../../api";
|
|
2
|
+
import type { OpenNextConfig } from "../../../api/index.js";
|
|
3
3
|
export declare function compileSkewProtection(options: BuildOptions, config: OpenNextConfig): Promise<void>;
|
|
@@ -138,6 +138,7 @@ async function generateBundle(name, options, fnOptions, codeCustomization) {
|
|
|
138
138
|
awsPatches.patchNextServer,
|
|
139
139
|
awsPatches.patchEnvVars,
|
|
140
140
|
awsPatches.patchBackgroundRevalidation,
|
|
141
|
+
awsPatches.patchNodeEnvironment,
|
|
141
142
|
// Cloudflare specific patches
|
|
142
143
|
patchResRevalidate,
|
|
143
144
|
patchUseCacheIO,
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
|
|
23
23
|
import { Cloudflare } from "cloudflare";
|
|
24
|
-
import type { OpenNextConfig } from "../../api";
|
|
24
|
+
import type { OpenNextConfig } from "../../api/index.js";
|
|
25
25
|
import type { WorkerEnvVar } from "./helpers.js";
|
|
26
26
|
/**
|
|
27
27
|
* Compute the deployment mapping for a deployment.
|
|
@@ -44,7 +44,7 @@ export default {
|
|
|
44
44
|
}
|
|
45
45
|
// @ts-expect-error: resolved by wrangler build
|
|
46
46
|
const { handler } = await import("./server-functions/default/handler.mjs");
|
|
47
|
-
return handler(reqOrResp, env, ctx);
|
|
47
|
+
return handler(reqOrResp, env, ctx, request.signal);
|
|
48
48
|
});
|
|
49
49
|
},
|
|
50
50
|
};
|
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.
|
|
4
|
+
"version": "1.7.0",
|
|
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.7.
|
|
46
|
+
"@opennextjs/aws": "3.7.6",
|
|
47
47
|
"cloudflare": "^4.4.1",
|
|
48
48
|
"enquirer": "^2.4.1",
|
|
49
49
|
"glob": "^11.0.0",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove a dependency on Babel by dropping the require of error-inspect
|
|
3
|
-
*/
|
|
4
|
-
import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-updater.js";
|
|
5
|
-
export declare function patchNodeEnvironment(updater: ContentUpdater): Plugin;
|
|
6
|
-
/**
|
|
7
|
-
* Drops `require("./node-environment-extensions/error-inspect");`
|
|
8
|
-
*/
|
|
9
|
-
export declare const errorInspectRule = "\nrule:\n pattern: require(\"./node-environment-extensions/error-inspect\");\nfix: |-\n // Removed by OpenNext\n // require(\"./node-environment-extensions/error-inspect\");\n";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove a dependency on Babel by dropping the require of error-inspect
|
|
3
|
-
*/
|
|
4
|
-
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
|
|
5
|
-
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
|
|
6
|
-
export function patchNodeEnvironment(updater) {
|
|
7
|
-
return updater.updateContent("node-environment", [
|
|
8
|
-
{
|
|
9
|
-
filter: getCrossPlatformPathRegex(String.raw `/next/dist/server/node-environment\.js$`, {
|
|
10
|
-
escape: false,
|
|
11
|
-
}),
|
|
12
|
-
contentFilter: /error-inspect/,
|
|
13
|
-
callback: async ({ contents }) => patchCode(contents, errorInspectRule),
|
|
14
|
-
},
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Drops `require("./node-environment-extensions/error-inspect");`
|
|
19
|
-
*/
|
|
20
|
-
export const errorInspectRule = `
|
|
21
|
-
rule:
|
|
22
|
-
pattern: require("./node-environment-extensions/error-inspect");
|
|
23
|
-
fix: |-
|
|
24
|
-
// Removed by OpenNext
|
|
25
|
-
// require("./node-environment-extensions/error-inspect");
|
|
26
|
-
`;
|