update-browserslist-db 1.0.10 → 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.
Files changed (3) hide show
  1. package/README.md +1 -2
  2. package/index.js +31 -28
  3. 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 **[full docs](https://github.com/browserslist/update-db#readme)** on GitHub.
22
+ Read full docs **[here](https://github.com/browserslist/update-db#readme)**.
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
- let childProcess = require('child_process')
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 = path.join(packageDir, 'package-lock.json')
38
- let lockfileShrinkwrap = path.join(packageDir, 'npm-shrinkwrap.json')
39
- let lockfileYarn = path.join(packageDir, 'yarn.lock')
40
- let lockfilePnpm = path.join(packageDir, 'pnpm-lock.yaml')
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 (fs.existsSync(lockfilePnpm)) {
42
+ if (existsSync(lockfilePnpm)) {
43
43
  return { mode: 'pnpm', file: lockfilePnpm }
44
- } else if (fs.existsSync(lockfileNpm)) {
44
+ } else if (existsSync(lockfileNpm)) {
45
45
  return { mode: 'npm', file: lockfileNpm }
46
- } else if (fs.existsSync(lockfileYarn)) {
46
+ } else if (existsSync(lockfileYarn)) {
47
47
  let lock = { mode: 'yarn', file: lockfileYarn }
48
- lock.content = fs.readFileSync(lock.file).toString()
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 (fs.existsSync(lockfileShrinkwrap)) {
51
+ } else if (existsSync(lockfileShrinkwrap)) {
52
52
  return { mode: 'npm', file: lockfileShrinkwrap }
53
53
  }
54
54
  throw new BrowserslistUpdateError(
@@ -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
- childProcess.execSync('yarn info caniuse-lite --json').toString()
64
- ).data
62
+ return JSON.parse(execSync('yarn info caniuse-lite --json').toString())
63
+ .data
65
64
  } else {
66
65
  return JSON.parse(
67
- childProcess.execSync('yarn npm info caniuse-lite --json').toString()
66
+ execSync('yarn 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 = fs.readFileSync(lock.file).toString()
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(latest.version)) +
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,7 +207,7 @@ function updatePackageManually(print, lock, latest) {
204
207
  '\n' +
205
208
  'Removing old caniuse-lite from lock file\n'
206
209
  )
207
- fs.writeFileSync(lock.file, lockfileData.content)
210
+ writeFileSync(lock.file, lockfileData.content)
208
211
 
209
212
  let install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install'
210
213
  print(
@@ -213,7 +216,7 @@ function updatePackageManually(print, lock, latest) {
213
216
  '\n'
214
217
  )
215
218
  try {
216
- childProcess.execSync(install + ' caniuse-lite')
219
+ execSync(install + ' caniuse-lite')
217
220
  } catch (e) /* c8 ignore start */ {
218
221
  print(
219
222
  pico.red(
@@ -235,13 +238,13 @@ function updatePackageManually(print, lock, latest) {
235
238
  pico.yellow('$ ' + del + ' caniuse-lite') +
236
239
  '\n'
237
240
  )
238
- childProcess.execSync(del + ' caniuse-lite')
241
+ execSync(del + ' caniuse-lite')
239
242
  }
240
243
 
241
244
  function updateWith(print, cmd) {
242
245
  print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
243
246
  try {
244
- childProcess.execSync(cmd)
247
+ execSync(cmd)
245
248
  } catch (e) /* c8 ignore start */ {
246
249
  print(pico.red(e.stdout.toString()))
247
250
  print(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-browserslist-db",
3
- "version": "1.0.10",
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
  }