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

fix for including excluded and vice versa #1067

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
43 changes: 21 additions & 22 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,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('')
)
Expand All @@ -1707,30 +1707,29 @@ 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])

// 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
))

)
);
});
Expand Down Expand Up @@ -2041,7 +2040,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.map(f => util.normalize(f.originalPath ?? (!isInMemoryFile(f) ? f.localPath : path.join(cwd, f.path))));
const filesIncludePatterns = manifest.files.map(includePattern => ({ absolute: util.normalize(path.join(cwd, includePattern)), relative: includePattern }));
const filesIncludePatterns = manifest.files.filter(includePattern => includePattern[0] !== '!').map(includePattern => ({ absolute: util.normalize(path.join(cwd, includePattern)), relative: includePattern }));

const unusedIncludePatterns = filesIncludePatterns.filter(includePattern => {
let absoluteIncludePattern = includePattern.absolute;
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/manifestFiles/foo/bar/exclude.me
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
should be ignored as it's listed as excluded in the package.json files list.
1 change: 1 addition & 0 deletions src/test/fixtures/manifestFiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"files": [
"foo",
"!**/exclude.me",
"foo2/bar2/include.me",
"*/bar3/**",
"package.json",
Expand Down