Overeager files interpretation in multi-tasks
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
If a multi-task is registered, and this multi-task is invoked with a section which is an array while grunt is run with the `--verbose`
option, the build will terminate with the error message:
```
Warning: pattern.indexOf is not a function Use --force to continue.
```
The exception itself is thrown at [line 45 in file.js](https://github.com/gruntjs/grunt/blob/e1bb073f108dd7b69b257a91f025994d5bd495b1/lib/grunt/file.js#L45), but it comes from task.normalizeMultiTaskFiles at [line 168 in task.js](https://github.com/gruntjs/grunt/blob/e1bb073f108dd7b69b257a91f025994d5bd495b1/lib/grunt/task.js#L168)
where `src` is now `[1, 2, 3]` when it processes the `foo` section, because [line 110 in task.js](https://github.com/gruntjs/grunt/blob/e1bb073f108dd7b69b257a91f025994d5bd495b1/lib/grunt/task.js#L110) interprets the `foo` section as if it was a file specification in a non-multi-task, and creates an object with `src=[1, 2, 3]` and `dest='foo'`.
Consider the example from the [documentation](https://gruntjs.com/api/grunt.task#grunt.task.registermultitask):
```
module.exports = grunt => {
grunt.initConfig({
log: {
foo: [1, 2, 3],
bar: 'hello world',
baz: false
}
});
grunt.task.registerMultiTask('log', 'Log stuff.', function() {
grunt.log.writeln(this.target + ': ' + this.data);
});
}
```
Given now also a `package.json` of:
```
{
"main": "index.js",
"scripts": {
"build": "grunt log",
"verbose": "grunt log --verbose"
},
"devDependencies": {
"grunt": "1.6.1"
}
}
```
one can reproduce the error with:
```
npm i
npm run build
npm run verbose
```
Contributor guide
Research direction
Start with task.normalizeMultiTaskFiles in lib/grunt/task.js, especially lines 110 and 168, then inspect the pattern handling at line 45 of lib/grunt/file.js. Reproduce the issue with the provided package.json and npm run verbose. Done means the documented array-valued multi-task target runs with --verbose without the pattern.indexOf error and still logs the target data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100