forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Improves pref of globbing by inheriting glob.GlobSync (fixes esl…
- Loading branch information
Kael
committed
Jul 28, 2016
1 parent
1025772
commit 146ad84
Showing
5 changed files
with
140 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @fileoverview An inherited `glob.GlobSync` to support .gitignore patterns. | ||
* @author Kael Zhang | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var Sync = require("glob").GlobSync, | ||
path = require("path"), | ||
util = require("util"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Private | ||
//------------------------------------------------------------------------------ | ||
|
||
var IGNORE = typeof Symbol === "function" ? Symbol("ignore") : "_shouldIgnore"; | ||
|
||
/** | ||
* Subclass of `glob.GlobSync` | ||
* @param {string} pattern Pattern to be matched. | ||
* @param {Object} options `options` for `glob` | ||
* @param {function()} shouldIgnore Method to check whether a directory should be ignored. | ||
* @constructor | ||
*/ | ||
function GlobSync(pattern, options, shouldIgnore) { | ||
|
||
/** | ||
* We don't put this thing to argument `options` to avoid | ||
* further problems, such as `options` validation. | ||
* | ||
* Use `Symbol` as much as possible to avoid confliction. | ||
*/ | ||
this[IGNORE] = shouldIgnore; | ||
|
||
Sync.call(this, pattern, options); | ||
} | ||
|
||
util.inherits(GlobSync, Sync); | ||
|
||
/* eslint no-underscore-dangle: ["error", { "allow": ["_readdir", "_mark"] }] */ | ||
|
||
GlobSync.prototype._readdir = function(abs, inGlobStar) { | ||
|
||
/** | ||
* `options.nodir` makes `options.mark` as `true`. | ||
* Mark `abs` first | ||
* to make sure `"node_modules"` will be ignored immediately with ignore pattern `"node_modules/"`. | ||
* There is a built-in cache about marked `File.Stat` in `glob`, so that we could not worry about the extra invocation of `this._mark()` | ||
*/ | ||
var marked = this._mark(abs); | ||
|
||
/** | ||
* `node-ignore` only accepts relative paths which are relative to the cwd, | ||
* as well as .gitignore file does. | ||
*/ | ||
var relative = path.relative(this.cwd, marked); | ||
|
||
if (relative && this[IGNORE](relative)) { | ||
return null; | ||
} | ||
|
||
return Sync.prototype._readdir.call(this, abs, inGlobStar); | ||
}; | ||
|
||
|
||
module.exports = GlobSync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters