Skip to content

Overeager files interpretation in multi-tasks #1773

@RolKau

Description

@RolKau

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, but it comes from task.normalizeMultiTaskFiles at line 168 in task.js
where src is now [1, 2, 3] when it processes the foo section, because line 110 in task.js 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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions