Comparing version 1.0.12 to 1.0.13
@@ -23,3 +23,3 @@ /*************************************************************************** | ||
* new MyProcessor({ | ||
* fileset: [ | ||
* files: [ | ||
* 'dep/** /*.js', | ||
@@ -34,3 +34,3 @@ * '!dep/esui/** /extension/*.js', | ||
* | ||
* @param {Array.<string>} patterns fileset的pattern. | ||
* @param {Array.<string>} patterns files的pattern. | ||
* @param {Array.<*>} allCandidates 所有的待选项. | ||
@@ -108,9 +108,24 @@ * @param {(function(string, *):boolean)=} comparator 用来判断是否符合要求的函数,如果符合返回true. | ||
* 支持exclude的写法,类似 edp.glob.filter | ||
* @param {string|Array.<string>} patterns | ||
* @param {string|Array.<string>} patterns 需要匹配的Pattern. | ||
* @param {Object=} options 一些额外的配置. | ||
*/ | ||
exports.sync = function( patterns ) { | ||
exports.sync = function( patterns, options ) { | ||
var glob = require( 'glob' ); | ||
var fs = require( 'fs' ); | ||
options = options || {}; | ||
var cwd = options.cwd || process.cwd(); | ||
function filter( candidates ) { | ||
var path = require( 'path' ); | ||
return candidates.filter(function( item ){ | ||
var stat = fs.statSync( path.join( cwd, item ) ); | ||
return !stat.isDirectory(); | ||
}); | ||
} | ||
var allCandidates = null; | ||
if ( typeof patterns === 'string' ) { | ||
return glob.sync( patterns ); | ||
allCandidates = glob.sync( patterns, options ); | ||
} | ||
@@ -122,27 +137,29 @@ else if ( Array.isArray( patterns ) ) { | ||
var allCandidates = glob.sync( patterns[ 0 ] ); | ||
if ( patterns.length === 1 ) { | ||
return allCandidates; | ||
} | ||
for ( var i = 1; i < patterns.length; i ++ ) { | ||
var pattern = patterns[ i ]; | ||
if ( pattern[ 0 ] === '!' ) { | ||
pattern = pattern.substring( 1 ); | ||
var len = allCandidates.length; | ||
while( len -- ) { | ||
// edp.path.satisfy就是基于minimatch的 | ||
if ( path.satisfy( allCandidates[ len ], pattern ) ) { | ||
allCandidates.splice( len, 1 ); | ||
var allCandidates = glob.sync( patterns[ 0 ], options ); | ||
if ( patterns.length > 1 ) { | ||
for ( var i = 1; i < patterns.length; i ++ ) { | ||
var pattern = patterns[ i ]; | ||
if ( pattern[ 0 ] === '!' ) { | ||
pattern = pattern.substring( 1 ); | ||
var len = allCandidates.length; | ||
while( len -- ) { | ||
// edp.path.satisfy就是基于minimatch的 | ||
if ( path.satisfy( allCandidates[ len ], pattern ) ) { | ||
allCandidates.splice( len, 1 ); | ||
} | ||
} | ||
} | ||
else { | ||
allCandidates.push.apply( allCandidates, | ||
glob.sync( pattern, options ) ); | ||
} | ||
} | ||
else { | ||
allCandidates.push.apply( allCandidates, | ||
glob.sync( pattern ) ); | ||
} | ||
} | ||
} | ||
return allCandidates; | ||
if ( options.nodir === true ) { | ||
return filter( allCandidates ); | ||
} | ||
return allCandidates; | ||
}; | ||
@@ -149,0 +166,0 @@ |
{ | ||
"name": "edp-core", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"esprima": "~1.0.2", | ||
"esprima": "~1.1.1", | ||
"estraverse": "~1.5.0", | ||
@@ -17,0 +17,0 @@ "minimatch": "~0.2.14", |
@@ -18,2 +18,3 @@ /*************************************************************************** | ||
var glob = require( '../lib/glob' ); | ||
var path = require( 'path' ); | ||
@@ -47,2 +48,11 @@ var ALL_CANDIDATES = [ | ||
}); | ||
it( 'sync', function(){ | ||
var cwd = path.join( __dirname, 'data/util/glob' ); | ||
var options = { nodir: true, cwd: cwd }; | ||
expect( glob.sync( [ '*.js' ], options ) ).toEqual( [ 'a.js' ] ); | ||
expect( glob.sync( [ '**/*.js' ], options ) ).toEqual( [ 'a.js', 'b/b.js' ] ); | ||
expect( glob.sync( [ '**/b**' ], options ) ).toEqual( [ 'b/b.js' ] ); | ||
expect( glob.sync( [ '**/b*' ], { cwd: cwd } ) ).toEqual( [ 'b', 'b/b.js' ] ); | ||
}); | ||
}); | ||
@@ -49,0 +59,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
189761
73
5734
26
+ Addedesprima@1.1.1(transitive)
- Removedesprima@1.0.4(transitive)
Updatedesprima@~1.1.1