@jqassistant/ts-lce
Version:
Tool to extract language concepts from a TypeScript codebase and export them to a JSON file.
44 lines (43 loc) • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExternalDependenciesPostProcessor = void 0;
const post_processor_1 = require("../post-processor");
const dependency_concept_1 = require("../concepts/dependency.concept");
const externals_concept_1 = require("../concepts/externals.concept");
const modulepath_utils_1 = require("../utils/modulepath.utils");
class ExternalDependenciesPostProcessor extends post_processor_1.PostProcessor {
postProcess(projects) {
for (const project of projects) {
const concepts = project.concepts;
const allDependencies = (concepts.get(dependency_concept_1.LCEDependency.conceptId) ?? []);
const externalModules = new Map();
const externalDeclarations = new Map();
for (const dep of allDependencies) {
const external = modulepath_utils_1.ModulePathUtils.isExternal(dep.targetType === "module" ? dep.globalSourceFQN : modulepath_utils_1.ModulePathUtils.extractFQNPath(dep.fqn.globalFqn), project.projectInfo, projects);
if (external) {
if (dep.targetType === "declaration") {
const modulePath = modulepath_utils_1.ModulePathUtils.extractFQNPath(dep.fqn.globalFqn);
if (!externalModules.has(modulePath)) {
externalModules.set(modulePath, new externals_concept_1.LCEExternalModule(modulePath, []));
externalDeclarations.set(modulePath, new Map());
}
if (!externalDeclarations.get(modulePath).has(dep.fqn.globalFqn)) {
externalDeclarations
.get(modulePath)
.set(dep.fqn.globalFqn, new externals_concept_1.LCEExternalDeclaration(dep.fqn.globalFqn, modulepath_utils_1.ModulePathUtils.extractFQNIdentifier(dep.fqn.globalFqn)));
}
}
else if (!externalModules.has(dep.fqn.globalFqn)) {
externalModules.set(dep.fqn.globalFqn, new externals_concept_1.LCEExternalModule(dep.fqn.globalFqn, []));
externalDeclarations.set(dep.fqn.globalFqn, new Map());
}
}
}
for (const entry of externalDeclarations.entries()) {
externalModules.get(entry[0]).declarations = [...entry[1].values()];
}
concepts.set(externals_concept_1.LCEExternalModule.conceptId, [...externalModules.values()]);
}
}
}
exports.ExternalDependenciesPostProcessor = ExternalDependenciesPostProcessor;