update-browserslist-db 1.0.9 → 1.0.11
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 +33 -25
- 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,8 +1,8 @@
|
|
|
1
|
-
let
|
|
1
|
+
let { writeFileSync, readFileSync, existsSync } = 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
7
|
const { detectIndent, detectEOL } = require('./utils')
|
|
8
8
|
|
|
@@ -34,21 +34,21 @@ 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 (
|
|
42
|
+
if (existsSync(lockfilePnpm)) {
|
|
43
43
|
return { mode: 'pnpm', file: lockfilePnpm }
|
|
44
|
-
} else if (
|
|
44
|
+
} else if (existsSync(lockfileNpm)) {
|
|
45
45
|
return { mode: 'npm', file: lockfileNpm }
|
|
46
|
-
} else if (
|
|
46
|
+
} else if (existsSync(lockfileYarn)) {
|
|
47
47
|
let lock = { mode: 'yarn', file: lockfileYarn }
|
|
48
|
-
lock.content =
|
|
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 (
|
|
51
|
+
} else if (existsSync(lockfileShrinkwrap)) {
|
|
52
52
|
return { mode: 'npm', file: lockfileShrinkwrap }
|
|
53
53
|
}
|
|
54
54
|
throw new BrowserslistUpdateError(
|
|
@@ -59,18 +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('yarn info caniuse-lite --json').toString())
|
|
63
|
+
.data
|
|
65
64
|
} else {
|
|
66
65
|
return JSON.parse(
|
|
67
|
-
|
|
66
|
+
execSync('yarn npm info caniuse-lite --json').toString()
|
|
68
67
|
)
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
if (lock.mode === 'pnpm') {
|
|
71
|
+
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
|
|
72
|
+
}
|
|
73
|
+
return JSON.parse(execSync('npm show caniuse-lite --json').toString())
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function getBrowsers() {
|
|
@@ -121,6 +121,14 @@ function deletePackage(node, metadata) {
|
|
|
121
121
|
node.dependencies[i] = deletePackage(node.dependencies[i], metadata)
|
|
122
122
|
}
|
|
123
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
|
+
}
|
|
124
132
|
return node
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -160,7 +168,7 @@ function updateYarnLockfile(lock, latest) {
|
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
function updateLockfile(lock, latest) {
|
|
163
|
-
if (!lock.content) lock.content =
|
|
171
|
+
if (!lock.content) lock.content = readFileSync(lock.file).toString()
|
|
164
172
|
|
|
165
173
|
let updatedLockFile
|
|
166
174
|
if (lock.mode === 'yarn') {
|
|
@@ -181,7 +189,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
181
189
|
if (caniuseVersions.length === 1 && caniuseVersions[0] === latest.version) {
|
|
182
190
|
print(
|
|
183
191
|
'Installed version: ' +
|
|
184
|
-
pico.bold(pico.green(
|
|
192
|
+
pico.bold(pico.green(caniuseVersions[0])) +
|
|
185
193
|
'\n' +
|
|
186
194
|
pico.bold(pico.green('caniuse-lite is up to date')) +
|
|
187
195
|
'\n'
|
|
@@ -199,7 +207,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
199
207
|
'\n' +
|
|
200
208
|
'Removing old caniuse-lite from lock file\n'
|
|
201
209
|
)
|
|
202
|
-
|
|
210
|
+
writeFileSync(lock.file, lockfileData.content)
|
|
203
211
|
|
|
204
212
|
let install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install'
|
|
205
213
|
print(
|
|
@@ -208,7 +216,7 @@ function updatePackageManually(print, lock, latest) {
|
|
|
208
216
|
'\n'
|
|
209
217
|
)
|
|
210
218
|
try {
|
|
211
|
-
|
|
219
|
+
execSync(install + ' caniuse-lite')
|
|
212
220
|
} catch (e) /* c8 ignore start */ {
|
|
213
221
|
print(
|
|
214
222
|
pico.red(
|
|
@@ -230,13 +238,13 @@ function updatePackageManually(print, lock, latest) {
|
|
|
230
238
|
pico.yellow('$ ' + del + ' caniuse-lite') +
|
|
231
239
|
'\n'
|
|
232
240
|
)
|
|
233
|
-
|
|
241
|
+
execSync(del + ' caniuse-lite')
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
function updateWith(print, cmd) {
|
|
237
245
|
print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
|
|
238
246
|
try {
|
|
239
|
-
|
|
247
|
+
execSync(cmd)
|
|
240
248
|
} catch (e) /* c8 ignore start */ {
|
|
241
249
|
print(pico.red(e.stdout.toString()))
|
|
242
250
|
print(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "update-browserslist-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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
|
}
|