Skip to content

Commit

Permalink
chore: minor refactor (#4205)
Browse files Browse the repository at this point in the history
eliminate redundancy
  • Loading branch information
jamesgeorge007 authored and sodatea committed Jun 28, 2019
1 parent 5460ca4 commit 934746d
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions packages/@vue/cli/lib/util/installDeps.js
Expand Up @@ -11,6 +11,29 @@ const taobaoDistURL = 'https://npm.taobao.org/dist'

const supportPackageManagerList = ['npm', 'yarn', 'pnpm']

const packageManagerConfig = {
npm: {
installDeps: ['install', '--loglevel', 'error'],
installPackage: ['install', '--loglevel', 'error'],
uninstallPackage: ['uninstall', '--loglevel', 'error'],
updatePackage: ['update', '--loglevel', 'error']
},

pnpm: {
installDeps: ['install', '--loglevel', 'error', '--shamefully-flatten'],
installPackage: ['install', '--loglevel', 'error'],
uninstallPackage: ['uninstall', '--loglevel', 'error'],
updatePackage: ['update', '--loglevel', 'error']
},

yarn: {
installDeps: [],
installPackage: ['add'],
uninstallPackage: ['remove'],
updatePackage: ['upgrade']
}
}

class InstallProgress extends EventEmitter {
constructor () {
super()
Expand Down Expand Up @@ -174,17 +197,7 @@ function executeCommand (command, args, targetDir) {
exports.installDeps = async function installDeps (targetDir, command, cliRegistry) {
checkPackageManagerIsSupported(command)

const args = []

if (command === 'npm' || command === 'pnpm') {
args.push('install', '--loglevel', 'error')
} else if (command === 'yarn') {
// do nothing
}

if (command === 'pnpm') {
args.push('--shamefully-flatten')
}
const args = packageManagerConfig[command].installDeps;

await addRegistryToArgs(command, args, cliRegistry)

Expand All @@ -197,13 +210,7 @@ exports.installDeps = async function installDeps (targetDir, command, cliRegistr
exports.installPackage = async function (targetDir, command, cliRegistry, packageName, dev = true) {
checkPackageManagerIsSupported(command)

const args = []

if (command === 'npm' || command === 'pnpm') {
args.push('install', '--loglevel', 'error')
} else if (command === 'yarn') {
args.push('add')
}
const args = packageManagerConfig[command].installPackage;

if (dev) args.push('-D')

Expand All @@ -220,13 +227,7 @@ exports.installPackage = async function (targetDir, command, cliRegistry, packag
exports.uninstallPackage = async function (targetDir, command, cliRegistry, packageName) {
checkPackageManagerIsSupported(command)

const args = []

if (command === 'npm' || command === 'pnpm') {
args.push('uninstall', '--loglevel', 'error')
} else if (command === 'yarn') {
args.push('remove')
}
const args = packageManagerConfig[command].uninstallPackage;

await addRegistryToArgs(command, args, cliRegistry)

Expand All @@ -241,13 +242,7 @@ exports.uninstallPackage = async function (targetDir, command, cliRegistry, pack
exports.updatePackage = async function (targetDir, command, cliRegistry, packageName) {
checkPackageManagerIsSupported(command)

const args = []

if (command === 'npm' || command === 'pnpm') {
args.push('update', '--loglevel', 'error')
} else if (command === 'yarn') {
args.push('upgrade')
}
const args = packageManagerConfig[command].updatePackage;

await addRegistryToArgs(command, args, cliRegistry)

Expand Down

0 comments on commit 934746d

Please sign in to comment.