update-browserslist-db 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
let {
|
|
1
|
+
let { existsSync, readFileSync, writeFileSync } = require('fs')
|
|
2
2
|
let { execSync } = require('child_process')
|
|
3
3
|
let { join } = require('path')
|
|
4
4
|
let escalade = require('escalade/sync')
|
|
5
5
|
let pico = require('picocolors')
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { detectEOL, detectIndent } = require('./utils')
|
|
8
8
|
|
|
9
9
|
function BrowserslistUpdateError(message) {
|
|
10
10
|
this.name = 'BrowserslistUpdateError'
|
|
@@ -40,16 +40,16 @@ function detectLockfile() {
|
|
|
40
40
|
let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
|
|
41
41
|
|
|
42
42
|
if (existsSync(lockfilePnpm)) {
|
|
43
|
-
return { mode: 'pnpm'
|
|
43
|
+
return { file: lockfilePnpm, mode: 'pnpm' }
|
|
44
44
|
} else if (existsSync(lockfileNpm)) {
|
|
45
|
-
return { mode: 'npm'
|
|
45
|
+
return { file: lockfileNpm, mode: 'npm' }
|
|
46
46
|
} else if (existsSync(lockfileYarn)) {
|
|
47
|
-
let lock = { mode: 'yarn'
|
|
47
|
+
let lock = { file: lockfileYarn, mode: 'yarn' }
|
|
48
48
|
lock.content = readFileSync(lock.file).toString()
|
|
49
49
|
lock.version = /# yarn lockfile v1/.test(lock.content) ? 1 : 2
|
|
50
50
|
return lock
|
|
51
51
|
} else if (existsSync(lockfileShrinkwrap)) {
|
|
52
|
-
return { mode: 'npm'
|
|
52
|
+
return { file: lockfileShrinkwrap, mode: 'npm' }
|
|
53
53
|
}
|
|
54
54
|
throw new BrowserslistUpdateError(
|
|
55
55
|
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"'
|
|
@@ -59,11 +59,11 @@ function detectLockfile() {
|
|
|
59
59
|
function getLatestInfo(lock) {
|
|
60
60
|
if (lock.mode === 'yarn') {
|
|
61
61
|
if (lock.version === 1) {
|
|
62
|
-
return JSON.parse(execSync('
|
|
62
|
+
return JSON.parse(execSync('yarnpkg info caniuse-lite --json').toString())
|
|
63
63
|
.data
|
|
64
64
|
} else {
|
|
65
65
|
return JSON.parse(
|
|
66
|
-
execSync('
|
|
66
|
+
execSync('yarnpkg npm info caniuse-lite --json').toString()
|
|
67
67
|
)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -209,10 +209,10 @@ function updatePackageManually(print, lock, latest) {
|
|
|
209
209
|
)
|
|
210
210
|
writeFileSync(lock.file, lockfileData.content)
|
|
211
211
|
|
|
212
|
-
let install = lock.mode === 'yarn' ? '
|
|
212
|
+
let install = lock.mode === 'yarn' ? 'yarnpkg add -W' : lock.mode + ' install'
|
|
213
213
|
print(
|
|
214
214
|
'Installing new caniuse-lite version\n' +
|
|
215
|
-
pico.yellow('$ ' + install + ' caniuse-lite') +
|
|
215
|
+
pico.yellow('$ ' + install.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
|
|
216
216
|
'\n'
|
|
217
217
|
)
|
|
218
218
|
try {
|
|
@@ -232,17 +232,22 @@ function updatePackageManually(print, lock, latest) {
|
|
|
232
232
|
process.exit(1)
|
|
233
233
|
} /* c8 ignore end */
|
|
234
234
|
|
|
235
|
-
let del =
|
|
235
|
+
let del =
|
|
236
|
+
lock.mode === 'yarn' ? 'yarnpkg remove -W' : lock.mode + ' uninstall'
|
|
236
237
|
print(
|
|
237
238
|
'Cleaning package.json dependencies from caniuse-lite\n' +
|
|
238
|
-
pico.yellow('$ ' + del + ' caniuse-lite') +
|
|
239
|
+
pico.yellow('$ ' + del.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
|
|
239
240
|
'\n'
|
|
240
241
|
)
|
|
241
242
|
execSync(del + ' caniuse-lite')
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
function updateWith(print, cmd) {
|
|
245
|
-
print(
|
|
246
|
+
print(
|
|
247
|
+
'Updating caniuse-lite version\n' +
|
|
248
|
+
pico.yellow('$ ' + cmd.replace('yarnpkg', 'yarn')) +
|
|
249
|
+
'\n'
|
|
250
|
+
)
|
|
246
251
|
try {
|
|
247
252
|
execSync(cmd)
|
|
248
253
|
} catch (e) /* c8 ignore start */ {
|
|
@@ -277,7 +282,7 @@ module.exports = function updateDB(print = defaultPrint) {
|
|
|
277
282
|
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
|
|
278
283
|
|
|
279
284
|
if (lock.mode === 'yarn' && lock.version !== 1) {
|
|
280
|
-
updateWith(print, '
|
|
285
|
+
updateWith(print, 'yarnpkg up -R caniuse-lite')
|
|
281
286
|
} else if (lock.mode === 'pnpm') {
|
|
282
287
|
updateWith(print, 'pnpm up caniuse-lite')
|
|
283
288
|
} else {
|