Skip to content

Commit

Permalink
Merge pull request #825 from MoralisWeb3/fix/find-missing-deps
Browse files Browse the repository at this point in the history
Fix: findMissingDependencies script
  • Loading branch information
Y0moo authored Nov 17, 2022
2 parents 21c34b1 + 6b81693 commit 324a1eb
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions scripts/findMissingDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const PACKAGE_DIR_PATHS = ['packages', 'packages/common', 'packages/client'];

const SKIP_DIRECTORIES = ['lib', 'integration', 'node_modules'];

const IGNORE_DEPENDENCIES = ['parse/node'];

function findPackages(dirPath) {
const result = [];
fs.readdirSync(dirPath).forEach((fileName) => {
Expand Down Expand Up @@ -51,19 +49,37 @@ function readTsFilesExternalImports(filePaths) {
return [...imports];
}

function readImports(tsFilePaths) {
return readTsFilesExternalImports(tsFilePaths).map((imp) => {
const hasSlash = imp.includes('/');
if (!hasSlash) {
return imp;
}
const nameParts = imp.split('/');
const isScopePackage = imp.includes('@');

if (isScopePackage) {
return `${nameParts[0]}/${nameParts[1]}`;
}

return nameParts[0];
});
}

function findPackageMissingDependencies(packageDirPath) {
const packageJsonPath = path.join(packageDirPath, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
if (packageJson.private) {
return null;
}
const packageDependencies = Object.keys(packageJson.dependencies || {});
const packageDependencies = { ...(packageJson?.dependencies || {}), ...(packageJson?.devDependencies || {}) };
const dependenciesList = Object.keys(packageDependencies || {});

const tsFilePaths = findFilesWithExt(packageDirPath, '.ts', '.test.ts', SKIP_DIRECTORIES);
const imports = readTsFilesExternalImports(tsFilePaths);
const imports = readImports(tsFilePaths);

const missing = imports.reduce((result, imp) => {
if (!packageDependencies.includes(imp) && !IGNORE_DEPENDENCIES.includes(imp)) {
if (!dependenciesList.includes(imp)) {
result.push(imp);
}
return result;
Expand All @@ -75,6 +91,7 @@ const repositoryPath = path.resolve(__dirname, '..');
const allPackagePaths = PACKAGE_DIR_PATHS.map((p) => path.join(repositoryPath, p))
.map(findPackages)
.flat();

let exitCode = 0;

for (const packagePath of allPackagePaths) {
Expand Down

1 comment on commit 324a1eb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 24%
25.68% (47/183) 19.56% (9/46) 22.85% (8/35)
auth Coverage: 94%
95.38% (124/130) 81.81% (18/22) 95.45% (42/44)
evm-api Coverage: 97%
97.46% (77/79) 66.66% (6/9) 95.74% (45/47)
common-evm-utils Coverage: 64%
65% (938/1443) 19.93% (123/617) 35.89% (201/560)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
73.77% (135/183) 60% (12/20) 65.67% (44/67)
common-streams-utils Coverage: 95%
95.6% (674/705) 97.93% (190/194) 100% (244/244)
streams Coverage: 87%
87.64% (525/599) 68.26% (71/104) 84.52% (142/168)

Please sign in to comment.