Skip to content

Commit

Permalink
Switch to make-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 12, 2017
1 parent 84fd1a5 commit 50cc993
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const makeDir = require('make-dir');
const md5Hex = require('md5-hex');
const writeFileAtomic = require('write-file-atomic');
const packageHash = require('package-hash');
Expand Down Expand Up @@ -37,7 +37,7 @@ function wrap(opts) {
function transform(input, metadata, hash) {
if (!created) {
if (!cacheDirCreated && !disableCache) {
mkdirp.sync(cacheDir);
makeDir.sync(cacheDir);
}

if (!transformFn) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"hash"
],
"dependencies": {
"make-dir": "^1.0.0",
"md5-hex": "^2.0.0",
"mkdirp": "^0.5.1",
"package-hash": "^2.0.0",
"write-file-atomic": "^2.0.0"
},
Expand Down
38 changes: 19 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function withMockedFs(fsConfig) {
const fs = mockfs.fs(fsConfig || {});
fs['@global'] = true;

const mkdirp = proxyquire('mkdirp', {fs});
mkdirp.sync = sinon.spy(mkdirp.sync);
const makeDir = proxyquire('make-dir', {fs});
makeDir.sync = sinon.spy(makeDir.sync);

const packageHash = {
sync() {
Expand All @@ -26,12 +26,12 @@ function withMockedFs(fsConfig) {

const cachingTransform = proxyquire('.', {
fs,
mkdirp,
'make-dir': makeDir,
'package-hash': packageHash
});

cachingTransform.fs = fs;
cachingTransform.mkdirp = mkdirp;
cachingTransform.makeDir = makeDir;

return cachingTransform;
}
Expand All @@ -47,7 +47,7 @@ function wrap(opts, fsConfig) {
const cachingTransform = withMockedFs(fsConfig);
const wrapped = cachingTransform(opts);
wrapped.fs = cachingTransform.fs;
wrapped.mkdirp = cachingTransform.mkdirp;
wrapped.makeDir = cachingTransform.makeDir;

return wrapped;
}
Expand Down Expand Up @@ -107,37 +107,37 @@ test('able to specify alternate extension', t => {
t.is(transform.fs.readFileSync(filename, 'utf8'), 'foo bar');
});

test('mkdirp is only called once', t => {
test('makeDir is only called once', t => {
const transform = wrap(
{
transform: append('bar'),
cacheDir: '/someDir'
}
);

t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
t.is(transform('foo'), 'foo bar');
t.is(transform.mkdirp.sync.callCount, 1);
t.is(transform.makeDir.sync.callCount, 1);
t.is(transform('bar'), 'bar bar');
t.is(transform.mkdirp.sync.callCount, 1);
t.is(transform.makeDir.sync.callCount, 1);
});

test('mkdirp is only called once, with factory', t => {
test('makeDir is only called once, with factory', t => {
const transform = wrap(
{
factory: () => append('bar'),
cacheDir: '/someDir'
}
);

t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
t.is(transform('foo'), 'foo bar');
t.is(transform.mkdirp.sync.callCount, 1);
t.is(transform.makeDir.sync.callCount, 1);
t.is(transform('bar'), 'bar bar');
t.is(transform.mkdirp.sync.callCount, 1);
t.is(transform.makeDir.sync.callCount, 1);
});

test('mkdirp is never called if `createCacheDir === false`', t => {
test('makeDir is never called if `createCacheDir === false`', t => {
const transform = wrap(
{
transform: append('bar'),
Expand All @@ -149,12 +149,12 @@ test('mkdirp is never called if `createCacheDir === false`', t => {
}
);

t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
t.is(transform('foo'), 'foo bar');
t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
});

test('mkdirp is never called if `createCacheDir === false`, with factory', t => {
test('makeDir is never called if `createCacheDir === false`, with factory', t => {
const transform = wrap(
{
factory: () => append('bar'),
Expand All @@ -166,9 +166,9 @@ test('mkdirp is never called if `createCacheDir === false`, with factory', t =>
}
);

t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
t.is(transform('foo'), 'foo bar');
t.is(transform.mkdirp.sync.callCount, 0);
t.is(transform.makeDir.sync.callCount, 0);
});

test('additional opts are passed to transform', t => {
Expand Down

0 comments on commit 50cc993

Please sign in to comment.