From 01747f66cefacee4faef70f0f03441231bbbeb30 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 3 Aug 2018 15:13:43 +0200 Subject: [PATCH] ignore folders without slashes in vsceignore, without disk access --- src/package.ts | 23 ++++++++++++----------- src/test/package.test.ts | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/package.ts b/src/package.ts index 73c9c1c..a6f0df8 100644 --- a/src/package.ts +++ b/src/package.ts @@ -26,7 +26,6 @@ const readFile = denodeify(fs.readFile); const unlink = denodeify(fs.unlink as any); const exec = denodeify(cp.exec as any, (err, stdout, stderr) => [err, { stdout, stderr }]); const glob = denodeify(_glob); -const lstat = denodeify(fs.lstat); const resourcesPath = path.join(path.dirname(__dirname), 'resources'); const vsixManifestTemplatePath = path.join(resourcesPath, 'extension.vsixmanifest'); @@ -705,19 +704,21 @@ function collectFiles(cwd: string, useYarn = false): Promise { return readFile(path.join(cwd, '.vscodeignore'), 'utf8') .catch(err => err.code !== 'ENOENT' ? Promise.reject(err) : Promise.resolve('')) - .then(rawIgnore => rawIgnore.split(/[\n\r]/).filter(s => !!s).map(s => s.trim().replace(/\/$/, ''))) - .then(ignore => { - const promises = ignore.map(i => { - return lstat(i) - .catch(() => Promise.resolve()) - .then(stat => stat && stat.isDirectory() ? `${i}/**` : i); - }); - return Promise.all(promises).then(i => Promise.resolve(i)); - }) + + // Parse raw ignore by splitting output into lines and filtering out empty lines and comments + .then(rawIgnore => rawIgnore.split(/[\n\r]/).map(s => s.trim()).filter(s => !!s).filter(i => !/^\s*#/.test(i))) + + // Add '/**' to possible folder names + .then(ignore => [...ignore, ...ignore.filter(i => !/(^|\/)[^/]*\*[^/]*$/.test(i)).map(i => /\/$/.test(i) ? `${i}**` : `${i}/**`)]) + + // Combine with default ignore list .then(ignore => [...defaultIgnore, ...ignore, '!package.json']) - .then(ignore => ignore.filter(i => !/^\s*#/.test(i))) + + // Split into ignore and negate list .then(ignore => _.partition(ignore, i => !/^\s*!/.test(i))) .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)))); }); } diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 32a5eea..cafb681 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -137,7 +137,7 @@ describe('collect', function () { it('should ignore content of .vscodeignore', () => { const cwd = fixture('vscodeignore'); - + return readManifest(cwd) .then(manifest => collect(manifest, { cwd })) .then(files => {