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

Centralize webpack stats config handling (refactor) #1006

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 2 additions & 13 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,16 @@
const _ = require('lodash');
const BbPromise = require('bluebird');
const webpack = require('webpack');
const tty = require('tty');
const isBuiltinModule = require('is-builtin-module');

const defaultStatsConfig = {
colors: tty.isatty(process.stdout.fd),
hash: false,
version: false,
chunks: false,
children: false
};
const logStats = require('./logStats');

function ensureArray(obj) {
return _.isArray(obj) ? obj : [obj];
}

function getStatsLogger(statsConfig, consoleLog) {
return stats => {
const statsOutput = stats.toString(statsConfig || defaultStatsConfig);
if (statsOutput) {
consoleLog(statsOutput);
}
logStats(stats, statsConfig, consoleLog);
};
}

Expand Down
18 changes: 18 additions & 0 deletions lib/logStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const tty = require('tty');

const defaultStatsConfig = {
colors: tty.isatty(process.stdout.fd),
hash: false,
version: false,
chunks: false,
children: false
};

module.exports = function (stats, statsConfig, consoleLog) {
const statsOutput = stats.toString(statsConfig || defaultStatsConfig);
if (statsOutput) {
consoleLog(statsOutput);
}
};
16 changes: 3 additions & 13 deletions lib/wpwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require('lodash');
const BbPromise = require('bluebird');
const webpack = require('webpack');
const tty = require('tty');
const logStats = require('./logStats');

module.exports = {
wpwatch() {
Expand Down Expand Up @@ -60,14 +60,7 @@ module.exports = {
});
}

const consoleStats = this.webpackConfig.stats || {
colors: tty.isatty(process.stdout.fd),
hash: false,
version: false,
chunks: false,
children: false
};

const consoleStats = this.webpackConfig.stats;
// This starts the watch and waits for the immediate compile that follows to end or fail.
let lastHash = null;

Expand Down Expand Up @@ -98,10 +91,7 @@ module.exports = {

if (stats) {
lastHash = stats.hash;
const statsOutput = stats.toString(consoleStats);
if (statsOutput) {
this.serverless.cli.consoleLog(stats.toString(consoleStats));
}
logStats(stats, consoleStats, this.serverless.cli.consoleLog);
}

if (firstRun) {
Expand Down