0.0.0-alpha3 • Published 4 years ago
@nossbigg/peerdeps-manager v0.0.0-alpha3
peerdeps-manager
A simple CLI utility to install (and uninstall) your node peer dependencies to your dev dependencies.
Why does this exist?
Because npm (v4-6) and yarn does not support installing peer depedencies (as of Sep 2021).
Note: This tool is inspired by install-peerdeps and does roughly the same thing, but with a declarative approach.
Usage
- Install peerdeps-manager:
yarn add @nossbigg/peerdeps-manager -Dornpm install @nossbigg/peerdeps-manager -D - Add
.peerdeps-manager.config.jsto define tool config - Install dependencies defined in config:
peerdeps-manager set - Uninstall dependencies defined in config:
peerdeps-manager unset Options to invoke
peerdeps-manager:Invoke via sequential command:
peerdeps-manager set && jest // or peerdeps-manager unset && create-react-app startInvoke via pre/post command hooks:
// package.json { "scripts": { "pretest": "peerdeps-manager set", "test": "jest" } }
.peerdeps-manager.config.js config file
peerdeps-manager requires a .peerdeps-manager.config.js config file from the root of the project for configuring the tool
Config file schema:
// .peerdeps-manager.config.js
const config = {
// where you define your packages to install/uninstall during set/unset actions
// format: same as per provided to npm install/uninstall or yarn add/remove to maximize compatibility
set: { packages: ["lodash.uniq", "lodash.template@4.0.6"] },
unset: {
packages: ["lodash.uniq", "lodash.template"],
// automatically restores package.json to last git checked-in state, requires 'git' in CLI
// set to 'false' to disable this feature
doGitRestorePackageJson: true,
},
};
module.exports = config;Note on unset.doGitRestorePackageJson:
npm uninstall/yarn removewill remove a given package from alldependenciesfields, includingpeerDependencies- However, after an
unset, a library package author would like to preservepeerDependencies, in order to indicate what peer dependencies a given library must have in order to work correctly - Thus, for an ideal developer experience, during the
unsetstep,peerdeps-managerwill do agit checkout package.jsonby default in order to restore thepeerDependenciesthat were lost due to uninstalling the temporary packages. - You can disable this feature by setting
doGitRestorePackageJson: false(eg. if you are experimenting with yourpackage.jsonand you do not want to lose your changes)
Related documentation:
Supported package managers:
npmyarn
Use case
As a react component library maintainer, I would like to:
- Specify
reactandreact-domin mypeerDependencies - Uninstall
reactandreact-domin mydevDependenciesbefore running a webpack dev instance locally- to ensure that my React component is working as expected.
- Install
reactandreact-domin mydevDependenciesbefore running my tests so that my test suite has the right dependencies to function and pass- eg.
enzymeandreact-testing-libraryrequires the aforementioned dependencies to work correctly
- eg.
- Uninstall
reactandreact-dombefore publishing my package for it to work correctly
Developing
- Clone the repo
- Install its dependencies:
npm ioryarn - Make
peerdeps-manageravailable to be locally symlinked:- (in
./peerdeps-manager)npm link
- (in
- Use
peerdeps-managerin a project:- (in other project directory)
npm install -D @nossbigg/peerdeps-manager - (in other project directory)
npm link @nossbigg/peerdeps-manager
- (in other project directory)
- Publish package:
npm publish --access public