UNPKG

2.74 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.DefaultFileFilterFactory = void 0;
4const tslib_1 = require("tslib");
5const inversify_1 = require("inversify");
6const ts = require("typescript");
7const utils_1 = require("../../utils");
8const path = require("path");
9let DefaultFileFilterFactory = class DefaultFileFilterFactory {
10 create(context) {
11 return new DefaultFileFilter(context.program, context.host);
12 }
13};
14DefaultFileFilterFactory = tslib_1.__decorate([
15 inversify_1.injectable()
16], DefaultFileFilterFactory);
17exports.DefaultFileFilterFactory = DefaultFileFilterFactory;
18class DefaultFileFilter {
19 constructor(program, host) {
20 this.program = program;
21 this.host = host;
22 this.rootNames = this.program.getRootFileNames();
23 this.options = this.program.getCompilerOptions();
24 this.libDirectory = utils_1.unixifyPath(path.dirname(ts.getDefaultLibFilePath(this.options))) + '/';
25 this.typeRoots = undefined;
26 this.outputsOfReferencedProjects = undefined;
27 }
28 filter(file) {
29 const { fileName } = file;
30 if (fileName.endsWith('.json'))
31 return false;
32 if (this.options.composite)
33 return this.rootNames.includes(fileName);
34 if (this.program.isSourceFileFromExternalLibrary(file))
35 return false;
36 if (!fileName.endsWith('.d.ts'))
37 return true;
38 if (
39 // lib.xxx.d.ts
40 fileName.startsWith(this.libDirectory) ||
41 // tslib implicitly gets added while linting a project where a dependency in node_modules contains typescript files
42 fileName.endsWith('/node_modules/tslib/tslib.d.ts'))
43 return false; // lib.xxx.d.ts
44 return !this.isInTypeRoot(fileName) && !this.isOutputOfReferencedProject(fileName);
45 }
46 isInTypeRoot(fileName) {
47 if (this.typeRoots === undefined)
48 this.typeRoots = ts.getEffectiveTypeRoots(this.options, {
49 directoryExists: (dir) => this.host.directoryExists(dir),
50 getCurrentDirectory: () => this.program.getCurrentDirectory(),
51 }) || utils_1.emptyArray;
52 return !this.typeRoots.every((typeRoot) => path.relative(typeRoot, fileName).startsWith('..' + path.sep));
53 }
54 isOutputOfReferencedProject(fileName) {
55 var _a;
56 (_a = this.outputsOfReferencedProjects) !== null && _a !== void 0 ? _a : (this.outputsOfReferencedProjects = utils_1.flatMap(utils_1.iterateProjectReferences(this.program.getResolvedProjectReferences()), utils_1.getOutputFileNamesOfProjectReference));
57 return this.outputsOfReferencedProjects.includes(fileName);
58 }
59}
60//# sourceMappingURL=file-filter.js.map
\No newline at end of file