Skip to content

Commit 725e6b4

Browse files
committed
Clean up code
1 parent 1d46a66 commit 725e6b4

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

test/update-db/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ if (!NODE_8 && !NODE_10) {
251251

252252
if (!NODE_8 && !NODE_10 && isInstalled('pnpm')) {
253253
let versions = ['1.0.30001000', '1.0.1234', '1.0.3000', '1.0.30001035']
254+
254255
test('updates caniuse-lite for pnpm', async () => {
255256
let dir = await chdir('update-pnpm', 'package.json', 'pnpm-lock.yaml')
256257
checkRunUpdateContents(versions.sort().join(', '), 'pnpm')

update-db.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ function updatePnpmLockfile(lock, latest) {
224224
function updateLockfile(lock, latest) {
225225
if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
226226

227-
if (lock.mode === 'npm') {
228-
return updateNpmLockfile(lock, latest)
229-
} else if (lock.mode === 'yarn') {
227+
if (lock.mode === 'yarn') {
230228
return updateYarnLockfile(lock, latest)
229+
} else if (lock.mode === 'pnpm') {
230+
return updatePnpmLockfile(lock, latest)
231+
} else {
232+
return updateNpmLockfile(lock, latest)
231233
}
232-
return updatePnpmLockfile(lock, latest)
233234
}
234235

235236
function updatePackageManually(print, lock, latest) {
@@ -290,6 +291,27 @@ function updatePackageManually(print, lock, latest) {
290291
childProcess.execSync(del + ' caniuse-lite')
291292
}
292293

294+
function updateWith(print, cmd) {
295+
print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
296+
try {
297+
childProcess.execSync(cmd)
298+
} catch (e) /* c8 ignore start */ {
299+
print(pico.red(e.stdout.toString()))
300+
print(
301+
pico.red(
302+
'\n' +
303+
e.stack +
304+
'\n\n' +
305+
'Problem with `' +
306+
cmd +
307+
'` call. ' +
308+
'Run it manually.\n'
309+
)
310+
)
311+
process.exit(1)
312+
} /* c8 ignore end */
313+
}
314+
293315
module.exports = function updateDB(print) {
294316
var lock = detectLockfile()
295317
var latest = getLatestInfo(lock)
@@ -305,28 +327,7 @@ module.exports = function updateDB(print) {
305327
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
306328

307329
if (lock.mode === 'yarn' && lock.version !== 1) {
308-
var update = 'yarn up -R'
309-
print(
310-
'Updating caniuse-lite version\n' +
311-
pico.yellow('$ ' + update + ' caniuse-lite') +
312-
'\n'
313-
)
314-
try {
315-
childProcess.execSync(update + ' caniuse-lite')
316-
} catch (e) /* c8 ignore start */ {
317-
print(
318-
pico.red(
319-
'\n' +
320-
e.stack +
321-
'\n\n' +
322-
'Problem with `' +
323-
update +
324-
' caniuse-lite` call. ' +
325-
'Run it manually.\n'
326-
)
327-
)
328-
process.exit(1)
329-
} /* c8 ignore end */
330+
updateWith(print, 'yarn up -R caniuse-lite')
330331
} else {
331332
updatePackageManually(print, lock, latest)
332333
}

0 commit comments

Comments
 (0)