fix(providence-analytics): from-import-to-export without fs lookup

This commit is contained in:
Thijs Louisse 2020-08-06 00:31:37 +02:00
parent d7f0807903
commit 7d1bde66c4
2 changed files with 36 additions and 16 deletions

View file

@ -49,6 +49,7 @@ function fromImportToExportPerspective({
// we still need to check if we're not dealing with a folder.
// - '@open-wc/x/y.js' -> '@open-wc/x/y.js' or... '@open-wc/x/y.js/index.js' ?
// - or 'lion-based-ui/test' -> 'lion-based-ui/test/index.js' or 'lion-based-ui/test' ?
if (externalRootPath) {
const pathToCheck = pathLib.resolve(externalRootPath, `./${localPath}`);
if (fs.existsSync(pathToCheck)) {
@ -61,6 +62,9 @@ function fromImportToExportPerspective({
} else if (fs.existsSync(`${pathToCheck}.js`)) {
return `./${localPath}.js`; // '/path/to/lion-based-ui/fol.der' is file '/path/to/lion-based-ui/fol.der.js'
}
} else {
return `./${localPath}`;
}
} else {
// like '@lion/core'
let mainEntry = externalProjectMeta.mainEntry || 'index.js';

View file

@ -19,6 +19,20 @@ function storeResult(resultsObj, exportId, filteredList, meta) {
resultsObj[exportId].files = [...(resultsObj[exportId].files || []), ...Array.from(filteredList)];
}
/**
* Needed in case fromImportToExportPerspective does not have a
* externalRootPath supplied.
* @param {string} exportPath exportEntry.file
* @param {string} translatedImportPath result of fromImportToExportPerspective
*/
function compareImportAndExportPaths(exportPath, translatedImportPath) {
return (
exportPath === translatedImportPath ||
exportPath === `${translatedImportPath}.js` ||
exportPath === `${translatedImportPath}/index.js`
);
}
/**
* @param {FindExportsAnalyzerResult} exportsAnalyzerResult
* @param {FindImportsAnalyzerResult} importsAnalyzerResult
@ -94,13 +108,15 @@ function matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerResult, c
* importFile 'importing-target-project/file.js'
* => import { z } from '@reference/foo.js'
*/
const isFromSameSource =
exportEntry.file ===
fromImportToExportPerspective({
const fromImportToExport = fromImportToExportPerspective({
requestedExternalSource: importEntryResult.normalizedSource,
externalProjectMeta: exportsProjectObj,
externalRootPath: cfg.referenceProjectPath,
externalRootPath: cfg.referenceProjectResult ? null : cfg.referenceProjectPath,
});
const isFromSameSource = compareImportAndExportPaths(
exportEntry.file,
fromImportToExport,
);
if (!isFromSameSource) {
return;