Skip to content

Commit

Permalink
Require Node.js 12
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 24, 2021
1 parent 2e5d663 commit b51e40f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
12 changes: 3 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const multimatch = require('multimatch');
const streamfilter = require('streamfilter');
const toAbsoluteGlob = require('to-absolute-glob');

/**
* @param {string | string[]|function(string):boolean} pattern function or glob pattern or array of glob patterns to filter files
* @param {object} options see minimatch options, also root option for path resolving
* @returns {Stream} Transform stream of Vinyl files
*/
module.exports = (pattern, options = {}) => {
pattern = typeof pattern === 'string' ? [pattern] : pattern;

Expand All @@ -25,8 +20,7 @@ module.exports = (pattern, options = {}) => {
} else {
const base = path.dirname(file.path);
const patterns = pattern.map(pattern => {
// Filename only matching glob
// prepend full path
// Filename only matching glob, prepend full path.
if (!pattern.includes('/')) {
if (pattern[0] === '!') {
return '!' + path.resolve(base, pattern.slice(1));
Expand All @@ -37,8 +31,8 @@ module.exports = (pattern, options = {}) => {

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
// 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));
}
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"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"
},
"scripts": {
"test": "xo && mocha"
Expand All @@ -31,15 +32,15 @@
"vinyl"
],
"dependencies": {
"multimatch": "^4.0.0",
"multimatch": "^5.0.0",
"plugin-error": "^1.0.1",
"streamfilter": "^3.0.0",
"to-absolute-glob": "^2.0.2"
},
"devDependencies": {
"mocha": "^6.2.0",
"vinyl": "^2.1.0",
"xo": "^0.24.0"
"mocha": "^8.3.2",
"vinyl": "^2.2.1",
"xo": "^0.39.1"
},
"peerDependencies": {
"gulp": ">=4"
Expand Down
7 changes: 2 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
Enables you to work on a subset of the original files by filtering them using glob patterns. When you're done and want all the original files back, you just use the `restore` stream.


## Install

```
$ npm install --save-dev gulp-filter
```


## Usage

### Filter only
Expand Down Expand Up @@ -109,7 +107,6 @@ exports.default = () => {
};
```


## API

### filter(pattern, options?)
Expand Down Expand Up @@ -138,14 +135,14 @@ Accepts [`minimatch` options](https://github.com/isaacs/minimatch#options).

##### restore

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

Restore filtered files.

##### passthrough

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

When set to `true`, filtered files are restored with a `stream.PassThrough`, otherwise, when set to `false`, filtered files are restored as a `stram.Readable`.
Expand Down
25 changes: 15 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path');
const {strict: assert} = require('assert');
const Vinyl = require('vinyl');
const filter = require('.');
const filter = require('./index.js');

describe('filter()', () => {
it('should filter files', cb => {
Expand Down Expand Up @@ -318,12 +318,11 @@ describe('filter.restore', () => {
// D /A/B/test.js
// E /A/B/C/test.js

// matching behaviour:
// 1) starting with / - absolute path matching
// 2) starting with .. - relative path mapping, cwd prepended
// 3) starting with just path, like abcd/<...> or **/**.js - relative path mapping, cwd prepended
// same rules for !

// Matching behaviour:
// 1) Starting with / - absolute path matching
// 2) Starting with .. - relative path mapping, cwd prepended
// 3) Starting with just path, like abcd/<...> or **/**.js - relative path mapping, cwd prepended
// Same rules for `!`
describe('path matching', () => {
const testFilesPaths = [
'/test.js',
Expand All @@ -333,6 +332,7 @@ describe('path matching', () => {
'/A/B/C/test.js',
'/A/B/C/d.js'
];

const testFiles = testFilesPaths.map(path => new Vinyl({cwd: '/A/B', path}));

const testCases = [
Expand Down Expand Up @@ -429,19 +429,24 @@ describe('path matching', () => {
];

for (const testCase of testCases) {
it('Should ' + testCase.description, cb => {
it(`Should ${testCase.description}`, cb => {
const stream = filter(testCase.pattern);

testFiles.forEach(file => stream.write(file));
for (const testFile of testFiles) {
stream.write(testFile);
}

const files = [];

stream.on('data', file => {
files.push(file);
});

stream.on('end', () => {
assert.deepEqual(files.map(f => f.path), testCase.expectedFiles.map(f => f.path));
assert.deepEqual(files.map(file => file.path), testCase.expectedFiles.map(file => file.path));
cb();
});

stream.end();
});
}
Expand Down

0 comments on commit b51e40f

Please sign in to comment.