gruntjs / grunt

Grunt: The JavaScript Task Runner
http://gruntjs.com/
Other
12.27k stars 1.5k forks source link

grunt.task.isTaskAlias not working #1089

Open stevenvachon opened 10 years ago

stevenvachon commented 10 years ago

It's always returning false. So, I ran some tests:

grunt.registerTask("test", "", function(){});

grunt.registerTask("bleh", ["test"]);
grunt.registerTask("default", ["test"]);

console.log( grunt.task._tasks["bleh"].fn.alias );    // undefined
console.log( grunt.task._tasks["bleh"].info );        // "Alias for..."

console.log( grunt.task._tasks["default"].fn.alias );    // undefined
console.log( grunt.task._tasks["default"].info );        // "Alias for..."

console.log( this.task._tasks["default"].fn.alias );    // undefined
console.log( this.task._tasks["default"].info );        // "Alias for..."
vladikoff commented 10 years ago

This does work in tests though https://github.com/gruntjs/grunt/blob/master/test/util/task_test.js#L62

stevenvachon commented 10 years ago

After looking at https://github.com/gruntjs/grunt/blob/v0.4.3/lib/grunt/task.js#L45-L47, I added:

// Support public use of task.isTaskAlias
if (_fn.alias) {
    thisTask.fn.alias = _fn.alias;
}

on line 84, right after the thisTask.fn=function(){…}, and it fixes the issue.

I wonder if anyone think twice about implementing this fix considering that grunt.task.isTaskAlias is an undocumented function. As a plugin developer, I'm currently finding it useful for extending Grunt's core features, not so much for typical plugins.

stevenvachon commented 10 years ago

This is a less than pretty work-around:

var queuedTask = grunt.task._queue["default"];

if ( !queuedTask.task.multi ||
      queuedTask.task.multi && queuedTask.args.length
   ) {
    console.log("not an alias");
}
stevenvachon commented 8 years ago

This issue was never referenced, so it was probably never fixed. Re-opening for core team to see again.