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

Commit 16e151d

Browse files
committed
feat: add logging during lifecycle events
Signed-off-by: Jonah Snider <[email protected]>
1 parent 537c061 commit 16e151d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ interface NetlifyOpts {
1616
constants: NetlifyConstants;
1717
}
1818

19+
const buildCachePath = '.next';
20+
const manifestPath = joinPaths(buildCachePath, 'build-manifest.json');
21+
1922
module.exports = {
2023
name: 'cache-nextjs',
2124
// Restore file/directory cached in previous builds.
2225
// Does not do anything if:
2326
// - the file/directory already exists locally
2427
// - the file/directory has not been cached yet
2528
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)]
2833
});
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+
}
2940
},
3041
// Cache file/directory for future builds.
3142
// Does not do anything if:
@@ -34,8 +45,16 @@ module.exports = {
3445
// If this is a directory, this includes children's contents
3546
// Note that this will cache after the build, even if it fails, which fcould be unwanted behavior
3647
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)]
3952
});
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+
}
4059
}
4160
};

0 commit comments

Comments
 (0)