Skip to content

Commit

Permalink
chore: upgrade to webpack defaults 2 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Mar 28, 2018
1 parent a760909 commit 999023e
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 167 deletions.
18 changes: 16 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"useBuiltIns": true,
"targets": {
"node": "6.0"
"node": "6.9.0"
},
"exclude": [
"transform-async-to-generator",
Expand All @@ -21,5 +21,19 @@
"useBuiltIns": true
}
]
]
],
"env": {
"test": {
"presets": [
[
"env",
{
"targets": {
"node": "6.9.0"
}
}
]
]
}
}
}
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
root: true,
plugins: ['prettier'],
extends: ['@webpack-contrib/eslint-config-webpack'],
rules: {
'prettier/prettier': [
'error',
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
],
},
};
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# These are the default owners for everything in
# webpack-contrib
@webpack-contrib/org-maintainers

# Add repository specific users / groups
# below here for libs that are not maintained by the org.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
32 changes: 32 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable */
const Configuration = {
extends: ['@commitlint/config-angular'],

rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [2, 'never', ['start-case', 'pascal-case', 'upper-case']],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always', [
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
]
],
},
};

module.exports = Configuration;
61 changes: 32 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,86 @@
{
"name": "webpackbar",
"version": "1.3.0",
"author": "Pooya Parsa <[email protected]>",
"description": "Elegant ProgressBar and Profiler for Webpack",
"license": "MIT",
"main": "dist/cjs.js",
"files": [
"dist"
],
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:fixture": "webpack-cli --config test/fixtures/basic",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"build:watch": "npm run build -- -w",
"start": "npm run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"clean": "del-cli dist",
"commitlint": "commitlint",
"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint --cache src test",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"lint-staged": "lint-staged",
"prebuild": "npm run clean",
"prepublish": "npm run build",
"release": "standard-version",
"release:ci": "conventional-github-releaser -p angular",
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
"security": "nsp check",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"ci:lint": "npm run lint && npm run security",
"ci:test": "npm run test -- --runInBand --ci --coverage",
"ci:test": "npm run test -- --runInBand",
"ci:coverage": "npm run test:coverage -- --runInBand",
"defaults": "webpack-defaults"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt/webpackbar.git"
},
"keywords": [
"webpack",
"webpack4",
"progress",
"progress-bar",
"profile",
"build",
"module"
],
"author": "Pooya Parsa <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/nuxt/webpackbar/issues"
},
"homepage": "https://github.com/nuxt/webpackbar#readme",
"dependencies": {
"chalk": "^2.3.2",
"figures": "^2.0.0",
"is-ci": "^1.1.0",
"loader-utils": "^1.1.0",
"lodash": "^4.17.5",
"log-update": "^2.3.0",
"pretty-time": "^1.0.0",
"schema-utils": "^0.4.5",
"table": "^4.0.3"
},
"devDependencies": {
"@commitlint/cli": "^6.1.3",
"@commitlint/config-angular": "^6.1.3",
"@webpack-contrib/eslint-config-webpack": "^2.0.2",
"babel-cli": "^6.26.0",
"babel-jest": "^22.4.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"codecov": "^3.0.0",
"conventional-github-releaser": "^2.0.2",
"cross-env": "^5.1.4",
"del": "^3.0.0",
"del-cli": "^1.1.0",
"eslint": "^4.19.1",
"eslint-config-webpack": "^1.2.5",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"husky": "^0.14.3",
"jest": "^22.4.3",
"lint-staged": "^7.0.0",
"memory-fs": "^0.4.1",
"nsp": "^3.2.1",
"pre-commit": "^1.2.2",
"prettier": "^1.11.1",
"standard-version": "^4.3.0",
"webpack": "^4.3.0",
"webpack-cli": "^2.0.13",
"webpack-defaults": "^2.0.0"
},
"files": [
"dist"
],
"engines": {
"node": ">= 6.0"
"node": ">= 6.9.0 || >= 8.9.0"
},
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
},
"homepage": "https://github.com/nuxt/webpackbar",
"repository": "https://github.com/nuxt/webpackbar",
"bugs": "https://github.com/nuxt/webpackbar/issues",
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
Expand Down
4 changes: 2 additions & 2 deletions src/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import _ from 'lodash';

