update-browserslist-db 1.3.3 → 1.4.0

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 +6 -0
  2. package/index.js +113 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -25,6 +25,12 @@ Or if using `bun`:
25
25
  bunx update-browserslist-db@latest
26
26
  ```
27
27
 
28
+ Or if using `aube`:
29
+
30
+ ```sh
31
+ aubx update-browserslist-db@latest
32
+ ```
33
+
28
34
  Or if using `yarn` 2+:
29
35
 
30
36
  ```sh
package/index.js CHANGED
@@ -17,7 +17,6 @@ function BrowserslistUpdateError(message) {
17
17
 
18
18
  BrowserslistUpdateError.prototype = Error.prototype
19
19
 
20
- // Check if HADOOP_HOME is set to determine if this is running in a Hadoop environment
21
20
  const YARN_CMD = process.env.HADOOP_HOME ? 'yarnpkg' : 'yarn'
22
21
 
23
22
  /* c8 ignore next 3 */
@@ -41,11 +40,14 @@ function detectLockfile() {
41
40
  let lockfileShrinkwrap = join(packageDir, 'npm-shrinkwrap.json')
42
41
  let lockfileYarn = join(packageDir, 'yarn.lock')
43
42
  let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
43
+ let lockfileAube = join(packageDir, 'aube-lock.yaml')
44
44
  let lockfileBun = join(packageDir, 'bun.lock')
45
45
  let lockfileBunBinary = join(packageDir, 'bun.lockb')
46
46
  let lockfileDeno = join(packageDir, 'deno.lock')
47
47
 
48
- if (existsSync(lockfilePnpm)) {
48
+ if (existsSync(lockfileAube)) {
49
+ return { file: lockfileAube, mode: 'aube' }
50
+ } else if (existsSync(lockfilePnpm)) {
49
51
  return { file: lockfilePnpm, mode: 'pnpm' }
50
52
  } else if (existsSync(lockfileBun) || existsSync(lockfileBunBinary)) {
51
53
  return { file: lockfileBun, mode: 'bun' }
@@ -62,7 +64,7 @@ function detectLockfile() {
62
64
  return { file: lockfileDeno, mode: 'deno' }
63
65
  }
64
66
  throw new BrowserslistUpdateError(
65
- 'No lockfile found. Run "npm install", "yarn install", "pnpm install", "bun install" or "deno install"'
67
+ 'No lockfile found. Run "npm install", "yarn install", "pnpm install", "bun install", "deno install" or "aube install"'
66
68
  )
67
69
  }
68
70
 
@@ -70,6 +72,14 @@ function getLatestInfo(lock) {
70
72
  try {
71
73
  if (lock.mode === 'yarn') {
72
74
  if (lock.version === 1) {
75
+ let yarnMajorVersion = getYarnMajor()
76
+ if (yarnMajorVersion !== 1) {
77
+ throw new BrowserslistUpdateError(
78
+ 'This project has a Yarn v1 (classic) lockfile, but the installed ' +
79
+ `Yarn is Berry v${yarnMajorVersion}. Install and activate Yarn classic ` +
80
+ 'to update caniuse-lite.'
81
+ )
82
+ }
73
83
  return JSON.parse(
74
84
  execSync(YARN_CMD + ' info caniuse-lite --json').toString()
75
85
  ).data
@@ -85,6 +95,9 @@ function getLatestInfo(lock) {
85
95
  if (lock.mode === 'bun') {
86
96
  return JSON.parse(execSync('bun info caniuse-lite --json').toString())
87
97
  }
98
+ if (lock.mode === 'aube') {
99
+ return JSON.parse(execSync('aube info caniuse-lite --json').toString())
100
+ }
88
101
  if (lock.mode === 'deno') {
89
102
  let result = JSON.parse(
90
103
  execSync(
@@ -96,7 +109,20 @@ function getLatestInfo(lock) {
96
109
 
97
110
  return JSON.parse(execSync('npm show caniuse-lite --json').toString())
98
111
  } catch (e) {
99
- if (e.code === 'ENOENT' || e.status === 127) {
112
+ // ENOENT / status 127 are the POSIX "command not found" signals. cmd.exe
113
+ // instead reports `'<binary>' is not recognized as an internal or external
114
+ // command`. Anchor that phrase to the binary we actually launched so an
115
+ // unrelated "is not recognized" line in a real failure's output (e.g. a
116
+ // nested tool) is not mistaken for a missing package manager.
117
+ let binary = lock.mode === 'yarn' ? YARN_CMD : lock.mode
118
+ let missingOnWindows = new RegExp(
119
+ "'" + binary + "' is not recognized as an internal or external command"
120
+ )
121
+ if (
122
+ e.code === 'ENOENT' ||
123
+ e.status === 127 ||
124
+ missingOnWindows.test(commandErrorText(e))
125
+ ) {
100
126
  throw new BrowserslistUpdateError(
101
127
  'Cannot find ' +
102
128
  lock.mode +
@@ -109,6 +135,11 @@ function getLatestInfo(lock) {
109
135
  }
110
136
  }
111
137
 
138
+ function getYarnMajor() {
139
+ let version = execSync(YARN_CMD + ' --version').toString().trim()
140
+ return Number(version.split('.')[0])
141
+ }
142
+
112
143
  function getBrowsers() {
113
144
  let browserslist = require('browserslist')
114
145
  return browserslist().reduce((result, entry) => {
@@ -171,7 +202,13 @@ function deletePackage(node, metadata) {
171
202
  let yarnVersionRe = /version "(.*?)"/
172
203
 
173
204
  function updateYarnLockfile(lock, latest) {
174
- let blocks = lock.content.split(/(\n{2,})/).map(block => {
205
+ // Split entries on blank lines using LF. A CRLF lockfile has `\r\n\r\n`
206
+ // between entries, which `\n{2,}` cannot match, so the whole file would
207
+ // collapse into one block and no version be detected. CRLF can occur on any
208
+ // OS (git autocrlf, editor settings), so normalize regardless of platform;
209
+ // updateLockfile restores the original EOL on the returned content.
210
+ let normalized = lock.content.replace(/\r\n/g, '\n')
211
+ let blocks = normalized.split(/(\n{2,})/).map(block => {
175
212
  return block.split('\n')
176
213
  })
177
214
  let versions = {}
@@ -335,8 +372,36 @@ function commandErrorText(error) {
335
372
  .join('\n')
336
373
  }
337
374
 
375
+ function quotePnpmArg(arg) {
376
+ // cmd.exe expands %VAR% and !VAR! even inside double quotes. It also ignores
377
+ // the backslash in `\"`, so JSON values end up outside its quotes, where
378
+ // ^ & | < > ( ) run commands or redirect output. Refuse rather than run
379
+ // a mangled command.
380
+ if (/[%!^&|<>()]/.test(arg)) {
381
+ throw new BrowserslistUpdateError(
382
+ 'Cannot safely pass any of %!^&|<>() to pnpm on Windows: ' + arg
383
+ )
384
+ }
385
+ if (!/[\s"]/.test(arg)) return arg
386
+ // Escape embedded quotes (doubling any backslash run that precedes them) and
387
+ // double a trailing backslash run so it cannot escape the closing quote.
388
+ return '"' + arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/, '$1$1') + '"'
389
+ }
390
+
391
+ function runPnpm(args, options = {}) {
392
+ // Node on Windows cannot launch pnpm's `.cmd` shim without a shell
393
+ if (process.platform === 'win32') {
394
+ return execFileSync('pnpm', args.map(quotePnpmArg), {
395
+ ...options,
396
+ shell: true
397
+ })
398
+ }
399
+
400
+ return execFileSync('pnpm', args, options)
401
+ }
402
+
338
403
  function getPnpmConfig(name) {
339
- let output = execFileSync('pnpm', [
404
+ let output = runPnpm([
340
405
  'config',
341
406
  'get',
342
407
  name,
@@ -349,7 +414,7 @@ function getPnpmPackageTimes(name) {
349
414
  let times
350
415
  try {
351
416
  times = JSON.parse(
352
- execFileSync('pnpm', ['info', name, 'time', '--json']).toString()
417
+ runPnpm(['info', name, 'time', '--json']).toString()
353
418
  )
354
419
  } catch (error) /* c8 ignore start */ {
355
420
  throw new BrowserslistUpdateError(
@@ -438,6 +503,10 @@ function updatePnpmStrict(print, lock, packages) {
438
503
  ? readFileSync(workspaceFile)
439
504
  : undefined
440
505
  let originalLockfile = readFileSync(lock.file)
506
+ let packageFile = join(packageDir, 'package.json')
507
+ let originalPackage = existsSync(packageFile)
508
+ ? readFileSync(packageFile)
509
+ : undefined
441
510
  let command = 'pnpm config set overrides'
442
511
 
443
512
  print(
@@ -452,8 +521,7 @@ function updatePnpmStrict(print, lock, packages) {
452
521
  )
453
522
 
454
523
  try {
455
- execFileSync(
456
- 'pnpm',
524
+ runPnpm(
457
525
  [
458
526
  'config',
459
527
  'set',
@@ -472,7 +540,7 @@ function updatePnpmStrict(print, lock, packages) {
472
540
  pico.yellow('$ ' + command) +
473
541
  ' (with temporary policy-compliant overrides)\n'
474
542
  )
475
- execFileSync('pnpm', ['install', '--lockfile-only'], { cwd: packageDir })
543
+ runPnpm(['install', '--lockfile-only'], { cwd: packageDir })
476
544
 
477
545
  restoreFile(workspaceFile, originalWorkspace)
478
546
  // The lockfile no longer matches the restored overrides, and pnpm
@@ -481,11 +549,12 @@ function updatePnpmStrict(print, lock, packages) {
481
549
  print(
482
550
  'Removing temporary pnpm overrides\n' + pico.yellow('$ ' + command) + '\n'
483
551
  )
484
- execFileSync('pnpm', ['install', '--no-frozen-lockfile'], {
552
+ runPnpm(['install', '--no-frozen-lockfile'], {
485
553
  cwd: packageDir
486
554
  })
487
555
  } catch (error) /* c8 ignore start */ {
488
556
  restoreFile(workspaceFile, originalWorkspace)
557
+ restoreFile(packageFile, originalPackage)
489
558
  writeFileSync(lock.file, originalLockfile)
490
559
  print(pico.red(commandErrorText(error)))
491
560
  print(
@@ -495,21 +564,35 @@ function updatePnpmStrict(print, lock, packages) {
495
564
  } /* c8 ignore end */
496
565
  }
497
566
 
498
- function updatePnpm(print, lock) {
567
+ function getLockedPackages(lock) {
499
568
  let lockContent = readFileSync(lock.file).toString()
500
- let packages = lockContent.includes('baseline-browser-mapping')
569
+ return lockContent.includes('baseline-browser-mapping')
501
570
  ? ['caniuse-lite', 'baseline-browser-mapping']
502
571
  : ['caniuse-lite']
572
+ }
573
+
574
+ function updatePnpm(print, lock) {
575
+ let packages = getLockedPackages(lock)
503
576
  let command = 'pnpm up --depth=9999 --no-save ' + packages.join(' ')
504
577
 
505
578
  print('Updating caniuse-lite version\n' + pico.yellow('$ ' + command) + '\n')
506
579
  try {
507
- execFileSync('pnpm', ['up', '--depth=9999', '--no-save', ...packages], {
580
+ runPnpm(['up', '--depth=9999', '--no-save', ...packages], {
508
581
  stdio: 'pipe'
509
582
  })
510
583
  } catch (error) /* c8 ignore start */ {
511
584
  let text = commandErrorText(error)
512
- if (text.includes('ERR_PNPM_STRICT_MIN_RELEASE_AGE_REQUIRES_SAVE')) {
585
+ // pnpm versions before 12.4.2 can fail `up --no-save` under strict
586
+ // minimumReleaseAge. The error differs by version: 10 uses
587
+ // NO_MATURE_MATCHING_VERSION, 11 uses MINIMUM_RELEASE_AGE_VIOLATION, and
588
+ // 12.0–12.4.1 uses STRICT_MIN_RELEASE_AGE_REQUIRES_SAVE. In each case,
589
+ // resolve and pin the newest mature versions ourselves. pnpm 12.4.2+ does
590
+ // this natively and succeeds before reaching this catch.
591
+ if (
592
+ text.includes('ERR_PNPM_STRICT_MIN_RELEASE_AGE_REQUIRES_SAVE') ||
593
+ text.includes('ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION') ||
594
+ text.includes('ERR_PNPM_NO_MATURE_MATCHING_VERSION')
595
+ ) {
513
596
  updatePnpmStrict(print, lock, packages)
514
597
  } else {
515
598
  print(pico.red(text))
@@ -521,6 +604,19 @@ function updatePnpm(print, lock) {
521
604
  } /* c8 ignore end */
522
605
  }
523
606
 
607
+ /**
608
+ * aube ignores `--depth` and only refreshes direct dependencies, so
609
+ * `aube update caniuse-lite` leaves a transitive caniuse-lite where it is.
610
+ * Asking for `@latest` re-resolves every copy without touching package.json.
611
+ * aube rejects names that are not in the dependency graph, so
612
+ * baseline-browser-mapping is only passed when the lockfile has it.
613
+ * aube applies its own minimumReleaseAge to the `@latest` resolution.
614
+ */
615
+ function updateAube(print, lock) {
616
+ let packages = getLockedPackages(lock)
617
+ updateWith(print, 'aube update ' + packages.map(i => i + '@latest').join(' '))
618
+ }
619
+
524
620
  function updateWith(print, cmd, message = 'Updating caniuse-lite version') {
525
621
  print(message + '\n' + pico.yellow('$ ' + cmd) + '\n')
526
622
  try {
@@ -564,6 +660,8 @@ module.exports = function updateDB(print = defaultPrint) {
564
660
  updatePnpm(print, lock)
565
661
  } else if (lock.mode === 'bun') {
566
662
  updateBun(print, lock, latest)
663
+ } else if (lock.mode === 'aube') {
664
+ updateAube(print, lock)
567
665
  } else if (lock.mode === 'deno') {
568
666
  updateWith(print, 'deno add npm:caniuse-lite npm:baseline-browser-mapping')
569
667
  updateWith(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-browserslist-db",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config",
5
5
  "keywords": [
6
6
  "browsers",