@opennextjs/cloudflare 1.0.0-beta.0 → 1.0.0-beta.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.
|
@@ -105,7 +105,7 @@ class KVIncrementalCache {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
getKVKey(key, isFetch) {
|
|
108
|
-
return `${this.getBuildId()}/${key}.${isFetch ? "fetch" : "cache"}
|
|
108
|
+
return `${this.getBuildId()}/${key}.${isFetch ? "fetch" : "cache"}`.replace(/\/+/g, "/");
|
|
109
109
|
}
|
|
110
110
|
getAssetUrl(key, isFetch) {
|
|
111
111
|
return isFetch
|
|
@@ -56,7 +56,7 @@ class R2IncrementalCache {
|
|
|
56
56
|
}
|
|
57
57
|
getR2Key(key, isFetch) {
|
|
58
58
|
const directory = getCloudflareContext().env.NEXT_INC_CACHE_R2_PREFIX ?? "incremental-cache";
|
|
59
|
-
return `${directory}/${process.env.NEXT_BUILD_ID ?? "no-build-id"}/${key}.${isFetch ? "fetch" : "cache"}
|
|
59
|
+
return `${directory}/${process.env.NEXT_BUILD_ID ?? "no-build-id"}/${key}.${isFetch ? "fetch" : "cache"}`.replace(/\/+/g, "/");
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
export default new R2IncrementalCache();
|
|
@@ -2,6 +2,8 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import logger from "@opennextjs/aws/logger.js";
|
|
4
4
|
import { globSync } from "glob";
|
|
5
|
+
import { tqdm } from "ts-tqdm";
|
|
6
|
+
import { unstable_readConfig } from "wrangler";
|
|
5
7
|
import { NAME as R2_CACHE_NAME } from "../../api/overrides/incremental-cache/r2-incremental-cache.js";
|
|
6
8
|
import { NAME as D1_TAG_NAME } from "../../api/overrides/tag-cache/d1-next-tag-cache.js";
|
|
7
9
|
import { runWrangler } from "../utils/run-wrangler.js";
|
|
@@ -34,15 +36,24 @@ export async function populateCache(options, config, populateCacheOptions) {
|
|
|
34
36
|
const name = await resolveCacheName(incrementalCache);
|
|
35
37
|
switch (name) {
|
|
36
38
|
case R2_CACHE_NAME: {
|
|
39
|
+
const config = unstable_readConfig({ env: populateCacheOptions.environment });
|
|
40
|
+
const binding = (config.r2_buckets ?? []).find(({ binding }) => binding === "NEXT_INC_CACHE_R2_BUCKET");
|
|
41
|
+
if (!binding) {
|
|
42
|
+
throw new Error("No R2 binding 'NEXT_INC_CACHE_R2_BUCKET' found!");
|
|
43
|
+
}
|
|
44
|
+
const bucket = binding.bucket_name;
|
|
45
|
+
if (!bucket) {
|
|
46
|
+
throw new Error("R2 binding 'NEXT_INC_CACHE_R2_BUCKET' should have a 'bucket_name'");
|
|
47
|
+
}
|
|
37
48
|
logger.info("\nPopulating R2 incremental cache...");
|
|
38
49
|
const assets = getCacheAssetPaths(options);
|
|
39
|
-
|
|
40
|
-
const fullDestPath = path.join(
|
|
50
|
+
for (const { fsPath, destPath } of tqdm(assets)) {
|
|
51
|
+
const fullDestPath = path.join(bucket, process.env.NEXT_INC_CACHE_R2_PREFIX ?? "incremental-cache", destPath);
|
|
41
52
|
runWrangler(options, ["r2 object put", JSON.stringify(fullDestPath), `--file ${JSON.stringify(fsPath)}`],
|
|
42
53
|
// NOTE: R2 does not support the environment flag and results in the following error:
|
|
43
54
|
// Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'.
|
|
44
55
|
{ target: populateCacheOptions.target, excludeRemoteFlag: true, logging: "error" });
|
|
45
|
-
}
|
|
56
|
+
}
|
|
46
57
|
logger.info(`Successfully populated cache with ${assets.length} assets`);
|
|
47
58
|
break;
|
|
48
59
|
}
|
|
@@ -49,6 +49,10 @@ export function runWrangler(options, args, wranglerOpts = {}) {
|
|
|
49
49
|
], {
|
|
50
50
|
shell: true,
|
|
51
51
|
stdio: wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit",
|
|
52
|
+
env: {
|
|
53
|
+
...process.env,
|
|
54
|
+
...(wranglerOpts.logging === "error" ? { WRANGLER_LOG: "error" } : undefined),
|
|
55
|
+
},
|
|
52
56
|
});
|
|
53
57
|
if (result.status !== 0) {
|
|
54
58
|
logger.error("Wrangler command failed");
|
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.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"opennextjs-cloudflare": "dist/cli/index.js"
|
|
@@ -43,9 +43,10 @@
|
|
|
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.5",
|
|
47
47
|
"enquirer": "^2.4.1",
|
|
48
|
-
"glob": "^11.0.0"
|
|
48
|
+
"glob": "^11.0.0",
|
|
49
|
+
"ts-tqdm": "^0.8.6"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@cloudflare/workers-types": "^4.20250224.0",
|