Merge pull request #824 from ing-bank/feat/providenceMatchImportsSupplyPrevResults
Feat/providence match imports supply prev results
This commit is contained in:
commit
872c028f47
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}`);
|
LogService.info(`starting ${LogService.pad(this.name, 16)} for ${this.identifier}`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get reference and search-target data
|
* Get reference and search-target data
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -201,11 +201,15 @@ class MatchImportsAnalyzer extends Analyzer {
|
||||||
* @property {GatherFilesConfig} [gatherFilesConfig]
|
* @property {GatherFilesConfig} [gatherFilesConfig]
|
||||||
* @property {array} [referenceProjectPath] reference paths
|
* @property {array} [referenceProjectPath] reference paths
|
||||||
* @property {array} [targetProjectPath] search target paths
|
* @property {array} [targetProjectPath] search target paths
|
||||||
|
* @property {FindExportsAnalyzerResult} [exportsAnalyzerResult]
|
||||||
|
* @property {FindImportsAnalyzerResult} [importsAnalyzerResult]
|
||||||
*/
|
*/
|
||||||
const cfg = {
|
const cfg = {
|
||||||
gatherFilesConfig: {},
|
gatherFilesConfig: {},
|
||||||
referenceProjectPath: null,
|
referenceProjectPath: null,
|
||||||
targetProjectPath: null,
|
targetProjectPath: null,
|
||||||
|
exportsAnalyzerResult: null,
|
||||||
|
importsAnalyzerResult: null,
|
||||||
...customConfig,
|
...customConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -220,16 +224,23 @@ class MatchImportsAnalyzer extends Analyzer {
|
||||||
/**
|
/**
|
||||||
* Traverse
|
* Traverse
|
||||||
*/
|
*/
|
||||||
const findExportsAnalyzer = new FindExportsAnalyzer();
|
let { exportsAnalyzerResult } = cfg;
|
||||||
const exportsAnalyzerResult = await findExportsAnalyzer.execute({
|
if (!exportsAnalyzerResult) {
|
||||||
metaConfig: cfg.metaConfig,
|
const findExportsAnalyzer = new FindExportsAnalyzer();
|
||||||
targetProjectPath: cfg.referenceProjectPath,
|
exportsAnalyzerResult = await findExportsAnalyzer.execute({
|
||||||
});
|
metaConfig: cfg.metaConfig,
|
||||||
const findImportsAnalyzer = new FindImportsAnalyzer();
|
targetProjectPath: cfg.referenceProjectPath,
|
||||||
const importsAnalyzerResult = await findImportsAnalyzer.execute({
|
});
|
||||||
metaConfig: cfg.metaConfig,
|
}
|
||||||
targetProjectPath: cfg.targetProjectPath,
|
|
||||||
});
|
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);
|
const queryOutput = matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerResult, cfg);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ const { expect } = require('chai');
|
||||||
const { providence } = require('../../../src/program/providence.js');
|
const { providence } = require('../../../src/program/providence.js');
|
||||||
const { QueryService } = require('../../../src/program/services/QueryService.js');
|
const { QueryService } = require('../../../src/program/services/QueryService.js');
|
||||||
const { InputDataService } = require('../../../src/program/services/InputDataService.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 {
|
const {
|
||||||
mockTargetAndReferenceProject,
|
mockTargetAndReferenceProject,
|
||||||
restoreMockedProjects,
|
restoreMockedProjects,
|
||||||
|
|
@ -233,6 +236,22 @@ describe('Analyzer "match-imports"', () => {
|
||||||
restoreMockedProjects();
|
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', () => {
|
describe('Extracting exports', () => {
|
||||||
it(`identifies all direct export specifiers consumed by "importing-target-project"`, async () => {
|
it(`identifies all direct export specifiers consumed by "importing-target-project"`, async () => {
|
||||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||||
|
|
@ -276,22 +295,6 @@ describe('Analyzer "match-imports"', () => {
|
||||||
|
|
||||||
describe('Matching', () => {
|
describe('Matching', () => {
|
||||||
it(`produces a list of all matches, sorted by project`, async () => {
|
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);
|
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||||
const queryResult = queryResults[0];
|
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