Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Support JSON stats output #16

Closed
1 of 3 tasks
billyjanitsch opened this issue May 9, 2018 · 7 comments
Closed
1 of 3 tasks

Support JSON stats output #16

billyjanitsch opened this issue May 9, 2018 · 7 comments

Comments

@billyjanitsch
Copy link

billyjanitsch commented May 9, 2018

  • Operating System: macOS 10.13.4
  • Node Version: 10.0.0
  • NPM Version: 6.0.0
  • webpack Version: 4.8.1
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --json
webpack.config.js

n/a

Expected Behavior

webpack-cli (and formerly the bundled webpack CLI) has a --json arg which causes the stats to be printed out as JSON. This is extremely useful for piping into files which can then be uploaded to web-based bundle analysis tools.

It would be great if webpack-command could support this flag or something equivalent -- perhaps through a reporter. Since webpack-command is already working with the JSON stats, I assume this would be a low-overhead feature to support.

I'm about to take a vacation but I might be able to get a PR out before I leave if this sounds reasonable to you.

Actual Behavior

There is currently no way to get the build stats as JSON.

New Feature Use Case

See expected behavior above.

@shellscape
Copy link
Contributor

@billyjanitsch thanks for the issue 🍺

This is exactly why we have the ability to write custom reporters. (And if you get one working that you like, and you think would be useful, it could be submitted for inclusion by default). I'd use the BasicReporter as a template for that.

@billyjanitsch
Copy link
Author

Cool. I will PR a JSON reporter either before or after my vacation.

These lines will be a problem because there is no way to disable them, and it's important that this reporter print only a single valid JSON object. Do you mind if I change the internals to allow the reporter to disable all other output, or is there a better option?

@shellscape
Copy link
Contributor

You can actually pull some trickery with that log object. In the constructor for your reporter:

this.log = weblog({ name: 'webpack', id: 'webpack-command' });
this.setLogLevel = log.logLevel;
log.logLevel = 'silent';

And then in the render method for your reporter, restore the level:

this.log.logLevel = this.setLogLevel;

Though I'm not sure if that's needed, especially if your reporter is only intended to report JSON and nothing more. Something else to consider: writing the JSON output to stderr so you can still allow the logging as per usual, but then could redirect stderr to a file or for examination by another process. That'd be the best of both worlds.

@valscion
Copy link
Member

Something else to consider: writing the JSON output to stderr so you can still allow the logging as per usual, but then could redirect stderr to a file or for examination by another process. That'd be the best of both worlds.

Could we instead do the opposite? If I'm not mistaken, it's common practice to log informational output to stderr if stdout will be used for e.g. piping.

Here's one nice blog post summarizing what I've understood stderr and stdout should be used for: https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

@shellscape
Copy link
Contributor

@valscion welcome to the nuances of writing tooling in the webpack ecosystem: no matter how many considerations you make for how people are going to work with a thing, someone will always have another method they're asking to account for 😄

There hasn't been a huge demand for this yet, so I really have no preference for how this functions. No one has stepped up to provide this in a PR yet.

@valscion
Copy link
Member

