Skip to content

Enable loader to exclude files matching regex for error checks #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface LoaderOptions {
compiler: string;
configFileName: string;
transpileOnly: boolean;
excludeErrorCheck: RegExp | Array<RegExp>;
ignoreDiagnostics: number[];
compilerOptions: typescript.CompilerOptions;
}
Expand Down Expand Up @@ -397,9 +398,9 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {

resolvedModules.push(resolutionResult);
}

instance.dependencyGraph[containingFile] = resolvedModules.filter(m => m != null).map(m => m.resolvedFileName);

return resolvedModules;
}
};
Expand All @@ -414,7 +415,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
callback();
return;
}

let stats = compilation.stats;

// handle all other errors. The basic approach here to get accurate error
Expand Down Expand Up @@ -462,9 +463,26 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
}
})

let tsRegex: RegExp = /(\.d)?\.ts(x?)$/;
function filterFiles(filePath) {
// Filters files we don't want to catch errors from TypeScript
if (loaderOptions.excludeErrorCheck) {
if (loaderOptions.excludeErrorCheck.constructor === RegExp) {
// Filter if matches regexp
if (!!filePath.match(loaderOptions.excludeErrorCheck)) { return false; }
} else if (loaderOptions.excludeErrorCheck.constructor === Array) {
// Filter if matches any of the regexps
for (let excludeRegexp of (loaderOptions.excludeErrorCheck as Array<RegExp>)) {
if (!!filePath.match(excludeRegexp)) { return false; }
}
}
}
return !!filePath.match(tsRegex);
}

// gather all errors from TypeScript and output them to webpack
Object.keys(instance.files)
.filter(filePath => !!filePath.match(/(\.d)?\.ts(x?)$/))
.filter(filterFiles)
.forEach(filePath => {
let errors = languageService.getSyntacticDiagnostics(filePath).concat(languageService.getSemanticDiagnostics(filePath));

Expand Down Expand Up @@ -590,7 +608,7 @@ function loader(contents) {

// Emit Javascript
var output = langService.getEmitOutput(filePath);

// Make this file dependent on *all* definition files in the program
this.clearDependencies();
this.addDependency(filePath);
Expand All @@ -601,9 +619,9 @@ function loader(contents) {
// Additionally make this file dependent on all imported files
let additionalDependencies = instance.dependencyGraph[filePath];
if (additionalDependencies) {
additionalDependencies.forEach(this.addDependency.bind(this))
additionalDependencies.forEach(this.addDependency.bind(this))
}

this._module.meta.tsLoaderDefinitionFileVersions = allDefinitionFiles
.concat(additionalDependencies)
.map(filePath => filePath+'@'+(instance.files[filePath] || {version: '?'}).version);
Expand Down