1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.DefaultFileFilterFactory = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const inversify_1 = require("inversify");
|
6 | const ts = require("typescript");
|
7 | const utils_1 = require("../../utils");
|
8 | const path = require("path");
|
9 | let DefaultFileFilterFactory = class DefaultFileFilterFactory {
|
10 | create(context) {
|
11 | return new DefaultFileFilter(context.program, context.host);
|
12 | }
|
13 | };
|
14 | DefaultFileFilterFactory = tslib_1.__decorate([
|
15 | inversify_1.injectable()
|
16 | ], DefaultFileFilterFactory);
|
17 | exports.DefaultFileFilterFactory = DefaultFileFilterFactory;
|
18 | class 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 |
|
40 | fileName.startsWith(this.libDirectory) ||
|
41 |
|
42 | fileName.endsWith('/node_modules/tslib/tslib.d.ts'))
|
43 | return false;
|
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 |
|
\ | No newline at end of file |