update-browserslist-db 1.0.10 → 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/README.md +1 -2
- package/index.js +47 -39
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -18,6 +18,5 @@ npx update-browserslist-db@latest
|
|
|
18
18
|
alt="Sponsored by Evil Martians" width="236" height="54">
|
|
19
19
|
</a>
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
## Docs
|
|
23
|
-
Read
|
|
22
|
+
Read full docs **[here](https://github.com/browserslist/update-db#readme)**.
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
let
|
|
1
|
+
let { existsSync, readFileSync, writeFileSync } = require('fs')
|
|
2
|
+
let { execSync } = require('child_process')
|
|
3
|
+
let { join } = require('path')
|
|
2
4
|
let escalade = require('escalade/sync')
|
|
3
5
|
let pico = require('picocolors')
|
|
4
|
-
let path = require('path')
|
|
5
|
-
let fs = require('fs')
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { detectEOL, detectIndent } = require('./utils')
|
|
8
8
|
|
|
9
9
|
function BrowserslistUpdateError(message) {
|
|
10
10
|
this.name = 'BrowserslistUpdateError'
|
|
@@ -34,22 +34,22 @@ function detectLockfile() {
|
|
|
34
34
|
)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
let lockfileNpm =
|
|
38
|
-
let lockfileShrinkwrap =
|
|
39
|
-
let lockfileYarn =
|
|
40
|
-
let lockfilePnpm =
|
|
37
|
+
let lockfileNpm = join(packageDir, 'package-lock.json')
|
|
38
|
+
let lockfileShrinkwrap = join(packageDir, 'npm-shrinkwrap.json')
|
|
39
|
+
let lockfileYarn = join(packageDir, 'yarn.lock')
|
|
40
|
+
let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
|
|
41
41
|
|
|
42
|
-
if (
|
|
43
|
-
return { mode: 'pnpm'
|
|
44
|
-
} else if (
|
|
45
|
-
return { mode: 'npm'
|
|
46
|
-
} else if (
|
|
47
|
-
let lock = { mode: 'yarn'
|
|
48
|
-
lock.content =
|
|
42
|
+
if (existsSync(lockfilePnpm)) {
|
|
43
|
+
return { file: lockfilePnpm, mode: 'pnpm' }
|
|
44
|
+
} else if (existsSync(lockfileNpm)) {
|
|
45
|
+
return { file: lockfileNpm, mode: 'npm' }
|
|
46
|
+
} else if (existsSync(lockfileYarn)) {
|
|
47
|
+
let lock = { file: lockfileYarn, mode: 'yarn' }
|
|
48
|
+
lock.content = readFileSync(lock.file).toString()
|
|
49
49
|
lock.version = /# yarn lockfile v1/.test(lock.content) ? 1 : 2
|
|
50
50
|
return lock
|
|
51
|
-
} else if (
|
|
52
|
-
return { mode: 'npm'
|
|
51
|
+
} else if (existsSync(lockfileShrinkwrap)) {
|
|
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,23 +59,18 @@ function detectLockfile() {
|
|
|
59
59
|
function getLatestInfo(lock) {
|
|
60
60
|
if (lock.mode === 'yarn') {
|
|
61
61
|
if (lock.version === 1) {
|
|
62
|
-
return JSON.parse(
|
|
63
|
-
|
|
64
|
-
).data
|
|
62
|
+
return JSON.parse(execSync('yarnpkg info caniuse-lite --json').toString())
|
|
63
|
+
.data
|
|
65
64
|
} else {
|
|
66
65
|
return JSON.parse(
|
|
67
|
-
|
|
66
|
+
execSync('yarnpkg npm info caniuse-lite --json').toString()
|
|
68
67
|
)
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
if (lock.mode === 'pnpm') {
|
|
72
|
-
return JSON.parse(
|
|
73
|
-
childProcess.execSync('pnpm info caniuse-lite --json').toString()
|
|
74
|
-
)
|
|
71
|
+
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
|
|
75
72
|
}
|
|
76
|
-
return JSON.parse(
|
|
77
|
-
childProcess.execSync('npm show caniuse-lite --json').toString()
|
|
78
|
-
)
|
|
73
|
+
return JSON.parse(execSync('npm show caniuse-lite --json').toString())
|
|
79
74
|
}
|
|
80
75
|
|
|
81
76
|
function getBrowsers() {
|
|
@@ -126,6 +121,14 @@ function deletePackage(node, metadata) {
|
|
|
126
121
|
node.dependencies[i] = deletePackage(node.dependencies[i], metadata)
|
|
127
122
|
}
|
|
128
123
|
}
|
|
124
|
+
if (node.packages) {
|
|
125
|
+
for (let path in node.packages) {
|
|
126
|
+
if (path.endsWith('/caniuse-lite')) {
|
|
127
|
+
metadata.versions[node.packages[path].version] = true
|
|
128
|
+
delete node.packages[path]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
129
132
|
return node
|
|
130
133
|
}
|
|
131
134
|
|
|
@@ -165,7 +168,7 @@ function updateYarnLockfile(lock, latest) {
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
function updateLockfile(lock, latest) {
|
|
168
|
-
if (!lock.content) lock.content =
|
|
171
|
+
if (!lock.content) lock.content = readFileSync(lock.file).toString()
|
|
169
172
|
|
|
170
173
|
let updatedLockFile
|
|
171
174
|
if (lock.mode === 'yarn') {
|
|
@@ -186,7 +189,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
186
189
|
if (caniuseVersions.length === 1 && caniuseVersions[0] === latest.version) {
|
|
187
190
|
print(
|
|
188
191
|
'Installed version: ' +
|
|
189
|
-
pico.bold(pico.green(
|
|
192
|
+
pico.bold(pico.green(caniuseVersions[0])) +
|
|
190
193
|
'\n' +
|
|
191
194
|
pico.bold(pico.green('caniuse-lite is up to date')) +
|
|
192
195
|
'\n'
|
|
@@ -204,16 +207,16 @@ function updatePackageManually(print, lock, latest) {
|
|
|
204
207
|
'\n' +
|
|
205
208
|
'Removing old caniuse-lite from lock file\n'
|
|
206
209
|
)
|
|
207
|
-
|
|
210
|
+
writeFileSync(lock.file, lockfileData.content)
|
|
208
211
|
|
|
209
|
-
let install = lock.mode === 'yarn' ? '
|
|
212
|
+
let install = lock.mode === 'yarn' ? 'yarnpkg add -W' : lock.mode + ' install'
|
|
210
213
|
print(
|
|
211
214
|
'Installing new caniuse-lite version\n' +
|
|
212
|
-
pico.yellow('$ ' + install + ' caniuse-lite') +
|
|
215
|
+
pico.yellow('$ ' + install.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
|
|
213
216
|
'\n'
|
|
214
217
|
)
|
|
215
218
|
try {
|
|
216
|
-
|
|
219
|
+
execSync(install + ' caniuse-lite')
|
|
217
220
|
} catch (e) /* c8 ignore start */ {
|
|
218
221
|
print(
|
|
219
222
|
pico.red(
|
|
@@ -229,19 +232,24 @@ function updatePackageManually(print, lock, latest) {
|
|
|
229
232
|
process.exit(1)
|
|
230
233
|
} /* c8 ignore end */
|
|
231
234
|
|
|
232
|
-
let del =
|
|
235
|
+
let del =
|
|
236
|
+
lock.mode === 'yarn' ? 'yarnpkg remove -W' : lock.mode + ' uninstall'
|
|
233
237
|
print(
|
|
234
238
|
'Cleaning package.json dependencies from caniuse-lite\n' +
|
|
235
|
-
pico.yellow('$ ' + del + ' caniuse-lite') +
|
|
239
|
+
pico.yellow('$ ' + del.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
|
|
236
240
|
'\n'
|
|
237
241
|
)
|
|
238
|
-
|
|
242
|
+
execSync(del + ' caniuse-lite')
|
|
239
243
|
}
|
|
240
244
|
|
|
241
245
|
function updateWith(print, cmd) {
|
|
242
|
-
print(
|
|
246
|
+
print(
|
|
247
|
+
'Updating caniuse-lite version\n' +
|
|
248
|
+
pico.yellow('$ ' + cmd.replace('yarnpkg', 'yarn')) +
|
|
249
|
+
'\n'
|
|
250
|
+
)
|
|
243
251
|
try {
|
|
244
|
-
|
|
252
|
+
execSync(cmd)
|
|
245
253
|
} catch (e) /* c8 ignore start */ {
|
|
246
254
|
print(pico.red(e.stdout.toString()))
|
|
247
255
|
print(
|
|
@@ -274,7 +282,7 @@ module.exports = function updateDB(print = defaultPrint) {
|
|
|
274
282
|
print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
|
|
275
283
|
|
|
276
284
|
if (lock.mode === 'yarn' && lock.version !== 1) {
|
|
277
|
-
updateWith(print, '
|
|
285
|
+
updateWith(print, 'yarnpkg up -R caniuse-lite')
|
|
278
286
|
} else if (lock.mode === 'pnpm') {
|
|
279
287
|
updateWith(print, 'pnpm up caniuse-lite')
|
|
280
288
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "update-browserslist-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"caniuse",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
{
|
|
16
16
|
"type": "tidelift",
|
|
17
17
|
"url": "https://tidelift.com/funding/github/npm/browserslist"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "github",
|
|
21
|
+
"url": "https://github.com/sponsors/ai"
|
|
18
22
|
}
|
|
19
23
|
],
|
|
20
24
|
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
|
@@ -32,7 +36,5 @@
|
|
|
32
36
|
"peerDependencies": {
|
|
33
37
|
"browserslist": ">= 4.21.0"
|
|
34
38
|
},
|
|
35
|
-
"bin":
|
|
36
|
-
"browserslist-lint": "cli.js"
|
|
37
|
-
}
|
|
39
|
+
"bin": "cli.js"
|
|
38
40
|
}
|