1- import { existsSync } from "node:fs" ;
1+ import { cpSync , existsSync , mkdirSync } from "node:fs" ;
22import path from "node:path" ;
33
44import type { BuildOptions } from "@opennextjs/aws/build/helper.js" ;
@@ -15,6 +15,10 @@ import { tqdm } from "ts-tqdm";
1515import { unstable_readConfig } from "wrangler" ;
1616
1717import { NAME as R2_CACHE_NAME } from "../../api/overrides/incremental-cache/r2-incremental-cache.js" ;
18+ import {
19+ CACHE_DIR as STATIC_ASSETS_CACHE_DIR ,
20+ NAME as STATIC_ASSETS_CACHE_NAME ,
21+ } from "../../api/overrides/incremental-cache/static-assets-incremental-cache.js" ;
1822import { NAME as D1_TAG_NAME } from "../../api/overrides/tag-cache/d1-next-tag-cache.js" ;
1923import type { WranglerTarget } from "../utils/run-wrangler.js" ;
2024import { runWrangler } from "../utils/run-wrangler.js" ;
@@ -100,6 +104,18 @@ export async function populateCache(
100104 logger . info ( `Successfully populated cache with ${ assets . length } assets` ) ;
101105 break ;
102106 }
107+ case STATIC_ASSETS_CACHE_NAME : {
108+ logger . info ( "\nPopulating Workers static assets..." ) ;
109+
110+ const assets = getCacheAssetPaths ( options ) ;
111+ for ( const { fsPath, destPath } of tqdm ( assets ) ) {
112+ const outputDestPath = path . join ( options . outputDir , "assets" , STATIC_ASSETS_CACHE_DIR , destPath ) ;
113+ mkdirSync ( path . dirname ( outputDestPath ) , { recursive : true } ) ;
114+ cpSync ( fsPath , outputDestPath ) ;
115+ }
116+ logger . info ( `Successfully populated static assets` ) ;
117+ break ;
118+ }
103119 default :
104120 logger . info ( "Incremental cache does not need populating" ) ;
105121 }
0 commit comments