Skip to content

Sharing Functionalities example not working for serial and parallel tasks. #87

@Smesharikable

Description

@Smesharikable

I tried to use Sharing Functionalities from README as an example to configure my tasks but it seems to not working, because this in function arguments of series and parallel stay bound to the Global object.

There is a gulpfile.js to reproduce:

var util = require('util');

var gulp = require('gulp');
var DefaultRegistry = require('undertaker-registry');

function ConfigRegistry(config){
  DefaultRegistry.call(this);
  this.config = config;
}

util.inherits(ConfigRegistry, DefaultRegistry);

ConfigRegistry.prototype.set = function set(name, fn) {
  // The `DefaultRegistry` uses `this._tasks` for storage.
  var task = this._tasks[name] = fn.bind(this.config);
  return task;
};

// `taker.registry` will reset each task in the registry with
// `ConfigRegistry.prototype.set` which will bind them to the config object.
gulp.registry(new ConfigRegistry({
  config: {
    src: './src',
    build: './build',
    bindTo: '0.0.0.0:8888'
  }
}));

gulp.task('dummy', function(cb) {
  // OK
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
})

gulp.task('test-series', gulp.series('dummy', function(cb) {
  // undefined
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
}));

gulp.task('test-parallel', gulp.parallel('dummy', function(cb) {
  // undefined
  console.log('Config: ' + JSON.stringify(this.config));
  cb();
}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions