From 0533dbbac67bd4d75fac6f16113a2fee60691f17 Mon Sep 17 00:00:00 2001 From: adrianstephens Date: Sat, 12 Oct 2024 16:30:23 -0700 Subject: [PATCH 1/6] fix for including excluded and vice versa --- src/package.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/package.ts b/src/package.ts index b0b95ea3..d76c0954 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1688,8 +1688,8 @@ function collectFiles( Promise.reject(err) : // No .vscodeignore file exists manifestFileIncludes ? - // include all files in manifestFileIncludes and ignore the rest - Promise.resolve(manifestFileIncludes.map(file => `!${file}`).concat(['**']).join('\n\r')) : + // ignore all, and then include all files in manifestFileIncludes + Promise.resolve(['**', ...manifestFileIncludes.map(file => file[0] === '!' ? file.slice(1) : `!${file}`)].join('\n\r')) : // "files" property not used in package.json Promise.resolve('') ) @@ -1712,22 +1712,14 @@ function collectFiles( // Combine with default ignore list .then(ignore => [...defaultIgnore, ...ignore, ...notIgnored]) - // Split into ignore and negate list + // Check the ignore list in order to filter out files .then(ignore => - ignore.reduce<[string[], string[]]>( - (r, e) => (!/^\s*!/.test(e) ? [[...r[0], e], r[1]] : [r[0], [...r[1], e]]), - [[], []] - ) - ) - .then(r => ({ ignore: r[0], negate: r[1] })) - - // Filter out files - .then(({ ignore, negate }) => - files.filter( - f => - !ignore.some(i => minimatch(f, i, MinimatchOptions)) || - negate.some(i => minimatch(f, i.substr(1), MinimatchOptions)) - ) + files.filter(f=> ignore.reduce((keep, i) => i[0] === '!' + ? keep || minimatch(f, i.slice(1), MinimatchOptions) + : keep && !minimatch(f, i, MinimatchOptions), + true + )) + ) ); }); From 80a9037479704043b5fd0016433658cf859b708e Mon Sep 17 00:00:00 2001 From: adrianstephens Date: Sat, 12 Oct 2024 17:14:44 -0700 Subject: [PATCH 2/6] interleave possible folder names --- src/package.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/package.ts b/src/package.ts index d76c0954..334b2c34 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1704,10 +1704,9 @@ function collectFiles( ) // Add '/**' to possible folder names - .then(ignore => [ - ...ignore, - ...ignore.filter(i => !/(^|\/)[^/]*\*[^/]*$/.test(i)).map(i => (/\/$/.test(i) ? `${i}**` : `${i}/**`)), - ]) + .then(ignore => + ignore.map(i => !/(^|\/)[^/]*\*[^/]*$/.test(i) ? [i, /\/$/.test(i) ? `${i}**` : `${i}/**`] : [i]).flat(), + ) // Combine with default ignore list .then(ignore => [...defaultIgnore, ...ignore, ...notIgnored]) From ed6c15814cc60ba02b059614bd3b4c9d0697f3fa Mon Sep 17 00:00:00 2001 From: adrianstephens Date: Sun, 13 Oct 2024 14:29:07 -0700 Subject: [PATCH 3/6] validation fix --- src/package.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package.ts b/src/package.ts index 334b2c34..f40508c8 100644 --- a/src/package.ts +++ b/src/package.ts @@ -2029,7 +2029,7 @@ export async function printAndValidatePackagedFiles(files: IFile[], cwd: string, // the package does not include at least one file for each include pattern else if (manifest.files !== undefined && manifest.files.length > 0 && !options.allowUnusedFilesPattern) { const localPaths = (files.filter(f => !isInMemoryFile(f)) as ILocalFile[]).map(f => util.normalize(f.localPath)); - const filesIncludePatterns = manifest.files.map(includePattern => util.normalize(path.join(cwd, includePattern))); + const filesIncludePatterns = manifest.files.filter(includePattern => includePattern[0] !== '!').map(includePattern => util.normalize(path.join(cwd, includePattern))); const unusedIncludePatterns = filesIncludePatterns.filter(includePattern => { // Check if the pattern provided by the user matches any file in the package From 0df38bd1899de0249275ab1d66f738a731be5371 Mon Sep 17 00:00:00 2001 From: AshtonStephens Date: Wed, 6 Nov 2024 19:55:51 +0000 Subject: [PATCH 4/6] feat: Reformat map expression. --- src/package.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/package.ts b/src/package.ts index 8a034a2b..fee3e29c 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1707,8 +1707,16 @@ function collectFiles( ) // Add '/**' to possible folder names - .then(ignore => - ignore.map(i => !/(^|\/)[^/]*\*[^/]*$/.test(i) ? [i, /\/$/.test(i) ? `${i}**` : `${i}/**`] : [i]).flat(), + .then(ignore => + ignore.map(i => !/(^|\/)[^/]*\*[^/]*$/.test(i) + ? [ + i, + /\/$/.test(i) + ? `${i}**` + : `${i}/**` + ] + : [i] + ).flat(), ) // Combine with default ignore list From aac35bda37f84e1ee9d9a4d8b72c8320d0a53076 Mon Sep 17 00:00:00 2001 From: AshtonStephens Date: Wed, 6 Nov 2024 19:57:07 +0000 Subject: [PATCH 5/6] feat: Add file exclusion to unit tests --- src/test/fixtures/manifestFiles/foo/bar/exclude.me | 1 + src/test/fixtures/manifestFiles/package.json | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/test/fixtures/manifestFiles/foo/bar/exclude.me diff --git a/src/test/fixtures/manifestFiles/foo/bar/exclude.me b/src/test/fixtures/manifestFiles/foo/bar/exclude.me new file mode 100644 index 00000000..31ba3b47 --- /dev/null +++ b/src/test/fixtures/manifestFiles/foo/bar/exclude.me @@ -0,0 +1 @@ +should be ignored as it's listed as excluded in the package.json files list. diff --git a/src/test/fixtures/manifestFiles/package.json b/src/test/fixtures/manifestFiles/package.json index ee4afe51..a45e420b 100644 --- a/src/test/fixtures/manifestFiles/package.json +++ b/src/test/fixtures/manifestFiles/package.json @@ -7,6 +7,7 @@ }, "files": [ "foo", + "!**/exclude.me", "foo2/bar2/include.me", "*/bar3/**", "package.json", From ef550f0f50a2dd1e42d539c91b807e4acd34f8c5 Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Tue, 10 Dec 2024 15:18:55 +0100 Subject: [PATCH 6/6] Add tests --- src/test/fixtures/manifestFiles/fooExclude/excluded.txt | 0 .../fixtures/manifestFiles/fooExclude/includeNotPossible.txt | 0 src/test/fixtures/manifestFiles/fooInclude/excluded.txt | 0 src/test/fixtures/manifestFiles/fooInclude/included.txt | 0 src/test/fixtures/manifestFiles/package.json | 4 ++++ src/test/package.test.ts | 1 + 6 files changed, 5 insertions(+) create mode 100644 src/test/fixtures/manifestFiles/fooExclude/excluded.txt create mode 100644 src/test/fixtures/manifestFiles/fooExclude/includeNotPossible.txt create mode 100644 src/test/fixtures/manifestFiles/fooInclude/excluded.txt create mode 100644 src/test/fixtures/manifestFiles/fooInclude/included.txt diff --git a/src/test/fixtures/manifestFiles/fooExclude/excluded.txt b/src/test/fixtures/manifestFiles/fooExclude/excluded.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/test/fixtures/manifestFiles/fooExclude/includeNotPossible.txt b/src/test/fixtures/manifestFiles/fooExclude/includeNotPossible.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/test/fixtures/manifestFiles/fooInclude/excluded.txt b/src/test/fixtures/manifestFiles/fooInclude/excluded.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/test/fixtures/manifestFiles/fooInclude/included.txt b/src/test/fixtures/manifestFiles/fooInclude/included.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/test/fixtures/manifestFiles/package.json b/src/test/fixtures/manifestFiles/package.json index a45e420b..7732243d 100644 --- a/src/test/fixtures/manifestFiles/package.json +++ b/src/test/fixtures/manifestFiles/package.json @@ -9,6 +9,10 @@ "foo", "!**/exclude.me", "foo2/bar2/include.me", + "!fooExclude/**", + "fooExclude/includeNotPossible.txt", + "fooInclude/**", + "!fooInclude/excluded.txt", "*/bar3/**", "package.json", "LICENSE", diff --git a/src/test/package.test.ts b/src/test/package.test.ts index a6689471..f40291bc 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -206,6 +206,7 @@ describe('collect', function () { 'extension/foo/bar/hello.txt', 'extension/foo2/bar2/include.me', 'extension/foo3/bar3/hello.txt', + 'extension/fooInclude/included.txt', 'extension/package.json', 'extension/readme.md', ]);