alm
Version:
The best IDE for TypeScript
42 lines (41 loc) • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var fsu_1 = require("../../../utils/fsu");
var path = require("path");
var fs = require("fs");
var fsu_2 = require("../../../utils/fsu");
var astUtils_1 = require("./astUtils");
function getProgramDependencies(projectFile, program) {
var links = [];
var projectDir = projectFile.projectFileDirectory;
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var file = _a[_i];
var filePath = file.fileName;
var dir = path.dirname(filePath);
var targets = astUtils_1.getSourceFileImports(file)
.filter(function (fileReference) { return fsu_2.isRelative(fileReference); })
.map(function (fileReference) {
var file = path.resolve(dir, fileReference + '.ts');
if (!fs.existsSync(file)) {
file = path.resolve(dir, fileReference + '.tsx');
}
if (!fs.existsSync(file)) {
/** Do not resolve to a `.d.ts` file as it makes no sense to analyze those */
return null;
}
return file;
})
.filter(function (x) { return !!x; });
for (var _b = 0, targets_1 = targets; _b < targets_1.length; _b++) {
var target = targets_1[_b];
var targetPath = fsu_1.consistentPath(path.relative(projectDir, fsu_1.consistentPath(target)));
var sourcePath = fsu_1.consistentPath(path.relative(projectDir, filePath));
links.push({
sourcePath: sourcePath,
targetPath: targetPath
});
}
}
return links;
}
exports.getProgramDependencies = getProgramDependencies;