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

Don't run task if Gruntfile was run with errors #1303

Closed
segrey opened this issue Mar 13, 2015 · 6 comments
Closed

Don't run task if Gruntfile was run with errors #1303

segrey opened this issue Mar 13, 2015 · 6 comments

Comments

@segrey
Copy link

segrey commented Mar 13, 2015

If requiring Gruntfile throws an error, don't run tasks loaded from additional directory paths (--tasks).
If it isn't a good idea, could you please advise how a task could use grunt API to figure out whether Gruntfile was required successfully?

Based on https://youtrack.jetbrains.com/issue/WEB-11338:
Even if Gruntfile is incorrect, WebStorm Grunt integration prints:

...
Running "_intellij_grunt_tasks_fetcher" task
{"aliasTasks":[],"coreTasks":[]}

Done, without errors. 
@shama
Copy link
Member

shama commented Nov 24, 2015

Closing as this doesn't seem like an issue with Grunt but a configuration issue with WebStorm. Please let us know if it is in fact an issue with Grunt. Thanks!

@shama shama closed this as completed Nov 24, 2015
@segrey
Copy link
Author

segrey commented Nov 24, 2015

Yes, you're correct, this issue is not about Grunt itself. I'd say it's about smooth interoperability between Grunt and tools (e.g. IDE). Usually, tools need to list available task, like grunt --help does in its Available tasks section. AFAIK, currently grunt doesn't support producing machine readable output containing all found tasks. So, WebStorm applies the following workaround: it registers and runs its own task that uses grunt private API to dump all tasks in json format:

grunt --gruntfile /path/to/users/Gruntfile.js --tasks /path/to/ide/tasks _intellij_grunt_tasks_fetcher

Source code of _intellij_grunt_tasks_fetcher is bundled with WebStorm. Also, I've created a gist grunt-tasks-fetcher.js for easier access.

Ideally, grunt could support out-of-the-box dumping tasks description in json format (via some cli option, e.g. gulp v4 has --tasks-json). That would allow tools to drop maintaining grunt private API usages.

As a small step forward better interop, what do you think about this issue?
I can be wrong, but skipping running grunt task if Gruntfile has errors seems like a reasonable thing to me. Does it break grunt design or some workflow?
Otherwise, unfortunately, I don't see a good way to fix https://youtrack.jetbrains.com/issue/WEB-11338: the console error output will always end with confusing "Done, without errors." message. Thanks!

@shama
Copy link
Member

shama commented Nov 24, 2015

So the feature request here is to provide an API to output the tasks in a JSON format?

@segrey
Copy link
Author

segrey commented Nov 24, 2015

Providing an API is a possible way to improve interop. Other ways are:

  • skipping running grunt task if Gruntfile has errors (this issue)
  • introducing a new cli flag that will dump the tasks in a JSON format

IMO, the proper way is introducing a new cli flag. In this case tools don't have to maintain similar small wrappers dumping JSON. I understand it might be taken as overkill, so I'd be happy if grunt tasks just aren't run in case of errors. :) Thanks.

Probably, I should have provided better description in the first place. Sorry about that.

@shama
Copy link
Member

shama commented Nov 24, 2015

skipping running grunt task if Gruntfile has errors (this issue)

I'm not sure what this means. Are you talking javascript syntax errors? Each task handles it's own errors and then Grunt by default will stop running tasks unless --force was provided.

@segrey
Copy link
Author

segrey commented Nov 24, 2015

Yes, about javascript syntax errors. To be more specific when grunt console runner rejects to run specified task. IIUC, it happens when gruntfile cannot be loaded

grunt.log.write(msg).error().verbose.error(e.stack).or.error(e);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants