From 9eb498004cfff3a714c64c80aa749e12b32f1365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Zaera=20Avell=C3=B3n?= Date: Mon, 9 Mar 2020 11:41:21 +0100 Subject: [PATCH 01/12] chore: Configure eslint --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 59124a08..d33d75cb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,6 +18,7 @@ module.exports = { root: true, rules: { '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/switch-exhaustiveness-check': 'error', '@typescript-eslint/no-explicit-any': [ 'error', { From 2f6f9dda6e66a75804a5c5c90d8a42d64569cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Zaera=20Avell=C3=B3n?= Date: Mon, 9 Mar 2020 11:44:01 +0100 Subject: [PATCH 02/12] feat: #538 Add webpack actions to report This is so that we can tell the user what webpack and/or our plugins are doing on each file. --- .../src/project/misc.ts | 67 ++++++++++++++- .../liferay-npm-bundler/src/report/html.ts | 62 ++++++++++++-- .../liferay-npm-bundler/src/report/index.ts | 63 +++++++++----- .../liferay-npm-bundler/src/report/logger.ts | 82 +++++++++++++++++++ 4 files changed, 246 insertions(+), 28 deletions(-) create mode 100644 packages/liferay-npm-bundler/src/report/logger.ts diff --git a/packages/liferay-npm-build-tools-common/src/project/misc.ts b/packages/liferay-npm-build-tools-common/src/project/misc.ts index 0fd988c5..d50181ed 100644 --- a/packages/liferay-npm-build-tools-common/src/project/misc.ts +++ b/packages/liferay-npm-build-tools-common/src/project/misc.ts @@ -5,9 +5,13 @@ import {Project} from '.'; import prop from 'dot-prop'; +import {print, warn} from 'liferay-npm-build-tools-common/lib/format'; import FilePath from '../file-path'; +/** Valid log levels for console and report */ +export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug'; + /** * Reflects miscellaneous project configuration values. */ @@ -23,10 +27,28 @@ export default class Misc { /** * Whether or not to dump detailed information about what the tool is doing */ - get logLevel(): 'off' | 'error' | 'warn' | 'info' | 'debug' { + get logLevel(): LogLevel { const {npmbundlerrc} = this._project; - return prop.get(npmbundlerrc, 'log-level', 'warn'); + let logLevel = prop.get(npmbundlerrc, 'log-level', 'warn'); + + switch (logLevel) { + case 'off': + case 'error': + case 'warn': + case 'info': + case 'debug': + break; + + default: + logLevel = 'off'; + print( + warn`Configuration value {log-level} has invalid value: it will be ignored` + ); + break; + } + + return logLevel as LogLevel; } /** @@ -54,7 +76,6 @@ export default class Misc { /** * Get the path to the report file or undefined if no report is configured. */ - get reportFile(): FilePath | undefined { const {_project} = this; const {npmbundlerrc} = _project; @@ -66,5 +87,45 @@ export default class Misc { : undefined; } + /** + * Get report log level + */ + get reportLevel(): LogLevel { + const {_project} = this; + const {npmbundlerrc} = _project; + + let dumpReport = prop.get( + npmbundlerrc, + 'dump-report', + false + ); + + switch (dumpReport) { + case 'off': + case 'error': + case 'warn': + case 'info': + case 'debug': + break; + + case true: + dumpReport = 'info'; + break; + + case false: + dumpReport = 'off'; + break; + + default: + dumpReport = 'off'; + print( + warn`Configuration value {dump-report} has invalid value: it will be ignored` + ); + break; + } + + return dumpReport as LogLevel; + } + private readonly _project: Project; } diff --git a/packages/liferay-npm-bundler/src/report/html.ts b/packages/liferay-npm-bundler/src/report/html.ts index 9d15da54..0314eb88 100644 --- a/packages/liferay-npm-bundler/src/report/html.ts +++ b/packages/liferay-npm-bundler/src/report/html.ts @@ -21,6 +21,7 @@ export function htmlDump(report: Report): string { _rules, _versionsInfo, _warnings, + _webpack, } = report; const title = 'Report of liferay-npm-bundler execution'; @@ -66,6 +67,39 @@ export function htmlDump(report: Report): string { ) ); + const webpack = htmlSection( + 'Details of webpack execution', + htmlTable( + 'File', + '', + 'Source', + 'Messages', + Object.entries(_webpack.logs) + .sort((a, b) => a[0].localeCompare(b[0])) + .map(([prjRelPath, sources]) => + Object.entries(sources).map(([source, logger]) => + logger.messages + .map(({logLevel, things}, index) => + htmlRow( + ` + ${index == 0 ? prjRelPath : ''} + + ${logLevel.toUpperCase()} + + [${source}] + + ${things.map(thing => `${thing}`).join(' ')} + + `, + logLevel + ) + ) + .join('') + ) + ) + ) + ); + const rulesExecution = htmlIf(Object.keys(_rules.files).length > 0, () => htmlSection( 'Details of rule executions', @@ -131,20 +165,28 @@ export function htmlDump(report: Report): string { } th, td { - padding: .1em 0; + padding: .1em; vertical-align: top; } - td.info, td.warn, td.error { - background: green; + td.debug, td.info, td.warn, td.error { border-radius: 4px; color: white; + padding: 0 2px; text-align: center; vertical-align: middle; width: 1px; white-space: nowrap; } + td.debug { + background: gray; + } + + td.info { + background: green; + } + td.warn { background: orange; } @@ -154,6 +196,7 @@ export function htmlDump(report: Report): string { } td.source { + color: grey; white-space: nowrap; } @@ -231,21 +274,28 @@ export function htmlDump(report: Report): string { var select = document.getElementById('log-level-select'); - select.value = 'info'; + select.value = 'debug'; select.onchange = function() { switch(select.value) { - case 'info': + case 'debug': style.innerHTML = ''; break; + case 'info': + style.innerHTML = + 'tr.debug {display: none;}'; + break; + case 'warn': style.innerHTML = + 'tr.debug {display: none;}' + 'tr.info {display: none;}'; break; case 'error': style.innerHTML = + 'tr.debug {display: none;}' + 'tr.info {display: none;} ' + 'tr.warn {display: none;}'; break; @@ -258,6 +308,7 @@ export function htmlDump(report: Report): string {
Log level filter: