diff --git a/packages/cloudflare/src/cli/build/build.ts b/packages/cloudflare/src/cli/build/build.ts index b9270f79..35d4522e 100644 --- a/packages/cloudflare/src/cli/build/build.ts +++ b/packages/cloudflare/src/cli/build/build.ts @@ -42,7 +42,6 @@ export async function build(projectOpts: ProjectOptions): Promise { const { config, buildDir } = await compileOpenNextConfig(baseDir); ensureCloudflareConfig(config); - // Initialize options const options = buildHelper.normalizeOptions(config, openNextDistDir, buildDir); logger.setLevel(options.debug ? "debug" : "info"); diff --git a/packages/cloudflare/src/cli/build/utils/extract-cache-assets-manifest.ts b/packages/cloudflare/src/cli/build/utils/extract-cache-assets-manifest.ts index a1a79f37..6d51c729 100644 --- a/packages/cloudflare/src/cli/build/utils/extract-cache-assets-manifest.ts +++ b/packages/cloudflare/src/cli/build/utils/extract-cache-assets-manifest.ts @@ -2,17 +2,12 @@ import { readFileSync } from "node:fs"; import path from "node:path"; import type { BuildOptions } from "@opennextjs/aws/build/helper.js"; -import { getBuildId } from "@opennextjs/aws/build/helper.js"; -import { globSync } from "glob"; - -type CacheInfo = { - type: string; - meta?: { - headers?: { - "x-next-cache-tags"?: string; - }; - }; -}; + +type RawManifest = { + tag: { S: string }; + path: { S: string }; + revalidatedAt: { N: string }; +}[]; export type CacheAssetsManifest = { tags: { [tag: string]: string[] }; @@ -24,25 +19,24 @@ export type CacheAssetsManifest = { * * The mapping creates an index of each tags pointing to its paths, and each path pointing to its tags. */ -export function extractCacheAssetsManifest(buildOpts: BuildOptions) { - const cachePath = path.join(buildOpts.outputDir, "cache"); - const buildId = getBuildId(buildOpts); - - const manifest = globSync(path.join(cachePath, buildId, "**/*.cache")).reduce( - (acc, p) => { - const { meta } = JSON.parse(readFileSync(p, "utf-8")) as CacheInfo; - const tags = meta?.headers?.["x-next-cache-tags"]?.split(",")?.map((tag) => `${buildId}/${tag}`) ?? []; - - const routePath = path.relative(cachePath, p).replace(/\.cache$/, ""); +export function extractCacheAssetsManifest(options: BuildOptions) { + // TODO: Expose the function for getting this data as an adapter-agnostic utility in AWS. + const rawManifest: RawManifest = JSON.parse( + readFileSync(path.join(options.outputDir, "dynamodb-provider", "dynamodb-cache.json"), "utf-8") + ); - acc.paths[routePath] = tags; + const manifest = rawManifest.reduce( + (acc, { tag: { S: tag }, path: { S: path } }) => { + if (!acc.paths[path]) { + acc.paths[path] = [tag]; + } else { + acc.paths[path].push(tag); + } - for (const tag of tags) { - if (!acc.tags[tag]) { - acc.tags[tag] = [routePath]; - } else { - acc.tags[tag].push(routePath); - } + if (!acc.tags[tag]) { + acc.tags[tag] = [path]; + } else { + acc.tags[tag].push(path); } return acc;