feat(providence): do not throw on unparseable files, but allow to proceed run for rest of projects

This commit is contained in:
Thijs Louisse 2023-11-29 12:36:01 +01:00 committed by Thijs Louisse
parent 244bdf7f53
commit 7f6eb15a21
4 changed files with 28 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'providence-analytics': patch
---
feat: allow to resolve outside node_modules as well

View file

@ -0,0 +1,5 @@
---
'providence-analytics': patch
---
feat: do not throw on unparseable files, but allow to proceed run for rest of projects

View file

@ -0,0 +1,5 @@
---
'providence-analytics': patch
---
fix: swc-traverse does not fail on object proto builtins like "toString"

View file

@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
import semver from 'semver';
import pathLib from 'path';
import path from 'path';
import { LogService } from './LogService.js';
import { QueryService } from './QueryService.js';
import { ReportService } from './ReportService.js';
@ -33,9 +33,17 @@ async function analyzePerAstFile(projectData, astAnalysis, analyzerCfg) {
for (const { file, ast, context: astContext } of projectData.entries) {
const relativePath = getFilePathRelativeFromRoot(file, projectData.project.path);
const context = { code: astContext.code, relativePath, projectData, analyzerCfg };
LogService.debug(`${pathLib.resolve(projectData.project.path, file)}`);
const fullPath = path.resolve(projectData.project.path, file);
LogService.debug(`[analyzePerAstFile]: ${fullPath}`);
// We do a try and catch here, so that unparseable files do not block all metrics we're gathering in a run
try {
const { result, meta } = await astAnalysis(ast, context);
entries.push({ file: relativePath, meta, result });
} catch (e) {
LogService.error(`[analyzePerAstFile]: ${fullPath} throws: ${e}`);
}
}
const filteredEntries = entries.filter(({ result }) => Boolean(result.length));
return filteredEntries;
@ -137,15 +145,14 @@ const checkForMatchCompatibility = (
/** @type {PathFromSystemRoot} */ referencePath,
/** @type {PathFromSystemRoot} */ targetPath,
) => {
// const refFile = pathLib.resolve(referencePath, 'package.json');
const referencePkg = InputDataService.getPackageJson(referencePath);
// const targetFile = pathLib.resolve(targetPath, 'package.json');
const targetPkg = InputDataService.getPackageJson(targetPath);
const allTargetDeps = [
...Object.entries(targetPkg?.devDependencies || {}),
...Object.entries(targetPkg?.dependencies || {}),
];
const importEntry = allTargetDeps.find(([name]) => referencePkg?.name === name);
if (!importEntry) {
return { compatible: false, reason: 'no-dependency' };