Skip to content

Commit

Permalink
feat(providence): do not throw on unparseable files, but allow to pro…
Browse files Browse the repository at this point in the history
…ceed run for rest of projects
  • Loading branch information
tlouisse committed Nov 30, 2023
1 parent 244bdf7 commit 7f6eb15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-gifts-reflect copy 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'providence-analytics': patch
---

feat: allow to resolve outside node_modules as well
5 changes: 5 additions & 0 deletions .changeset/big-gifts-reflect copy 3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'providence-analytics': patch
---

feat: do not throw on unparseable files, but allow to proceed run for rest of projects
5 changes: 5 additions & 0 deletions .changeset/big-gifts-reflect copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'providence-analytics': patch
---

fix: swc-traverse does not fail on object proto builtins like "toString"
19 changes: 13 additions & 6 deletions packages-node/providence-analytics/src/program/core/Analyzer.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 { result, meta } = await astAnalysis(ast, context);
entries.push({ file: relativePath, meta, result });

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;
Expand Down Expand Up @@ -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' };
Expand Down

0 comments on commit 7f6eb15

Please sign in to comment.