feat: refactoring project
This commit is contained in:
79
node_modules/browserslist/node.js
generated
vendored
79
node_modules/browserslist/node.js
generated
vendored
@@ -1,14 +1,13 @@
|
||||
var feature = require('caniuse-lite/dist/unpacker/feature').default
|
||||
var region = require('caniuse-lite/dist/unpacker/region').default
|
||||
var path = require('path')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
var BrowserslistError = require('./error')
|
||||
|
||||
var IS_SECTION = /^\s*\[(.+)]\s*$/
|
||||
var CONFIG_PATTERN = /^browserslist-config-/
|
||||
var SCOPED_CONFIG__PATTERN = /@[^/]+(?:\/[^/]+)?\/browserslist-config(?:-|$|\/)/
|
||||
var TIME_TO_UPDATE_CANIUSE = 6 * 30 * 24 * 60 * 60 * 1000
|
||||
var FORMAT =
|
||||
'Browserslist config should be a string or an array ' +
|
||||
'of strings with browser queries'
|
||||
@@ -126,6 +125,14 @@ function parsePackage(file) {
|
||||
return list
|
||||
}
|
||||
|
||||
function parsePackageOrReadConfig(file) {
|
||||
if (path.basename(file) === 'package.json') {
|
||||
return parsePackage(file)
|
||||
} else {
|
||||
return module.exports.readConfig(file)
|
||||
}
|
||||
}
|
||||
|
||||
function latestReleaseTime(agents) {
|
||||
var latest = 0
|
||||
for (var name in agents) {
|
||||
@@ -139,6 +146,16 @@ function latestReleaseTime(agents) {
|
||||
return latest * 1000
|
||||
}
|
||||
|
||||
function getMonthsPassed(date) {
|
||||
var now = new Date()
|
||||
var past = new Date(date)
|
||||
|
||||
var years = now.getFullYear() - past.getFullYear()
|
||||
var months = now.getMonth() - past.getMonth()
|
||||
|
||||
return years * 12 + months
|
||||
}
|
||||
|
||||
function normalizeStats(data, stats) {
|
||||
if (!data) {
|
||||
data = {}
|
||||
@@ -237,11 +254,7 @@ module.exports = {
|
||||
return process.env.BROWSERSLIST
|
||||
} else if (opts.config || process.env.BROWSERSLIST_CONFIG) {
|
||||
var file = opts.config || process.env.BROWSERSLIST_CONFIG
|
||||
if (path.basename(file) === 'package.json') {
|
||||
return pickEnv(parsePackage(file), opts)
|
||||
} else {
|
||||
return pickEnv(module.exports.readConfig(file), opts)
|
||||
}
|
||||
return pickEnv(parsePackageOrReadConfig(file), opts)
|
||||
} else if (opts.path) {
|
||||
return pickEnv(module.exports.findConfig(opts.path), opts)
|
||||
} else {
|
||||
@@ -330,17 +343,8 @@ module.exports = {
|
||||
return module.exports.parseConfig(fs.readFileSync(file))
|
||||
},
|
||||
|
||||
findConfig: function findConfig(from) {
|
||||
from = path.resolve(from)
|
||||
|
||||
var passed = []
|
||||
findConfigFile: function findConfigFile(from) {
|
||||
var resolved = eachParent(from, function (dir) {
|
||||
if (dir in configCache) {
|
||||
return configCache[dir]
|
||||
}
|
||||
|
||||
passed.push(dir)
|
||||
|
||||
var config = path.join(dir, 'browserslist')
|
||||
var pkg = path.join(dir, 'package.json')
|
||||
var rc = path.join(dir, '.browserslistrc')
|
||||
@@ -370,16 +374,38 @@ module.exports = {
|
||||
dir + ' contains both .browserslistrc and browserslist'
|
||||
)
|
||||
} else if (isFile(config)) {
|
||||
return module.exports.readConfig(config)
|
||||
return config
|
||||
} else if (isFile(rc)) {
|
||||
return module.exports.readConfig(rc)
|
||||
} else {
|
||||
return pkgBrowserslist
|
||||
return rc
|
||||
} else if (pkgBrowserslist) {
|
||||
return pkg
|
||||
}
|
||||
})
|
||||
|
||||
return resolved
|
||||
},
|
||||
|
||||
findConfig: function findConfig(from) {
|
||||
from = path.resolve(from)
|
||||
|
||||
var fromDir = isFile(from) ? path.dirname(from) : from
|
||||
if (fromDir in configCache) {
|
||||
return configCache[fromDir]
|
||||
}
|
||||
|
||||
var resolved
|
||||
var configFile = this.findConfigFile(from)
|
||||
if (configFile) {
|
||||
resolved = parsePackageOrReadConfig(configFile)
|
||||
}
|
||||
|
||||
if (!process.env.BROWSERSLIST_DISABLE_CACHE) {
|
||||
passed.forEach(function (dir) {
|
||||
var configDir = configFile && path.dirname(configFile)
|
||||
eachParent(from, function (dir) {
|
||||
configCache[dir] = resolved
|
||||
if (dir === configDir) {
|
||||
return null
|
||||
}
|
||||
})
|
||||
}
|
||||
return resolved
|
||||
@@ -399,11 +425,14 @@ module.exports = {
|
||||
if (process.env.BROWSERSLIST_IGNORE_OLD_DATA) return
|
||||
|
||||
var latest = latestReleaseTime(agentsObj)
|
||||
var halfYearAgo = Date.now() - TIME_TO_UPDATE_CANIUSE
|
||||
var monthsPassed = getMonthsPassed(latest)
|
||||
|
||||
if (latest !== 0 && latest < halfYearAgo) {
|
||||
if (latest !== 0 && monthsPassed >= 6) {
|
||||
var months = monthsPassed + ' ' + (monthsPassed > 1 ? 'months' : 'month')
|
||||
console.warn(
|
||||
'Browserslist: caniuse-lite is outdated. Please run:\n' +
|
||||
'Browserslist: browsers data (caniuse-lite) is ' +
|
||||
months +
|
||||
' old. Please run:\n' +
|
||||
' npx update-browserslist-db@latest\n' +
|
||||
' Why you should do it regularly: ' +
|
||||
'https://github.com/browserslist/update-db#readme'
|
||||
|
||||
Reference in New Issue
Block a user