From c6821133c84fad679ae83d71de0c1d2bda5074a7 Mon Sep 17 00:00:00 2001 From: Nils Leif Fischer Date: Wed, 17 Jan 2018 02:22:31 +0100 Subject: [PATCH 1/2] Suggested fix for #97, review of implications required With the prepended slash, minimatch will never actually return an object with negate: true, so it's impossible to ignore files in clean operations. Please review this change and consider implications to the remaining codebase - perhaps even consider refactoring to use the glob processing implementation in vinyl-fs, that also gulp.src uses, if possible? --- lib/glob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/glob.js b/lib/glob.js index 7b11c76..2b13cd7 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -14,7 +14,7 @@ function glob( globs, options ) { var negatives = []; globs.forEach( function ( glob ) { - var mm = new Minimatch( self.join( '/', glob ), options ); + var mm = new Minimatch( glob, options ); mm.base = mmBase( mm ); if ( mm.negate ) negatives.push( mm ); From 6d08219a21ae3c2cdb7a7dd25b933d26adebc4ee Mon Sep 17 00:00:00 2001 From: Nils Leif Fischer Date: Sun, 28 Jan 2018 15:51:16 +0100 Subject: [PATCH 2/2] attempt to implement test --- lib/glob.js | 7 +++++++ test/clean.js | 30 ++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/glob.js b/lib/glob.js index 2b13cd7..d3f0a83 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -14,6 +14,13 @@ function glob( globs, options ) { var negatives = []; globs.forEach( function ( glob ) { + var negate = new Minimatch( glob, options ).negate; + glob = glob.replace(/^[!]+/g, ''); + glob = self.join( '/', glob ); + if (negate) { + glob = self.join( '!', glob ); + } + var mm = new Minimatch( glob, options ); mm.base = mmBase( mm ); diff --git a/test/clean.js b/test/clean.js index 1ec33a9..8265494 100644 --- a/test/clean.js +++ b/test/clean.js @@ -11,8 +11,17 @@ describe( 'clean', function () { it( '(preparing: create files to clean up later)', function ( done ) { - VinylFs.src( 'test/fixtures/**' ) - .pipe( VinylFs.dest( 'test/fixtures/cleaning' ) ) + VinylFs.src( 'test/fixtures/index.html' ) + .pipe( VinylFs.dest( 'test/fixtures/cleanthis' ) ) + .on( 'error', done ) + .on( 'end', done ); + + } ); + + it( '(preparing: create files to ignore in cleanup)', function ( done ) { + + VinylFs.src( 'test/fixtures/index.html' ) + .pipe( VinylFs.dest( 'test/fixtures/dontcleanthis' ) ) .on( 'error', done ) .on( 'end', done ); @@ -31,22 +40,27 @@ describe( 'clean', function () { it( '(preparing: remove files to clean)', function ( done ) { - rmdir( 'test/fixtures/cleaning', done ); + rmdir( 'test/fixtures/cleanthis', done ); + + } ); + + it( '(preparing: remove files to ignore in cleanup)', function ( done ) { + + rmdir( 'test/fixtures/dontcleanthis', done ); } ); - it( 'should clean up extra remote files', function ( done ) { + it( 'should clean up extra remote files but repect ignore rules', function ( done ) { done = suite.done( done ); - suite.vftp.clean( 'test/clean/**', 'test/fixtures' ) + suite.vftp.clean( [ 'test/clean/**/*', '!test/clean/dontcleanthis/**/*' ], 'test/fixtures' ) .on( 'error', done ) .on( 'end', check ); function check() { - - assert.ok( suite.log.match( /DEL/ ) ); - assert.ok( suite.log.match( /RMDIR/ ) ); + assert.ok( suite.log.match( /RMDIR(.)*test\/clean\/cleanthis/ ) ); + assert.equal( suite.log.match( /RMDIR(.)*test\/clean\/dontcleanthis/ ), null ); done(); }