Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vue/cli

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue/cli - npm Package Compare versions

Comparing version 3.0.0-beta.10 to 3.0.0-beta.11

lib/util/injectImportsAndOptions.js

4

bin/vue.js

@@ -71,2 +71,6 @@ #!/usr/bin/env node

.option('--mode <mode>')
.option('--rule <ruleName>', 'inspect a specific module rule')
.option('--plugin <pluginName>', 'inspect a specific plugin')
.option('--rules', 'list all module rule names')
.option('--plugins', 'list all plugin names')
.option('-v --verbose', 'Show full function definitions in output')

@@ -73,0 +77,0 @@ .description('inspect the webpack config in a project with vue-cli-service')

@@ -15,2 +15,10 @@ const chalk = require('chalk')

async function add (pluginName, options = {}, context = process.cwd()) {
// special internal "plugins"
if (/^(@vue\/)?router$/.test(pluginName)) {
return addRouter(context)
}
if (/^(@vue\/)?vuex$/.test(pluginName)) {
return addVuex(context)
}
const packageName = resolvePluginId(pluginName)

@@ -39,2 +47,18 @@

async function addRouter (context) {
invoke.runGenerator(context, {
id: 'core:router',
apply: require('@vue/cli-service/generator/router'),
options: { invoking: true }
})
}
async function addVuex (context) {
invoke.runGenerator(context, {
id: 'core:vuex',
apply: require('@vue/cli-service/generator/vuex'),
options: { invoking: true }
})
}
module.exports = (...args) => {

@@ -41,0 +65,0 @@ return add(...args).catch(err => {

@@ -29,2 +29,3 @@ const fs = require('fs-extra')

log,
warn,
error,

@@ -162,2 +163,3 @@ hasGit,

// commit initial state
let gitCommitFailed = false
if (shouldInitGit) {

@@ -170,3 +172,7 @@ await run('git add -A')

const msg = typeof cliOptions.git === 'string' ? cliOptions.git : 'init'
await run('git', ['commit', '-m', msg])
try {
await run('git', ['commit', '-m', msg])
} catch (e) {
gitCommitFailed = true
}
}

@@ -185,2 +191,9 @@

if (gitCommitFailed) {
warn(
`Skipped git commit due to missing username and email in git config.\n` +
`You will need to perform the initial commit yourself.\n`
)
}
generator.printExitLogs()

@@ -321,3 +334,3 @@ }

choices: [],
pageSize: 8
pageSize: 10
}

@@ -324,0 +337,0 @@ return {

@@ -8,2 +8,3 @@ const ejs = require('ejs')

const configTransforms = require('./util/configTransforms')
const injectImportsAndOptions = require('./util/injectImportsAndOptions')
const { toShortPluginId, matchesPluginId } = require('@vue/cli-shared-utils')

@@ -31,2 +32,4 @@

this.pkg = Object.assign({}, pkg)
this.imports = {}
this.rootOptions = {}
this.completeCbs = completeCbs

@@ -93,5 +96,11 @@

}
} else if (!process.env.VUE_CLI_TEST) {
// by default, always extract vue.config.js
extract('vue')
} else {
if (!process.env.VUE_CLI_TEST) {
// by default, always extract vue.config.js
extract('vue')
}
// always extract babel.config.js as this is the only way to apply
// project-wide configuration even to dependencies.
// TODO: this can be removed when Babel supports root: true in package.json
extract('babel')
}

@@ -136,4 +145,4 @@ }

}
// normalize paths
Object.keys(files).forEach(file => {
// normalize paths
const normalized = slash(file)

@@ -144,2 +153,8 @@ if (file !== normalized) {

}
// handle imports and root option injections
files[normalized] = injectImportsAndOptions(
files[normalized],
this.imports[normalized],
this.rootOptions[normalized]
)
})

@@ -146,0 +161,0 @@ for (const postProcess of this.postProcessFilesCbs) {

@@ -10,3 +10,3 @@ const fs = require('fs')

const mergeDeps = require('./util/mergeDeps')
const stringifyJS = require('javascript-stringify')
const stringifyJS = require('./util/stringifyJS')
const { getPluginLink, toShortPluginId } = require('@vue/cli-shared-utils')

@@ -203,2 +203,28 @@

}
/**
* Add import statements to a file.
*/
injectImports (file, imports) {
const _imports = (
this.generator.imports[file] ||
(this.generator.imports[file] = new Set())
)
;(Array.isArray(imports) ? imports : [imports]).forEach(imp => {
_imports.add(imp)
})
}
/**
* Add options to the root Vue instance (detected by `new Vue`).
*/
injectRootOptions (file, options) {
const _options = (
this.generator.rootOptions[file] ||
(this.generator.rootOptions[file] = new Set())
)
;(Array.isArray(options) ? options : [options]).forEach(opt => {
_options.add(opt)
})
}
}

