fix(providence-analytics): from-import-to-export without fs lookup
This commit is contained in:
parent
d7f0807903
commit
7d1bde66c4
2 changed files with 36 additions and 16 deletions
|
|
@ -49,17 +49,21 @@ 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' ?
|
||||
const pathToCheck = pathLib.resolve(externalRootPath, `./${localPath}`);
|
||||
if (externalRootPath) {
|
||||
const pathToCheck = pathLib.resolve(externalRootPath, `./${localPath}`);
|
||||
|
||||
if (fs.existsSync(pathToCheck)) {
|
||||
const stat = fs.statSync(pathToCheck);
|
||||
if (stat && stat.isFile()) {
|
||||
return `./${localPath}`; // '/path/to/lion-based-ui/fol.der' is a file
|
||||
if (fs.existsSync(pathToCheck)) {
|
||||
const stat = fs.statSync(pathToCheck);
|
||||
if (stat && stat.isFile()) {
|
||||
return `./${localPath}`; // '/path/to/lion-based-ui/fol.der' is a file
|
||||
}
|
||||
return `./${localPath}/index.js`; // '/path/to/lion-based-ui/fol.der' is a folder
|
||||
// eslint-disable-next-line no-else-return
|
||||
} 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'
|
||||
}
|
||||
return `./${localPath}/index.js`; // '/path/to/lion-based-ui/fol.der' is a folder
|
||||
// eslint-disable-next-line no-else-return
|
||||
} 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'
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
requestedExternalSource: importEntryResult.normalizedSource,
|
||||
externalProjectMeta: exportsProjectObj,
|
||||
externalRootPath: cfg.referenceProjectPath,
|
||||
});
|
||||
const fromImportToExport = fromImportToExportPerspective({
|
||||
requestedExternalSource: importEntryResult.normalizedSource,
|
||||
externalProjectMeta: exportsProjectObj,
|
||||
externalRootPath: cfg.referenceProjectResult ? null : cfg.referenceProjectPath,
|
||||
});
|
||||
const isFromSameSource = compareImportAndExportPaths(
|
||||
exportEntry.file,
|
||||
fromImportToExport,
|
||||
);
|
||||
|
||||
if (!isFromSameSource) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue