From 0f6d634b98c844e1cd24743b75cfff9cd6b2e968 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Sat, 6 May 2017 12:44:50 -0600 Subject: [PATCH 1/5] Switch to micromatch: fixes yarnpkg/yarn#3336 --- package.json | 2 +- src/util/filter.js | 6 +++--- yarn.lock | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b15b5e727b..45faaaa64b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/util/filter.js b/src/util/filter.js index a479bf3c10..788576d40f 100644 --- a/src/util/filter.js +++ b/src/util/filter.js @@ -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+$/; @@ -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, base: string = '.'): Array { @@ -126,7 +126,7 @@ export function ignoreLinesToRegex(lines: Array, base: string = '.'): Ar // remove trailing slash pattern = removeSuffix(pattern, '/'); - const regex: ?RegExp = minimatch.makeRe(pattern, {nocase: true}); + const regex: ?RegExp = mm.makeRe(pattern, {nocase: true}); if (regex) { return { diff --git a/yarn.lock b/yarn.lock index 2c843b0217..b1a7748ea5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3173,7 +3173,7 @@ merge@^1.1.3: micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7: version "2.3.11" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" + resolved "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" dependencies: arr-diff "^2.0.0" array-unique "^0.2.1" From 6d8b3d37fe42f0fc8cdf5cc97074cf363e648b52 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Mon, 8 May 2017 09:23:55 -0600 Subject: [PATCH 2/5] Trim patterns before generating RegExp Test suite now passes --- __tests__/util/filter.js | 34 +++++++++++++++++----------------- src/util/filter.js | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/__tests__/util/filter.js b/__tests__/util/filter.js index 65e11f4e17..e4b64b3229 100644 --- a/__tests__/util/filter.js +++ b/__tests__/util/filter.js @@ -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}, ]); }); diff --git a/src/util/filter.js b/src/util/filter.js index 788576d40f..339db4774e 100644 --- a/src/util/filter.js +++ b/src/util/filter.js @@ -126,7 +126,7 @@ export function ignoreLinesToRegex(lines: Array, base: string = '.'): Ar // remove trailing slash pattern = removeSuffix(pattern, '/'); - const regex: ?RegExp = mm.makeRe(pattern, {nocase: true}); + const regex: ?RegExp = mm.makeRe(pattern.trim(), {nocase: true}); if (regex) { return { From 9a804820afbf99918b7bb703b5fc11cd8878e297 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Fri, 12 May 2017 09:01:29 -0600 Subject: [PATCH 3/5] Add test + test fixtures to test micromatch --- __tests__/commands/pack.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index 326a6568c4..a88b4a1dd7 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -41,7 +41,8 @@ export async function getFilesFromArchive(source, destination): Promise => { +test.concurrent('pack should work with a minimal example', +(): Promise => { return runPack([], {}, 'minimal', async (config): Promise => { const {cwd} = config; const files = await getFilesFromArchive( @@ -53,7 +54,8 @@ test.concurrent('pack should work with a minimal example', (): Promise => }); }); -test.concurrent('pack should include all files listed in the files array', (): Promise => { +test.concurrent('pack should include all files listed in the files array', +(): Promise => { return runPack([], {}, 'files-include', async (config): Promise => { const {cwd} = config; const files = await getFilesFromArchive( @@ -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 => { + return runPack([], {}, 'files-glob', async (config): Promise => { + 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 => { return runPack([], {}, 'files-include-mandatory', async (config): Promise => { @@ -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 => { +test.concurrent('pack should exclude mandatory files from ignored directories', +(): Promise => { return runPack([], {}, 'exclude-mandatory-files-from-ignored-directories', async (config): Promise => { const {cwd} = config; const files = await getFilesFromArchive( @@ -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 => { return runPack([], {}, 'files-exclude-dotdir', async (config): Promise => { const {cwd} = config; From d9e330081739cab5ddc778948ae887e7ce8a5d87 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Fri, 12 May 2017 09:11:11 -0600 Subject: [PATCH 4/5] Oops. Actually add the fixtures to Git this time --- __tests__/fixtures/pack/files-glob/index.js | 2 ++ __tests__/fixtures/pack/files-glob/lib/a.js | 2 ++ __tests__/fixtures/pack/files-glob/lib/b.js | 2 ++ __tests__/fixtures/pack/files-glob/package.json | 7 +++++++ __tests__/fixtures/pack/files-glob/src/a.js | 2 ++ __tests__/fixtures/pack/files-glob/src/b.js | 2 ++ 6 files changed, 17 insertions(+) create mode 100644 __tests__/fixtures/pack/files-glob/index.js create mode 100644 __tests__/fixtures/pack/files-glob/lib/a.js create mode 100644 __tests__/fixtures/pack/files-glob/lib/b.js create mode 100644 __tests__/fixtures/pack/files-glob/package.json create mode 100644 __tests__/fixtures/pack/files-glob/src/a.js create mode 100644 __tests__/fixtures/pack/files-glob/src/b.js diff --git a/__tests__/fixtures/pack/files-glob/index.js b/__tests__/fixtures/pack/files-glob/index.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/index.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-glob/lib/a.js b/__tests__/fixtures/pack/files-glob/lib/a.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/lib/a.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-glob/lib/b.js b/__tests__/fixtures/pack/files-glob/lib/b.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/lib/b.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-glob/package.json b/__tests__/fixtures/pack/files-glob/package.json new file mode 100644 index 0000000000..0129755fe7 --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/package.json @@ -0,0 +1,7 @@ +{ + "name": "files-glob", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "files": ["lib/**/*.js"] +} diff --git a/__tests__/fixtures/pack/files-glob/src/a.js b/__tests__/fixtures/pack/files-glob/src/a.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/src/a.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); diff --git a/__tests__/fixtures/pack/files-glob/src/b.js b/__tests__/fixtures/pack/files-glob/src/b.js new file mode 100644 index 0000000000..66a7302f5c --- /dev/null +++ b/__tests__/fixtures/pack/files-glob/src/b.js @@ -0,0 +1,2 @@ +/* @flow */ +console.log('hello world'); From acd4c247fcedd7481c57f5187d4d806313daf08d Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 12 May 2017 16:29:25 +0100 Subject: [PATCH 5/5] Update yarn.lock reverted registry change --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index b1a7748ea5..2c843b0217 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3173,7 +3173,7 @@ merge@^1.1.3: micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7: version "2.3.11" - resolved "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" dependencies: arr-diff "^2.0.0" array-unique "^0.2.1"