browserslist
Advanced tools
Comparing version 4.16.1 to 4.16.2
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 4.16.2 | ||
* Fixed `--update-db` (by @ialarmedalien). | ||
## 4.16.1 | ||
@@ -5,0 +8,0 @@ * Fixed Chrome 4 with `mobileToDesktop` (by Aron Woost). |
{ | ||
"name": "browserslist", | ||
"version": "4.16.1", | ||
"version": "4.16.2", | ||
"description": "Share target browsers between different front-end tools, like Autoprefixer, Stylelint and babel-env-preset", | ||
@@ -18,7 +18,7 @@ "keywords": [ | ||
"dependencies": { | ||
"caniuse-lite": "^1.0.30001173", | ||
"caniuse-lite": "^1.0.30001181", | ||
"colorette": "^1.2.1", | ||
"electron-to-chromium": "^1.3.634", | ||
"electron-to-chromium": "^1.3.649", | ||
"escalade": "^3.1.1", | ||
"node-releases": "^1.1.69" | ||
"node-releases": "^1.1.70" | ||
}, | ||
@@ -25,0 +25,0 @@ "engines": { |
204
update-db.js
@@ -22,3 +22,3 @@ var childProcess = require('child_process') | ||
'Cannot find package.json. ' + | ||
'Is it a right project to run npx browserslist --update-db?' | ||
'Is this the right directory to run `npx browserslist --update-db` in?' | ||
) | ||
@@ -31,3 +31,2 @@ } | ||
/* istanbul ignore next */ | ||
if (fs.existsSync(lockfilePnpm)) { | ||
@@ -39,37 +38,17 @@ return { mode: 'pnpm', file: lockfilePnpm } | ||
return { mode: 'yarn', file: lockfileYarn } | ||
} else { | ||
throw new BrowserslistError( | ||
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"' | ||
) | ||
} | ||
throw new BrowserslistError( | ||
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"' | ||
) | ||
} | ||
function getCurrentVersion (lock) { | ||
var match | ||
/* istanbul ignore if */ | ||
if (lock.mode === 'pnpm') { | ||
match = /\/caniuse-lite\/([^:]+):/.exec(lock.content) | ||
if (match[1]) return match[1] | ||
} else if (lock.mode === 'npm') { | ||
var dependencies = JSON.parse(lock.content).dependencies | ||
if (dependencies && dependencies['caniuse-lite']) { | ||
return dependencies['caniuse-lite'].version | ||
} | ||
} else if (lock.mode === 'yarn') { | ||
match = /caniuse-lite@[^:]+:\r?\n\s+version\s+"([^"]+)"/.exec(lock.content) | ||
if (match[1]) return match[1] | ||
} | ||
return null | ||
} | ||
function getLatestInfo (lock) { | ||
if (lock.mode !== 'yarn') { | ||
if (lock.mode === 'yarn') { | ||
return JSON.parse( | ||
childProcess.execSync('npm show caniuse-lite --json').toString() | ||
) | ||
} else { | ||
return JSON.parse( | ||
childProcess.execSync('yarn info caniuse-lite --json').toString() | ||
).data | ||
} | ||
return JSON.parse( | ||
childProcess.execSync('npm show caniuse-lite --json').toString() | ||
) | ||
} | ||
@@ -123,55 +102,98 @@ | ||
function updateLockfile (lock, latest) { | ||
if (lock.mode === 'npm') { | ||
var fixed = deletePackage(JSON.parse(lock.content)) | ||
return JSON.stringify(fixed, null, ' ') | ||
} else { | ||
var lines = lock.content.split('\n') | ||
var i | ||
/* istanbul ignore if */ | ||
if (lock.mode === 'pnpm') { | ||
for (i = 0; i < lines.length; i++) { | ||
if (lines[i].indexOf('caniuse-lite:') >= 0) { | ||
lines[i] = lines[i].replace(/: .*$/, ': ' + latest.version) | ||
} else if (lines[i].indexOf('/caniuse-lite') >= 0) { | ||
lines[i] = lines[i].replace(/\/[^/:]+:/, '/' + latest.version + ':') | ||
for (i = i + 1; i < lines.length; i++) { | ||
if (lines[i].indexOf('integrity: ') !== -1) { | ||
lines[i] = lines[i].replace( | ||
/integrity: .+/, 'integrity: ' + latest.dist.integrity | ||
) | ||
} else if (lines[i].indexOf(' /') !== -1) { | ||
break | ||
} | ||
} | ||
function updateNpmLockfile (lock, latest) { | ||
var metadata = { latest: latest, versions: [] } | ||
var content = deletePackage(JSON.parse(lock.content), metadata) | ||
metadata.content = JSON.stringify(content, null, ' ') | ||
return metadata | ||
} | ||
function deletePackage (node, metadata) { | ||
if (node.dependencies) { | ||
if (node.dependencies['caniuse-lite']) { | ||
var version = node.dependencies['caniuse-lite'].version | ||
metadata.versions[version] = true | ||
delete node.dependencies['caniuse-lite'] | ||
} | ||
for (var i in node.dependencies) { | ||
node.dependencies[i] = deletePackage(node.dependencies[i], metadata) | ||
} | ||
} | ||
return node | ||
} | ||
var yarnVersionRe = new RegExp('version "(.*?)"') | ||
function updateYarnLockfile (lock, latest) { | ||
var blocks = lock.content.split(/(\n{2,})/).map(function (block) { | ||
return block.split('\n') | ||
}) | ||
var versions = {} | ||
blocks.forEach(function (lines) { | ||
if (lines[0].indexOf('caniuse-lite@') !== -1) { | ||
var match = yarnVersionRe.exec(lines[1]) | ||
versions[match[1]] = true | ||
if (match[1] !== latest.version) { | ||
lines[1] = lines[1].replace( | ||
/version "[^"]+"/, 'version "' + latest.version + '"' | ||
) | ||
lines[2] = lines[2].replace( | ||
/resolved "[^"]+"/, 'resolved "' + latest.dist.tarball + '"' | ||
) | ||
lines[3] = lines[3].replace( | ||
/integrity .+/, 'integrity ' + latest.dist.integrity | ||
) | ||
} | ||
} | ||
}) | ||
var content = blocks.map(function (lines) { | ||
return lines.join('\n') | ||
}).join('') | ||
return { content: content, versions: versions } | ||
} | ||
function updatePnpmLockfile (lock, latest) { | ||
var versions = {} | ||
var lines = lock.content.split('\n') | ||
var i | ||
var j | ||
var lineParts | ||
for (i = 0; i < lines.length; i++) { | ||
if (lines[i].indexOf('caniuse-lite:') >= 0) { | ||
lineParts = lines[i].split(/:\s?/, 2) | ||
versions[lineParts[1]] = true | ||
lines[i] = lineParts[0] + ': ' + latest.version | ||
} else if (lines[i].indexOf('/caniuse-lite') >= 0) { | ||
lineParts = lines[i].split(/([/:])/) | ||
for (j = 0; j < lineParts.length; j++) { | ||
if (lineParts[j].indexOf('caniuse-lite') >= 0) { | ||
versions[lineParts[j + 2]] = true | ||
lineParts[j + 2] = latest.version | ||
break | ||
} | ||
} | ||
} else if (lock.mode === 'yarn') { | ||
for (i = 0; i < lines.length; i++) { | ||
if (lines[i].indexOf('caniuse-lite@') !== -1) { | ||
lines[i + 1] = lines[i + 1].replace( | ||
/version "[^"]+"/, 'version "' + latest.version + '"' | ||
lines[i] = lineParts.join('') | ||
for (i = i + 1; i < lines.length; i++) { | ||
if (lines[i].indexOf('integrity: ') !== -1) { | ||
lines[i] = lines[i].replace( | ||
/integrity: .+/, 'integrity: ' + latest.dist.integrity | ||
) | ||
lines[i + 2] = lines[i + 2].replace( | ||
/resolved "[^"]+"/, 'resolved "' + latest.dist.tarball + '"' | ||
) | ||
lines[i + 3] = lines[i + 3].replace( | ||
/integrity .+/, 'integrity ' + latest.dist.integrity | ||
) | ||
i += 4 | ||
} else if (lines[i].indexOf(' /') !== -1) { | ||
break | ||
} | ||
} | ||
} | ||
return lines.join('\n') | ||
} | ||
return { content: lines.join('\n'), versions: versions } | ||
} | ||
function deletePackage (node) { | ||
if (node.dependencies) { | ||
delete node.dependencies['caniuse-lite'] | ||
for (var i in node.dependencies) { | ||
node.dependencies[i] = deletePackage(node.dependencies[i]) | ||
} | ||
function updateLockfile (lock, latest) { | ||
lock.content = fs.readFileSync(lock.file).toString() | ||
if (lock.mode === 'npm') { | ||
return updateNpmLockfile(lock, latest) | ||
} else if (lock.mode === 'yarn') { | ||
return updateYarnLockfile(lock, latest) | ||
} | ||
return node | ||
return updatePnpmLockfile(lock, latest) | ||
} | ||
@@ -181,5 +203,2 @@ | ||
var lock = detectLockfile() | ||
lock.content = fs.readFileSync(lock.file).toString() | ||
var current = getCurrentVersion(lock) | ||
var latest = getLatestInfo(lock) | ||
@@ -194,13 +213,30 @@ var browsersListRetrievalError | ||
if (typeof current === 'string') { | ||
print('Current version: ' + bold(red(current)) + '\n') | ||
print( | ||
'Latest version: ' + bold(green(latest.version)) + '\n' | ||
) | ||
var lockfileData = updateLockfile(lock, latest) | ||
var caniuseVersions = Object.keys(lockfileData.versions).sort() | ||
if (caniuseVersions.length === 1 && | ||
caniuseVersions[0] === latest.version) { | ||
print( | ||
'Installed version: ' + bold(green(latest.version)) + '\n' + | ||
bold(green('caniuse-lite is up to date')) + '\n' | ||
) | ||
return | ||
} | ||
if (caniuseVersions.length === 0) { | ||
caniuseVersions[0] = 'none' | ||
} | ||
print( | ||
'New version: ' + bold(green(latest.version)) + '\n' + | ||
'Installed version' + | ||
(caniuseVersions.length === 1 ? ': ' : 's: ') + | ||
bold(red(caniuseVersions.join(', '))) + | ||
'\n' + | ||
'Removing old caniuse-lite from lock file\n' | ||
) | ||
fs.writeFileSync(lock.file, lockfileData.content) | ||
fs.writeFileSync(lock.file, updateLockfile(lock, latest)) | ||
var install = lock.mode === 'yarn' ? 'yarn add -W' : lock.mode + ' install' | ||
var install = (lock.mode === 'yarn' ? 'yarn add -W' : lock.mode) + ' install' | ||
print( | ||
@@ -217,3 +253,3 @@ 'Installing new caniuse-lite version\n' + | ||
e.stack + '\n\n' + | ||
'Problem with `' + install + ' caniuse-lite` call. ' + | ||
'Problem with `' + install + ' caniuse-lite` call. ' + | ||
'Run it manually.\n' | ||
@@ -225,3 +261,3 @@ ) | ||
var del = lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode + ' uninstall' | ||
var del = (lock.mode === 'yarn' ? 'yarn remove -W' : lock.mode) + ' uninstall' | ||
print( | ||
@@ -249,3 +285,3 @@ 'Cleaning package.json dependencies from caniuse-lite\n' + | ||
browsersListRetrievalError.stack + '\n\n' + | ||
'Problem with browsers list retrieval.\n' + | ||
'Problem with browser list retrieval.\n' + | ||
'Target browser changes won’t be shown.\n' | ||
@@ -252,0 +288,0 @@ ) |
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
99356
2058
Updatedcaniuse-lite@^1.0.30001181
Updatednode-releases@^1.1.70