From 617b59756fcf5a091ac8346ce879bb68bc85dc5f Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Tue, 13 Aug 2019 21:40:52 +0200 Subject: [PATCH] allow glob patterns for --project Fixes: #646 --- packages/wotan/src/runner.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/wotan/src/runner.ts b/packages/wotan/src/runner.ts index 6bb085479..3df6305f5 100644 --- a/packages/wotan/src/runner.ts +++ b/packages/wotan/src/runner.ts @@ -244,7 +244,7 @@ export class Runner { ): Iterable<{files: Iterable, program: ts.Program}> { const cwd = unixifyPath(this.directories.getCurrentDirectory()); if (projects.length !== 0) { - projects = projects.map((configFile) => this.checkConfigDirectory(unixifyPath(path.resolve(cwd, configFile)))); + projects = this.matchProjectGlobs(projects); } else if (references) { projects = [this.checkConfigDirectory(cwd)]; } else { @@ -302,6 +302,37 @@ export class Runner { } } + private matchProjectGlobs(projects: ReadonlyArray) { + const cwd = this.directories.getCurrentDirectory(); + const result = []; + const globOptions: glob.IOptions = { + cwd, + nobrace: true, // braces are already expanded + cache: {}, + realpathCache: {}, + statCache: {}, + symlinks: {}, + }; + for (const project of projects) { + if (!glob.hasMagic(project)) { + result.push(this.checkConfigDirectory(unixifyPath(path.resolve(cwd, project)))); + } else { + let matched = false; + for (const pattern of normalizeGlob(project, cwd)) { + log("globbing project pattern '%s'", pattern); + for (const match of glob.sync(pattern, globOptions)) { + matched = true; + result.push(this.checkConfigDirectory(unixifyPath(match))); + } + } + if (!matched) + throw new ConfigurationError(`The specified pattern does not match any file: '${project}'`); + } + + } + return result; + } + private checkConfigDirectory(fileOrDirName: string): string { switch (this.fs.getKind(fileOrDirName)) { case FileKind.NonExistent: