From 46a0486ed092755063d3b291d66830cb5c72bb6c Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 22 Jul 2018 20:42:59 +0200 Subject: [PATCH] Read file before creating directory --- src/cache.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cache.js b/src/cache.js index db668060..24b44143 100644 --- a/src/cache.js +++ b/src/cache.js @@ -80,6 +80,14 @@ const filename = function(source, identifier, options) { const handleCache = async function(directory, params) { const { source, options = {}, cacheIdentifier, cacheDirectory } = params; + const file = path.join(directory, filename(source, cacheIdentifier, options)); + + try { + // No errors mean that the file was previously cached + // we just need to return it + return await read(file); + } catch (err) {} + const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); @@ -94,14 +102,6 @@ const handleCache = async function(directory, params) { throw err; } - const file = path.join(directory, filename(source, cacheIdentifier, options)); - - try { - // No errors mean that the file was previously cached - // we just need to return it - return await read(file); - } catch (err) {} - // Otherwise just transform the file // return it to the user asap and write it in cache const result = await transform(source, options);