update-browserslist-db 1.0.13 → 1.0.15

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.
@@ -1,4 +1,4 @@
1
- let { execSync } = require('child_process')
1
+ let { execSync } = require('node:child_process')
2
2
  let pico = require('picocolors')
3
3
 
4
4
  try {
@@ -7,7 +7,7 @@ try {
7
7
  process.stderr.write(
8
8
  pico.red(
9
9
  'Update npm or call ' +
10
- pico.yellow('npx update-browserslist-db@latest') +
10
+ pico.yellow('npx browserslist@latest --update-db') +
11
11
  '\n'
12
12
  )
13
13
  )
package/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- let { readFileSync } = require('fs')
4
- let { join } = require('path')
3
+ let { readFileSync } = require('node:fs')
4
+ let { join } = require('node:path')
5
5
 
6
6
  require('./check-npm-version')
7
7
  let updateDb = require('./')
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- let { existsSync, readFileSync, writeFileSync } = require('fs')
2
- let { execSync } = require('child_process')
3
- let { join } = require('path')
1
+ let { existsSync, readFileSync, writeFileSync } = require('node:fs')
2
+ let { execSync } = require('node:child_process')
3
+ let { join } = require('node:path')
4
4
  let escalade = require('escalade/sync')
5
5
  let pico = require('picocolors')
6
6
 
@@ -17,6 +17,10 @@ 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
+ const IsHadoopExists = !!process.env.HADOOP_HOME
22
+ const yarnCommand = IsHadoopExists ? 'yarnpkg' : 'yarn'
23
+
20
24
  /* c8 ignore next 3 */
21
25
  function defaultPrint(str) {
22
26
  process.stdout.write(str)
@@ -59,11 +63,12 @@ function detectLockfile() {
59
63
  function getLatestInfo(lock) {
60
64
  if (lock.mode === 'yarn') {
61
65
  if (lock.version === 1) {
62
- return JSON.parse(execSync('yarnpkg info caniuse-lite --json').toString())
63
- .data
66
+ return JSON.parse(
67
+ execSync(yarnCommand + ' info caniuse-lite --json').toString()
68
+ ).data
64
69
  } else {
65
70
  return JSON.parse(
66
- execSync('yarnpkg npm info caniuse-lite --json').toString()
71
+ execSync(yarnCommand + ' npm info caniuse-lite --json').toString()
67
72
  )
68
73
  }
69
74
  }
@@ -209,10 +214,11 @@ function updatePackageManually(print, lock, latest) {
209
214
  )
210
215
  writeFileSync(lock.file, lockfileData.content)
211
216
 
212
- let install = lock.mode === 'yarn' ? 'yarnpkg add -W' : lock.mode + ' install'
217
+ let install =
218
+ lock.mode === 'yarn' ? yarnCommand + ' add -W' : lock.mode + ' install'
213
219
  print(
214
220
  'Installing new caniuse-lite version\n' +
215
- pico.yellow('$ ' + install.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
221
+ pico.yellow('$ ' + install + ' caniuse-lite') +
216
222
  '\n'
217
223
  )
218
224
  try {
@@ -233,21 +239,17 @@ function updatePackageManually(print, lock, latest) {
233
239
  } /* c8 ignore end */
234
240
 
235
241
  let del =
236
- lock.mode === 'yarn' ? 'yarnpkg remove -W' : lock.mode + ' uninstall'
242
+ lock.mode === 'yarn' ? yarnCommand + ' remove -W' : lock.mode + ' uninstall'
237
243
  print(
238
244
  'Cleaning package.json dependencies from caniuse-lite\n' +
239
- pico.yellow('$ ' + del.replace('yarnpkg', 'yarn') + ' caniuse-lite') +
245
+ pico.yellow('$ ' + del + ' caniuse-lite') +
240
246
  '\n'
241
247
  )
242
248
  execSync(del + ' caniuse-lite')
243
249
  }
244
250
 
245
251
  function updateWith(print, cmd) {
246
- print(
247
- 'Updating caniuse-lite version\n' +
248
- pico.yellow('$ ' + cmd.replace('yarnpkg', 'yarn')) +
249
- '\n'
250
- )
252
+ print('Updating caniuse-lite version\n' + pico.yellow('$ ' + cmd) + '\n')
251
253
  try {
252
254
  execSync(cmd)
253
255
  } catch (e) /* c8 ignore start */ {
@@ -282,7 +284,7 @@ module.exports = function updateDB(print = defaultPrint) {
282
284
  print('Latest version: ' + pico.bold(pico.green(latest.version)) + '\n')
283
285
 
284
286
  if (lock.mode === 'yarn' && lock.version !== 1) {
285
- updateWith(print, 'yarnpkg up -R caniuse-lite')
287
+ updateWith(print, yarnCommand + ' up -R caniuse-lite')
286
288
  } else if (lock.mode === 'pnpm') {
287
289
  updateWith(print, 'pnpm up caniuse-lite')
288
290
  } else {
@@ -301,15 +303,24 @@ module.exports = function updateDB(print = defaultPrint) {
301
303
  }
302
304
 
303
305
  if (listError) {
304
- print(
305
- pico.red(
306
- '\n' +
307
- listError.stack +
308
- '\n\n' +
309
- 'Problem with browser list retrieval.\n' +
310
- 'Target browser changes won’t be shown.\n'
306
+ if (listError.message.includes("Cannot find module 'browserslist'")) {
307
+ print(
308
+ pico.gray(
309
+ 'Install `browserslist` to your direct dependencies ' +
310
+ 'to see target browser changes\n'
311
+ )
311
312
  )
312
- )
313
+ } else {
314
+ print(
315
+ pico.red(
316
+ '\n' +
317
+ listError.stack +
318
+ '\n\n' +
319
+ 'Problem with browser list retrieval.\n' +
320
+ 'Target browser changes won’t be shown.\n'
321
+ )
322
+ )
323
+ }
313
324
  } else {
314
325
  let changes = diffBrowsers(oldList, newList)
315
326
  if (changes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-browserslist-db",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config",
5
5
  "keywords": [
6
6
  "caniuse",
@@ -30,7 +30,7 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "escalade": "^3.1.1",
33
+ "escalade": "^3.1.2",
34
34
  "picocolors": "^1.0.0"
35
35
  },
36
36
  "peerDependencies": {
package/utils.js CHANGED
@@ -1,10 +1,13 @@
1
- const { EOL } = require('os')
1
+ const { EOL } = require('node:os')
2
2
 
3
3
  const getFirstRegexpMatchOrDefault = (text, regexp, defaultValue) => {
4
4
  regexp.lastIndex = 0 // https://stackoverflow.com/a/11477448/4536543
5
5
  let match = regexp.exec(text)
6
- if (match !== null) return match[1]
7
- return defaultValue
6
+ if (match !== null) {
7
+ return match[1]
8
+ } else {
9
+ return defaultValue
10
+ }
8
11
  }
9
12
 
10
13
  const DEFAULT_INDENT = ' '