gruntjs / gruntjs/grunt

Request: have grunt automatically enter async mode if task returns a promise

Open
#1,665 2 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.2k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Every grunt task I've ever seen looks, essentially, like this:
```
grunt.registerTask('build', function () {
const done = this.async();

callSomeModule()
.then(() => done())
.catch(error => {
grunt.fail.warn(error);
done(false);
});
});
```

It would be nice if _by default_, grunt recognized a Promise return value and did the boilerplate for you (spitting a stack trace to `warn` if the promise is rejected, continuing if the promise resolved).

I'd be open to to putting up a tentative PR, if this sounds like something that could be added.

Example desired syntax:
```
grunt.registerTask('build', function () {
return callSomeModule();
});
```

Contributor guide

Open the contributing guide

Research direction

Start at the grunt.registerTask entry point and trace how task completion currently handles this.async() and returned values. Define and test the behavior for resolved and rejected Promise returns, including continuation and warning stack traces; done means the example syntax works without explicit async boilerplate.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.