@@ -3,7 +3,6 @@ import path from "node:path";
33
44import { isBinaryContentType } from "../adapters/binary.js" ;
55import logger from "../logger.js" ;
6- import { openNextResolvePlugin } from "../plugins/resolve.js" ;
76import * as buildHelper from "./helper.js" ;
87
98export function createStaticAssets ( options : buildHelper . BuildOptions ) {
@@ -45,15 +44,19 @@ export function createStaticAssets(options: buildHelper.BuildOptions) {
4544 }
4645}
4746
48- export async function createCacheAssets ( options : buildHelper . BuildOptions ) {
49- const { config } = options ;
50- if ( config . dangerous ?. disableIncrementalCache ) return ;
51-
47+ /**
48+ * Create the cache assets.
49+ *
50+ * @param options Build options.
51+ * @returns Wether tag cache is used.
52+ */
53+ export function createCacheAssets ( options : buildHelper . BuildOptions ) {
5254 logger . info ( `Bundling cache assets...` ) ;
5355
5456 const { appBuildOutputPath, outputDir } = options ;
5557 const packagePath = path . relative ( options . monorepoRoot , appBuildOutputPath ) ;
5658 const buildId = buildHelper . getBuildId ( appBuildOutputPath ) ;
59+ let useTagCache = false ;
5760
5861 // Copy pages to cache folder
5962 const dotNextPath = path . join (
@@ -77,7 +80,7 @@ export async function createCacheAssets(options: buildHelper.BuildOptions) {
7780 ( file . endsWith ( ".html" ) && htmlPages . has ( file ) ) ,
7881 ) ;
7982
80- //merge cache files into a single file
83+ // Merge cache files into a single file
8184 const cacheFilesPath : Record <
8285 string ,
8386 {
@@ -94,18 +97,17 @@ export async function createCacheAssets(options: buildHelper.BuildOptions) {
9497 ( ) => true ,
9598 ( filepath ) => {
9699 const ext = path . extname ( filepath ) ;
97- let newFilePath =
98- ext !== "" ? filepath . replace ( ext , ".cache" ) : `${ filepath } .cache` ;
99- // Handle prefetch cache files for partial prerendering
100- if ( newFilePath . endsWith ( ".prefetch.cache" ) ) {
101- newFilePath = newFilePath . replace ( ".prefetch.cache" , ".cache" ) ;
102- }
103100 switch ( ext ) {
104101 case ".meta" :
105102 case ".html" :
106103 case ".json" :
107104 case ".body" :
108105 case ".rsc" :
106+ const newFilePath =
107+ filepath
108+ . substring ( 0 , filepath . length - ext . length )
109+ . replace ( / \. p r e f e t c h $ / , "" ) + ".cache" ;
110+
109111 cacheFilesPath [ newFilePath ] = {
110112 [ ext . slice ( 1 ) ] : filepath ,
111113 ...cacheFilesPath [ newFilePath ] ,
@@ -146,7 +148,7 @@ export async function createCacheAssets(options: buildHelper.BuildOptions) {
146148 fs . writeFileSync ( cacheFilePath , JSON . stringify ( cacheFileContent ) ) ;
147149 } ) ;
148150
149- if ( ! config . dangerous ?. disableTagCache ) {
151+ if ( ! options . config . dangerous ?. disableTagCache ) {
150152 // Generate dynamodb data
151153 // We need to traverse the cache to find every .meta file
152154 const metaFiles : {
@@ -216,36 +218,10 @@ export async function createCacheAssets(options: buildHelper.BuildOptions) {
216218 ) ;
217219 }
218220
219- // TODO: Extract the code below to a compileTagCacheProvider function
220221 if ( metaFiles . length > 0 ) {
222+ useTagCache = true ;
221223 const providerPath = path . join ( outputDir , "dynamodb-provider" ) ;
222224
223- await buildHelper . esbuildAsync (
224- {
225- external : [ "@aws-sdk/client-dynamodb" ] ,
226- entryPoints : [
227- path . join (
228- options . openNextDistDir ,
229- "adapters" ,
230- "dynamo-provider.js" ,
231- ) ,
232- ] ,
233- outfile : path . join ( providerPath , "index.mjs" ) ,
234- target : [ "node18" ] ,
235- plugins : [
236- openNextResolvePlugin ( {
237- fnName : "initializationFunction" ,
238- overrides : {
239- converter :
240- config . initializationFunction ?. override ?. converter ?? "dummy" ,
241- wrapper : config . initializationFunction ?. override ?. wrapper ,
242- } ,
243- } ) ,
244- ] ,
245- } ,
246- options ,
247- ) ;
248-
249225 //Copy open-next.config.mjs into the bundle
250226 buildHelper . copyOpenNextConfig ( options . buildDir , providerPath ) ;
251227
@@ -259,4 +235,6 @@ export async function createCacheAssets(options: buildHelper.BuildOptions) {
259235
260236 // We need to remove files later because we need the metafiles for dynamodb tags cache
261237 buildHelper . removeFiles ( outputPath , ( file ) => ! file . endsWith ( ".cache" ) ) ;
238+
239+ return { useTagCache } ;
262240}
0 commit comments