Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: micromatch/picomatch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1d546ea22efa8ff3ca15b4848a2dffdb53aaef9a
Choose a base ref
...
head repository: micromatch/picomatch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.2.2
Choose a head ref
  • 8 commits
  • 7 files changed
  • 3 contributors

Commits on Jan 4, 2020

  1. remove lint from ci for now...

    Since eslint is using a unicode regex flag that is breaking tests. We'll re-add this after a major bump in picomatch, so we can require Node 10 or later.
    jonschlinkert committed Jan 4, 2020
    Copy the full SHA
    cc2c3fc View commit details
  2. lint

    jonschlinkert committed Jan 4, 2020
    Copy the full SHA
    6741df3 View commit details
  3. fix .compileRe docs

    jonschlinkert committed Jan 4, 2020
    Copy the full SHA
    66e1b20 View commit details

Commits on Mar 9, 2020

  1. Copy the full SHA
    e97ba07 View commit details
  2. Copy the full SHA
    2ca064f View commit details

Commits on Mar 21, 2020

  1. Merge pull request #65 from mrmlnc/fix_parens

    ISSUE-58: Correctly handle a part after parentheses
    mrmlnc authored Mar 21, 2020
    Copy the full SHA
    e15b920 View commit details
  2. docs: update changelog

    mrmlnc committed Mar 21, 2020
    Copy the full SHA
    4f4c857 View commit details
  3. 2.2.2

    mrmlnc committed Mar 21, 2020
    Copy the full SHA
    aed790f View commit details
