From c183d330239c90a797d4d1c6fed5a40c483794b9 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Fri, 25 Sep 2020 21:00:03 +0200 Subject: [PATCH] stop roll() from failing if the new cache folder is not created (#243) * stop roll() from failing if the new cache has no files Today I stumbled upon an error where it would fail when the cache folder was not present ```(typescript) Error: ENOENT: no such file or directory, rename 'REDACTED\node_modules\.cache\rollup-plugin-typescript2/rpt2_759e2fd8d3f20c1a0805faf5404af6bea36632fd/code/cache_' -> 'REDACTED\node_modules\.cache\rollup-plugin-typescript2/rpt2_759e2fd8d3f20c1a0805faf5404af6bea36632fd/code/cache'``` This PR fixes it by checking its existence before trying to rename it * use existsSync instead of fs.existsSync * use renameSync instead of fs.renameSync --- src/rollingcache.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rollingcache.ts b/src/rollingcache.ts index dee19d0..8553438 100644 --- a/src/rollingcache.ts +++ b/src/rollingcache.ts @@ -98,6 +98,8 @@ export class RollingCache implements ICache this.rolled = true; removeSync(this.oldCacheRoot); - renameSync(this.newCacheRoot, this.oldCacheRoot); + if (existsSync(this.newCacheRoot)) { + renameSync(this.newCacheRoot, this.oldCacheRoot); + } } }