From 02124754fbb5f3312ee06cf86cb0cfc8460c7af7 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Mon, 28 May 2018 09:18:51 -0400 Subject: [PATCH] fix: use find-cache-dir for default cache directory (#237) (#355) * fix: use find-cache-dir for default cache directory (#237) * fix: find root environment hash directory with pkg-dir * fixup! fix: use find-cache-dir for default cache directory (#237) * fixup! fix: find root environment hash directory with pkg-dir --- index.js | 9 ++++++--- lib/envHash.js | 4 +++- package.json | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f7fe003d..e1937cf1 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const lodash = require('lodash'); const _mkdirp = require('mkdirp'); const _rimraf = require('rimraf'); const nodeObjectHash = require('node-object-hash'); +const findCacheDir = require('find-cache-dir'); const envHash = require('./lib/envHash'); const defaultConfigHash = require('./lib/defaultConfigHash'); @@ -149,9 +150,11 @@ class HardSourceWebpackPlugin { if (!options.cacheDirectory) { options.cacheDirectory = path.resolve( - process.cwd(), - compiler.options.context, - 'node_modules/.cache/hard-source/[confighash]', + findCacheDir({ + name: 'hard-source', + cwd: compiler.options.context || process.cwd(), + }), + '[confighash]', ); } diff --git a/lib/envHash.js b/lib/envHash.js index 8327da1c..20efc248 100644 --- a/lib/envHash.js +++ b/lib/envHash.js @@ -9,6 +9,8 @@ const crypto = require('crypto'); const fs = require('fs'); const path = require('path'); +const pkgDir = require('pkg-dir'); + const promisify = require('./util/promisify'); const readFile = promisify(fs.readFile); @@ -73,7 +75,7 @@ const inputs = async ({ files, directories, root = process.cwd() } = {}) => { module.exports = options => { options = options || {}; - const root = options.root || process.cwd(); + const root = options.root || pkgDir.sync(process.cwd()); let files = options.files; let directories = options.directories; diff --git a/package.json b/package.json index ef520171..1cc3c21d 100644 --- a/package.json +++ b/package.json @@ -63,10 +63,12 @@ }, "dependencies": { "chalk": "^2.4.1", + "find-cache-dir": "^1.0.0", "jsonlint": "^1.6.3", "lodash": "^4.15.0", "mkdirp": "^0.5.1", "node-object-hash": "^1.2.0", + "pkg-dir": "^2.0.0", "rimraf": "^2.6.2", "tapable": "^1.0.0-beta.5", "webpack-sources": "^1.0.1",