Showing with 94 additions and 27 deletions.
  1. +6 −0 CHANGELOG.md
  2. +7 −6 README.md
  3. +1 −3 lib/parse.js
  4. +5 −4 lib/picomatch.js
  5. +13 −12 lib/scan.js
  6. +2 −2 package.json
  7. +60 −0 test/api.scan.js
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -32,6 +32,12 @@ Changelog entries are classified using the following labels _(from [keep-a-chang

</details>

## 2.2.2 (2020-03-21)

### Fixed

* Correctly handle parts of the pattern after parentheses in the `scan` method ([e15b920](https://github.com/micromatch/picomatch/commit/e15b920)).

## 2.2.1 (2020-01-04)

* Fixes [#49](https://github.com/micromatch/picomatch/issues/49), so that braces with no sets or ranges are now propertly treated as literals.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -234,27 +234,28 @@ console.log(result);
negated: true }
```
### [.compileRe](lib/picomatch.js#L249)
### [.compileRe](lib/picomatch.js#L250)
Create a regular expression from a glob pattern.
Create a regular expression from a parsed glob pattern.
**Params**
* `input` **{String}**: A glob pattern to convert to regex.
* `state` **{String}**: The object returned from the `.parse` method.
* `options` **{Object}**
* `returns` **{RegExp}**: Returns a regex created from the given pattern.
**Example**
```js
const picomatch = require('picomatch');
// picomatch.makeRe(input[, options]);
const state = picomatch.parse('*.js');
// picomatch.compileRe(state[, options]);

console.log(picomatch.makeRe('*.js'));
console.log(picomatch.compileRe(state));
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
```
### [.toRegex](lib/picomatch.js#L317)
### [.toRegex](lib/picomatch.js#L318)
Create a regular expression from the given regex source string.
4 changes: 1 addition & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -228,8 +228,6 @@ const parse = (input, options) => {
const output = (opts.capture ? '(' : '') + token.open;

increment('parens');


push({ type, value, output: state.output ? '' : ONE_CHAR });
push({ type: 'paren', extglob: true, value: advance(), output });
extglobs.push(token);
@@ -585,7 +583,7 @@ const parse = (input, options) => {
const out = state.output.slice(0, brace.outputIndex);
const toks = state.tokens.slice(brace.tokensIndex);
brace.value = brace.output = '\\{';
value = output = `\\}`;
value = output = '\\}';
state.output = out;
for (const t of toks) {
state.output += (t.output || t.value);
9 changes: 5 additions & 4 deletions lib/picomatch.js
Original file line number Diff line number Diff line change
@@ -231,16 +231,17 @@ picomatch.parse = (pattern, options) => {
picomatch.scan = (input, options) => scan(input, options);

/**
* Create a regular expression from a glob pattern.
* Create a regular expression from a parsed glob pattern.
*
* ```js
* const picomatch = require('picomatch');
* // picomatch.makeRe(input[, options]);
* const state = picomatch.parse('*.js');
* // picomatch.compileRe(state[, options]);
*
* console.log(picomatch.makeRe('*.js'));
* console.log(picomatch.compileRe(state));
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
* ```
* @param {String} `input` A glob pattern to convert to regex.
* @param {String} `state` The object returned from the `.parse` method.
* @param {Object} `options`
* @return {RegExp} Returns a regex created from the given pattern.
* @api public
25 changes: 13 additions & 12 deletions lib/scan.js
Original file line number Diff line number Diff line change
@@ -247,23 +247,24 @@ const scan = (input, options) => {
}

if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
while (eos() !== true && (code = advance())) {
if (code === CHAR_BACKWARD_SLASH) {
backslashes = token.backslashes = true;
code = advance();
continue;
}

if (code === CHAR_RIGHT_PARENTHESES) {
isGlob = token.isGlob = true;
finished = true;
isGlob = token.isGlob = true;

if (scanToEnd === true) {
if (scanToEnd === true) {
while (eos() !== true && (code = advance())) {
if (code === CHAR_LEFT_PARENTHESES) {
backslashes = token.backslashes = true;
code = advance();
continue;
}
break;

if (code === CHAR_RIGHT_PARENTHESES) {
finished = true;
break;
}
}
continue;
}
break;
}

if (isGlob === true) {
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "picomatch",
"description": "Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.",
"version": "2.2.1",
"version": "2.2.2",
"homepage": "https://github.com/micromatch/picomatch",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"funding": "https://github.com/sponsors/jonschlinkert",
@@ -22,7 +22,7 @@
"lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
"mocha": "mocha --reporter dot",
"test": "npm run lint && npm run mocha",
"test:ci": "npm run lint && npm run test:cover",
"test:ci": "npm run test:cover",
"test:cover": "nyc npm run mocha"
},
"devDependencies": {
60 changes: 60 additions & 0 deletions test/api.scan.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,16 @@ const both = (...args) => {
return [base, glob];
};

/**
* @param {String} pattern
* @param {String[]} parts
*/
function assertParts(pattern, parts) {
const info = scan(pattern, { parts: true });

assert.deepStrictEqual(info.parts, parts);
}

/**
* Most of the unit tests in this file were from https://github.com/es128/glob-parent
* and https://github.com/jonschlinkert/glob-base. Both libraries use a completely
@@ -252,6 +262,56 @@ describe('picomatch', () => {
negated: false
});
});

it('should return parts of the pattern', () => {
// Right now it returns []
// assertParts('', ['']);
// assertParts('*', ['*']);
// assertParts('.*', ['.*']);
// assertParts('**', ['**']);
// assertParts('foo', ['foo']);
// assertParts('foo*', ['foo*']);
// assertParts('/', ['', '']);
// assertParts('/*', ['', '*']);
// assertParts('./', ['']);
// assertParts('{1..9}', ['{1..9}']);
// assertParts('c!(.)z', ['c!(.)z']);
// assertParts('(b|a).(a)', ['(b|a).(a)']);
// assertParts('+(a|b\\[)*', ['+(a|b\\[)*']);
// assertParts('@(a|b).md', ['@(a|b).md']);
// assertParts('(a/b)', ['(a/b)']);
// assertParts('(a\\b)', ['(a\\b)']);
// assertParts('foo\\[a\\/]', ['foo\\[a\\/]']);
// assertParts('foo[/]bar', ['foo[/]bar']);
// assertParts('/dev\\/@(tcp|udp)\\/*\\/*', ['', '/dev\\/@(tcp|udp)\\/*\\/*']);

// Right now it returns ['*']
// assertParts('*/', ['*', '']);

// Right now it returns ['!(!(bar)', 'baz)']
// assertParts('!(!(bar)/baz)', ['!(!(bar)/baz)']);

assertParts('./foo', ['foo']);
assertParts('../foo', ['..', 'foo']);

assertParts('foo/bar', ['foo', 'bar']);
assertParts('foo/*', ['foo', '*']);
assertParts('foo/**', ['foo', '**']);
assertParts('foo/**/*', ['foo', '**', '*']);
assertParts('フォルダ/**/*', ['フォルダ', '**', '*']);

assertParts('foo/!(abc)', ['foo', '!(abc)']);
assertParts('c/!(z)/v', ['c', '!(z)', 'v']);
assertParts('c/@(z)/v', ['c', '@(z)', 'v']);
assertParts('foo/(bar|baz)', ['foo', '(bar|baz)']);
assertParts('foo/(bar|baz)*', ['foo', '(bar|baz)*']);
assertParts('**/*(W*, *)*', ['**', '*(W*, *)*']);
assertParts('a/**@(/x|/z)/*.md', ['a', '**@(/x|/z)', '*.md']);
assertParts('foo/(bar|baz)/*.js', ['foo', '(bar|baz)', '*.js']);

assertParts('XXX/*/*/12/*/*/m/*/*', ['XXX', '*', '*', '12', '*', '*', 'm', '*', '*']);
assertParts('foo/\\"**\\"/bar', ['foo', '\\"**\\"', 'bar']);
});
});

describe('.base (glob2base test patterns)', () => {