@@ -7,15 +7,24 @@ interface NetlifyUtils {
7
7
} ;
8
8
}
9
9
10
+ interface NetlifyConstants {
11
+ BUILD_DIR : string
12
+ }
13
+
14
+ interface NetlifyOpts {
15
+ utils : NetlifyUtils ,
16
+ constants : NetlifyConstants
17
+ }
18
+
10
19
module . exports = {
11
20
name : 'cache-nextjs' ,
12
21
// Restore file/directory cached in previous builds.
13
22
// Does not do anything if:
14
23
// - the file/directory already exists locally
15
24
// - the file/directory has not been cached yet
16
- async onPreBuild ( { utils} : { utils : NetlifyUtils } ) {
17
- await utils . cache . restore ( joinPaths ( __dirname , '.next' ) , {
18
- digest : [ joinPaths ( __dirname , '.next' , 'build-manifest.json' ) ]
25
+ 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' ) ]
19
28
} ) ;
20
29
} ,
21
30
// Cache file/directory for future builds.
@@ -24,9 +33,9 @@ module.exports = {
24
33
// - the file/directory is already cached and its contents has not changed
25
34
// If this is a directory, this includes children's contents
26
35
// Note that this will cache after the build, even if it fails, which fcould be unwanted behavior
27
- async onPostBuild ( { utils} : { utils : NetlifyUtils } ) {
28
- await utils . cache . save ( joinPaths ( __dirname , '.next' ) , {
29
- digest : [ joinPaths ( __dirname , '.next' , 'build-manifest.json' ) ]
36
+ 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' ) ]
30
39
} ) ;
31
40
}
32
41
} ;
0 commit comments