update-browserslist-db
Advanced tools
Comparing version 1.0.3 to 1.0.4
95
index.js
@@ -74,26 +74,16 @@ let childProcess = require('child_process') | ||
function getBrowsersList() { | ||
let spawn = childProcess.spawnSync('npx', ['browserslist']) | ||
if (spawn.status !== 0) throw new Error(spawn.stderr.toString()) | ||
return spawn.stdout | ||
.toString() | ||
.trim() | ||
.split('\n') | ||
.map(line => { | ||
return line.trim().split(' ') | ||
}) | ||
.reduce((result, entry) => { | ||
if (!result[entry[0]]) { | ||
result[entry[0]] = [] | ||
} | ||
result[entry[0]].push(entry[1]) | ||
return result | ||
}, {}) | ||
function getBrowsers() { | ||
let browserslist = require('browserslist') | ||
return browserslist().reduce((result, entry) => { | ||
if (!result[entry[0]]) { | ||
result[entry[0]] = [] | ||
} | ||
result[entry[0]].push(entry[1]) | ||
return result | ||
}, {}) | ||
} | ||
function diffBrowsersLists(old, current) { | ||
function diffBrowsers(old, current) { | ||
let browsers = Object.keys(old).concat( | ||
Object.keys(current).filter(browser => { | ||
return old[browser] === undefined | ||
}) | ||
Object.keys(current).filter(browser => old[browser] === undefined) | ||
) | ||
@@ -104,24 +94,10 @@ return browsers | ||
let currentVersions = current[browser] || [] | ||
let intersection = oldVersions.filter(version => { | ||
return currentVersions.indexOf(version) !== -1 | ||
}) | ||
let addedVersions = currentVersions.filter(version => { | ||
return intersection.indexOf(version) === -1 | ||
}) | ||
let removedVersions = oldVersions.filter(version => { | ||
return intersection.indexOf(version) === -1 | ||
}) | ||
return removedVersions | ||
.map(version => { | ||
return pico.red('- ' + browser + ' ' + version) | ||
}) | ||
.concat( | ||
addedVersions.map(version => { | ||
return pico.green('+ ' + browser + ' ' + version) | ||
}) | ||
) | ||
let common = oldVersions.filter(v => currentVersions.includes(v)) | ||
let added = currentVersions.filter(v => !common.includes(v)) | ||
let removed = oldVersions.filter(v => !common.includes(v)) | ||
return removed | ||
.map(v => pico.red('- ' + browser + ' ' + v)) | ||
.concat(added.map(v => pico.green('+ ' + browser + ' ' + v))) | ||
}) | ||
.reduce((result, array) => { | ||
return result.concat(array) | ||
}, []) | ||
.reduce((result, array) => result.concat(array), []) | ||
.join('\n') | ||
@@ -182,7 +158,3 @@ } | ||
}) | ||
let content = blocks | ||
.map(lines => { | ||
return lines.join('\n') | ||
}) | ||
.join('') | ||
let content = blocks.map(lines => lines.join('\n')).join('') | ||
return { content, versions } | ||
@@ -284,8 +256,8 @@ } | ||
let browsersListRetrievalError | ||
let oldBrowsersList | ||
let listError | ||
let oldList | ||
try { | ||
oldBrowsersList = getBrowsersList() | ||
oldList = getBrowsers() | ||
} catch (e) { | ||
browsersListRetrievalError = e | ||
listError = e | ||
} | ||
@@ -305,16 +277,16 @@ | ||
let currentBrowsersList | ||
if (!browsersListRetrievalError) { | ||
let newList | ||
if (!listError) { | ||
try { | ||
currentBrowsersList = getBrowsersList() | ||
newList = getBrowsers() | ||
} catch (e) /* c8 ignore start */ { | ||
browsersListRetrievalError = e | ||
listError = e | ||
} /* c8 ignore end */ | ||
} | ||
if (browsersListRetrievalError) { | ||
if (listError) { | ||
print( | ||
pico.red( | ||
'\n' + | ||
browsersListRetrievalError.message + | ||
listError.stack + | ||
'\n\n' + | ||
@@ -326,9 +298,6 @@ 'Problem with browser list retrieval.\n' + | ||
} else { | ||
let targetBrowserChanges = diffBrowsersLists( | ||
oldBrowsersList, | ||
currentBrowsersList | ||
) | ||
if (targetBrowserChanges) { | ||
let changes = diffBrowsers(oldList, newList) | ||
if (changes) { | ||
print('\nTarget browser changes:\n') | ||
print(targetBrowserChanges + '\n') | ||
print(changes + '\n') | ||
} else { | ||
@@ -335,0 +304,0 @@ print('\n' + pico.green('No target browser changes') + '\n') |
{ | ||
"name": "update-browserslist-db", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "CLI tool to update caniuse-lite to refresh target browsers from Browserslist config", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12144
310