update-browserslist-db 1.3.0 → 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.
@@ -4,7 +4,8 @@ let pico = require('picocolors')
4
4
 
5
5
  if (!existsSync('deno.lock')) {
6
6
  try {
7
- let version = parseInt(execSync('npm -v'))
7
+ let output = execSync('npm -v').toString().trim()
8
+ let version = parseInt(output.replace(/^[^\d]*/, ''))
8
9
  if (version <= 6) {
9
10
  process.stderr.write(
10
11
  pico.red(
package/cli.js CHANGED
@@ -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('browserslist-lint ' + getPackage().version + '\n')
31
+ process.stdout.write(getPackage().name + ' ' + getPackage().version + '\n')
32
32
  } else {
33
33
  try {
34
34
  updateDb()
package/index.js CHANGED
@@ -1,7 +1,7 @@
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')
@@ -67,31 +67,46 @@ function detectLockfile() {
67
67
  }
68
68
 
69
69
  function getLatestInfo(lock) {
70
- if (lock.mode === 'yarn') {
71
- if (lock.version === 1) {
72
- return JSON.parse(
73
- execSync(YARN_CMD + ' info caniuse-lite --json').toString()
74
- ).data
75
- } else {
76
- return JSON.parse(
77
- execSync(YARN_CMD + ' npm info caniuse-lite --json').toString()
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()
78
93
  )
94
+ return { version: Array.isArray(result) ? result[0] : result }
79
95
  }
80
- }
81
- if (lock.mode === 'pnpm') {
82
- return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
83
- }
84
- if (lock.mode === 'bun') {
85
- return JSON.parse(execSync(' bun info caniuse-lite --json').toString())
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
- }
93
96
 
94
- return JSON.parse(execSync('npm show caniuse-lite --json').toString())
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
+ }
95
110
  }
96
111
 
97
112
  function getBrowsers() {
@@ -264,6 +279,55 @@ function updatePackageManually(print, lock, latest) {
264
279
  execSync(del + ' caniuse-lite baseline-browser-mapping')
265
280
  }
266
281
 
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
+
267
331
  function updateWith(print, cmd, message = 'Updating caniuse-lite version') {
268
332
  print(message + '\n' + pico.yellow('$ ' + cmd) + '\n')
269
333
  try {
@@ -306,9 +370,9 @@ module.exports = function updateDB(print = defaultPrint) {
306
370
  let packages = lockContent.includes('baseline-browser-mapping')
307
371
  ? 'caniuse-lite baseline-browser-mapping'
308
372
  : 'caniuse-lite'
309
- updateWith(print, 'pnpm up --depth=Infinity --no-save ' + packages)
373
+ updateWith(print, 'pnpm up --depth=9999 --no-save ' + packages)
310
374
  } else if (lock.mode === 'bun') {
311
- updateWith(print, 'bun update caniuse-lite baseline-browser-mapping')
375
+ updateBun(print, lock, latest)
312
376
  } else if (lock.mode === 'deno') {
313
377
  updateWith(print, 'deno add npm:caniuse-lite npm:baseline-browser-mapping')
314
378
  updateWith(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-browserslist-db",
3
- "version": "1.3.0",
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
6
  "browsers",