diff --git a/packages/fes-compiler/package.json b/packages/fes-compiler/package.json index 27a02d34..ba7b0b8d 100644 --- a/packages/fes-compiler/package.json +++ b/packages/fes-compiler/package.json @@ -27,7 +27,7 @@ "@babel/register": "^7.12.1", "@umijs/babel-preset-umi": "3.3.3", "@umijs/utils": "3.3.3", - "commander": "^6.2.1", + "commander": "^7.0.0", "dotenv": "8.2.0", "joi": "17.3.0", "readline": "^1.3.0", diff --git a/packages/fes-compiler/src/service/index.js b/packages/fes-compiler/src/service/index.js index 1d957cd1..ccc112d9 100644 --- a/packages/fes-compiler/src/service/index.js +++ b/packages/fes-compiler/src/service/index.js @@ -536,7 +536,9 @@ export default class Service extends EventEmitter { } if (commandOption.fn) { c.action(async () => { - await commandOption.fn({ rawArgv, args, program }); + await commandOption.fn({ + rawArgv, args, options: c.opts(), program + }); }); } }); diff --git a/packages/fes-preset-built-in/package.json b/packages/fes-preset-built-in/package.json index df5bdb24..4e9260c1 100644 --- a/packages/fes-preset-built-in/package.json +++ b/packages/fes-preset-built-in/package.json @@ -39,6 +39,8 @@ "html-webpack-plugin": "^3.2.0", "html-webpack-tags-plugin": "2.0.17", "vue-loader": "^16.1.2", - "webpack-bundle-analyzer": "4.3.0" + "webpack-bundle-analyzer": "4.3.0", + "cli-highlight": "^2.1.4", + "webpack-chain": "6.5.1" } } diff --git a/packages/fes-preset-built-in/src/index.js b/packages/fes-preset-built-in/src/index.js index bb2cda71..e4d3599c 100644 --- a/packages/fes-preset-built-in/src/index.js +++ b/packages/fes-preset-built-in/src/index.js @@ -55,7 +55,8 @@ export default function () { require.resolve('./plugins/commands/build'), require.resolve('./plugins/commands/dev'), require.resolve('./plugins/commands/help'), - require.resolve('./plugins/commands/info') + require.resolve('./plugins/commands/info'), + require.resolve('./plugins/commands/webpack') ] }; } diff --git a/packages/fes-preset-built-in/src/plugins/commands/webpack/index.js b/packages/fes-preset-built-in/src/plugins/commands/webpack/index.js new file mode 100644 index 00000000..f6944d67 --- /dev/null +++ b/packages/fes-preset-built-in/src/plugins/commands/webpack/index.js @@ -0,0 +1,43 @@ + +import assert from 'assert'; +import { getBundleAndConfigs } from '../../../utils/buildDevUtils'; + +export default function (api) { + api.registerCommand({ + command: 'webpack', + description: 'inspect webpack configurations', + options: { + '--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' + }, + async fn({ options }) { + const { toString } = require('webpack-chain'); + const { highlight } = require('cli-highlight'); + const { bundleConfigs } = await getBundleAndConfigs({ api }); + + let config = bundleConfigs.filter(bundleConfig => bundleConfig.entry?.fes)[0]; + assert(config, 'No valid config found with fes entry.'); + + if (options.rule) { + config = config.module.rules.find( + r => r.__ruleNames[0] === options.rule + ); + } else if (options.plugin) { + config = config.plugins.find( + p => p.__pluginName === options.plugin + ); + } else if (options.rules) { + config = config.module.rules.map(r => r.__ruleNames[0]); + } else if (options.plugins) { + config = config.plugins.map( + p => p.__pluginName || p.constructor.name + ); + } + + console.log(highlight(toString(config, { verbose: options.verbose }), { language: 'js' })); + } + }); +} diff --git a/packages/fes-preset-built-in/src/plugins/features/analyze.js b/packages/fes-preset-built-in/src/plugins/features/analyze.js index ea643eee..28ef0b23 100644 --- a/packages/fes-preset-built-in/src/plugins/features/analyze.js +++ b/packages/fes-preset-built-in/src/plugins/features/analyze.js @@ -36,7 +36,7 @@ export default (api) => { webpackConfig .plugin('bundle-analyzer') .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [ - api.config?.analyze || {} + api.config?.analyze || {} ]); } return webpackConfig; diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index db77aa6f..e9a7d3f3 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -4,7 +4,7 @@ export default { base: '/foo/', define: { - __DEV__: false + __DEV__: true }, publicPath: '/', access: { diff --git a/packages/fes-template/src/pages/index.vue b/packages/fes-template/src/pages/index.vue index 3a304634..1ba658b3 100644 --- a/packages/fes-template/src/pages/index.vue +++ b/packages/fes-template/src/pages/index.vue @@ -25,6 +25,8 @@ import { access, useAccess, useRouter, useI18n, locale, enums } from '@webank/fes'; +console.log(__DEV__); + export default { setup() { const fes = ref('fes upgrade to vue3'); diff --git a/yarn.lock b/yarn.lock index b2582f5d..c1d2842e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6521,6 +6521,18 @@ cli-cursor@^3.1.0: dependencies: restore-cursor "^3.1.0" +cli-highlight@^2.1.4: + version "2.1.10" + resolved "https://registry.yarnpkg.com/cli-highlight/-/cli-highlight-2.1.10.tgz#26a087da9209dce4fcb8cf5427dc97cd96ac173a" + integrity sha512-CcPFD3JwdQ2oSzy+AMG6j3LRTkNjM82kzcSKzoVw6cLanDCJNlsLjeqVTOTfOfucnWv5F0rmBemVf1m9JiIasw== + dependencies: + chalk "^4.0.0" + highlight.js "^10.0.0" + mz "^2.4.0" + parse5 "^5.1.1" + parse5-htmlparser2-tree-adapter "^6.0.0" + yargs "^16.0.0" + cli-spinners@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.5.0.tgz#12763e47251bf951cb75c201dfa58ff1bcb2d047" @@ -6597,6 +6609,15 @@ cliui@^5.0.0: strip-ansi "^5.2.0" wrap-ansi "^5.1.0" +cliui@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" + integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + clone-buffer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/clone-buffer/-/clone-buffer-1.0.0.tgz#e3e25b207ac4e701af721e2cb5a16792cac3dc58" @@ -6773,11 +6794,16 @@ commander@^4.1.1: resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== -commander@^6.2.0, commander@^6.2.1: +commander@^6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== +commander@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-7.0.0.tgz#3e2bbfd8bb6724760980988fb5b22b7ee6b71ab2" + integrity sha512-ovx/7NkTrnPuIV8sqk/GjUIIM1+iUQeqA3ye2VNpq9sVoiZsooObWlQy+OPWGI17GDaEoybuAGJm6U8yC077BA== + commander@~2.19.0: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" @@ -9427,7 +9453,7 @@ gensync@^1.0.0-beta.1: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== -get-caller-file@^2.0.1: +get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -9966,6 +9992,11 @@ hex-color-regex@^1.1.0: resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e" integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ== +highlight.js@^10.0.0: + version "10.5.0" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.5.0.tgz#3f09fede6a865757378f2d9ebdcbc15ba268f98f" + integrity sha512-xTmvd9HiIHR6L53TMC7TKolEj65zG1XU+Onr8oi86mYa+nLcIbxTTWkpW7CsEwv/vK7u1zb8alZIMLDqqN6KTw== + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -12940,7 +12971,7 @@ mute-stream@0.0.8, mute-stream@~0.0.4: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== -mz@^2.5.0: +mz@^2.4.0, mz@^2.5.0: version "2.7.0" resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q== @@ -13839,7 +13870,14 @@ parse-url@^5.0.0: parse-path "^4.0.0" protocols "^1.4.0" -parse5@5.1.1: +parse5-htmlparser2-tree-adapter@^6.0.0: + version "6.0.1" + resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6" + integrity sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA== + dependencies: + parse5 "^6.0.1" + +parse5@5.1.1, parse5@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178" integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug== @@ -13851,6 +13889,11 @@ parse5@^3.0.1: dependencies: "@types/node" "*" +parse5@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b" + integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw== + parseurl@~1.3.2, parseurl@~1.3.3: version "1.3.3" resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" @@ -18797,6 +18840,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4" integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ== +y18n@^5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.5.tgz#8769ec08d03b1ea2df2500acef561743bbb9ab18" + integrity sha512-hsRUr4FFrvhhRH12wOdfs38Gy7k2FFzB9qgN9v3aLykRq0dRcdcpz5C9FxdS2NuhOrI/628b/KSTJ3rwHysYSg== + yallist@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" @@ -18833,7 +18881,7 @@ yargs-parser@18.1.3, yargs-parser@^18.1.2: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@20.x, yargs-parser@^20.2.3: +yargs-parser@20.x, yargs-parser@^20.2.2, yargs-parser@^20.2.3: version "20.2.4" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== @@ -18880,6 +18928,19 @@ yargs@^14.2.2: y18n "^4.0.0" yargs-parser "^15.0.1" +yargs@^16.0.0: + version "16.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.5" + yargs-parser "^20.2.2" + yargs@~3.10.0: version "3.10.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"