Skip to content

Commit

Permalink
fix: use find-cache-dir for default cache directory (#237) (#355)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mzgoddard committed May 28, 2018
1 parent 58d1dfa commit 0212475
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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]',
);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/envHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0212475

Please sign in to comment.