Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions packages/@vue/cli-shared-utils/lib/env.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
const { execSync } = require('child_process')

let _hasYarn
let _hasGit
const _hasYarn = new Map()
const _hasGit = new Map()

// env detection
exports.hasYarn = () => {
exports.hasYarn = (context = undefined) => {
if (process.env.VUE_CLI_TEST) {
return true
}
if (_hasYarn != null) {
return _hasYarn
if (_hasYarn.has(context)) {
return _hasYarn.get(context)
}
let result
try {
execSync('yarnpkg --version', { stdio: 'ignore' })
return (_hasYarn = true)
result = true
} catch (e) {
return (_hasYarn = false)
result = false
}
_hasYarn.set(context, result)
return result
}

exports.hasGit = () => {
exports.hasGit = (context = undefined) => {
if (process.env.VUE_CLI_TEST) {
return true
}
if (_hasGit != null) {
return _hasGit
if (_hasGit.has(context)) {
return _hasGit.get(context)
}
let result
try {
execSync('git --version', { stdio: 'ignore' })
return (_hasGit = true)
execSync('git --version', { stdio: 'ignore', cwd: context })
result = true
} catch (e) {
return (_hasGit = false)
result = false
}
_hasGit.set(context, result)
return result
}
8 changes: 4 additions & 4 deletions packages/@vue/cli-ui/apollo-server/connectors/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function install ({ id, type }, context) {
status: 'dependency-install',
args: [id]
})
await installPackage(cwd.get(), getCommand(), null, id, type === 'devDependencies')
await installPackage(cwd.get(), getCommand(cwd.get()), null, id, type === 'devDependencies')

logs.add({
message: `Dependency ${id} installed`,
Expand Down Expand Up @@ -178,7 +178,7 @@ function uninstall ({ id }, context) {

const dep = findOne(id, context)

await uninstallPackage(cwd.get(), getCommand(), null, id)
await uninstallPackage(cwd.get(), getCommand(cwd.get()), null, id)

logs.add({
message: `Dependency ${id} uninstalled`,
Expand All @@ -204,7 +204,7 @@ function update ({ id }, context) {

const dep = findOne(id, context)
const { current, wanted } = await getVersion(dep, context)
await updatePackage(cwd.get(), getCommand(), null, id)
await updatePackage(cwd.get(), getCommand(cwd.get()), null, id)

logs.add({
message: `Dependency ${id} updated from ${current} to ${wanted}`,
Expand Down Expand Up @@ -249,7 +249,7 @@ function updateAll (context) {
args: [updatedDeps.length]
})

await updatePackage(cwd.get(), getCommand(), null, updatedDeps.map(
await updatePackage(cwd.get(), getCommand(cwd.get()), null, updatedDeps.map(
p => p.id
).join(' '))

Expand Down
12 changes: 12 additions & 0 deletions packages/@vue/cli-ui/apollo-server/connectors/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ const path = require('path')
const parseDiff = require('../util/parse-diff')
// Connectors
const cwd = require('./cwd')
// Utils
const { hasGit } = require('@vue/cli-shared-utils')

async function getNewFiles (context) {
if (!hasGit(cwd.get())) return []

const { stdout } = await execa('git', [
'ls-files',
'-o',
Expand All @@ -20,6 +24,8 @@ async function getNewFiles (context) {
}

async function getDiffs (context) {
if (!hasGit(cwd.get())) return []

const newFiles = await getNewFiles(context)
await execa('git', ['add', '-N', '*'], {
cwd: cwd.get()
Expand All @@ -40,6 +46,8 @@ async function getDiffs (context) {
}

async function commit (message, context) {
if (!hasGit(cwd.get())) return false

await execa('git', ['add', '*'], {
cwd: cwd.get()
})
Expand All @@ -50,13 +58,17 @@ async function commit (message, context) {
}

async function reset (context) {
if (!hasGit(cwd.get())) return false

await execa('git', ['reset'], {
cwd: cwd.get()
})
return true
}

async function getRoot (context) {
if (!hasGit(cwd.get())) return cwd.get()

const { stdout } = await execa('git', [
'rev-parse',
'--show-toplevel'
Expand Down
8 changes: 4 additions & 4 deletions packages/@vue/cli-ui/apollo-server/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function install (id, context) {
if (process.env.VUE_CLI_DEBUG && isOfficialPlugin(id)) {
mockInstall(id, context)
} else {
await installPackage(cwd.get(), getCommand(), null, id)
await installPackage(cwd.get(), getCommand(cwd.get()), null, id)
}
await initPrompts(id, context)
installationStep = 'config'
Expand Down Expand Up @@ -250,7 +250,7 @@ function uninstall (id, context) {
if (process.env.VUE_CLI_DEBUG && isOfficialPlugin(id)) {
mockUninstall(id, context)
} else {
await uninstallPackage(cwd.get(), getCommand(), null, id)
await uninstallPackage(cwd.get(), getCommand(cwd.get()), null, id)
}
currentPluginId = null
installationStep = null
Expand Down Expand Up @@ -330,7 +330,7 @@ function update (id, context) {
const plugin = findOne(id, context)
const { current, wanted } = await dependencies.getVersion(plugin, context)

await updatePackage(cwd.get(), getCommand(), null, id)
await updatePackage(cwd.get(), getCommand(cwd.get()), null, id)

logs.add({
message: `Plugin ${id} updated from ${current} to ${wanted}`,
Expand Down Expand Up @@ -377,7 +377,7 @@ async function updateAll (context) {
args: [updatedPlugins.length]
})

await updatePackage(cwd.get(), getCommand(), null, updatedPlugins.map(
await updatePackage(cwd.get(), getCommand(cwd.get()), null, updatedPlugins.map(
p => p.id
).join(' '))

Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-ui/apollo-server/util/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const {
} = require('@vue/cli-shared-utils')
const { loadOptions } = require('@vue/cli/lib/options')

exports.getCommand = function () {
return loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
exports.getCommand = function (context) {
return loadOptions().packageManager || (hasYarn(context) ? 'yarn' : 'npm')
}