Skip to content
This repository was archived by the owner on Jan 2, 2022. It is now read-only.

Commit cf033b1

Browse files
committed
fix: use Netlify build dir constant
Signed-off-by: Jonah Snider <[email protected]>
1 parent 7dd0754 commit cf033b1

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ interface NetlifyUtils {
77
};
88
}
99

10+
interface NetlifyConstants {
11+
BUILD_DIR: string
12+
}
13+
14+
interface NetlifyOpts {
15+
utils: NetlifyUtils,
16+
constants: NetlifyConstants
17+
}
18+
1019
module.exports = {
1120
name: 'cache-nextjs',
1221
// Restore file/directory cached in previous builds.
1322
// Does not do anything if:
1423
// - the file/directory already exists locally
1524
// - 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')]
1928
});
2029
},
2130
// Cache file/directory for future builds.
@@ -24,9 +33,9 @@ module.exports = {
2433
// - the file/directory is already cached and its contents has not changed
2534
// If this is a directory, this includes children's contents
2635
// 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')]
3039
});
3140
}
3241
};

0 commit comments

Comments
 (0)