Skip to content

Commit

Permalink
Fix file-finding for files outside of working directory
Browse files Browse the repository at this point in the history
Closes GH-60.

Introduced in 3c4520f.
  • Loading branch information
wooorm committed Nov 19, 2015
1 parent 82cf85a commit 0ee8d9a
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,22 @@ function filterFactory(ignore, given) {
var filePath = file.filePath();
var extension = file.extension;

if (shouldIgnore(ignore, filePath)) {
if (given.indexOf(filePath) !== -1 || shouldIgnore(ignore, filePath)) {
return findDown.SKIP;
}

return given.indexOf(filePath) !== -1 ||
(extension && extensions.indexOf(extension) !== -1)
return extension && extensions.indexOf(extension) !== -1;
}
}

/**
* Factory to create a file filter based on bound ignore
* patterns.
*
* @param {Array.<VFile>} failed - List of failed files.
* @param {Array.<VFile>} given - List of given files.
* @return {Function} - Process callback.
*/
function processFactory(failed) {
function processFactory(given) {
/**
* Process all found files (and failed ones too).
*
Expand All @@ -254,7 +253,7 @@ function processFactory(failed) {
* @param {Array.<VFile>} [files] - Virtual files.
*/
return function (err, files) {
failed.concat(files || []).forEach(function (file) {
given.concat(files || []).forEach(function (file) {
file.quiet = true;

try {
Expand All @@ -275,8 +274,8 @@ function processFactory(failed) {
*/

globby(globs).then(function (filePaths) {
var files = [];
var given = [];
var failed = [];

/*
* Check whether files are given directly that either
Expand All @@ -285,21 +284,19 @@ globby(globs).then(function (filePaths) {
*/

globs.forEach(function (glob) {
var stats;

if (hasMagic(glob)) {
return;
}

try {
stats = stat(glob);
files.push(toFile(glob));
given.push(glob);

if (stats.isFile()) {
given.push(glob);
try {
if (!stat(glob).isFile()) {
files.pop();
given.pop();
}
} catch (err) {
failed.push(toFile(glob));
}
} catch (err) { /* Empty. */ }
});

/*
Expand All @@ -313,8 +310,8 @@ globby(globs).then(function (filePaths) {
ignore = file && loadIgnore(file.filePath());
} catch (err) { /* Empty. */ }

ignore = defaultIgnore.concat(ignore);
ignore = defaultIgnore.concat(ignore || []);

findDown.all(filterFactory(ignore, given), filePaths, processFactory(failed));
findDown.all(filterFactory(ignore, given), filePaths, processFactory(files));
});
}, bail);

0 comments on commit 0ee8d9a

Please sign in to comment.