Socket
Socket
Sign inDemoInstall

fs-jetpack

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-jetpack - npm Package Compare versions

Comparing version 0.13.3 to 1.0.0

36

benchmark/copy.js

@@ -5,11 +5,11 @@ /* eslint no-console: 0 */

var utils = require('./utils');
const utils = require('./utils');
var testDir = utils.prepareJetpackTestDir();
var toCopyDir = testDir.dir('to-copy');
var timer;
var jetpackTime;
var nativeTime;
const testDir = utils.prepareJetpackTestDir();
const toCopyDir = testDir.dir('to-copy');
let timer;
let jetpackTime;
let nativeTime;
var test = function (testConfig) {
const test = (testConfig) => {
console.log('');

@@ -19,15 +19,15 @@

.then(utils.waitAWhile)
.then(function () {
.then(() => {
timer = utils.startTimer('jetpack.copyAsync()');
return toCopyDir.copyAsync('.', testDir.path('copied-jetpack'));
})
.then(function () {
.then(() => {
jetpackTime = timer();
return utils.waitAWhile();
})
.then(function () {
.then(() => {
timer = utils.startTimer('Native cp -R');
return utils.exec('cp -R ' + toCopyDir.path() + ' ' + testDir.path('copied-native'));
return utils.exec(`cp -R ${toCopyDir.path()} ${testDir.path('copied-native')}`);
})
.then(function () {
.then(() => {
nativeTime = timer();

@@ -37,3 +37,3 @@ utils.showDifferenceInfo(jetpackTime, nativeTime);

})
.catch(function (err) {
.catch((err) => {
console.log(err);

@@ -43,14 +43,14 @@ });

var testConfigs = [
const testConfigs = [
{
files: 10000,
size: 1000
size: 1000,
},
{
files: 50,
size: 1000 * 1000 * 10
}
size: 1000 * 1000 * 10,
},
];
var runNext = function () {
const runNext = () => {
if (testConfigs.length > 0) {

@@ -57,0 +57,0 @@ test(testConfigs.pop()).then(runNext);

@@ -5,12 +5,12 @@ /* eslint no-console: 0 */

var utils = require('./utils');
const utils = require('./utils');
var testDir = utils.prepareJetpackTestDir();
var timer;
var jetpackTime;
var nativeTime;
const testDir = utils.prepareJetpackTestDir();
let timer;
let jetpackTime;
let nativeTime;
var test = function (testConfig) {
var dirJet = testDir.dir('to-be-removed-by-jetpack');
var dirNative = testDir.dir('to-be-removed-by-native');
const test = (testConfig) => {
const dirJet = testDir.dir('to-be-removed-by-jetpack');
const dirNative = testDir.dir('to-be-removed-by-native');

@@ -20,19 +20,19 @@ console.log('');

return utils.prepareFiles(dirJet, testConfig)
.then(function () {
.then(() => {
return utils.prepareFiles(dirNative, testConfig);
})
.then(utils.waitAWhile)
.then(function () {
.then(() => {
timer = utils.startTimer('jetpack.removeAsync()');
return dirJet.removeAsync();
})
.then(function () {
.then(() => {
jetpackTime = timer();
return utils.waitAWhile();
})
.then(function () {
.then(() => {
timer = utils.startTimer('Native rm -rf');
return utils.exec('rm -rf ' + dirNative.path());
return utils.exec(`rm -rf ${dirNative.path()}`);
})
.then(function () {
.then(() => {
nativeTime = timer();

@@ -42,3 +42,3 @@ utils.showDifferenceInfo(jetpackTime, nativeTime);

})
.catch(function (err) {
.catch((err) => {
console.log(err);

@@ -48,10 +48,10 @@ });

var testConfigs = [
const testConfigs = [
{
files: 10000,
size: 1000
}
size: 1000,
},
];
var runNext = function () {
const runNext = () => {
if (testConfigs.length > 0) {

@@ -58,0 +58,0 @@ test(testConfigs.pop()).then(runNext);

/* eslint no-console:0 */
'use strct';
'use strict';
var os = require('os');
var childProcess = require('child_process');
var promisify = require('../lib/utils/promisify');
var jetpack = require('..');
const os = require('os');
const childProcess = require('child_process');
const prettyBytes = require('pretty-bytes');
const promisify = require('../lib/utils/promisify');
const jetpack = require('..');
var humanReadableFileSize = function (bytes, si) {
var units;
var u;
var b = bytes;
var thresh = si ? 1000 : 1024;
if (Math.abs(b) < thresh) {
return b + ' B';
}
units = si
? ['kB', 'MB', 'GB', 'TB']
: ['KiB', 'MiB', 'GiB', 'TiB'];
u = -1;
do {
b /= thresh;
++u;
} while (Math.abs(b) >= thresh && u < units.length - 1);
return b.toFixed(1) + ' ' + units[u];
const testDirPath = () => {
return `${os.tmpdir()}/jetpack-benchmark`;
};
var testDirPath = function () {
return os.tmpdir() + '/jetpack-benchmark';
};
var prepareJetpackTestDir = function () {
const prepareJetpackTestDir = () => {
return jetpack.dir(testDirPath(), { empty: true });
};
var prepareFiles = function (jetpackDir, creationConfig) {
return new Promise(function (resolve, reject) {
var count = 0;
var content = new Buffer(creationConfig.size);
const prepareFiles = (jetpackDir, creationConfig) => {
return new Promise((resolve, reject) => {
let count = 0;
const content = new Buffer(creationConfig.size);
var makeOneFile = function () {
jetpackDir.fileAsync(count + '.txt', { content: content })
.then(function () {
const makeOneFile = () => {
jetpackDir.fileAsync(`${count}.txt`, { content })
.then(() => {
count += 1;

@@ -54,4 +36,3 @@ if (count < creationConfig.files) {

console.log('Preparing ' + creationConfig.files + ' test files (' +
humanReadableFileSize(creationConfig.size, true) + ' each)...');
console.log(`Preparing ${creationConfig.files} test files (${prettyBytes(creationConfig.size)} each)...`);
makeOneFile();

@@ -61,14 +42,17 @@ });

var startTimer = function (startMessage) {
var start = Date.now();
process.stdout.write(startMessage + ' ... ');
return function stop() {
var time = Date.now() - start;
console.log(time + 'ms');
const startTimer = (startMessage) => {
const start = Date.now();
process.stdout.write(`${startMessage} ... `);
const stop = () => {
const time = Date.now() - start;
console.log(`${time}ms`);
return time;
};
return stop;
};
var waitAWhile = function () {
return new Promise(function (resolve) {
const waitAWhile = () => {
return new Promise((resolve) => {
console.log('Waiting 5s to allow hardware buffers be emptied...');

@@ -79,10 +63,8 @@ setTimeout(resolve, 5000);

var promisedExec = promisify(childProcess.exec);
var showDifferenceInfo = function (jetpackTime, nativeTime) {
var perc = Math.round(jetpackTime / nativeTime * 100) - 100;
console.log('Jetpack is ' + perc + '% slower than native');
const showDifferenceInfo = (jetpackTime, nativeTime) => {
const perc = Math.round(jetpackTime / nativeTime * 100) - 100;
console.log(`Jetpack is ${perc}% slower than native`);
};
var cleanAfterTest = function () {
const cleanAfterTest = () => {
console.log('Cleaning up after test...');

@@ -93,9 +75,9 @@ return jetpack.removeAsync(testDirPath());

module.exports = {
prepareJetpackTestDir: prepareJetpackTestDir,
prepareFiles: prepareFiles,
startTimer: startTimer,
waitAWhile: waitAWhile,
exec: promisedExec,
showDifferenceInfo: showDifferenceInfo,
cleanAfterTest: cleanAfterTest
prepareJetpackTestDir,
prepareFiles,
startTimer,
waitAWhile,
exec: promisify(childProcess.exec),
showDifferenceInfo,
cleanAfterTest,
};

@@ -0,1 +1,5 @@

# 1.0.0 (2017-05-14)
- API declared stable. From now on braking changes will be minimized and whenever possible preceded by deprecation periods.
- Codebase updated to ES6
# 0.13.3 (2017-03-25)

@@ -2,0 +6,0 @@ - `removeAsync()` retries deletion attempts for errors like `EBUSY`.

@@ -1,9 +0,9 @@

# Cool things about fs-jetpack in examples
# Cool things about fs-jetpack
**Note:** All examples here are synchronous for simplicity. You can easily make them asynchronous just by adding 'Async' to method names and expecting promise to be returned instead of ready value.
## Every jetpack instance has its internal CWD
You can create many jetpack objects with different internal working directories (which are independent of `process.cwd()`) and work on directories in a little more object-oriented manner.
## Every fs-jetpack instance has its internal CWD
You can create many fs-jetpack objects with different internal working directories (which are independent of `process.cwd()`) and work on directories in a little more object-oriented manner.
```js
var src = jetpack.cwd('path/to/source');
var dest = jetpack.cwd('path/to/destination');
const src = jetpack.cwd('path/to/source');
const dest = jetpack.cwd('path/to/destination');
src.copy('foo.txt', dest.path('bar.txt'));

@@ -15,3 +15,3 @@ ```

```js
var obj = { greet: "Hello World!" };
const obj = { greet: "Hello World!" };
jetpack.write('file.json', obj);

@@ -21,27 +21,21 @@ ```

```js
var obj = jetpack.read('file.json', 'json');
const obj = jetpack.read('file.json', 'json');
```
## Jetpack throws errors at you as the last resort
Everyone who did something with files for sure seen (and probably hates) *"ENOENT, no such file or directory"* error. Jetpack tries to recover from that error if possible.
1. For write/creation operations, if any of parent directories doesn't exist jetpack will just create lacking directories.
## Safer writes to disk
For essential data you might consider "atomic write" feature. To read more about "why" and "how" please see: [Transactionally writing files in Node.js](http://stackoverflow.com/questions/17047994/transactionally-writing-files-in-node-js) Jetpack implements this simple trick and makes it available as an option.
```js
jetpack.write('important_config.json', { atomic: true });
```
## Errors are thrown at you as the last resort
Everyone who did something with files for sure seen *"ENOENT, no such file or directory"* error. Fs-jetpack tries to recover from it if possible.
1. For write/creation operations, if any of parent directories doesn't exist jetpack will just create them as well.
2. For read/inspect operations, if file or directory doesn't exist `undefined` is returned instead of throwing.
## Jetpack is great for build scripts
```js
var src = jetpack.cwd('path/to/source');
var dest = jetpack.dir('path/to/destination', { empty: true });
src.copy('.', dest.path(), {
matching: ['./vendor/**', '*.html', '*.png', '*.jpg']
});
# It's just more convenient API (in examples)
var config = src.read('config.json', 'json');
config.env = 'production';
dest.write('config.json', config);
## 1. Let's say you want to create folder structure:
```
## All methods play nicely with each other
Let's say you want to create folder structure:
```
.

@@ -65,5 +59,5 @@ |- greets

## Find and delete all `.tmp` files inside `my-dir`
## 2. Find and delete all `.tmp` files inside `foo` directory
```js
jetpack.find('my-dir', {
jetpack.find('foo', {
matching: '*.tmp'

@@ -74,13 +68,14 @@ })

## Check if two files have the same content
## 3. Get the job done faster in your build scripts
```js
var file1 = jetpack.inspect('file1', { checksum: 'md5' });
var file2 = jetpack.inspect('file2', { checksum: 'md5' });
var areTheSame = (file1.md5 === file2.md5);
```
const src = jetpack.cwd('path/to/source');
const dest = jetpack.dir('path/to/destination', { empty: true });
## More secure writes to disk
For essential data you might consider "atomic write" feature. To read more about "why" and "how" please see: [Transactionally writing files in Node.js](http://stackoverflow.com/questions/17047994/transactionally-writing-files-in-node-js) Jetpack implements this simple trick and makes it available as an option.
```js
jetpack.write('important_config.json', { atomic: true });
src.copy('.', dest.path(), {
matching: ['./vendor/**', '*.html', '*.png', '*.jpg']
});
const config = src.read('config.json', 'json');
config.env = 'production';
dest.write('config.json', config);
```
'use strict';
var fs = require('./utils/fs');
var write = require('./write');
var validate = require('./utils/validate');
const fs = require('./utils/fs');
const write = require('./write');
const validate = require('./utils/validate');
var validateInput = function (methodName, path, data, options) {
var methodSignature = methodName + '(path, data, [options])';
const validateInput = (methodName, path, data, options) => {
const methodSignature = `${methodName}(path, data, [options])`;
validate.argument(methodSignature, 'path', path, ['string']);
validate.argument(methodSignature, 'data', data, ['string', 'buffer']);
validate.options(methodSignature, 'options', options, {
mode: ['string', 'number']
mode: ['string', 'number'],
});

@@ -20,3 +20,3 @@ };

var appendSync = function (path, data, options) {
const appendSync = (path, data, options) => {
try {

@@ -39,7 +39,7 @@ fs.appendFileSync(path, data, options);

var appendAsync = function (path, data, options) {
return new Promise(function (resolve, reject) {
const appendAsync = (path, data, options) => {
return new Promise((resolve, reject) => {
fs.appendFile(path, data, options)
.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {

@@ -46,0 +46,0 @@ // Parent directory doesn't exist, so just pass the task to `write`,

'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var dir = require('./dir');
var exists = require('./exists');
var matcher = require('./utils/matcher');
var fileMode = require('./utils/mode');
var treeWalker = require('./utils/tree_walker');
var validate = require('./utils/validate');
var write = require('./write');
const pathUtil = require('path');
const fs = require('./utils/fs');
const dir = require('./dir');
const exists = require('./exists');
const matcher = require('./utils/matcher');
const fileMode = require('./utils/mode');
const treeWalker = require('./utils/tree_walker');
const validate = require('./utils/validate');
const write = require('./write');
var validateInput = function (methodName, from, to, options) {
var methodSignature = methodName + '(from, to, [options])';
const validateInput = (methodName, from, to, options) => {
const methodSignature = `${methodName}(from, to, [options])`;
validate.argument(methodSignature, 'from', from, ['string']);

@@ -19,9 +19,9 @@ validate.argument(methodSignature, 'to', to, ['string']);

overwrite: ['boolean'],
matching: ['string', 'array of string']
matching: ['string', 'array of string'],
});
};
var parseOptions = function (options, from) {
var opts = options || {};
var parsedOptions = {};
const parseOptions = (options, from) => {
const opts = options || {};
const parsedOptions = {};

@@ -33,3 +33,3 @@ parsedOptions.overwrite = opts.overwrite;

} else {
parsedOptions.allowedToCopy = function () {
parsedOptions.allowedToCopy = () => {
// Default behaviour - copy everything.

@@ -43,4 +43,4 @@ return true;

var generateNoSourceError = function (path) {
var err = new Error("Path to copy doesn't exist " + path);
const generateNoSourceError = (path) => {
const err = new Error(`Path to copy doesn't exist ${path}`);
err.code = 'ENOENT';

@@ -50,4 +50,4 @@ return err;

var generateDestinationExistsError = function (path) {
var err = new Error('Destination path already exists ' + path);
const generateDestinationExistsError = (path) => {
const err = new Error(`Destination path already exists ${path}`);
err.code = 'EEXIST';

@@ -61,3 +61,3 @@ return err;

var checksBeforeCopyingSync = function (from, to, opts) {
const checksBeforeCopyingSync = (from, to, opts) => {
if (!exists.sync(from)) {

@@ -72,9 +72,9 @@ throw generateNoSourceError(from);

var copyFileSync = function (from, to, mode) {
var data = fs.readFileSync(from);
write.sync(to, data, { mode: mode });
const copyFileSync = (from, to, mode) => {
const data = fs.readFileSync(from);
write.sync(to, data, { mode });
};
var copySymlinkSync = function (from, to) {
var symlinkPointsAt = fs.readlinkSync(from);
const copySymlinkSync = (from, to) => {
const symlinkPointsAt = fs.readlinkSync(from);
try {

@@ -95,6 +95,6 @@ fs.symlinkSync(symlinkPointsAt, to);

var copyItemSync = function (from, inspectData, to) {
var mode = fileMode.normalizeFileMode(inspectData.mode);
const copyItemSync = (from, inspectData, to) => {
const mode = fileMode.normalizeFileMode(inspectData.mode);
if (inspectData.type === 'dir') {
dir.createSync(to, { mode: mode });
dir.createSync(to, { mode });
} else if (inspectData.type === 'file') {

@@ -107,4 +107,4 @@ copyFileSync(from, to, mode);

var copySync = function (from, to, options) {
var opts = parseOptions(options, from);
const copySync = (from, to, options) => {
const opts = parseOptions(options, from);

@@ -116,7 +116,7 @@ checksBeforeCopyingSync(from, to, opts);

mode: true,
symlinks: true
}
}, function (path, inspectData) {
var rel = pathUtil.relative(from, path);
var destPath = pathUtil.resolve(to, rel);
symlinks: true,
},
}, (path, inspectData) => {
const rel = pathUtil.relative(from, path);
const destPath = pathUtil.resolve(to, rel);
if (opts.allowedToCopy(path)) {

@@ -132,5 +132,5 @@ copyItemSync(path, inspectData, destPath);

var checksBeforeCopyingAsync = function (from, to, opts) {
const checksBeforeCopyingAsync = (from, to, opts) => {
return exists.async(from)
.then(function (srcPathExists) {
.then((srcPathExists) => {
if (!srcPathExists) {

@@ -142,3 +142,3 @@ throw generateNoSourceError(from);

})
.then(function (destPathExists) {
.then((destPathExists) => {
if (destPathExists && !opts.overwrite) {

@@ -150,11 +150,11 @@ throw generateDestinationExistsError(to);

var copyFileAsync = function (from, to, mode, retriedAttempt) {
return new Promise(function (resolve, reject) {
var readStream = fs.createReadStream(from);
var writeStream = fs.createWriteStream(to, { mode: mode });
const copyFileAsync = (from, to, mode, retriedAttempt) => {
return new Promise((resolve, reject) => {
const readStream = fs.createReadStream(from);
const writeStream = fs.createWriteStream(to, { mode });
readStream.on('error', reject);
writeStream.on('error', function (err) {
var toDirPath = pathUtil.dirname(to);
writeStream.on('error', (err) => {
const toDirPath = pathUtil.dirname(to);

@@ -168,3 +168,3 @@ // Force read stream to close, since write stream errored

dir.createAsync(toDirPath)
.then(function () {
.then(() => {
// Make retry attempt only once to prevent vicious infinite loop

@@ -188,9 +188,9 @@ // (when for some obscure reason I/O will keep returning ENOENT error).

var copySymlinkAsync = function (from, to) {
const copySymlinkAsync = (from, to) => {
return fs.readlink(from)
.then(function (symlinkPointsAt) {
return new Promise(function (resolve, reject) {
.then((symlinkPointsAt) => {
return new Promise((resolve, reject) => {
fs.symlink(symlinkPointsAt, to)
.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code === 'EEXIST') {

@@ -200,3 +200,3 @@ // There is already file/symlink with this name on destination location.

fs.unlink(to)
.then(function () {
.then(() => {
// Retry...

@@ -214,6 +214,6 @@ return fs.symlink(symlinkPointsAt, to);

var copyItemAsync = function (from, inspectData, to) {
var mode = fileMode.normalizeFileMode(inspectData.mode);
const copyItemAsync = (from, inspectData, to) => {
const mode = fileMode.normalizeFileMode(inspectData.mode);
if (inspectData.type === 'dir') {
return dir.createAsync(to, { mode: mode });
return dir.createAsync(to, { mode });
} else if (inspectData.type === 'file') {

@@ -229,21 +229,21 @@ return copyFileAsync(from, to, mode);

var copyAsync = function (from, to, options) {
return new Promise(function (resolve, reject) {
var opts = parseOptions(options, from);
const copyAsync = (from, to, options) => {
return new Promise((resolve, reject) => {
const opts = parseOptions(options, from);
checksBeforeCopyingAsync(from, to, opts)
.then(function () {
var allFilesDelivered = false;
var filesInProgress = 0;
.then(() => {
let allFilesDelivered = false;
let filesInProgress = 0;
var stream = treeWalker.stream(from, {
const stream = treeWalker.stream(from, {
inspectOptions: {
mode: true,
symlinks: true
}
symlinks: true,
},
})
.on('readable', function () {
var item = stream.read();
var rel;
var destPath;
.on('readable', () => {
const item = stream.read();
let rel;
let destPath;
if (item) {

@@ -255,3 +255,3 @@ rel = pathUtil.relative(from, item.path);

copyItemAsync(item.path, item.item, destPath)
.then(function () {
.then(() => {
filesInProgress -= 1;

@@ -267,3 +267,3 @@ if (allFilesDelivered && filesInProgress === 0) {

.on('error', reject)
.on('end', function () {
.on('end', () => {
allFilesDelivered = true;

@@ -270,0 +270,0 @@ if (allFilesDelivered && filesInProgress === 0) {

'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var modeUtil = require('./utils/mode');
var validate = require('./utils/validate');
var remove = require('./remove');
const pathUtil = require('path');
const fs = require('./utils/fs');
const modeUtil = require('./utils/mode');
const validate = require('./utils/validate');
const remove = require('./remove');
var validateInput = function (methodName, path, criteria) {
var methodSignature = methodName + '(path, [criteria])';
const validateInput = (methodName, path, criteria) => {
const methodSignature = `${methodName}(path, [criteria])`;
validate.argument(methodSignature, 'path', path, ['string']);
validate.options(methodSignature, 'criteria', criteria, {
empty: ['boolean'],
mode: ['string', 'number']
mode: ['string', 'number'],
});
};
var getCriteriaDefaults = function (passedCriteria) {
var criteria = passedCriteria || {};
const getCriteriaDefaults = (passedCriteria) => {
const criteria = passedCriteria || {};
if (typeof criteria.empty !== 'boolean') {

@@ -29,5 +29,4 @@ criteria.empty = false;

var generatePathOccupiedByNotDirectoryError = function (path) {
return new Error('Path ' + path + ' exists but is not a directory.' +
' Halting jetpack.dir() call for safety reasons.');
const generatePathOccupiedByNotDirectoryError = (path) => {
return new Error(`Path ${path} exists but is not a directory. Halting jetpack.dir() call for safety reasons.`);
};

@@ -39,4 +38,4 @@

var checkWhatAlreadyOccupiesPathSync = function (path) {
var stat;
const checkWhatAlreadyOccupiesPathSync = (path) => {
let stat;

@@ -59,4 +58,4 @@ try {

var createBrandNewDirectorySync = function (path, opts) {
var options = opts || {};
const createBrandNewDirectorySync = (path, opts) => {
const options = opts || {};

@@ -79,5 +78,5 @@ try {

var checkExistingDirectoryFulfillsCriteriaSync = function (path, stat, criteria) {
var checkMode = function () {
var mode = modeUtil.normalizeFileMode(stat.mode);
const checkExistingDirectoryFulfillsCriteriaSync = (path, stat, criteria) => {
const checkMode = () => {
const mode = modeUtil.normalizeFileMode(stat.mode);
if (criteria.mode !== undefined && criteria.mode !== mode) {

@@ -88,8 +87,7 @@ fs.chmodSync(path, criteria.mode);

var checkEmptiness = function () {
var list;
const checkEmptiness = () => {
if (criteria.empty) {
// Delete everything inside this directory
list = fs.readdirSync(path);
list.forEach(function (filename) {
const list = fs.readdirSync(path);
list.forEach((filename) => {
remove.sync(pathUtil.resolve(path, filename));

@@ -104,5 +102,5 @@ });

var dirSync = function (path, passedCriteria) {
var criteria = getCriteriaDefaults(passedCriteria);
var stat = checkWhatAlreadyOccupiesPathSync(path);
const dirSync = (path, passedCriteria) => {
const criteria = getCriteriaDefaults(passedCriteria);
const stat = checkWhatAlreadyOccupiesPathSync(path);
if (stat) {

@@ -119,6 +117,6 @@ checkExistingDirectoryFulfillsCriteriaSync(path, stat, criteria);

var checkWhatAlreadyOccupiesPathAsync = function (path) {
return new Promise(function (resolve, reject) {
const checkWhatAlreadyOccupiesPathAsync = (path) => {
return new Promise((resolve, reject) => {
fs.stat(path)
.then(function (stat) {
.then((stat) => {
if (stat.isDirectory()) {

@@ -130,3 +128,3 @@ resolve(stat);

})
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {

@@ -144,13 +142,12 @@ // Path doesn't exist

// Delete all files and directores inside given directory
var emptyAsync = function (path) {
return new Promise(function (resolve, reject) {
const emptyAsync = (path) => {
return new Promise((resolve, reject) => {
fs.readdir(path)
.then(function (list) {
var doOne = function (index) {
var subPath;
.then((list) => {
const doOne = (index) => {
if (index === list.length) {
resolve();
} else {
subPath = pathUtil.resolve(path, list[index]);
remove.async(subPath).then(function () {
const subPath = pathUtil.resolve(path, list[index]);
remove.async(subPath).then(() => {
doOne(index + 1);

@@ -167,6 +164,6 @@ });

var checkExistingDirectoryFulfillsCriteriaAsync = function (path, stat, criteria) {
return new Promise(function (resolve, reject) {
var checkMode = function () {
var mode = modeUtil.normalizeFileMode(stat.mode);
const checkExistingDirectoryFulfillsCriteriaAsync = (path, stat, criteria) => {
return new Promise((resolve, reject) => {
const checkMode = () => {
const mode = modeUtil.normalizeFileMode(stat.mode);
if (criteria.mode !== undefined && criteria.mode !== mode) {

@@ -178,3 +175,3 @@ return fs.chmod(path, criteria.mode);

var checkEmptiness = function () {
const checkEmptiness = () => {
if (criteria.empty) {

@@ -192,13 +189,13 @@ return emptyAsync(path);

var createBrandNewDirectoryAsync = function (path, opts) {
var options = opts || {};
const createBrandNewDirectoryAsync = (path, opts) => {
const options = opts || {};
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
fs.mkdir(path, options.mode)
.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {
// Parent directory doesn't exist. Need to create it first.
createBrandNewDirectoryAsync(pathUtil.dirname(path), options)
.then(function () {
.then(() => {
// Now retry creating this directory.

@@ -208,3 +205,3 @@ return fs.mkdir(path, options.mode);

.then(resolve)
.catch(function (err2) {
.catch((err2) => {
if (err2.code === 'EEXIST') {

@@ -228,8 +225,8 @@ // Hmm, something other have already created the directory?

var dirAsync = function (path, passedCriteria) {
return new Promise(function (resolve, reject) {
var criteria = getCriteriaDefaults(passedCriteria);
const dirAsync = (path, passedCriteria) => {
return new Promise((resolve, reject) => {
const criteria = getCriteriaDefaults(passedCriteria);
checkWhatAlreadyOccupiesPathAsync(path)
.then(function (stat) {
.then((stat) => {
if (stat !== undefined) {

@@ -236,0 +233,0 @@ return checkExistingDirectoryFulfillsCriteriaAsync(path, stat, criteria);

'use strict';
var fs = require('./utils/fs');
var validate = require('./utils/validate');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
var validateInput = function (methodName, path) {
var methodSignature = methodName + '(path)';
const validateInput = (methodName, path) => {
const methodSignature = `${methodName}(path)`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -15,6 +15,5 @@ };

var existsSync = function (path) {
var stat;
const existsSync = (path) => {
try {
stat = fs.statSync(path);
const stat = fs.statSync(path);
if (stat.isDirectory()) {

@@ -39,5 +38,5 @@ return 'dir';

var existsAsync = function (path) {
return new Promise(function (resolve, reject) {
fs.stat(path, function (err, stat) {
const existsAsync = (path) => {
return new Promise((resolve, reject) => {
fs.stat(path, (err, stat) => {
if (err) {

@@ -44,0 +43,0 @@ if (err.code === 'ENOENT') {

'use strict';
var fs = require('./utils/fs');
var modeUtil = require('./utils/mode');
var validate = require('./utils/validate');
var write = require('./write');
const fs = require('./utils/fs');
const modeUtil = require('./utils/mode');
const validate = require('./utils/validate');
const write = require('./write');
var validateInput = function (methodName, path, criteria) {
var methodSignature = methodName + '(path, [criteria])';
const validateInput = (methodName, path, criteria) => {
const methodSignature = `${methodName}(path, [criteria])`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -14,8 +14,8 @@ validate.options(methodSignature, 'criteria', criteria, {

jsonIndent: ['number'],
mode: ['string', 'number']
mode: ['string', 'number'],
});
};
var getCriteriaDefaults = function (passedCriteria) {
var criteria = passedCriteria || {};
const getCriteriaDefaults = (passedCriteria) => {
const criteria = passedCriteria || {};
if (criteria.mode !== undefined) {

@@ -27,5 +27,4 @@ criteria.mode = modeUtil.normalizeFileMode(criteria.mode);

var generatePathOccupiedByNotFileError = function (path) {
return new Error('Path ' + path + ' exists but is not a file.' +
' Halting jetpack.file() call for safety reasons.');
const generatePathOccupiedByNotFileError = (path) => {
return new Error(`Path ${path} exists but is not a file. Halting jetpack.file() call for safety reasons.`);
};

@@ -37,4 +36,4 @@

var checkWhatAlreadyOccupiesPathSync = function (path) {
var stat;
const checkWhatAlreadyOccupiesPathSync = (path) => {
let stat;

@@ -57,10 +56,10 @@ try {

var checkExistingFileFulfillsCriteriaSync = function (path, stat, criteria) {
var mode = modeUtil.normalizeFileMode(stat.mode);
const checkExistingFileFulfillsCriteriaSync = (path, stat, criteria) => {
const mode = modeUtil.normalizeFileMode(stat.mode);
var checkContent = function () {
const checkContent = () => {
if (criteria.content !== undefined) {
write.sync(path, criteria.content, {
mode: mode,
jsonIndent: criteria.jsonIndent
mode,
jsonIndent: criteria.jsonIndent,
});

@@ -72,3 +71,3 @@ return true;

var checkMode = function () {
const checkMode = () => {
if (criteria.mode !== undefined && criteria.mode !== mode) {

@@ -79,3 +78,3 @@ fs.chmodSync(path, criteria.mode);

var contentReplaced = checkContent();
const contentReplaced = checkContent();
if (!contentReplaced) {

@@ -86,4 +85,4 @@ checkMode();

var createBrandNewFileSync = function (path, criteria) {
var content = '';
const createBrandNewFileSync = (path, criteria) => {
let content = '';
if (criteria.content !== undefined) {

@@ -94,9 +93,9 @@ content = criteria.content;

mode: criteria.mode,
jsonIndent: criteria.jsonIndent
jsonIndent: criteria.jsonIndent,
});
};
var fileSync = function (path, passedCriteria) {
var criteria = getCriteriaDefaults(passedCriteria);
var stat = checkWhatAlreadyOccupiesPathSync(path);
const fileSync = (path, passedCriteria) => {
const criteria = getCriteriaDefaults(passedCriteria);
const stat = checkWhatAlreadyOccupiesPathSync(path);
if (stat !== undefined) {

@@ -113,6 +112,6 @@ checkExistingFileFulfillsCriteriaSync(path, stat, criteria);

var checkWhatAlreadyOccupiesPathAsync = function (path) {
return new Promise(function (resolve, reject) {
const checkWhatAlreadyOccupiesPathAsync = (path) => {
return new Promise((resolve, reject) => {
fs.stat(path)
.then(function (stat) {
.then((stat) => {
if (stat.isFile()) {

@@ -124,3 +123,3 @@ resolve(stat);

})
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {

@@ -137,13 +136,13 @@ // Path doesn't exist.

var checkExistingFileFulfillsCriteriaAsync = function (path, stat, criteria) {
var mode = modeUtil.normalizeFileMode(stat.mode);
const checkExistingFileFulfillsCriteriaAsync = (path, stat, criteria) => {
const mode = modeUtil.normalizeFileMode(stat.mode);
var checkContent = function () {
return new Promise(function (resolve, reject) {
const checkContent = () => {
return new Promise((resolve, reject) => {
if (criteria.content !== undefined) {
write.async(path, criteria.content, {
mode: mode,
jsonIndent: criteria.jsonIndent
mode,
jsonIndent: criteria.jsonIndent,
})
.then(function () {
.then(() => {
resolve(true);

@@ -158,3 +157,3 @@ })

var checkMode = function () {
const checkMode = () => {
if (criteria.mode !== undefined && criteria.mode !== mode) {

@@ -167,3 +166,3 @@ return fs.chmod(path, criteria.mode);

return checkContent()
.then(function (contentReplaced) {
.then((contentReplaced) => {
if (!contentReplaced) {

@@ -176,4 +175,4 @@ return checkMode();

var createBrandNewFileAsync = function (path, criteria) {
var content = '';
const createBrandNewFileAsync = (path, criteria) => {
let content = '';
if (criteria.content !== undefined) {

@@ -185,12 +184,12 @@ content = criteria.content;

mode: criteria.mode,
jsonIndent: criteria.jsonIndent
jsonIndent: criteria.jsonIndent,
});
};
var fileAsync = function (path, passedCriteria) {
return new Promise(function (resolve, reject) {
var criteria = getCriteriaDefaults(passedCriteria);
const fileAsync = (path, passedCriteria) => {
return new Promise((resolve, reject) => {
const criteria = getCriteriaDefaults(passedCriteria);
checkWhatAlreadyOccupiesPathAsync(path)
.then(function (stat) {
.then((stat) => {
if (stat !== undefined) {

@@ -197,0 +196,0 @@ return checkExistingFileFulfillsCriteriaAsync(path, stat, criteria);

'use strict';
var pathUtil = require('path');
var treeWalker = require('./utils/tree_walker');
var inspect = require('./inspect');
var matcher = require('./utils/matcher');
var validate = require('./utils/validate');
const pathUtil = require('path');
const treeWalker = require('./utils/tree_walker');
const inspect = require('./inspect');
const matcher = require('./utils/matcher');
const validate = require('./utils/validate');
var validateInput = function (methodName, path, options) {
var methodSignature = methodName + '([path], options)';
const validateInput = (methodName, path, options) => {
const methodSignature = `${methodName}([path], options)`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -16,8 +16,8 @@ validate.options(methodSignature, 'options', options, {

directories: ['boolean'],
recursive: ['boolean']
recursive: ['boolean'],
});
};
var normalizeOptions = function (options) {
var opts = options || {};
const normalizeOptions = (options) => {
const opts = options || {};
// defaults:

@@ -36,4 +36,4 @@ if (opts.files === undefined) {

var processFoundObjects = function (foundObjects, cwd) {
return foundObjects.map(function (inspectObj) {
const processFoundObjects = (foundObjects, cwd) => {
return foundObjects.map((inspectObj) => {
return pathUtil.relative(cwd, inspectObj.absolutePath);

@@ -43,4 +43,4 @@ });

var generatePathDoesntExistError = function (path) {
var err = new Error("Path you want to find stuff in doesn't exist " + path);
const generatePathDoesntExistError = (path) => {
const err = new Error(`Path you want to find stuff in doesn't exist ${path}`);
err.code = 'ENOENT';

@@ -50,4 +50,4 @@ return err;

var generatePathNotDirectoryError = function (path) {
var err = new Error('Path you want to find stuff in must be a directory ' + path);
const generatePathNotDirectoryError = (path) => {
const err = new Error(`Path you want to find stuff in must be a directory ${path}`);
err.code = 'ENOTDIR';

@@ -61,12 +61,17 @@ return err;

var findSync = function (path, options) {
var foundInspectObjects = [];
var matchesAnyOfGlobs = matcher.create(path, options.matching);
const findSync = (path, options) => {
const foundInspectObjects = [];
const matchesAnyOfGlobs = matcher.create(path, options.matching);
let maxLevelsDeep = Infinity;
if (options.recursive === false) {
maxLevelsDeep = 1;
}
treeWalker.sync(path, {
maxLevelsDeep: options.recursive ? Infinity : 1,
maxLevelsDeep,
inspectOptions: {
absolutePath: true
}
}, function (itemPath, item) {
absolutePath: true,
},
}, (itemPath, item) => {
if (itemPath !== path && matchesAnyOfGlobs(itemPath)) {

@@ -83,4 +88,4 @@ if ((item.type === 'file' && options.files === true)

var findSyncInit = function (path, options) {
var entryPointInspect = inspect.sync(path);
const findSyncInit = (path, options) => {
const entryPointInspect = inspect.sync(path);
if (entryPointInspect === undefined) {

@@ -99,18 +104,22 @@ throw generatePathDoesntExistError(path);

var findAsync = function (path, options) {
return new Promise(function (resolve, reject) {
var foundInspectObjects = [];
var matchesAnyOfGlobs = matcher.create(path, options.matching);
const findAsync = (path, options) => {
return new Promise((resolve, reject) => {
const foundInspectObjects = [];
const matchesAnyOfGlobs = matcher.create(path, options.matching);
var walker = treeWalker.stream(path, {
maxLevelsDeep: options.recursive ? Infinity : 1,
let maxLevelsDeep = Infinity;
if (options.recursive === false) {
maxLevelsDeep = 1;
}
const walker = treeWalker.stream(path, {
maxLevelsDeep,
inspectOptions: {
absolutePath: true
}
absolutePath: true,
},
})
.on('readable', function () {
var data = walker.read();
var item;
.on('readable', () => {
const data = walker.read();
if (data && data.path !== path && matchesAnyOfGlobs(data.path)) {
item = data.item;
const item = data.item;
if ((item.type === 'file' && options.files === true)

@@ -123,3 +132,3 @@ || (item.type === 'dir' && options.directories === true)) {

.on('error', reject)
.on('end', function () {
.on('end', () => {
resolve(processFoundObjects(foundInspectObjects, options.cwd));

@@ -130,5 +139,5 @@ });

var findAsyncInit = function (path, options) {
const findAsyncInit = (path, options) => {
return inspect.async(path)
.then(function (entryPointInspect) {
.then((entryPointInspect) => {
if (entryPointInspect === undefined) {

@@ -135,0 +144,0 @@ throw generatePathDoesntExistError(path);

'use strict';
var crypto = require('crypto');
var pathUtil = require('path');
var inspect = require('./inspect');
var list = require('./list');
var validate = require('./utils/validate');
const crypto = require('crypto');
const pathUtil = require('path');
const inspect = require('./inspect');
const list = require('./list');
const validate = require('./utils/validate');
var validateInput = function (methodName, path, options) {
var methodSignature = methodName + '(path, [options])';
const validateInput = (methodName, path, options) => {
const methodSignature = `${methodName}(path, [options])`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -15,3 +15,3 @@ validate.options(methodSignature, 'options', options, {

relativePath: ['boolean'],
symlinks: ['string']
symlinks: ['string'],
});

@@ -21,4 +21,3 @@

&& inspect.supportedChecksumAlgorithms.indexOf(options.checksum) === -1) {
throw new Error('Argument "options.checksum" passed to ' + methodSignature
+ ' must have one of values: ' + inspect.supportedChecksumAlgorithms.join(', '));
throw new Error(`Argument "options.checksum" passed to ${methodSignature} must have one of values: ${inspect.supportedChecksumAlgorithms.join(', ')}`);
}

@@ -28,12 +27,11 @@

&& inspect.symlinkOptions.indexOf(options.symlinks) === -1) {
throw new Error('Argument "options.symlinks" passed to ' + methodSignature
+ ' must have one of values: ' + inspect.symlinkOptions.join(', '));
throw new Error(`Argument "options.symlinks" passed to ${methodSignature} must have one of values: ${inspect.symlinkOptions.join(', ')}`);
}
};
var generateTreeNodeRelativePath = function (parent, path) {
const generateTreeNodeRelativePath = (parent, path) => {
if (!parent) {
return '.';
}
return parent.relativePath + '/' + pathUtil.basename(path);
return `${parent.relativePath}/${pathUtil.basename(path)}`;
};

@@ -43,5 +41,5 @@

// checksums and names of all its children inside.
var checksumOfDir = function (inspectList, algo) {
var hash = crypto.createHash(algo);
inspectList.forEach(function (inspectObj) {
const checksumOfDir = (inspectList, algo) => {
const hash = crypto.createHash(algo);
inspectList.forEach((inspectObj) => {
hash.update(inspectObj.name + inspectObj[algo]);

@@ -56,4 +54,4 @@ });

var inspectTreeNodeSync = function (path, options, parent) {
var treeBranch = inspect.sync(path, options);
const inspectTreeNodeSync = (path, options, parent) => {
const treeBranch = inspect.sync(path, options);

@@ -67,5 +65,5 @@ if (treeBranch) {

treeBranch.size = 0;
treeBranch.children = list.sync(path).map(function (filename) {
var subBranchPath = pathUtil.join(path, filename);
var treeSubBranch = inspectTreeNodeSync(subBranchPath, options, treeBranch);
treeBranch.children = list.sync(path).map((filename) => {
const subBranchPath = pathUtil.join(path, filename);
const treeSubBranch = inspectTreeNodeSync(subBranchPath, options, treeBranch);
// Add together all childrens' size to get directory combined size.

@@ -85,6 +83,5 @@ treeBranch.size += treeSubBranch.size || 0;

var inspectTreeSync = function (path, options) {
options = options || {};
return inspectTreeNodeSync(path, options, undefined);
const inspectTreeSync = (path, options) => {
const opts = options || {};
return inspectTreeNodeSync(path, opts, undefined);
};

@@ -96,9 +93,8 @@

var inspectTreeNodeAsync = function (path, options, parent) {
return new Promise(function (resolve, reject) {
var inspectAllChildren = function (treeBranch) {
return new Promise(function (resolve2, reject2) {
list.async(path).then(function (children) {
var doNext = function (index) {
var subPath;
const inspectTreeNodeAsync = (path, options, parent) => {
return new Promise((resolve, reject) => {
const inspectAllChildren = (treeBranch) => {
return new Promise((resolve2, reject2) => {
list.async(path).then((children) => {
const doNext = (index) => {
if (index === children.length) {

@@ -111,5 +107,5 @@ if (options.checksum) {

} else {
subPath = pathUtil.join(path, children[index]);
const subPath = pathUtil.join(path, children[index]);
inspectTreeNodeAsync(subPath, options, treeBranch)
.then(function (treeSubBranch) {
.then((treeSubBranch) => {
children[index] = treeSubBranch;

@@ -132,3 +128,3 @@ treeBranch.size += treeSubBranch.size || 0;

inspect.async(path, options)
.then(function (treeBranch) {
.then((treeBranch) => {
if (!treeBranch) {

@@ -146,3 +142,3 @@ // Given path doesn't exist. We are done.

inspectAllChildren(treeBranch)
.then(function () {
.then(() => {
resolve(treeBranch);

@@ -158,6 +154,5 @@ })

var inspectTreeAsync = function (path, options) {
options = options || {};
return inspectTreeNodeAsync(path, options);
const inspectTreeAsync = (path, options) => {
const opts = options || {};
return inspectTreeNodeAsync(path, opts);
};

@@ -164,0 +159,0 @@

'use strict';
var crypto = require('crypto');
var pathUtil = require('path');
var fs = require('./utils/fs');
var validate = require('./utils/validate');
const crypto = require('crypto');
const pathUtil = require('path');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
var supportedChecksumAlgorithms = ['md5', 'sha1', 'sha256', 'sha512'];
const supportedChecksumAlgorithms = ['md5', 'sha1', 'sha256', 'sha512'];
var symlinkOptions = ['report', 'follow'];
const symlinkOptions = ['report', 'follow'];
var validateInput = function (methodName, path, options) {
var methodSignature = methodName + '(path, [options])';
const validateInput = (methodName, path, options) => {
const methodSignature = `${methodName}(path, [options])`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -20,3 +20,3 @@ validate.options(methodSignature, 'options', options, {

absolutePath: ['boolean'],
symlinks: ['string']
symlinks: ['string'],
});

@@ -26,4 +26,3 @@

&& supportedChecksumAlgorithms.indexOf(options.checksum) === -1) {
throw new Error('Argument "options.checksum" passed to ' + methodSignature
+ ' must have one of values: ' + supportedChecksumAlgorithms.join(', '));
throw new Error(`Argument "options.checksum" passed to ${methodSignature} must have one of values: ${supportedChecksumAlgorithms.join(', ')}`);
}

@@ -33,9 +32,8 @@

&& symlinkOptions.indexOf(options.symlinks) === -1) {
throw new Error('Argument "options.symlinks" passed to ' + methodSignature
+ ' must have one of values: ' + symlinkOptions.join(', '));
throw new Error(`Argument "options.symlinks" passed to ${methodSignature} must have one of values: ${symlinkOptions.join(', ')}`);
}
};
var createInspectObj = function (path, options, stat) {
var obj = {};
const createInspectObj = (path, options, stat) => {
const obj = {};

@@ -76,5 +74,5 @@ obj.name = pathUtil.basename(path);

var fileChecksum = function (path, algo) {
var hash = crypto.createHash(algo);
var data = fs.readFileSync(path);
const fileChecksum = (path, algo) => {
const hash = crypto.createHash(algo);
const data = fs.readFileSync(path);
hash.update(data);

@@ -84,3 +82,3 @@ return hash.digest('hex');

var addExtraFieldsSync = function (path, inspectObj, options) {
const addExtraFieldsSync = (path, inspectObj, options) => {
if (inspectObj.type === 'file' && options.checksum) {

@@ -93,9 +91,8 @@ inspectObj[options.checksum] = fileChecksum(path, options.checksum);

var inspectSync = function (path, options) {
var statOperation = fs.lstatSync;
var stat;
var inspectObj;
options = options || {};
const inspectSync = (path, options) => {
let statOperation = fs.lstatSync;
let stat;
const opts = options || {};
if (options.symlinks === 'follow') {
if (opts.symlinks === 'follow') {
statOperation = fs.statSync;

@@ -115,4 +112,4 @@ }

inspectObj = createInspectObj(path, options, stat);
addExtraFieldsSync(path, inspectObj, options);
const inspectObj = createInspectObj(path, opts, stat);
addExtraFieldsSync(path, inspectObj, opts);

@@ -126,10 +123,10 @@ return inspectObj;

var fileChecksumAsync = function (path, algo) {
return new Promise(function (resolve, reject) {
var hash = crypto.createHash(algo);
var s = fs.createReadStream(path);
s.on('data', function (data) {
const fileChecksumAsync = (path, algo) => {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(algo);
const s = fs.createReadStream(path);
s.on('data', (data) => {
hash.update(data);
});
s.on('end', function () {
s.on('end', () => {
resolve(hash.digest('hex'));

@@ -141,6 +138,6 @@ });

var addExtraFieldsAsync = function (path, inspectObj, options) {
const addExtraFieldsAsync = (path, inspectObj, options) => {
if (inspectObj.type === 'file' && options.checksum) {
return fileChecksumAsync(path, options.checksum)
.then(function (checksum) {
.then((checksum) => {
inspectObj[options.checksum] = checksum;

@@ -151,3 +148,3 @@ return inspectObj;

return fs.readlink(path)
.then(function (linkPath) {
.then((linkPath) => {
inspectObj.pointsAt = linkPath;

@@ -160,8 +157,8 @@ return inspectObj;

var inspectAsync = function (path, options) {
return new Promise(function (resolve, reject) {
var statOperation = fs.lstat;
options = options || {};
const inspectAsync = (path, options) => {
return new Promise((resolve, reject) => {
let statOperation = fs.lstat;
const opts = options || {};
if (options.symlinks === 'follow') {
if (opts.symlinks === 'follow') {
statOperation = fs.stat;

@@ -171,8 +168,8 @@ }

statOperation(path)
.then(function (stat) {
var inspectObj = createInspectObj(path, options, stat);
addExtraFieldsAsync(path, inspectObj, options)
.then((stat) => {
const inspectObj = createInspectObj(path, opts, stat);
addExtraFieldsAsync(path, inspectObj, opts)
.then(resolve, reject);
})
.catch(function (err) {
.catch((err) => {
// Detection if path exists

@@ -179,0 +176,0 @@ if (err.code === 'ENOENT') {

@@ -5,20 +5,20 @@ /* eslint no-param-reassign:0 */

var util = require('util');
var pathUtil = require('path');
var append = require('./append');
var dir = require('./dir');
var file = require('./file');
var find = require('./find');
var inspect = require('./inspect');
var inspectTree = require('./inspect_tree');
var copy = require('./copy');
var exists = require('./exists');
var list = require('./list');
var move = require('./move');
var read = require('./read');
var remove = require('./remove');
var rename = require('./rename');
var symlink = require('./symlink');
var streams = require('./streams');
var write = require('./write');
const util = require('util');
const pathUtil = require('path');
const append = require('./append');
const dir = require('./dir');
const file = require('./file');
const find = require('./find');
const inspect = require('./inspect');
const inspectTree = require('./inspect_tree');
const copy = require('./copy');
const exists = require('./exists');
const list = require('./list');
const move = require('./move');
const read = require('./read');
const remove = require('./remove');
const rename = require('./rename');
const symlink = require('./symlink');
const streams = require('./streams');
const write = require('./write');

@@ -28,11 +28,8 @@ // The Jetpack Context object.

// passed cwdPath, or default process.cwd() if cwdPath was not specified.
var jetpackContext = function (cwdPath) {
var getCwdPath = function () {
const jetpackContext = (cwdPath) => {
const getCwdPath = () => {
return cwdPath || process.cwd();
};
var cwd = function () {
var args;
var pathParts;
const cwd = function () {
// return current CWD if no arguments specified...

@@ -44,4 +41,4 @@ if (arguments.length === 0) {

// ...create new CWD context otherwise
args = Array.prototype.slice.call(arguments);
pathParts = [getCwdPath()].concat(args);
const args = Array.prototype.slice.call(arguments);
const pathParts = [getCwdPath()].concat(args);
return jetpackContext(pathUtil.resolve.apply(null, pathParts));

@@ -51,7 +48,7 @@ };

// resolves path to inner CWD path of this jetpack instance
var resolvePath = function (path) {
const resolvePath = (path) => {
return pathUtil.resolve(getCwdPath(), path);
};
var getPath = function () {
const getPath = function () {
// add CWD base path as first element of arguments array

@@ -62,4 +59,4 @@ Array.prototype.unshift.call(arguments, getCwdPath());

var normalizeOptions = function (options) {
var opts = options || {};
const normalizeOptions = (options) => {
const opts = options || {};
opts.cwd = getCwdPath();

@@ -71,11 +68,11 @@ return opts;

var api = {
cwd: cwd,
const api = {
cwd,
path: getPath,
append: function (path, data, options) {
append: (path, data, options) => {
append.validateInput('append', path, data, options);
append.sync(resolvePath(path), data, options);
},
appendAsync: function (path, data, options) {
appendAsync: (path, data, options) => {
append.validateInput('appendAsync', path, data, options);

@@ -85,7 +82,7 @@ return append.async(resolvePath(path), data, options);

copy: function (from, to, options) {
copy: (from, to, options) => {
copy.validateInput('copy', from, to, options);
copy.sync(resolvePath(from), resolvePath(to), options);
},
copyAsync: function (from, to, options) {
copyAsync: (from, to, options) => {
copy.validateInput('copyAsync', from, to, options);

@@ -95,22 +92,21 @@ return copy.async(resolvePath(from), resolvePath(to), options);

createWriteStream: function (path, options) {
createWriteStream: (path, options) => {
return streams.createWriteStream(resolvePath(path), options);
},
createReadStream: function (path, options) {
createReadStream: (path, options) => {
return streams.createReadStream(resolvePath(path), options);
},
dir: function (path, criteria) {
var normalizedPath;
dir: (path, criteria) => {
dir.validateInput('dir', path, criteria);
normalizedPath = resolvePath(path);
const normalizedPath = resolvePath(path);
dir.sync(normalizedPath, criteria);
return cwd(normalizedPath);
},
dirAsync: function (path, criteria) {
dirAsync: (path, criteria) => {
dir.validateInput('dirAsync', path, criteria);
return new Promise(function (resolve, reject) {
var normalizedPath = resolvePath(path);
return new Promise((resolve, reject) => {
const normalizedPath = resolvePath(path);
dir.async(normalizedPath, criteria)
.then(function () {
.then(() => {
resolve(cwd(normalizedPath));

@@ -121,7 +117,7 @@ }, reject);

exists: function (path) {
exists: (path) => {
exists.validateInput('exists', path);
return exists.sync(resolvePath(path));
},
existsAsync: function (path) {
existsAsync: (path) => {
exists.validateInput('existsAsync', path);

@@ -131,14 +127,13 @@ return exists.async(resolvePath(path));

file: function (path, criteria) {
file: (path, criteria) => {
file.validateInput('file', path, criteria);
file.sync(resolvePath(path), criteria);
return this;
return api;
},
fileAsync: function (path, criteria) {
var that = this;
fileAsync: (path, criteria) => {
file.validateInput('fileAsync', path, criteria);
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
file.async(resolvePath(path), criteria)
.then(function () {
resolve(that);
.then(() => {
resolve(api);
}, reject);

@@ -148,3 +143,3 @@ });

find: function (startPath, options) {
find: (startPath, options) => {
// startPath is optional parameter, if not specified move rest of params

@@ -159,3 +154,3 @@ // to proper places and default startPath to CWD.

},
findAsync: function (startPath, options) {
findAsync: (startPath, options) => {
// startPath is optional parameter, if not specified move rest of params

@@ -171,7 +166,7 @@ // to proper places and default startPath to CWD.

inspect: function (path, fieldsToInclude) {
inspect: (path, fieldsToInclude) => {
inspect.validateInput('inspect', path, fieldsToInclude);
return inspect.sync(resolvePath(path), fieldsToInclude);
},
inspectAsync: function (path, fieldsToInclude) {
inspectAsync: (path, fieldsToInclude) => {
inspect.validateInput('inspectAsync', path, fieldsToInclude);

@@ -181,7 +176,7 @@ return inspect.async(resolvePath(path), fieldsToInclude);

inspectTree: function (path, options) {
inspectTree: (path, options) => {
inspectTree.validateInput('inspectTree', path, options);
return inspectTree.sync(resolvePath(path), options);
},
inspectTreeAsync: function (path, options) {
inspectTreeAsync: (path, options) => {
inspectTree.validateInput('inspectTreeAsync', path, options);

@@ -191,7 +186,7 @@ return inspectTree.async(resolvePath(path), options);

list: function (path) {
list: (path) => {
list.validateInput('list', path);
return list.sync(resolvePath(path || '.'));
},
listAsync: function (path) {
listAsync: (path) => {
list.validateInput('listAsync', path);

@@ -201,7 +196,7 @@ return list.async(resolvePath(path || '.'));

move: function (from, to) {
move: (from, to) => {
move.validateInput('move', from, to);
move.sync(resolvePath(from), resolvePath(to));
},
moveAsync: function (from, to) {
moveAsync: (from, to) => {
move.validateInput('moveAsync', from, to);

@@ -211,7 +206,7 @@ return move.async(resolvePath(from), resolvePath(to));

read: function (path, returnAs) {
read: (path, returnAs) => {
read.validateInput('read', path, returnAs);
return read.sync(resolvePath(path), returnAs);
},
readAsync: function (path, returnAs) {
readAsync: (path, returnAs) => {
read.validateInput('readAsync', path, returnAs);

@@ -221,3 +216,3 @@ return read.async(resolvePath(path), returnAs);

remove: function (path) {
remove: (path) => {
remove.validateInput('remove', path);

@@ -227,3 +222,3 @@ // If path not specified defaults to CWD

},
removeAsync: function (path) {
removeAsync: (path) => {
remove.validateInput('removeAsync', path);

@@ -234,7 +229,7 @@ // If path not specified defaults to CWD

rename: function (path, newName) {
rename: (path, newName) => {
rename.validateInput('rename', path, newName);
rename.sync(resolvePath(path), newName);
},
renameAsync: function (path, newName) {
renameAsync: (path, newName) => {
rename.validateInput('renameAsync', path, newName);

@@ -244,7 +239,7 @@ return rename.async(resolvePath(path), newName);

symlink: function (symlinkValue, path) {
symlink: (symlinkValue, path) => {
symlink.validateInput('symlink', symlinkValue, path);
symlink.sync(symlinkValue, resolvePath(path));
},
symlinkAsync: function (symlinkValue, path) {
symlinkAsync: (symlinkValue, path) => {
symlink.validateInput('symlinkAsync', symlinkValue, path);

@@ -254,10 +249,10 @@ return symlink.async(symlinkValue, resolvePath(path));

write: function (path, data, options) {
write: (path, data, options) => {
write.validateInput('write', path, data, options);
write.sync(resolvePath(path), data, options);
},
writeAsync: function (path, data, options) {
writeAsync: (path, data, options) => {
write.validateInput('writeAsync', path, data, options);
return write.async(resolvePath(path), data, options);
}
},
};

@@ -269,4 +264,4 @@

// https://nodejs.org/api/util.html#util_custom_inspection_functions_on_objects
api[util.inspect.custom] = function () {
return '[fs-jetpack CWD: ' + getCwdPath() + ']';
api[util.inspect.custom] = () => {
return `[fs-jetpack CWD: ${getCwdPath()}]`;
};

@@ -273,0 +268,0 @@ }

'use strict';
var fs = require('./utils/fs');
var validate = require('./utils/validate');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
var validateInput = function (methodName, path) {
var methodSignature = methodName + '(path)';
const validateInput = (methodName, path) => {
const methodSignature = `${methodName}(path)`;
validate.argument(methodSignature, 'path', path, ['string', 'undefined']);

@@ -15,3 +15,3 @@ };

var listSync = function (path) {
const listSync = (path) => {
try {

@@ -32,9 +32,9 @@ return fs.readdirSync(path);

var listAsync = function (path) {
return new Promise(function (resolve, reject) {
const listAsync = (path) => {
return new Promise((resolve, reject) => {
fs.readdir(path)
.then(function (list) {
.then((list) => {
resolve(list);
})
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {

@@ -41,0 +41,0 @@ // Doesn't exist. Return undefined instead of throwing.

'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var validate = require('./utils/validate');
var dir = require('./dir');
var exists = require('./exists');
const pathUtil = require('path');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
const dir = require('./dir');
const exists = require('./exists');
var validateInput = function (methodName, from, to) {
var methodSignature = methodName + '(from, to)';
const validateInput = (methodName, from, to) => {
const methodSignature = `${methodName}(from, to)`;
validate.argument(methodSignature, 'from', from, ['string']);

@@ -15,4 +15,4 @@ validate.argument(methodSignature, 'to', to, ['string']);

var generateSourceDoesntExistError = function (path) {
var err = new Error("Path to move doesn't exist " + path);
const generateSourceDoesntExistError = (path) => {
const err = new Error(`Path to move doesn't exist ${path}`);
err.code = 'ENOENT';

@@ -26,3 +26,3 @@ return err;

var moveSync = function (from, to) {
const moveSync = (from, to) => {
try {

@@ -54,7 +54,7 @@ fs.renameSync(from, to);

var ensureDestinationPathExistsAsync = function (to) {
return new Promise(function (resolve, reject) {
var destDir = pathUtil.dirname(to);
const ensureDestinationPathExistsAsync = (to) => {
return new Promise((resolve, reject) => {
const destDir = pathUtil.dirname(to);
exists.async(destDir)
.then(function (dstExists) {
.then((dstExists) => {
if (!dstExists) {

@@ -72,7 +72,7 @@ dir.createAsync(destDir)

var moveAsync = function (from, to) {
return new Promise(function (resolve, reject) {
const moveAsync = (from, to) => {
return new Promise((resolve, reject) => {
fs.rename(from, to)
.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code !== 'ENOENT') {

@@ -85,3 +85,3 @@ // Something unknown. Rethrow original error.

exists.async(from)
.then(function (srcExists) {
.then((srcExists) => {
if (!srcExists) {

@@ -91,3 +91,3 @@ reject(generateSourceDoesntExistError(from));

ensureDestinationPathExistsAsync(to)
.then(function () {
.then(() => {
// Retry the attempt

@@ -94,0 +94,0 @@ return fs.rename(from, to);

@@ -5,9 +5,9 @@ /* eslint no-console:1 */

var fs = require('./utils/fs');
var validate = require('./utils/validate');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
var supportedReturnAs = ['utf8', 'buffer', 'json', 'jsonWithDates'];
const supportedReturnAs = ['utf8', 'buffer', 'json', 'jsonWithDates'];
var validateInput = function (methodName, path, returnAs) {
var methodSignature = methodName + '(path, returnAs)';
const validateInput = (methodName, path, returnAs) => {
const methodSignature = `${methodName}(path, returnAs)`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -17,4 +17,3 @@ validate.argument(methodSignature, 'returnAs', returnAs, ['string', 'undefined']);

if (returnAs && supportedReturnAs.indexOf(returnAs) === -1) {
throw new Error('Argument "returnAs" passed to ' + methodSignature
+ ' must have one of values: ' + supportedReturnAs.join(', '));
throw new Error(`Argument "returnAs" passed to ${methodSignature} must have one of values: ${supportedReturnAs.join(', ')}`);
}

@@ -25,4 +24,4 @@ };

// which is called to serialize date to JSON.
var jsonDateParser = function (key, value) {
var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
const jsonDateParser = (key, value) => {
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
if (typeof value === 'string') {

@@ -36,5 +35,4 @@ if (reISO.exec(value)) {

var makeNicerJsonParsingError = function (path, err) {
var nicerError = new Error('JSON parsing failed while reading '
+ path + ' [' + err + ']');
const makeNicerJsonParsingError = (path, err) => {
const nicerError = new Error(`JSON parsing failed while reading ${path} [${err}]`);
nicerError.originalError = err;

@@ -48,7 +46,7 @@ return nicerError;

var readSync = function (path, returnAs) {
var retAs = returnAs || 'utf8';
var data;
const readSync = (path, returnAs) => {
const retAs = returnAs || 'utf8';
let data;
var encoding = 'utf8';
let encoding = 'utf8';
if (retAs === 'buffer') {

@@ -59,3 +57,3 @@ encoding = null;

try {
data = fs.readFileSync(path, { encoding: encoding });
data = fs.readFileSync(path, { encoding });
} catch (err) {

@@ -87,6 +85,6 @@ if (err.code === 'ENOENT') {

var readAsync = function (path, returnAs) {
return new Promise(function (resolve, reject) {
var retAs = returnAs || 'utf8';
var encoding = 'utf8';
const readAsync = (path, returnAs) => {
return new Promise((resolve, reject) => {
const retAs = returnAs || 'utf8';
let encoding = 'utf8';
if (retAs === 'buffer') {

@@ -96,4 +94,4 @@ encoding = null;

fs.readFile(path, { encoding: encoding })
.then(function (data) {
fs.readFile(path, { encoding })
.then((data) => {
// Make final parsing of the data before returning.

@@ -112,3 +110,3 @@ try {

})
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {

@@ -115,0 +113,0 @@ // If file doesn't exist return undefined instead of throwing.

'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var validate = require('./utils/validate');
var list = require('./list');
const pathUtil = require('path');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
const list = require('./list');
var validateInput = function (methodName, path) {
var methodSignature = methodName + '([path])';
const validateInput = (methodName, path) => {
const methodSignature = `${methodName}([path])`;
validate.argument(methodSignature, 'path', path, ['string', 'undefined']);

@@ -17,3 +17,3 @@ };

var removeSync = function (path) {
const removeSync = (path) => {
try {

@@ -25,3 +25,3 @@ // Assume the path is a file and just try to remove it.

// Must delete everything inside the directory first.
list.sync(path).forEach(function (filename) {
list.sync(path).forEach((filename) => {
removeSync(pathUtil.join(path, filename));

@@ -45,5 +45,5 @@ });

var removeAsyncInternal = function (path, retryCount) {
return new Promise(function (resolve, reject) {
var retryInAWhileOrFail = function (err) {
const removeAsyncInternal = (path, retryCount) => {
return new Promise((resolve, reject) => {
const retryInAWhileOrFail = (err) => {
if (retryCount === 3) {

@@ -54,3 +54,3 @@ // Too many retries already. Fail.

// Try the same action after some pause.
setTimeout(function () {
setTimeout(() => {
removeAsyncInternal(path, retryCount + 1)

@@ -62,6 +62,6 @@ .then(resolve, reject);

var removeEverythingInsideDirectory = function () {
const removeEverythingInsideDirectory = () => {
return list.async(path)
.then(function (filenamesInsideDir) {
var promises = filenamesInsideDir.map(function (filename) {
.then((filenamesInsideDir) => {
const promises = filenamesInsideDir.map((filename) => {
return removeAsyncInternal(pathUtil.join(path, filename), 0);

@@ -76,3 +76,3 @@ });

.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code === 'EBUSY') {

@@ -84,3 +84,3 @@ retryInAWhileOrFail(err);

removeEverythingInsideDirectory()
.then(function () {
.then(() => {
// Now go for the directory.

@@ -90,3 +90,3 @@ return fs.rmdir(path);

.then(resolve)
.catch(function (err2) {
.catch((err2) => {
if (err2.code === 'EBUSY' || err2.code === 'EPERM' || err2.code === 'ENOTEMPTY') {

@@ -111,3 +111,3 @@ // Failed again. This might be due to other processes reading

var removeAsync = function (path) {
const removeAsync = (path) => {
return removeAsyncInternal(path, 0);

@@ -114,0 +114,0 @@ };

'use strict';
var pathUtil = require('path');
var move = require('./move');
var validate = require('./utils/validate');
const pathUtil = require('path');
const move = require('./move');
const validate = require('./utils/validate');
var validateInput = function (methodName, path, newName) {
var methodSignature = methodName + '(path, newName)';
const validateInput = (methodName, path, newName) => {
const methodSignature = `${methodName}(path, newName)`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -17,4 +17,4 @@ validate.argument(methodSignature, 'newName', newName, ['string']);

var renameSync = function (path, newName) {
var newPath = pathUtil.join(pathUtil.dirname(path), newName);
const renameSync = (path, newName) => {
const newPath = pathUtil.join(pathUtil.dirname(path), newName);
move.sync(path, newPath);

@@ -27,4 +27,4 @@ };

var renameAsync = function (path, newName) {
var newPath = pathUtil.join(pathUtil.dirname(path), newName);
const renameAsync = (path, newName) => {
const newPath = pathUtil.join(pathUtil.dirname(path), newName);
return move.async(path, newPath);

@@ -31,0 +31,0 @@ };

'use strict';
var fs = require('fs');
const fs = require('fs');
exports.createWriteStream = fs.createWriteStream;
exports.createReadStream = fs.createReadStream;
'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var validate = require('./utils/validate');
var dir = require('./dir');
const pathUtil = require('path');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
const dir = require('./dir');
var validateInput = function (methodName, symlinkValue, path) {
var methodSignature = methodName + '(symlinkValue, path)';
const validateInput = (methodName, symlinkValue, path) => {
const methodSignature = `${methodName}(symlinkValue, path)`;
validate.argument(methodSignature, 'symlinkValue', symlinkValue, ['string']);

@@ -18,3 +18,3 @@ validate.argument(methodSignature, 'path', path, ['string']);

var symlinkSync = function (symlinkValue, path) {
const symlinkSync = (symlinkValue, path) => {
try {

@@ -37,11 +37,11 @@ fs.symlinkSync(symlinkValue, path);

var symlinkAsync = function (symlinkValue, path) {
return new Promise(function (resolve, reject) {
const symlinkAsync = (symlinkValue, path) => {
return new Promise((resolve, reject) => {
fs.symlink(symlinkValue, path)
.then(resolve)
.catch(function (err) {
.catch((err) => {
if (err.code === 'ENOENT') {
// Parent directories don't exist. Just create them and rety.
dir.createAsync(pathUtil.dirname(path))
.then(function () {
.then(() => {
return fs.symlink(symlinkValue, path);

@@ -48,0 +48,0 @@ })

@@ -5,6 +5,6 @@ // Adater module exposing all `fs` methods with promises instead of callbacks.

var fs = require('fs');
var promisify = require('./promisify');
const fs = require('fs');
const promisify = require('./promisify');
var isCallbackMethod = function (key) {
const isCallbackMethod = (key) => {
return [

@@ -15,23 +15,15 @@ typeof fs[key] === 'function',

!key.match(/^create/),
!key.match(/^(un)?watch/)
!key.match(/^(un)?watch/),
].every(Boolean);
};
var promisifiedExists = function (path) {
return new Promise(function (resolve) {
fs.exists(path, function (data) {
resolve(data);
});
});
};
var adaptMethod = function (name) {
var original = fs[name];
const adaptMethod = (name) => {
const original = fs[name];
return promisify(original);
};
var adaptAllMethods = function () {
var adapted = {};
const adaptAllMethods = () => {
const adapted = {};
Object.keys(fs).forEach(function (key) {
Object.keys(fs).forEach((key) => {
if (isCallbackMethod(key)) {

@@ -42,3 +34,5 @@ if (key === 'exists') {

// no error object in the callback
adapted.exists = promisifiedExists;
adapted.exists = () => {
throw new Error('fs.exists() is deprecated');
};
} else {

@@ -45,0 +39,0 @@ adapted[key] = adaptMethod(key);

'use strict';
var Minimatch = require('minimatch').Minimatch;
const Minimatch = require('minimatch').Minimatch;
var convertPatternToAbsolutePath = function (basePath, pattern) {
const convertPatternToAbsolutePath = (basePath, pattern) => {
// All patterns without slash are left as they are, if pattern contain
// any slash we need to turn it into absolute path.
var hasSlash = (pattern.indexOf('/') !== -1);
var isAbsolute = /^!?\//.test(pattern);
var isNegated = /^!/.test(pattern);
var separator;
const hasSlash = (pattern.indexOf('/') !== -1);
const isAbsolute = /^!?\//.test(pattern);
const isNegated = /^!/.test(pattern);
let separator;
if (!isAbsolute && hasSlash) {
// Throw out meaningful characters from the beginning ("!", "./").
pattern = pattern.replace(/^!/, '').replace(/^\.\//, '');
const patternWithoutFirstCharacters = pattern.replace(/^!/, '').replace(/^\.\//, '');

@@ -24,5 +24,5 @@ if (/\/$/.test(basePath)) {

if (isNegated) {
return '!' + basePath + separator + pattern;
return `!${basePath}${separator}${patternWithoutFirstCharacters}`;
}
return basePath + separator + pattern;
return `${basePath}${separator}${patternWithoutFirstCharacters}`;
}

@@ -33,25 +33,27 @@

exports.create = function (basePath, patterns) {
var matchers;
exports.create = (basePath, patterns) => {
let normalizedPatterns;
if (typeof patterns === 'string') {
patterns = [patterns];
normalizedPatterns = [patterns];
} else {
normalizedPatterns = patterns;
}
matchers = patterns.map(function (pattern) {
const matchers = normalizedPatterns.map((pattern) => {
return convertPatternToAbsolutePath(basePath, pattern);
})
.map(function (pattern) {
.map((pattern) => {
return new Minimatch(pattern, {
matchBase: true,
nocomment: true,
dot: true
dot: true,
});
});
return function performMatch(absolutePath) {
var mode = 'matching';
var weHaveMatch = false;
var currentMatcher;
var i;
const performMatch = (absolutePath) => {
let mode = 'matching';
let weHaveMatch = false;
let currentMatcher;
let i;

@@ -83,2 +85,4 @@ for (i = 0; i < matchers.length; i += 1) {

};
return performMatch;
};

@@ -6,4 +6,4 @@ // Logic for unix file mode operations.

// Converts mode to string 3 characters long.
exports.normalizeFileMode = function (mode) {
var modeAsString;
exports.normalizeFileMode = (mode) => {
let modeAsString;
if (typeof mode === 'number') {

@@ -10,0 +10,0 @@ modeAsString = mode.toString(8);

'use strict';
module.exports = function (fn) {
module.exports = (fn) => {
return function () {
var i = 0;
var length = arguments.length;
var args = new Array(length);
const length = arguments.length;
const args = new Array(length);
for (; i < length; i++) {
for (let i = 0; i < length; i += 1) {
args[i] = arguments[i];
}
return new Promise(function (resolve, reject) {
args.push(function (err, data) {
return new Promise((resolve, reject) => {
args.push((err, data) => {
if (err) {

@@ -16,0 +15,0 @@ reject(err);

@@ -5,6 +5,6 @@ /* eslint no-underscore-dangle:0 */

var Readable = require('stream').Readable;
var pathUtil = require('path');
var inspect = require('../inspect');
var list = require('../list');
const Readable = require('stream').Readable;
const pathUtil = require('path');
const inspect = require('../inspect');
const list = require('../list');

@@ -15,4 +15,4 @@ // ---------------------------------------------------------

var walkSync = function (path, options, callback, currentLevel) {
var item = inspect.sync(path, options.inspectOptions);
const walkSync = (path, options, callback, currentLevel) => {
const item = inspect.sync(path, options.inspectOptions);

@@ -22,9 +22,6 @@ if (options.maxLevelsDeep === undefined) {

}
if (currentLevel === undefined) {
currentLevel = 0;
}
callback(path, item);
if (item && item.type === 'dir' && currentLevel < options.maxLevelsDeep) {
list.sync(path).forEach(function (child) {
list.sync(path).forEach((child) => {
walkSync(path + pathUtil.sep + child, options, callback, currentLevel + 1);

@@ -35,2 +32,6 @@ });

const initialWalkSync = (path, options, callback) => {
walkSync(path, options, callback, 0);
};
// ---------------------------------------------------------

@@ -40,17 +41,17 @@ // STREAM

var walkStream = function (path, options) {
var rs = new Readable({ objectMode: true });
var nextTreeNode = {
path: path,
const walkStream = (path, options) => {
const rs = new Readable({ objectMode: true });
let nextTreeNode = {
path,
parent: undefined,
level: 0
level: 0,
};
var running = false;
var readSome;
let running = false;
let readSome;
var error = function (err) {
const error = function (err) {
rs.emit('error', err);
};
var findNextUnprocessedNode = function (node) {
const findNextUnprocessedNode = (node) => {
if (node.nextSibling) {

@@ -64,4 +65,4 @@ return node.nextSibling;

var pushAndContinueMaybe = function (data) {
var theyWantMore = rs.push(data);
const pushAndContinueMaybe = (data) => {
const theyWantMore = rs.push(data);
running = false;

@@ -80,4 +81,4 @@ if (!nextTreeNode) {

readSome = function () {
var theNode = nextTreeNode;
readSome = () => {
const theNode = nextTreeNode;

@@ -87,16 +88,16 @@ running = true;

inspect.async(theNode.path, options.inspectOptions)
.then(function (inspected) {
.then((inspected) => {
theNode.inspected = inspected;
if (inspected && inspected.type === 'dir' && theNode.level < options.maxLevelsDeep) {
list.async(theNode.path)
.then(function (childrenNames) {
var children = childrenNames.map(function (name) {
.then((childrenNames) => {
const children = childrenNames.map((name) => {
return {
name: name,
name,
path: theNode.path + pathUtil.sep + name,
parent: theNode,
level: theNode.level + 1
level: theNode.level + 1,
};
});
children.forEach(function (child, index) {
children.forEach((child, index) => {
child.nextSibling = children[index + 1];

@@ -130,3 +131,3 @@ });

exports.sync = walkSync;
exports.sync = initialWalkSync;
exports.stream = walkStream;
'use strict';
var prettyPrintTypes = function (types) {
var addArticle = function (str) {
var vowels = ['a', 'e', 'i', 'o', 'u'];
const prettyPrintTypes = (types) => {
const addArticle = (str) => {
const vowels = ['a', 'e', 'i', 'o', 'u'];
if (vowels.indexOf(str[0]) !== -1) {
return 'an ' + str;
return `an ${str}`;
}
return 'a ' + str;
return `a ${str}`;
};

@@ -15,7 +15,7 @@

var isArrayOfNotation = function (typeDefinition) {
const isArrayOfNotation = (typeDefinition) => {
return /array of /.test(typeDefinition);
};
var extractTypeFromArrayOfNotation = function (typeDefinition) {
const extractTypeFromArrayOfNotation = (typeDefinition) => {
// The notation is e.g. 'array of string'

@@ -25,3 +25,3 @@ return typeDefinition.split(' of ')[1];

var isValidTypeDefinition = function (typeStr) {
const isValidTypeDefinition = (typeStr) => {
if (isArrayOfNotation(typeStr)) {

@@ -39,4 +39,4 @@ return isValidTypeDefinition(extractTypeFromArrayOfNotation(typeStr));

'null',
'undefined'
].some(function (validType) {
'undefined',
].some((validType) => {
return validType === typeStr;

@@ -46,3 +46,3 @@ });

var detectType = function (value) {
const detectType = (value) => {
if (value === null) {

@@ -60,17 +60,17 @@ return 'null';

var onlyUniqueValuesInArrayFilter = function (value, index, self) {
const onlyUniqueValuesInArrayFilter = (value, index, self) => {
return self.indexOf(value) === index;
};
var detectTypeDeep = function (value) {
var type = detectType(value);
var typesInArray;
const detectTypeDeep = (value) => {
let type = detectType(value);
let typesInArray;
if (type === 'array') {
typesInArray = value
.map(function (element) {
.map((element) => {
return detectType(element);
})
.filter(onlyUniqueValuesInArrayFilter);
type += ' of ' + typesInArray.join(', ');
type += ` of ${typesInArray.join(', ')}`;
}

@@ -81,4 +81,4 @@

var validateArray = function (argumentValue, typeToCheck) {
var allowedTypeInArray = extractTypeFromArrayOfNotation(typeToCheck);
const validateArray = (argumentValue, typeToCheck) => {
const allowedTypeInArray = extractTypeFromArrayOfNotation(typeToCheck);

@@ -89,3 +89,3 @@ if (detectType(argumentValue) !== 'array') {

return argumentValue.every(function (element) {
return argumentValue.every((element) => {
return detectType(element) === allowedTypeInArray;

@@ -95,6 +95,6 @@ });

var validateArgument = function (methodName, argumentName, argumentValue, argumentMustBe) {
var isOneOfAllowedTypes = argumentMustBe.some(function (type) {
const validateArgument = (methodName, argumentName, argumentValue, argumentMustBe) => {
const isOneOfAllowedTypes = argumentMustBe.some((type) => {
if (!isValidTypeDefinition(type)) {
throw new Error('Unknown type "' + type + '"');
throw new Error(`Unknown type "${type}"`);
}

@@ -110,16 +110,15 @@

if (!isOneOfAllowedTypes) {
throw new Error('Argument "' + argumentName + '" passed to ' + methodName + ' must be '
+ prettyPrintTypes(argumentMustBe) + '. Received ' + detectTypeDeep(argumentValue));
throw new Error(`Argument "${argumentName}" passed to ${methodName} must be ${prettyPrintTypes(argumentMustBe)}. Received ${detectTypeDeep(argumentValue)}`);
}
};
var validateOptions = function (methodName, optionsObjName, obj, allowedOptions) {
const validateOptions = (methodName, optionsObjName, obj, allowedOptions) => {
if (obj !== undefined) {
validateArgument(methodName, optionsObjName, obj, ['object']);
Object.keys(obj).forEach(function (key) {
var argName = optionsObjName + '.' + key;
if (allowedOptions.hasOwnProperty(key)) {
Object.keys(obj).forEach((key) => {
const argName = `${optionsObjName}.${key}`;
if (allowedOptions[key] !== undefined) {
validateArgument(methodName, argName, obj[key], allowedOptions[key]);
} else {
throw new Error('Unknown argument "' + argName + '" passed to ' + methodName);
throw new Error(`Unknown argument "${argName}" passed to ${methodName}`);
}

@@ -132,3 +131,3 @@ });

argument: validateArgument,
options: validateOptions
options: validateOptions,
};
'use strict';
var pathUtil = require('path');
var fs = require('./utils/fs');
var validate = require('./utils/validate');
var dir = require('./dir');
const pathUtil = require('path');
const fs = require('./utils/fs');
const validate = require('./utils/validate');
const dir = require('./dir');
var validateInput = function (methodName, path, data, options) {
var methodSignature = methodName + '(path, data, [options])';
const validateInput = (methodName, path, data, options) => {
const methodSignature = `${methodName}(path, data, [options])`;
validate.argument(methodSignature, 'path', path, ['string']);

@@ -14,3 +14,3 @@ validate.argument(methodSignature, 'data', data, ['string', 'buffer', 'object', 'array']);

atomic: ['boolean'],
jsonIndent: ['number']
jsonIndent: ['number'],
});

@@ -20,6 +20,6 @@ };

// Temporary file extensions used for atomic file overwriting.
var newExt = '.__new__';
const newExt = '.__new__';
var serializeToJsonMaybe = function (data, jsonIndent) {
var indent = jsonIndent;
const serializeToJsonMaybe = (data, jsonIndent) => {
let indent = jsonIndent;
if (typeof indent !== 'number') {

@@ -42,3 +42,3 @@ indent = 2;

var writeFileSync = function (path, data, options) {
const writeFileSync = (path, data, options) => {
try {

@@ -57,3 +57,3 @@ fs.writeFileSync(path, data, options);

var writeAtomicSync = function (path, data, options) {
const writeAtomicSync = (path, data, options) => {
// we are assuming there is file on given path, and we don't want

@@ -67,7 +67,7 @@ // to touch it until we are sure our data has been saved correctly,

var writeSync = function (path, data, options) {
var opts = options || {};
var processedData = serializeToJsonMaybe(data, opts.jsonIndent);
const writeSync = (path, data, options) => {
const opts = options || {};
const processedData = serializeToJsonMaybe(data, opts.jsonIndent);
var writeStrategy = writeFileSync;
let writeStrategy = writeFileSync;
if (opts.atomic) {

@@ -83,7 +83,7 @@ writeStrategy = writeAtomicSync;

var writeFileAsync = function (path, data, options) {
return new Promise(function (resolve, reject) {
const writeFileAsync = (path, data, options) => {
return new Promise((resolve, reject) => {
fs.writeFile(path, data, options)
.then(resolve)
.catch(function (err) {
.catch((err) => {
// First attempt to write a file ended with error.

@@ -94,3 +94,3 @@ // Check if this is not due to nonexistent parent directory.

dir.createAsync(pathUtil.dirname(path))
.then(function () {
.then(() => {
return fs.writeFile(path, data, options);

@@ -107,4 +107,4 @@ })

var writeAtomicAsync = function (path, data, options) {
return new Promise(function (resolve, reject) {
const writeAtomicAsync = (path, data, options) => {
return new Promise((resolve, reject) => {
// We are assuming there is file on given path, and we don't want

@@ -114,3 +114,3 @@ // to touch it until we are sure our data has been saved correctly,

writeFileAsync(path + newExt, data, options)
.then(function () {
.then(() => {
// ...next rename temp file to real path.

@@ -123,7 +123,7 @@ return fs.rename(path + newExt, path);

var writeAsync = function (path, data, options) {
var opts = options || {};
var processedData = serializeToJsonMaybe(data, opts.jsonIndent);
const writeAsync = (path, data, options) => {
const opts = options || {};
const processedData = serializeToJsonMaybe(data, opts.jsonIndent);
var writeStrategy = writeFileAsync;
let writeStrategy = writeFileAsync;
if (opts.atomic) {

@@ -130,0 +130,0 @@ writeStrategy = writeAtomicAsync;

'use strict';
var jetpack = require('./lib/jetpack');
const jetpack = require('./lib/jetpack');
module.exports = jetpack();
{
"name": "fs-jetpack",
"description": "Better file system API",
"version": "0.13.3",
"version": "1.0.0",
"author": "Jakub Szwacz <jakub@szwacz.com>",

@@ -11,6 +11,5 @@ "dependencies": {

"chai": "^3.5.0",
"codecov": "^1.0.1",
"eslint": "^2.13.1",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.9.2",
"codecov": "^2.2.0",
"eslint": "^3.19.0",
"eslint-config-decent-code": "szwacz/eslint-config-decent-code",
"fs-extra": "^0.16.3",

@@ -21,2 +20,3 @@ "istanbul": "^0.4.5",

"pre-commit": "^1.1.2",
"pretty-bytes": "^4.0.2",
"release-assist": "^1.0.1"

@@ -29,3 +29,3 @@ },

"test": "mocha \"spec/**/*.spec.js\"",
"test-with-coverage": "istanbul cover node_modules/.bin/_mocha -- 'spec/**/*.spec.js'",
"test-with-coverage": "istanbul cover _mocha -- 'spec/**/*.spec.js'",
"lint": "eslint .",

@@ -32,0 +32,0 @@ "lint-staged": "lint-staged",

@@ -15,3 +15,3 @@ fs-jetpack [![Build Status](https://travis-ci.org/szwacz/fs-jetpack.svg?branch=master)](https://travis-ci.org/szwacz/fs-jetpack) [![Build status](https://ci.appveyor.com/api/projects/status/er206e91fpuuqf58?svg=true)](https://ci.appveyor.com/project/szwacz/fs-jetpack) [![codecov](https://codecov.io/gh/szwacz/fs-jetpack/branch/master/graph/badge.svg)](https://codecov.io/gh/szwacz/fs-jetpack)

```javascript
var jetpack = require('fs-jetpack');
const jetpack = require('fs-jetpack');
```

@@ -29,3 +29,3 @@

```js
var data = jetpack.read('file.txt');
const data = jetpack.read('file.txt');
console.log(data);

@@ -37,3 +37,3 @@ ```

jetpack.readAsync('file.txt')
.then(function (data) {
.then((data) => {
console.log(data);

@@ -75,3 +75,3 @@ });

`options` (optional) `Object` with possible fields:
* `mode` if the file doesn't exist yet, will be created with given mode. Value could be number (eg. `0700`) or string (eg. `'700'`).
* `mode` if the file doesn't exist yet, will be created with given mode. Value could be number (eg. `0o700`) or string (eg. `'700'`).

@@ -91,3 +91,3 @@ **returns:**

`options` (optional) additional options for customization. Is an `Object` with possible fields:
* `overwrite` (default: `false`) Whether to overwrite destination path if arready exists. For directories, source directory is merged with destination directory, so files in destination which are not present in the source, will remain intact.
* `overwrite` (default: `false`) Whether to overwrite destination path when it already exists. For directories, source directory is merged with destination directory, so files in destination which are not present in the source, will remain intact.
* `matching` if defined will actually copy **only** items matching any of specified glob patterns and omit everything else ([all possible globs are described further in this readme](#matching-patterns)).

@@ -156,3 +156,3 @@

// Now let's create new CWD context...
var jetParent = jetpack.cwd('..');
const jetParent = jetpack.cwd('..');
console.log(jetParent.cwd()); // '/one/two'

@@ -163,7 +163,7 @@ // ...and use this new context.

// One CWD context can be used to create next CWD context.
var jetParentParent = jetParent.cwd('..');
const jetParentParent = jetParent.cwd('..');
console.log(jetParentParent.cwd()); // '/one'
// When many parameters specified they are treated as parts of path to resolve
var sillyCwd = jetpack.cwd('a', 'b', 'c');
const sillyCwd = jetpack.cwd('a', 'b', 'c');
console.log(sillyCwd.cwd()); // '/one/two/three/a/b/c'

@@ -182,3 +182,3 @@ ```

* `empty` (default: `false`) whether directory should be empty (no other files or directories inside). If set to `true` and directory contains any files or subdirectories all of them will be deleted.
* `mode` ensures directory has specified mode. If not set and directory already exists, current mode will be preserved. Value could be number (eg. `0700`) or string (eg. `'700'`).
* `mode` ensures directory has specified mode. If not set and directory already exists, current mode will be preserved. Value could be number (eg. `0o700`) or string (eg. `'700'`).

@@ -226,3 +226,3 @@ **returns:**

* `jsonIndent` (defaults to 2) if writing JSON data this tells how many spaces should one indentation have.
* `mode` ensures file has specified mode. If not set and file already exists, current mode will be preserved. Value could be number (eg. `0700`) or string (eg. `'700'`).
* `mode` ensures file has specified mode. If not set and file already exists, current mode will be preserved. Value could be number (eg. `0o700`) or string (eg. `'700'`).

@@ -281,3 +281,3 @@ **returns:**

// Path parameter might be omitted and CWD is used as path in that case.
var myStuffDir = jetpack.cwd('my-stuff');
const myStuffDir = jetpack.cwd('my-stuff');
myStuffDir.find({ matching: ['*.md'] });

@@ -445,3 +445,3 @@ ```

// In this example folder 'my_work' will cease to exist.
var myStuffDir = jetpack.cwd('my_stuff');
const myStuffDir = jetpack.cwd('my_stuff');
myStuffDir.remove();

@@ -448,0 +448,0 @@ ```

@@ -1,21 +0,23 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('append', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('append', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('appends String to file', function () {
var preparations = function () {
describe('appends String to file', () => {
const preparations = () => {
fse.writeFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('abcxyz');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -26,6 +28,6 @@ jetpack.append('file.txt', 'xyz');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.appendAsync('file.txt', 'xyz')
.then(function () {
.then(() => {
expectations();

@@ -37,12 +39,12 @@ done();

describe('appends Buffer to file', function () {
var preparations = function () {
describe('appends Buffer to file', () => {
const preparations = () => {
fse.writeFileSync('file.bin', new Buffer([11]));
};
var expectations = function () {
const expectations = () => {
path('file.bin').shouldBeFileWithContent(new Buffer([11, 22]));
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -53,6 +55,6 @@ jetpack.append('file.bin', new Buffer([22]));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.appendAsync('file.bin', new Buffer([22]))
.then(function () {
.then(() => {
expectations();

@@ -64,8 +66,8 @@ done();

describe("if file doesn't exist creates it", function () {
var expectations = function () {
describe("if file doesn't exist creates it", () => {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('xyz');
};
it('sync', function () {
it('sync', () => {
jetpack.append('file.txt', 'xyz');

@@ -75,5 +77,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.appendAsync('file.txt', 'xyz')
.then(function () {
.then(() => {
expectations();

@@ -85,8 +87,8 @@ done();

describe("if parent directory doesn't exist creates it", function () {
var expectations = function () {
describe("if parent directory doesn't exist creates it", () => {
const expectations = () => {
path('dir/dir/file.txt').shouldBeFileWithContent('xyz');
};
it('sync', function () {
it('sync', () => {
jetpack.append('dir/dir/file.txt', 'xyz');

@@ -96,5 +98,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.appendAsync('dir/dir/file.txt', 'xyz')
.then(function () {
.then(() => {
expectations();

@@ -106,13 +108,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b.txt').shouldBeFileWithContent('abcxyz');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -123,7 +125,7 @@ jetContext.append('b.txt', 'xyz');

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.appendAsync('b.txt', 'xyz')
.then(function () {
.then(() => {
expectations();

@@ -135,15 +137,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.append, methodName: 'append' },
{ type: 'async', method: jetpack.appendAsync, methodName: 'appendAsync' }
{ type: 'async', method: jetpack.appendAsync, methodName: 'appendAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'xyz');
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, data, [options]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, data, [options]) must be a string. Received undefined`);
});

@@ -153,9 +154,8 @@ });

describe('"data" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"data" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc');
}).to.throw('Argument "data" passed to ' + test.methodName
+ '(path, data, [options]) must be a string or a buffer. Received undefined');
}).to.throw(`Argument "data" passed to ${test.methodName}(path, data, [options]) must be a string or a buffer. Received undefined`);
});

@@ -165,10 +165,9 @@ });

describe('"options" object', function () {
describe('"mode" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"mode" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', 'xyz', { mode: true });
}).to.throw('Argument "options.mode" passed to ' + test.methodName
+ '(path, data, [options]) must be a string or a number. Received boolean');
}).to.throw(`Argument "options.mode" passed to ${test.methodName}(path, data, [options]) must be a string or a number. Received boolean`);
});

@@ -181,8 +180,8 @@ });

if (process.platform !== 'win32') {
describe('sets file mode on created file (unix only)', function () {
var expectations = function () {
describe('sets file mode on created file (unix only)', () => {
const expectations = () => {
path('file.txt').shouldHaveMode('711');
};
it('sync', function () {
it('sync', () => {
jetpack.append('file.txt', 'abc', { mode: '711' });

@@ -192,5 +191,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.appendAsync('file.txt', 'abc', { mode: '711' })
.then(function () {
.then(() => {
expectations();

@@ -197,0 +196,0 @@ done();

@@ -1,10 +0,11 @@

var fs = require('fs');
'use strict';
var areBuffersEqual = function (bufA, bufB) {
var i;
var len = bufA.length;
const fs = require('fs');
const areBuffersEqual = (bufA, bufB) => {
const len = bufA.length;
if (len !== bufB.length) {
return false;
}
for (i = 0; i < len; i++) {
for (let i = 0; i < len; i += 1) {
if (bufA.readUInt8(i) !== bufB.readUInt8(i)) {

@@ -17,9 +18,9 @@ return false;

module.exports = function (path) {
module.exports = (path) => {
return {
shouldNotExist: function () {
var message;
shouldNotExist: () => {
let message;
try {
fs.statSync(path);
message = 'Path ' + path + ' should NOT exist';
message = `Path ${path} should NOT exist`;
} catch (err) {

@@ -35,13 +36,13 @@ if (err.code !== 'ENOENT') {

shouldBeDirectory: function () {
var message;
var stat;
shouldBeDirectory: () => {
let message;
let stat;
try {
stat = fs.statSync(path);
if (!stat.isDirectory()) {
message = 'Path ' + path + ' should be a directory';
message = `Path ${path} should be a directory`;
}
} catch (err) {
if (err.code === 'ENOENT') {
message = 'Path ' + path + ' should exist';
message = `Path ${path} should exist`;
} else {

@@ -56,9 +57,8 @@ throw err;

shouldBeFileWithContent: function (expectedContent) {
var message;
var content;
shouldBeFileWithContent: (expectedContent) => {
let message;
let content;
var generateMessage = function (expected, found) {
message = 'File ' + path + ' should have content "'
+ expected + '" but have instead "' + found + '"';
const generateMessage = (expected, found) => {
message = `File ${path} should have content "${expected}" but found "${found}"`;
};

@@ -80,3 +80,3 @@

if (err.code === 'ENOENT') {
message = 'File ' + path + ' should exist';
message = `File ${path} should exist`;
} else {

@@ -91,5 +91,6 @@ throw err;

shouldHaveMode: function (expectedMode) {
var mode;
var message;
shouldHaveMode: (expectedMode) => {
let mode;
let message;
try {

@@ -99,8 +100,7 @@ mode = fs.statSync(path).mode.toString(8);

if (mode !== expectedMode) {
message = 'Path ' + path + ' should have mode "'
+ expectedMode + '" but have instead "' + mode + '"';
message = `Path ${path} should have mode "${expectedMode}" but have instead "${mode}"`;
}
} catch (err) {
if (err.code === 'ENOENT') {
message = 'Path ' + path + ' should exist';
message = `Path ${path} should exist`;
} else {

@@ -113,4 +113,4 @@ throw err;

}
}
},
};
};

@@ -1,17 +0,19 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('copy', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('copy', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('copies a file', function () {
var preparations = function () {
describe('copies a file', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('abc');

@@ -21,3 +23,3 @@ path('file_copied.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -28,6 +30,6 @@ jetpack.copy('file.txt', 'file_copied.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('file.txt', 'file_copied.txt')
.then(function () {
.then(() => {
expectations();

@@ -39,8 +41,8 @@ done();

describe('can copy file to nonexistent directory (will create directory)', function () {
var preparations = function () {
describe('can copy file to nonexistent directory (will create directory)', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('abc');

@@ -50,3 +52,3 @@ path('dir/dir/file.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -57,6 +59,6 @@ jetpack.copy('file.txt', 'dir/dir/file.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('file.txt', 'dir/dir/file.txt')
.then(function () {
.then(() => {
expectations();

@@ -68,12 +70,12 @@ done();

describe('copies empty directory', function () {
var preparations = function () {
describe('copies empty directory', () => {
const preparations = () => {
fse.mkdirsSync('dir');
};
var expectations = function () {
const expectations = () => {
path('copied/dir').shouldBeDirectory();
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -84,6 +86,6 @@ jetpack.copy('dir', 'copied/dir');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('dir', 'copied/dir')
.then(function () {
.then(() => {
expectations();

@@ -95,4 +97,4 @@ done();

describe('copies a tree of files', function () {
var preparations = function () {
describe('copies a tree of files', () => {
const preparations = () => {
fse.outputFileSync('a/f1.txt', 'abc');

@@ -103,3 +105,3 @@ fse.outputFileSync('a/b/f2.txt', '123');

var expectations = function () {
const expectations = () => {
path('copied/a/f1.txt').shouldBeFileWithContent('abc');

@@ -110,3 +112,3 @@ path('copied/a/b/c').shouldBeDirectory();

it('sync', function () {
it('sync', () => {
preparations();

@@ -117,6 +119,6 @@ jetpack.copy('a', 'copied/a');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('a', 'copied/a')
.then(function () {
.then(() => {
expectations();

@@ -128,4 +130,4 @@ done();

describe("generates nice error if source path doesn't exist", function () {
var expectations = function (err) {
describe("generates nice error if source path doesn't exist", () => {
const expectations = (err) => {
expect(err.code).to.equal('ENOENT');

@@ -135,3 +137,3 @@ expect(err.message).to.have.string("Path to copy doesn't exist");

it('sync', function () {
it('sync', () => {
try {

@@ -145,5 +147,5 @@ jetpack.copy('a', 'b');

it('async', function (done) {
it('async', (done) => {
jetpack.copyAsync('a', 'b')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -155,8 +157,8 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b.txt').shouldBeFileWithContent('abc');

@@ -166,4 +168,4 @@ path('a/x.txt').shouldBeFileWithContent('abc');

it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -174,7 +176,7 @@ jetContext.copy('b.txt', 'x.txt');

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.copyAsync('b.txt', 'x.txt')
.then(function () {
.then(() => {
expectations();

@@ -186,5 +188,5 @@ done();

describe('overwriting behaviour', function () {
describe('does not overwrite by default', function () {
var preparations = function () {
describe('overwriting behaviour', () => {
describe('does not overwrite by default', () => {
const preparations = () => {
fse.outputFileSync('a/file.txt', 'abc');

@@ -194,3 +196,3 @@ fse.mkdirsSync('b');

var expectations = function (err) {
const expectations = (err) => {
expect(err.code).to.equal('EEXIST');

@@ -200,3 +202,3 @@ expect(err.message).to.have.string('Destination path already exists');

it('sync', function () {
it('sync', () => {
preparations();

@@ -211,6 +213,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('a', 'b')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -222,4 +224,4 @@ done();

describe('overwrites if it was specified', function () {
var preparations = function () {
describe('overwrites if it was specified', () => {
const preparations = () => {
fse.outputFileSync('a/file.txt', 'abc');

@@ -229,3 +231,3 @@ fse.outputFileSync('b/file.txt', 'xyz');

var expectations = function () {
const expectations = () => {
path('a/file.txt').shouldBeFileWithContent('abc');

@@ -235,3 +237,3 @@ path('b/file.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -242,6 +244,6 @@ jetpack.copy('a', 'b', { overwrite: true });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('a', 'b', { overwrite: true })
.then(function () {
.then(() => {
expectations();

@@ -254,5 +256,5 @@ done();

describe('filter what to copy', function () {
describe('by simple pattern', function () {
var preparations = function () {
describe('filter what to copy', () => {
describe('by simple pattern', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', '1');

@@ -264,3 +266,3 @@ fse.outputFileSync('dir/file.md', 'm1');

var expectations = function () {
const expectations = () => {
path('copy/file.txt').shouldBeFileWithContent('1');

@@ -272,3 +274,3 @@ path('copy/file.md').shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -279,6 +281,6 @@ jetpack.copy('dir', 'copy', { matching: '*.txt' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('dir', 'copy', { matching: '*.txt' })
.then(function () {
.then(() => {
expectations();

@@ -290,4 +292,4 @@ done();

describe('by pattern anchored to copied directory', function () {
var preparations = function () {
describe('by pattern anchored to copied directory', () => {
const preparations = () => {
fse.outputFileSync('x/y/dir/file.txt', '1');

@@ -298,3 +300,3 @@ fse.outputFileSync('x/y/dir/a/file.txt', '2');

var expectations = function () {
const expectations = () => {
path('copy/file.txt').shouldNotExist();

@@ -305,3 +307,3 @@ path('copy/a/file.txt').shouldBeFileWithContent('2');

it('sync', function () {
it('sync', () => {
preparations();

@@ -312,6 +314,6 @@ jetpack.copy('x/y/dir', 'copy', { matching: 'a/*.txt' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('x/y/dir', 'copy', { matching: 'a/*.txt' })
.then(function () {
.then(() => {
expectations();

@@ -323,4 +325,4 @@ done();

describe('can use ./ as indication of anchor directory', function () {
var preparations = function () {
describe('can use ./ as indication of anchor directory', () => {
const preparations = () => {
fse.outputFileSync('x/y/a.txt', '123');

@@ -330,3 +332,3 @@ fse.outputFileSync('x/y/b/a.txt', '456');

var expectations = function () {
const expectations = () => {
path('copy/a.txt').shouldBeFileWithContent('123');

@@ -336,3 +338,3 @@ path('copy/b/a.txt').shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -343,6 +345,6 @@ jetpack.copy('x/y', 'copy', { matching: './a.txt' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('x/y', 'copy', { matching: './a.txt' })
.then(function () {
.then(() => {
expectations();

@@ -354,4 +356,4 @@ done();

describe('matching works also if copying single file', function () {
var preparations = function () {
describe('matching works also if copying single file', () => {
const preparations = () => {
fse.outputFileSync('a', '123');

@@ -361,3 +363,3 @@ fse.outputFileSync('x', '456');

var expectations = function () {
const expectations = () => {
path('a-copy').shouldNotExist();

@@ -367,3 +369,3 @@ path('x-copy').shouldBeFileWithContent('456');

it('sync', function () {
it('sync', () => {
preparations();

@@ -375,9 +377,9 @@ jetpack.copy('a', 'a-copy', { matching: 'x' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('a', 'a-copy', { matching: 'x' })
.then(function () {
.then(() => {
return jetpack.copyAsync('x', 'x-copy', { matching: 'x' });
})
.then(function () {
.then(() => {
expectations();

@@ -389,4 +391,4 @@ done();

describe('can use negation in patterns', function () {
var preparations = function () {
describe('can use negation in patterns', () => {
const preparations = () => {
fse.mkdirsSync('x/y/dir/a/b');

@@ -398,3 +400,3 @@ fse.mkdirsSync('x/y/dir/a/x');

var expectations = function () {
const expectations = () => {
path('copy/dir/a/b').shouldBeDirectory();

@@ -406,3 +408,3 @@ path('copy/dir/a/x').shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -415,4 +417,4 @@ jetpack.copy('x/y', 'copy', {

'!dir/a/y',
'!./dir/a/z'
]
'!./dir/a/z',
],
});

@@ -422,3 +424,3 @@ expectations();

it('async', function (done) {
it('async', (done) => {
preparations();

@@ -431,6 +433,6 @@ jetpack.copyAsync('x/y', 'copy', {

'!dir/a/y',
'!./dir/a/z'
]
'!./dir/a/z',
],
})
.then(function () {
.then(() => {
expectations();

@@ -442,4 +444,4 @@ done();

describe('wildcard copies everything', function () {
var preparations = function () {
describe('wildcard copies everything', () => {
const preparations = () => {
// Just a file

@@ -453,3 +455,3 @@ fse.outputFileSync('x/file.txt', '123');

var expectations = function () {
const expectations = () => {
path('copy/file.txt').shouldBeFileWithContent('123');

@@ -460,3 +462,3 @@ path('copy/y/.dot').shouldBeFileWithContent('dot');

it('sync', function () {
it('sync', () => {
preparations();

@@ -467,6 +469,6 @@ jetpack.copy('x', 'copy', { matching: '**' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('x', 'copy', { matching: '**' })
.then(function () {
.then(() => {
expectations();

@@ -479,8 +481,8 @@ done();

describe('can copy symlink', function () {
var preparations = function () {
describe('can copy symlink', () => {
const preparations = () => {
fse.mkdirsSync('to_copy');
fse.symlinkSync('some/file', 'to_copy/symlink');
};
var expectations = function () {
const expectations = () => {
expect(fse.lstatSync('copied/symlink').isSymbolicLink()).to.equal(true);

@@ -490,3 +492,3 @@ expect(fse.readlinkSync('copied/symlink')).to.equal(helper.osSep('some/file'));

it('sync', function () {
it('sync', () => {
preparations();

@@ -497,6 +499,6 @@ jetpack.copy('to_copy', 'copied');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('to_copy', 'copied')
.then(function () {
.then(() => {
expectations();

@@ -508,4 +510,4 @@ done();

describe('can overwrite symlink', function () {
var preparations = function () {
describe('can overwrite symlink', () => {
const preparations = () => {
fse.mkdirsSync('to_copy');

@@ -517,3 +519,3 @@ fse.symlinkSync('some/file', 'to_copy/symlink');

var expectations = function () {
const expectations = () => {
expect(fse.lstatSync('copied/symlink').isSymbolicLink()).to.equal(true);

@@ -523,3 +525,3 @@ expect(fse.readlinkSync('copied/symlink')).to.equal(helper.osSep('some/file'));

it('sync', function () {
it('sync', () => {
preparations();

@@ -530,6 +532,6 @@ jetpack.copy('to_copy', 'copied', { overwrite: true });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('to_copy', 'copied', { overwrite: true })
.then(function () {
.then(() => {
expectations();

@@ -542,4 +544,4 @@ done();

if (process.platform !== 'win32') {
describe('copies also file permissions (unix only)', function () {
var preparations = function () {
describe('copies also file permissions (unix only)', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');

@@ -550,3 +552,3 @@ fse.chmodSync('a/b', '700');

var expectations = function () {
const expectations = () => {
path('x/b').shouldHaveMode('700');

@@ -556,3 +558,3 @@ path('x/b/c.txt').shouldHaveMode('711');

it('sync', function () {
it('sync', () => {
preparations();

@@ -563,6 +565,6 @@ jetpack.copy('a', 'x');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.copyAsync('a', 'x')
.then(function () {
.then(() => {
expectations();

@@ -575,15 +577,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.copy, methodName: 'copy' },
{ type: 'async', method: jetpack.copyAsync, methodName: 'copyAsync' }
{ type: 'async', method: jetpack.copyAsync, methodName: 'copyAsync' },
];
describe('"from" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"from" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'xyz');
}).to.throw('Argument "from" passed to ' + test.methodName
+ '(from, to, [options]) must be a string. Received undefined');
}).to.throw(`Argument "from" passed to ${test.methodName}(from, to, [options]) must be a string. Received undefined`);
});

@@ -593,9 +594,8 @@ });

describe('"to" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"to" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc');
}).to.throw('Argument "to" passed to ' + test.methodName
+ '(from, to, [options]) must be a string. Received undefined');
}).to.throw(`Argument "to" passed to ${test.methodName}(from, to, [options]) must be a string. Received undefined`);
});

@@ -605,20 +605,18 @@ });

describe('"options" object', function () {
describe('"overwrite" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"overwrite" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', 'xyz', { overwrite: 1 });
}).to.throw('Argument "options.overwrite" passed to ' + test.methodName
+ '(from, to, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.overwrite" passed to ${test.methodName}(from, to, [options]) must be a boolean. Received number`);
});
});
});
describe('"matching" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"matching" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', 'xyz', { matching: 1 });
}).to.throw('Argument "options.matching" passed to ' + test.methodName
+ '(from, to, [options]) must be a string or an array of string. Received number');
}).to.throw(`Argument "options.matching" passed to ${test.methodName}(from, to, [options]) must be a string or an array of string. Received number`);
});

@@ -625,0 +623,0 @@ });

@@ -1,12 +0,14 @@

var pathUtil = require('path');
var expect = require('chai').expect;
var jetpack = require('..');
'use strict';
describe('cwd', function () {
it('returns the same path as process.cwd for main instance of jetpack', function () {
const pathUtil = require('path');
const expect = require('chai').expect;
const jetpack = require('..');
describe('cwd', () => {
it('returns the same path as process.cwd for main instance of jetpack', () => {
expect(jetpack.cwd()).to.equal(process.cwd());
});
it('can create new context with different cwd', function () {
var jetCwd = jetpack.cwd('/'); // absolute path
it('can create new context with different cwd', () => {
let jetCwd = jetpack.cwd('/'); // absolute path
expect(jetCwd.cwd()).to.equal(pathUtil.resolve(process.cwd(), '/'));

@@ -20,17 +22,14 @@

it('cwd contexts can be created recursively', function () {
var jetCwd1;
var jetCwd2;
jetCwd1 = jetpack.cwd('..');
it('cwd contexts can be created recursively', () => {
const jetCwd1 = jetpack.cwd('..');
expect(jetCwd1.cwd()).to.equal(pathUtil.resolve(process.cwd(), '..'));
jetCwd2 = jetCwd1.cwd('..');
const jetCwd2 = jetCwd1.cwd('..');
expect(jetCwd2.cwd()).to.equal(pathUtil.resolve(process.cwd(), '../..'));
});
it('cwd can join path parts', function () {
var jetCwd = jetpack.cwd('a', 'b', 'c');
it('cwd can join path parts', () => {
const jetCwd = jetpack.cwd('a', 'b', 'c');
expect(jetCwd.cwd()).to.equal(pathUtil.resolve(process.cwd(), 'a', 'b', 'c'));
});
});

@@ -1,18 +0,20 @@

var fse = require('fs-extra');
var pathUtil = require('path');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('dir', function () {
const fse = require('fs-extra');
const pathUtil = require('path');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('dir', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe("creates directory if it doesn't exist", function () {
var expectations = function () {
describe("creates directory if it doesn't exist", () => {
const expectations = () => {
path('x').shouldBeDirectory();
};
it('sync', function () {
it('sync', () => {
jetpack.dir('x');

@@ -22,5 +24,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.dirAsync('x')
.then(function () {
.then(() => {
expectations();

@@ -32,12 +34,12 @@ done();

describe('does nothing if directory already exists', function () {
var preparations = function () {
describe('does nothing if directory already exists', () => {
const preparations = () => {
fse.mkdirsSync('x');
};
var expectations = function () {
const expectations = () => {
path('x').shouldBeDirectory();
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -48,6 +50,6 @@ jetpack.dir('x');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('x')
.then(function () {
.then(() => {
expectations();

@@ -59,8 +61,8 @@ done();

describe('creates nested directories if necessary', function () {
var expectations = function () {
describe('creates nested directories if necessary', () => {
const expectations = () => {
path('a/b/c').shouldBeDirectory();
};
it('sync', function () {
it('sync', () => {
jetpack.dir('a/b/c');

@@ -70,5 +72,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.dirAsync('a/b/c')
.then(function () {
.then(() => {
expectations();

@@ -80,10 +82,10 @@ done();

describe('handles well two calls racing to create the same directory', function () {
var expectations = function () {
describe('handles well two calls racing to create the same directory', () => {
const expectations = () => {
path('a/b/c').shouldBeDirectory();
};
it('async', function (done) {
var doneCount = 0;
var check = function () {
it('async', (done) => {
let doneCount = 0;
const check = () => {
doneCount += 1;

@@ -100,4 +102,4 @@ if (doneCount === 2) {

describe("doesn't touch directory content by default", function () {
var preparations = function () {
describe("doesn't touch directory content by default", () => {
const preparations = () => {
fse.mkdirsSync('a/b');

@@ -107,3 +109,3 @@ fse.outputFileSync('a/c.txt', 'abc');

var expectations = function () {
const expectations = () => {
path('a/b').shouldBeDirectory();

@@ -113,3 +115,3 @@ path('a/c.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -120,6 +122,6 @@ jetpack.dir('a');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('a')
.then(function () {
.then(() => {
expectations();

@@ -131,8 +133,8 @@ done();

describe('makes directory empty if that option specified', function () {
var preparations = function () {
describe('makes directory empty if that option specified', () => {
const preparations = () => {
fse.outputFileSync('a/b/file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b/file.txt').shouldNotExist();

@@ -142,3 +144,3 @@ path('a').shouldBeDirectory();

it('sync', function () {
it('sync', () => {
preparations();

@@ -149,6 +151,6 @@ jetpack.dir('a', { empty: true });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('a', { empty: true })
.then(function () {
.then(() => {
expectations();

@@ -160,12 +162,12 @@ done();

describe('throws if given path is something other than directory', function () {
var preparations = function () {
describe('throws if given path is something other than directory', () => {
const preparations = () => {
fse.outputFileSync('a', 'abc');
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.message).to.have.string('exists but is not a directory');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -180,6 +182,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('a')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -191,9 +193,9 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var expectations = function () {
describe('respects internal CWD of jetpack instance', () => {
const expectations = () => {
path('a/b').shouldBeDirectory();
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
jetContext.dir('b');

@@ -203,6 +205,6 @@ expectations();

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
jetContext.dirAsync('b')
.then(function () {
.then(() => {
expectations();

@@ -214,14 +216,14 @@ done();

describe('returns jetack instance pointing on this directory', function () {
var expectations = function (jetpackContext) {
describe('returns jetack instance pointing on this directory', () => {
const expectations = (jetpackContext) => {
expect(jetpackContext.cwd()).to.equal(pathUtil.resolve('a'));
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.dir('a'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.dirAsync('a')
.then(function (jetpackContext) {
.then((jetpackContext) => {
expectations(jetpackContext);

@@ -235,8 +237,8 @@ done();

if (process.platform !== 'win32') {
describe('sets mode to newly created directory (unix only)', function () {
var expectations = function () {
describe('sets mode to newly created directory (unix only)', () => {
const expectations = () => {
path('a').shouldHaveMode('511');
};
it('sync, mode passed as string', function () {
it('sync, mode passed as string', () => {
jetpack.dir('a', { mode: '511' });

@@ -246,10 +248,10 @@ expectations();

it('sync, mode passed as number', function () {
jetpack.dir('a', { mode: parseInt('511', 8) });
it('sync, mode passed as number', () => {
jetpack.dir('a', { mode: 0o511 });
expectations();
});
it('async, mode passed as string', function (done) {
it('async, mode passed as string', (done) => {
jetpack.dirAsync('a', { mode: '511' })
.then(function () {
.then(() => {
expectations();

@@ -260,5 +262,5 @@ done();

it('async, mode passed as number', function (done) {
jetpack.dirAsync('a', { mode: parseInt('511', 8) })
.then(function () {
it('async, mode passed as number', (done) => {
jetpack.dirAsync('a', { mode: 0o511 })
.then(() => {
expectations();

@@ -270,4 +272,4 @@ done();

describe('sets desired mode to every created directory (unix only)', function () {
var expectations = function () {
describe('sets desired mode to every created directory (unix only)', () => {
const expectations = () => {
path('a').shouldHaveMode('711');

@@ -277,3 +279,3 @@ path('a/b').shouldHaveMode('711');

it('sync', function () {
it('sync', () => {
jetpack.dir('a/b', { mode: '711' });

@@ -283,5 +285,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.dirAsync('a/b', { mode: '711' })
.then(function () {
.then(() => {
expectations();

@@ -293,11 +295,11 @@ done();

describe('changes mode of existing directory to desired (unix only)', function () {
var preparations = function () {
describe('changes mode of existing directory to desired (unix only)', () => {
const preparations = () => {
fse.mkdirSync('a', '777');
};
var expectations = function () {
const expectations = () => {
path('a').shouldHaveMode('511');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -308,6 +310,6 @@ jetpack.dir('a', { mode: '511' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('a', { mode: '511' })
.then(function () {
.then(() => {
expectations();

@@ -319,12 +321,12 @@ done();

describe('leaves mode of directory intact by default (unix only)', function () {
var preparations = function () {
describe('leaves mode of directory intact by default (unix only)', () => {
const preparations = () => {
fse.mkdirSync('a', '700');
};
var expectations = function () {
const expectations = () => {
path('a').shouldHaveMode('700');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -335,6 +337,6 @@ jetpack.dir('a');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.dirAsync('a')
.then(function () {
.then(() => {
expectations();

@@ -346,8 +348,8 @@ done();

} else {
describe('specyfying mode have no effect and throws no error (windows only)', function () {
var expectations = function () {
describe('specyfying mode have no effect and throws no error (windows only)', () => {
const expectations = () => {
path('x').shouldBeDirectory();
};
it('sync', function () {
it('sync', () => {
jetpack.dir('x', { mode: '511' });

@@ -357,5 +359,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.dirAsync('x', { mode: '511' })
.then(function () {
.then(() => {
expectations();

@@ -368,15 +370,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.dir, methodName: 'dir' },
{ type: 'async', method: jetpack.dirAsync, methodName: 'dirAsync' }
{ type: 'async', method: jetpack.dirAsync, methodName: 'dirAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, [criteria]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, [criteria]) must be a string. Received undefined`);
});

@@ -386,20 +387,18 @@ });

describe('"criteria" object', function () {
describe('"empty" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"criteria" object', () => {
describe('"empty" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { empty: 1 });
}).to.throw('Argument "criteria.empty" passed to ' + test.methodName
+ '(path, [criteria]) must be a boolean. Received number');
}).to.throw(`Argument "criteria.empty" passed to ${test.methodName}(path, [criteria]) must be a boolean. Received number`);
});
});
});
describe('"mode" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"mode" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { mode: true });
}).to.throw('Argument "criteria.mode" passed to ' + test.methodName
+ '(path, [criteria]) must be a string or a number. Received boolean');
}).to.throw(`Argument "criteria.mode" passed to ${test.methodName}(path, [criteria]) must be a string or a number. Received boolean`);
});

@@ -406,0 +405,0 @@ });

@@ -1,22 +0,24 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('exists', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('exists', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe("returns false if file doesn't exist", function () {
var expectations = function (exists) {
describe("returns false if file doesn't exist", () => {
const expectations = (exists) => {
expect(exists).to.equal(false);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.exists('file.txt'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.existsAsync('file.txt')
.then(function (exists) {
.then((exists) => {
expectations(exists);

@@ -28,12 +30,12 @@ done();

describe("returns 'dir' if directory exists on given path", function () {
var preparations = function () {
describe("returns 'dir' if directory exists on given path", () => {
const preparations = () => {
fse.mkdirsSync('a');
};
var expectations = function (exists) {
const expectations = (exists) => {
expect(exists).to.equal('dir');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -43,6 +45,6 @@ expectations(jetpack.exists('a'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.existsAsync('a')
.then(function (exists) {
.then((exists) => {
expectations(exists);

@@ -54,12 +56,12 @@ done();

describe("returns 'file' if file exists on given path", function () {
var preparations = function () {
describe("returns 'file' if file exists on given path", () => {
const preparations = () => {
fse.outputFileSync('text.txt', 'abc');
};
var expectations = function (exists) {
const expectations = (exists) => {
expect(exists).to.equal('file');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -69,6 +71,6 @@ expectations(jetpack.exists('text.txt'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.existsAsync('text.txt')
.then(function (exists) {
.then((exists) => {
expectations(exists);

@@ -80,13 +82,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/text.txt', 'abc');
};
var expectations = function (exists) {
const expectations = (exists) => {
expect(exists).to.equal('file');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -96,7 +98,7 @@ expectations(jetContext.exists('text.txt'));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.existsAsync('text.txt')
.then(function (exists) {
.then((exists) => {
expectations(exists);

@@ -108,15 +110,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.exists, methodName: 'exists' },
{ type: 'async', method: jetpack.existsAsync, methodName: 'existsAsync' }
{ type: 'async', method: jetpack.existsAsync, methodName: 'existsAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path) must be a string. Received undefined`);
});

@@ -123,0 +124,0 @@ });

@@ -1,17 +0,19 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('file', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('file', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe("creates file if it doesn't exist", function () {
var expectations = function () {
describe("creates file if it doesn't exist", () => {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('');
};
it('sync', function () {
it('sync', () => {
jetpack.file('file.txt');

@@ -21,5 +23,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file.txt')
.then(function () {
.then(() => {
expectations();

@@ -32,12 +34,12 @@ done();

describe('leaves file intact if it already exists', function () {
var preparations = function () {
describe('leaves file intact if it already exists', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('abc');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -48,6 +50,6 @@ jetpack.file('file.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.fileAsync('file.txt')
.then(function () {
.then(() => {
expectations();

@@ -60,8 +62,8 @@ done();

describe('can save file content given as string', function () {
var expectations = function () {
describe('can save file content given as string', () => {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('ąbć');
};
it('sync', function () {
it('sync', () => {
jetpack.file('file.txt', { content: 'ąbć' });

@@ -71,5 +73,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file.txt', { content: 'ąbć' })
.then(function () {
.then(() => {
expectations();

@@ -82,8 +84,8 @@ done();

describe('can save file content given as buffer', function () {
var expectations = function () {
describe('can save file content given as buffer', () => {
const expectations = () => {
path('file').shouldBeFileWithContent(new Buffer([11, 22]));
};
it('sync', function () {
it('sync', () => {
jetpack.file('file', { content: new Buffer([11, 22]) });

@@ -93,5 +95,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file', { content: new Buffer([11, 22]) })
.then(function () {
.then(() => {
expectations();

@@ -104,14 +106,14 @@ done();

describe('can save file content given as plain JS object (will be saved as JSON)', function () {
var obj = {
describe('can save file content given as plain JS object (will be saved as JSON)', () => {
const obj = {
a: 'abc',
b: 123
b: 123,
};
var expectations = function () {
var data = JSON.parse(fse.readFileSync('file.txt', 'utf8'));
const expectations = () => {
const data = JSON.parse(fse.readFileSync('file.txt', 'utf8'));
expect(data).to.eql(obj);
};
it('sync', function () {
it('sync', () => {
jetpack.file('file.txt', { content: obj });

@@ -121,5 +123,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file.txt', { content: obj })
.then(function () {
.then(() => {
expectations();

@@ -132,12 +134,12 @@ done();

describe('written JSON data can be indented', function () {
var obj = {
describe('written JSON data can be indented', () => {
const obj = {
a: 'abc',
b: 123
b: 123,
};
var expectations = function () {
var sizeA = fse.statSync('a.json').size;
var sizeB = fse.statSync('b.json').size;
var sizeC = fse.statSync('c.json').size;
const expectations = () => {
const sizeA = fse.statSync('a.json').size;
const sizeB = fse.statSync('b.json').size;
const sizeC = fse.statSync('c.json').size;
expect(sizeB).to.be.above(sizeA);

@@ -147,3 +149,3 @@ expect(sizeC).to.be.above(sizeB);

it('sync', function () {
it('sync', () => {
jetpack.file('a.json', { content: obj, jsonIndent: 0 });

@@ -155,11 +157,11 @@ jetpack.file('b.json', { content: obj }); // Default indent = 2

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('a.json', { content: obj, jsonIndent: 0 })
.then(function () {
.then(() => {
return jetpack.fileAsync('b.json', { content: obj }); // Default indent = 2
})
.then(function () {
.then(() => {
return jetpack.fileAsync('c.json', { content: obj, jsonIndent: 4 });
})
.then(function () {
.then(() => {
expectations();

@@ -172,12 +174,12 @@ done();

describe('replaces content of already existing file', function () {
var preparations = function () {
describe('replaces content of already existing file', () => {
const preparations = () => {
fse.writeFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('123');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -188,6 +190,6 @@ jetpack.file('file.txt', { content: '123' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.fileAsync('file.txt', { content: '123' })
.then(function () {
.then(() => {
expectations();

@@ -200,12 +202,12 @@ done();

describe('throws if given path is not a file', function () {
var preparations = function () {
describe('throws if given path is not a file', () => {
const preparations = () => {
fse.mkdirsSync('a');
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.message).to.have.string('exists but is not a file.');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -220,6 +222,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.fileAsync('a')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -232,8 +234,8 @@ done();

describe("if directory for file doesn't exist creates it as well", function () {
var expectations = function () {
describe("if directory for file doesn't exist creates it as well", () => {
const expectations = () => {
path('a/b/c.txt').shouldBeFileWithContent('');
};
it('sync', function () {
it('sync', () => {
jetpack.file('a/b/c.txt');

@@ -243,5 +245,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('a/b/c.txt')
.then(function () {
.then(() => {
expectations();

@@ -254,14 +256,14 @@ done();

describe('returns currently used jetpack instance', function () {
var expectations = function (jetpackContext) {
describe('returns currently used jetpack instance', () => {
const expectations = (jetpackContext) => {
expect(jetpackContext).to.equal(jetpack);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.file('file.txt'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file.txt')
.then(function (jetpackContext) {
.then((jetpackContext) => {
expectations(jetpackContext);

@@ -274,9 +276,9 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var expectations = function () {
describe('respects internal CWD of jetpack instance', () => {
const expectations = () => {
path('a/b.txt').shouldBeFileWithContent('');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
jetContext.file('b.txt');

@@ -286,6 +288,6 @@ expectations();

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
jetContext.fileAsync('b.txt')
.then(function () {
.then(() => {
expectations();

@@ -299,8 +301,8 @@ done();

if (process.platform !== 'win32') {
describe('sets mode of newly created file (unix only)', function () {
var expectations = function () {
describe('sets mode of newly created file (unix only)', () => {
const expectations = () => {
path('file.txt').shouldHaveMode('711');
};
it('sync, mode passed as string', function () {
it('sync, mode passed as string', () => {
jetpack.file('file.txt', { mode: '711' });

@@ -310,10 +312,10 @@ expectations();

it('sync, mode passed as number', function () {
jetpack.file('file.txt', { mode: parseInt('711', 8) });
it('sync, mode passed as number', () => {
jetpack.file('file.txt', { mode: 0o711 });
expectations();
});
it('async, mode passed as string', function (done) {
it('async, mode passed as string', (done) => {
jetpack.fileAsync('file.txt', { mode: '711' })
.then(function () {
.then(() => {
expectations();

@@ -325,5 +327,5 @@ done();

it('async, mode passed as number', function (done) {
jetpack.fileAsync('file.txt', { mode: parseInt('711', 8) })
.then(function () {
it('async, mode passed as number', (done) => {
jetpack.fileAsync('file.txt', { mode: 0o711 })
.then(() => {
expectations();

@@ -336,12 +338,12 @@ done();

describe("changes mode of existing file if it doesn't match (unix only)", function () {
var preparations = function () {
describe("changes mode of existing file if it doesn't match (unix only)", () => {
const preparations = () => {
fse.writeFileSync('file.txt', 'abc', { mode: '700' });
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldHaveMode('511');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -352,6 +354,6 @@ jetpack.file('file.txt', { mode: '511' });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.fileAsync('file.txt', { mode: '511' })
.then(function () {
.then(() => {
expectations();

@@ -364,12 +366,12 @@ done();

describe('leaves mode of file intact if not explicitly specified (unix only)', function () {
var preparations = function () {
describe('leaves mode of file intact if not explicitly specified (unix only)', () => {
const preparations = () => {
fse.writeFileSync('file.txt', 'abc', { mode: '700' });
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldHaveMode('700');
};
it('sync, ensure exists', function () {
it('sync, ensure exists', () => {
preparations();

@@ -380,3 +382,3 @@ jetpack.file('file.txt');

it('sync, ensure content', function () {
it('sync, ensure content', () => {
preparations();

@@ -387,6 +389,6 @@ jetpack.file('file.txt', { content: 'abc' });

it('async, ensure exists', function (done) {
it('async, ensure exists', (done) => {
preparations();
jetpack.fileAsync('file.txt')
.then(function () {
.then(() => {
expectations();

@@ -398,6 +400,6 @@ done();

it('async, ensure content', function (done) {
it('async, ensure content', (done) => {
preparations();
jetpack.fileAsync('file.txt', { content: 'abc' })
.then(function () {
.then(() => {
expectations();

@@ -410,10 +412,10 @@ done();

} else {
describe('specyfying mode have no effect and throws no error (windows only)', function () {
it('sync', function () {
describe('specyfying mode have no effect and throws no error (windows only)', () => {
it('sync', () => {
jetpack.file('file.txt', { mode: '711' });
});
it('async', function (done) {
it('async', (done) => {
jetpack.fileAsync('file.txt', { mode: '711' })
.then(function () {
.then(() => {
done();

@@ -426,15 +428,14 @@ })

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.file, methodName: 'file' },
{ type: 'async', method: jetpack.fileAsync, methodName: 'fileAsync' }
{ type: 'async', method: jetpack.fileAsync, methodName: 'fileAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, [criteria]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, [criteria]) must be a string. Received undefined`);
});

@@ -444,31 +445,27 @@ });

describe('"criteria" object', function () {
describe('"content" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"criteria" object', () => {
describe('"content" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { content: 1 });
}).to.throw('Argument "criteria.content" passed to ' + test.methodName
+ '(path, [criteria]) must be a string or a buffer or an object or '
+ 'an array. Received number');
}).to.throw(`Argument "criteria.content" passed to ${test.methodName}(path, [criteria]) must be a string or a buffer or an object or an array. Received number`);
});
});
});
describe('"jsonIndent" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"jsonIndent" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { jsonIndent: true });
}).to.throw('Argument "criteria.jsonIndent" passed to ' + test.methodName
+ '(path, [criteria]) must be a number. Received boolean');
}).to.throw(`Argument "criteria.jsonIndent" passed to ${test.methodName}(path, [criteria]) must be a number. Received boolean`);
});
});
});
describe('"mode" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"mode" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { mode: true });
}).to.throw('Argument "criteria.mode" passed to ' + test.methodName
+ '(path, [criteria]) must be a string or a number. Received boolean');
}).to.throw(`Argument "criteria.mode" passed to ${test.methodName}(path, [criteria]) must be a string or a number. Received boolean`);
});

@@ -475,0 +472,0 @@ });

@@ -1,21 +0,23 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('find', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('find', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('returns list of relative paths anchored to CWD', function () {
var preparations = function () {
describe('returns list of relative paths anchored to CWD', () => {
const preparations = () => {
fse.outputFileSync('a/b/file.txt', 'abc');
};
var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/b/file.txt']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/b/file.txt']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -25,6 +27,6 @@ expectations(jetpack.find('a', { matching: '*.txt' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', { matching: '*.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -36,4 +38,4 @@ done();

describe('if recursive=false will exclude subfolders from search', function () {
var preparations = function () {
describe('if recursive=false will exclude subfolders from search', () => {
const preparations = () => {
fse.outputFileSync('x/file.txt', 'abc');

@@ -44,8 +46,8 @@ fse.outputFileSync('x/y/file.txt', '123');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['x/file.txt']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['x/file.txt']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -55,6 +57,6 @@ expectations(jetpack.find('x', { matching: '*.txt', recursive: false }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('x', { matching: '*.txt', recursive: false })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -66,13 +68,13 @@ done();

describe('defaults to CWD if no path provided', function () {
var preparations = function () {
describe('defaults to CWD if no path provided', () => {
const preparations = () => {
fse.outputFileSync('a/b/file.txt', 'abc');
};
var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/b/file.txt']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/b/file.txt']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -82,6 +84,6 @@ expectations(jetpack.find({ matching: '*.txt' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync({ matching: '*.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -93,12 +95,12 @@ done();

describe('returns empty list if nothing found', function () {
var preparations = function () {
describe('returns empty list if nothing found', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.md', 'abc');
};
var expectations = function (found) {
const expectations = (found) => {
expect(found).to.eql([]);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -108,6 +110,6 @@ expectations(jetpack.find('a', { matching: '*.txt' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', { matching: '*.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -119,4 +121,4 @@ done();

describe('finds all paths which match globs', function () {
var preparations = function () {
describe('finds all paths which match globs', () => {
const preparations = () => {
fse.outputFileSync('a/b/file.txt', '1');

@@ -128,7 +130,7 @@ fse.outputFileSync('a/b/c/file.txt', '2');

var expectations = function (found) {
var normalizedPaths = helper.osSep([
const expectations = (found) => {
const normalizedPaths = helper.osSep([
'a/b/c/file.txt',
'a/b/file.txt',
'a/x/y/z'
'a/x/y/z',
]);

@@ -139,3 +141,3 @@ found.sort();

it('sync', function () {
it('sync', () => {
preparations();

@@ -145,6 +147,6 @@ expectations(jetpack.find('a', { matching: ['*.txt', 'z'] }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', { matching: ['*.txt', 'z'] })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -156,4 +158,4 @@ done();

describe("anchors globs to directory you're finding in", function () {
var preparations = function () {
describe("anchors globs to directory you're finding in", () => {
const preparations = () => {
fse.outputFileSync('x/y/a/b/file.txt', '123');

@@ -163,8 +165,8 @@ fse.outputFileSync('x/y/a/b/c/file.txt', '456');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['x/y/a/b/file.txt']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['x/y/a/b/file.txt']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -174,6 +176,6 @@ expectations(jetpack.find('x/y/a', { matching: 'b/*.txt' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('x/y/a', { matching: 'b/*.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -185,4 +187,4 @@ done();

describe('can use ./ as indication of anchor directory', function () {
var preparations = function () {
describe('can use ./ as indication of anchor directory', () => {
const preparations = () => {
fse.outputFileSync('x/y/file.txt', '123');

@@ -192,8 +194,8 @@ fse.outputFileSync('x/y/b/file.txt', '456');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['x/y/file.txt']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['x/y/file.txt']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -203,6 +205,6 @@ expectations(jetpack.find('x/y', { matching: './file.txt' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('x/y', { matching: './file.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -214,4 +216,4 @@ done();

describe('deals with negation globs', function () {
var preparations = function () {
describe('deals with negation globs', () => {
const preparations = () => {
fse.outputFileSync('x/y/a/b', 'bbb');

@@ -223,8 +225,8 @@ fse.outputFileSync('x/y/a/x', 'xxx');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['x/y/a/b']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['x/y/a/b']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -237,8 +239,8 @@ expectations(jetpack.find('x/y', {

'!a/y',
'!./a/z'
]
'!./a/z',
],
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();

@@ -251,6 +253,6 @@ jetpack.findAsync('x/y', {

'!a/y',
'!./a/z'
]
'!./a/z',
],
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -262,4 +264,4 @@ done();

describe("doesn't look for directories by default", function () {
var preparations = function () {
describe("doesn't look for directories by default", () => {
const preparations = () => {
fse.outputFileSync('a/b/foo1', 'abc');

@@ -269,8 +271,8 @@ fse.mkdirsSync('a/b/foo2');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/b/foo1']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/b/foo1']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -280,6 +282,6 @@ expectations(jetpack.find('a', { matching: 'foo*' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', { matching: 'foo*' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -291,4 +293,4 @@ done();

describe('can look for files and directories', function () {
var preparations = function () {
describe('can look for files and directories', () => {
const preparations = () => {
fse.outputFileSync('a/b/foo1', 'abc');

@@ -298,22 +300,22 @@ fse.mkdirsSync('a/b/foo2');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/b/foo1', 'a/b/foo2']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/b/foo1', 'a/b/foo2']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();
expectations(jetpack.find('a', {
matching: 'foo*',
directories: true
directories: true,
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', {
matching: 'foo*',
directories: true
directories: true,
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -326,4 +328,4 @@ done();

describe('can look for only directories', function () {
var preparations = function () {
describe('can look for only directories', () => {
const preparations = () => {
fse.outputFileSync('a/b/foo1', 'abc');

@@ -333,8 +335,8 @@ fse.mkdirsSync('a/b/foo2');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/b/foo2']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/b/foo2']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -344,7 +346,7 @@ expectations(jetpack.find('a', {

files: false,
directories: true
directories: true,
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();

@@ -354,5 +356,5 @@ jetpack.findAsync('a', {

files: false,
directories: true
directories: true,
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -365,4 +367,4 @@ done();

describe('looking for directories works ok with only negation globs in set', function () {
var preparations = function () {
describe('looking for directories works ok with only negation globs in set', () => {
const preparations = () => {
fse.outputFileSync('a/x', '123');

@@ -372,22 +374,22 @@ fse.outputFileSync('a/y', '789');

var expectations = function (found) {
var normalizedPaths = helper.osSep(['a/x']);
const expectations = (found) => {
const normalizedPaths = helper.osSep(['a/x']);
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
it('sync', () => {
preparations();
expectations(jetpack.find('a', {
matching: ['!y'],
directories: true
directories: true,
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a', {
matching: ['!y'],
directories: true
directories: true,
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -400,4 +402,4 @@ done();

describe('when you turn off files and directoies returns empty list', function () {
var preparations = function () {
describe('when you turn off files and directoies returns empty list', () => {
const preparations = () => {
fse.outputFileSync('a/b/foo1', 'abc');

@@ -407,7 +409,7 @@ fse.mkdirsSync('a/b/foo2');

var expectations = function (found) {
const expectations = (found) => {
expect(found).to.eql([]);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -417,7 +419,7 @@ expectations(jetpack.find('a', {

files: false,
directories: false
directories: false,
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();

@@ -427,5 +429,5 @@ jetpack.findAsync('a', {

files: false,
directories: false
directories: false,
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -437,4 +439,4 @@ done();

describe("throws if path doesn't exist", function () {
var expectations = function (err) {
describe("throws if path doesn't exist", () => {
const expectations = (err) => {
expect(err.code).to.equal('ENOENT');

@@ -444,3 +446,3 @@ expect(err.message).to.have.string("Path you want to find stuff in doesn't exist");

it('sync', function () {
it('sync', () => {
try {

@@ -454,5 +456,5 @@ jetpack.find('a', { matching: '*.txt' });

it('async', function (done) {
it('async', (done) => {
jetpack.findAsync('a', { matching: '*.txt' })
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -464,8 +466,8 @@ done();

describe('throws if path is a file, not a directory', function () {
var preparations = function () {
describe('throws if path is a file, not a directory', () => {
const preparations = () => {
fse.outputFileSync('a/b', 'abc');
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.code).to.equal('ENOTDIR');

@@ -475,3 +477,3 @@ expect(err.message).to.have.string('Path you want to find stuff in must be a directory');

it('sync', function () {
it('sync', () => {
preparations();

@@ -486,6 +488,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync('a/b', { matching: '*.txt' })
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -497,14 +499,14 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b/c/d.txt', 'abc');
};
var expectations = function (found) {
var normalizedPaths = helper.osSep(['b/c/d.txt']); // NOT a/b/c/d.txt
const expectations = (found) => {
const normalizedPaths = helper.osSep(['b/c/d.txt']); // NOT a/b/c/d.txt
expect(found).to.eql(normalizedPaths);
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -514,7 +516,7 @@ expectations(jetContext.find('b', { matching: '*.txt' }));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.findAsync('b', { matching: '*.txt' })
.then(function (found) {
.then((found) => {
expectations(found);

@@ -526,4 +528,4 @@ done();

describe('finds dot-dirs and dot-files', function () {
var preparations = function () {
describe('finds dot-dirs and dot-files', () => {
const preparations = () => {
fse.outputFileSync('.dir/file', 'a');

@@ -534,6 +536,6 @@ fse.outputFileSync('.dir/.file', 'b');

var expectations = function (found) {
var normalizedPaths = helper.osSep([
const expectations = (found) => {
const normalizedPaths = helper.osSep([
'.dir',
'.dir/.file'
'.dir/.file',
]);

@@ -543,17 +545,17 @@ expect(found).to.eql(normalizedPaths);

it('sync', function () {
it('sync', () => {
preparations();
expectations(jetpack.find({
matching: ['.dir', '.file', '!.foo/**'],
directories: true
directories: true,
}));
});
it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.findAsync({
matching: ['.dir', '.file', '!.foo/**'],
directories: true
directories: true,
})
.then(function (found) {
.then((found) => {
expectations(found);

@@ -565,15 +567,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.find, methodName: 'find' },
{ type: 'async', method: jetpack.findAsync, methodName: 'findAsync' }
{ type: 'async', method: jetpack.findAsync, methodName: 'findAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, {});
}).to.throw('Argument "path" passed to ' + test.methodName
+ '([path], options) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}([path], options) must be a string. Received undefined`);
});

@@ -583,40 +584,36 @@ });

describe('"options" object', function () {
describe('"matching" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"matching" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method({ matching: 1 });
}).to.throw('Argument "options.matching" passed to ' + test.methodName
+ '([path], options) must be a string or an array of string. Received number');
}).to.throw(`Argument "options.matching" passed to ${test.methodName}([path], options) must be a string or an array of string. Received number`);
});
});
});
describe('"files" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"files" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { files: 1 });
}).to.throw('Argument "options.files" passed to ' + test.methodName
+ '([path], options) must be a boolean. Received number');
}).to.throw(`Argument "options.files" passed to ${test.methodName}([path], options) must be a boolean. Received number`);
});
});
});
describe('"directories" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"directories" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { directories: 1 });
}).to.throw('Argument "options.directories" passed to ' + test.methodName
+ '([path], options) must be a boolean. Received number');
}).to.throw(`Argument "options.directories" passed to ${test.methodName}([path], options) must be a boolean. Received number`);
});
});
});
describe('"recursive" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"recursive" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { recursive: 1 });
}).to.throw('Argument "options.recursive" passed to ' + test.methodName
+ '([path], options) must be a boolean. Received number');
}).to.throw(`Argument "options.recursive" passed to ${test.methodName}([path], options) must be a boolean. Received number`);
});

@@ -623,0 +620,0 @@ });

@@ -1,14 +0,14 @@

/* eslint no-console:0 */
'use strict';
var os = require('os');
var crypto = require('crypto');
var fse = require('fs-extra');
const os = require('os');
const crypto = require('crypto');
const fse = require('fs-extra');
var originalCwd = process.cwd();
var createdDirectories = [];
const originalCwd = process.cwd();
const createdDirectories = [];
process.on('exit', function () {
process.on('exit', () => {
// In case something went wrong and some temp
// directories are still on the disk.
createdDirectories.forEach(function (path) {
createdDirectories.forEach((path) => {
fse.removeSync(path);

@@ -18,5 +18,5 @@ });

exports.setCleanTestCwd = function () {
var random = crypto.randomBytes(16).toString('hex');
var path = os.tmpdir() + '/fs-jetpack-test-' + random;
exports.setCleanTestCwd = () => {
const random = crypto.randomBytes(16).toString('hex');
const path = `${os.tmpdir()}/fs-jetpack-test-${random}`;
fse.mkdirSync(path);

@@ -27,4 +27,4 @@ createdDirectories.push(path);

exports.switchBackToCorrectCwd = function () {
var path = createdDirectories.pop();
exports.switchBackToCorrectCwd = () => {
const path = createdDirectories.pop();
process.chdir(originalCwd);

@@ -34,4 +34,4 @@ fse.removeSync(path);

exports.parseMode = function (modeAsNumber) {
var mode = modeAsNumber.toString(8);
exports.parseMode = (modeAsNumber) => {
const mode = modeAsNumber.toString(8);
return mode.substring(mode.length - 3);

@@ -41,3 +41,3 @@ };

// Converts paths to windows or unix formats depending on platform running.
exports.osSep = function (path) {
exports.osSep = (path) => {
if (Array.isArray(path)) {

@@ -44,0 +44,0 @@ return path.map(exports.osSep);

@@ -1,12 +0,14 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('inspectTree', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('inspectTree', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('inspects whole tree of files', function () {
var preparations = function () {
describe('inspects whole tree of files', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');

@@ -16,3 +18,3 @@ fse.outputFileSync('dir/subdir/file.txt', 'defg');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({

@@ -26,3 +28,3 @@ name: 'dir',

type: 'file',
size: 3
size: 3,
}, {

@@ -36,11 +38,11 @@ name: 'subdir',

type: 'file',
size: 4
}
]
}
]
size: 4,
},
],
},
],
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -50,6 +52,6 @@ expectations(jetpack.inspectTree('dir'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir')
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -61,4 +63,4 @@ done();

describe('can calculate size of a whole tree', function () {
var preparations = function () {
describe('can calculate size of a whole tree', () => {
const preparations = () => {
fse.mkdirsSync('dir/empty');

@@ -70,3 +72,3 @@ fse.outputFileSync('dir/empty.txt', '');

var expectations = function (data) {
const expectations = (data) => {
// dir

@@ -86,3 +88,3 @@ expect(data.size).to.equal(7);

it('sync', function () {
it('sync', () => {
preparations();

@@ -92,6 +94,6 @@ expectations(jetpack.inspectTree('dir'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir')
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -103,8 +105,8 @@ done();

describe('can output relative path for every tree node', function () {
var preparations = function () {
describe('can output relative path for every tree node', () => {
const preparations = () => {
fse.outputFileSync('dir/subdir/file.txt', 'defg');
};
var expectations = function (data) {
const expectations = (data) => {
// data will look like...

@@ -132,3 +134,3 @@ // {

it('sync', function () {
it('sync', () => {
preparations();

@@ -138,6 +140,6 @@ expectations(jetpack.inspectTree('dir', { relativePath: true }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir', { relativePath: true })
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -149,16 +151,16 @@ done();

describe('if given path is a file just inspects that file', function () {
var preparations = function () {
describe('if given path is a file just inspects that file', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({
name: 'file.txt',
type: 'file',
size: 3
size: 3,
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -168,6 +170,6 @@ expectations(jetpack.inspectTree('dir/file.txt'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir/file.txt')
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -179,8 +181,8 @@ done();

describe('behaves ok with empty directory', function () {
var preparations = function () {
describe('behaves ok with empty directory', () => {
const preparations = () => {
fse.mkdirsSync('empty');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({

@@ -190,7 +192,7 @@ name: 'empty',

size: 0,
children: []
children: [],
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -200,6 +202,6 @@ expectations(jetpack.inspectTree('empty'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('empty')
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -211,14 +213,14 @@ done();

describe("returns undefined if path doesn't exist", function () {
var expectations = function (data) {
describe("returns undefined if path doesn't exist", () => {
const expectations = (data) => {
expect(data).to.equal(undefined);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.inspectTree('nonexistent'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.inspectTreeAsync('nonexistent')
.then(function (dataAsync) {
.then((dataAsync) => {
expectations(dataAsync);

@@ -230,13 +232,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data.name).to.equal('b.txt');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -246,7 +248,7 @@ expectations(jetContext.inspectTree('b.txt'));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.inspectTreeAsync('b.txt')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -258,4 +260,4 @@ done();

describe('reports symlinks by default', function () {
var preparations = function () {
describe('reports symlinks by default', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');

@@ -265,3 +267,3 @@ fse.symlinkSync('file.txt', 'dir/symlinked_file.txt');

var expectations = function (tree) {
const expectations = (tree) => {
expect(tree).to.eql({

@@ -274,12 +276,12 @@ name: 'dir',

type: 'file',
size: 3
size: 3,
}, {
name: 'symlinked_file.txt',
type: 'symlink',
pointsAt: 'file.txt'
}]
pointsAt: 'file.txt',
}],
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -290,10 +292,10 @@ expectations(jetpack.inspectTree('dir')); // implicit

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir') // implicit
.then(function (tree) {
.then((tree) => {
expectations(tree);
return jetpack.inspectTreeAsync('dir', { symlinks: 'report' }); // explicit
})
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -306,4 +308,4 @@ done();

describe('follows symlinks when option specified', function () {
var preparations = function () {
describe('follows symlinks when option specified', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');

@@ -313,3 +315,3 @@ fse.symlinkSync('file.txt', 'dir/symlinked_file.txt');

var expectations = function (tree) {
const expectations = (tree) => {
expect(tree).to.eql({

@@ -322,12 +324,12 @@ name: 'dir',

type: 'file',
size: 3
size: 3,
}, {
name: 'symlinked_file.txt',
type: 'file',
size: 3
}]
size: 3,
}],
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -337,6 +339,6 @@ expectations(jetpack.inspectTree('dir', { symlinks: 'follow' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir', { symlinks: 'follow' })
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -349,4 +351,4 @@ done();

describe('can compute checksum of a whole tree', function () {
var preparations = function () {
describe('can compute checksum of a whole tree', () => {
const preparations = () => {
fse.outputFileSync('dir/a.txt', 'abc');

@@ -356,3 +358,3 @@ fse.outputFileSync('dir/b.txt', 'defg');

var expectations = function (data) {
const expectations = (data) => {
// md5 of

@@ -368,3 +370,3 @@ // 'a.txt' + '900150983cd24fb0d6963f7d28e17f72' +

it('sync', function () {
it('sync', () => {
preparations();

@@ -374,6 +376,6 @@ expectations(jetpack.inspectTree('dir', { checksum: 'md5' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('dir', { checksum: 'md5' })
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -385,8 +387,8 @@ done();

describe('can count checksum of empty directory', function () {
var preparations = function () {
describe('can count checksum of empty directory', () => {
const preparations = () => {
fse.mkdirsSync('empty_dir');
};
var expectations = function (data) {
const expectations = (data) => {
// md5 of empty string

@@ -397,3 +399,3 @@ expect(data.md5).to.equal('d41d8cd98f00b204e9800998ecf8427e');

// SYNC
it('sync', function () {
it('sync', () => {
preparations();

@@ -403,6 +405,6 @@ expectations(jetpack.inspectTree('empty_dir', { checksum: 'md5' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectTreeAsync('empty_dir', { checksum: 'md5' })
.then(function (tree) {
.then((tree) => {
expectations(tree);

@@ -414,15 +416,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.inspectTree, methodName: 'inspectTree' },
{ type: 'async', method: jetpack.inspectTreeAsync, methodName: 'inspectTreeAsync' }
{ type: 'async', method: jetpack.inspectTreeAsync, methodName: 'inspectTreeAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, [options]) must be a string. Received undefined`);
});

@@ -432,42 +433,37 @@ });

describe('"options" object', function () {
describe('"checksum" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"checksum" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { checksum: 1 });
}).to.throw('Argument "options.checksum" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received number');
}).to.throw(`Argument "options.checksum" passed to ${test.methodName}(path, [options]) must be a string. Received number`);
});
it(test.type, function () {
expect(function () {
it(test.type, () => {
expect(() => {
test.method('abc', { checksum: 'foo' });
}).to.throw('Argument "options.checksum" passed to ' + test.methodName
+ '(path, [options]) must have one of values: md5, sha1, sha256');
}).to.throw(`Argument "options.checksum" passed to ${test.methodName}(path, [options]) must have one of values: md5, sha1, sha256`);
});
});
});
describe('"relativePath" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"relativePath" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { relativePath: 1 });
}).to.throw('Argument "options.relativePath" passed to ' + test.methodName
+ '(path, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.relativePath" passed to ${test.methodName}(path, [options]) must be a boolean. Received number`);
});
});
});
describe('"symlinks" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"symlinks" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { symlinks: 1 });
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received number');
}).to.throw(`Argument "options.symlinks" passed to ${test.methodName}(path, [options]) must be a string. Received number`);
});
it(test.type, function () {
expect(function () {
it(test.type, () => {
expect(() => {
test.method('abc', { symlinks: 'foo' });
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName
+ '(path, [options]) must have one of values: report, follow');
}).to.throw(`Argument "options.symlinks" passed to ${test.methodName}(path, [options]) must have one of values: report, follow`);
});

@@ -474,0 +470,0 @@ });

@@ -1,24 +0,26 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('inspect', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('inspect', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('can inspect a file', function () {
var preparations = function () {
describe('can inspect a file', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({
name: 'file.txt',
type: 'file',
size: 3
size: 3,
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -28,6 +30,6 @@ expectations(jetpack.inspect('dir/file.txt'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('dir/file.txt')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -39,15 +41,15 @@ done();

describe('can inspect a directory', function () {
var preparations = function () {
describe('can inspect a directory', () => {
const preparations = () => {
fse.mkdirsSync('empty');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({
name: 'empty',
type: 'dir'
type: 'dir',
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -57,6 +59,6 @@ expectations(jetpack.inspect('empty'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('empty')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -68,14 +70,14 @@ done();

describe("returns undefined if path doesn't exist", function () {
var expectations = function (data) {
describe("returns undefined if path doesn't exist", () => {
const expectations = (data) => {
expect(data).to.equal(undefined);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.inspect('nonexistent'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.inspectAsync('nonexistent')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -87,8 +89,8 @@ done();

describe('can output file times (ctime, mtime, atime)', function () {
var preparations = function () {
describe('can output file times (ctime, mtime, atime)', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(typeof data.accessTime.getTime).to.equal('function');

@@ -99,3 +101,3 @@ expect(typeof data.modifyTime.getTime).to.equal('function');

it('sync', function () {
it('sync', () => {
preparations();

@@ -105,6 +107,6 @@ expectations(jetpack.inspect('dir/file.txt', { times: true }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('dir/file.txt', { times: true })
.then(function (data) {
.then((data) => {
expectations(data);

@@ -116,12 +118,12 @@ done();

describe('can output absolute path', function () {
var preparations = function () {
describe('can output absolute path', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data.absolutePath).to.equal(jetpack.path('dir/file.txt'));
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -131,6 +133,6 @@ expectations(jetpack.inspect('dir/file.txt', { absolutePath: true }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('dir/file.txt', { absolutePath: true })
.then(function (data) {
.then((data) => {
expectations(data);

@@ -142,13 +144,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data.name).to.equal('b.txt');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -158,7 +160,7 @@ expectations(jetContext.inspect('b.txt'));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.inspectAsync('b.txt')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -170,4 +172,4 @@ done();

describe('reports symlink by default', function () {
var preparations = function () {
describe('reports symlink by default', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');

@@ -177,11 +179,11 @@ fse.symlinkSync('dir/file.txt', 'symlinked_file.txt');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({
name: 'symlinked_file.txt',
type: 'symlink',
pointsAt: helper.osSep('dir/file.txt')
pointsAt: helper.osSep('dir/file.txt'),
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -192,10 +194,10 @@ expectations(jetpack.inspect('symlinked_file.txt')); // implicit

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('symlinked_file.txt') // implicit
.then(function (data) {
.then((data) => {
expectations(data);
return jetpack.inspectAsync('symlinked_file.txt', { symlinks: 'report' }); // explicit
})
.then(function (data) {
.then((data) => {
expectations(data);

@@ -208,4 +210,4 @@ done();

describe('follows symlink if option specified', function () {
var preparations = function () {
describe('follows symlink if option specified', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc');

@@ -215,11 +217,11 @@ fse.symlinkSync('dir/file.txt', 'symlinked_file.txt');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql({
name: 'symlinked_file.txt',
type: 'file',
size: 3
size: 3,
});
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -229,6 +231,6 @@ expectations(jetpack.inspect('symlinked_file.txt', { symlinks: 'follow' }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('symlinked_file.txt', { symlinks: 'follow' })
.then(function (data) {
.then((data) => {
expectations(data);

@@ -242,14 +244,14 @@ done();

if (process.platform !== 'win32') {
describe('can output file mode (unix only)', function () {
var preparations = function () {
describe('can output file mode (unix only)', () => {
const preparations = () => {
fse.outputFileSync('dir/file.txt', 'abc', {
mode: '511'
mode: '511',
});
};
var expectations = function (data) {
const expectations = (data) => {
expect(helper.parseMode(data.mode)).to.equal('511');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -259,6 +261,6 @@ expectations(jetpack.inspect('dir/file.txt', { mode: true }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('dir/file.txt', { mode: true })
.then(function (data) {
.then((data) => {
expectations(data);

@@ -271,4 +273,4 @@ done();

describe('checksums', function () {
var testsData = [
describe('checksums', () => {
const testsData = [
{

@@ -278,3 +280,3 @@ name: 'md5',

content: 'abc',
expected: '900150983cd24fb0d6963f7d28e17f72'
expected: '900150983cd24fb0d6963f7d28e17f72',
},

@@ -285,3 +287,3 @@ {

content: 'abc',
expected: 'a9993e364706816aba3e25717850c26c9cd0d89d'
expected: 'a9993e364706816aba3e25717850c26c9cd0d89d',
},

@@ -292,3 +294,3 @@ {

content: 'abc',
expected: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
expected: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
},

@@ -299,4 +301,3 @@ {

content: 'abc',
expected: 'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a21'
+ '92992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f'
expected: 'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f',
},

@@ -307,17 +308,17 @@ {

content: '',
expected: 'd41d8cd98f00b204e9800998ecf8427e'
}
expected: 'd41d8cd98f00b204e9800998ecf8427e',
},
];
testsData.forEach(function (test) {
describe(test.name, function () {
var preparations = function () {
testsData.forEach((test) => {
describe(test.name, () => {
const preparations = () => {
fse.outputFileSync('file.txt', test.content);
};
var expectations = function (data) {
const expectations = (data) => {
expect(data[test.type]).to.eql(test.expected);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -327,6 +328,6 @@ expectations(jetpack.inspect('file.txt', { checksum: test.type }));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.inspectAsync('file.txt', { checksum: test.type })
.then(function (data) {
.then((data) => {
expectations(data);

@@ -341,15 +342,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.inspect, methodName: 'inspect' },
{ type: 'async', method: jetpack.inspectAsync, methodName: 'inspectAsync' }
{ type: 'async', method: jetpack.inspectAsync, methodName: 'inspectAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, [options]) must be a string. Received undefined`);
});

@@ -359,62 +359,55 @@ });

describe('"options" object', function () {
describe('"checksum" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"checksum" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { checksum: 1 });
}).to.throw('Argument "options.checksum" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received number');
}).to.throw(`Argument "options.checksum" passed to ${test.methodName}(path, [options]) must be a string. Received number`);
});
it(test.type, function () {
expect(function () {
it(test.type, () => {
expect(() => {
test.method('abc', { checksum: 'foo' });
}).to.throw('Argument "options.checksum" passed to ' + test.methodName
+ '(path, [options]) must have one of values: md5, sha1, sha256');
}).to.throw(`Argument "options.checksum" passed to ${test.methodName}(path, [options]) must have one of values: md5, sha1, sha256`);
});
});
});
describe('"mode" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"mode" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { mode: 1 });
}).to.throw('Argument "options.mode" passed to ' + test.methodName
+ '(path, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.mode" passed to ${test.methodName}(path, [options]) must be a boolean. Received number`);
});
});
});
describe('"times" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"times" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { times: 1 });
}).to.throw('Argument "options.times" passed to ' + test.methodName
+ '(path, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.times" passed to ${test.methodName}(path, [options]) must be a boolean. Received number`);
});
});
});
describe('"absolutePath" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"absolutePath" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { absolutePath: 1 });
}).to.throw('Argument "options.absolutePath" passed to ' + test.methodName
+ '(path, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.absolutePath" passed to ${test.methodName}(path, [options]) must be a boolean. Received number`);
});
});
});
describe('"symlinks" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"symlinks" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', { symlinks: 1 });
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName
+ '(path, [options]) must be a string. Received number');
}).to.throw(`Argument "options.symlinks" passed to ${test.methodName}(path, [options]) must be a string. Received number`);
});
it(test.type, function () {
expect(function () {
it(test.type, () => {
expect(() => {
test.method('abc', { symlinks: 'foo' });
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName
+ '(path, [options]) must have one of values: report, follow');
}).to.throw(`Argument "options.symlinks" passed to ${test.methodName}(path, [options]) must have one of values: report, follow`);
});

@@ -421,0 +414,0 @@ });

@@ -1,12 +0,14 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('list', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('list', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('lists file names in given path', function () {
var preparations = function () {
describe('lists file names in given path', () => {
const preparations = () => {
fse.mkdirsSync('dir/empty');

@@ -18,7 +20,7 @@ fse.outputFileSync('dir/empty.txt', '');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql(['empty', 'empty.txt', 'file.txt', 'subdir']);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -28,6 +30,6 @@ expectations(jetpack.list('dir'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.listAsync('dir')
.then(function (listAsync) {
.then((listAsync) => {
expectations(listAsync);

@@ -39,4 +41,4 @@ done();

describe('lists CWD if no path parameter passed', function () {
var preparations = function () {
describe('lists CWD if no path parameter passed', () => {
const preparations = () => {
fse.mkdirsSync('dir/a');

@@ -46,8 +48,8 @@ fse.outputFileSync('dir/b');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql(['a', 'b']);
};
it('sync', function () {
var jetContext = jetpack.cwd('dir');
it('sync', () => {
const jetContext = jetpack.cwd('dir');
preparations();

@@ -57,7 +59,7 @@ expectations(jetContext.list());

it('async', function (done) {
var jetContext = jetpack.cwd('dir');
it('async', (done) => {
const jetContext = jetpack.cwd('dir');
preparations();
jetContext.listAsync()
.then(function (list) {
.then((list) => {
expectations(list);

@@ -69,14 +71,14 @@ done();

describe("returns undefined if path doesn't exist", function () {
var expectations = function (data) {
describe("returns undefined if path doesn't exist", () => {
const expectations = (data) => {
expect(data).to.equal(undefined);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.list('nonexistent'));
});
it('async', function (done) {
it('async', (done) => {
jetpack.listAsync('nonexistent')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -88,12 +90,12 @@ done();

describe('throws if given path is not a directory', function () {
var preparations = function () {
describe('throws if given path is not a directory', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.code).to.equal('ENOTDIR');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -108,6 +110,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.listAsync('file.txt')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -119,13 +121,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql(['c.txt']);
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -135,7 +137,7 @@ expectations(jetContext.list('b'));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.listAsync('b')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -147,15 +149,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.list, methodName: 'list' },
{ type: 'async', method: jetpack.listAsync, methodName: 'listAsync' }
{ type: 'async', method: jetpack.listAsync, methodName: 'listAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(true);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path) must be a string or an undefined. Received boolean');
}).to.throw(`Argument "path" passed to ${test.methodName}(path) must be a string or an undefined. Received boolean`);
});

@@ -162,0 +163,0 @@ });

/* eslint no-console:0 */
var util = require('util');
var expect = require('chai').expect;
var jetpack = require('..');
'use strict';
const util = require('util');
const expect = require('chai').expect;
const jetpack = require('..');
if (util.inspect.custom !== undefined) {

@@ -11,5 +13,5 @@ // Test for https://github.com/szwacz/fs-jetpack/issues/29

// introduced in node v6.6.0, hence this test is runned conditionally.
describe('console.log', function () {
it('can be printed by console.log', function () {
expect(function () {
describe('console.log', () => {
it('can be printed by console.log', () => {
expect(() => {
console.log(jetpack);

@@ -16,0 +18,0 @@ }).not.to.throw();

@@ -1,17 +0,19 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('move', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('move', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('moves file', function () {
var preparations = function () {
describe('moves file', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b.txt').shouldNotExist();

@@ -21,3 +23,3 @@ path('c.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -28,6 +30,6 @@ jetpack.move('a/b.txt', 'c.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.moveAsync('a/b.txt', 'c.txt')
.then(function () {
.then(() => {
expectations();

@@ -39,4 +41,4 @@ done();

describe('moves directory', function () {
var preparations = function () {
describe('moves directory', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');

@@ -46,3 +48,3 @@ fse.mkdirsSync('x');

var expectations = function () {
const expectations = () => {
path('a').shouldNotExist();

@@ -52,3 +54,3 @@ path('x/y/b/c.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -59,6 +61,6 @@ jetpack.move('a', 'x/y');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.moveAsync('a', 'x/y')
.then(function () {
.then(() => {
expectations();

@@ -70,8 +72,8 @@ done();

describe('creates nonexistent directories for destination path', function () {
var preparations = function () {
describe('creates nonexistent directories for destination path', () => {
const preparations = () => {
fse.outputFileSync('a.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a.txt').shouldNotExist();

@@ -81,3 +83,3 @@ path('a/b/z.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -88,6 +90,6 @@ jetpack.move('a.txt', 'a/b/z.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.moveAsync('a.txt', 'a/b/z.txt')
.then(function () {
.then(() => {
expectations();

@@ -99,4 +101,4 @@ done();

describe("generates nice error when source path doesn't exist", function () {
var expectations = function (err) {
describe("generates nice error when source path doesn't exist", () => {
const expectations = (err) => {
expect(err.code).to.equal('ENOENT');

@@ -106,3 +108,3 @@ expect(err.message).to.have.string("Path to move doesn't exist");

it('sync', function () {
it('sync', () => {
try {

@@ -116,5 +118,5 @@ jetpack.move('a', 'b');

it('async', function (done) {
it('async', (done) => {
jetpack.moveAsync('a', 'b')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -126,8 +128,8 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b.txt').shouldNotExist();

@@ -137,4 +139,4 @@ path('a/x.txt').shouldBeFileWithContent('abc');

it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -145,7 +147,7 @@ jetContext.move('b.txt', 'x.txt');

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.moveAsync('b.txt', 'x.txt')
.then(function () {
.then(() => {
expectations();

@@ -157,15 +159,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.move, methodName: 'move' },
{ type: 'async', method: jetpack.moveAsync, methodName: 'moveAsync' }
{ type: 'async', method: jetpack.moveAsync, methodName: 'moveAsync' },
];
describe('"from" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"from" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'xyz');
}).to.throw('Argument "from" passed to ' + test.methodName
+ '(from, to) must be a string. Received undefined');
}).to.throw(`Argument "from" passed to ${test.methodName}(from, to) must be a string. Received undefined`);
});

@@ -175,9 +176,8 @@ });

describe('"to" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"to" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', undefined);
}).to.throw('Argument "to" passed to ' + test.methodName
+ '(from, to) must be a string. Received undefined');
}).to.throw(`Argument "to" passed to ${test.methodName}(from, to) must be a string. Received undefined`);
});

@@ -184,0 +184,0 @@ });

@@ -1,7 +0,9 @@

var pathUtil = require('path');
var expect = require('chai').expect;
var jetpack = require('..');
'use strict';
describe('path', function () {
it('if no parameters passed returns same path as cwd()', function () {
const pathUtil = require('path');
const expect = require('chai').expect;
const jetpack = require('..');
describe('path', () => {
it('if no parameters passed returns same path as cwd()', () => {
expect(jetpack.path()).to.equal(jetpack.cwd());

@@ -12,11 +14,11 @@ expect(jetpack.path('')).to.equal(jetpack.cwd());

it('is absolute if prepending slash present', function () {
it('is absolute if prepending slash present', () => {
expect(jetpack.path('/blah')).to.equal(pathUtil.resolve('/blah'));
});
it('resolves to CWD path of this jetpack instance', function () {
var a = pathUtil.join(jetpack.cwd(), 'a');
it('resolves to CWD path of this jetpack instance', () => {
const a = pathUtil.join(jetpack.cwd(), 'a');
// Create jetpack instance with other CWD
var jetpackSubdir = jetpack.cwd('subdir');
var b = pathUtil.join(jetpack.cwd(), 'subdir', 'b');
const jetpackSubdir = jetpack.cwd('subdir');
const b = pathUtil.join(jetpack.cwd(), 'subdir', 'b');
expect(jetpack.path('a')).to.equal(a);

@@ -26,6 +28,6 @@ expect(jetpackSubdir.path('b')).to.equal(b);

it('can take unlimited number of arguments as path parts', function () {
var abc = pathUtil.join(jetpack.cwd(), 'a', 'b', 'c');
it('can take unlimited number of arguments as path parts', () => {
const abc = pathUtil.join(jetpack.cwd(), 'a', 'b', 'c');
expect(jetpack.path('a', 'b', 'c')).to.equal(abc);
});
});

@@ -1,20 +0,22 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('read', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('read', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('reads file as a string', function () {
var preparations = function () {
describe('reads file as a string', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function (content) {
const expectations = (content) => {
expect(content).to.equal('abc');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -25,10 +27,10 @@ expectations(jetpack.read('file.txt')); // defaults to 'utf8'

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('file.txt') // defaults to 'utf8'
.then(function (content) {
.then((content) => {
expectations(content);
return jetpack.readAsync('file.txt', 'utf8'); // explicitly said
})
.then(function (content) {
.then((content) => {
expectations(content);

@@ -40,8 +42,8 @@ done();

describe('reads file as a Buffer', function () {
var preparations = function () {
describe('reads file as a Buffer', () => {
const preparations = () => {
fse.outputFileSync('file.txt', new Buffer([11, 22]));
};
var expectations = function (content) {
const expectations = (content) => {
expect(Buffer.isBuffer(content)).to.equal(true);

@@ -53,3 +55,3 @@ expect(content.length).to.equal(2);

it('sync', function () {
it('sync', () => {
preparations();

@@ -59,6 +61,6 @@ expectations(jetpack.read('file.txt', 'buffer'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('file.txt', 'buffer')
.then(function (content) {
.then((content) => {
expectations(content);

@@ -70,16 +72,16 @@ done();

describe('reads file as JSON', function () {
var obj = {
utf8: 'ąćłźż'
describe('reads file as JSON', () => {
const obj = {
utf8: 'ąćłźż',
};
var preparations = function () {
const preparations = () => {
fse.outputFileSync('file.json', JSON.stringify(obj));
};
var expectations = function (content) {
const expectations = (content) => {
expect(content).to.eql(obj);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -89,6 +91,6 @@ expectations(jetpack.read('file.json', 'json'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('file.json', 'json')
.then(function (content) {
.then((content) => {
expectations(content);

@@ -100,12 +102,12 @@ done();

describe('gives nice error message when JSON parsing failed', function () {
var preparations = function () {
describe('gives nice error message when JSON parsing failed', () => {
const preparations = () => {
fse.outputFileSync('file.json', '{ "abc: 123 }'); // Malformed JSON
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.message).to.have.string('JSON parsing failed while reading');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -120,6 +122,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('file.json', 'json')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -131,17 +133,17 @@ done();

describe('reads file as JSON with Date parsing', function () {
var obj = {
describe('reads file as JSON with Date parsing', () => {
const obj = {
utf8: 'ąćłźż',
date: new Date()
date: new Date(),
};
var preparations = function () {
const preparations = () => {
fse.outputFileSync('file.json', JSON.stringify(obj));
};
var expectations = function (content) {
const expectations = (content) => {
expect(content).to.eql(obj);
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -151,6 +153,6 @@ expectations(jetpack.read('file.json', 'jsonWithDates'));

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('file.json', 'jsonWithDates')
.then(function (content) {
.then((content) => {
expectations(content);

@@ -162,8 +164,8 @@ done();

describe("returns undefined if file doesn't exist", function () {
var expectations = function (content) {
describe("returns undefined if file doesn't exist", () => {
const expectations = (content) => {
expect(content).to.equal(undefined);
};
it('sync', function () {
it('sync', () => {
expectations(jetpack.read('nonexistent.txt'));

@@ -174,13 +176,13 @@ expectations(jetpack.read('nonexistent.txt', 'json'));

it('async', function (done) {
it('async', (done) => {
jetpack.readAsync('nonexistent.txt')
.then(function (content) {
.then((content) => {
expectations(content);
return jetpack.readAsync('nonexistent.txt', 'json');
})
.then(function (content) {
.then((content) => {
expectations(content);
return jetpack.readAsync('nonexistent.txt', 'buffer');
})
.then(function (content) {
.then((content) => {
expectations(content);

@@ -192,12 +194,12 @@ done();

describe('throws if given path is a directory', function () {
var preparations = function () {
describe('throws if given path is a directory', () => {
const preparations = () => {
fse.mkdirsSync('dir');
};
var expectations = function (err) {
const expectations = (err) => {
expect(err.code).to.equal('EISDIR');
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -212,6 +214,6 @@ try {

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.readAsync('dir')
.catch(function (err) {
.catch((err) => {
expectations(err);

@@ -223,13 +225,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/file.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.equal('abc');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -239,7 +241,7 @@ expectations(jetContext.read('file.txt'));

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.readAsync('file.txt')
.then(function (data) {
.then((data) => {
expectations(data);

@@ -251,15 +253,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.read, methodName: 'read' },
{ type: 'async', method: jetpack.readAsync, methodName: 'readAsync' }
{ type: 'async', method: jetpack.readAsync, methodName: 'readAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'xyz');
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, returnAs) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, returnAs) must be a string. Received undefined`);
});

@@ -269,13 +270,11 @@ });

describe('"returnAs" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"returnAs" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', true);
}).to.throw('Argument "returnAs" passed to ' + test.methodName
+ '(path, returnAs) must be a string or an undefined. Received boolean');
expect(function () {
}).to.throw(`Argument "returnAs" passed to ${test.methodName}(path, returnAs) must be a string or an undefined. Received boolean`);
expect(() => {
test.method('abc', 'foo');
}).to.throw('Argument "returnAs" passed to ' + test.methodName
+ '(path, returnAs) must have one of values: utf8, buffer, json, jsonWithDates');
}).to.throw(`Argument "returnAs" passed to ${test.methodName}(path, returnAs) must have one of values: utf8, buffer, json, jsonWithDates`);
});

@@ -282,0 +281,0 @@ });

@@ -1,19 +0,21 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('remove', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('remove', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe("doesn't throw if path already doesn't exist", function () {
it('sync', function () {
describe("doesn't throw if path already doesn't exist", () => {
it('sync', () => {
jetpack.remove('dir');
});
it('async', function (done) {
it('async', (done) => {
jetpack.removeAsync('dir')
.then(function () {
.then(() => {
done();

@@ -24,12 +26,12 @@ });

describe('should delete file', function () {
var preparations = function () {
describe('should delete file', () => {
const preparations = () => {
fse.outputFileSync('file.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('file.txt').shouldNotExist();
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -40,6 +42,6 @@ jetpack.remove('file.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.removeAsync('file.txt')
.then(function () {
.then(() => {
expectations();

@@ -51,4 +53,4 @@ done();

describe('removes directory with stuff inside', function () {
var preparations = function () {
describe('removes directory with stuff inside', () => {
const preparations = () => {
fse.mkdirsSync('a/b/c');

@@ -59,7 +61,7 @@ fse.outputFileSync('a/f.txt', 'abc');

var expectations = function () {
const expectations = () => {
path('a').shouldNotExist();
};
it('sync', function () {
it('sync', () => {
preparations();

@@ -70,6 +72,6 @@ jetpack.remove('a');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.removeAsync('a')
.then(function () {
.then(() => {
expectations();

@@ -81,4 +83,4 @@ done();

describe('will retry attempt if file is locked', function () {
var preparations = function () {
describe('will retry attempt if file is locked', () => {
const preparations = () => {
fse.mkdirsSync('a/b/c');

@@ -89,10 +91,10 @@ fse.outputFileSync('a/f.txt', 'abc');

var expectations = function () {
const expectations = () => {
path('a').shouldNotExist();
};
it('async', function (done) {
it('async', (done) => {
preparations();
fse.open('a/f.txt', 'w', function (err, fd) {
fse.open('a/f.txt', 'w', (err, fd) => {
if (err) {

@@ -102,3 +104,3 @@ done(err);

// Unlock the file after some time.
setTimeout(function () {
setTimeout(() => {
fse.close(fd);

@@ -108,3 +110,3 @@ }, 150);

jetpack.removeAsync('a')
.then(function () {
.then(() => {
expectations();

@@ -119,8 +121,8 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', '123');
};
var expectations = function () {
const expectations = () => {
path('a').shouldBeDirectory();

@@ -130,4 +132,4 @@ path('a/b').shouldNotExist();

it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -138,7 +140,7 @@ jetContext.remove('b');

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.removeAsync('b')
.then(function () {
.then(() => {
expectations();

@@ -150,13 +152,13 @@ done();

describe('can be called with no parameters, what will remove CWD directory', function () {
var preparations = function () {
describe('can be called with no parameters, what will remove CWD directory', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a').shouldNotExist();
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -167,7 +169,7 @@ jetContext.remove();

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.removeAsync()
.then(function () {
.then(() => {
expectations();

@@ -179,4 +181,4 @@ done();

describe('removes only symlinks, never real content where symlinks point', function () {
var preparations = function () {
describe('removes only symlinks, never real content where symlinks point', () => {
const preparations = () => {
fse.outputFileSync('have_to_stay_file', 'abc');

@@ -189,3 +191,3 @@ fse.mkdirsSync('to_remove');

var expectations = function () {
const expectations = () => {
path('have_to_stay_file').shouldBeFileWithContent('abc');

@@ -195,3 +197,3 @@ path('to_remove').shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -202,6 +204,6 @@ jetpack.remove('to_remove');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.removeAsync('to_remove')
.then(function () {
.then(() => {
expectations();

@@ -213,15 +215,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.remove, methodName: 'remove' },
{ type: 'async', method: jetpack.removeAsync, methodName: 'removeAsync' }
{ type: 'async', method: jetpack.removeAsync, methodName: 'removeAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(true);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '([path]) must be a string or an undefined. Received boolean');
}).to.throw(`Argument "path" passed to ${test.methodName}([path]) must be a string or an undefined. Received boolean`);
});

@@ -228,0 +229,0 @@ });

@@ -1,17 +0,19 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('rename', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('rename', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('renames file', function () {
var preparations = function () {
describe('renames file', () => {
const preparations = () => {
fse.outputFileSync('a/b.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b.txt').shouldNotExist();

@@ -21,3 +23,3 @@ path('a/x.txt').shouldBeFileWithContent('abc');

it('sync', function () {
it('sync', () => {
preparations();

@@ -28,6 +30,6 @@ jetpack.rename('a/b.txt', 'x.txt');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.renameAsync('a/b.txt', 'x.txt')
.then(function () {
.then(() => {
expectations();

@@ -39,8 +41,8 @@ done();

describe('renames directory', function () {
var preparations = function () {
describe('renames directory', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b').shouldNotExist();

@@ -50,3 +52,3 @@ path('a/x').shouldBeDirectory();

it('sync', function () {
it('sync', () => {
preparations();

@@ -57,6 +59,6 @@ jetpack.rename('a/b', 'x');

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.renameAsync('a/b', 'x')
.then(function () {
.then(() => {
expectations();

@@ -68,8 +70,8 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.outputFileSync('a/b/c.txt', 'abc');
};
var expectations = function () {
const expectations = () => {
path('a/b').shouldNotExist();

@@ -79,4 +81,4 @@ path('a/x').shouldBeDirectory();

it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
preparations();

@@ -87,7 +89,7 @@ jetContext.rename('b', 'x');

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
preparations();
jetContext.renameAsync('b', 'x')
.then(function () {
.then(() => {
expectations();

@@ -99,15 +101,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.rename, methodName: 'rename' },
{ type: 'async', method: jetpack.renameAsync, methodName: 'renameAsync' }
{ type: 'async', method: jetpack.renameAsync, methodName: 'renameAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'xyz');
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, newName) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, newName) must be a string. Received undefined`);
});

@@ -117,9 +118,8 @@ });

describe('"newName" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"newName" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', undefined);
}).to.throw('Argument "newName" passed to ' + test.methodName
+ '(path, newName) must be a string. Received undefined');
}).to.throw(`Argument "newName" passed to ${test.methodName}(path, newName) must be a string. Received undefined`);
});

@@ -126,0 +126,0 @@ });

@@ -1,19 +0,18 @@

var fse = require('fs-extra');
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('streams', function () {
const fse = require('fs-extra');
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('streams', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
it('exposes vanilla stream methods', function (done) {
var input;
var output;
it('exposes vanilla stream methods', (done) => {
fse.outputFileSync('a.txt', 'abc');
input = jetpack.createReadStream('a.txt');
output = jetpack.createWriteStream('b.txt');
output.on('finish', function () {
const input = jetpack.createReadStream('a.txt');
const output = jetpack.createWriteStream('b.txt');
output.on('finish', () => {
path('b.txt').shouldBeFileWithContent('abc');

@@ -25,13 +24,10 @@ done();

it('stream methods respect jetpack internal CWD', function (done) {
var input;
var output;
it('stream methods respect jetpack internal CWD', (done) => {
const dir = jetpack.cwd('dir');
var dir = jetpack.cwd('dir');
fse.outputFileSync('dir/a.txt', 'abc');
input = dir.createReadStream('a.txt');
output = dir.createWriteStream('b.txt');
output.on('finish', function () {
const input = dir.createReadStream('a.txt');
const output = dir.createWriteStream('b.txt');
output.on('finish', () => {
path('dir/b.txt').shouldBeFileWithContent('abc');

@@ -38,0 +34,0 @@ done();

@@ -1,12 +0,14 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('symlink', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const helper = require('./helper');
const jetpack = require('..');
describe('symlink', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('can create a symlink', function () {
var expectations = function () {
describe('can create a symlink', () => {
const expectations = () => {
expect(fse.lstatSync('symlink').isSymbolicLink()).to.equal(true);

@@ -16,3 +18,3 @@ expect(fse.readlinkSync('symlink')).to.equal('some_path');

it('sync', function () {
it('sync', () => {
jetpack.symlink('some_path', 'symlink');

@@ -22,5 +24,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.symlinkAsync('some_path', 'symlink')
.then(function () {
.then(() => {
expectations();

@@ -32,8 +34,8 @@ done();

describe('can create nonexistent parent directories', function () {
var expectations = function () {
describe('can create nonexistent parent directories', () => {
const expectations = () => {
expect(fse.lstatSync('a/b/symlink').isSymbolicLink()).to.equal(true);
};
it('sync', function () {
it('sync', () => {
jetpack.symlink('whatever', 'a/b/symlink');

@@ -43,5 +45,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.symlinkAsync('whatever', 'a/b/symlink')
.then(function () {
.then(() => {
expectations();

@@ -53,13 +55,13 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var preparations = function () {
describe('respects internal CWD of jetpack instance', () => {
const preparations = () => {
fse.mkdirsSync('a/b');
};
var expectations = function () {
const expectations = () => {
expect(fse.lstatSync('a/b/symlink').isSymbolicLink()).to.equal(true);
};
it('sync', function () {
var jetContext = jetpack.cwd('a/b');
it('sync', () => {
const jetContext = jetpack.cwd('a/b');
preparations();

@@ -70,7 +72,7 @@ jetContext.symlink('whatever', 'symlink');

it('async', function (done) {
var jetContext = jetpack.cwd('a/b');
it('async', (done) => {
const jetContext = jetpack.cwd('a/b');
preparations();
jetContext.symlinkAsync('whatever', 'symlink')
.then(function () {
.then(() => {
expectations();

@@ -82,15 +84,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.symlink, methodName: 'symlink' },
{ type: 'async', method: jetpack.symlinkAsync, methodName: 'symlinkAsync' }
{ type: 'async', method: jetpack.symlinkAsync, methodName: 'symlinkAsync' },
];
describe('"symlinkValue" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"symlinkValue" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined, 'abc');
}).to.throw('Argument "symlinkValue" passed to ' + test.methodName
+ '(symlinkValue, path) must be a string. Received undefined');
}).to.throw(`Argument "symlinkValue" passed to ${test.methodName}(symlinkValue, path) must be a string. Received undefined`);
});

@@ -100,9 +101,8 @@ });

describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('xyz', undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(symlinkValue, path) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(symlinkValue, path) must be a string. Received undefined`);
});

@@ -109,0 +109,0 @@ });

@@ -1,11 +0,13 @@

var fsNode = require('fs');
var expect = require('chai').expect;
var fs = require('../../lib/utils/fs');
'use strict';
describe('fs', function () {
it('contains all the same keys as the node fs module', function () {
var originalKeys = Object.keys(fsNode);
var adaptedKeys = Object.keys(fs);
const fsNode = require('fs');
const expect = require('chai').expect;
const fs = require('../../lib/utils/fs');
describe('promised fs', () => {
it('contains all the same keys as the node fs module', () => {
const originalKeys = Object.keys(fsNode);
const adaptedKeys = Object.keys(fs);
expect(adaptedKeys).to.deep.equal(originalKeys);
});
});

@@ -1,7 +0,9 @@

var expect = require('chai').expect;
var matcher = require('../../lib/utils/matcher');
'use strict';
describe('matcher', function () {
it('can test against one pattern passed as a string', function () {
var test = matcher.create('/', 'a');
const expect = require('chai').expect;
const matcher = require('../../lib/utils/matcher');
describe('matcher', () => {
it('can test against one pattern passed as a string', () => {
const test = matcher.create('/', 'a');
expect(test('/a')).to.equal(true);

@@ -11,4 +13,4 @@ expect(test('/b')).to.equal(false);

it('can test against many patterns passed as an array', function () {
var test = matcher.create('/', ['a', 'b']);
it('can test against many patterns passed as an array', () => {
const test = matcher.create('/', ['a', 'b']);
expect(test('/a')).to.equal(true);

@@ -19,5 +21,5 @@ expect(test('/b')).to.equal(true);

describe('pattern types', function () {
it('only basename', function () {
var test = matcher.create('/', 'a');
describe('pattern types', () => {
it('only basename', () => {
const test = matcher.create('/', 'a');
expect(test('/a')).to.equal(true);

@@ -28,4 +30,4 @@ expect(test('/b/a')).to.equal(true);

it('absolute', function () {
var test = matcher.create('/', ['/b']);
it('absolute', () => {
let test = matcher.create('/', ['/b']);
expect(test('/b')).to.equal(true);

@@ -37,4 +39,4 @@ expect(test('/a/b')).to.equal(false);

it('relative with ./', function () {
var test = matcher.create('/a', ['./b']);
it('relative with ./', () => {
const test = matcher.create('/a', ['./b']);
expect(test('/a/b')).to.equal(true);

@@ -44,4 +46,4 @@ expect(test('/b')).to.equal(false);

it('relative (because has slash inside)', function () {
var test = matcher.create('/a', ['b/c']);
it('relative (because has slash inside)', () => {
const test = matcher.create('/a', ['b/c']);
expect(test('/a/b/c')).to.equal(true);

@@ -52,5 +54,5 @@ expect(test('/b/c')).to.equal(false);

describe('possible tokens', function () {
it('*', function () {
var test = matcher.create('/', ['*']);
describe('possible tokens', () => {
it('*', () => {
let test = matcher.create('/', ['*']);
expect(test('/a')).to.equal(true);

@@ -65,4 +67,4 @@ expect(test('/a/b.txt')).to.equal(true);

it('**', function () {
var test = matcher.create('/', ['**']);
it('**', () => {
let test = matcher.create('/', ['**']);
expect(test('/a')).to.equal(true);

@@ -79,4 +81,4 @@ expect(test('/a/b')).to.equal(true);

it('**/something', function () {
var test = matcher.create('/', ['**/a']);
it('**/something', () => {
const test = matcher.create('/', ['**/a']);
expect(test('/a')).to.equal(true);

@@ -88,4 +90,4 @@ expect(test('/x/a')).to.equal(true);

it('@(pattern|pattern) - exactly one of patterns', function () {
var test = matcher.create('/', ['@(foo|bar)']);
it('@(pattern|pattern) - exactly one of patterns', () => {
const test = matcher.create('/', ['@(foo|bar)']);
expect(test('/foo')).to.equal(true);

@@ -96,4 +98,4 @@ expect(test('/bar')).to.equal(true);

it('+(pattern|pattern) - one or more of patterns', function () {
var test = matcher.create('/', ['+(foo|bar)']);
it('+(pattern|pattern) - one or more of patterns', () => {
const test = matcher.create('/', ['+(foo|bar)']);
expect(test('/foo')).to.equal(true);

@@ -105,4 +107,4 @@ expect(test('/bar')).to.equal(true);

it('?(pattern|pattern) - zero or one of patterns', function () {
var test = matcher.create('/', ['?(foo|bar)1']);
it('?(pattern|pattern) - zero or one of patterns', () => {
const test = matcher.create('/', ['?(foo|bar)1']);
expect(test('/1')).to.equal(true);

@@ -114,4 +116,4 @@ expect(test('/foo1')).to.equal(true);

it('*(pattern|pattern) - zero or more of patterns', function () {
var test = matcher.create('/', ['*(foo|bar)1']);
it('*(pattern|pattern) - zero or more of patterns', () => {
const test = matcher.create('/', ['*(foo|bar)1']);
expect(test('/1')).to.equal(true);

@@ -125,4 +127,4 @@ expect(test('/foo1')).to.equal(true);

it('{a,b}', function () {
var test = matcher.create('/', ['*.{jpg,png}']);
it('{a,b}', () => {
const test = matcher.create('/', ['*.{jpg,png}']);
expect(test('a.jpg')).to.equal(true);

@@ -133,4 +135,4 @@ expect(test('b.png')).to.equal(true);

it('?', function () {
var test = matcher.create('/', ['a?c']);
it('?', () => {
const test = matcher.create('/', ['a?c']);
expect(test('/abc')).to.equal(true);

@@ -141,4 +143,4 @@ expect(test('/ac')).to.equal(false);

it('[...] - characters range', function () {
var test = matcher.create('/', ['[0-9][0-9]']);
it('[...] - characters range', () => {
const test = matcher.create('/', ['[0-9][0-9]']);
expect(test('/78')).to.equal(true);

@@ -148,4 +150,4 @@ expect(test('/a78')).to.equal(false);

it('combining different tokens together', function () {
var test = matcher.create('/', ['+(f?o|bar*)']);
it('combining different tokens together', () => {
const test = matcher.create('/', ['+(f?o|bar*)']);
expect(test('/f0o')).to.equal(true);

@@ -159,4 +161,4 @@ expect(test('/f_o')).to.equal(true);

it('comment character # has no special meaning', function () {
var test = matcher.create('/', ['#a']);
it('comment character # has no special meaning', () => {
const test = matcher.create('/', ['#a']);
expect(test('/#a')).to.equal(true);

@@ -166,5 +168,5 @@ });

describe('negation', function () {
it('selects everything except negated', function () {
var test = matcher.create('/', '!abc');
describe('negation', () => {
it('selects everything except negated', () => {
const test = matcher.create('/', '!abc');
expect(test('/abc')).to.equal(false);

@@ -174,4 +176,4 @@ expect(test('/xyz')).to.equal(true);

it('selects everything except negated (multiple patterns)', function () {
var test = matcher.create('/', ['!abc', '!xyz']);
it('selects everything except negated (multiple patterns)', () => {
const test = matcher.create('/', ['!abc', '!xyz']);
expect(test('/abc')).to.equal(false);

@@ -182,4 +184,4 @@ expect(test('/xyz')).to.equal(false);

it('filters previous match if negation is farther in order', function () {
var test = matcher.create('/', ['abc', '123', '!/xyz/**', '!789/**']);
it('filters previous match if negation is farther in order', () => {
const test = matcher.create('/', ['abc', '123', '!/xyz/**', '!789/**']);
expect(test('/abc')).to.equal(true);

@@ -193,5 +195,5 @@ expect(test('/456/123')).to.equal(true);

describe('dotfiles', function () {
it('has no problem with matching dotfile', function () {
var test = matcher.create('/', '.foo');
describe('dotfiles', () => {
it('has no problem with matching dotfile', () => {
const test = matcher.create('/', '.foo');
expect(test('/.foo')).to.equal(true);

@@ -201,4 +203,4 @@ expect(test('/foo')).to.equal(false);

it('dotfile negation', function () {
var test = matcher.create('/', ['abc', '!.foo/**']);
it('dotfile negation', () => {
let test = matcher.create('/', ['abc', '!.foo/**']);
expect(test('/.foo/abc')).to.equal(false);

@@ -205,0 +207,0 @@ test = matcher.create('/', ['abc', '!.foo/**']);

@@ -1,15 +0,15 @@

/* eslint no-console:0 */
'use strict';
var fse = require('fs-extra');
var pathUtil = require('path');
var expect = require('chai').expect;
var helper = require('../helper');
var walker = require('../../lib/utils/tree_walker');
const fse = require('fs-extra');
const pathUtil = require('path');
const expect = require('chai').expect;
const helper = require('../helper');
const walker = require('../../lib/utils/tree_walker');
describe('tree walker', function () {
describe('tree walker', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('inspects all files and folders recursively and returns them one by one', function () {
var preparations = function () {
describe('inspects all files and folders recursively and returns them one by one', () => {
const preparations = () => {
fse.outputFileSync('a/a.txt', 'a');

@@ -21,3 +21,3 @@ fse.outputFileSync('a/b/z1.txt', 'z1');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -28,4 +28,4 @@ {

type: 'dir',
name: 'a'
}
name: 'a',
},
},

@@ -37,4 +37,4 @@ {

name: 'a.txt',
size: 1
}
size: 1,
},
},

@@ -45,4 +45,4 @@ {

type: 'dir',
name: 'b'
}
name: 'b',
},
},

@@ -53,4 +53,4 @@ {

type: 'dir',
name: 'c'
}
name: 'c',
},
},

@@ -62,4 +62,4 @@ {

name: 'z1.txt',
size: 2
}
size: 2,
},
},

@@ -71,14 +71,14 @@ {

name: 'z2.txt',
size: 2
}
}
size: 2,
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
walker.sync(absoluteStartingPath, {}, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, {}, (path, item) => {
data.push({ path, item });
});

@@ -88,10 +88,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, {})
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, {})
.on('readable', () => {
const a = st.read();
if (a) {

@@ -101,4 +100,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -110,4 +109,4 @@ done();

describe('can walk through many nested directories', function () {
var preparations = function () {
describe('can walk through many nested directories', () => {
const preparations = () => {
fse.outputFileSync('a/b/x/z1.txt', 'z1');

@@ -117,3 +116,3 @@ fse.outputFileSync('a/c/y/z2.txt', 'z2');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -124,4 +123,4 @@ {

type: 'dir',
name: 'a'
}
name: 'a',
},
},

@@ -132,4 +131,4 @@ {

type: 'dir',
name: 'b'
}
name: 'b',
},
},

@@ -140,4 +139,4 @@ {

type: 'dir',
name: 'x'
}
name: 'x',
},
},

@@ -149,4 +148,4 @@ {

name: 'z1.txt',
size: 2
}
size: 2,
},
},

@@ -157,4 +156,4 @@ {

type: 'dir',
name: 'c'
}
name: 'c',
},
},

@@ -165,4 +164,4 @@ {

type: 'dir',
name: 'y'
}
name: 'y',
},
},

@@ -174,14 +173,14 @@ {

name: 'z2.txt',
size: 2
}
}
size: 2,
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
walker.sync(absoluteStartingPath, {}, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, {}, (path, item) => {
data.push({ path, item });
});

@@ -191,10 +190,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, {})
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, {})
.on('readable', () => {
const a = st.read();
if (a) {

@@ -204,4 +202,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -214,8 +212,8 @@ done();

describe("won't penetrate folder tree deeper than maxLevelsDeep option tells", function () {
var options = {
maxLevelsDeep: 1
describe("won't penetrate folder tree deeper than maxLevelsDeep option tells", () => {
const options = {
maxLevelsDeep: 1,
};
var preparations = function () {
const preparations = () => {
fse.outputFileSync('a/a.txt', 'a');

@@ -225,3 +223,3 @@ fse.outputFileSync('a/b/z1.txt', 'z1');

var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -232,4 +230,4 @@ {

type: 'dir',
name: 'a'
}
name: 'a',
},
},

@@ -241,4 +239,4 @@ {

name: 'a.txt',
size: 1
}
size: 1,
},
},

@@ -249,14 +247,14 @@ {

type: 'dir',
name: 'b'
}
}
name: 'b',
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
walker.sync(absoluteStartingPath, options, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, options, (path, item) => {
data.push({ path, item });
});

@@ -266,10 +264,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('a');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('a');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, options)
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, options)
.on('readable', () => {
const a = st.read();
if (a) {

@@ -279,4 +276,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -288,8 +285,8 @@ done();

describe('will do fine with empty directory as entry point', function () {
var preparations = function () {
describe('will do fine with empty directory as entry point', () => {
const preparations = () => {
fse.mkdirsSync('abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -300,14 +297,14 @@ {

type: 'dir',
name: 'abc'
}
}
name: 'abc',
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('abc');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('abc');
const data = [];
preparations();
walker.sync(absoluteStartingPath, {}, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, {}, (path, item) => {
data.push({ path, item });
});

@@ -317,10 +314,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('abc');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('abc');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, {})
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, {})
.on('readable', () => {
const a = st.read();
if (a) {

@@ -330,4 +326,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -339,8 +335,8 @@ done();

describe('will do fine with file as entry point', function () {
var preparations = function () {
describe('will do fine with file as entry point', () => {
const preparations = () => {
fse.outputFileSync('abc.txt', 'abc');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -352,14 +348,14 @@ {

name: 'abc.txt',
size: 3
}
}
size: 3,
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('abc.txt');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('abc.txt');
const data = [];
preparations();
walker.sync(absoluteStartingPath, {}, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, {}, (path, item) => {
data.push({ path, item });
});

@@ -369,10 +365,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('abc.txt');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('abc.txt');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, {})
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, {})
.on('readable', () => {
const a = st.read();
if (a) {

@@ -382,4 +377,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -391,17 +386,17 @@ done();

describe('will do fine with nonexistent entry point', function () {
var expectations = function (data) {
describe('will do fine with nonexistent entry point', () => {
const expectations = (data) => {
expect(data).to.eql([
{
path: pathUtil.resolve('abc.txt'),
item: undefined
}
item: undefined,
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('abc.txt');
var data = [];
walker.sync(absoluteStartingPath, {}, function (path, item) {
data.push({ path: path, item: item });
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('abc.txt');
const data = [];
walker.sync(absoluteStartingPath, {}, (path, item) => {
data.push({ path, item });
});

@@ -411,9 +406,8 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('abc.txt');
var data = [];
var st;
st = walker.stream(absoluteStartingPath, {})
.on('readable', function () {
var a = st.read();
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('abc.txt');
const data = [];
const st = walker.stream(absoluteStartingPath, {})
.on('readable', () => {
const a = st.read();
if (a) {

@@ -423,4 +417,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -432,14 +426,14 @@ done();

describe('supports inspect options', function () {
var options = {
describe('supports inspect options', () => {
const options = {
inspectOptions: {
checksum: 'md5'
}
checksum: 'md5',
},
};
var preparations = function () {
const preparations = () => {
fse.outputFileSync('abc/a.txt', 'a');
};
var expectations = function (data) {
const expectations = (data) => {
expect(data).to.eql([

@@ -450,4 +444,4 @@ {

type: 'dir',
name: 'abc'
}
name: 'abc',
},
},

@@ -460,14 +454,14 @@ {

size: 1,
md5: '0cc175b9c0f1b6a831c399e269772661'
}
}
md5: '0cc175b9c0f1b6a831c399e269772661',
},
},
]);
};
it('sync', function () {
var absoluteStartingPath = pathUtil.resolve('abc');
var data = [];
it('sync', () => {
const absoluteStartingPath = pathUtil.resolve('abc');
const data = [];
preparations();
walker.sync(absoluteStartingPath, options, function (path, item) {
data.push({ path: path, item: item });
walker.sync(absoluteStartingPath, options, (path, item) => {
data.push({ path, item });
});

@@ -477,10 +471,9 @@ expectations(data);

it('async', function (done) {
var absoluteStartingPath = pathUtil.resolve('abc');
var data = [];
var st;
it('async', (done) => {
const absoluteStartingPath = pathUtil.resolve('abc');
const data = [];
preparations();
st = walker.stream(absoluteStartingPath, options)
.on('readable', function () {
var a = st.read();
const st = walker.stream(absoluteStartingPath, options)
.on('readable', () => {
const a = st.read();
if (a) {

@@ -490,4 +483,4 @@ data.push(a);

})
.on('error', console.error)
.on('end', function () {
.on('error', done)
.on('end', () => {
expectations(data);

@@ -494,0 +487,0 @@ done();

@@ -1,8 +0,10 @@

var expect = require('chai').expect;
var validate = require('../../lib/utils/validate');
'use strict';
describe('util validate', function () {
describe('validates arguments passed to methods', function () {
it('validates its own input', function () {
expect(function () {
const expect = require('chai').expect;
const validate = require('../../lib/utils/validate');
describe('util validate', () => {
describe('validates arguments passed to methods', () => {
it('validates its own input', () => {
expect(() => {
validate.argument('foo(thing)', 'thing', 123, ['foo']);

@@ -14,44 +16,67 @@ }).to.throw('Unknown type "foo"');

{
type: 'string', article: 'a', goodValue: 'abc',
wrongValue: 123, wrongValueType: 'number'
type: 'string',
article: 'a',
goodValue: 'abc',
wrongValue: 123,
wrongValueType: 'number',
},
{
type: 'number', article: 'a', goodValue: 123,
wrongValue: 'abc', wrongValueType: 'string'
type: 'number',
article: 'a',
goodValue: 123,
wrongValue: 'abc',
wrongValueType: 'string',
},
{
type: 'boolean', article: 'a', goodValue: true,
wrongValue: 'abc', wrongValueType: 'string'
type: 'boolean',
article: 'a',
goodValue: true,
wrongValue: 'abc',
wrongValueType: 'string',
},
{
type: 'array', article: 'an', goodValue: [],
wrongValue: {}, wrongValueType: 'object'
type: 'array',
article: 'an',
goodValue: [],
wrongValue: {},
wrongValueType: 'object',
},
{
type: 'object', article: 'an', goodValue: {},
wrongValue: [], wrongValueType: 'array'
type: 'object',
article: 'an',
goodValue: {},
wrongValue: [],
wrongValueType: 'array',
},
{
type: 'buffer', article: 'a', goodValue: new Buffer(1),
wrongValue: 123, wrongValueType: 'number'
type: 'buffer',
article: 'a',
goodValue: new Buffer(1),
wrongValue: 123,
wrongValueType: 'number',
},
{
type: 'null', article: 'a', goodValue: null,
wrongValue: 123, wrongValueType: 'number'
type: 'null',
article: 'a',
goodValue: null,
wrongValue: 123,
wrongValueType: 'number',
},
{
type: 'undefined', article: 'an', goodValue: undefined,
wrongValue: 123, wrongValueType: 'number'
}
type: 'undefined',
article: 'an',
goodValue: undefined,
wrongValue: 123,
wrongValueType: 'number',
},
]
.forEach(function (test) {
it('validates that given thing is a(n) ' + test.type, function () {
expect(function () {
.forEach((test) => {
it(`validates that given thing is a(n) ${test.type}`, () => {
expect(() => {
validate.argument('foo(thing)', 'thing', test.goodValue, [test.type]);
}).not.to.throw();
expect(function () {
expect(() => {
validate.argument('foo(thing)', 'thing', test.wrongValue, [test.type]);
}).to.throw('Argument "thing" passed to foo(thing) must be ' + test.article
+ ' ' + test.type + '. Received ' + test.wrongValueType);
}).to.throw(`Argument "thing" passed to foo(thing) must be ${test.article} ${test.type}. Received ${test.wrongValueType}`);
});

@@ -68,35 +93,32 @@ });

{ type: 'null', value: null, expect: 'number' },
{ type: 'undefined', value: undefined, expect: 'number' }
{ type: 'undefined', value: undefined, expect: 'number' },
]
.forEach(function (test) {
it('can detect wrong type: ' + test.type, function () {
expect(function () {
.forEach((test) => {
it(`can detect wrong type: ${test.type}`, () => {
expect(() => {
validate.argument('foo(thing)', 'thing', test.value, [test.expect]);
}).to.throw('Argument "thing" passed to foo(thing) must be a '
+ test.expect + '. Received ' + test.type);
}).to.throw(`Argument "thing" passed to foo(thing) must be a ${test.expect}. Received ${test.type}`);
});
});
it('supports more than one allowed type', function () {
expect(function () {
it('supports more than one allowed type', () => {
expect(() => {
validate.argument('foo(thing)', 'thing', {}, ['string', 'number', 'boolean']);
}).to.throw('Argument "thing" passed to foo(thing) must be a string'
+ ' or a number or a boolean. Received object');
}).to.throw('Argument "thing" passed to foo(thing) must be a string or a number or a boolean. Received object');
});
it('validates array internal data', function () {
expect(function () {
it('validates array internal data', () => {
expect(() => {
validate.argument('foo(thing)', 'thing', [1, 2, 3], ['array of number']);
}).not.to.throw();
expect(function () {
expect(() => {
validate.argument('foo(thing)', 'thing', [1, 2, 'a'], ['array of number']);
}).to.throw('Argument "thing" passed to foo(thing) must be an array of number.'
+ ' Received array of number, string');
}).to.throw('Argument "thing" passed to foo(thing) must be an array of number. Received array of number, string');
});
});
describe('validates options object', function () {
it('options object might be undefined', function () {
expect(function () {
describe('validates options object', () => {
it('options object might be undefined', () => {
expect(() => {
validate.options('foo(options)', 'options', undefined, { foo: ['string'] });

@@ -106,4 +128,4 @@ }).not.to.throw();

it('option key in options object is optional (doh!)', function () {
expect(function () {
it('option key in options object is optional (doh!)', () => {
expect(() => {
validate.options('foo(options)', 'options', {}, { foo: ['string'] });

@@ -113,4 +135,4 @@ }).not.to.throw();

it('throws if option key definition not found', function () {
expect(function () {
it('throws if option key definition not found', () => {
expect(() => {
validate.options('foo(options)', 'options',

@@ -123,4 +145,4 @@ { bar: 123 },

it('validates option', function () {
expect(function () {
it('validates option', () => {
expect(() => {
validate.options('foo(options)', 'options',

@@ -132,3 +154,3 @@ { foo: 'abc' },

expect(function () {
expect(() => {
validate.options('foo(options)', 'options',

@@ -138,6 +160,5 @@ { foo: 123 },

);
}).to.throw('Argument "options.foo" passed to foo(options) must be'
+ ' a string. Received number');
}).to.throw('Argument "options.foo" passed to foo(options) must be a string. Received number');
});
});
});

@@ -1,15 +0,17 @@

var fse = require('fs-extra');
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('atomic write', function () {
var filePath = 'file.txt';
var tempPath = filePath + '.__new__';
const fse = require('fs-extra');
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('atomic write', () => {
const filePath = 'file.txt';
const tempPath = `${filePath}.__new__`;
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe("fresh write (file doesn't exist yet)", function () {
var expectations = function () {
describe("fresh write (file doesn't exist yet)", () => {
const expectations = () => {
path(filePath).shouldBeFileWithContent('abc');

@@ -19,3 +21,3 @@ path(tempPath).shouldNotExist();

it('sync', function () {
it('sync', () => {
jetpack.write(filePath, 'abc', { atomic: true });

@@ -25,5 +27,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync(filePath, 'abc', { atomic: true })
.then(function () {
.then(() => {
expectations();

@@ -35,8 +37,8 @@ done();

describe('overwrite existing file', function () {
var preparations = function () {
describe('overwrite existing file', () => {
const preparations = () => {
fse.outputFileSync(filePath, 'xyz');
};
var expectations = function () {
const expectations = () => {
path(filePath).shouldBeFileWithContent('abc');

@@ -46,3 +48,3 @@ path(tempPath).shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -53,6 +55,6 @@ jetpack.write(filePath, 'abc', { atomic: true });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.writeAsync(filePath, 'abc', { atomic: true })
.then(function () {
.then(() => {
expectations();

@@ -64,4 +66,4 @@ done();

describe('if previous operation failed', function () {
var preparations = function () {
describe('if previous operation failed', () => {
const preparations = () => {
fse.outputFileSync(filePath, 'xyz');

@@ -72,3 +74,3 @@ // Simulating remained file from interrupted previous write attempt.

var expectations = function () {
const expectations = () => {
path(filePath).shouldBeFileWithContent('abc');

@@ -78,3 +80,3 @@ path(tempPath).shouldNotExist();

it('sync', function () {
it('sync', () => {
preparations();

@@ -85,6 +87,6 @@ jetpack.write(filePath, 'abc', { atomic: true });

it('async', function (done) {
it('async', (done) => {
preparations();
jetpack.writeAsync(filePath, 'abc', { atomic: true })
.then(function () {
.then(() => {
expectations();

@@ -91,0 +93,0 @@ done();

@@ -1,17 +0,19 @@

var fse = require('fs-extra');
var expect = require('chai').expect;
var path = require('./assert_path');
var helper = require('./helper');
var jetpack = require('..');
'use strict';
describe('write', function () {
const fse = require('fs-extra');
const expect = require('chai').expect;
const path = require('./assert_path');
const helper = require('./helper');
const jetpack = require('..');
describe('write', () => {
beforeEach(helper.setCleanTestCwd);
afterEach(helper.switchBackToCorrectCwd);
describe('writes data from string', function () {
var expectations = function () {
describe('writes data from string', () => {
const expectations = () => {
path('file.txt').shouldBeFileWithContent('abc');
};
it('sync', function () {
it('sync', () => {
jetpack.write('file.txt', 'abc');

@@ -21,5 +23,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync('file.txt', 'abc')
.then(function () {
.then(() => {
expectations();

@@ -31,8 +33,8 @@ done();

describe('writes data from Buffer', function () {
var expectations = function () {
describe('writes data from Buffer', () => {
const expectations = () => {
path('file.txt').shouldBeFileWithContent(new Buffer([11, 22]));
};
it('sync', function () {
it('sync', () => {
jetpack.write('file.txt', new Buffer([11, 22]));

@@ -42,5 +44,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync('file.txt', new Buffer([11, 22]))
.then(function () {
.then(() => {
expectations();

@@ -52,13 +54,13 @@ done();

describe('writes data as JSON', function () {
var obj = {
utf8: 'ąćłźż'
describe('writes data as JSON', () => {
const obj = {
utf8: 'ąćłźż',
};
var expectations = function () {
var content = JSON.parse(fse.readFileSync('file.json', 'utf8'));
const expectations = () => {
const content = JSON.parse(fse.readFileSync('file.json', 'utf8'));
expect(content).to.eql(obj);
};
it('sync', function () {
it('sync', () => {
jetpack.write('file.json', obj);

@@ -68,5 +70,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync('file.json', obj)
.then(function () {
.then(() => {
expectations();

@@ -78,11 +80,11 @@ done();

describe('written JSON data can be indented', function () {
var obj = {
utf8: 'ąćłźż'
describe('written JSON data can be indented', () => {
const obj = {
utf8: 'ąćłźż',
};
var expectations = function () {
var sizeA = fse.statSync('a.json').size;
var sizeB = fse.statSync('b.json').size;
var sizeC = fse.statSync('c.json').size;
const expectations = () => {
const sizeA = fse.statSync('a.json').size;
const sizeB = fse.statSync('b.json').size;
const sizeC = fse.statSync('c.json').size;
expect(sizeB).to.be.above(sizeA);

@@ -92,3 +94,3 @@ expect(sizeC).to.be.above(sizeB);

it('sync', function () {
it('sync', () => {
jetpack.write('a.json', obj, { jsonIndent: 0 });

@@ -100,9 +102,9 @@ jetpack.write('b.json', obj); // Default indent = 2

it('async', function (done) {
it('async', (done) => {
Promise.all([
jetpack.writeAsync('a.json', obj, { jsonIndent: 0 }),
jetpack.writeAsync('b.json', obj), // Default indent = 2
jetpack.writeAsync('c.json', obj, { jsonIndent: 4 })
jetpack.writeAsync('c.json', obj, { jsonIndent: 4 }),
])
.then(function () {
.then(() => {
expectations();

@@ -114,13 +116,13 @@ done();

describe('writes and reads file as JSON with Date parsing', function () {
var obj = {
date: new Date()
describe('writes and reads file as JSON with Date parsing', () => {
const obj = {
date: new Date(),
};
var expectations = function () {
var content = JSON.parse(fse.readFileSync('file.json', 'utf8'));
const expectations = () => {
const content = JSON.parse(fse.readFileSync('file.json', 'utf8'));
expect(content.date).to.equal(obj.date.toISOString());
};
it('sync', function () {
it('sync', () => {
jetpack.write('file.json', obj);

@@ -130,5 +132,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync('file.json', obj)
.then(function () {
.then(() => {
expectations();

@@ -140,8 +142,8 @@ done();

describe('can create nonexistent parent directories', function () {
var expectations = function () {
describe('can create nonexistent parent directories', () => {
const expectations = () => {
path('a/b/c.txt').shouldBeFileWithContent('abc');
};
it('sync', function () {
it('sync', () => {
jetpack.write('a/b/c.txt', 'abc');

@@ -151,5 +153,5 @@ expectations();

it('async', function (done) {
it('async', (done) => {
jetpack.writeAsync('a/b/c.txt', 'abc')
.then(function () {
.then(() => {
expectations();

@@ -161,9 +163,9 @@ done();

describe('respects internal CWD of jetpack instance', function () {
var expectations = function () {
describe('respects internal CWD of jetpack instance', () => {
const expectations = () => {
path('a/b/c.txt').shouldBeFileWithContent('abc');
};
it('sync', function () {
var jetContext = jetpack.cwd('a');
it('sync', () => {
const jetContext = jetpack.cwd('a');
jetContext.write('b/c.txt', 'abc');

@@ -173,6 +175,6 @@ expectations();

it('async', function (done) {
var jetContext = jetpack.cwd('a');
it('async', (done) => {
const jetContext = jetpack.cwd('a');
jetContext.writeAsync('b/c.txt', 'abc')
.then(function () {
.then(() => {
expectations();

@@ -184,15 +186,14 @@ done();

describe('input validation', function () {
var tests = [
describe('input validation', () => {
const tests = [
{ type: 'sync', method: jetpack.write, methodName: 'write' },
{ type: 'async', method: jetpack.writeAsync, methodName: 'writeAsync' }
{ type: 'async', method: jetpack.writeAsync, methodName: 'writeAsync' },
];
describe('"path" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"path" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method(undefined);
}).to.throw('Argument "path" passed to ' + test.methodName
+ '(path, data, [options]) must be a string. Received undefined');
}).to.throw(`Argument "path" passed to ${test.methodName}(path, data, [options]) must be a string. Received undefined`);
});

@@ -202,10 +203,8 @@ });

describe('"data" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"data" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', true);
}).to.throw('Argument "data" passed to ' + test.methodName
+ '(path, data, [options]) must be a string or a buffer or an object or '
+ 'an array. Received boolean');
}).to.throw(`Argument "data" passed to ${test.methodName}(path, data, [options]) must be a string or a buffer or an object or an array. Received boolean`);
});

@@ -215,20 +214,18 @@ });

describe('"options" object', function () {
describe('"atomic" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"options" object', () => {
describe('"atomic" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', 'xyz', { atomic: 1 });
}).to.throw('Argument "options.atomic" passed to ' + test.methodName
+ '(path, data, [options]) must be a boolean. Received number');
}).to.throw(`Argument "options.atomic" passed to ${test.methodName}(path, data, [options]) must be a boolean. Received number`);
});
});
});
describe('"jsonIndent" argument', function () {
tests.forEach(function (test) {
it(test.type, function () {
expect(function () {
describe('"jsonIndent" argument', () => {
tests.forEach((test) => {
it(test.type, () => {
expect(() => {
test.method('abc', 'xyz', { jsonIndent: true });
}).to.throw('Argument "options.jsonIndent" passed to ' + test.methodName
+ '(path, data, [options]) must be a number. Received boolean');
}).to.throw(`Argument "options.jsonIndent" passed to ${test.methodName}(path, data, [options]) must be a number. Received boolean`);
});

@@ -235,0 +232,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc