Skip to content

Commit

Permalink
fix: use ignore npm package instead of half-baked custom code for .vs…
Browse files Browse the repository at this point in the history
…codeignore
  • Loading branch information
jedwards1211 committed Jan 31, 2020
1 parent 2ca36aa commit 2e76a86
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
20 changes: 2 additions & 18 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<string, string, string>(fs.readFile);
const unlink = denodeify<string, void>(fs.unlink as any);
Expand All @@ -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;
Expand Down Expand Up @@ -834,21 +832,7 @@ function collectFiles(cwd: string, useYarn = false, dependencyEntryPoints?: stri
return readFile(ignoreFile ? ignoreFile : path.join(cwd, '.vscodeignore'), 'utf8')
.catch<string>(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))
});
}

Expand Down
9 changes: 7 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==

[email protected], minimatch@^3.0.3, minimatch@^3.0.4:
[email protected], 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==
Expand Down

0 comments on commit 2e76a86

Please sign in to comment.