vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

Command line options with confirm type prompt not parsed as boolean #6566

Open petterw03 opened 3 years ago

petterw03 commented 3 years ago

Version

4.5.13

Reproduction link

https://github.com/Yleisradio/vue-cli-plugin-yddviz

Environment info

Environment Info:

  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 AMD Ryzen 3 PRO 3300U w/ Radeon Vega Mobile Gfx
  Binaries:
    Node: 16.4.0 - ~/.nvm/versions/node/v16.4.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v16.4.0/bin/yarn
    npm: 7.18.1 - ~/.nvm/versions/node/v16.4.0/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1
    @vue/babel-helper-vue-transform-on:  1.0.2
    @vue/babel-plugin-jsx:  1.0.6
    @vue/babel-plugin-transform-vue-jsx:  1.2.1
    @vue/babel-preset-app:  4.5.13
    @vue/babel-preset-jsx:  1.2.4
    @vue/babel-sugar-composition-api-inject-h:  1.2.1
    @vue/babel-sugar-composition-api-render-instance:  1.2.4
    @vue/babel-sugar-functional-vue:  1.2.2
    @vue/babel-sugar-inject-h:  1.2.2
    @vue/babel-sugar-v-model:  1.2.3
    @vue/babel-sugar-v-on:  1.2.3
    @vue/cli-overlay:  4.5.13
    @vue/cli-plugin-babel: ~4.5.0 => 4.5.13
    @vue/cli-plugin-eslint: ~4.5.0 => 4.5.13
    @vue/cli-plugin-router:  4.5.13
    @vue/cli-plugin-vuex:  4.5.13
    @vue/cli-service: ~4.5.0 => 4.5.13
    @vue/cli-shared-utils:  4.5.13
    @vue/compiler-core:  3.1.3
    @vue/compiler-dom:  3.1.3
    @vue/compiler-sfc: ^3.0.0 => 3.1.3
    @vue/compiler-ssr:  3.1.3
    @vue/component-compiler-utils:  3.2.2
    @vue/preload-webpack-plugin:  1.1.2
    @vue/reactivity:  3.1.3
    @vue/runtime-core:  3.1.3
    @vue/runtime-dom:  3.1.3
    @vue/shared:  3.1.3
    @vue/web-component-wrapper:  1.3.0
    eslint-plugin-vue: ^7.0.0 => 7.12.1
    vue: ^3.0.0 => 3.1.3
    vue-cli-plugin-yddviz: ~4.3.2 => 4.3.2
    vue-eslint-parser:  7.7.1
    vue-hot-reload-api:  2.3.4
    vue-loader:  15.9.7 (16.3.0)
    vue-style-loader:  4.1.3
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Invoke the plugin for example like this: vue add yddviz --projectName test-project --externalContent true or vue add yddviz --projectName test-project --externalContent y

What is expected?

Since the externalContent option is of type confirm, it should be parsed as an boolean, in the same way as if you enter the prompts manually (by using just vue add yddviz). package.json in the vue project should include the following after invoking the plugin:

"yleDataviz": {
  "externalContent": true
}

What is actually happening?

The externalContent option is parsed like a string instead of a boolean.

"yleDataviz": {
  "externalContent": "true"
}
"yleDataviz": {
  "externalContent": "y"
}
petterw03 commented 3 years ago

I think this bug is weird because you would think that this line here https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/lib/invoke.js#L64 would automatically parse the boolean value:

pluginOptions = JSON.parse($inlineOptions)

But for some reason it doesn't.