-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A single task in gulp.watch() using gulp.task() incorrectly logs as <anonymous> #1492
Comments
gulp.task(): function task(name, fn) {
if (typeof name === 'function') {
fn = name;
name = fn.displayName || fn.name;
}
if (!fn) {
return this._getTask(name);
}
this._setTask(name, fn);
} gulp._getTask(): function get(name) {
var wrapper = this._registry.get(name);
if (!wrapper) {
return;
}
var meta = metadata.get(wrapper);
if (meta) {
return meta.orig; // Here is our anonymous function, Watson!
}
return wrapper;
} The problem can be resolved by overriding _getTask method in var metadata = require('undertaker/lib/helpers/metadata');
function Gulp() {
// ...
this._getTask = function get(name) {
var wrapper = this._registry.get(name);
if (!wrapper) {
return;
}
var meta = metadata.get(wrapper);
if (meta) {
let orig = meta.orig;
orig.displayName = meta.name;
return orig;
}
return wrapper;
};
} Yea, this is private method but another way to fix the problem - override |
@avxm it just needs to be fixed in undertaker. |
@phated I can send PR. But which way preferred? Set function displayName in public |
Neither, gulp shouldn't modify a user's function. I'm not sure of the complete solution for this. It might need to be done with the watch debounce changes. |
@phated I don't understand why we can't set fn.displayName = fn.displayName || 'foo' We do not modify value if it defined. Also i'm not sure with decision to fix it in undertaker. This is project-specific problem so it needs to be fixed here, isn't? |
Ok. Now I understand why it needs to be fixed in undertaker and why we shouldn't modify user's functions. Anyways the problem in return value of |
I had some time to look into this and I couldn't come up with a good reason why I wanted to return the unwrapped function. Instead, |
@jaydenseric @axvm this should be fixed by my update of undertaker in d8f5c90 |
As discussed earlier.
Using the latest version of Gulp 4:
Results in:
Whereas replacing the watch task with:
Results in:
The text was updated successfully, but these errors were encountered: