Skip to content

Commit

Permalink
missing dependencies validator. (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Nov 10, 2022
1 parent e14fba8 commit 51d7b9d
Show file tree
Hide file tree
Showing 12 changed files with 533 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,5 @@ jobs:
common-sol-utils, ./packages/common/solUtils/coverage/coverage-summary.json
common-streams-utils, ./packages/common/streamsUtils/coverage/coverage-summary.json
streams, ./packages/streams/coverage/coverage-summary.json
- name: Find missing dependencies
run: node scripts/findMissingDependencies.js
4 changes: 3 additions & 1 deletion packages/apiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@moralisweb3/common-evm-utils": "^2.6.7"
},
"dependencies": {
"@moralisweb3/common-core": "^2.6.7"
"@moralisweb3/common-core": "^2.6.7",
"@moralisweb3/common-evm-utils": "^2.6.7",
"axios": "^0.27.2"
}
}
3 changes: 2 additions & 1 deletion packages/client/firebaseApiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"typescript": "^4.5.5"
},
"dependencies": {
"firebase": "^9.10.0",
"firebase": "^9.13.0",
"@firebase/functions": "^0.8.8",
"@moralisweb3/common-core": "^2.6.7",
"@moralisweb3/client-api-utils": "^2.6.7"
}
Expand Down
5 changes: 4 additions & 1 deletion packages/client/firebaseAuthUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"typescript": "^4.5.5"
},
"dependencies": {
"firebase": "^9.10.0"
"firebase": "^9.13.0",
"@firebase/functions": "^0.8.8",
"@firebase/app": "^0.8.3",
"@firebase/auth": "^0.20.11"
}
}
7 changes: 5 additions & 2 deletions packages/client/firebaseEvmApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"typescript": "^4.5.5"
},
"dependencies": {
"firebase": "^9.10.0",
"firebase": "^9.13.0",
"@firebase/app": "^0.8.3",
"@firebase/functions": "^0.8.8",
"@moralisweb3/common-core": "^2.6.7",
"@moralisweb3/common-evm-utils": "^2.6.7",
"@moralisweb3/client-evm-api": "^2.6.7"
"@moralisweb3/client-evm-api": "^2.6.7",
"@moralisweb3/client-firebase-api-utils": "^2.6.7"
}
}
1 change: 1 addition & 0 deletions packages/client/firebaseEvmAuth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"dependencies": {
"firebase": "^9.10.0",
"@firebase/auth": "^0.20.11",
"@moralisweb3/client-firebase-auth-utils": "^2.6.7",
"@ethersproject/providers": "^5.7.1",
"@metamask/detect-provider": "^1.2.0"
Expand Down
5 changes: 4 additions & 1 deletion packages/client/firebaseSolApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
},
"dependencies": {
"firebase": "^9.10.0",
"@firebase/functions": "^0.8.8",
"@firebase/app": "^0.8.3",
"@moralisweb3/common-core": "^2.6.7",
"@moralisweb3/common-sol-utils": "^2.6.7",
"@moralisweb3/client-sol-api": "^2.6.7"
"@moralisweb3/client-sol-api": "^2.6.7",
"@moralisweb3/client-firebase-api-utils": "^2.6.7"
}
}
1 change: 1 addition & 0 deletions packages/client/firebaseSolAuth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"dependencies": {
"firebase": "^9.10.0",
"@firebase/auth": "^0.20.11",
"@moralisweb3/client-firebase-auth-utils": "^2.6.7",
"bs58": "^5.0.0"
}
Expand Down
1 change: 1 addition & 0 deletions packages/common/evmUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@ethersproject/address": "^5.6.0",
"@ethersproject/transactions": "^5.6.0",
"@ethersproject/bytes": "^5.6.0",
"@moralisweb3/common-core": "^2.6.7"
}
}
3 changes: 2 additions & 1 deletion packages/common/streamsUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@moralisweb3/common-core": "^2.6.5",
"@moralisweb3/common-evm-utils": "^2.6.5"
"@moralisweb3/common-evm-utils": "^2.6.5",
"@moralisweb3/streams-typings": "^1.0.5"
}
}
87 changes: 87 additions & 0 deletions scripts/findMissingDependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const fs = require('fs');
const path = require('path');
const ts = require('typescript');

const PACKAGE_DIR_PATHS = ['../packages', '../packages/common', '../packages/client'];

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

function findPackages(dirPath) {
const result = [];
fs.readdirSync(dirPath).forEach((fileName) => {
const filePath = path.join(dirPath, fileName);
const packagePath = path.join(filePath, 'package.json');
if (fs.statSync(filePath).isDirectory() && fs.existsSync(packagePath)) {
result.push(filePath);
}
});
return result;
}

function findFilesWithExt(rootDirPath, ext, ignoreExt, ignoredDirectoryNames) {
const result = [];
function iterate(dirPath) {
fs.readdirSync(dirPath).forEach((fileName) => {
const filePath = path.join(dirPath, fileName);
if (fs.statSync(filePath).isDirectory() && !ignoredDirectoryNames.includes(fileName)) {
iterate(filePath);
} else if (fileName.endsWith(ext) && !fileName.endsWith(ignoreExt)) {
result.push(filePath);
}
});
}
iterate(rootDirPath);
return result;
}

function readTsFilesExternalImports(filePaths) {
const imports = new Set();
const program = ts.createProgram(filePaths, {});
for (const tsFilePath of filePaths) {
const sourceFile = program.getSourceFile(tsFilePath);
for (const imp of sourceFile.imports) {
const importPath = imp.text;
if (!importPath.startsWith('../') && !importPath.startsWith('./')) {
imports.add(importPath);
}
}
}
return [...imports];
}

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

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

return imports.reduce((result, imp) => {
if (!packageDependencies.includes(imp)) {
result.push(imp);
}
return result;
}, []);
}

const allPackagePaths = PACKAGE_DIR_PATHS.map((p) => path.join(__dirname, p))
.map(findPackages)
.flat();
let exitCode = 0;

for (const packagePath of allPackagePaths) {
const packageName = packagePath;
const missingDependencies = findPackageMissingDependencies(packagePath);
if (missingDependencies.length > 0) {
console.log(`❌ Package ${packageName} has missing dependencies:\n* ${missingDependencies.join('\n* ')}\n`);
exitCode = 1;
} else {
console.log(`✅ Package ${packageName} is valid`);
}
}

process.exit(exitCode);
Loading

1 comment on commit 51d7b9d

@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: 56%
56.43% (263/466) 43.85% (50/114) 57.73% (56/97)
auth Coverage: 100%
100% (143/143) 90.9% (20/22) 100% (42/42)
evm-api Coverage: 92%
92.72% (51/55) 66.66% (4/6) 81.25% (13/16)
common-evm-utils Coverage: 64%
65.02% (939/1444) 20.19% (123/609) 35.89% (201/560)
sol-api Coverage: 100%
100% (20/20) 66.66% (4/6) 100% (6/6)
common-sol-utils Coverage: 75%
74.86% (134/179) 63.15% (12/19) 65.67% (44/67)
common-streams-utils Coverage: 95%
95.6% (674/705) 97.93% (190/194) 100% (244/244)
streams Coverage: 82%
82.72% (388/469) 64% (64/100) 73.6% (92/125)

Please sign in to comment.