Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael M authored Oct 3, 2021
2 parents a26d19c + eca0274 commit 98c85ed
Show file tree
Hide file tree
Showing 51 changed files with 1,303 additions and 743 deletions.
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@public-js/ng-pkg-keeper",
"version": "1.0.0-beta.3",
"version": "1.0.0",
"description": "Add description",
"scripts": {
"build": "npm run clean:dist && tsc",
Expand All @@ -21,6 +21,7 @@
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.6.0",
"@types/semver": "^6.2.3",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"chai": "^4.2.0",
Expand Down
209 changes: 0 additions & 209 deletions src/analyze.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { analyze } from './analyze';
export { IAnalyzeInput, IPackageInput, IPackage } from './types';
export { analyze } from './lib';
147 changes: 147 additions & 0 deletions src/lib/analyze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { Package } from './models/package';
import { IAnalyzeInput } from './types/analyze-input.interface';
import { checkLocalList, checkVersions } from './utils/check-dependencies';
import { checkImports } from './utils/check-imports';
import { checkPkgVersion } from './utils/check-pkg-version';
import { countImportsHits } from './utils/count-imports-hits';
import { getImportsFromFiles } from './utils/get-imports-from-files';
import { getImportsModelEp } from './utils/get-imports-model-ep';
import { resolveBasePackage } from './utils/resolve-base-package';
import { resolvePackage } from './utils/resolve-package';

export function analyze(params: IAnalyzeInput): Package[] {
const requireRootJson: boolean = params.checkDeps === 'full' || Boolean(params.checkPackageVersion);
const { basePath, packageJson } = resolveBasePackage(params.rootPath, !requireRootJson, true);
const packages: Package[] = params.packagesPaths.map((packagePath) => resolvePackage(packagePath));

packages.forEach((pkg) => {
if (params.countHits || params.checkImports || params.checkDeps) {
pkg.importsModel = getImportsFromFiles(
pkg.packageFilesArr,
params.matchExt || [],
params.ignoreImports || []
);
pkg.secondaryEPsArr.forEach((entryPoint) => {
entryPoint.importsModel = getImportsModelEp(pkg.importsModel, entryPoint.basePath, []);
});
pkg.primaryEP.importsModel = getImportsModelEp(
pkg.importsModel,
pkg.primaryEP.basePath,
pkg.secondaryEPsArr.map((entryPoint) => entryPoint.basePath)
);
}

if (params.countHits) {
const hitsReport: [string, number][] = countImportsHits(
pkg.importsModel.importsUnique,
pkg.importsModel.importsMatched
);
pkg.reports.importsHits = new Map(hitsReport);
}

if (params.checkImports) {
pkg.reports.importsCheck = checkImports(
pkg,
params.bannedImports || [],
params.treatImports || null
);
}

if (params.checkDeps === 'local') {
pkg.reports.depsLocalCheck = checkLocalList(pkg, params.treatDeps || null);
} else if (params.checkDeps === 'full' && packageJson?.version) {
pkg.reports.depsLocalCheck = checkLocalList(pkg, params.treatDeps || null);
pkg.reports.depsFullCheck = checkVersions(pkg, packageJson, params.treatDeps || null);
}

if (params.checkPackageVersion && packageJson?.version) {
pkg.reports.versionCheck = checkPkgVersion(
pkg,
packageJson.version,
params.treatPackageVersion || null
);
}
});

if (params.logToConsole) {
// const replacer = (key: unknown, value: unknown) => {
// if (value instanceof Map) {
// return Array.from(value.entries());
// } else if (value instanceof Set) {
// return Array.from(value);
// } else {
// return value;
// }
// };
// console.log(JSON.stringify(packages, replacer));

packages.forEach((pkg: Package) => {
console.log('\n----------------------------------------------------------------------');
console.log('Package: ' + pkg.packageName);
console.log('Path: ' + pkg.basePath.replace(basePath, ''));
if (params.logStats) {
console.log('------------------------------');
console.log('Total files : ' + pkg.packageFilesArr.length);
console.log('Matched files : ' + pkg.importsModel.filesMatched.length);
console.log('Total imports : ' + pkg.importsModel.importsTotal);
console.log('Matched imports: ' + pkg.importsModel.importsMatched.length);
console.log('Unique imports : ' + pkg.importsModel.importsUnique.length);
}
if (params.countHits) {
console.log('------------------------------');
Array.from(pkg.reports.importsHits.entries()).map(([imp, hits]) => console.log(imp, '–', hits));
}
if (pkg.reports.hasErrors || pkg.reports.hasWarnings) {
if (pkg.reports.versionCheck?.details) {
console.log('------------------------------');
console.log(pkg.reports.versionCheck.details);
}
if (pkg.reports.importsCheck) {
const details = pkg.reports.importsCheck.reportDetails;
Object.entries(details).forEach(([issue, report]) => {
console.log('------------------------------');
console.log(issue);
console.log(report.join('\n'));
});
}
if (pkg.reports.depsLocalCheck) {
const details = pkg.reports.depsLocalCheck.reportDetails;
Object.entries(details).forEach(([issue, report]) => {
console.log('------------------------------');
console.log(issue);
console.log(report.join('\n'));
});
}
if (pkg.reports.depsFullCheck) {
const details = pkg.reports.depsFullCheck.reportDetails;
Object.entries(details).forEach(([issue, report]) => {
console.log('------------------------------');
console.log(issue);
console.log(report.join('\n'));
});
}
}
// console.log('----------------------------------------------------------------------');
});
}

if (packages.some((pkg: Package) => pkg.reports.hasErrors)) {
if (params.throwError && params.logToConsole) {
throw new Error('Errors found. See the report above.');
} else if (params.logToConsole) {
console.error('Errors found. See the report above.');
} else if (params.throwError) {
throw new Error('Errors found. To see the report pass \'logToConsole\' to parameters.');
} else {
console.error('Errors found. To see the report pass \'logToConsole\' to parameters.');
}
} else if (packages.some((pkg: Package) => pkg.reports.hasWarnings)) {
if (params.logToConsole) {
console.warn('Warnings found. See the report above.');
} else {
console.warn('Warnings found. To see the report pass \'logToConsole\' to parameters.');
}
}

return packages;
}
Loading

0 comments on commit 98c85ed

Please sign in to comment.