Skip to content
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

Provide source file path for tasks in gulp --tasks-json output #1180

Closed
segrey opened this issue Jul 31, 2015 · 9 comments
Closed

Provide source file path for tasks in gulp --tasks-json output #1180

segrey opened this issue Jul 31, 2015 · 9 comments
Labels

Comments

@segrey
Copy link

segrey commented Jul 31, 2015

This information would be very useful in IDE integrations that allow to navigate from gulp tasks in a tree to their definitions in code.
If all gulp tasks are defined in a single gulpfile, there are no problems.
The problems arise where gulp tasks are spreaded among several gulpfiles. All IDEs can do in this situation is to use some sort of static analysis that determines all files required from the main gulpfile, i.e. the files where gulp tasks might be defined in. Unfortunately, static analysis fails sometimes, e.g. in case of an app generated with yo gulp-angular.

It'd be nice to have JSON output like this:

[
...
  {
    "label": "hello",
    "type": "task",
    "sourceFilePath": "/path/to/my.js", #
  }
...
]

/path/to/my.js

var gulp = require('gulp');
gulp.task('hello', function(){});

Thanks.

@yocontra
Copy link
Member

Err... technically possible to do in undertaker (track what line of code called undertaker.add) by abusing the Error class and stackFrame overrides. @phated ?

@phated
Copy link
Member

phated commented Aug 1, 2015

I don't think this is a good idea because in gulp 4, it is not recommended to break up gulpfiles in this fashion (all your functions should be exported and gulp.task should only be called in the gulpfile)

@segrey
Copy link
Author

segrey commented Aug 1, 2015

Didn't know about this. However, it's still possible to break up gulpfiles even it is not recommended to.
@phated Is there a page describing the recommendation?

@phated
Copy link
Member

phated commented Sep 9, 2015

@segrey Sorry I haven't been able to write something up for this yet. Basically, the recommended pattern is going to be to export functions from your task modules, require them all in the top-level gulpfile and make all of your gulp.task/series/parallel calls in that gulpfile. I feel this is the ultimate reusability story (functions could be used anywhere, even outside gulp) and avoids the forward referencing problem, etc.

@segrey
Copy link
Author

segrey commented Oct 7, 2015

@phated Thanks for the info, I see. That would be more reusable indeed. However, if I understand correctly, nothing would prevent from tasks splitting? I mean probably there will be fewer examples of tasks split across multiple files, but who knows may be some new project template/generator will exploit such a capability.
JFYI: WebStorm 11 will have support for require-dir (https://youtrack.jetbrains.com/issue/WEB-18229). That lowers this issue's severity for WebStorm, but still it's just a static analysis, that can (and most likely will) fail for more complex examples.
We can close this issue for now. If there are some real gulp 4 examples having tasks split across multiple files, we can reopen it then?

@phated phated modified the milestone: gulp-cli 1.1.0 Nov 18, 2015
@phated phated added gulp-cli and removed gulp4 labels Nov 18, 2015
@phated
Copy link
Member

phated commented Dec 21, 2015

@segrey I started looking into this and have a WIP branch at https://github.com/gulpjs/undertaker/tree/sourceFilePath - can you take a look at the implementation and test output to see if it is what you are looking for? The main caveat I ran into was: when using an unregister (with gulp.task) function in a series/parallel chain, I set the sourceFilePath to null because it wasn't ever passed through the callsite machinery

@phated
Copy link
Member

phated commented Dec 21, 2015

Deferring to gulp-cli 1.2.0

@phated phated modified the milestones: gulp-cli 1.2.0, gulp-cli 1.1.0 Dec 21, 2015
@yocontra
Copy link
Member

@phated
Copy link
Member

phated commented Apr 5, 2016

Moved to gulpjs/gulp-cli#74

@phated phated closed this as completed Apr 5, 2016
@phated phated removed this from the gulp-cli 1.3.0 milestone Apr 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants