update, text, response
This commit is contained in:
66
node_modules/update-browserslist-db/index.js
generated
vendored
66
node_modules/update-browserslist-db/index.js
generated
vendored
@@ -1,10 +1,10 @@
|
||||
let { writeFileSync, readFileSync, existsSync } = require('fs')
|
||||
let { execSync } = require('child_process')
|
||||
let { join } = require('path')
|
||||
let escalade = require('escalade/sync')
|
||||
let { existsSync, readFileSync, writeFileSync } = require('fs')
|
||||
let { join } = require('path')
|
||||
let pico = require('picocolors')
|
||||
|
||||
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)
|
||||
@@ -38,18 +42,22 @@ function detectLockfile() {
|
||||
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.lock')
|
||||
let lockfileBunBinary = join(packageDir, 'bun.lockb')
|
||||
|
||||
if (existsSync(lockfilePnpm)) {
|
||||
return { mode: 'pnpm', file: lockfilePnpm }
|
||||
return { file: lockfilePnpm, mode: 'pnpm' }
|
||||
} else if (existsSync(lockfileBun) || existsSync(lockfileBunBinary)) {
|
||||
return { file: lockfileBun, mode: 'bun' }
|
||||
} else if (existsSync(lockfileNpm)) {
|
||||
return { mode: 'npm', file: lockfileNpm }
|
||||
return { file: lockfileNpm, mode: 'npm' }
|
||||
} else if (existsSync(lockfileYarn)) {
|
||||
let lock = { mode: 'yarn', file: 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 (existsSync(lockfileShrinkwrap)) {
|
||||
return { mode: 'npm', file: lockfileShrinkwrap }
|
||||
return { file: lockfileShrinkwrap, mode: 'npm' }
|
||||
}
|
||||
throw new BrowserslistUpdateError(
|
||||
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"'
|
||||
@@ -59,17 +67,23 @@ function detectLockfile() {
|
||||
function getLatestInfo(lock) {
|
||||
if (lock.mode === 'yarn') {
|
||||
if (lock.version === 1) {
|
||||
return JSON.parse(execSync('yarn info caniuse-lite --json').toString())
|
||||
.data
|
||||
return JSON.parse(
|
||||
execSync(yarnCommand + ' info caniuse-lite --json').toString()
|
||||
).data
|
||||
} else {
|
||||
return JSON.parse(
|
||||
execSync('yarn npm info caniuse-lite --json').toString()
|
||||
execSync(yarnCommand + ' npm info caniuse-lite --json').toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
if (lock.mode === 'pnpm') {
|
||||
return JSON.parse(execSync('pnpm info 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())
|
||||
}
|
||||
|
||||
@@ -209,7 +223,8 @@ function updatePackageManually(print, lock, latest) {
|
||||
)
|
||||
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') +
|
||||
@@ -232,7 +247,8 @@ 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') +
|
||||
@@ -277,9 +293,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)
|
||||
}
|
||||
@@ -296,15 +314,21 @@ 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 won’t 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.gray(
|
||||
'Problem with browser list retrieval.\n' +
|
||||
'Target browser changes won’t be shown.\n'
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
let changes = diffBrowsers(oldList, newList)
|
||||
if (changes) {
|
||||
|
||||
Reference in New Issue
Block a user