fs-jetpack
Advanced tools
Comparing version 0.11.0 to 0.12.0
@@ -0,1 +1,6 @@ | ||
# 0.12.0 (2017-02-19) | ||
- **(breaking change)** Changes in `symlinks` option passed to `inspect()`. | ||
- Added `symlinks` option to `inspectTree()`. | ||
- Removed controversial edge case behaviour for `exists()`. | ||
# 0.11.0 (2017-02-09) | ||
@@ -2,0 +7,0 @@ - Added input validation for the whole API |
@@ -27,3 +27,3 @@ 'use strict'; | ||
} catch (err) { | ||
if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') { | ||
if (err.code !== 'ENOENT') { | ||
throw err; | ||
@@ -45,3 +45,3 @@ } | ||
if (err) { | ||
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { | ||
if (err.code === 'ENOENT') { | ||
deferred.resolve(false); | ||
@@ -48,0 +48,0 @@ } else { |
@@ -11,7 +11,8 @@ 'use strict'; | ||
var validateInput = function (methodName, path, options) { | ||
var methodSignature = methodName + '(path, options)'; | ||
var methodSignature = methodName + '(path, [options])'; | ||
validate.argument(methodSignature, 'path', path, ['string']); | ||
validate.options(methodSignature, 'options', options, { | ||
checksum: ['string'], | ||
relativePath: ['boolean'] | ||
relativePath: ['boolean'], | ||
symlinks: ['string'] | ||
}); | ||
@@ -24,2 +25,8 @@ | ||
} | ||
if (options && options.symlinks !== undefined | ||
&& inspect.symlinkOptions.indexOf(options.symlinks) === -1) { | ||
throw new Error('Argument "options.symlinks" passed to ' + methodSignature | ||
+ ' must have one of values: ' + inspect.symlinkOptions.join(', ')); | ||
} | ||
}; | ||
@@ -77,3 +84,2 @@ | ||
options = options || {}; | ||
options.symlinks = true; | ||
@@ -151,3 +157,2 @@ return inspectTreeNodeSync(path, options, undefined); | ||
options = options || {}; | ||
options.symlinks = true; | ||
@@ -154,0 +159,0 @@ return inspectTreeNodeAsync(path, options); |
@@ -11,2 +11,4 @@ 'use strict'; | ||
var symlinkOptions = ['report', 'follow']; | ||
var validateInput = function (methodName, path, options) { | ||
@@ -20,3 +22,3 @@ var methodSignature = methodName + '(path, [options])'; | ||
absolutePath: ['boolean'], | ||
symlinks: ['boolean'] | ||
symlinks: ['string'] | ||
}); | ||
@@ -29,2 +31,8 @@ | ||
} | ||
if (options && options.symlinks !== undefined | ||
&& symlinkOptions.indexOf(options.symlinks) === -1) { | ||
throw new Error('Argument "options.symlinks" passed to ' + methodSignature | ||
+ ' must have one of values: ' + symlinkOptions.join(', ')); | ||
} | ||
}; | ||
@@ -85,3 +93,3 @@ | ||
var inspectSync = function (path, options) { | ||
var statOperation = fs.statSync; | ||
var statOperation = fs.lstatSync; | ||
var stat; | ||
@@ -91,4 +99,4 @@ var inspectObj; | ||
if (options.symlinks) { | ||
statOperation = fs.lstatSync; | ||
if (options.symlinks === 'follow') { | ||
statOperation = fs.statSync; | ||
} | ||
@@ -156,7 +164,7 @@ | ||
var deferred = Q.defer(); | ||
var statOperation = promisedStat; | ||
var statOperation = promisedLstat; | ||
options = options || {}; | ||
if (options.symlinks) { | ||
statOperation = promisedLstat; | ||
if (options.symlinks === 'follow') { | ||
statOperation = promisedStat; | ||
} | ||
@@ -188,4 +196,5 @@ | ||
exports.supportedChecksumAlgorithms = supportedChecksumAlgorithms; | ||
exports.symlinkOptions = symlinkOptions; | ||
exports.validateInput = validateInput; | ||
exports.sync = inspectSync; | ||
exports.async = inspectAsync; |
{ | ||
"name": "fs-jetpack", | ||
"description": "Better file system API", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"author": "Jakub Szwacz <jakub@szwacz.com>", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -288,3 +288,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) | ||
* `absolutePath` (default `false`) if set to `true` will add absolute path to this resource. | ||
* `symlinks` (default `false`) if set to `true` will just inspect symlink itself and not follow it. | ||
* `symlinks` (default `'report'`) if a given path is a symlink by default `inspect` will report that symlink (not follow it). You can flip this behaviour by setting this option to `'follow'`. | ||
@@ -297,3 +297,3 @@ **returns:** | ||
name: "my_dir", | ||
type: "file", // possible values: "file", "dir" | ||
type: "file", // possible values: "file", "dir", "symlink" | ||
size: 123, // size in bytes, this is returned only for files | ||
@@ -322,2 +322,3 @@ // if checksum option was specified: | ||
* `relativePath` if set to `true` every tree node will have relative path anchored to root inspected folder. | ||
* `symlinks` (default `'report'`) if a given path is a symlink by default `inspectTree` will report that symlink (not follow it). You can flip this behaviour by setting this option to `'follow'`. | ||
@@ -324,0 +325,0 @@ **returns:** |
@@ -511,4 +511,2 @@ var fse = require('fs-extra'); | ||
}); | ||
} else { | ||
// TODO what with Windows? | ||
} | ||
@@ -515,0 +513,0 @@ |
@@ -102,32 +102,2 @@ var fse = require('fs-extra'); | ||
describe("(edge case) ENOTDIR error changed into 'false'", function () { | ||
// We have here malformed path: /some/dir/file.txt/some_dir | ||
// (so file is in the middle of path, not at the end). | ||
// This leads to ENOTDIR error, but technically speaking this | ||
// path doesn't exist so let's just return false. | ||
// TODO Not fully sure this is sensible behaviour. It just turns one misleading | ||
// state into another. The fact is this path is malformed. Can we do better? | ||
var preparations = function () { | ||
fse.outputFileSync('text.txt', 'abc'); | ||
}; | ||
var expectations = function (exists) { | ||
expect(exists).to.equal(false); | ||
}; | ||
it('sync', function () { | ||
preparations(); | ||
expectations(jetpack.exists('text.txt/something')); | ||
}); | ||
it('async', function (done) { | ||
preparations(); | ||
jetpack.existsAsync('text.txt/something') | ||
.then(function (exists) { | ||
expectations(exists); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('input validation', function () { | ||
@@ -134,0 +104,0 @@ var tests = [ |
@@ -239,6 +239,6 @@ var fse = require('fs-extra'); | ||
describe('can inspect symlink', function () { | ||
describe('reports symlinks by default', function () { | ||
var preparations = function () { | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
fse.symlinkSync('dir/file.txt', 'dir/symlinked_file.txt'); | ||
fse.symlinkSync('file.txt', 'dir/symlinked_file.txt'); | ||
}; | ||
@@ -258,3 +258,3 @@ | ||
type: 'symlink', | ||
pointsAt: helper.osSep('dir/file.txt') | ||
pointsAt: 'file.txt' | ||
}] | ||
@@ -266,3 +266,4 @@ }); | ||
preparations(); | ||
expectations(jetpack.inspectTree('dir')); | ||
expectations(jetpack.inspectTree('dir')); // implicit | ||
expectations(jetpack.inspectTree('dir', { symlinks: 'report' })); // explicit | ||
}); | ||
@@ -272,8 +273,52 @@ | ||
preparations(); | ||
jetpack.inspectTreeAsync('dir') | ||
jetpack.inspectTreeAsync('dir') // implicit | ||
.then(function (tree) { | ||
expectations(tree); | ||
return jetpack.inspectTreeAsync('dir', { symlinks: 'report' }); // explicit | ||
}) | ||
.then(function (tree) { | ||
expectations(tree); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
describe('follows symlinks when option specified', function () { | ||
var preparations = function () { | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
fse.symlinkSync('file.txt', 'dir/symlinked_file.txt'); | ||
}; | ||
var expectations = function (tree) { | ||
expect(tree).to.eql({ | ||
name: 'dir', | ||
type: 'dir', | ||
size: 6, | ||
children: [{ | ||
name: 'file.txt', | ||
type: 'file', | ||
size: 3 | ||
}, { | ||
name: 'symlinked_file.txt', | ||
type: 'file', | ||
size: 3 | ||
}] | ||
}); | ||
}; | ||
it('sync', function () { | ||
preparations(); | ||
expectations(jetpack.inspectTree('dir', { symlinks: 'follow' })); | ||
}); | ||
it('async', function (done) { | ||
preparations(); | ||
jetpack.inspectTreeAsync('dir', { symlinks: 'follow' }) | ||
.then(function (tree) { | ||
expectations(tree); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
@@ -351,3 +396,3 @@ | ||
}).to.throw('Argument "path" passed to ' + test.methodName | ||
+ '(path, options) must be a string. Received undefined'); | ||
+ '(path, [options]) must be a string. Received undefined'); | ||
}); | ||
@@ -364,3 +409,3 @@ }); | ||
}).to.throw('Argument "options.checksum" passed to ' + test.methodName | ||
+ '(path, options) must be a string. Received number'); | ||
+ '(path, [options]) must be a string. Received number'); | ||
}); | ||
@@ -371,3 +416,3 @@ it(test.type, function () { | ||
}).to.throw('Argument "options.checksum" passed to ' + test.methodName | ||
+ '(path, options) must have one of values: md5, sha1, sha256'); | ||
+ '(path, [options]) must have one of values: md5, sha1, sha256'); | ||
}); | ||
@@ -382,8 +427,24 @@ }); | ||
}).to.throw('Argument "options.relativePath" passed to ' + test.methodName | ||
+ '(path, options) must be a boolean. Received number'); | ||
+ '(path, [options]) must be a boolean. Received number'); | ||
}); | ||
}); | ||
}); | ||
describe('"symlinks" argument', function () { | ||
tests.forEach(function (test) { | ||
it(test.type, function () { | ||
expect(function () { | ||
test.method('abc', { symlinks: 1 }); | ||
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName | ||
+ '(path, [options]) must be a string. Received number'); | ||
}); | ||
it(test.type, function () { | ||
expect(function () { | ||
test.method('abc', { symlinks: 'foo' }); | ||
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName | ||
+ '(path, [options]) must have one of values: report, follow'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -159,3 +159,3 @@ var fse = require('fs-extra'); | ||
describe('follows symlink by default', function () { | ||
describe('reports symlink by default', function () { | ||
var preparations = function () { | ||
@@ -169,4 +169,4 @@ fse.outputFileSync('dir/file.txt', 'abc'); | ||
name: 'symlinked_file.txt', | ||
type: 'file', | ||
size: 3 | ||
type: 'symlink', | ||
pointsAt: helper.osSep('dir/file.txt') | ||
}); | ||
@@ -177,3 +177,4 @@ }; | ||
preparations(); | ||
expectations(jetpack.inspect('symlinked_file.txt')); | ||
expectations(jetpack.inspect('symlinked_file.txt')); // implicit | ||
expectations(jetpack.inspect('symlinked_file.txt', { symlinks: 'report' })); // explicit | ||
}); | ||
@@ -183,11 +184,16 @@ | ||
preparations(); | ||
jetpack.inspectAsync('symlinked_file.txt') | ||
jetpack.inspectAsync('symlinked_file.txt') // implicit | ||
.then(function (data) { | ||
expectations(data); | ||
return jetpack.inspectAsync('symlinked_file.txt', { symlinks: 'report' }); // explicit | ||
}) | ||
.then(function (data) { | ||
expectations(data); | ||
done(); | ||
}); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
describe('stats symlink if option specified', function () { | ||
describe('follows symlink if option specified', function () { | ||
var preparations = function () { | ||
@@ -201,4 +207,4 @@ fse.outputFileSync('dir/file.txt', 'abc'); | ||
name: 'symlinked_file.txt', | ||
type: 'symlink', | ||
pointsAt: helper.osSep('dir/file.txt') | ||
type: 'file', | ||
size: 3 | ||
}); | ||
@@ -209,3 +215,3 @@ }; | ||
preparations(); | ||
expectations(jetpack.inspect('symlinked_file.txt', { symlinks: true })); | ||
expectations(jetpack.inspect('symlinked_file.txt', { symlinks: 'follow' })); | ||
}); | ||
@@ -215,7 +221,8 @@ | ||
preparations(); | ||
jetpack.inspectAsync('symlinked_file.txt', { symlinks: true }) | ||
jetpack.inspectAsync('symlinked_file.txt', { symlinks: 'follow' }) | ||
.then(function (data) { | ||
expectations(data); | ||
done(); | ||
}); | ||
}) | ||
.catch(done); | ||
}); | ||
@@ -250,4 +257,2 @@ }); | ||
}); | ||
} else { | ||
// TODO what with Windows? | ||
} | ||
@@ -388,4 +393,10 @@ | ||
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName | ||
+ '(path, [options]) must be a boolean. Received number'); | ||
+ '(path, [options]) must be a string. Received number'); | ||
}); | ||
it(test.type, function () { | ||
expect(function () { | ||
test.method('abc', { symlinks: 'foo' }); | ||
}).to.throw('Argument "options.symlinks" passed to ' + test.methodName | ||
+ '(path, [options]) must have one of values: report, follow'); | ||
}); | ||
}); | ||
@@ -392,0 +403,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250656
7000
506