Skip to content

Commit a1041a8

Browse files
authored
fix: avoid process hanging when trying to get Chrome version (#5315)
* fix: add a timeout, avoid process hanging fixes #5310 * fix: avoid accidentally trigerring the `installedBrowsers` getter fixes #5286
1 parent 4225c30 commit a1041a8

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

packages/@vue/cli-shared-utils/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@
1919
exports.chalk = require('chalk')
2020
exports.execa = require('execa')
2121
exports.semver = require('semver')
22+
23+
Object.defineProperty(exports, 'installedBrowsers', {
24+
enumerable: true,
25+
get () {
26+
return exports.getInstalledBrowsers()
27+
}
28+
})

packages/@vue/cli-shared-utils/lib/env.js

+37-39
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ let hasCheckedBrowsers = false
156156
function tryRun (cmd) {
157157
try {
158158
return execSync(cmd, {
159-
stdio: [0, 'pipe', 'ignore']
159+
stdio: [0, 'pipe', 'ignore'],
160+
timeout: 10000
160161
}).toString().trim()
161162
} catch (e) {
162163
return ''
@@ -177,44 +178,41 @@ function getMacAppVersion (bundleIdentifier) {
177178
}
178179
}
179180

180-
Object.defineProperty(exports, 'installedBrowsers', {
181-
enumerable: true,
182-
get () {
183-
if (hasCheckedBrowsers) {
184-
return browsers
185-
}
186-
hasCheckedBrowsers = true
187-
188-
if (exports.isLinux) {
189-
browsers.chrome = getLinuxAppVersion('google-chrome')
190-
browsers.firefox = getLinuxAppVersion('firefox')
191-
} else if (exports.isMacintosh) {
192-
browsers.chrome = getMacAppVersion('com.google.Chrome')
193-
browsers.firefox = getMacAppVersion('org.mozilla.firefox')
194-
} else if (exports.isWindows) {
195-
// get chrome stable version
196-
// https://stackoverflow.com/a/51773107/2302258
197-
const chromeQueryResult = tryRun(
198-
'reg query "HKLM\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
199-
) || tryRun(
200-
'reg query "HKCU\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
201-
)
202-
if (chromeQueryResult) {
203-
const matched = chromeQueryResult.match(/REG_SZ\s+(\S*)$/)
204-
browsers.chrome = matched && matched[1]
205-
}
206-
207-
// get firefox version
208-
// https://community.spiceworks.com/topic/111518-how-to-determine-version-of-installed-firefox-in-windows-batchscript
209-
const ffQueryResult = tryRun(
210-
'reg query "HKLM\\Software\\Mozilla\\Mozilla Firefox" /v CurrentVersion'
211-
)
212-
if (ffQueryResult) {
213-
const matched = ffQueryResult.match(/REG_SZ\s+(\S*)$/)
214-
browsers.firefox = matched && matched[1]
215-
}
181+
exports.getInstalledBrowsers = () => {
182+
if (hasCheckedBrowsers) {
183+
return browsers
184+
}
185+
hasCheckedBrowsers = true
186+
187+
if (exports.isLinux) {
188+
browsers.chrome = getLinuxAppVersion('google-chrome')
189+
browsers.firefox = getLinuxAppVersion('firefox')
190+
} else if (exports.isMacintosh) {
191+
browsers.chrome = getMacAppVersion('com.google.Chrome')
192+
browsers.firefox = getMacAppVersion('org.mozilla.firefox')
193+
} else if (exports.isWindows) {
194+
// get chrome stable version
195+
// https://stackoverflow.com/a/51773107/2302258
196+
const chromeQueryResult = tryRun(
197+
'reg query "HKLM\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
198+
) || tryRun(
199+
'reg query "HKCU\\Software\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}" /v pv /reg:32'
200+
)
201+
if (chromeQueryResult) {
202+
const matched = chromeQueryResult.match(/REG_SZ\s+(\S*)$/)
203+
browsers.chrome = matched && matched[1]
216204
}
217205

218-
return browsers
206+
// get firefox version
207+
// https://community.spiceworks.com/topic/111518-how-to-determine-version-of-installed-firefox-in-windows-batchscript
208+
const ffQueryResult = tryRun(
209+
'reg query "HKLM\\Software\\Mozilla\\Mozilla Firefox" /v CurrentVersion'
210+
)
211+
if (ffQueryResult) {
212+
const matched = ffQueryResult.match(/REG_SZ\s+(\S*)$/)
213+
browsers.firefox = matched && matched[1]
214+
}
219215
}
220-
})
216+
217+
return browsers
218+
}

0 commit comments

Comments
 (0)