Skip to content

Commit

Permalink
stop roll() from failing if the new cache folder is not created (#243)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xaviergonz committed Sep 25, 2020
1 parent dcf59ac commit c183d33
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rollingcache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export class RollingCache<DataType> implements ICache<DataType>

this.rolled = true;
removeSync(this.oldCacheRoot);
renameSync(this.newCacheRoot, this.oldCacheRoot);
if (existsSync(this.newCacheRoot)) {
renameSync(this.newCacheRoot, this.oldCacheRoot);
}
}
}

0 comments on commit c183d33

Please sign in to comment.