update-browserslist-db 1.2.3 → 1.3.2
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/LICENSE +1 -1
- package/README.md +17 -6
- package/check-npm-version.js +16 -13
- package/cli.js +2 -2
- package/index.js +107 -31
- package/package.json +7 -7
- package/utils.js +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright 2022 Andrey Sitnik <andrey@sitnik.
|
|
3
|
+
Copyright 2022 Andrey Sitnik <andrey@sitnik.es> and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -12,19 +12,30 @@ from `caniuse-lite`.
|
|
|
12
12
|
```sh
|
|
13
13
|
npx update-browserslist-db@latest
|
|
14
14
|
```
|
|
15
|
+
|
|
15
16
|
Or if using `pnpm`:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pnpm dlx update-browserslist-db latest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or if using `bun`:
|
|
23
|
+
|
|
16
24
|
```sh
|
|
17
|
-
|
|
25
|
+
bunx update-browserslist-db@latest
|
|
18
26
|
```
|
|
19
|
-
|
|
27
|
+
|
|
28
|
+
Or if using `yarn` 2+:
|
|
29
|
+
|
|
20
30
|
```sh
|
|
21
31
|
yarn dlx update-browserslist-db@latest
|
|
22
32
|
```
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
<img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" /> Update Browserslist DB is built by <b><a href="https://evilmartians.com/">Evil Martians</a></b>, an American design and engineering consultancy for <b>developer tools, AI, and cybersecurity startups</b>.
|
|
37
|
+
|
|
38
|
+
---
|
|
28
39
|
|
|
29
40
|
## Docs
|
|
30
41
|
Read full docs **[here](https://github.com/browserslist/update-db#readme)**.
|
package/check-npm-version.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
let { execSync } = require('child_process')
|
|
2
|
+
let { existsSync } = require('fs')
|
|
2
3
|
let pico = require('picocolors')
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'
|
|
5
|
+
if (!existsSync('deno.lock')) {
|
|
6
|
+
try {
|
|
7
|
+
let output = execSync('npm -v').toString().trim()
|
|
8
|
+
let version = parseInt(output.replace(/^[^\d]*/, ''))
|
|
9
|
+
if (version <= 6) {
|
|
10
|
+
process.stderr.write(
|
|
11
|
+
pico.red(
|
|
12
|
+
'Update npm or call ' +
|
|
13
|
+
pico.yellow('npx browserslist@latest --update-db') +
|
|
14
|
+
'\n'
|
|
15
|
+
)
|
|
12
16
|
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
} catch (e) {}
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
package/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ function getPackage() {
|
|
|
14
14
|
|
|
15
15
|
let args = process.argv.slice(2)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const USAGE = 'Usage:\n npx update-browserslist-db\n'
|
|
18
18
|
|
|
19
19
|
function isArg(arg) {
|
|
20
20
|
return args.some(i => i === arg)
|
|
@@ -28,7 +28,7 @@ function error(msg) {
|
|
|
28
28
|
if (isArg('--help') || isArg('-h')) {
|
|
29
29
|
process.stdout.write(getPackage().description + '.\n\n' + USAGE + '\n')
|
|
30
30
|
} else if (isArg('--version') || isArg('-v')) {
|
|
31
|
-
process.stdout.write('
|
|
31
|
+
process.stdout.write(getPackage().name + ' ' + getPackage().version + '\n')
|
|
32
32
|
} else {
|
|
33
33
|
try {
|
|
34
34
|
updateDb()
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
let { execSync } = require('child_process')
|
|
2
2
|
let escalade = require('escalade/sync')
|
|
3
3
|
let { existsSync, readFileSync, writeFileSync } = require('fs')
|
|
4
|
-
let { join } = require('path')
|
|
4
|
+
let { dirname, join } = require('path')
|
|
5
5
|
let pico = require('picocolors')
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let { detectEOL, detectIndent } = require('./utils')
|
|
8
8
|
|
|
9
9
|
function BrowserslistUpdateError(message) {
|
|
10
10
|
this.name = 'BrowserslistUpdateError'
|
|
@@ -18,8 +18,7 @@ function BrowserslistUpdateError(message) {
|
|
|
18
18
|
BrowserslistUpdateError.prototype = Error.prototype
|
|
19
19
|
|
|
20
20
|
// Check if HADOOP_HOME is set to determine if this is running in a Hadoop environment
|
|
21
|
-
const
|
|
22
|
-
const yarnCommand = IsHadoopExists ? 'yarnpkg' : 'yarn'
|
|
21
|
+
const YARN_CMD = process.env.HADOOP_HOME ? 'yarnpkg' : 'yarn'
|
|
23
22
|
|
|
24
23
|
/* c8 ignore next 3 */
|
|
25
24
|
function defaultPrint(str) {
|
|
@@ -44,6 +43,7 @@ function detectLockfile() {
|
|
|
44
43
|
let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
|
|
45
44
|
let lockfileBun = join(packageDir, 'bun.lock')
|
|
46
45
|
let lockfileBunBinary = join(packageDir, 'bun.lockb')
|
|
46
|
+
let lockfileDeno = join(packageDir, 'deno.lock')
|
|
47
47
|
|
|
48
48
|
if (existsSync(lockfilePnpm)) {
|
|
49
49
|
return { file: lockfilePnpm, mode: 'pnpm' }
|
|
@@ -58,32 +58,55 @@ function detectLockfile() {
|
|
|
58
58
|
return lock
|
|
59
59
|
} else if (existsSync(lockfileShrinkwrap)) {
|
|
60
60
|
return { file: lockfileShrinkwrap, mode: 'npm' }
|
|
61
|
+
} else if (existsSync(lockfileDeno)) {
|
|
62
|
+
return { file: lockfileDeno, mode: 'deno' }
|
|
61
63
|
}
|
|
62
64
|
throw new BrowserslistUpdateError(
|
|
63
|
-
'No lockfile found. Run "npm install", "yarn install" or "
|
|
65
|
+
'No lockfile found. Run "npm install", "yarn install", "pnpm install", "bun install" or "deno install"'
|
|
64
66
|
)
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
function getLatestInfo(lock) {
|
|
68
|
-
|
|
69
|
-
if (lock.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
try {
|
|
71
|
+
if (lock.mode === 'yarn') {
|
|
72
|
+
if (lock.version === 1) {
|
|
73
|
+
return JSON.parse(
|
|
74
|
+
execSync(YARN_CMD + ' info caniuse-lite --json').toString()
|
|
75
|
+
).data
|
|
76
|
+
} else {
|
|
77
|
+
return JSON.parse(
|
|
78
|
+
execSync(YARN_CMD + ' npm info caniuse-lite --json').toString()
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (lock.mode === 'pnpm') {
|
|
83
|
+
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
|
|
84
|
+
}
|
|
85
|
+
if (lock.mode === 'bun') {
|
|
86
|
+
return JSON.parse(execSync('bun info caniuse-lite --json').toString())
|
|
87
|
+
}
|
|
88
|
+
if (lock.mode === 'deno') {
|
|
89
|
+
let result = JSON.parse(
|
|
90
|
+
execSync(
|
|
91
|
+
'deno run -A npm:npm show caniuse-lite version --json'
|
|
92
|
+
).toString()
|
|
76
93
|
)
|
|
94
|
+
return { version: Array.isArray(result) ? result[0] : result }
|
|
77
95
|
}
|
|
78
|
-
}
|
|
79
|
-
if (lock.mode === 'pnpm') {
|
|
80
|
-
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
|
|
81
|
-
}
|
|
82
|
-
if (lock.mode === 'bun') {
|
|
83
|
-
return JSON.parse(execSync(' bun info caniuse-lite --json').toString())
|
|
84
|
-
}
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
return JSON.parse(execSync('npm show caniuse-lite --json').toString())
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (e.code === 'ENOENT' || e.status === 127) {
|
|
100
|
+
throw new BrowserslistUpdateError(
|
|
101
|
+
'Cannot find ' +
|
|
102
|
+
lock.mode +
|
|
103
|
+
' binary in PATH. Please install ' +
|
|
104
|
+
lock.mode +
|
|
105
|
+
' or run updates manually.'
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
throw e
|
|
109
|
+
}
|
|
87
110
|
}
|
|
88
111
|
|
|
89
112
|
function getBrowsers() {
|
|
@@ -223,7 +246,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
223
246
|
writeFileSync(lock.file, lockfileData.content)
|
|
224
247
|
|
|
225
248
|
let install =
|
|
226
|
-
lock.mode === 'yarn' ?
|
|
249
|
+
lock.mode === 'yarn' ? YARN_CMD + ' add -W' : lock.mode + ' install'
|
|
227
250
|
print(
|
|
228
251
|
'Installing new caniuse-lite version\n' +
|
|
229
252
|
pico.yellow('$ ' + install + ' caniuse-lite baseline-browser-mapping') +
|
|
@@ -247,7 +270,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
247
270
|
} /* c8 ignore end */
|
|
248
271
|
|
|
249
272
|
let del =
|
|
250
|
-
lock.mode === 'yarn' ?
|
|
273
|
+
lock.mode === 'yarn' ? YARN_CMD + ' remove -W' : lock.mode + ' uninstall'
|
|
251
274
|
print(
|
|
252
275
|
'Cleaning package.json dependencies from caniuse-lite\n' +
|
|
253
276
|
pico.yellow('$ ' + del + ' caniuse-lite baseline-browser-mapping') +
|
|
@@ -256,8 +279,57 @@ function updatePackageManually(print, lock, latest) {
|
|
|
256
279
|
execSync(del + ' caniuse-lite baseline-browser-mapping')
|
|
257
280
|
}
|
|
258
281
|
|
|
259
|
-
|
|
260
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Bun cannot update a transitive dependency by name: `bun update caniuse-lite`
|
|
284
|
+
* adds caniuse-lite to package.json as a new direct dependency at the latest
|
|
285
|
+
* version and leaves every nested copy - the ones that actually get resolved at
|
|
286
|
+
* runtime - on the old version. A temporary `overrides` entry reaches those,
|
|
287
|
+
* and the resolutions survive once it is taken back out.
|
|
288
|
+
*/
|
|
289
|
+
function updateBun(print, lock, latest) {
|
|
290
|
+
let pkgFile = join(dirname(lock.file), 'package.json')
|
|
291
|
+
let original = readFileSync(pkgFile)
|
|
292
|
+
let pkg = JSON.parse(original.toString())
|
|
293
|
+
let withOverride = {
|
|
294
|
+
...pkg,
|
|
295
|
+
overrides: {
|
|
296
|
+
...pkg.overrides,
|
|
297
|
+
'baseline-browser-mapping': 'latest',
|
|
298
|
+
'caniuse-lite': latest.version
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// The file is restored byte for byte below, so its formatting does not matter.
|
|
303
|
+
writeFileSync(pkgFile, JSON.stringify(withOverride, null, 2) + '\n')
|
|
304
|
+
|
|
305
|
+
print(
|
|
306
|
+
'Updating caniuse-lite version\n' +
|
|
307
|
+
pico.yellow('$ bun install') +
|
|
308
|
+
' (with a temporary caniuse-lite override)\n'
|
|
309
|
+
)
|
|
310
|
+
try {
|
|
311
|
+
execSync('bun install')
|
|
312
|
+
} catch (e) /* c8 ignore start */ {
|
|
313
|
+
writeFileSync(pkgFile, original)
|
|
314
|
+
print(pico.red(e.stdout.toString()))
|
|
315
|
+
print(
|
|
316
|
+
pico.red(
|
|
317
|
+
'\n' +
|
|
318
|
+
e.stack +
|
|
319
|
+
'\n\n' +
|
|
320
|
+
'Problem with `bun install` call. ' +
|
|
321
|
+
'Run it manually.\n'
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
process.exit(1)
|
|
325
|
+
} /* c8 ignore end */
|
|
326
|
+
|
|
327
|
+
writeFileSync(pkgFile, original)
|
|
328
|
+
updateWith(print, 'bun install', 'Removing the temporary override')
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function updateWith(print, cmd, message = 'Updating caniuse-lite version') {
|
|
332
|
+
print(message + '\n' + pico.yellow('$ ' + cmd) + '\n')
|
|
261
333
|
try {
|
|
262
334
|
execSync(cmd)
|
|
263
335
|
} catch (e) /* c8 ignore start */ {
|
|
@@ -292,18 +364,22 @@ module.exports = function updateDB(print = defaultPrint) {
|
|
|
292
364
|
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
|
|
293
365
|
|
|
294
366
|
if (lock.mode === 'yarn' && lock.version !== 1) {
|
|
295
|
-
updateWith(
|
|
296
|
-
print,
|
|
297
|
-
yarnCommand + ' up -R caniuse-lite baseline-browser-mapping'
|
|
298
|
-
)
|
|
367
|
+
updateWith(print, YARN_CMD + ' up -R caniuse-lite baseline-browser-mapping')
|
|
299
368
|
} else if (lock.mode === 'pnpm') {
|
|
300
369
|
let lockContent = readFileSync(lock.file).toString()
|
|
301
370
|
let packages = lockContent.includes('baseline-browser-mapping')
|
|
302
371
|
? 'caniuse-lite baseline-browser-mapping'
|
|
303
372
|
: 'caniuse-lite'
|
|
304
|
-
updateWith(print, 'pnpm up --depth=
|
|
373
|
+
updateWith(print, 'pnpm up --depth=9999 --no-save ' + packages)
|
|
305
374
|
} else if (lock.mode === 'bun') {
|
|
306
|
-
|
|
375
|
+
updateBun(print, lock, latest)
|
|
376
|
+
} else if (lock.mode === 'deno') {
|
|
377
|
+
updateWith(print, 'deno add npm:caniuse-lite npm:baseline-browser-mapping')
|
|
378
|
+
updateWith(
|
|
379
|
+
print,
|
|
380
|
+
'deno remove caniuse-lite baseline-browser-mapping',
|
|
381
|
+
'Cleaning package.json dependencies from caniuse-lite'
|
|
382
|
+
)
|
|
307
383
|
} else {
|
|
308
384
|
updatePackageManually(print, lock, latest)
|
|
309
385
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "update-browserslist-db",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"caniuse",
|
|
7
6
|
"browsers",
|
|
7
|
+
"caniuse",
|
|
8
8
|
"target"
|
|
9
9
|
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Andrey Sitnik <andrey@sitnik.es>",
|
|
12
|
+
"repository": "browserslist/update-db",
|
|
10
13
|
"funding": [
|
|
11
14
|
{
|
|
12
15
|
"type": "opencollective",
|
|
@@ -21,9 +24,7 @@
|
|
|
21
24
|
"url": "https://github.com/sponsors/ai"
|
|
22
25
|
}
|
|
23
26
|
],
|
|
24
|
-
"
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"repository": "browserslist/update-db",
|
|
27
|
+
"bin": "cli.js",
|
|
27
28
|
"types": "./index.d.ts",
|
|
28
29
|
"exports": {
|
|
29
30
|
".": "./index.js",
|
|
@@ -35,6 +36,5 @@
|
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"browserslist": ">= 4.21.0"
|
|
38
|
-
}
|
|
39
|
-
"bin": "cli.js"
|
|
39
|
+
}
|
|
40
40
|
}
|
package/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { EOL } = require('os')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function getFirstRegexpMatchOrDefault(text, regexp, defaultValue) {
|
|
4
4
|
regexp.lastIndex = 0 // https://stackoverflow.com/a/11477448/4536543
|
|
5
5
|
let match = regexp.exec(text)
|
|
6
6
|
if (match !== null) {
|