
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
grunt-promise
Advanced tools
Create asynchronous Grunt tasks using Promises.
This package requires Node.js ^0.12.
This package requires Grunt ^0.4.5.
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-promise --save-dev
Below are a list of supported NPM modules that implement Promise APIs. The goal of this plugin is to abstract the Grunt integration so it does not limit or assume how one creates or consumes the Promises in a Grunt task; it merely facilitates communication.
By default, this plugin will attempt to automatically detect if one of the NPM modules below is already installed (order of appearance). If no NPM module is detected, it defaults to using the native Promise object.
Note: This plugin does NOT depend on any Promise based NPM modules.
You, of course, are not limited in using any of these modules, they are simply supported "out-of-the-box". For customization and other Promise solutions, see below.
Require the plugin's NPM module at the top and call the using method with the
name of the Promise module you wish to use. If no module is specified, it will
attempt to load the first available Promise object in environment. You can use
this Promise object to create new Promises, see example below.
// Gruntfile.js
var Promise = require('grunt-promise').using('bluebird');
module.exports = function (grunt) {
// Continue your grunt initialization as normal.
grunt.initConfig({...});
}
It is highly recommended that you are always explicit when loading a Promise object via this plugin to avoid confusion and any randomness if/when other NPM modules may depend on a Promise library different from what you are expecting.
There are several ways to specify which Promise object will be returned from this plugin:
Pass a NPM package name when loading the Promise object. This can
either be a string or a function that returns a string. It will
automatically require the module if not already loaded:
var Promise = require('grunt-promise').using('an-npm-promise-module');
Or:
var Promise = require('grunt-promise').using(function () {
return 'an-npm-promise-module';
});
Pass an existing module (or create a new one). This must be a function that
either creates a "thenable" Promise object or a plain object that has
exported this constructor to a "Promise" method (e.g. module.exports.Promise):
var promiseModule = require('an-npm-promise-module');
var Promise = require('grunt-promise').using(promiseModule);
Or:
var Promise = require('grunt-promise').using(function () {
return require('an-npm-promise-module');
});
Grunt Option - The following option is available where some use cases may require a little bit of CLI love. In which case, you can use:
grunt --grunt-promise-library=<module>
Where <module> is an NPM package module. You may also specify native here.
This plugin provides two new methods on the main grunt object that help save
a little bit of time and whitespace. It's worth noting that you do not have to
call this.async() inside these tasks (which is the whole point for this
plugin).
grunt.registerPromise(name, info, fn) - Normal taskgrunt.registerMultiPromise(name, info, fn) - Multi taskArguments:
{string} name - The name of the Grunt task to register.{string|function} info - (Optional) Descriptive text explaining what the
task does. Shows up on --help. You may omit this argument and replace it with
fn instead.{function} fn - (Required) The task function. Remember not to pass in your
Promise function directly. Promise resolvers are immediately invoked when
they are created. You must wrap the Promise with an anonymous task function
instead. The task function must return a Promise or it will fail.Examples:
var grunt = require('grunt');
var Promise = require('grunt-promise').using('bluebird');
// Register a promised task (working example).
// @see https://tonicdev.com/npm/grunt-promise
grunt.registerPromise('timeout', function () {
return new Promise(function (resolve) {
setTimeout(function () {
resolve('Hello World!');
}, 1000); // 1 second.
}).then(grunt.log.write);
});
// Register a promised task (workflow example).
grunt.registerPromise('my-promise', function () {
return promiseReturningFunction()
.then(anotherPromise)
.then(yetAnotherPromise)
.then(function (value) {
grunt.log.writeln('Value:', value);
})
.catch(function (e) {
// Do something with your errors.
// It's not entirely necessary to implement this. This plugin
// already appends the necessary catch/then handlers to properly
// fail or end the async task.
grunt.fail.fatal(e);
});
});
Mark Halliwell
Code and documentation Copyright 2016 Mark Halliwell. Released under the MIT license.
FAQs
Create asynchronous Grunt tasks using Promises.
We found that grunt-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.