gulpjs / undertaker

Task registry that allows composition through series/parallel methods.
MIT License
200 stars 31 forks source link

feat(normalizeArgs): publish task key as displayName for anonymous functions #22

Closed mgcrea closed 9 years ago

mgcrea commented 9 years ago

I've been playing with https://github.com/phated/undertaker-registry to properly modularize gulp-like workflows.

Somehow when loading tasks from theses registry, they end up as anonymous when used with gulp:

[17:25:20] Using gulpfile ~/Projects/ng-tools/sandbox-dashboard/gulpfile.js
[17:25:20] Starting 'ng:serve'...
[17:25:20] Starting 'ng:beforeServe'...
[17:25:20] Finished 'ng:beforeServe' after 509 μs
[17:25:20] Starting '<anonymous>'...
[17:25:20] Finished '<anonymous>' after 9.55 ms
[17:25:20] Starting '<anonymous>'...
[17:25:23] gulp-inject 17 files into index.jade.

Where it should be:

[17:25:42] Using gulpfile ~/Projects/ng-tools/sandbox-dashboard/gulpfile.js
[17:25:42] Starting 'ng:serve'...
[17:25:42] Starting 'ng:beforeServe'...
[17:25:42] Finished 'ng:beforeServe' after 487 μs
[17:25:42] Starting 'ng:src/clean'...
[17:25:42] Finished 'ng:src/clean' after 8.45 ms
[17:25:42] Starting 'ng:src/views'...
[17:25:45] gulp-inject 17 files into index.jade.

You can check some of theses registries here: https://github.com/ng-tools/undertaker-app-tasks/tree/master/lib/tasks

I tried to come up with an unit test for this, but the metadata part where this could be checked does seem totally private.


EDIT: I'm using the ConfigRegistry setup showed in your README, maybe the issue is coming from the overriding of the registry set method.

EDIT2: It's not due to that, but can be fixed easily there:

ConfigRegistry.prototype.set = function set(name, fn) {
  this._tasks[name] = fn.bind(this.config);
  this._tasks[name].displayName = name;
  return this._tasks[name];
};
phated commented 9 years ago

I need to investigate this more because I thought I already had this working. Am I able to reproduce from the linked repo? If not, can you link me something that I can reproduce from? Thanks.

phated commented 9 years ago

@mgcrea pinging this thread for my previous questions.

mgcrea commented 9 years ago

It's a bit long, but you can replicate it like that:

$ npm i -g generator-angular-factory
$ mkdir test-app; cd test-app
$ yo ng-factory
# yes/enter to all
$ gulp serve
# should work with resolved names (might require a gulp-cli#4.0)
comment out [this line](https://github.com/ng-tools/ng-factory/blob/master/lib/config.js#L34) in you `node_modules` folder.
$ gulp serve
# should show <anonymous> lines

To sum things up, latest ng-factory autoloads undertaker registries installed in your app, in this case a generic undertaker-app-tasks that is supposed to be generic and bound to a specialized "factory" of reusable transform streams, by default it's bound to factory-angular-channels to properly build and serve an angular application.

Everything is still quite experimental and only used internally to harmonize gulpfiles accross my teams.

But the objective was to release something that just works out of the box, and is safely upgradable. The need came from me spending way to much time fixing old/broken gulpfiles, or one that would break when you update a module.

phated commented 9 years ago

this is related to #25 - Not sure the best way to solve it. Still needs some thought put into it.

phated commented 9 years ago

Can you test against https://github.com/phated/undertaker/commits/registry-init to see if this is still a problem? Using the init hook should avoid this problem.

phated commented 9 years ago

@mgcrea pinging

phated commented 9 years ago

I believe this was closed by https://github.com/phated/undertaker/commit/e7bf5b3602e522e75d7bf964d8b70d9e7fa26a32 - Please reopen if changing to the init lifecycle hook doesn't solve this problem