Fix pattern matching in .vscodeignore

This commit is contained in:
JimiC 2018-07-03 17:19:18 +03:00
parent b48f1603f7
commit 58c7d55d61
5 changed files with 61 additions and 5 deletions

View file

@ -34,8 +34,8 @@ function compile() {
const api = ts.dts
.pipe(filter('**/api.d.ts'));
const resources = gulp.src('src/**')
.pipe(filter(['**', '!**/*.ts']));
const resources = gulp.src('src/**', { dot: true })
.pipe(filter(['**', '!**/*.ts'], { dot: true }));
return es.merge(js, api, resources)
.pipe(gulp.dest('out'));
@ -54,7 +54,7 @@ gulp.task('test', ['compile'], test);
gulp.task('just-test', ['just-compile'], test);
function watch(task) {
return cb => gulp.watch(['src/**', 'typings/**'], [task]);
return () => gulp.watch(['src/**', 'typings/**'], [task]);
}
gulp.task('watch', ['compile'], watch('just-compile'));

View file

@ -26,12 +26,13 @@ const readFile = denodeify<string, string, string>(fs.readFile);
const unlink = denodeify<string, void>(fs.unlink as any);
const exec = denodeify<string, { cwd?: string; env?: any; }, { stdout: string; stderr: string; }>(cp.exec as any, (err, stdout, stderr) => [err, { stdout, stderr }]);
const glob = denodeify<string, _glob.Options, string[]>(_glob);
const lstat = denodeify<string, fs.Stats>(fs.lstat);
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 = { dot: true };
const MinimatchOptions: minimatch.Options = { dot: true };
export interface IFile {
path: string;
@ -701,7 +702,15 @@ function collectFiles(cwd: string, useYarn = false): Promise<string[]> {
return readFile(path.join(cwd, '.vscodeignore'), 'utf8')
.catch<string>(err => err.code !== 'ENOENT' ? Promise.reject(err) : Promise.resolve(''))
.then(rawIgnore => rawIgnore.split(/[\n\r]/).map(s => s.trim()).filter(s => !!s))
.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<fs.Stats>(() => Promise.resolve())
.then(stat => stat && stat.isDirectory() ? `${i}/**` : i);
});
return Promise.all(promises).then<string[]>(i => Promise.resolve(i));
})
.then(ignore => [...defaultIgnore, ...ignore, '!package.json'])
.then(ignore => ignore.filter(i => !/^\s*#/.test(i)))
.then(ignore => _.partition(ignore, i => !/^\s*!/.test(i)))

View file

@ -0,0 +1,8 @@
# pattern of dotted directory without backslash
.vscode
# pattern of directory with trailing backslash
out/
# pattern of file name
*.log

View file

@ -0,0 +1,6 @@
{
"name": "uuid",
"publisher": "joaomoreno",
"version": "1.0.0",
"engines": { "vscode": "*" }
}

View file

@ -135,6 +135,39 @@ describe('collect', function () {
});
});
it('should ignore content of .vscodeignore', () => {
const cwd = fixture('vscodeignore');
// pattern of dotted directory name without backslash
if (!fs.existsSync(path.join(cwd, '.vscode'))) {
fs.mkdirSync(path.join(cwd, '.vscode'));
}
if (!fs.existsSync(path.join(cwd, '.vscode', 'tasks.json'))) {
fs.writeFileSync(path.join(cwd, '.vscode', 'tasks.json'), 'tasks');
}
// pattern of directory name with trailing backslash
if (!fs.existsSync(path.join(cwd, 'out'))) {
fs.mkdirSync(path.join(cwd, 'out'));
}
if (!fs.existsSync(path.join(cwd, 'out', 'hello'))) {
fs.writeFileSync(path.join(cwd, 'out', 'hello'), 'world');
}
// pattern of file name
if (!fs.existsSync(path.join(cwd, 'logger.log'))) {
fs.writeFileSync(path.join(cwd, 'logger.log'), 'log');
}
return readManifest(cwd)
.then(manifest => collect(manifest, { cwd }))
.then(files => {
assert.equal(files.length, 3);
});
});
it('should ignore devDependencies', () => {
const cwd = fixture('devDependencies');
return readManifest(cwd)