Skip to content

Commit

Permalink
fix: moved cache delete into finally
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 19, 2024
1 parent 90fa704 commit 469eecc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/packem/src/create-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ const removeOldCacheFolders = async (cachePath: string | undefined, logger: Pail

logger.info({
message: "Removing " + dirent.name + " file cache, the cache key is not used anymore.",
prefix: "file-cache"
})
prefix: "file-cache",
});
}
}
}
Expand Down Expand Up @@ -579,6 +579,10 @@ const createBundler = async (
}
}

const cachePath = findCacheDirSync(packageJson.name as string, {
cwd: rootDirectory,
});

try {
let packemConfigFilePath = configPath ?? "";

Expand Down Expand Up @@ -636,10 +640,6 @@ const createBundler = async (
}),
);

const cachePath = findCacheDirSync(packageJson.name as string, {
cwd: rootDirectory,
});

for await (const config of arrayify(buildConfig)) {
const cacheKey = packageJsonCacheKey + getHash(JSON.stringify(config));
const fileCache = new FileCache(rootDirectory, cachePath, cacheKey, logger);
Expand Down Expand Up @@ -692,9 +692,6 @@ const createBundler = async (

logger.raw("\n⚡️ Build run in " + getDuration());
}

await removeOldCacheFolders(cachePath, logger);

// Restore all wrapped console methods
logger.restoreAll();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -704,6 +701,8 @@ const createBundler = async (
enhanceRollupError(error);

throw error;
} finally {
await removeOldCacheFolders(cachePath, logger);
}
};

Expand Down

0 comments on commit 469eecc

Please sign in to comment.