Skip to content

Commit 8034a33

Browse files
committed
re-use the manifest from the createcacheassets function
1 parent b28b327 commit 8034a33

File tree

4 files changed

+2547
-5029
lines changed

4 files changed

+2547
-5029
lines changed

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"dependencies": {
7474
"@ast-grep/napi": "^0.34.1",
7575
"@dotenvx/dotenvx": "catalog:",
76-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@733",
76+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@748",
7777
"enquirer": "^2.4.1",
7878
"glob": "catalog:",
7979
"yaml": "^2.7.0"

packages/cloudflare/src/cli/build/build.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ export async function build(projectOpts: ProjectOptions): Promise<void> {
8787
createStaticAssets(options);
8888

8989
if (config.dangerous?.disableIncrementalCache !== true) {
90-
createCacheAssets(options);
90+
const { metaFiles } = createCacheAssets(options);
9191
copyCacheAssets(options);
92-
compileCacheAssetsManifestSqlFile(options);
92+
93+
if (config.dangerous?.disableTagCache !== true) {
94+
compileCacheAssetsManifestSqlFile(options, metaFiles);
95+
}
9396
}
9497

9598
await createServerBundle(options);
Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
1+
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
22
import path from "node:path";
33

44
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
5-
6-
type RawManifest = {
7-
tag: { S: string };
8-
path: { S: string };
9-
revalidatedAt: { N: string };
10-
}[];
5+
import type { TagCacheMetaFile } from "@opennextjs/aws/types/open-next.js";
116

127
/**
138
* Generates SQL statements that can be used to initialise the cache assets manifest in an SQL data store.
149
*/
15-
export function compileCacheAssetsManifestSqlFile(options: BuildOptions) {
16-
// TODO: Expose the function for getting this data as an adapter-agnostic utility in AWS.
17-
const rawManifestPath = path.join(options.outputDir, "dynamodb-provider/dynamodb-cache.json");
10+
export function compileCacheAssetsManifestSqlFile(options: BuildOptions, metaFiles: TagCacheMetaFile[]) {
1811
const outputPath = path.join(options.outputDir, "cloudflare/cache-assets-manifest.sql");
1912

2013
const tagsTable = process.env.NEXT_CACHE_D1_TAGS_TABLE || "tags";
@@ -27,18 +20,12 @@ export function compileCacheAssetsManifestSqlFile(options: BuildOptions) {
2720
CREATE TABLE IF NOT EXISTS ${JSON.stringify(revalidationsTable)} (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);\n`
2821
);
2922

30-
if (existsSync(rawManifestPath)) {
31-
const rawManifest: RawManifest = JSON.parse(readFileSync(rawManifestPath, "utf-8"));
23+
const values = metaFiles.map(({ tag, path }) => `(${JSON.stringify(tag.S)}, ${JSON.stringify(path.S)})`);
3224

33-
const values = rawManifest.map(
34-
({ tag, path }) => `(${JSON.stringify(tag.S)}, ${JSON.stringify(path.S)})`
25+
if (values.length) {
26+
appendFileSync(
27+
outputPath,
28+
`INSERT INTO ${JSON.stringify(tagsTable)} (tag, path) VALUES ${values.join(", ")};`
3529
);
36-
37-
if (values.length) {
38-
appendFileSync(
39-
outputPath,
40-
`INSERT INTO ${JSON.stringify(tagsTable)} (tag, path) VALUES ${values.join(", ")};`
41-
);
42-
}
4330
}
4431
}

0 commit comments

Comments
 (0)