feat(providence-analytics): supply prev results match-imports
This commit is contained in:
parent
8396888699
commit
e31d1f5150
3 changed files with 66 additions and 27 deletions
|
|
@ -186,7 +186,6 @@ class Analyzer {
|
|||
}
|
||||
|
||||
LogService.info(`starting ${LogService.pad(this.name, 16)} for ${this.identifier}`);
|
||||
|
||||
/**
|
||||
* Get reference and search-target data
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -201,11 +201,15 @@ class MatchImportsAnalyzer extends Analyzer {
|
|||
* @property {GatherFilesConfig} [gatherFilesConfig]
|
||||
* @property {array} [referenceProjectPath] reference paths
|
||||
* @property {array} [targetProjectPath] search target paths
|
||||
* @property {FindExportsAnalyzerResult} [exportsAnalyzerResult]
|
||||
* @property {FindImportsAnalyzerResult} [importsAnalyzerResult]
|
||||
*/
|
||||
const cfg = {
|
||||
gatherFilesConfig: {},
|
||||
referenceProjectPath: null,
|
||||
targetProjectPath: null,
|
||||
exportsAnalyzerResult: null,
|
||||
importsAnalyzerResult: null,
|
||||
...customConfig,
|
||||
};
|
||||
|
||||
|
|
@ -220,16 +224,23 @@ class MatchImportsAnalyzer extends Analyzer {
|
|||
/**
|
||||
* Traverse
|
||||
*/
|
||||
const findExportsAnalyzer = new FindExportsAnalyzer();
|
||||
const exportsAnalyzerResult = await findExportsAnalyzer.execute({
|
||||
metaConfig: cfg.metaConfig,
|
||||
targetProjectPath: cfg.referenceProjectPath,
|
||||
});
|
||||
const findImportsAnalyzer = new FindImportsAnalyzer();
|
||||
const importsAnalyzerResult = await findImportsAnalyzer.execute({
|
||||
metaConfig: cfg.metaConfig,
|
||||
targetProjectPath: cfg.targetProjectPath,
|
||||
});
|
||||
let { exportsAnalyzerResult } = cfg;
|
||||
if (!exportsAnalyzerResult) {
|
||||
const findExportsAnalyzer = new FindExportsAnalyzer();
|
||||
exportsAnalyzerResult = await findExportsAnalyzer.execute({
|
||||
metaConfig: cfg.metaConfig,
|
||||
targetProjectPath: cfg.referenceProjectPath,
|
||||
});
|
||||
}
|
||||
|
||||
let { importsAnalyzerResult } = cfg;
|
||||
if (!importsAnalyzerResult) {
|
||||
const findImportsAnalyzer = new FindImportsAnalyzer();
|
||||
importsAnalyzerResult = await findImportsAnalyzer.execute({
|
||||
metaConfig: cfg.metaConfig,
|
||||
targetProjectPath: cfg.targetProjectPath,
|
||||
});
|
||||
}
|
||||
|
||||
const queryOutput = matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerResult, cfg);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ const { expect } = require('chai');
|
|||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/services/QueryService.js');
|
||||
const { InputDataService } = require('../../../src/program/services/InputDataService.js');
|
||||
const FindExportsAnalyzer = require('../../../src/program/analyzers/find-exports.js');
|
||||
const FindImportsAnalyzer = require('../../../src/program/analyzers/find-imports.js');
|
||||
|
||||
const {
|
||||
mockTargetAndReferenceProject,
|
||||
restoreMockedProjects,
|
||||
|
|
@ -233,6 +236,22 @@ describe('Analyzer "match-imports"', () => {
|
|||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
function testMatchedEntry(targetExportedId, queryResult, importedByFiles = []) {
|
||||
const matchedEntry = queryResult.queryOutput.find(
|
||||
r => r.exportSpecifier.id === targetExportedId,
|
||||
);
|
||||
|
||||
const [name, filePath, project] = targetExportedId.split('::');
|
||||
expect(matchedEntry.exportSpecifier).to.eql({
|
||||
name,
|
||||
filePath,
|
||||
project,
|
||||
id: targetExportedId,
|
||||
});
|
||||
expect(matchedEntry.matchesPerProject[0].project).to.equal('importing-target-project');
|
||||
expect(matchedEntry.matchesPerProject[0].files).to.eql(importedByFiles);
|
||||
}
|
||||
|
||||
describe('Extracting exports', () => {
|
||||
it(`identifies all direct export specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
|
|
@ -276,22 +295,6 @@ describe('Analyzer "match-imports"', () => {
|
|||
|
||||
describe('Matching', () => {
|
||||
it(`produces a list of all matches, sorted by project`, async () => {
|
||||
function testMatchedEntry(targetExportedId, queryResult, importedByFiles = []) {
|
||||
const matchedEntry = queryResult.queryOutput.find(
|
||||
r => r.exportSpecifier.id === targetExportedId,
|
||||
);
|
||||
|
||||
const [name, filePath, project] = targetExportedId.split('::');
|
||||
expect(matchedEntry.exportSpecifier).to.eql({
|
||||
name,
|
||||
filePath,
|
||||
project,
|
||||
id: targetExportedId,
|
||||
});
|
||||
expect(matchedEntry.matchesPerProject[0].project).to.equal('importing-target-project');
|
||||
expect(matchedEntry.matchesPerProject[0].files).to.eql(importedByFiles);
|
||||
}
|
||||
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
|
@ -305,4 +308,30 @@ describe('Analyzer "match-imports"', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Configuration', () => {
|
||||
it(`allows to provide results of FindExportsAnalyzer and FindImportsAnalyzer`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
const importsAnalyzerResult = await new FindImportsAnalyzer().execute({
|
||||
targetProjectPath: searchTargetProject.path,
|
||||
});
|
||||
const exportsAnalyzerResult = await new FindExportsAnalyzer().execute({
|
||||
targetProjectPath: referenceProject.path,
|
||||
});
|
||||
await providence(matchImportsQueryConfig, {
|
||||
..._providenceCfg,
|
||||
importsAnalyzerResult,
|
||||
exportsAnalyzerResult,
|
||||
});
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
expectedExportIdsDirect.forEach(targetId => {
|
||||
testMatchedEntry(targetId, queryResult, ['./target-src/direct-imports.js']);
|
||||
});
|
||||
|
||||
expectedExportIdsIndirect.forEach(targetId => {
|
||||
testMatchedEntry(targetId, queryResult, ['./target-src/indirect-imports.js']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue