Skip to content

Commit

Permalink
Add debug code for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 23, 2021
1 parent 319de91 commit 4b5b4a1
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions update-db.js
Expand Up @@ -164,9 +164,11 @@ function updatePnpmLockfile (lock, latest) {
for (i = 0; i < lines.length; i++) {
if (lines[i].indexOf('caniuse-lite:') >= 0) {
lineParts = lines[i].split(/:\s?/, 2)
console.log(1, lines[i])
versions[lineParts[1]] = true
lines[i] = lineParts[0] + ': ' + latest.version
} else if (lines[i].indexOf('/caniuse-lite') >= 0) {
console.log(1, lines[i])
lineParts = lines[i].split(/([/:])/)
for (j = 0; j < lineParts.length; j++) {
if (lineParts[j].indexOf('caniuse-lite') >= 0) {
Expand All @@ -179,7 +181,8 @@ function updatePnpmLockfile (lock, latest) {
for (i = i + 1; i < lines.length; i++) {
if (lines[i].indexOf('integrity: ') !== -1) {
lines[i] = lines[i].replace(
/integrity: .+/, 'integrity: ' + latest.dist.integrity
/integrity: .+/,
'integrity: ' + latest.dist.integrity
)
} else if (lines[i].indexOf(' /') !== -1) {
break
Expand All @@ -204,11 +207,13 @@ function updateLockfile (lock, latest) {
function updatePackageManually (print, lock, latest) {
var lockfileData = updateLockfile(lock, latest)
var caniuseVersions = Object.keys(lockfileData.versions).sort()
if (caniuseVersions.length === 1 &&
caniuseVersions[0] === latest.version) {
if (caniuseVersions.length === 1 && caniuseVersions[0] === latest.version) {
print(
'Installed version: ' + pico.bold(pico.green(latest.version)) + '\n' +
pico.bold(pico.green('caniuse-lite is up to date')) + '\n'
'Installed version: ' +
pico.bold(pico.green(latest.version)) +
'\n' +
pico.bold(pico.green('caniuse-lite is up to date')) +
'\n'
)
return
}
Expand All @@ -218,27 +223,31 @@ function updatePackageManually (print, lock, latest) {
}
print(
'Installed version' +
(caniuseVersions.length === 1 ? ': ' : 's: ') +
pico.bold(pico.red(caniuseVersions.join(', '))) +
'\n' +
'Removing old caniuse-lite from lock file\n'
(caniuseVersions.length === 1 ? ': ' : 's: ') +
pico.bold(pico.red(caniuseVersions.join(', '))) +
'\n' +
'Removing old caniuse-lite from lock file\n'
)
fs.writeFileSync(lock.file, lockfileData.content)

var install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install'
print(
'Installing new caniuse-lite version\n' +
pico.yellow('$ ' + install + ' caniuse-lite') + '\n'
pico.yellow('$ ' + install + ' caniuse-lite') +
'\n'
)
try {
childProcess.execSync(install + ' caniuse-lite')
} catch (e) /* istanbul ignore next */ {
print(
pico.red(
'\n' +
e.stack + '\n\n' +
'Problem with `' + install + ' caniuse-lite` call. ' +
'Run it manually.\n'
e.stack +
'\n\n' +
'Problem with `' +
install +
' caniuse-lite` call. ' +
'Run it manually.\n'
)
)
process.exit(1)
Expand All @@ -247,7 +256,8 @@ function updatePackageManually (print, lock, latest) {
var del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall'
print(
'Cleaning package.json dependencies from caniuse-lite\n' +
pico.yellow('$ ' + del + ' caniuse-lite') + '\n'
pico.yellow('$ ' + del + ' caniuse-lite') +
'\n'
)
childProcess.execSync(del + ' caniuse-lite')
}
Expand All @@ -256,10 +266,6 @@ module.exports = function updateDB (print) {
var lock = detectLockfile()
var latest = getLatestInfo(lock)

if (Array.isArray(latest.version)) {
latest.version = latest.version[0]
}

var browsersListRetrievalError
var oldBrowsersList
try {
Expand All @@ -268,25 +274,27 @@ module.exports = function updateDB (print) {
browsersListRetrievalError = e
}

print(
'Latest version: ' + pico.bold(pico.green(latest.version)) + '\n'
)
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'
pico.yellow('$ ' + update + ' caniuse-lite') +
'\n'
)
try {
childProcess.execSync(update + ' caniuse-lite')
} catch (e) /* istanbul ignore next */ {
print(
pico.red(
'\n' +
e.stack + '\n\n' +
'Problem with `' + update + ' caniuse-lite` call. ' +
'Run it manually.\n'
e.stack +
'\n\n' +
'Problem with `' +
update +
' caniuse-lite` call. ' +
'Run it manually.\n'
)
)
process.exit(1)
Expand All @@ -310,9 +318,10 @@ module.exports = function updateDB (print) {
print(
pico.red(
'\n' +
browsersListRetrievalError.stack + '\n\n' +
'Problem with browser list retrieval.\n' +
'Target browser changes won鈥檛 be shown.\n'
browsersListRetrievalError.stack +
'\n\n' +
'Problem with browser list retrieval.\n' +
'Target browser changes won鈥檛 be shown.\n'
)
)
} else {
Expand Down

0 comments on commit 4b5b4a1

Please sign in to comment.