@merger203/expert-invention
Check package dependencies for duplicates, peer dependencies satisfaction and more early
Install
npm install --save-dev @merger203/expert-invention
What is it for ?
Based on my experience, I often saw issues with duplicate dependencies like two versions of babel, or two versions a react library that cannot share a context, peer dependencies not respected. I wrote specific script inside each repository for a long time, but they tend to be hard to maintain, hard to read, and not generic enough.
I you have any idea, or found bug, please open an issue.
Try it with cli
Use npx to try and check package.json
in current directory:
npx @merger203/expert-invention
Uses Cases
- Check devDependencies are exact versions
- Check resolutions versions matches versions in devDependencies or dependencies
- Check direct peer dependencies are respected, and list exceptions
- Check some dependencies in your package.json respect another dependency dependencies
- Lock versions depending on certain conditions
- Be more confident when automerging renovate's PR
If something is missing for your need, please open an issue !
How to use
Create a script, for example scripts/check-package.js
. Add it in "scripts"
in your package.json. Run in CI and/or in your husky hooks.
import { createCheckPackage } from '@merger203/expert-invention';
await createCheckPackage()
.checkExactVersions({
isLibrary: false,
})
.checkDirectPeerDependencies({
missingOnlyWarnsFor: {},
invalidOnlyWarnsFor: {},
})
.checkDirectDuplicateDependencies({
onlyWarnsFor: { '*': 'type-fest' },
})
.checkResolutionsVersionsMatch()
.checkResolutionsHasExplanation()
.checkRecommended({
isLibrary: false,
peerDependenciesOnlyWarnsFor: [],
directDuplicateDependenciesOnlyWarnsFor: ['type-fest'],
})
.checkIdenticalVersionsThanDependency('react-scripts', {
resolutions: ['@babel/core'],
devDependencies: ['@babel/core'],
})
.checkSatisfiesVersionsFromDependency('@pob/eslint-config-typescript', {
devDependencies: [
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
],
})
.checkIdenticalVersions({
dependencies: {
react: {
dependencies: ['react-dom'],
devDependencies: ['react-test-renderer'],
},
},
})
.run();
'use script';
const { createCheckPackage } = require('@merger203/expert-invention');
await createCheckPackage()
.checkRecommended({})
.run();
If you use workspaces:
'use script';
const {
createCheckPackageWithWorkspaces,
} = require('@merger203/expert-invention');
await createCheckPackageWithWorkspaces()
.checkRecommended({
isLibrary: (pkgName) => !pkgName.endsWith('-example'),
peerDependenciesOnlyWarnsFor: [],
directDuplicateDependenciesOnlyWarnsFor: ['semver', 'github-username'],
})
.forRoot((rootPackageCheck) => {
})
.for('packageName', (pkgCheck) => {
})
.run();