Skip to content

Commit

Permalink
fix(check-package-dependencies): pkg path name
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Mar 13, 2021
1 parent a5f4dd7 commit f056a54
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.checkWarnedFor = checkWarnedFor;

exports.checkDirectDuplicateDependencies = (
pkg,
pkgPath,
pkgPathName,
depType,
searchIn,
depPkg,
Expand All @@ -30,7 +30,7 @@ exports.checkDirectDuplicateDependencies = (

const reportError = createReportError(
'Direct Duplicate Dependencies',
pkgPath,
pkgPathName,
);
const searchInExisting = searchIn.filter((type) => pkg[type]);

Expand Down
4 changes: 2 additions & 2 deletions packages/check-package-dependencies/lib/checkExactVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

const { createReportError } = require('./utils/createReportError');

exports.checkExactVersions = (pkg, pkgPath, type) => {
exports.checkExactVersions = (pkg, pkgPathName, type) => {
const pkgDependencies = pkg[type];
if (!pkgDependencies) return;

const reportError = createReportError('Exact versions', pkgPath);
const reportError = createReportError('Exact versions', pkgPathName);

for (const [depKey, version] of Object.entries(pkgDependencies)) {
if (version.startsWith('^') || version.startsWith('~')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { createReportError } = require('./utils/createReportError');

exports.checkIdenticalVersionsThanDependency = (
pkg,
pkgPath,
pkgPathName,
type,
depKeys,
depPkg,
Expand All @@ -14,7 +14,7 @@ exports.checkIdenticalVersionsThanDependency = (
const pkgDependencies = pkg[type];
const reportError = createReportError(
`Same Versions than ${depPkg.name}`,
pkgPath,
pkgPathName,
);

depKeys.forEach((depKey) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const { createReportError } = require('./utils/createReportError');

exports.checkPeerDependencies = (
pkg,
pkgPath,
pkgPathName,
type,
allowedPeerIn,
depPkg,
onlyWarnsFor = [],
) => {
if (!depPkg.peerDependencies) return;
const reportError = createReportError('Peer Dependencies', pkgPath);
const reportError = createReportError('Peer Dependencies', pkgPathName);
const { peerDependencies, peerDependenciesMeta = {} } = depPkg;

const allowedPeerInExisting = allowedPeerIn.filter((type) => pkg[type]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ const { createReportError } = require('./utils/createReportError');

exports.checkResolutionsHasExplanation = (
pkg,
pkgPath,
pkgPathName,
checkMessage,
getDependencyPackageJson,
) => {
const pkgResolutions = pkg.resolutions || {};
const pkgResolutionsExplained = pkg.resolutionsExplained || {};
const reportError = createReportError('Resolutions has explanation', pkgPath);
const reportError = createReportError(
'Resolutions has explanation',
pkgPathName,
);

Object.keys(pkgResolutions).forEach((depKey) => {
if (!pkgResolutionsExplained[depKey]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { createReportError } = require('./utils/createReportError');

exports.checkSatisfiesVersionsFromDependency = (
pkg,
pkgPath,
pkgPathName,
type,
depKeys,
depPkg,
Expand All @@ -15,7 +15,7 @@ exports.checkSatisfiesVersionsFromDependency = (
const pkgDependencies = pkg[type];
const reportError = createReportError(
`Satisfies Versions from ${depPkg.name}`,
pkgPath,
pkgPathName,
);

depKeys.forEach((depKey) => {
Expand Down
48 changes: 24 additions & 24 deletions packages/check-package-dependencies/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const readPkgJson = (packagePath) => {
exports.createCheckPackage = (pkgDirectoryPath = '.') => {
const pkgDirname = path.resolve(pkgDirectoryPath);
const pkgPath = `${pkgDirname}/package.json`;
const pkgPathName = `${pkgDirectoryPath}/package.json`;
const pkg = readPkgJson(pkgPath);
const nodeModulesPackagePathCache = new Map();
const getDependencyPackageJson = (pkgDepName) => {
Expand Down Expand Up @@ -80,15 +81,15 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
},

checkExactDevVersions() {
checkExactVersions(pkg, pkgPath, 'devDependencies');
checkExactVersions(pkg, pkgPathName, 'devDependencies');
return this;
},

checkNoDependencies(
type = 'dependencies',
moveToSuggestion = 'devDependencies',
) {
checkNoDependencies(pkg, pkgPath, type, moveToSuggestion);
checkNoDependencies(pkg, pkgPathName, type, moveToSuggestion);
return this;
},

Expand All @@ -111,7 +112,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (depPkg.peerDependencies) {
checkPeerDependencies(
pkg,
pkgPath,
pkgPathName,
type,
allowedPeerIn,
depPkg,
Expand Down Expand Up @@ -141,7 +142,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
const depPkg = getDependencyPackageJson(depName);
checkDirectDuplicateDependencies(
pkg,
pkgPath,
pkgPathName,
'dependencies',
searchIn,
depPkg,
Expand All @@ -154,7 +155,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (!warnedForInternal) {
const reportError = createReportError(
'Direct Duplicate Dependencies',
pkgPath,
pkgPathName,
);
checkWarnedFor(reportError, onlyWarnsFor, warnedForInternal);
}
Expand All @@ -166,7 +167,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
) {
checkResolutionsHasExplanation(
pkg,
pkgPath,
pkgPathName,
checkMessage,
getDependencyPackageJson,
);
Expand Down Expand Up @@ -207,7 +208,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (resolutions) {
checkIdenticalVersionsThanDependency(
pkg,
pkgPath,
pkgPathName,
'resolutions',
resolutions,
depPkg,
Expand All @@ -217,7 +218,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (dependencies) {
checkIdenticalVersionsThanDependency(
pkg,
pkgPath,
pkgPathName,
'dependencies',
dependencies,
depPkg,
Expand All @@ -227,7 +228,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (devDependencies) {
checkIdenticalVersionsThanDependency(
pkg,
pkgPath,
pkgPathName,
'devDependencies',
devDependencies,
depPkg,
Expand Down Expand Up @@ -277,7 +278,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (resolutions) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'resolutions',
resolutions,
depPkg,
Expand All @@ -287,7 +288,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (dependencies) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'dependencies',
dependencies,
depPkg,
Expand All @@ -297,7 +298,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (devDependencies) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'devDependencies',
devDependencies,
depPkg,
Expand All @@ -315,7 +316,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (resolutions) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'resolutions',
resolutions,
depPkg,
Expand All @@ -325,7 +326,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (dependencies) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'dependencies',
dependencies,
depPkg,
Expand All @@ -335,7 +336,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {
if (devDependencies) {
checkSatisfiesVersionsFromDependency(
pkg,
pkgPath,
pkgPathName,
'devDependencies',
devDependencies,
depPkg,
Expand All @@ -362,7 +363,7 @@ exports.createCheckPackage = (pkgDirectoryPath = '.') => {

exports.createCheckPackageWithWorkspaces = (pkgDirectoryPath = '.') => {
const checkPackage = exports.createCheckPackage(pkgDirectoryPath);
const { pkg, pkgDirname, pkgPath } = checkPackage;
const { pkg, pkgDirname, pkgPathName } = checkPackage;

if (!pkg.workspaces) {
throw new Error('Package is missing "workspaces"');
Expand All @@ -374,24 +375,23 @@ exports.createCheckPackageWithWorkspaces = (pkgDirectoryPath = '.') => {
match.forEach((pathMatch) => {
const stat = fs.statSync(pathMatch);
if (!stat.isDirectory()) return;
const pkgPath = path.relative(
process.cwd(),
path.join(pathMatch, 'package.json'),
);
const pkgDirectoryPath = path.relative(process.cwd(), pathMatch);
const pkgPath = path.join(pkgDirectoryPath, 'package.json');
const pkg = readPkgJson(pkgPath);
workspaces.push({
id: pkg.name,
pkgDirname: pathMatch,
pkgDirectoryPath,
pkgPath,
pkg,
});
});
});

const checksWorkspaces = new Map(
workspaces.map(({ id, pkgDirname }) => [
workspaces.map(({ id, pkgDirectoryPath }) => [
id,
exports.createCheckPackage(pkgDirname),
exports.createCheckPackage(pkgDirectoryPath),
]),
);

Expand Down Expand Up @@ -421,7 +421,7 @@ exports.createCheckPackageWithWorkspaces = (pkgDirectoryPath = '.') => {
});
checkDirectDuplicateDependencies(
pkg,
pkgPath,
pkgPathName,
'devDependencies',
['devDependencies', 'dependencies'],
pkg,
Expand All @@ -431,7 +431,7 @@ exports.createCheckPackageWithWorkspaces = (pkgDirectoryPath = '.') => {
});

checkWarnedFor(
createReportError('Recommended Checks', pkgPath),
createReportError('Recommended Checks', pkgPathName),
directDuplicateDependenciesOnlyWarnsFor,
warnedForDuplicate,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const chalk = require('chalk');

let titleDisplayed = null;
let pkgPathDisplayed = null;
exports.createReportError = (title, pkgPath) => {
exports.createReportError = (title, pkgPathName) => {
return function reportError(msgTitle, msgInfo, onlyWarns) {
if (titleDisplayed !== title || pkgPath !== pkgPathDisplayed) {
if (titleDisplayed !== title || pkgPathName !== pkgPathDisplayed) {
if (titleDisplayed) console.error();
console.error(chalk.cyan(`== ${title} in ${pkgPath} ==`));
console.error(chalk.cyan(`== ${title} in ${pkgPathName} ==`));
titleDisplayed = title;
pkgPathDisplayed = pkgPath;
pkgPathDisplayed = pkgPathName;
}
console.error(
`${
Expand Down

0 comments on commit f056a54

Please sign in to comment.