I hope my comment wasn't coming through as assertative. Didn't mean to bring bad feelings. (I feel the need to apologise as your reply comes off a bit snarky, and I worry it's my fault)

Anyway. Great to hear that either way goes ☺️. I'm in the process of painfully migrating to webpack 4 and wanted to use webpack-command, and as I'm maintaining webpack-bundle-analyzer, having the --json flag supported here would be useful to allow for the CLI usage of webpack-bundle-analyzer.

I might get to writing this JSON reporter, depending on how much energy this migration will end up consuming 😅

@shellscape
Copy link
Contributor

shellscape commented Jun 18, 2018

I hope my comment wasn't coming through as assertative. Didn't mean to bring bad feelings. (I feel the need to apologise as your reply comes off a bit snarky, and I worry it's my fault)

Tangent: I believe people anymore are way too worried about the mere possibility of offending someone. My reply contained no snark, it was straight truth. And it even had a smiley face. If your reply offended anyone, they can go jump in a lake, because it was absolutely fine and perfectly illustrated the nuances I mentioned.

shellscape added a commit that referenced this issue Jun 23, 2018
goto-bus-stop pushed a commit to goto-bus-stop/react-abstract-autocomplete that referenced this issue Jun 25, 2018
## Version **0.3.0** of **[webpack-command](https://github.com/webpack-contrib/webpack-command)** was just published.

<table>
  <tr>
    <th align=left>
      Dependency
    </th>
    <td>
      <code>[webpack-command](https://github.com/webpack-contrib/webpack-command)</code>
    </td>
  </tr>
  <tr>
      <th align=left>
       Current Version
      </th>
      <td>
        0.2.1
      </td>
    </tr>
  <tr>
    <th align=left>
      Type
    </th>
    <td>
      devDependency
    </td>
  </tr>
</table>



The version **0.3.0** is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

It might be worth looking into these changes and trying to get this project onto the latest version of webpack-command.

If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


---


<details>
<summary>Release Notes</summary>
<strong>v0.3.0</strong>

<h2>Bugfixes</h2>
<ul>
<li>fix: define flag documentation, run-dev and run-prod implementation (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="332770158" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#34" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/34">#34</a>)</li>
<li>fix: add handling for exit codes on error (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="332811830" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#35" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/35">#35</a>)</li>
<li>fix: context overriden by flags default value. fixes <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="333107805" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#36" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/issues/36">#36</a> (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="335098804" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#38" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/38">#38</a>)</li>
</ul>
<h2>Features</h2>
<ul>
<li>feat: warn if bail is used in watch mode (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="324626565" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#21" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/21">#21</a>)</li>
<li>feat: allow --reporter to be relative to CWD (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="328774213" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#24" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/24">#24</a>)</li>
<li>feat: add JSON reporter. fixes <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="321608573" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#16" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/issues/16">#16</a> (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="335103834" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#39" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/39">#39</a>)</li>
<li>feat: export <code>wp</code> binary in package to avoid binary name conflicts (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="335137725" data-permission-text="Issue title is private" data-url="webpack-contrib/webpack-command#40" href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/pull/40">#40</a>)</li>
</ul>
<h2>Updates</h2>
<p><code>webpack-command</code> is no longer just a proof of concept, but a legitimate replacement for webpack-cli.</p>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 15 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/11e7799c81c0af9d3356243d83acb75c6a5af8e2"><code>11e7799</code></a> <code>chore(release): 0.3.0</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/77e64110141c540bf38ae3f267ab0d03aa3cbde4"><code>77e6411</code></a> <code>chore: update circleci config</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/9c232b749b8abdd94022659da7b92f92cbb9a272"><code>9c232b7</code></a> <code>test: update relative path reporter test snapshot</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/a5cff710f4e02b7679597a6d9b10eb8f595525df"><code>a5cff71</code></a> <code>feat: allow --reporter to be relative to CWD (#24)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/5786adc88548ff6fbed8831aa3cb339fa06c9d81"><code>5786adc</code></a> <code>docs: update README details</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/17a73b49512e946afb6b129f4ac7dad174ddce18"><code>17a73b4</code></a> <code>chore: eslint@5 has issues with eslint-webpack-config. downgrade</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/a31d9c511639962b7642b608d80753181d9357b8"><code>a31d9c5</code></a> <code>chore: update deps, metadata</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/19b486acf297f7b1a22af8ab65df22e343efc831"><code>19b486a</code></a> <code>test: update reporter snapshots for context fix</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/ec6406089c13590e300b1c0f5a1bb43b95df5632"><code>ec64060</code></a> <code>fix: add handling for exit codes on error (#35)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/76f6869762dcb2b87c28d1fe780700f4efff336a"><code>76f6869</code></a> <code>feat: add JSON reporter. fixes #16 (#39)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/5afbcee76e769026e8ef8ba9c72af7ecb91707d0"><code>5afbcee</code></a> <code>feat: export <code>wp</code> binary in package to avoid binary name conflicts (#40)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/331eb8d39eeddde959b731d21afc68c0defcdafb"><code>331eb8d</code></a> <code>fix: context overriden by flags default value. fixes #36 (#38)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/204b5f9ee381813ea3e7d35681ab153eccf3c196"><code>204b5f9</code></a> <code>feat: warn if bail is used in watch mode (#21)</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/32d4f63e47fe459ac3cb6d40a477f148a5b768e1"><code>32d4f63</code></a> <code>docs: remove "proof of concept" from description</code></li>
<li><a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/commit/75ff73c1389f1c4575318116185d8bbe8b7aa515"><code>75ff73c</code></a> <code>fix: define flag documentation, run-dev and run-prod implementation (#34)</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/webpack-contrib/webpack-command/compare/63c94a347cc67f3d14b6e99d9416a0c6866751b8...11e7799c81c0af9d3356243d83acb75c6a5af8e2">full diff</a></p>
</details>

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants