Skip to content

Commit d223116

Browse files
jropbestander
authored andcommitted
Switch to micromatch: fixes #3336 (#3339)
* Switch to micromatch: fixes #3336 * Trim patterns before generating RegExp Test suite now passes * Add test + test fixtures to test micromatch * Oops. Actually add the fixtures to Git this time * Update yarn.lock reverted registry change
1 parent 6e54578 commit d223116

File tree

10 files changed

+63
-25
lines changed

10 files changed

+63
-25
lines changed

__tests__/commands/pack.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export async function getFilesFromArchive(source, destination): Promise<Array<st
4141
return files;
4242
}
4343

44-
test.concurrent('pack should work with a minimal example', (): Promise<void> => {
44+
test.concurrent('pack should work with a minimal example',
45+
(): Promise<void> => {
4546
return runPack([], {}, 'minimal', async (config): Promise<void> => {
4647
const {cwd} = config;
4748
const files = await getFilesFromArchive(
@@ -53,7 +54,8 @@ test.concurrent('pack should work with a minimal example', (): Promise<void> =>
5354
});
5455
});
5556

56-
test.concurrent('pack should include all files listed in the files array', (): Promise<void> => {
57+
test.concurrent('pack should include all files listed in the files array',
58+
(): Promise<void> => {
5759
return runPack([], {}, 'files-include', async (config): Promise<void> => {
5860
const {cwd} = config;
5961
const files = await getFilesFromArchive(
@@ -71,6 +73,24 @@ test.concurrent('pack should include all files listed in the files array', (): P
7173
});
7274
});
7375

76+
test.concurrent('pack should included globbed files',
77+
(): Promise<void> => {
78+
return runPack([], {}, 'files-glob', async (config): Promise<void> => {
79+
const {cwd} = config;
80+
const files = await getFilesFromArchive(
81+
path.join(cwd, 'files-glob-v1.0.0.tgz'),
82+
path.join(cwd, 'files-glob-v1.0.0'),
83+
);
84+
expect(files.sort()).toEqual([
85+
'lib',
86+
'lib/a.js',
87+
'lib/b.js',
88+
'index.js',
89+
'package.json',
90+
].sort());
91+
});
92+
});
93+
7494
test.concurrent('pack should include mandatory files not listed in files array if files not empty',
7595
(): Promise<void> => {
7696
return runPack([], {}, 'files-include-mandatory', async (config): Promise<void> => {
@@ -86,7 +106,8 @@ test.concurrent('pack should include mandatory files not listed in files array i
86106
});
87107
});
88108

89-
test.concurrent('pack should exclude mandatory files from ignored directories', (): Promise<void> => {
109+
test.concurrent('pack should exclude mandatory files from ignored directories',
110+
(): Promise<void> => {
90111
return runPack([], {}, 'exclude-mandatory-files-from-ignored-directories', async (config): Promise<void> => {
91112
const {cwd} = config;
92113
const files = await getFilesFromArchive(
@@ -126,7 +147,7 @@ test.concurrent('pack should exclude all dotflies if not in files and files not
126147
});
127148
});
128149

129-
test.concurrent('pack should exclude all files in dot-directories if not in files and files not empty ',
150+
test.concurrent('pack should exclude all files in dot-directories if not in files and files not empty',
130151
(): Promise<void> => {
131152
return runPack([], {}, 'files-exclude-dotdir', async (config): Promise<void> => {
132153
const {cwd} = config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
console.log('hello world');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
console.log('hello world');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
console.log('hello world');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "files-glob",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"files": ["lib/**/*.js"]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
console.log('hello world');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
console.log('hello world');

__tests__/util/filter.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ test('ignoreLinesToRegex', () => {
2929
'! F # # ',
3030
'#! G',
3131
])).toEqual([
32-
{base: '.', isNegation: false, pattern: 'a', regex: /^(?:(?=.)a)$/i},
33-
{base: '.', isNegation: false, pattern: 'b ', regex: /^(?:(?=.)b)$/i},
34-
{base: '.', isNegation: false, pattern: ' c ', regex: /^(?:(?=.)c)$/i},
35-
{base: '.', isNegation: false, pattern: 'd #', regex: /^(?:(?=.)d #)$/i},
36-
{base: '.', isNegation: false, pattern: 'e#', regex: /^(?:(?=.)e#)$/i},
37-
{base: '.', isNegation: false, pattern: 'f # ', regex: /^(?:(?=.)f #)$/i},
38-
{base: '.', isNegation: false, pattern: 'g# ', regex: /^(?:(?=.)g#)$/i},
39-
{base: '.', isNegation: false, pattern: 'h # foo', regex: /^(?:(?=.)h # foo)$/i},
40-
{base: '.', isNegation: false, pattern: 'i# foo', regex: /^(?:(?=.)i# foo)$/i},
41-
{base: '.', isNegation: false, pattern: 'j # foo #', regex: /^(?:(?=.)j # foo #)$/i},
42-
{base: '.', isNegation: false, pattern: 'k # foo # #', regex: /^(?:(?=.)k # foo # #)$/i},
43-
{base: '.', isNegation: true, pattern: 'A', regex: /^(?:(?=.)A)$/i},
44-
{base: '.', isNegation: true, pattern: ' B', regex: /^(?:(?=.)B)$/i},
45-
{base: '.', isNegation: true, pattern: ' C ', regex: /^(?:(?=.)C)$/i},
46-
{base: '.', isNegation: true, pattern: ' D #', regex: /^(?:(?=.)D #)$/i},
47-
{base: '.', isNegation: true, pattern: ' E # ', regex: /^(?:(?=.)E #)$/i},
48-
{base: '.', isNegation: true, pattern: ' F # # ', regex: /^(?:(?=.)F # #)$/i},
32+
{base: '.', isNegation: false, pattern: 'a', regex: /^(?:a)$/i},
33+
{base: '.', isNegation: false, pattern: 'b ', regex: /^(?:b)$/i},
34+
{base: '.', isNegation: false, pattern: ' c ', regex: /^(?:c)$/i},
35+
{base: '.', isNegation: false, pattern: 'd #', regex: /^(?:d #)$/i},
36+
{base: '.', isNegation: false, pattern: 'e#', regex: /^(?:e#)$/i},
37+
{base: '.', isNegation: false, pattern: 'f # ', regex: /^(?:f #)$/i},
38+
{base: '.', isNegation: false, pattern: 'g# ', regex: /^(?:g#)$/i},
39+
{base: '.', isNegation: false, pattern: 'h # foo', regex: /^(?:h # foo)$/i},
40+
{base: '.', isNegation: false, pattern: 'i# foo', regex: /^(?:i# foo)$/i},
41+
{base: '.', isNegation: false, pattern: 'j # foo #', regex: /^(?:j # foo #)$/i},
42+
{base: '.', isNegation: false, pattern: 'k # foo # #', regex: /^(?:k # foo # #)$/i},
43+
{base: '.', isNegation: true, pattern: 'A', regex: /^(?:A)$/i},
44+
{base: '.', isNegation: true, pattern: ' B', regex: /^(?:B)$/i},
45+
{base: '.', isNegation: true, pattern: ' C ', regex: /^(?:C)$/i},
46+
{base: '.', isNegation: true, pattern: ' D #', regex: /^(?:D #)$/i},
47+
{base: '.', isNegation: true, pattern: ' E # ', regex: /^(?:E #)$/i},
48+
{base: '.', isNegation: true, pattern: ' F # # ', regex: /^(?:F # #)$/i},
4949
]);
5050
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"is-ci": "^1.0.10",
2525
"leven": "^2.0.0",
2626
"loud-rejection": "^1.2.0",
27-
"minimatch": "^3.0.3",
27+
"micromatch": "^2.3.11",
2828
"mkdirp": "^0.5.1",
2929
"node-emoji": "^1.0.4",
3030
"object-path": "^0.11.2",

src/util/filter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type {WalkFiles} from './fs.js';
44
import {removeSuffix} from './misc.js';
55

6-
const minimatch = require('minimatch');
6+
const mm = require('micromatch');
77
const path = require('path');
88

99
const WHITESPACE_RE = /^\s+$/;
@@ -101,7 +101,7 @@ export function matchesFilter(filter: IgnoreFilter, basename: string, loc: strin
101101
return filter.regex.test(loc) ||
102102
filter.regex.test(`/${loc}`) ||
103103
filter.regex.test(basename) ||
104-
minimatch(loc, filter.pattern);
104+
mm.isMatch(loc, filter.pattern);
105105
}
106106

107107
export function ignoreLinesToRegex(lines: Array<string>, base: string = '.'): Array<IgnoreFilter> {
@@ -126,7 +126,7 @@ export function ignoreLinesToRegex(lines: Array<string>, base: string = '.'): Ar
126126
// remove trailing slash
127127
pattern = removeSuffix(pattern, '/');
128128

129-
const regex: ?RegExp = minimatch.makeRe(pattern, {nocase: true});
129+
const regex: ?RegExp = mm.makeRe(pattern.trim(), {nocase: true});
130130

131131
if (regex) {
132132
return {

0 commit comments

Comments
 (0)