Git Product home page Git Product logo

satisfaction's Introduction

Satisfaction

Build Status NPM Version License Dependency Status devDependency Status

Verifies that a package.json file is satisfied by its node_modules dir.

Satisfaction uses the Semver package (which is used by NPM) to verify that the versions installed in your node_modules satisfy the requirement defined in your package.json, and can also verify that all of your dependencies are required with specific versions, (no ~, ^, >=, etc).


Installation

$ npm i satisfaction

or globally:

$ npm i -g satisfaction

Usage

As a dependency

const satisfaction = require('satisfaction')

const statusErrors = satisfaction.checkStatus()
if (statusErrors.length) {
  throw new Error(`node_modules does not satisfy package.json:\n${statusErrors.join('\n')}`)
}

const exactErrors = satisfaction.checkExact()
if (exactErrors.length) {
  throw new Error(`Dependencies are not exact versions:\n${exactErrors.join('\n')}`)
}

Likely use in Grunt:

grunt.registerTask('verify-npm', () => {
  const satisfaction = require('satisfaction')

  const statusErrors = satisfaction.checkStatus()
  if (statusErrors.length) {
    grunt.fail.warn(`node_modules does not satisfy package.json:\n${statusErrors.join('\n')}`)
  }

  const exactErrors = satisfaction.checkExact()
  if (exactErrors.length) {
    grunt.fail.warn(`Dependencies are not exact versions:\n${exactErrors.join('\n')}`)
  }
})

Both statusErrors and exactErrors accept an options object:

console.log(require('satisfaction').statusErrors({
  dir: someDir // containing folder of package.json and node_modules, defaults to process.cwd()
}).join('\n'))

As a global

The satisfaction-status and satisfaction-exact global binaries will throw errors listing which violations were found.

Running satisfaction-status || npm i will be prevent npm i from running when everything is already installed with compliant versions.

Example errors for running satisfaction-status:

Error: node_modules does not satisfy package.json:
package eslint installed with 3.6.1 but required 3.6.2
package ava is not installed

Example errors for running satisfaction-exact:

Error: Dependencies are not exact versions:
package lodash is required with a non-exact version ^4.16.2

Notes / Caveats

  • When using git urls in dependencies, (like "byRepo": "git+ssh://[email protected]:repo.git#3.5.3" or like "byRepo": "githubuser/githubrepo#3.5.3"), it must be done with a tag (3.5.3 or v3.5.3) that corresponds to the version of said package (3.5.3), or it will be considered an error.
  • Checks the "dependencies" and "devDependencies" fields of package.json.

Feedback

satisfaction's People

Contributors

danyshaanan avatar

Stargazers

Chris Watson avatar

Watchers

Shmulik Flint avatar Luis Godinez avatar Ivan Kamenev avatar James Cloos avatar Jonathan Bensaid avatar  avatar Adam Matan avatar  avatar Danny Steinhoff avatar Mykyta Shyrin avatar Shai Ben-Yehuda avatar Omar Shibli avatar Algimantas Krasauskas avatar Denys avatar Guy Sopher avatar  avatar avgar marciano avatar Ariel avatar Noam Katzir avatar Ihor Krysenko avatar JJ Major avatar  avatar Roman Shevchuk avatar Valera avatar Matan Lieberman avatar Yuval Aviyam avatar Olesia Zaichenko avatar Andrii Ziabriev avatar Maor Hamami avatar Gregory Bondar avatar Dror avatar Evaldas avatar Ward Abbass avatar Jurij Mikelionis avatar uri bechar avatar Vladimir Sorkin avatar Artur Rieznik avatar Ariel Wine avatar Ilya Lytvynov avatar Leonid Zhuk avatar Oren Zakay avatar Peter Tarasenko avatar Tomer Chajaj avatar Tetiana Stashchenko avatar Mykolas Sindeikis avatar Adam Shavit avatar Eyal Malron avatar ittay avatar Jonas Kabelka avatar Sergey Shpadyrev avatar Guy Benron avatar Nir Orman avatar Ovchinnikov Konstantyn avatar Avi Mualem avatar Guy Segev avatar  avatar Alexey Soshin avatar Moises Rezonzew avatar Dmitriy Gordienko avatar  avatar  avatar Yakir Amar avatar Dom avatar Yaniv Stein avatar Yonatan Hattav avatar Ihor Kucherenko avatar  avatar  avatar Cheli Bachar avatar Aleksandra Pervunina avatar Assaf Segev avatar  avatar Nancy avatar Valentyna Kalinichenko avatar Nojus Adomaitis avatar Svitlana Koshelieva avatar  avatar Yevheniia Hlovatska avatar Miki Leib avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.