From f33b731429e91d592f87f4138fe4cca9ef223e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Mon, 28 Jan 2019 08:55:51 +0100 Subject: [PATCH 1/4] fix(cli-service): inspect --rules should only return rules that actually have a name (= which were added with the chainWebpack API) close #3334 --- packages/@vue/cli-service/lib/commands/inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-service/lib/commands/inspect.js b/packages/@vue/cli-service/lib/commands/inspect.js index c805667d6a..c2ae044c53 100644 --- a/packages/@vue/cli-service/lib/commands/inspect.js +++ b/packages/@vue/cli-service/lib/commands/inspect.js @@ -22,7 +22,7 @@ module.exports = (api, options) => { } else if (args.plugin) { res = config.plugins.find(p => p.__pluginName === args.plugin) } else if (args.rules) { - res = config.module.rules.map(r => r.__ruleNames[0]) + res = config.module.rules.filter(r => r.__ruleNames).map(r => r.__ruleNames[0]) } else if (args.plugins) { res = config.plugins.map(p => p.__pluginName || p.constructor.name) } else if (paths.length > 1) { From 92de499cf4f5ebc28ffa26c41bde5f8f7077ed6f Mon Sep 17 00:00:00 2001 From: Thorsten Date: Wed, 30 Jan 2019 19:47:59 +0100 Subject: [PATCH 2/4] refactor: provide placeholder for nameless rules and log explanation --- .../@vue/cli-service/lib/commands/inspect.js | 103 +++++++++++------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/inspect.js b/packages/@vue/cli-service/lib/commands/inspect.js index c2ae044c53..db34236027 100644 --- a/packages/@vue/cli-service/lib/commands/inspect.js +++ b/packages/@vue/cli-service/lib/commands/inspect.js @@ -1,44 +1,71 @@ module.exports = (api, options) => { - api.registerCommand('inspect', { - description: 'inspect internal webpack config', - usage: 'vue-cli-service inspect [options] [...paths]', - options: { - '--mode': 'specify env mode (default: development)', - '--rule ': 'inspect a specific module rule', - '--plugin ': 'inspect a specific plugin', - '--rules': 'list all module rule names', - '--plugins': 'list all plugin names', - '--verbose': 'show full function definitions in output' - } - }, args => { - const { get } = require('@vue/cli-shared-utils') - const { toString } = require('webpack-chain') - const config = api.resolveWebpackConfig() - const { _: paths, verbose } = args + api.registerCommand( + 'inspect', + { + description: 'inspect internal webpack config', + usage: 'vue-cli-service inspect [options] [...paths]', + options: { + '--mode': 'specify env mode (default: development)', + '--rule ': 'inspect a specific module rule', + '--plugin ': 'inspect a specific plugin', + '--rules': 'list all module rule names', + '--plugins': 'list all plugin names', + '--verbose': 'show full function definitions in output' + } + }, + args => { + const chalk = require('chalk') + const { get } = require('@vue/cli-shared-utils') + const { toString } = require('webpack-chain') + const config = api.resolveWebpackConfig() + const { _: paths, verbose } = args - let res - if (args.rule) { - res = config.module.rules.find(r => r.__ruleNames[0] === args.rule) - } else if (args.plugin) { - res = config.plugins.find(p => p.__pluginName === args.plugin) - } else if (args.rules) { - res = config.module.rules.filter(r => r.__ruleNames).map(r => r.__ruleNames[0]) - } else if (args.plugins) { - res = config.plugins.map(p => p.__pluginName || p.constructor.name) - } else if (paths.length > 1) { - res = {} - paths.forEach(path => { - res[path] = get(config, path) - }) - } else if (paths.length === 1) { - res = get(config, paths[0]) - } else { - res = config - } + let res + let hasUnnamedRule + if (args.rule) { + res = config.module.rules.find(r => r.__ruleNames[0] === args.rule) + } else if (args.plugin) { + res = config.plugins.find(p => p.__pluginName === args.plugin) + } else if (args.rules) { + res = config.module.rules.map(r => { + const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule*' + + hasUnnamedRule = !hasUnnamedRule && !r.__ruleNames - const output = toString(res, { verbose }) - console.log(output) - }) + return name + }) + } else if (args.plugins) { + res = config.plugins.map(p => p.__pluginName || p.constructor.name) + } else if (paths.length > 1) { + res = {} + paths.forEach(path => { + res[path] = get(config, path) + }) + } else if (paths.length === 1) { + res = get(config, paths[0]) + } else { + res = config + } + + const output = toString(res, { verbose }) + console.log(output) + + // Log explanation for Nameless Rules + if (hasUnnamedRule) { + console.log('--------') + console.log(`* => Rules that are "nameless" were added with ${chalk.green( + 'configureWebpack()' + )} (possibly by a plugin). + Run ${chalk.green( + 'vue-cli-service inspect' + )} without any arguments to inspect the full config. + + We recommend using ${chalk.green( + 'chainWebpack()' + )} instead whenever possible`) + } + } + ) } module.exports.defaultModes = { From d75758208b439171a24b4162b052deef3c804273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Tue, 26 Feb 2019 22:03:07 +0100 Subject: [PATCH 3/4] fix: conditional --- packages/@vue/cli-service/lib/commands/inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-service/lib/commands/inspect.js b/packages/@vue/cli-service/lib/commands/inspect.js index db34236027..0cbed98ebd 100644 --- a/packages/@vue/cli-service/lib/commands/inspect.js +++ b/packages/@vue/cli-service/lib/commands/inspect.js @@ -30,7 +30,7 @@ module.exports = (api, options) => { res = config.module.rules.map(r => { const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule*' - hasUnnamedRule = !hasUnnamedRule && !r.__ruleNames + hasUnnamedRule = !!hasUnnamedRule || !r.__ruleNames return name }) From cdaa1378a1c3ed0ea067db68ded454bd420b7122 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sun, 3 Mar 2019 15:13:46 +0100 Subject: [PATCH 4/4] fix: logic mistake and logged message --- .../@vue/cli-service/lib/commands/inspect.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/inspect.js b/packages/@vue/cli-service/lib/commands/inspect.js index db34236027..2e885e38fe 100644 --- a/packages/@vue/cli-service/lib/commands/inspect.js +++ b/packages/@vue/cli-service/lib/commands/inspect.js @@ -28,9 +28,9 @@ module.exports = (api, options) => { res = config.plugins.find(p => p.__pluginName === args.plugin) } else if (args.rules) { res = config.module.rules.map(r => { - const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule*' + const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule (*)' - hasUnnamedRule = !hasUnnamedRule && !r.__ruleNames + hasUnnamedRule = hasUnnamedRule || !r.__ruleNames return name }) @@ -52,17 +52,17 @@ module.exports = (api, options) => { // Log explanation for Nameless Rules if (hasUnnamedRule) { - console.log('--------') - console.log(`* => Rules that are "nameless" were added with ${chalk.green( + console.log(`--- ${chalk.green('Footnotes')} ---`) + console.log(`*: ${chalk.green( + 'Nameless Rules' + )} were added through the ${chalk.green( 'configureWebpack()' - )} (possibly by a plugin). - Run ${chalk.green( + )} API (possibly by a plugin) instead of ${chalk.green( + 'chainWebpack()' + )} (recommended). + You can run ${chalk.green( 'vue-cli-service inspect' - )} without any arguments to inspect the full config. - - We recommend using ${chalk.green( - 'chainWebpack()' - )} instead whenever possible`) + )} without any arguments to inspect the full config and read these rules' config.`) } } )