@@ -16,16 +16,27 @@ interface NetlifyOpts {
16
16
constants : NetlifyConstants ;
17
17
}
18
18
19
+ const buildCachePath = '.next' ;
20
+ const manifestPath = joinPaths ( buildCachePath , 'build-manifest.json' ) ;
21
+
19
22
module . exports = {
20
23
name : 'cache-nextjs' ,
21
24
// Restore file/directory cached in previous builds.
22
25
// Does not do anything if:
23
26
// - the file/directory already exists locally
24
27
// - the file/directory has not been cached yet
25
28
async onPreBuild ( { utils, constants} : NetlifyOpts ) {
26
- await utils . cache . restore ( joinPaths ( constants . BUILD_DIR , '.next' ) , {
27
- digest : [ joinPaths ( constants . BUILD_DIR , '.next' , 'build-manifest.json' ) ]
29
+ const directory = joinPaths ( constants . BUILD_DIR , buildCachePath ) ;
30
+
31
+ const success = await utils . cache . restore ( directory , {
32
+ digest : [ joinPaths ( constants . BUILD_DIR , manifestPath ) ]
28
33
} ) ;
34
+
35
+ if ( success ) {
36
+ console . log ( `Restored the cached .next folder at the location \`${ directory } \`` ) ;
37
+ } else {
38
+ console . log ( `Unable to restore the cached .next folder at the location \`${ directory } \`` ) ;
39
+ }
29
40
} ,
30
41
// Cache file/directory for future builds.
31
42
// Does not do anything if:
@@ -34,8 +45,16 @@ module.exports = {
34
45
// If this is a directory, this includes children's contents
35
46
// Note that this will cache after the build, even if it fails, which fcould be unwanted behavior
36
47
async onPostBuild ( { utils, constants} : NetlifyOpts ) {
37
- await utils . cache . save ( joinPaths ( constants . BUILD_DIR , '.next' ) , {
38
- digest : [ joinPaths ( constants . BUILD_DIR , '.next' , 'build-manifest.json' ) ]
48
+ const directory = joinPaths ( constants . BUILD_DIR , buildCachePath ) ;
49
+
50
+ const success = await utils . cache . save ( directory , {
51
+ digest : [ joinPaths ( constants . BUILD_DIR , manifestPath ) ]
39
52
} ) ;
53
+
54
+ if ( success ) {
55
+ console . log ( `Cached the .next folder at the location \`${ directory } \`` ) ;
56
+ } else {
57
+ console . error ( `An error occurred and the .next folder at the location \`${ directory } \` could not be cached` ) ;
58
+ }
40
59
}
41
60
} ;
0 commit comments