const DB = {
loader: {
get: loader => _.startCase(loader),
get: (loader) => _.startCase(loader),
},
ext: {
get: ext => `${ext} files`,
get: (ext) => `${ext} files`,
vue: 'Vue Signle File components',
js: 'JavaScript files',
sass: 'SASS files',
Expand Down
82 changes: 51 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import _ from 'lodash';
import logUpdate from 'log-update';
import isCI from 'is-ci';
import Profile from './profile';
import { BULLET, parseRequst, formatRequest, renderBar, printStats, colorize } from './utils';
import {
BULLET,
parseRequst,
formatRequest,
renderBar,
printStats,
colorize,
} from './utils';

const sharedState = {};

Expand All @@ -24,20 +31,26 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {

this.options = Object.assign({}, defaults, options);

this.handler = (percent, msg, ...details) => this.updateProgress(percent, msg, details);
this.handler = (percent, msg, ...details) =>
this.updateProgress(percent, msg, details);

// Don't throttle when profiling
if (!this.options.profile) {
this.handler = _.throttle(this.handler, 25, { leading: true, trailing: true });
this.handler = _.throttle(this.handler, 25, {
leading: true,
trailing: true,
});
}

if (!this.options.enabled) {
return;
}

this.logUpdate = this.options.logUpdate || logUpdate.create(this.options.stream, {
showCursor: this.options.showCursor,
});
this.logUpdate =
this.options.logUpdate ||
logUpdate.create(this.options.stream, {
showCursor: this.options.showCursor,
});

if (!sharedState[this.options.name]) {
sharedState[this.options.name] = {
Expand Down Expand Up @@ -90,41 +103,48 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
msg,
details: details || [],
request: parseRequst(details[2]),
isRunning: (progress && progress !== 100) && (msg && msg.length),
isRunning: progress && progress !== 100 && (msg && msg.length),
});

if (this.options.profile) {
sharedState[this.options.name].profile
.onRequest(sharedState[this.options.name].request);
sharedState[this.options.name].profile.onRequest(
sharedState[this.options.name].request
);
}

// Process all states
let isRunning = false;

const lines = [];

_.sortBy(Object.keys(sharedState), s => s.name).reverse().forEach((name) => {
const state = sharedState[name];

if (state.isRunning) {
isRunning = true;
} else if (this.options.clear) {
// Hide finished jobs
return;
}

const lColor = colorize(state.color);
const lIcon = lColor(BULLET);
const lName = lColor(_.startCase(name));
const lBar = renderBar(state.progress, state.color);
const lMsg = _.startCase(state.msg);
const lProgress = `(${state.progress || 0}%)`;
const lDetail1 = chalk.grey((state.details && state.details[0]) || '');
const lDetail2 = chalk.grey((state.details && state.details[1]) || '');
const lRequest = state.request ? formatRequest(state.request) : '';

lines.push(`${[lIcon, lName, lBar, lMsg, lProgress, lDetail1, lDetail2].join(' ')}\n ${lRequest}`);
});
_.sortBy(Object.keys(sharedState), (s) => s.name)
.reverse()
.forEach((name) => {
const state = sharedState[name];

if (state.isRunning) {
isRunning = true;
} else if (this.options.clear) {
// Hide finished jobs
return;
}

const lColor = colorize(state.color);
const lIcon = lColor(BULLET);
const lName = lColor(_.startCase(name));
const lBar = renderBar(state.progress, state.color);
const lMsg = _.startCase(state.msg);
const lProgress = `(${state.progress || 0}%)`;
const lDetail1 = chalk.grey((state.details && state.details[0]) || '');
const lDetail2 = chalk.grey((state.details && state.details[1]) || '');
const lRequest = state.request ? formatRequest(state.request) : '';

lines.push(
`${[lIcon, lName, lBar, lMsg, lProgress, lDetail1, lDetail2].join(
' '
)}\n ${lRequest}`
);
});

if (!isRunning) {
if (this.options.clear) {
Expand Down
9 changes: 9 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"name": {
"type": "boolean"
}
},
"additionalProperties": false
}
Loading

0 comments on commit 999023e

Please sign in to comment.