Skip to content

Commit

Permalink
move incrementalCacheHandlerPath check as suggested in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Jan 22, 2024
1 parent ac9393d commit 95cf34b
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions packages/next-on-pages/src/buildApplication/buildCacheFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@ export async function buildCacheFiles(
): Promise<void> {
const outputCacheDir = join(nopDistDir, 'cache');

const customCacheHandlerBuilt = await buildCustomIncrementalCacheHandler(
outputCacheDir,
minify,
);
const nextConfig = await getNextConfig();

const incrementalCacheHandlerPath =
nextConfig?.experimental?.incrementalCacheHandlerPath;

if (!customCacheHandlerBuilt) {
if (incrementalCacheHandlerPath) {
await buildCustomIncrementalCacheHandler(
incrementalCacheHandlerPath,
outputCacheDir,
minify,
);
} else {
await buildBuiltInCacheHandlers(templatesDir, outputCacheDir, minify);
}
}

/**
* Builds the file implementing the custom cache handler provided by the user, if one was provided.
* Builds the file implementing the custom cache handler provided by the user.
*
* @param incrementalCacheHandlerPath path to the user defined incremental cache handler
* @param outputCacheDir path to the directory in which to write the file
* @param minify flag indicating wether minification should be applied to the cache files
* @returns true if the file was built, false otherwise (meaning that the user has not provided a custom cache handler)
* @param minify flag indicating wether minification should be applied to the output file
*/
async function buildCustomIncrementalCacheHandler(
incrementalCacheHandlerPath: string,
outputCacheDir: string,
minify: boolean,
): Promise<boolean> {
const nextConfig = await getNextConfig();

const incrementalCacheHandlerPath =
nextConfig?.experimental?.incrementalCacheHandlerPath;

if (!incrementalCacheHandlerPath) {
return false;
}

): Promise<void> {
try {
await build({
entryPoints: [incrementalCacheHandlerPath],
Expand All @@ -61,7 +59,6 @@ async function buildCustomIncrementalCacheHandler(
`Failed to build custom incremental cache handler from the following provided path: ${incrementalCacheHandlerPath}`,
);
}
return true;
}

/**
Expand Down

0 comments on commit 95cf34b

Please sign in to comment.