@@ -205,0 +231,0 @@

@@ -22,2 +22,6 @@ const fs = require('fs')

...(args.mode ? ['--mode', args.mode] : []),
...(args.rule ? ['--rule', args.rule] : []),
...(args.plugin ? ['--plugin', args.plugin] : []),
...(args.rules ? ['--rules'] : []),
...(args.plugins ? ['--plugins'] : []),
...(args.verbose ? ['--verbose'] : []),

@@ -24,0 +28,0 @@ ...paths

22

lib/invoke.js

@@ -39,12 +39,13 @@ const fs = require('fs')

async function invoke (pluginName, options = {}, context = process.cwd()) {
delete options._
function getPkg (context) {
const pkgPath = path.resolve(context, 'package.json')
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
if (!fs.existsSync(pkgPath)) {
throw new Error(`package.json not found in ${chalk.yellow(context)}`)
}
return require(pkgPath)
}
const pkg = require(pkgPath)
async function invoke (pluginName, options = {}, context = process.cwd()) {
delete options._
const pkg = getPkg(context)

@@ -93,2 +94,7 @@ // attempt to locate the plugin in package.json

await runGenerator(context, plugin, pkg)
}
async function runGenerator (context, plugin, pkg = getPkg(context)) {
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
const createCompleteCbs = []

@@ -103,3 +109,3 @@ const generator = new Generator(context, {

log()
logWithSpinner('🚀', `Invoking generator for ${id}...`)
logWithSpinner('🚀', `Invoking generator for ${plugin.id}...`)
await generator.generate({

@@ -133,3 +139,3 @@ extractConfigFiles: true,

log()
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
log(` Successfully invoked generator for plugin: ${chalk.cyan(plugin.id)}`)
if (!process.env.VUE_CLI_TEST && hasGit()) {

@@ -173,1 +179,3 @@ const { stdout } = await execa('git', [

}
module.exports.runGenerator = runGenerator

@@ -12,3 +12,3 @@ jest.mock('fs')

message: 'features',
check: []
check: [0]
}

@@ -31,5 +31,6 @@ ]

test('should not include the plugin if ts is also present', async () => {
test('with TS', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.useTsWithBabel = true
answers.features.push('ts')

@@ -42,2 +43,30 @@ })

message: 'features',
check: [] // no need to check if "useTsWithBabel" is explicitly true
}
]
const expectedOptions = {
plugins: {
'@vue/cli-plugin-babel': {}
}
}
await assertPromptModule(
[mockTSModule, moduleToTest],
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})
test('with TS, no Babel', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.features.push('ts')
})
}
const expectedPrompts = [
{
message: 'features',
check: []

@@ -44,0 +73,0 @@ }

module.exports = cli => {
cli.injectFeature({
name: 'Babel',
value: 'babel',
short: 'Babel',
checked: true
})
cli.onPromptComplete((answers, options) => {
if (
!answers.features.includes('ts') ||
answers.useTsWithBabel ||
answers.experimentalCompileTsWithBabel
) {
options.plugins['@vue/cli-plugin-babel'] = {}
if (answers.features.includes('ts')) {
if (!answers.useTsWithBabel) {
return
}
} else {
if (!answers.features.includes('babel')) {
return
}
}
options.plugins['@vue/cli-plugin-babel'] = {}
})
}

@@ -8,3 +8,4 @@ module.exports = cli => {

value: 'linter',
short: 'Linter'
short: 'Linter',
checked: true
})

@@ -58,3 +59,4 @@

name: 'Lint on save',
value: 'save'
value: 'save',
checked: true
},

@@ -61,0 +63,0 @@ {

@@ -1,3 +0,1 @@

const chalk = require('chalk')
module.exports = cli => {

@@ -17,17 +15,9 @@ cli.injectFeature({

if (process.env.VUE_CLI_EXPERIMENTAL) {
cli.injectPrompt({
name: 'compileTsWithBabel',
when: answers => answers.features.includes('ts'),
type: 'confirm',
message: `Compile TS with babel? ${chalk.yellow(`(experimental)`)}`
})
} else {
cli.injectPrompt({
name: 'useTsWithBabel',
when: answers => answers.features.includes('ts'),
type: 'confirm',
message: 'Use Babel alongside TypeScript for auto-detected polyfills?'
})
}
cli.injectPrompt({
name: 'useTsWithBabel',
when: answers => answers.features.includes('ts'),
type: 'confirm',
message: 'Use Babel alongside TypeScript for auto-detected polyfills?',
default: answers => answers.features.includes('babel')
})

@@ -45,4 +35,2 @@ cli.onPromptComplete((answers, options) => {

tsOptions.useTsWithBabel = true
} else if (answers.compileTsWithBabel) {
tsOptions.experimentalCompileTsWithBabel = true
}

@@ -49,0 +37,0 @@ options.plugins['@vue/cli-plugin-typescript'] = tsOptions

const fs = require('fs')
const path = require('path')
const extendJSConfig = require('./extendJSConfig')
const stringifyJS = require('javascript-stringify')
const stringifyJS = require('./stringifyJS')

@@ -80,3 +80,3 @@ function makeJSTransform (filename) {

vue: makeJSTransform('vue.config.js'),
babel: makeJSONTransform('.babelrc'),
babel: makeJSTransform('babel.config.js'),
postcss: makeMutliExtensionJSONTransform('.postcssrc', true),

@@ -83,0 +83,0 @@ eslintConfig: makeMutliExtensionJSONTransform('.eslintrc', true),

module.exports = function extendJSConfig (value, source) {
const recast = require('recast')
const stringifyJS = require('javascript-stringify')
const stringifyJS = require('./stringifyJS')

@@ -5,0 +5,0 @@ let exportsIdentifier = null

@@ -12,4 +12,3 @@ module.exports = async function getVersions () {

const request = require('./request')
const options = require('../options').loadOptions()
const registry = options.useTaobaoRegistry
const registry = (await require('./shouldUseTaobao')())
? `https://registry.npm.taobao.org`

@@ -16,0 +15,0 @@ : `https://registry.npmjs.org`

@@ -1,76 +0,11 @@

const request = require('./request')
const chalk = require('chalk')
const execa = require('execa')
const readline = require('readline')
const inquirer = require('inquirer')
const { loadOptions, saveOptions } = require('../options')
const { pauseSpinner, resumeSpinner } = require('@vue/cli-shared-utils')
const registries = require('./registries')
const shouldUseTaobao = require('./shouldUseTaobao')
const debug = require('debug')('vue-cli:install')
const registries = {
npm: 'https://registry.npmjs.org',
yarn: 'https://registry.yarnpkg.com',
taobao: 'https://registry.npm.taobao.org'
}
const taobaoDistURL = 'https://npm.taobao.org/dist'
async function ping (registry) {
await request.get(`${registry}/vue-cli-version-marker/latest`)
return registry
}
function removeSlash (url) {
return url.replace(/\/$/, '')
}
let checked
let result
async function shouldUseTaobao () {
// ensure this only gets called once.
if (checked) return result
checked = true
// previously saved preference
const saved = loadOptions().useTaobaoRegistry
if (typeof saved === 'boolean') {
return (result = saved)
}
const save = val => {
result = val
saveOptions({ useTaobaoRegistry: val })
return val
}
const userCurrent = (await execa(`npm`, ['config', 'get', 'registry'])).stdout
const defaultRegistry = registries.npm
if (removeSlash(userCurrent) !== removeSlash(defaultRegistry)) {
// user has configured custom regsitry, respect that
return save(false)
}
const faster = await Promise.race([
ping(defaultRegistry),
ping(registries.taobao)
])
if (faster !== registries.taobao) {
// default is already faster
return save(false)
}
// ask and save preference
pauseSpinner()
const { useTaobaoRegistry } = await inquirer.prompt([{
name: 'useTaobaoRegistry',
type: 'confirm',
message: chalk.yellow(
` Your connection to the the default npm registry seems to be slow.\n` +
` Use ${chalk.cyan(registries.taobao)} for faster installation?`
)
}])
resumeSpinner()
return save(useTaobaoRegistry)
}
function toStartOfLine (stream) {

@@ -77,0 +12,0 @@ if (!chalk.supportsColor) {

{
"name": "@vue/cli",
"version": "3.0.0-beta.10",
"version": "3.0.0-beta.11",
"description": "Command line interface for rapid Vue.js development",

@@ -30,3 +30,3 @@ "bin": {

"dependencies": {
"@vue/cli-shared-utils": "^3.0.0-beta.10",
"@vue/cli-shared-utils": "^3.0.0-beta.11",
"chalk": "^2.3.0",

@@ -33,0 +33,0 @@ "commander": "^2.12.2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc