Skip to content

Commit 6ca86aa

Browse files
dhenscheyyx990803
authored andcommitted
feat(inspect): add a -v/--verbose flag to inspect command to output full functions (#1175)
close #1157
1 parent abb82ab commit 6ca86aa

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

packages/@vue/cli-service/lib/commands/inspect.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = (api, options) => {
33
description: 'inspect internal webpack config',
44
usage: 'vue-cli-service inspect [options] [...paths]',
55
options: {
6-
'--mode': 'specify env mode (default: development)'
6+
'--mode': 'specify env mode (default: development)',
7+
'--verbose': 'show full function definitions in output'
78
}
89
}, args => {
910
api.setMode(args.mode || 'development')
@@ -27,13 +28,15 @@ module.exports = (api, options) => {
2728

2829
const pluginRE = /(?:function|class) (\w+Plugin)/
2930
console.log(stringify(res, (value, indent, stringify) => {
30-
if (typeof value === 'function' && value.toString().length > 100) {
31-
return `function () { /* omitted long function */ }`
32-
}
33-
if (value && typeof value.constructor === 'function') {
34-
const match = value.constructor.toString().match(pluginRE)
35-
if (match) {
36-
return `/* ${match[1]} */ ` + stringify(value)
31+
if (!args.verbose) {
32+
if (typeof value === 'function' && value.toString().length > 100) {
33+
return `function () { /* omitted long function */ }`
34+
}
35+
if (value && typeof value.constructor === 'function') {
36+
const match = value.constructor.toString().match(pluginRE)
37+
if (match) {
38+
return `/* ${match[1]} */ ` + stringify(value)
39+
}
3740
}
3841
}
3942
return stringify(value)

packages/@vue/cli/bin/vue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ program
6767
program
6868
.command('inspect [paths...]')
6969
.option('--mode <mode>')
70+
.option('-v --verbose', 'Show full function definitions in output')
7071
.description('inspect the webpack config in a project with vue-cli-service')
7172
.action((paths, cmd) => {
72-
require('../lib/inspect')(paths, cmd.mode)
73+
require('../lib/inspect')(paths, cleanArgs(cmd))
7374
})
7475

7576
program

packages/@vue/cli/lib/inspect.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path')
33
const execa = require('execa')
44
const resolve = require('resolve')
55

6-
module.exports = function inspect (paths, mode) {
6+
module.exports = function inspect (paths, args) {
77
const cwd = process.cwd()
88
let servicePath
99
try {
@@ -18,7 +18,8 @@ module.exports = function inspect (paths, mode) {
1818
execa('node', [
1919
binPath,
2020
'inspect',
21-
...(mode ? ['--mode', mode] : []),
21+
...(args.mode ? ['--mode', args.mode] : []),
22+
...(args.verbose ? ['--verbose'] : []),
2223
...paths
2324
], { cwd, stdio: 'inherit' })
2425
}

0 commit comments

Comments
 (0)