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

Switch to micromatch: fixes yarnpkg/yarn#3336 #3339

Merged
merged 5 commits into from
May 12, 2017
Merged
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
29 changes: 25 additions & 4 deletions __tests__/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export async function getFilesFromArchive(source, destination): Promise<Array<st
return files;
}

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

test.concurrent('pack should include all files listed in the files array', (): Promise<void> => {
test.concurrent('pack should include all files listed in the files array',
(): Promise<void> => {
return runPack([], {}, 'files-include', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
Expand All @@ -71,6 +73,24 @@ test.concurrent('pack should include all files listed in the files array', (): P
});
});

test.concurrent('pack should included globbed files',
(): Promise<void> => {
return runPack([], {}, 'files-glob', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
path.join(cwd, 'files-glob-v1.0.0.tgz'),
path.join(cwd, 'files-glob-v1.0.0'),
);
expect(files.sort()).toEqual([
'lib',
'lib/a.js',
'lib/b.js',
'index.js',
'package.json',
].sort());
});
});

test.concurrent('pack should include mandatory files not listed in files array if files not empty',
(): Promise<void> => {
return runPack([], {}, 'files-include-mandatory', async (config): Promise<void> => {
Expand All @@ -86,7 +106,8 @@ test.concurrent('pack should include mandatory files not listed in files array i
});
});

test.concurrent('pack should exclude mandatory files from ignored directories', (): Promise<void> => {
test.concurrent('pack should exclude mandatory files from ignored directories',
(): Promise<void> => {
return runPack([], {}, 'exclude-mandatory-files-from-ignored-directories', async (config): Promise<void> => {
const {cwd} = config;
const files = await getFilesFromArchive(
Expand Down Expand Up @@ -126,7 +147,7 @@ test.concurrent('pack should exclude all dotflies if not in files and files not
});
});

test.concurrent('pack should exclude all files in dot-directories if not in files and files not empty ',
test.concurrent('pack should exclude all files in dot-directories if not in files and files not empty',
(): Promise<void> => {
return runPack([], {}, 'files-exclude-dotdir', async (config): Promise<void> => {
const {cwd} = config;
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/pack/files-glob/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
2 changes: 2 additions & 0 deletions __tests__/fixtures/pack/files-glob/lib/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
2 changes: 2 additions & 0 deletions __tests__/fixtures/pack/files-glob/lib/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
7 changes: 7 additions & 0 deletions __tests__/fixtures/pack/files-glob/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "files-glob",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"files": ["lib/**/*.js"]
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/pack/files-glob/src/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
2 changes: 2 additions & 0 deletions __tests__/fixtures/pack/files-glob/src/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
console.log('hello world');
34 changes: 17 additions & 17 deletions __tests__/util/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ test('ignoreLinesToRegex', () => {
'! F # # ',
'#! G',
])).toEqual([
{base: '.', isNegation: false, pattern: 'a', regex: /^(?:(?=.)a)$/i},
{base: '.', isNegation: false, pattern: 'b ', regex: /^(?:(?=.)b)$/i},
{base: '.', isNegation: false, pattern: ' c ', regex: /^(?:(?=.)c)$/i},
{base: '.', isNegation: false, pattern: 'd #', regex: /^(?:(?=.)d #)$/i},
{base: '.', isNegation: false, pattern: 'e#', regex: /^(?:(?=.)e#)$/i},
{base: '.', isNegation: false, pattern: 'f # ', regex: /^(?:(?=.)f #)$/i},
{base: '.', isNegation: false, pattern: 'g# ', regex: /^(?:(?=.)g#)$/i},
{base: '.', isNegation: false, pattern: 'h # foo', regex: /^(?:(?=.)h # foo)$/i},
{base: '.', isNegation: false, pattern: 'i# foo', regex: /^(?:(?=.)i# foo)$/i},
{base: '.', isNegation: false, pattern: 'j # foo #', regex: /^(?:(?=.)j # foo #)$/i},
{base: '.', isNegation: false, pattern: 'k # foo # #', regex: /^(?:(?=.)k # foo # #)$/i},
{base: '.', isNegation: true, pattern: 'A', regex: /^(?:(?=.)A)$/i},
{base: '.', isNegation: true, pattern: ' B', regex: /^(?:(?=.)B)$/i},
{base: '.', isNegation: true, pattern: ' C ', regex: /^(?:(?=.)C)$/i},
{base: '.', isNegation: true, pattern: ' D #', regex: /^(?:(?=.)D #)$/i},
{base: '.', isNegation: true, pattern: ' E # ', regex: /^(?:(?=.)E #)$/i},
{base: '.', isNegation: true, pattern: ' F # # ', regex: /^(?:(?=.)F # #)$/i},
{base: '.', isNegation: false, pattern: 'a', regex: /^(?:a)$/i},
{base: '.', isNegation: false, pattern: 'b ', regex: /^(?:b)$/i},
{base: '.', isNegation: false, pattern: ' c ', regex: /^(?:c)$/i},
{base: '.', isNegation: false, pattern: 'd #', regex: /^(?:d #)$/i},
{base: '.', isNegation: false, pattern: 'e#', regex: /^(?:e#)$/i},
{base: '.', isNegation: false, pattern: 'f # ', regex: /^(?:f #)$/i},
{base: '.', isNegation: false, pattern: 'g# ', regex: /^(?:g#)$/i},
{base: '.', isNegation: false, pattern: 'h # foo', regex: /^(?:h # foo)$/i},
{base: '.', isNegation: false, pattern: 'i# foo', regex: /^(?:i# foo)$/i},
{base: '.', isNegation: false, pattern: 'j # foo #', regex: /^(?:j # foo #)$/i},
{base: '.', isNegation: false, pattern: 'k # foo # #', regex: /^(?:k # foo # #)$/i},
{base: '.', isNegation: true, pattern: 'A', regex: /^(?:A)$/i},
{base: '.', isNegation: true, pattern: ' B', regex: /^(?:B)$/i},
{base: '.', isNegation: true, pattern: ' C ', regex: /^(?:C)$/i},
{base: '.', isNegation: true, pattern: ' D #', regex: /^(?:D #)$/i},
{base: '.', isNegation: true, pattern: ' E # ', regex: /^(?:E #)$/i},
{base: '.', isNegation: true, pattern: ' F # # ', regex: /^(?:F # #)$/i},
]);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"is-ci": "^1.0.10",
"leven": "^2.0.0",
"loud-rejection": "^1.2.0",
"minimatch": "^3.0.3",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"node-emoji": "^1.0.4",
"object-path": "^0.11.2",
Expand Down
6 changes: 3 additions & 3 deletions src/util/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type {WalkFiles} from './fs.js';
import {removeSuffix} from './misc.js';

const minimatch = require('minimatch');
const mm = require('micromatch');
const path = require('path');

const WHITESPACE_RE = /^\s+$/;
Expand Down Expand Up @@ -101,7 +101,7 @@ export function matchesFilter(filter: IgnoreFilter, basename: string, loc: strin
return filter.regex.test(loc) ||
filter.regex.test(`/${loc}`) ||
filter.regex.test(basename) ||
minimatch(loc, filter.pattern);
mm.isMatch(loc, filter.pattern);
}

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

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

if (regex) {
return {
Expand Down