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

Commit 755a21d

Browse files
authored
feat: upgrade to latest Netlify Build (#57)
1 parent c60cb80 commit 755a21d

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

manifest.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: netlify-plugin-cache-nextjs
2+
inputs:
3+
- name: build_dir_path
4+
description: The directory the build folder is in
5+
default: '.'
6+
- name: custom_build_dir_name
7+
description: The name of the build folder
8+
default: '.next'

src/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ interface NetlifyUtils {
1010

1111
interface NetlifyInputs {
1212
// The TOML config uses camelcase for readability and because it's convention
13-
custom_build_dir_name?: string;
14-
build_dir_path?: string;
13+
custom_build_dir_name: string;
14+
build_dir_path: string;
1515
}
1616

1717
interface NetlifyOpts {
@@ -33,9 +33,9 @@ function generateAbsolutePaths(
3333
buildDirName: string;
3434
} {
3535
/** The name of the build folder. `.next`, unless specially configured. */
36-
const buildDirName = options.inputs.custom_build_dir_name ?? '.next';
36+
const buildDirName = options.inputs.custom_build_dir_name;
3737
/** The directory the build folder is in. Defaults to current directory, although some larger repositories might keep this in a `frontend` folder. */
38-
const buildDirPathFromProject = options.inputs.build_dir_path ?? '.';
38+
const buildDirPathFromProject = options.inputs.build_dir_path;
3939

4040
/** The absolute path to the build folder for Next.js. */
4141
const absoluteBuildDirPath = joinPaths(buildDirPathFromProject, buildDirName, 'cache');
@@ -53,19 +53,18 @@ function generateAbsolutePaths(
5353
}
5454

5555
module.exports = {
56-
name: 'cache-nextjs',
5756
// Restore file/directory cached in previous builds.
5857
// Does not do anything if:
5958
// - the file/directory already exists locally
6059
// - the file/directory has not been cached yet
6160
async onPreBuild({utils, inputs}: ReadonlyDeep<NetlifyOpts>) {
6261
const paths = generateAbsolutePaths({inputs});
63-
const success = await utils.cache.restore(paths.absolute.buildDir, {move: true});
62+
const success = await utils.cache.restore(paths.absolute.buildDir);
6463

6564
if (success) {
6665
console.log(`Restored the cached ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
6766
} else {
68-
console.log(`Unable to restore the cached ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
67+
console.log(`No cache found for the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
6968
}
7069
},
7170
// Cache file/directory for future builds.
@@ -78,14 +77,13 @@ module.exports = {
7877
const paths = generateAbsolutePaths({inputs});
7978

8079
const success = await utils.cache.save(paths.absolute.buildDir, {
81-
digests: [paths.absolute.manifest],
82-
move: true
80+
digests: [paths.absolute.manifest]
8381
});
8482

8583
if (success) {
8684
console.log(`Cached the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
8785
} else {
88-
console.error(`An error occurred and the ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\` could not be cached`);
86+
console.log(`No ${paths.buildDirName} folder at the location \`${paths.absolute.buildDir}\``);
8987
}
9088
}
9189
};

0 commit comments

Comments
 (0)