Fix pattern matching in .vscodeignore
This commit is contained in:
parent
b48f1603f7
commit
58c7d55d61
5 changed files with 61 additions and 5 deletions
|
@ -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'));
|
||||
|
|
|
@ -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)))
|
||||
|
|
8
src/test/fixtures/vscodeignore/.vscodeignore
vendored
Normal file
8
src/test/fixtures/vscodeignore/.vscodeignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# pattern of dotted directory without backslash
|
||||
.vscode
|
||||
|
||||
# pattern of directory with trailing backslash
|
||||
out/
|
||||
|
||||
# pattern of file name
|
||||
*.log
|
6
src/test/fixtures/vscodeignore/package.json
vendored
Normal file
6
src/test/fixtures/vscodeignore/package.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "uuid",
|
||||
"publisher": "joaomoreno",
|
||||
"version": "1.0.0",
|
||||
"engines": { "vscode": "*" }
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue