From 2e76a86b1cce3bda9445593ad336179fc0d8c344 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Fri, 31 Jan 2020 12:19:30 -0600 Subject: [PATCH] fix: use ignore npm package instead of half-baked custom code for .vscodeignore --- package.json | 3 +-- src/package.ts | 20 ++------------------ yarn.lock | 9 +++++++-- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index c6b2e1a3..035e887b 100644 --- a/package.json +++ b/package.json @@ -42,10 +42,10 @@ "denodeify": "^1.2.1", "didyoumean": "^1.2.1", "glob": "^7.0.6", + "ignore": "^5.1.4", "lodash": "^4.17.10", "markdown-it": "^8.3.1", "mime": "^1.3.4", - "minimatch": "^3.0.3", "osenv": "^0.1.3", "parse-semver": "^1.1.1", "read": "^1.0.7", @@ -64,7 +64,6 @@ "@types/lodash": "^4.14.123", "@types/markdown-it": "0.0.2", "@types/mime": "^1", - "@types/minimatch": "^3.0.3", "@types/mocha": "^5.2.6", "@types/node": "^8", "@types/read": "^0.0.28", diff --git a/src/package.ts b/src/package.ts index f84d78a7..5efa2407 100644 --- a/src/package.ts +++ b/src/package.ts @@ -7,7 +7,6 @@ import { Manifest } from './manifest'; import { ITranslations, patchNLS } from './nls'; import * as util from './util'; import * as _glob from 'glob'; -import * as minimatch from 'minimatch'; import * as denodeify from 'denodeify'; import * as markdownit from 'markdown-it'; import * as cheerio from 'cheerio'; @@ -16,6 +15,7 @@ import { lookup } from 'mime'; import * as urljoin from 'url-join'; import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility, validateVSCodeTypesCompatibility } from './validation'; import { getDependencies } from './npm'; +import ignore from 'ignore' const readFile = denodeify(fs.readFile); const unlink = denodeify(fs.unlink as any); @@ -27,8 +27,6 @@ const resourcesPath = path.join(path.dirname(__dirname), 'resources'); const vsixManifestTemplatePath = path.join(resourcesPath, 'extension.vsixmanifest'); const contentTypesTemplatePath = path.join(resourcesPath, '[Content_Types].xml'); -const MinimatchOptions: minimatch.IOptions = { dot: true }; - export interface IFile { path: string; contents?: Buffer | string; @@ -834,21 +832,7 @@ function collectFiles(cwd: string, useYarn = false, dependencyEntryPoints?: stri return readFile(ignoreFile ? ignoreFile : path.join(cwd, '.vscodeignore'), 'utf8') .catch(err => err.code !== 'ENOENT' ? Promise.reject(err) : ignoreFile ? Promise.reject(err) : Promise.resolve('')) - // 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']) - - // 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)))); + .then(rawIgnore => ignore().add(defaultIgnore).add(rawIgnore).filter(files)) }); } diff --git a/yarn.lock b/yarn.lock index 483a9b3f..552f79d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -46,7 +46,7 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.1.tgz#2cf42972d0931c1060c7d5fa6627fce6bd876f2f" integrity sha512-rek8twk9C58gHYqIrUlJsx8NQMhlxqHzln9Z9ODqiNgv3/s+ZwIrfr+djqzsnVM12xe9hL98iJ20lj2RvCBv6A== -"@types/minimatch@*", "@types/minimatch@^3.0.3": +"@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== @@ -460,6 +460,11 @@ htmlparser2@^3.9.1: inherits "^2.0.1" readable-stream "^3.0.6" +ignore@^5.1.4: + version "5.1.4" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf" + integrity sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A== + inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -579,7 +584,7 @@ mimic-fn@^2.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== -minimatch@3.0.4, minimatch@^3.0.3, minimatch@^3.0.4: +minimatch@3.0.4, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==