From 536862e1efb48806d73cc3fc4d60fb3dd1454c1f Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Sun, 10 Dec 2017 19:18:14 -0500 Subject: [PATCH] Remove out of date cache before writing to it anew --- index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 4e79bd1f..8e2983d3 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,8 @@ var path = require('path'); var level = require('level'); var lodash = require('lodash'); -var mkdirp = require('mkdirp'); +var _mkdirp = require('mkdirp'); +var _rimraf = require('rimraf'); var Promise = require('bluebird'); var nodeObjectHash = require('node-object-hash'); @@ -95,6 +96,10 @@ function requestHash(request) { return crypto.createHash('sha1').update(request).digest().hexSlice(); } +var mkdirp = Promise.promisify(_mkdirp, {context: _mkdirp}); +mkdirp.sync = _mkdirp.sync.bind(_mkdirp); +var rimraf = Promise.promisify(_rimraf); +rimraf.sync = _rimraf.sync.bind(_rimraf); var fsReadFile = Promise.promisify(fs.readFile, {context: fs}); var fsWriteFile = Promise.promisify(fs.writeFile, {context: fs}); @@ -713,7 +718,8 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) { resolverCache = {normal: {},loader: {},context: {}}; fileTimestamps = {}; contextTimestamps = {}; - return; + + return rimraf(cacheDirPath); } if (Object.keys(moduleCache).length) {return Promise.resolve();} @@ -2055,8 +2061,13 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) { }); Promise.all([ - fsWriteFile(path.join(cacheDirPath, 'stamp'), currentStamp, 'utf8'), - fsWriteFile(path.join(cacheDirPath, 'version'), hardSourceVersion, 'utf8'), + mkdirp(cacheDirPath) + .then(function() { + return Promise.all([ + fsWriteFile(path.join(cacheDirPath, 'stamp'), currentStamp, 'utf8'), + fsWriteFile(path.join(cacheDirPath, 'version'), hardSourceVersion, 'utf8'), + ]); + }), moduleResolveCacheSerializer.write(moduleResolveOps), assetCacheSerializer.write(assetOps), moduleCacheSerializer.write(moduleOps),