Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid process hanging when trying to get Chrome version #5315

Merged
merged 2 commits into from Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@vue/cli-shared-utils/index.js
Expand Up @@ -19,3 +19,10 @@
exports.chalk = require('chalk')
exports.execa = require('execa')
exports.semver = require('semver')

Object.defineProperty(exports, 'installedBrowsers', {
enumerable: true,
get () {
return exports.getInstalledBrowsers()
}
})
76 changes: 37 additions & 39 deletions packages/@vue/cli-shared-utils/lib/env.js
Expand Up @@ -156,7 +156,8 @@ let hasCheckedBrowsers = false
function tryRun (cmd) {
try {
return execSync(cmd, {
stdio: [0, 'pipe', 'ignore']
stdio: [0, 'pipe', 'ignore'],
timeout: 10000
}).toString().trim()
} catch (e) {
return ''
Expand All @@ -177,44 +178,41 @@ function getMacAppVersion (bundleIdentifier) {
}
}

Object.defineProperty(exports, 'installedBrowsers', {
enumerable: true,
get () {
if (hasCheckedBrowsers) {
return browsers
}
hasCheckedBrowsers = true

if (exports.isLinux) {
browsers.chrome = getLinuxAppVersion('google-chrome')
browsers.firefox = getLinuxAppVersion('firefox')
} else if (exports.isMacintosh) {
browsers.chrome = getMacAppVersion('com.google.Chrome')
browsers.firefox = getMacAppVersion('org.mozilla.firefox')
} else if (exports.isWindows) {
// get chrome stable version
// https://stackoverflow.com/a/51773107/2302258
const chromeQueryResult = tryRun(
'reg query "HKLM\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
) || tryRun(
'reg query "HKCU\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
)
if (chromeQueryResult) {
const matched = chromeQueryResult.match(/REG_SZ\s+(\S*)$/)
browsers.chrome = matched && matched[1]
}

// get firefox version
// https://community.spiceworks.com/topic/111518-how-to-determine-version-of-installed-firefox-in-windows-batchscript
const ffQueryResult = tryRun(
'reg query "HKLM\\Software\\Mozilla\\Mozilla Firefox" /v CurrentVersion'
)
if (ffQueryResult) {
const matched = ffQueryResult.match(/REG_SZ\s+(\S*)$/)
browsers.firefox = matched && matched[1]
}
exports.getInstalledBrowsers = () => {
if (hasCheckedBrowsers) {
return browsers
}
hasCheckedBrowsers = true

if (exports.isLinux) {
browsers.chrome = getLinuxAppVersion('google-chrome')
browsers.firefox = getLinuxAppVersion('firefox')
} else if (exports.isMacintosh) {
browsers.chrome = getMacAppVersion('com.google.Chrome')
browsers.firefox = getMacAppVersion('org.mozilla.firefox')
} else if (exports.isWindows) {
// get chrome stable version
// https://stackoverflow.com/a/51773107/2302258
const chromeQueryResult = tryRun(
'reg query "HKLM\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
) || tryRun(
'reg query "HKCU\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
)
if (chromeQueryResult) {
const matched = chromeQueryResult.match(/REG_SZ\s+(\S*)$/)
browsers.chrome = matched && matched[1]
}

return browsers
// get firefox version
// https://community.spiceworks.com/topic/111518-how-to-determine-version-of-installed-firefox-in-windows-batchscript
const ffQueryResult = tryRun(
'reg query "HKLM\\Software\\Mozilla\\Mozilla Firefox" /v CurrentVersion'
)
if (ffQueryResult) {
const matched = ffQueryResult.match(/REG_SZ\s+(\S*)$/)
browsers.firefox = matched && matched[1]
}
}
})

return browsers
}