Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2024-12-03 18:37:29 +00:00
parent 49f7b34c3d
commit 5261a1223f
1640 changed files with 174830 additions and 182292 deletions

View file

@ -6,7 +6,7 @@
CLI tool to update `caniuse-lite` with browsers DB
from [Browserslist](https://github.com/browserslist/browserslist/) config.
Some queries like `last 2 version` or `>1%` depends on actual data
Some queries like `last 2 versions` or `>1%` depend on actual data
from `caniuse-lite`.
```sh
@ -18,6 +18,5 @@ npx update-browserslist-db@latest
alt="Sponsored by Evil Martians" width="236" height="54">
</a>
## Docs
Read **[full docs](https://github.com/browserslist/update-db#readme)** on GitHub.
Read full docs **[here](https://github.com/browserslist/update-db#readme)**.

View file

@ -13,4 +13,5 @@ try {
)
process.exit(1)
}
// eslint-disable-next-line no-unused-vars
} catch (e) {}

View file

@ -1,6 +1,6 @@
/**
* Run update and print output to terminal.
*/
declare function updateDb(print?: (str: string) => void): Promise<void>
declare function updateDb(print?: (str: string) => void): void
export = updateDb

View file

@ -1,10 +1,10 @@
let childProcess = require('child_process')
let { execSync } = require('child_process')
let escalade = require('escalade/sync')
let { existsSync, readFileSync, writeFileSync } = require('fs')
let { join } = require('path')
let pico = require('picocolors')
let path = require('path')
let fs = require('fs')
const { detectIndent, detectEOL } = require('./utils')
const { detectEOL, detectIndent } = require('./utils')
function BrowserslistUpdateError(message) {
this.name = 'BrowserslistUpdateError'
@ -17,6 +17,10 @@ function BrowserslistUpdateError(message) {
BrowserslistUpdateError.prototype = Error.prototype
// Check if HADOOP_HOME is set to determine if this is running in a Hadoop environment
const IsHadoopExists = !!process.env.HADOOP_HOME
const yarnCommand = IsHadoopExists ? 'yarnpkg' : 'yarn'
/* c8 ignore next 3 */
function defaultPrint(str) {
process.stdout.write(str)
@ -34,22 +38,25 @@ function detectLockfile() {
)
}
let lockfileNpm = path.join(packageDir, 'package-lock.json')
let lockfileShrinkwrap = path.join(packageDir, 'npm-shrinkwrap.json')
let lockfileYarn = path.join(packageDir, 'yarn.lock')
let lockfilePnpm = path.join(packageDir, 'pnpm-lock.yaml')
let lockfileNpm = join(packageDir, 'package-lock.json')
let lockfileShrinkwrap = join(packageDir, 'npm-shrinkwrap.json')
let lockfileYarn = join(packageDir, 'yarn.lock')
let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
let lockfileBun = join(packageDir, 'bun.lockb')
if (fs.existsSync(lockfilePnpm)) {
return { mode: 'pnpm', file: lockfilePnpm }
} else if (fs.existsSync(lockfileNpm)) {
return { mode: 'npm', file: lockfileNpm }
} else if (fs.existsSync(lockfileYarn)) {
let lock = { mode: 'yarn', file: lockfileYarn }
lock.content = fs.readFileSync(lock.file).toString()
if (existsSync(lockfilePnpm)) {
return { file: lockfilePnpm, mode: 'pnpm' }
} else if (existsSync(lockfileBun)) {
return { file: lockfileBun, mode: 'bun' }
} else if (existsSync(lockfileNpm)) {
return { file: lockfileNpm, mode: 'npm' }
} else if (existsSync(lockfileYarn)) {
let lock = { file: lockfileYarn, mode: 'yarn' }
lock.content = readFileSync(lock.file).toString()
lock.version = /# yarn lockfile v1/.test(lock.content) ? 1 : 2
return lock
} else if (fs.existsSync(lockfileShrinkwrap)) {
return { mode: 'npm', file: lockfileShrinkwrap }
} else if (existsSync(lockfileShrinkwrap)) {
return { file: lockfileShrinkwrap, mode: 'npm' }
}
throw new BrowserslistUpdateError(
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"'
@ -60,22 +67,23 @@ function getLatestInfo(lock) {
if (lock.mode === 'yarn') {
if (lock.version === 1) {
return JSON.parse(
childProcess.execSync('yarn info caniuse-lite --json').toString()
execSync(yarnCommand + ' info caniuse-lite --json').toString()
).data
} else {
return JSON.parse(
childProcess.execSync('yarn npm info caniuse-lite --json').toString()
execSync(yarnCommand + ' npm info caniuse-lite --json').toString()
)
}
}
if (lock.mode === 'pnpm') {
return JSON.parse(
childProcess.execSync('pnpm info caniuse-lite --json').toString()
)
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
}
return JSON.parse(
childProcess.execSync('npm show caniuse-lite --json').toString()
)
if (lock.mode === 'bun') {
// TO-DO: No 'bun info' yet. Created issue: https://github.com/oven-sh/bun/issues/12280
return JSON.parse(execSync(' npm info caniuse-lite --json').toString())
}
return JSON.parse(execSync('npm show caniuse-lite --json').toString())
}
function getBrowsers() {
@ -126,6 +134,14 @@ function deletePackage(node, metadata) {
node.dependencies[i] = deletePackage(node.dependencies[i], metadata)
}
}
if (node.packages) {
for (let path in node.packages) {
if (path.endsWith('/caniuse-lite')) {
metadata.versions[node.packages[path].version] = true
delete node.packages[path]
}
}
}
return node
}
@ -165,7 +181,7 @@ function updateYarnLockfile(lock, latest) {
}
function updateLockfile(lock, latest) {
if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
if (!lock.content) lock.content = readFileSync(lock.file).toString()
let updatedLockFile
if (lock.mode === 'yarn') {
@ -186,7 +202,7 @@ function updatePackageManually(print, lock, latest) {
if (caniuseVersions.length === 1 && caniuseVersions[0] === latest.version) {
print(
'Installed version: ' +
pico.bold(pico.green(latest.version)) +
pico.bold(pico.green(caniuseVersions[0])) +
'\n' +
pico.bold(pico.green('caniuse-lite is up to date')) +
'\n'
@ -204,16 +220,17 @@ function updatePackageManually(print, lock, latest) {
'\n' +
'Removing old caniuse-lite from lock file\n'
)
fs.writeFileSync(lock.file, lockfileData.content)
writeFileSync(lock.file, lockfileData.content)
let install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install'
let install =
lock.mode === 'yarn' ? yarnCommand + ' add -W' : lock.mode + ' install'
print(
'Installing new caniuse-lite version\n' +
pico.yellow('$ ' + install + ' caniuse-lite') +
'\n'
)
try {
childProcess.execSync(install + ' caniuse-lite')
execSync(install + ' caniuse-lite')
} catch (e) /* c8 ignore start */ {
print(
pico.red(
@ -229,19 +246,20 @@ function updatePackageManually(print, lock, latest) {
process.exit(1)
} /* c8 ignore end */
let del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall'
let del =
lock.mode === 'yarn' ? yarnCommand + ' remove -W' : lock.mode + ' uninstall'
print(
'Cleaning package.json dependencies from caniuse-lite\n' +
pico.yellow('$ ' + del + ' caniuse-lite') +
'\n'
)
childProcess.execSync(del + ' caniuse-lite')
execSync(del + ' caniuse-lite')
}
function updateWith(print, cmd) {
print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
try {
childProcess.execSync(cmd)
execSync(cmd)
} catch (e) /* c8 ignore start */ {
print(pico.red(e.stdout.toString()))
print(
@ -274,9 +292,11 @@ module.exports = function updateDB(print = defaultPrint) {
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
if (lock.mode === 'yarn' && lock.version !== 1) {
updateWith(print, 'yarn up -R caniuse-lite')
updateWith(print, yarnCommand + ' up -R caniuse-lite')
} else if (lock.mode === 'pnpm') {
updateWith(print, 'pnpm up caniuse-lite')
} else if (lock.mode === 'bun') {
updateWith(print, 'bun update caniuse-lite')
} else {
updatePackageManually(print, lock, latest)
}
@ -293,15 +313,24 @@ module.exports = function updateDB(print = defaultPrint) {
}
if (listError) {
print(
pico.red(
'\n' +
listError.stack +
'\n\n' +
'Problem with browser list retrieval.\n' +
'Target browser changes wont be shown.\n'
if (listError.message.includes("Cannot find module 'browserslist'")) {
print(
pico.gray(
'Install `browserslist` to your direct dependencies ' +
'to see target browser changes\n'
)
)
)
} else {
print(
pico.red(
'\n' +
listError.stack +
'\n\n' +
'Problem with browser list retrieval.\n' +
'Target browser changes wont be shown.\n'
)
)
}
} else {
let changes = diffBrowsers(oldList, newList)
if (changes) {

View file

@ -1,6 +1,6 @@
{
"name": "update-browserslist-db",
"version": "1.0.10",
"version": "1.1.1",
"description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config",
"keywords": [
"caniuse",
@ -15,6 +15,10 @@
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/browserslist"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"author": "Andrey Sitnik <andrey@sitnik.ru>",
@ -26,13 +30,11 @@
"./package.json": "./package.json"
},
"dependencies": {
"escalade": "^3.1.1",
"picocolors": "^1.0.0"
"escalade": "^3.2.0",
"picocolors": "^1.1.0"
},
"peerDependencies": {
"browserslist": ">= 4.21.0"
},
"bin": {
"browserslist-lint": "cli.js"
}
"bin": "cli.js"
}

View file

@ -3,8 +3,11 @@ const { EOL } = require('os')
const getFirstRegexpMatchOrDefault = (text, regexp, defaultValue) => {
regexp.lastIndex = 0 // https://stackoverflow.com/a/11477448/4536543
let match = regexp.exec(text)
if (match !== null) return match[1]
return defaultValue
if (match !== null) {
return match[1]
} else {
return defaultValue
}
}
const DEFAULT_INDENT = ' '