This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+514
View File
@@ -0,0 +1,514 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
# [4.0.0](https://github.com/nuxt/webpackbar/compare/v3.2.0...v4.0.0) (2019-08-05)
### chore
* **deps:** update dependency wrap-ansi to v6 ([#49](https://github.com/nuxt/webpackbar/issues/49)) ([0970f70](https://github.com/nuxt/webpackbar/commit/0970f70))
### BREAKING CHANGES
* **deps:** Require Node.js 8
<a name="3.2.0"></a>
# [3.2.0](https://github.com/nuxt/webpackbar/compare/v3.1.5...v3.2.0) (2019-04-18)
### Bug Fixes
* path can be something else than a string ([#45](https://github.com/nuxt/webpackbar/issues/45)) ([b2ae0c9](https://github.com/nuxt/webpackbar/commit/b2ae0c9))
* **pkg:** remove nsp ([73ef3ae](https://github.com/nuxt/webpackbar/commit/73ef3ae))
### Features
* update dependencies ([9fc93e9](https://github.com/nuxt/webpackbar/commit/9fc93e9))
<a name="3.1.5"></a>
## [3.1.5](https://github.com/nuxt/webpackbar/compare/v3.1.4...v3.1.5) (2019-01-12)
### Bug Fixes
* **fancy:** eliminate the probability of replacement of stream.write conflicts ([#39](https://github.com/nuxt/webpackbar/issues/39)) ([b3b9c62](https://github.com/nuxt/webpackbar/commit/b3b9c62))
<a name="3.1.4"></a>
## [3.1.4](https://github.com/nuxt/webpackbar/compare/v3.1.3...v3.1.4) (2018-12-11)
### Bug Fixes
* avoid object.values for node < 7 compability ([83fcd06](https://github.com/nuxt/webpackbar/commit/83fcd06))
<a name="3.1.3"></a>
## [3.1.3](https://github.com/nuxt/webpackbar/compare/v3.1.2...v3.1.3) (2018-11-14)
<a name="3.1.2"></a>
## [3.1.2](https://github.com/nuxt/webpackbar/compare/v3.1.1...v3.1.2) (2018-11-09)
### Bug Fixes
* **profile:** use context.state ([0d92aae](https://github.com/nuxt/webpackbar/commit/0d92aae))
* revert back afterPlugins to call _ensureState ([2f17454](https://github.com/nuxt/webpackbar/commit/2f17454))
* update profile reporter ([4f28403](https://github.com/nuxt/webpackbar/commit/4f28403))
* **stats:** fix typo ([d2f6edb](https://github.com/nuxt/webpackbar/commit/d2f6edb))
<a name="3.1.1"></a>
## [3.1.1](https://github.com/nuxt/webpackbar/compare/v3.1.0...v3.1.1) (2018-11-09)
### Bug Fixes
* prevent calling done hook twice ([1753826](https://github.com/nuxt/webpackbar/commit/1753826))
* **plugin:** handle conditions that start is not available ([4e0dc73](https://github.com/nuxt/webpackbar/commit/4e0dc73))
<a name="3.1.0"></a>
# [3.1.0](https://github.com/nuxt/webpackbar/compare/v3.0.5...v3.1.0) (2018-11-09)
### Features
* prevent adding multi instances to the same compiler ([759a4e6](https://github.com/nuxt/webpackbar/commit/759a4e6))
* **log-update:** support concurrent writes to stdout/stderr on render ([d51c508](https://github.com/nuxt/webpackbar/commit/d51c508))
<a name="3.0.5"></a>
## [3.0.5](https://github.com/nuxt/webpackbar/compare/v3.0.4...v3.0.5) (2018-11-09)
### Bug Fixes
* detect and support old consola instance ([9fc6e09](https://github.com/nuxt/webpackbar/commit/9fc6e09))
<a name="3.0.4"></a>
## [3.0.4](https://github.com/nuxt/webpackbar/compare/v3.0.3...v3.0.4) (2018-11-09)
### Bug Fixes
* ensure state exists on hooks ([#30](https://github.com/nuxt/webpackbar/issues/30)) ([8f0085a](https://github.com/nuxt/webpackbar/commit/8f0085a))
<a name="3.0.3"></a>
## [3.0.3](https://github.com/nuxt/webpackbar/compare/v3.0.2...v3.0.3) (2018-11-08)
<a name="3.0.2"></a>
## [3.0.2](https://github.com/nuxt/webpackbar/compare/v3.0.1...v3.0.2) (2018-11-08)
### Bug Fixes
* **fancy:** resume consola befor we die! ([ea1c6a8](https://github.com/nuxt/webpackbar/commit/ea1c6a8))
* **stats:** report errors before we die ([53aa6bb](https://github.com/nuxt/webpackbar/commit/53aa6bb))
<a name="3.0.1"></a>
## [3.0.1](https://github.com/nuxt/webpackbar/compare/v3.0.0...v3.0.1) (2018-11-08)
### Bug Fixes
* windows and linux don't support fsync ([8be7459](https://github.com/nuxt/webpackbar/commit/8be7459))
<a name="3.0.0"></a>
# [3.0.0](https://github.com/nuxt/webpackbar/compare/v3.0.0-3...v3.0.0) (2018-11-07)
<a name="3.0.0-3"></a>
# [3.0.0-3](https://github.com/nuxt/webpackbar/compare/v3.0.0-2...v3.0.0-3) (2018-11-07)
### Bug Fixes
* unused plugin instances store state in global ([556f830](https://github.com/nuxt/webpackbar/commit/556f830))
### Features
* add change hook support ([8057e4c](https://github.com/nuxt/webpackbar/commit/8057e4c))
<a name="3.0.0-2"></a>
# [3.0.0-2](https://github.com/nuxt/webpackbar/compare/v3.0.0-1...v3.0.0-2) (2018-11-04)
### Bug Fixes
* convert name using startCase ([4264503](https://github.com/nuxt/webpackbar/commit/4264503))
* fix globalState bug ([8c0441b](https://github.com/nuxt/webpackbar/commit/8c0441b))
* handler assignment should be happened after super() call ([150699d](https://github.com/nuxt/webpackbar/commit/150699d))
* minor fixes ([d7a10c9](https://github.com/nuxt/webpackbar/commit/d7a10c9))
* refactor and memory improvements ([74d265a](https://github.com/nuxt/webpackbar/commit/74d265a))
* stability and improvements ([7e3e9ad](https://github.com/nuxt/webpackbar/commit/7e3e9ad))
* typo ([5dcd6bf](https://github.com/nuxt/webpackbar/commit/5dcd6bf))
* use compile instead of beforeCompile to prevent duplicate calls ([05cf301](https://github.com/nuxt/webpackbar/commit/05cf301))
### Features
* allow easily disabling reporters ([f96ad47](https://github.com/nuxt/webpackbar/commit/f96ad47))
* improve stats reporter ([09459af](https://github.com/nuxt/webpackbar/commit/09459af))
* rework bars reporter using a rewrite of log-update ([d918a9a](https://github.com/nuxt/webpackbar/commit/d918a9a))
### Reverts
* revert 100% check condition ([c2632ef](https://github.com/nuxt/webpackbar/commit/c2632ef))
<a name="3.0.0-1"></a>
# [3.0.0-1](https://github.com/nuxt/webpackbar/compare/v3.0.0-0...v3.0.0-1) (2018-11-02)
### Features
* **bars:** consola integration ([8db1118](https://github.com/nuxt/webpackbar/commit/8db1118))
* consola integration with bars ([1c22321](https://github.com/nuxt/webpackbar/commit/1c22321))
* use a shared throttle for bars ([91512c1](https://github.com/nuxt/webpackbar/commit/91512c1))
<a name="3.0.0-0"></a>
# [3.0.0-0](https://github.com/nuxt/webpackbar/compare/v2.6.3...v3.0.0-0) (2018-11-02)
### Bug Fixes
* avoid using null details ([c72c7c1](https://github.com/nuxt/webpackbar/commit/c72c7c1))
* fix hasRunning and and hasErrors ([2241cd7](https://github.com/nuxt/webpackbar/commit/2241cd7))
* fix imports ([226dbe2](https://github.com/nuxt/webpackbar/commit/226dbe2))
* fix utils ([9d60a17](https://github.com/nuxt/webpackbar/commit/9d60a17))
* handle hook errors ([c24b341](https://github.com/nuxt/webpackbar/commit/c24b341))
* handle reporter errors ([20e78c1](https://github.com/nuxt/webpackbar/commit/20e78c1))
* preserve start time and stats until next compile ([c93de65](https://github.com/nuxt/webpackbar/commit/c93de65))
* remove extra state field ([ab32217](https://github.com/nuxt/webpackbar/commit/ab32217))
* Remove unused dependencies ([#23](https://github.com/nuxt/webpackbar/issues/23)) ([2ab0dd2](https://github.com/nuxt/webpackbar/commit/2ab0dd2))
* **bars:** remove extra ending new line ([695fc56](https://github.com/nuxt/webpackbar/commit/695fc56))
* replace Object.values for node 6.x compability ([#17](https://github.com/nuxt/webpackbar/issues/17)) ([d004bb6](https://github.com/nuxt/webpackbar/commit/d004bb6))
* typos ([3b5c9cf](https://github.com/nuxt/webpackbar/commit/3b5c9cf))
* unshift built-in reporters ([007c9c5](https://github.com/nuxt/webpackbar/commit/007c9c5))
* update std-env to 2.1.0 ([e720ad8](https://github.com/nuxt/webpackbar/commit/e720ad8))
### Features
* reporters and draftlog ([6541a1c](https://github.com/nuxt/webpackbar/commit/6541a1c))
* support single reporter option ([0a10a08](https://github.com/nuxt/webpackbar/commit/0a10a08))
### Performance Improvements
* remove lodash dependency ([#22](https://github.com/nuxt/webpackbar/issues/22)) ([883a0dc](https://github.com/nuxt/webpackbar/commit/883a0dc))
* use text-table for less package size ([#22](https://github.com/nuxt/webpackbar/issues/22)) ([ea22b7b](https://github.com/nuxt/webpackbar/commit/ea22b7b))
<a name="2.6.3"></a>
## [2.6.3](https://github.com/nuxt/webpackbar/compare/v2.6.2...v2.6.3) (2018-08-18)
<a name="2.6.2"></a>
## [2.6.2](https://github.com/nuxt/webpackbar/compare/v2.6.1...v2.6.2) (2018-08-12)
### Bug Fixes
* ESLint is broken when using eslint-plugin-import ([783f243](https://github.com/nuxt/webpackbar/commit/783f243))
<a name="2.6.1"></a>
## [2.6.1](https://github.com/nuxt/webpackbar/compare/v2.6.0...v2.6.1) (2018-04-04)
### Bug Fixes
* fix ellipsis logic ([0fdb30f](https://github.com/nuxt/webpackbar/commit/0fdb30f))
<a name="2.6.0"></a>
# [2.6.0](https://github.com/nuxt/webpackbar/compare/v2.5.0...v2.6.0) (2018-04-04)
### Features
* cli improvements ([76d7306](https://github.com/nuxt/webpackbar/commit/76d7306))
<a name="2.5.0"></a>
# [2.5.0](https://github.com/nuxt/webpackbar/compare/v2.4.0...v2.5.0) (2018-04-04)
### Features
* windows visual improvements ([2ae8339](https://github.com/nuxt/webpackbar/commit/2ae8339))
<a name="2.4.0"></a>
# [2.4.0](https://github.com/nuxt/webpackbar/compare/v2.3.2...v2.4.0) (2018-04-01)
### Features
* add compile stats to the sharedState ([3973f6b](https://github.com/nuxt/webpackbar/commit/3973f6b))
<a name="2.3.2"></a>
## [2.3.2](https://github.com/nuxt/webpackbar/compare/v2.3.1...v2.3.2) (2018-03-31)
### Bug Fixes
* hot update for consola ([1d13980](https://github.com/nuxt/webpackbar/commit/1d13980))
<a name="2.3.1"></a>
## [2.3.1](https://github.com/nuxt/webpackbar/compare/v2.3.0...v2.3.1) (2018-03-31)
### Bug Fixes
* consola 1.1.1 ([b44fd11](https://github.com/nuxt/webpackbar/commit/b44fd11))
<a name="2.3.0"></a>
# [2.3.0](https://github.com/nuxt/webpackbar/compare/v2.2.1...v2.3.0) (2018-03-31)
### Features
* **colorize:** try chalk built-in colors first ([73fd89e](https://github.com/nuxt/webpackbar/commit/73fd89e))
<a name="2.2.1"></a>
## [2.2.1](https://github.com/nuxt/webpackbar/compare/v2.2.0...v2.2.1) (2018-03-31)
<a name="2.2.0"></a>
# [2.2.0](https://github.com/nuxt/webpackbar/compare/v2.1.0...v2.2.0) (2018-03-31)
### Features
* consola integration ([d99f254](https://github.com/nuxt/webpackbar/commit/d99f254))
<a name="2.1.0"></a>
# [2.1.0](https://github.com/nuxt/webpackbar/compare/v2.0.3...v2.1.0) (2018-03-31)
### Features
* show inactive parallel tasks ([2862002](https://github.com/nuxt/webpackbar/commit/2862002))
<a name="2.0.3"></a>
## [2.0.3](https://github.com/nuxt/webpackbar/compare/v2.0.2...v2.0.3) (2018-03-31)
### Bug Fixes
* honor options.stream everywhere ([34733b7](https://github.com/nuxt/webpackbar/commit/34733b7))
<a name="2.0.2"></a>
## [2.0.2](https://github.com/nuxt/webpackbar/compare/v2.0.1...v2.0.2) (2018-03-31)
### Bug Fixes
* fix compiled message in minimal mode ([80f7ac2](https://github.com/nuxt/webpackbar/commit/80f7ac2))
<a name="2.0.1"></a>
## [2.0.1](https://github.com/nuxt/webpackbar/compare/v2.0.0...v2.0.1) (2018-03-31)
### Bug Fixes
* fix cannot read property 'write' of undefined ([ccb1d65](https://github.com/nuxt/webpackbar/commit/ccb1d65))
<a name="2.0.0"></a>
# [2.0.0](https://github.com/nuxt/webpackbar/compare/v1.5.1...v2.0.0) (2018-03-31)
### Features
* v2 rewrite ([5151960](https://github.com/nuxt/webpackbar/commit/5151960))
### BREAKING CHANGES
* behaviour and options changed. Refer to the new docs
<a name="1.5.1"></a>
## [1.5.1](https://github.com/nuxt/webpackbar/compare/v1.5.0...v1.5.1) (2018-03-28)
### Bug Fixes
* call done hook last ([642a9ef](https://github.com/nuxt/webpackbar/commit/642a9ef))
<a name="1.5.0"></a>
# [1.5.0](https://github.com/nuxt/webpackbar/compare/v1.4.0...v1.5.0) (2018-03-28)
### Features
* options.buildTitle & consistent number of output lines ([1263fc1](https://github.com/nuxt/webpackbar/commit/1263fc1))
<a name="1.4.0"></a>
# [1.4.0](https://github.com/nuxt/webpackbar/compare/v1.3.0...v1.4.0) (2018-03-28)
### Features
* accept done callback as an option ([30bfd1e](https://github.com/nuxt/webpackbar/commit/30bfd1e))
* better handling for 100% state and clear: false ([a2c823f](https://github.com/nuxt/webpackbar/commit/a2c823f))
<a name="1.3.0"></a>
# [1.3.0](https://github.com/nuxt/webpackbar/compare/v1.2.1...v1.3.0) (2018-03-27)
### Features
* enabled option with smart defaults. ([0d22e4c](https://github.com/nuxt/webpackbar/commit/0d22e4c))
<a name="1.2.1"></a>
## [1.2.1](https://github.com/nuxt/webpackbar/compare/v1.2.0...v1.2.1) (2018-03-27)
### Bug Fixes
* default clear to true ([528b769](https://github.com/nuxt/webpackbar/commit/528b769))
<a name="1.2.0"></a>
# [1.2.0](https://github.com/nuxt/webpackbar/compare/v1.1.4...v1.2.0) (2018-03-27)
### Features
* new options: stream, profile, clear and showCursor. ([#3](https://github.com/nuxt/webpackbar/issues/3)) ([80f5f17](https://github.com/nuxt/webpackbar/commit/80f5f17))
* support hex colors. ([#2](https://github.com/nuxt/webpackbar/issues/2)) ([1c7cc0b](https://github.com/nuxt/webpackbar/commit/1c7cc0b))
<a name="1.1.4"></a>
## [1.1.4](https://github.com/nuxt/webpackbar/compare/v1.1.3...v1.1.4) (2018-03-26)
### Bug Fixes
* webpack 3 compability ([#1](https://github.com/nuxt/webpackbar/issues/1)) ([ff24c14](https://github.com/nuxt/webpackbar/commit/ff24c14))
<a name="1.1.3"></a>
## [1.1.3](https://github.com/nuxt/webpackbar/compare/v1.1.2...v1.1.3) (2018-03-24)
### Bug Fixes
* remove debug ([a27a83c](https://github.com/nuxt/webpackbar/commit/a27a83c))
<a name="1.1.2"></a>
## [1.1.2](https://github.com/nuxt/webpackbar/compare/v1.1.1...v1.1.2) (2018-03-24)
### Bug Fixes
* **profile:** ignore requests without any file or loaders ([d3eb446](https://github.com/nuxt/webpackbar/commit/d3eb446))
<a name="1.1.1"></a>
## [1.1.1](https://github.com/nuxt/webpackbar/compare/v1.1.0...v1.1.1) (2018-03-24)
<a name="1.1.0"></a>
# [1.1.0](https://github.com/nuxt/webpackbar/compare/v1.0.0...v1.1.0) (2018-03-24)
### Features
* build profiler ([0c05d65](https://github.com/nuxt/webpackbar/commit/0c05d65))
<a name="1.0.0"></a>
# 1.0.0 (2018-03-24)
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
x.x.x / <year>-<month>-<day>
==================
* Bug fix -
* Feature -
* Chore -
* Docs -
+20
View File
@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+189
View File
@@ -0,0 +1,189 @@
[![Standard JS][standard-js-src]][standard-js-href]
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![package phobia][package-phobia-src]][package-phobia-href]
<div align="center">
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
<img width="200" height="200" hspace="25" src="./assets/logo.svg">
<a href="https://webpack.js.org/">
<img width="200" height="200" hspace="25" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
</a>
<p>Elegant ProgressBar and Profiler for Webpack</p>
</div>
✔ Display elegant progress bar while building or watch
✔ Support of multiple concurrent builds (useful for SSR)
✔ Pretty print filename and loaders
✔ Windows compatible
✔ **Fully** customizable using reporters
✔ Advanced build profiler
<div align="center">
<br>
<img src="./assets/screen1.png" width="600px">
<p>Multi progress bars</p>
<br>
</div>
<div align="center">
<br>
<img src="./assets/screen2.png" width="600px">
<p>Build Profiler</p>
<br>
</div>
<h2 align="center">Getting Started</h2>
To begin, you'll need to install `webpackbar`:
Using npm:
```bash
npm install webpackbar -D
```
Using yarn:
```bash
yarn add webpackbar -D
```
Then add the reporter as a plugin to your webpack config.
**webpack.config.js**
```js
const webpack = require('webpack');
const WebpackBar = require('webpackbar');
module.exports = {
context: path.resolve(__dirname),
devtool: 'source-map',
entry: './entry.js',
output: {
filename: './output.js',
path: path.resolve(__dirname)
},
plugins: [
new WebpackBar()
]
};
```
<h2 align="center">Options</h2>
### `name`
- Default: `webpack`
Name.
### `color`
- Default: `green`
Primary color (can be HEX like `#xxyyzz` or a web color like `green`).
### `profile`
- Default: `false`
Enable profiler.
### `fancy`
- Default: `true` when not in CI or testing mode.
Enable bars reporter.
### `basic`
- Default: `true` when running in minimal environments.
Enable a simple log reporter (only start and end).
### `reporter`
Register a custom reporter.
### `reporters`
- Default: `[]`
Register an Array of your custom reporters. (Same as `reporter` but array)
<h2 align="center">Custom Reporters</h2>
Webpackbar comes with a fancy progress-bar out of the box.
But you may want to show progress somewhere else or provide your own.
For this purpose, you can provide one or more extra reporters using `reporter` and `reporters` options.
**NOTE:** If you plan to provide your own reporter, don't forget to setting `fancy` and `basic` options to false to prevent conflicts.
A reporter should be instance of a class or plain object and functions for special hooks. It is not necessary to implement all functions, webpackbar only calls those that exists.
**Simple logger:**
```js
{
start(context) {
// Called when (re)compile is started
},
change(context) {
// Called when a file changed on watch mode
},
update(context) {
// Called after each progress update
},
done(context) {
// Called when compile finished
},
progress(context) {
// Called when build progress updated
},
allDone(context) {
// Called when _all_ compiles finished
},
beforeAllDone(context) {
},
afterAllDone(context) {
},
}
```
`context` is the reference to the plugin. You can use `context.state` to access status.
**Schema of `context.state`:**
```js
{
start,
progress,
message,
details,
request,
hasErrors
}
```
<h2 align="center">License</h2>
MIT - Made with 💖 By Nuxt.js team!
<!-- Refs -->
[standard-js-src]: https://flat.badgen.net/badge/code%20style/standard/green
[standard-js-href]: https://standardjs.com
[npm-version-src]: https://flat.badgen.net/npm/v/webpackbar/latest
[npm-version-href]: https://npmjs.com/package/webpackbar
[npm-downloads-src]: https://flat.badgen.net/npm/dt/webpackbar
[npm-downloads-href]: https://npmjs.com/package/webpackbar
[package-phobia-src]: https://flat.badgen.net/packagephobia/install/webpackbar
[package-phobia-href]: https://packagephobia.now.sh/result?p=webpackbar
+706
View File
@@ -0,0 +1,706 @@
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var webpack = require('webpack');
var env = _interopDefault(require('std-env'));
var prettyTime = _interopDefault(require('pretty-time'));
var path = require('path');
var path__default = _interopDefault(path);
var chalk = _interopDefault(require('chalk'));
var Consola = _interopDefault(require('consola'));
var textTable = _interopDefault(require('text-table'));
var figures = require('figures');
var ansiEscapes = _interopDefault(require('ansi-escapes'));
var wrapAnsi = _interopDefault(require('wrap-ansi'));
function first(arr) {
return arr[0];
}
function last(arr) {
return arr.length ? arr[arr.length - 1] : null;
}
function startCase(str) {
return str[0].toUpperCase() + str.substr(1);
}
function firstMatch(regex, str) {
const m = regex.exec(str);
return m ? m[0] : null;
}
function hasValue(s) {
return s && s.length;
}
function removeAfter(delimiter, str) {
return first(str.split(delimiter)) || '';
}
function removeBefore(delimiter, str) {
return last(str.split(delimiter)) || '';
}
function range(len) {
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(i);
}
return arr;
}
function shortenPath(path$1 = '') {
const cwd = process.cwd() + path.sep;
return String(path$1).replace(cwd, '');
}
function objectValues(obj) {
return Object.keys(obj).map(key => obj[key]);
}
const nodeModules = `${path__default.delimiter}node_modules${path__default.delimiter}`;
const BAR_LENGTH = 25;
const BLOCK_CHAR = '█';
const BLOCK_CHAR2 = '█';
const NEXT = ' ' + chalk.blue(figures.pointerSmall) + ' ';
const BULLET = figures.bullet;
const TICK = figures.tick;
const CROSS = figures.cross;
const CIRCLE_OPEN = figures.radioOff;
const consola = Consola.withTag('webpackbar');
const colorize = color => {
if (color[0] === '#') {
return chalk.hex(color);
}
return chalk[color] || chalk.keyword(color);
};
const renderBar = (progress, color) => {
const w = progress * (BAR_LENGTH / 100);
const bg = chalk.white(BLOCK_CHAR);
const fg = colorize(color)(BLOCK_CHAR2);
return range(BAR_LENGTH).map(i => i < w ? fg : bg).join('');
};
function createTable(data) {
return textTable(data, {
align: data[0].map(() => 'l')
}).replace(/\n/g, '\n\n');
}
function ellipsisLeft(str, n) {
if (str.length <= n - 3) {
return str;
}
return `...${str.substr(str.length - n - 1)}`;
}
const parseRequest = requestStr => {
const parts = (requestStr || '').split('!');
const file = path__default.relative(process.cwd(), removeAfter('?', removeBefore(nodeModules, parts.pop())));
const loaders = parts.map(part => firstMatch(/[a-z0-9-@]+-loader/, part)).filter(hasValue);
return {
file: hasValue(file) ? file : null,
loaders
};
};
const formatRequest = request => {
const loaders = request.loaders.join(NEXT);
if (!loaders.length) {
return request.file || '';
}
return `${loaders}${NEXT}${request.file}`;
}; // Hook helper for webpack 3 + 4 support
function hook(compiler, hookName, fn) {
if (compiler.hooks) {
compiler.hooks[hookName].tap('WebpackBar:' + hookName, fn);
} else {
compiler.plugin(hookName, fn);
}
}
const originalWrite = Symbol('webpackbarWrite');
class LogUpdate {
constructor() {
this.prevLineCount = 0;
this.listening = false;
this.extraLines = '';
this._onData = this._onData.bind(this);
this._streams = [process.stdout, process.stderr];
}
render(lines) {
this.listen();
const wrappedLines = wrapAnsi(lines, this.columns, {
trim: false,
hard: true,
wordWrap: false
});
const data = ansiEscapes.eraseLines(this.prevLineCount) + wrappedLines + '\n' + this.extraLines;
this.write(data);
this.prevLineCount = data.split('\n').length;
}
get columns() {
return (process.stderr.columns || 80) - 2;
}
write(data) {
const stream = process.stderr;
if (stream.write[originalWrite]) {
stream.write[originalWrite].call(stream, data, 'utf-8');
} else {
stream.write(data, 'utf-8');
}
}
clear() {
this.done();
this.write(ansiEscapes.eraseLines(this.prevLineCount));
}
done() {
this.stopListen();
this.prevLineCount = 0;
this.extraLines = '';
}
_onData(data) {
const str = String(data);
const lines = str.split('\n').length - 1;
if (lines > 0) {
this.prevLineCount += lines;
this.extraLines += data;
}
}
listen() {
// Prevent listening more than once
if (this.listening) {
return;
} // Spy on all streams
for (const stream of this._streams) {
// Prevent overriding more than once
if (stream.write[originalWrite]) {
continue;
} // Create a wrapper fn
const write = (data, ...args) => {
if (!stream.write[originalWrite]) {
return stream.write(data, ...args);
}
this._onData(data);
return stream.write[originalWrite].call(stream, data, ...args);
}; // Backup original write fn
write[originalWrite] = stream.write; // Override write fn
stream.write = write;
}
this.listening = true;
}
stopListen() {
// Restore original write fns
for (const stream of this._streams) {
if (stream.write[originalWrite]) {
stream.write = stream.write[originalWrite];
}
}
this.listening = false;
}
}
/* eslint-disable no-console */
const logUpdate = new LogUpdate();
let lastRender = Date.now();
class FancyReporter {
allDone() {
logUpdate.done();
}
done(context) {
this._renderStates(context.statesArray);
if (context.hasErrors) {
logUpdate.done();
}
}
progress(context) {
if (Date.now() - lastRender > 50) {
this._renderStates(context.statesArray);
}
}
_renderStates(statesArray) {
lastRender = Date.now();
const renderedStates = statesArray.map(c => this._renderState(c)).join('\n\n');
logUpdate.render('\n' + renderedStates + '\n');
}
_renderState(state) {
const color = colorize(state.color);
let line1;
let line2;
if (state.progress >= 0 && state.progress < 100) {
// Running
line1 = [color(BULLET), color(state.name), renderBar(state.progress, state.color), state.message, `(${state.progress || 0}%)`, chalk.grey(state.details[0] || ''), chalk.grey(state.details[1] || '')].join(' ');
line2 = state.request ? ' ' + chalk.grey(ellipsisLeft(formatRequest(state.request), logUpdate.columns)) : '';
} else {
let icon = ' ';
if (state.hasErrors) {
icon = CROSS;
} else if (state.progress === 100) {
icon = TICK;
} else if (state.progress === -1) {
icon = CIRCLE_OPEN;
}
line1 = color(`${icon} ${state.name}`);
line2 = chalk.grey(' ' + state.message);
}
return line1 + '\n' + line2;
}
}
class SimpleReporter {
start(context) {
consola.info(`Compiling ${context.state.name}`);
}
change(context, {
shortPath
}) {
consola.debug(`${shortPath} changed.`, `Rebuilding ${context.state.name}`);
}
done(context) {
const {
hasError,
message,
name
} = context.state;
consola[hasError ? 'error' : 'success'](`${name}: ${message}`);
}
}
const DB = {
loader: {
get: loader => startCase(loader)
},
ext: {
get: ext => `${ext} files`,
vue: 'Vue Single File components',
js: 'JavaScript files',
sass: 'SASS files',
scss: 'SASS files',
unknown: 'Unknown files'
}
};
function getDescription(category, keyword) {
if (!DB[category]) {
return startCase(keyword);
}
if (DB[category][keyword]) {
return DB[category][keyword];
}
if (DB[category].get) {
return DB[category].get(keyword);
}
return '-';
}
function formatStats(allStats) {
const lines = [];
Object.keys(allStats).forEach(category => {
const stats = allStats[category];
lines.push(`> Stats by ${chalk.bold(startCase(category))}`);
let totalRequests = 0;
const totalTime = [0, 0];
const data = [[startCase(category), 'Requests', 'Time', 'Time/Request', 'Description']];
Object.keys(stats).forEach(item => {
const stat = stats[item];
totalRequests += stat.count || 0;
const description = getDescription(category, item);
totalTime[0] += stat.time[0];
totalTime[1] += stat.time[1];
const avgTime = [stat.time[0] / stat.count, stat.time[1] / stat.count];
data.push([item, stat.count || '-', prettyTime(stat.time), prettyTime(avgTime), description]);
});
data.push(['Total', totalRequests, prettyTime(totalTime), '', '']);
lines.push(createTable(data));
});
return `${lines.join('\n\n')}\n`;
}
class Profiler {
constructor() {
this.requests = [];
}
onRequest(request) {
if (!request) {
return;
} // Measure time for last request
if (this.requests.length) {
const lastReq = this.requests[this.requests.length - 1];
if (lastReq.start) {
lastReq.time = process.hrtime(lastReq.start);
delete lastReq.start;
}
} // Ignore requests without any file or loaders
if (!request.file || !request.loaders.length) {
return;
}
this.requests.push({
request,
start: process.hrtime()
});
}
getStats() {
const loaderStats = {};
const extStats = {};
const getStat = (stats, name) => {
if (!stats[name]) {
// eslint-disable-next-line no-param-reassign
stats[name] = {
count: 0,
time: [0, 0]
};
}
return stats[name];
};
const addToStat = (stats, name, count, time) => {
const stat = getStat(stats, name);
stat.count += count;
stat.time[0] += time[0];
stat.time[1] += time[1];
};
this.requests.forEach(({
request,
time = [0, 0]
}) => {
request.loaders.forEach(loader => {
addToStat(loaderStats, loader, 1, time);
});
const ext = request.file && path__default.extname(request.file).substr(1);
addToStat(extStats, ext && ext.length ? ext : 'unknown', 1, time);
});
return {
ext: extStats,
loader: loaderStats
};
}
getFormattedStats() {
return formatStats(this.getStats());
}
}
class ProfileReporter {
progress(context) {
if (!context.state.profiler) {
context.state.profiler = new Profiler();
}
context.state.profiler.onRequest(context.state.request);
}
done(context) {
if (context.state.profiler) {
context.state.profile = context.state.profiler.getFormattedStats();
delete context.state.profiler;
}
}
allDone(context) {
let str = '';
for (const state of context.statesArray) {
const color = colorize(state.color);
if (state.profile) {
str += color(`\nProfile results for ${chalk.bold(state.name)}\n`) + `\n${state.profile}\n`;
delete state.profile;
}
}
process.stderr.write(str);
}
}
class StatsReporter {
constructor(options) {
this.options = Object.assign({
chunks: false,
children: false,
modules: false,
colors: true,
warnings: true,
errors: true
}, options);
}
done(context, {
stats
}) {
const str = stats.toString(this.options);
if (context.hasErrors) {
process.stderr.write('\n' + str + '\n');
} else {
context.state.statsString = str;
}
}
allDone(context) {
let str = '';
for (const state of context.statesArray) {
if (state.statsString) {
str += '\n' + state.statsString + '\n';
delete state.statsString;
}
}
process.stderr.write(str);
}
}
var reporters = /*#__PURE__*/Object.freeze({
fancy: FancyReporter,
basic: SimpleReporter,
profile: ProfileReporter,
stats: StatsReporter
});
const DEFAULTS = {
name: 'webpack',
color: 'green',
reporters: env.minimalCLI ? ['basic'] : ['fancy'],
reporter: null // Default state object
};
const DEFAULT_STATE = {
start: null,
progress: -1,
done: false,
message: '',
details: [],
request: null,
hasErrors: false // Mapping from name => State
};
const globalStates = {};
class WebpackBarPlugin extends webpack.ProgressPlugin {
constructor(options) {
super();
this.options = Object.assign({}, DEFAULTS, options); // Assign a better handler to base ProgressPlugin
this.handler = (percent, message, ...details) => {
this.updateProgress(percent, message, details);
}; // Reporters
this.reporters = Array.from(this.options.reporters || []);
if (this.options.reporter) {
this.reporters.push(this.options.reporter);
} // Resolve reporters
this.reporters = this.reporters.filter(Boolean).map(_reporter => {
if (this.options[_reporter] === false) {
return false;
}
let reporter = _reporter;
let reporterOptions = this.options[reporter] || {};
if (Array.isArray(_reporter)) {
reporter = _reporter[0];
if (_reporter[1] === false) {
return false;
}
if (_reporter[1]) {
reporterOptions = _reporter[1];
}
}
if (typeof reporter === 'string') {
if (reporters[reporter]) {
// eslint-disable-line import/namespace
reporter = reporters[reporter]; // eslint-disable-line import/namespace
} else {
reporter = require(reporter);
}
}
if (typeof reporter === 'function') {
if (typeof reporter.constructor === 'function') {
const Reporter = reporter;
reporter = new Reporter(reporterOptions);
} else {
reporter = reporter(reporterOptions);
}
}
return reporter;
}).filter(Boolean);
}
callReporters(fn, payload = {}) {
for (const reporter of this.reporters) {
if (typeof reporter[fn] === 'function') {
try {
reporter[fn](this, payload);
} catch (e) {
process.stdout.write(e.stack + '\n');
}
}
}
}
get hasRunning() {
return objectValues(this.states).some(state => !state.done);
}
get hasErrors() {
return objectValues(this.states).some(state => state.hasErrors);
}
get statesArray() {
return objectValues(this.states).sort((s1, s2) => s1.name.localeCompare(s2.name));
}
get states() {
return globalStates;
}
get state() {
return globalStates[this.options.name];
}
_ensureState() {
// Keep our state in shared object
if (!this.states[this.options.name]) {
this.states[this.options.name] = { ...DEFAULT_STATE,
color: this.options.color,
name: startCase(this.options.name)
};
}
}
apply(compiler) {
// Prevent adding multi instances to the same compiler
if (compiler.webpackbar) {
return;
}
compiler.webpackbar = this; // Apply base hooks
super.apply(compiler); // Register our state after all plugins initialized
hook(compiler, 'afterPlugins', () => {
this._ensureState();
}); // Hook into the compiler before a new compilation is created.
hook(compiler, 'compile', () => {
this._ensureState();
Object.assign(this.state, { ...DEFAULT_STATE,
start: process.hrtime()
});
this.callReporters('start');
}); // Watch compilation has been invalidated.
hook(compiler, 'invalid', (fileName, changeTime) => {
this._ensureState();
this.callReporters('change', {
path: fileName,
shortPath: shortenPath(fileName),
time: changeTime
});
}); // Compilation has completed
hook(compiler, 'done', stats => {
this._ensureState(); // Prevent calling done twice
if (this.state.done) {
return;
}
const hasErrors = stats.hasErrors();
const status = hasErrors ? 'with some errors' : 'successfully';
const time = this.state.start ? ' in ' + prettyTime(process.hrtime(this.state.start), 2) : '';
Object.assign(this.state, { ...DEFAULT_STATE,
progress: 100,
done: true,
message: `Compiled ${status}${time}`,
hasErrors
});
this.callReporters('progress');
this.callReporters('done', {
stats
});
if (!this.hasRunning) {
this.callReporters('beforeAllDone');
this.callReporters('allDone');
this.callReporters('afterAllDone');
}
});
}
updateProgress(percent = 0, message = '', details = []) {
const progress = Math.floor(percent * 100);
Object.assign(this.state, {
progress,
message: message || '',
details,
request: parseRequest(details[2])
});
this.callReporters('progress');
}
}
module.exports = WebpackBarPlugin;
+91
View File
@@ -0,0 +1,91 @@
{
"_args": [
[
"webpackbar@4.0.0",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "webpackbar@4.0.0",
"_id": "webpackbar@4.0.0",
"_inBundle": false,
"_integrity": "sha512-k1qRoSL/3BVuINzngj09nIwreD8wxV4grcuhHTD8VJgUbGcy8lQSPqv+bM00B7F+PffwIsQ8ISd4mIwRbr23eQ==",
"_location": "/webpackbar",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "webpackbar@4.0.0",
"name": "webpackbar",
"escapedName": "webpackbar",
"rawSpec": "4.0.0",
"saveSpec": null,
"fetchSpec": "4.0.0"
},
"_requiredBy": [
"/@nuxt/webpack"
],
"_resolved": "https://registry.npmjs.org/webpackbar/-/webpackbar-4.0.0.tgz",
"_spec": "4.0.0",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "Pooya Parsa",
"email": "pooya@pi0.ir"
},
"bugs": {
"url": "https://github.com/nuxt/webpackbar/issues"
},
"dependencies": {
"ansi-escapes": "^4.2.1",
"chalk": "^2.4.2",
"consola": "^2.10.0",
"figures": "^3.0.0",
"pretty-time": "^1.1.0",
"std-env": "^2.2.1",
"text-table": "^0.2.0",
"wrap-ansi": "^6.0.0"
},
"description": "Elegant ProgressBar and Profiler for Webpack",
"devDependencies": {
"@nuxtjs/eslint-config": "^1.0.1",
"babel-jest": "^24.8.0",
"bili": "^4.8.1",
"codecov": "^3.5.0",
"eslint": "^6.1.0",
"esm": "^3.2.25",
"jest": "^24.8.0",
"memory-fs": "^0.4.1",
"rimraf": "^2.6.3",
"standard-version": "^5.0.2",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6"
},
"engines": {
"node": ">= 8.0.0"
},
"files": [
"dist"
],
"homepage": "https://github.com/nuxt/webpackbar#readme",
"license": "MIT",
"main": "dist/webpackbar.js",
"name": "webpackbar",
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt/webpackbar.git"
},
"scripts": {
"build": "bili src/index.js --file-name webpackbar.js --format cjs",
"clean": "rimraf dist",
"demo": "webpack-cli --config demo/webpack.config.js",
"lint": "eslint src test",
"prebuild": "yarn clean",
"prepublish": "yarn build",
"release": "standard-version",
"start": "yarn build -- -w",
"test": "jest"
},
"version": "4.0.0"
}