Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 14, 2021
1 parent 1d46a66 commit 725e6b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions test/update-db/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ if (!NODE_8 && !NODE_10) {

if (!NODE_8 && !NODE_10 && isInstalled('pnpm')) {
let versions = ['1.0.30001000', '1.0.1234', '1.0.3000', '1.0.30001035']

test('updates caniuse-lite for pnpm', async () => {
let dir = await chdir('update-pnpm', 'package.json', 'pnpm-lock.yaml')
checkRunUpdateContents(versions.sort().join(', '), 'pnpm')
Expand Down
53 changes: 27 additions & 26 deletions update-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ function updatePnpmLockfile(lock, latest) {
function updateLockfile(lock, latest) {
if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()

if (lock.mode === 'npm') {
return updateNpmLockfile(lock, latest)
} else if (lock.mode === 'yarn') {
if (lock.mode === 'yarn') {
return updateYarnLockfile(lock, latest)
} else if (lock.mode === 'pnpm') {
return updatePnpmLockfile(lock, latest)
} else {
return updateNpmLockfile(lock, latest)
}
return updatePnpmLockfile(lock, latest)
}

function updatePackageManually(print, lock, latest) {
Expand Down Expand Up @@ -290,6 +291,27 @@ function updatePackageManually(print, lock, latest) {
childProcess.execSync(del + ' caniuse-lite')
}

function updateWith(print, cmd) {
print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
try {
childProcess.execSync(cmd)
} catch (e) /* c8 ignore start */ {
print(pico.red(e.stdout.toString()))
print(
pico.red(
'\n' +
e.stack +
'\n\n' +
'Problem with `' +
cmd +
'` call. ' +
'Run it manually.\n'
)
)
process.exit(1)
} /* c8 ignore end */
}

module.exports = function updateDB(print) {
var lock = detectLockfile()
var latest = getLatestInfo(lock)
Expand All @@ -305,28 +327,7 @@ module.exports = function updateDB(print) {
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')

if (lock.mode === 'yarn' && lock.version !== 1) {
var update = 'yarn up -R'
print(
'Updating caniuse-lite version\n' +
pico.yellow('$ ' + update + ' caniuse-lite') +
'\n'
)
try {
childProcess.execSync(update + ' caniuse-lite')
} catch (e) /* c8 ignore start */ {
print(
pico.red(
'\n' +
e.stack +
'\n\n' +
'Problem with `' +
update +
' caniuse-lite` call. ' +
'Run it manually.\n'
)
)
process.exit(1)
} /* c8 ignore end */
updateWith(print, 'yarn up -R caniuse-lite')
} else {
updatePackageManually(print, lock, latest)
}
Expand Down

0 comments on commit 725e6b4

Please sign in to comment.