Semantic Versioning

  • Semantic: which conveys meaning
  • Semantic Versioning is versioning the code such that by looking at the version itself gives some understanding
  • The version format is ${MAJOR}.${MINOR}.${PATCH}
  • Upgrading PATCH of dependency will fix some bugs, and your code will work fine
  • Upgrading MINOR of dependency will add some features, and your code will work fine
  • Upgrading MAJOR of dependency will introduce some big changes and code will maybe break
  • You can learn more at https://semver.org

Package.json dependencies

  • Consider the example of moment library in package.json
{
	"dependencies": {
		"moment": "^2.10.6"
	}
}
  • ^2.10.6 : Increment automatically PATCH and MINOR version but not MAJOR version
    • example: 2.12.3 can be automatically downloaded
  • ~2.10.6 : Increment automatically only PATCH version
    • example: 2.10.8 can be automatically downloaded
  • 2.10.6 : Exact version should be matched and downloaded
  • latest : Obtains latest version
  • It is very flexible and can have conditions too. For more version configuration, you can visit: https://docs.npmjs.com/cli/v7/configuring-npm/package-json/#dependencies

Dev Dependency

  • devDependencies is used to define Dev Dependencies.
  • These are tools/libraries which you do not want to be in the production
  • They are usually meant for testing, documenting or ease development
  • They are installed with npm install <package> --dev

Peer Dependency

  • peerDependencies is used to define Peer Dependencies
  • These are usually meant for plugins
  • examples are babel plugins, express middleware
  • Consider example of dependencies:
node_modules  
|_ A  
| |_ node_modules  
|   |_ B  
|_C  
  |_ node_modules  
    |_ B
  • Suppose A and C are packages which depends on B. Now the requirement is such that A should not install B instead it is fine to for B to be just installed irrespective of the version, then we can define B as peerDependencies of A, then while installing A it will not attempt to install B since it is already installed

Transitive Dependency

  •  If package A has dependency B and dependency B has dependency C, then package A transitively depends on dependency C.
  • A (our project) B (direct dependency) C (transitive dependency) …