Coder Social home page Coder Social logo

grunt-check-dependencies's Introduction

grunt-check-dependencies

Checks if currently installed npm dependencies are installed in the exact same versions that are specified in package.json. Based on check-dependencies.

NOTE: grunt-check-dependencies is no longer maintained. Consider switching to a pure-JS check-dependencies package.

Build Status Build status Built with Grunt

Getting Started

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-check-dependencies --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-check-dependencies');

The "checkDependencies" task

Overview

The checkDependencies task checks if the package has all necessary dependencies installed in right versions. If that's not the case, the task fails and advises to run npm install.

If in case of a missing package you want to invoke the npm install command automatically, set the install option to true.

In your project's Gruntfile, add a section named checkDependencies to the data object passed into grunt.initConfig().

grunt.initConfig({
    checkDependencies: {
        options: {
            // Task-specific options go here.
        },
        your_target: {
            // Target-specific file lists and/or options go here.
        },
    },
})

Options

The checkDependencies task accepts the same options the check-dependencies library accepts in its config except verbose, log and error. Click here to see the full list.

Below is a description of a few most basic options

{
    // `'npm'` or `'bower'`, depending on what we want to test.
    // Default: `'npm'`.
    packageManager: string,

    // Path to a directory containing the package to test. By default the current app is tested.
    packageDir: string,

    // Ensures all installed dependencies are specified in `package.json` or `bower.json`.
    // Default: `false`.
    onlySpecified: boolean,

    // If true, on error, instead of failing the task, `npm install` will be invoked for the user.
    // Default: `false`.
    install: boolean,

    // If true, instead of aborting the task after checking (and installing), the task will
    // continueAfterInstall. This option requires `install: true` to work.
    // Default: `false`.
    continueAfterInstall: boolean,
}

If you run the task with the --verbose flag, it will log non-error messages as well.

For the full list, see the usage section of the README of the check-dependencies package.

Usage Examples

The most basic (and probably most common) use of the task requires just providing a target, i.e.:

{
    checkDependencies: {
        this: {},
    },
}

If you want to automatically install missing packages, here's what you want:

{
    checkDependencies: {
        this: {
            options: {
                install: true,
            },
        },
    },
}

If you want to automatically install missing packages without interrupting the task, you can use:

{
    checkDependencies: {
        this: {
            options: {
                install: true,
                continueAfterInstall: true,
            },
        },
    },
}

However, be careful with the continueAfterInstall option as the tasks loaded before will not be updated unless re-running the task. This will also be the case with plugins like load-grunt-tasks.

Supported Node.js versions

This project aims to support all supported Node.js LTS versions (see LTS README for more details) as well as the latest stable Node.js.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014 Michał Gołębiowski-Owczarek. Licensed under the MIT license.

grunt-check-dependencies's People

Contributors

mfgcode avatar mgol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

grunt-check-dependencies's Issues

Also check bower dependencies

This would be useful for projects using bower to manage dependencies, or as in this case, where both npm and bower are used. Since this module already does a lot more then my little check-modules plugin, it might be the right place. That would be one more reason to switch various jQuery projects over.

Is there an option to read the output JSON in grunt

@mzgol I would like to create a JSON file once the dependencies check is completed, is there a way we can do using this plugin?

In check-dependencies npm package the output object can be passed to the callback as per the doc.

https://github.com/mzgol/check-dependencies#api

The function returns a promise so passing a callback is not necessary; instead you can do:

require('check-dependencies')(config)
    .then(function (output) {
        /* handle output */
    });

The promise should never fail.

There is a synchronous alternative -- the following code:

var output = require('check-dependencies').sync(config);

will assign to output the same object that would otherwise be passed to the callback in the asynchronous scenario.

src directory not published on npm

I just updated to 0.11.1 and the task is now failing with:

Loading "check-dependencies.js" tasks...ERROR
>> Error: Cannot find module '../dist/src/check-dependencies'
Warning: Task "checkDependencies:dev" not found. Use --force to continue.

I looked into node_module/grunt-check-dependencies/, and there is now src directory. Seems it did not get published to npm.

Yarn support and/or callback

Currently this package doesn't support Yarn. This could be ameliorated either by:

  • Adding support for Yarn
  • Or, adding semi-generic support for package managers that come along (that support the package.json format, like Yarn does). This could be done by offering in the options to specify a callback function that's called if the dependencies are out of date. In there I could manually run Yarn or whatever else.

continue option does not work

Hi ,

according the documentation in npmjs

// If true, instead of aborting the task after checking (and installing), the task will continue.
// Default: false.
continue: boolean,
i configured the option, but the task is anyway aborted. At the same time I wouldn't use --force.

Regards

When using `onlySpecified` it complains about .bin

checkDependencies: {
    this: {
        options: {
            onlySpecified: true
        }
    }
}
grunt checkDependencies
Running "checkDependencies:this" (checkDependencies) task
>> Package .bin installed, though it shouldn't be

`onlySpecified` errors with scoped packages

The npm registry supports scoped packages in the form @user/package now, however with onlySpecified enabled it errors with Package @user installed, though it shouldn't be

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.