update-browserslist-db 1.2.3 → 1.3.1
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 +15 -13
- package/cli.js +1 -1
- package/index.js +77 -16
- 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,19 @@
|
|
|
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 version = parseInt(execSync('npm -v'))
|
|
8
|
+
if (version <= 6) {
|
|
9
|
+
process.stderr.write(
|
|
10
|
+
pico.red(
|
|
11
|
+
'Update npm or call ' +
|
|
12
|
+
pico.yellow('npx browserslist@latest --update-db') +
|
|
13
|
+
'\n'
|
|
14
|
+
)
|
|
12
15
|
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
} catch (e) {}
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
package/cli.js
CHANGED
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,9 +58,11 @@ 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
|
|
|
@@ -68,11 +70,11 @@ function getLatestInfo(lock) {
|
|
|
68
70
|
if (lock.mode === 'yarn') {
|
|
69
71
|
if (lock.version === 1) {
|
|
70
72
|
return JSON.parse(
|
|
71
|
-
execSync(
|
|
73
|
+
execSync(YARN_CMD + ' info caniuse-lite --json').toString()
|
|
72
74
|
).data
|
|
73
75
|
} else {
|
|
74
76
|
return JSON.parse(
|
|
75
|
-
execSync(
|
|
77
|
+
execSync(YARN_CMD + ' npm info caniuse-lite --json').toString()
|
|
76
78
|
)
|
|
77
79
|
}
|
|
78
80
|
}
|
|
@@ -82,6 +84,12 @@ function getLatestInfo(lock) {
|
|
|
82
84
|
if (lock.mode === 'bun') {
|
|
83
85
|
return JSON.parse(execSync(' bun info caniuse-lite --json').toString())
|
|
84
86
|
}
|
|
87
|
+
if (lock.mode === 'deno') {
|
|
88
|
+
let result = JSON.parse(
|
|
89
|
+
execSync('deno x -y npm:npm show caniuse-lite version --json').toString()
|
|
90
|
+
)
|
|
91
|
+
return { version: Array.isArray(result) ? result[0] : result }
|
|
92
|
+
}
|
|
85
93
|
|
|
86
94
|
return JSON.parse(execSync('npm show caniuse-lite --json').toString())
|
|
87
95
|
}
|
|
@@ -223,7 +231,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
223
231
|
writeFileSync(lock.file, lockfileData.content)
|
|
224
232
|
|
|
225
233
|
let install =
|
|
226
|
-
lock.mode === 'yarn' ?
|
|
234
|
+
lock.mode === 'yarn' ? YARN_CMD + ' add -W' : lock.mode + ' install'
|
|
227
235
|
print(
|
|
228
236
|
'Installing new caniuse-lite version\n' +
|
|
229
237
|
pico.yellow('$ ' + install + ' caniuse-lite baseline-browser-mapping') +
|
|
@@ -247,7 +255,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
247
255
|
} /* c8 ignore end */
|
|
248
256
|
|
|
249
257
|
let del =
|
|
250
|
-
lock.mode === 'yarn' ?
|
|
258
|
+
lock.mode === 'yarn' ? YARN_CMD + ' remove -W' : lock.mode + ' uninstall'
|
|
251
259
|
print(
|
|
252
260
|
'Cleaning package.json dependencies from caniuse-lite\n' +
|
|
253
261
|
pico.yellow('$ ' + del + ' caniuse-lite baseline-browser-mapping') +
|
|
@@ -256,8 +264,57 @@ function updatePackageManually(print, lock, latest) {
|
|
|
256
264
|
execSync(del + ' caniuse-lite baseline-browser-mapping')
|
|
257
265
|
}
|
|
258
266
|
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Bun cannot update a transitive dependency by name: `bun update caniuse-lite`
|
|
269
|
+
* adds caniuse-lite to package.json as a new direct dependency at the latest
|
|
270
|
+
* version and leaves every nested copy - the ones that actually get resolved at
|
|
271
|
+
* runtime - on the old version. A temporary `overrides` entry reaches those,
|
|
272
|
+
* and the resolutions survive once it is taken back out.
|
|
273
|
+
*/
|
|
274
|
+
function updateBun(print, lock, latest) {
|
|
275
|
+
let pkgFile = join(dirname(lock.file), 'package.json')
|
|
276
|
+
let original = readFileSync(pkgFile)
|
|
277
|
+
let pkg = JSON.parse(original.toString())
|
|
278
|
+
let withOverride = {
|
|
279
|
+
...pkg,
|
|
280
|
+
overrides: {
|
|
281
|
+
...pkg.overrides,
|
|
282
|
+
'baseline-browser-mapping': 'latest',
|
|
283
|
+
'caniuse-lite': latest.version
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// The file is restored byte for byte below, so its formatting does not matter.
|
|
288
|
+
writeFileSync(pkgFile, JSON.stringify(withOverride, null, 2) + '\n')
|
|
289
|
+
|
|
290
|
+
print(
|
|
291
|
+
'Updating caniuse-lite version\n' +
|
|
292
|
+
pico.yellow('$ bun install') +
|
|
293
|
+
' (with a temporary caniuse-lite override)\n'
|
|
294
|
+
)
|
|
295
|
+
try {
|
|
296
|
+
execSync('bun install')
|
|
297
|
+
} catch (e) /* c8 ignore start */ {
|
|
298
|
+
writeFileSync(pkgFile, original)
|
|
299
|
+
print(pico.red(e.stdout.toString()))
|
|
300
|
+
print(
|
|
301
|
+
pico.red(
|
|
302
|
+
'\n' +
|
|
303
|
+
e.stack +
|
|
304
|
+
'\n\n' +
|
|
305
|
+
'Problem with `bun install` call. ' +
|
|
306
|
+
'Run it manually.\n'
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
process.exit(1)
|
|
310
|
+
} /* c8 ignore end */
|
|
311
|
+
|
|
312
|
+
writeFileSync(pkgFile, original)
|
|
313
|
+
updateWith(print, 'bun install', 'Removing the temporary override')
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function updateWith(print, cmd, message = 'Updating caniuse-lite version') {
|
|
317
|
+
print(message + '\n' + pico.yellow('$ ' + cmd) + '\n')
|
|
261
318
|
try {
|
|
262
319
|
execSync(cmd)
|
|
263
320
|
} catch (e) /* c8 ignore start */ {
|
|
@@ -292,10 +349,7 @@ module.exports = function updateDB(print = defaultPrint) {
|
|
|
292
349
|
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
|
|
293
350
|
|
|
294
351
|
if (lock.mode === 'yarn' && lock.version !== 1) {
|
|
295
|
-
updateWith(
|
|
296
|
-
print,
|
|
297
|
-
yarnCommand + ' up -R caniuse-lite baseline-browser-mapping'
|
|
298
|
-
)
|
|
352
|
+
updateWith(print, YARN_CMD + ' up -R caniuse-lite baseline-browser-mapping')
|
|
299
353
|
} else if (lock.mode === 'pnpm') {
|
|
300
354
|
let lockContent = readFileSync(lock.file).toString()
|
|
301
355
|
let packages = lockContent.includes('baseline-browser-mapping')
|
|
@@ -303,7 +357,14 @@ module.exports = function updateDB(print = defaultPrint) {
|
|
|
303
357
|
: 'caniuse-lite'
|
|
304
358
|
updateWith(print, 'pnpm up --depth=Infinity --no-save ' + packages)
|
|
305
359
|
} else if (lock.mode === 'bun') {
|
|
306
|
-
|
|
360
|
+
updateBun(print, lock, latest)
|
|
361
|
+
} else if (lock.mode === 'deno') {
|
|
362
|
+
updateWith(print, 'deno add npm:caniuse-lite npm:baseline-browser-mapping')
|
|
363
|
+
updateWith(
|
|
364
|
+
print,
|
|
365
|
+
'deno remove caniuse-lite baseline-browser-mapping',
|
|
366
|
+
'Cleaning package.json dependencies from caniuse-lite'
|
|
367
|
+
)
|
|
307
368
|
} else {
|
|
308
369
|
updatePackageManually(print, lock, latest)
|
|
309
370
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "update-browserslist-db",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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) {
|