gulp-filter
Advanced tools
Comparing version 6.0.0 to 7.0.0
30
index.js
@@ -6,2 +6,3 @@ 'use strict'; | ||
const streamfilter = require('streamfilter'); | ||
const toAbsoluteGlob = require('to-absolute-glob'); | ||
@@ -21,12 +22,25 @@ module.exports = (pattern, options = {}) => { | ||
} else { | ||
let relativePath = path.relative(file.cwd, file.path); | ||
const base = path.dirname(file.path); | ||
const patterns = pattern.map(pattern => { | ||
// Filename only matching glob, prepend full path. | ||
if (!pattern.includes('/')) { | ||
if (pattern[0] === '!') { | ||
return '!' + path.resolve(base, pattern.slice(1)); | ||
} | ||
// If the path leaves the current working directory, then we need to | ||
// resolve the absolute path so that the path can be properly matched | ||
// by minimatch (via multimatch) | ||
if (/^\.\.[\\/]/.test(relativePath)) { | ||
relativePath = path.resolve(relativePath); | ||
} | ||
return path.resolve(base, pattern); | ||
} | ||
match = multimatch(relativePath, pattern, options).length > 0; | ||
pattern = toAbsoluteGlob(pattern, {cwd: file.cwd, root: options.root}); | ||
// Calling `path.resolve` after `toAbsoluteGlob` is required for removing `..` from path. | ||
// This is useful for `../A/B` cases. | ||
if (pattern[0] === '!') { | ||
return '!' + path.resolve(pattern.slice(1)); | ||
} | ||
return path.resolve(pattern); | ||
}); | ||
match = multimatch(path.resolve(file.cwd, file.path), patterns, options).length > 0; | ||
} | ||
@@ -33,0 +47,0 @@ |
{ | ||
"name": "gulp-filter", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "Filter files in a `vinyl` stream", | ||
"license": "MIT", | ||
"repository": "sindresorhus/gulp-filter", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -34,11 +35,20 @@ "scripts": { | ||
"dependencies": { | ||
"multimatch": "^4.0.0", | ||
"multimatch": "^5.0.0", | ||
"plugin-error": "^1.0.1", | ||
"streamfilter": "^3.0.0" | ||
"streamfilter": "^3.0.0", | ||
"to-absolute-glob": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^6.1.4", | ||
"vinyl": "^2.1.0", | ||
"xo": "^0.24.0" | ||
"mocha": "^8.3.2", | ||
"vinyl": "^2.2.1", | ||
"xo": "^0.39.1" | ||
}, | ||
"peerDependencies": { | ||
"gulp": ">=4" | ||
}, | ||
"peerDependenciesMeta": { | ||
"gulp": { | ||
"optional": true | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# gulp-filter [![Build Status](https://travis-ci.org/sindresorhus/gulp-filter.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-filter) | ||
# gulp-filter | ||
@@ -7,3 +7,2 @@ > Filter files in a [`vinyl`](https://github.com/gulpjs/vinyl) stream | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -28,3 +26,3 @@ | ||
gulp.task('default', () => { | ||
exports.default = () => { | ||
// Create filter instance inside task function | ||
@@ -39,3 +37,3 @@ const f = filter(['**', '!*src/vendor']); | ||
.pipe(gulp.dest('dist')); | ||
}); | ||
}; | ||
``` | ||
@@ -50,3 +48,3 @@ | ||
gulp.task('default', () => { | ||
exports.default = () => { | ||
// Create filter instance inside task function | ||
@@ -63,3 +61,3 @@ const f = filter(['**', '!*src/vendor'], {restore: true}); | ||
.pipe(gulp.dest('dist')); | ||
}); | ||
}; | ||
``` | ||
@@ -77,3 +75,3 @@ | ||
gulp.task('default', () => { | ||
exports.default = () => { | ||
const jsFilter = filter('**/*.js', {restore: true}); | ||
@@ -90,3 +88,3 @@ const lessFilter = filter('**/*.less', {restore: true}); | ||
.pipe(gulp.dest('out/')); | ||
}); | ||
}; | ||
``` | ||
@@ -103,3 +101,3 @@ | ||
gulp.task('default', () => { | ||
exports.default = () => { | ||
const f = filter(['**', '!*src/vendor'], {restore: true, passthrough: false}); | ||
@@ -118,9 +116,8 @@ | ||
return stream; | ||
}); | ||
}; | ||
``` | ||
## API | ||
### filter(pattern, [options]) | ||
### filter(pattern, options?) | ||
@@ -151,3 +148,3 @@ Returns a [transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform) with a [.restore](#optionsrestore) property. | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -159,3 +156,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -162,0 +159,0 @@ |
Sorry, the diff of this file is not supported yet
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
7453
42
5
151
+ Addedto-absolute-glob@^2.0.2
+ Added@gulpjs/messages@1.1.0(transitive)
+ Added@gulpjs/to-absolute-glob@4.0.0(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedarray-each@1.0.1(transitive)
+ Addedarray-slice@1.1.0(transitive)
+ Addedasync-done@2.0.0(transitive)
+ Addedasync-settle@2.0.0(transitive)
+ Addedb4a@1.6.7(transitive)
+ Addedbach@2.0.1(transitive)
+ Addedbare-events@2.5.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbl@5.1.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedcliui@7.0.4(transitive)
+ Addedclone@2.1.2(transitive)
+ Addedclone-stats@1.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedcopy-props@4.0.0(transitive)
+ Addeddetect-file@1.0.0(transitive)
+ Addedeach-props@3.0.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedexpand-tilde@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedfast-fifo@1.3.2(transitive)
+ Addedfast-levenshtein@3.0.0(transitive)
+ Addedfastest-levenshtein@1.0.16(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfindup-sync@5.0.0(transitive)
+ Addedfined@2.0.0(transitive)
+ Addedflagged-respawn@2.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@1.0.0(transitive)
+ Addedfs-mkdirp-stream@2.0.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedglob-parent@5.1.26.0.2(transitive)
+ Addedglob-stream@8.0.2(transitive)
+ Addedglob-watcher@6.0.0(transitive)
+ Addedglobal-modules@1.0.0(transitive)
+ Addedglobal-prefix@1.0.2(transitive)
+ Addedglogg@2.2.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedgulp@5.0.0(transitive)
+ Addedgulp-cli@3.0.0(transitive)
+ Addedgulplog@2.2.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinterpret@3.1.1(transitive)
+ Addedis-absolute@1.0.0(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-negated-glob@1.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-plain-object@5.0.0(transitive)
+ Addedis-relative@1.0.0(transitive)
+ Addedis-unc-path@1.0.0(transitive)
+ Addedis-valid-glob@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlast-run@2.0.0(transitive)
+ Addedlead@4.0.0(transitive)
+ Addedliftoff@5.0.0(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmultimatch@5.0.0(transitive)
+ Addedmute-stdout@2.0.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addednow-and-later@3.0.0(transitive)
+ Addedobject.defaults@1.1.0(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedparse-filepath@1.0.2(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-root@0.1.1(transitive)
+ Addedpath-root-regex@0.1.2(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-tick@1.0.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedrechoir@0.8.0(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedreplace-ext@2.0.0(transitive)
+ Addedreplace-homedir@2.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedresolve-dir@1.0.1(transitive)
+ Addedresolve-options@2.0.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedsemver-greatest-satisfied-range@2.0.0(transitive)
+ Addedsparkles@2.1.0(transitive)
+ Addedstream-composer@1.0.2(transitive)
+ Addedstream-exhaust@1.0.2(transitive)
+ Addedstreamx@2.20.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedsver@1.8.4(transitive)
+ Addedteex@1.0.1(transitive)
+ Addedtext-decoder@1.2.0(transitive)
+ Addedto-absolute-glob@2.0.2(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedto-through@3.0.0(transitive)
+ Addedunc-path-regex@0.1.2(transitive)
+ Addedundertaker@2.0.0(transitive)
+ Addedundertaker-registry@2.0.0(transitive)
+ Addedv8flags@4.0.1(transitive)
+ Addedvalue-or-function@4.0.0(transitive)
+ Addedvinyl@3.0.0(transitive)
+ Addedvinyl-contents@2.0.0(transitive)
+ Addedvinyl-fs@4.0.0(transitive)
+ Addedvinyl-sourcemap@2.0.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@16.2.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)
- Removedmultimatch@4.0.0(transitive)
Updatedmultimatch@^5.0.0