Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #62 #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignorePatterns": ["examples/**", "bench/**"]
}
13 changes: 6 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"extends": [
"eslint:recommended"
],
"extends": ["eslint:recommended"],

"env": {
"es6": true,
"node": true
},

"parserOptions":{
"parserOptions": {
"ecmaVersion": 9
},

"rules": {
"accessor-pairs": 2,
"arrow-parens": [2, "as-needed"],
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
Expand All @@ -26,7 +25,7 @@
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"handle-callback-err": [2, "^(err|error)$"],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
Expand Down Expand Up @@ -104,13 +103,13 @@
"one-var": [2, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"prefer-const": 2,
"prefer-const": [2, { "destructuring": "all", "ignoreReadBeforeAssign": false }],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-before-function-paren": [2, { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
Expand Down
6 changes: 4 additions & 2 deletions .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ The following options may be used with the main `picomatch()` function or any of
| [onMatch](#optionsonMatch) | `function` | `undefined` | Function to be called on matched items. |
| [onResult](#optionsonResult) | `function` | `undefined` | Function to be called on all items, regardless of whether or not they are matched or ignored. |
| `posix` | `boolean` | `false` | Support POSIX character classes ("posix brackets"). |
| `posixSlashes` | `boolean` | `undefined` | Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself |
| `prepend` | `boolean` | `undefined` | String to prepend to the generated regex used for matching. |
| `regex` | `boolean` | `false` | Use regular expression rules for `+` (instead of matching literal `+`), and for stars that follow closing parentheses or brackets (as in `)*` and `]*`). |
| `strictBrackets` | `boolean` | `undefined` | Throw an error if brackets, braces, or parens are imbalanced. |
| `strictBraces` | `boolean` | `undefined` | Treat brace patterns with no sets or ranges as literals. For example, `{abc}` would be a literal. |
| `strictBrackets` | `boolean` | `undefined` | Throw an error if brackets, braces, or parens are imbalanced. |
| `strictSlashes` | `boolean` | `undefined` | When true, picomatch won't match trailing slashes with single stars. |
| `unescape` | `boolean` | `undefined` | Remove backslashes preceding escaped characters in the glob pattern. By default, backslashes are retained. |
| `unixify` | `boolean` | `undefined` | Alias for `posixSlashes`, for backwards compatibility. |
| `windows` | `boolean` | `undefined` | Force picomatch to act like the platform is Windows. When true, converts all slashes file paths (or whatever input strings are passed) to forward (posix) slashes. Note that this does not convert slashes in **glob patterns**, only in the strings to be matched. |


### Scan Options

Expand Down
10 changes: 5 additions & 5 deletions bench/glob-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ bench('*.js')
.add(' glob-parent', () => parent('*.js'))
.run();

bench('foo/bar/baz')
.add('picomatch.scan', () => scan('foo/bar/baz'))
.add(' glob-parent', () => parent('foo/bar/baz'))
.run();

bench('foo/*.js')
.add('picomatch.scan', () => scan('foo/*.js'))
.add(' glob-parent', () => parent('foo/*.js'))
Expand All @@ -62,6 +57,11 @@ bench('foo/{a,b}/*.js')
.add(' glob-parent', () => parent('foo/{a,b}/*.js'))
.run();

bench('foo/bar/baz')
.add('picomatch.scan', () => scan('foo/bar/baz'))
.add(' glob-parent', () => parent('foo/bar/baz'))
.run();

bench('*.js { parts: true, tokens: true }')
.add('picomatch.scan', () => scan('*.js', { parts: true, tokens: true }))
.add(' glob-parent', () => parent('*.js'))
Expand Down
33 changes: 19 additions & 14 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,36 @@ const bench = (name, options) => {
};

bench(`${red('.makeRe')} star`)
.add('picomatch', () => pm.makeRe('*'))
.add('picomatch', () => pm.makeRe('*', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('*'))
.run();

bench(`${red('.makeRe')} star; dot=true`)
.add('picomatch', () => pm.makeRe('*', { dot: true }))
bench(`${red('.makeRe')} leading star`)
.add('picomatch', () => pm.makeRe('*.txt', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('*.txt'))
.run();

bench(`${red('.makeRe')} path with star`)
.add('picomatch', () => pm.makeRe('foo/*.js', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('foo/*.js'))
.run();

bench(`${red('.makeRe')} star w/ { dot: true }`)
.add('picomatch', () => pm.makeRe('*', { dot: true, fastpaths: false }))
.add('minimatch', () => mm.makeRe('*', { dot: true }))
.run();

bench(`${red('.makeRe')} globstar`)
.add('picomatch', () => pm.makeRe('**'))
.add('picomatch', () => pm.makeRe('**', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('**'))
.run();

bench(`${red('.makeRe')} globstars`)
.add('picomatch', () => pm.makeRe('**/**/**'))
bench(`${red('.makeRe')} multiple globstars`)
.add('picomatch', () => pm.makeRe('**/**/**', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('**/**/**'))
.run();

bench(`${red('.makeRe')} with leading star`)
.add('picomatch', () => pm.makeRe('*.txt'))
.add('minimatch', () => mm.makeRe('*.txt'))
.run();

bench(`${red('.makeRe')} - basic braces`)
.add('picomatch', () => pm.makeRe('{a,b,c}*.txt'))
.add('minimatch', () => mm.makeRe('{a,b,c}*.txt'))
bench(`${red('.makeRe')} basic braces`)
.add('picomatch', () => pm.makeRe('foo/{a,b,c}*.txt', { fastpaths: false }))
.add('minimatch', () => mm.makeRe('foo/{a,b,c}*.txt'))
.run();
13 changes: 11 additions & 2 deletions bench/load-time.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use strict';

const libs = {
pm() {
return require('..');
},
mm() {
return require('minimatch');
}
};

console.log('# Load time');
console.time('picomatch');
exports.pm = require('..');
libs.pm();
console.timeEnd('picomatch');
console.time('minimatch');
exports.mm = require('minimatch');
libs.mm();
console.timeEnd('minimatch');
console.log();
4 changes: 2 additions & 2 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"private": true,
"main": "index.js",
"dependencies": {
"ansi-colors": "^3.0.3",
"ansi-colors": "^4.1.1",
"benchmark": "^2.1.4",
"minimist": "^1.2.0"
},
"devDependencies": {
"glob-parent": "^3.1.0",
"glob-parent": "^5.1.0",
"minimatch": "^3.0.4"
},
"lintDeps": {
Expand Down
55 changes: 55 additions & 0 deletions examples/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,58 @@ console.log(pm.scan('foo/**/*.js'));
console.log(pm.scan('foo/bar/*.js'));
console.log(pm.scan('foo/*.js'));
console.log(pm.scan('/foo'));

const braces = require('braces');

const scan = (pattern, options) => {
// const matchers = {};
const patterns = braces.expand(pattern, options);
const result = patterns.map(p => pm.scan(p, options));

for (let i = 0; i < result.length; i++) {
const state = result[i];
if (state.maxDepth === Infinity) continue;

// const matcher = matchers[state.base] || (matchers[state.base] = {});
let foundGlob = false;

for (const token of state.tokens) {
if (token.isGlob === true) {
foundGlob = true;
}

if (foundGlob === false) {
continue;
}

if (token.isGlob === false) {
token.matcher = name => token.value === name;
} else {
token.matcher = function glob() {};
}

}
console.log(state);
}

return result;
};

scan('{one/two,foo}/*/abc/{bar,**/*}.js', { parts: true, tokens: true });

// scan('./foo/**/*/*.js', { parts: true, tokens: true });
// scan('**/bar.js', { parts: true, tokens: true });
// scan('foo/**/bar.js', { parts: true, tokens: true });
// scan('foo/**/{bar,*/*}.js', { parts: true, tokens: true });
// scan('foo/**/{bar,*/*}/*.js', { parts: true, tokens: true });
// const { tokens } = scan('foo/*/{bar,*/*}/*.js', { parts: true, tokens: true });
// for (const token of tokens) {
// console.log(token);
// }

// console.log(scan('./foo/**/*/*.js', { parts: true, tokens: true }));
// console.log(scan('foo/**/bar.js', { parts: true, tokens: true }));
// console.log(scan('foo/**/{bar,*/*}.js', { parts: true, tokens: true }));
// console.log(scan('foo/**/{bar,*/*}/*.js', { parts: true, tokens: true }));
// console.log(scan('!./foo/*.js'));
// console.log(scan('!./foo/*.js', { parts: true, tokens: true }));
Loading