-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Trailing spaces in gulp --tasks output breaks WebStorm tooling. #24
Comments
I just got feedback from Jetbrains. Apparently this was already brought up and WebStorm will be using --tasks-json (which I just discovered in another issue) as of 10.0.2 Source here: |
Should probably leave this issue open because in any case I don't think the regular tree output should be appending spaces to ensure backward compatibility with older version of WebStorm and other tooling. Agreed? |
This is a side-effect of us supporting task descriptions now. We've exposed the entire task tree for use by tooling through the Btw, do you have any idea how to comment on the jetbrains issue tracker? I would highly suggest they use the |
@phated Ya I've been scouring issues and docs today relating to gulp/gulp-cli and undertaker so I eventually figured that out. Task descriptions: Ah, I see. So I'm guessing the resulting two spaces is a side effect of a printf()-like functionality where you set a specific number of character aside for a column? Commenting on jetbrains issue: Yes, I think you just have to log in at the top right. The IntelliJ IDE platform is not a node app, so they can't simply |
@mikehaas763 yeah, the issue comes from pretty-printing columns for the descriptions. I think they could create a tiny bin file that expects to be run in node. Reading through the comments on that thread, it seems like it would be less hacky than shelling out to gulp and parsing the output, looking for |
@phated I don't have any contacts there but I'm fairly positive that @segrey who opened gulpjs/gulp#584 is the same Sergey that is responding to the Jetbrains issue ticket. |
Hi guys, |
@segrey I think what he's saying is that you would call from the node bin "gulp.tree()". Then you would be in control of what can get logged to stdout. Is that right @phated? I do like the idea of being able to call directly into code to get an object but what is the purpose of --tasks-json if it cannot be guaranteed a whole and valid JSON document? In the case of someone logging during the task registration phase as he mentioned. |
Could noop process.stdout if --tasks or --tasks-json was passed to the CLI to make sure nothing but the tasks gets logged |
@contra That's a solution. Other possible solutions:
|
I like the idea of using JSON.stringify to reduce the JSON to a single output line. @contra thoughts? |
@phated I think nooping stdout/stderr is the more robust solution because there are multiple tools (for example, all of our autocomplete script) that rely on this output being clean and usable |
@contra I understand that sentiment but it just seems so dirty to hijack stdout. I actually rely on the ability to |
@phated only when --tasks or --tasks-json is passed, not like it would always hijack it |
I agree that it seems dirty to hijack it though it doesn't seem so bad if limited to only specific routines where it's needed like --tasks-json. I'd think it would be worse to have someones tooling break because they forgot a console.log somewhere than it would be to suppress their console.log for routines that are intended for tooling. Heh, if it ever became a problem you could extend --tasks-json with an optional flag like --enable-logging or --enable-stdout. |
Nooping stdout sounds reasonable. What bothers me a bit about nooping stdout is that inserting About nooping stderr: wouldn't it hide exceptions raised in gulpfile? Probably, nooping stderr is not needed because tools can work with standard streams independently. |
Reopening this because I almost lost it and forgot about it. Can we come up with the best solution for this? |
IMO, the most reliable solution is to dump JSON to a file specified by some cli option, like |
We can probably use https://github.com/isaacs/mute-stream to mute the stream during load, unmute to spit out the json and then mute again until the process finishes. @segrey why is a JSON file the best option? We could probably add an optional parameter to --tasks-json (e.g. |
@phated I think nooping var MuteStream = require('mute-stream')
var ms = new MuteStream()
ms.pipe(process.stdout)
ms.mute()
process.stdout = ms
ms.write('Muted output\n')
process.stdout.write('process.stdout.write\n')
var fs = require('fs')
fs.write(process.stdout.fd, 'fs.write\n')
fs.writeSync(process.stdout.fd, 'fs.writeSync\n')
console.log('console.log') Output (node 0.12.7):
|
@segrey I just pushed a change that allows an output file to be specified for the Example usage: |
Cool, thank you. |
Just added support for muting the process.stdout while requiring a gulpfile if we see a task listing flag. Closing, as I believe both use cases are handled now. |
Hello! I'd like to point out that this check in lib/versioned/^4.0.0-alpha.1/index.js probably doesn't work as intended if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
return console.log(output);
} else {
return fs.writeFileSync(opts.tasksJson, output, 'utf-8');
} As mentioned before, WebStorm uses I am not sure if WebStorm is going to change in future to accommodate this commit, but please, if it's possible, reopen this issue to find a better, non-breaking solution. |
@pycbouh fyi, you should be opening new issues for new issues, not commenting on extremely old issues. I did it for you 😒 |
@phated Yeah, sorry :( I wanted to continue this discussion, as this is where the problem had been created, but didn't realize the right way would've been to create a new issue and then link this one there. Thanks for educating me and fixing the problem anyway! |
Right now, WebStorm parses the output of
gulp --tasks
to capture the tasks that can be run. I'm testing this with the v4 alpha of both gulp and gulp-cli. I have a very simple gulpfile with a single task. I've noticed that the output from runninggulp --tasks
now has two spaces appended to my task name. So when WebStorm parses the task tree, it attempts to rungulp "clean "
which does not exist (notice the two trailing spaces).I've already submitted a bug to Jetbrains letting them know that they should probably trim the task names after parsing them. I see a couple of things that could be improved on the gulp side too. I think the first and most obvious step is to remove the trailing spaces from the task tree output. I have a couple of other ideas also.
I know gulp uses Liftoff for CLI work so maybe it can't be easily addressed directly in the gulp project, but I'm thinking the gulp-cli should trim the tasks arguments that are passed in just as a simple normalization step. I don't think anyone should be defining tasks with whitespace on either side so this shouldn't cause a problem. That would create a simple fix for any other tooling out there that parses the task tree and does not do its own trim. This is to keep existing tooling happy and not cause any backward compatibility issues.
It could be taken one step further though and I may be interested in spending some time implementing it. There should be a separate CLI flag that can be used by other tooling that outputs to something that does not need to be manually parsed. I'm thinking a simple object graph version of the tree serialized to JSON and written to stdout. This should help to make any tooling integration with gulp easier.
Update:
I just noticed that gulp is using archy, which means this object is probably already defined somewhere.
The text was updated successfully, but these errors were encountered: