mirror of
https://github.com/primer/css.git
synced 2024-11-23 03:10:10 +03:00
add variable deprecation + tests
This commit is contained in:
parent
8dc9609bd8
commit
ed61a3a6d5
@ -4,6 +4,32 @@
|
||||
* array and a "message" string.
|
||||
*/
|
||||
const versionDeprecations = {
|
||||
'14.0.0': [
|
||||
{
|
||||
variables: ['$status-pending'],
|
||||
message: `This variable is deprecated.`
|
||||
},
|
||||
{
|
||||
variables: ['$repo-private-text', '$repo-private-bg', '$repo-private-icon'],
|
||||
message: `These variables are deprecated.`
|
||||
},
|
||||
{
|
||||
variables: ['$marketingSpacers', '$allSpacers'],
|
||||
message: `Please use the $marketing-spacers and $marketing-all-spacers variables.`
|
||||
},
|
||||
{
|
||||
variables: ['$exploregrid-item-border-radius'],
|
||||
message: `This variable is deprecated. Use "4px" instead.`
|
||||
},
|
||||
{
|
||||
variables: ['$stats-switcher-py', '$stats-viewport-height'],
|
||||
message: `These variables are deprecated.`
|
||||
},
|
||||
{
|
||||
variables: ['$min_tab_size', '$max_tab_size'],
|
||||
message: `These variables are deprecated.`
|
||||
}
|
||||
],
|
||||
'13.0.0': [
|
||||
{
|
||||
selectors: [
|
||||
@ -68,11 +94,15 @@ const semver = require('semver')
|
||||
|
||||
// map selectors to the version and message of their deprecation
|
||||
const selectorDeprecations = new Map()
|
||||
const variableDeprecations = new Map()
|
||||
for (const [version, deps] of Object.entries(versionDeprecations)) {
|
||||
for (const {selectors, message} of deps) {
|
||||
for (const {selectors = [], variables = [], message} of deps) {
|
||||
for (const selector of selectors) {
|
||||
selectorDeprecations.set(selector, {version, message})
|
||||
}
|
||||
for (const variable of variables) {
|
||||
variableDeprecations.set(variable, {version, message})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,4 +111,15 @@ function isSelectorDeprecated(selector, version = CURRENT_VERSION) {
|
||||
return deprecation ? semver.gte(deprecation.version, version) : false
|
||||
}
|
||||
|
||||
module.exports = {versionDeprecations, selectorDeprecations, isSelectorDeprecated}
|
||||
function isVariableDeprecated(variable, version = CURRENT_VERSION) {
|
||||
const deprecation = variableDeprecations.get(variable)
|
||||
return deprecation ? semver.gte(deprecation.version, version) : false
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
versionDeprecations,
|
||||
selectorDeprecations,
|
||||
variableDeprecations,
|
||||
isSelectorDeprecated,
|
||||
isVariableDeprecated
|
||||
}
|
||||
|
@ -30,9 +30,16 @@ If either check fails, the process exits with an error status (1).
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
checkDeprecations(args)
|
||||
Promise.all([checkSelectorDeprecations(args), checkVariableDeprecations(args)]).then(
|
||||
(deprecationErrors, variableErrors) => {
|
||||
const errors = deprecationErrors.concat(variableErrors)
|
||||
if (errors.length) {
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
async function checkDeprecations(options = {}) {
|
||||
async function checkSelectorDeprecations(options = {}) {
|
||||
const {bundle = 'primer', version = 'latest'} = options
|
||||
|
||||
const currentVersion = require('../package.json').version
|
||||
@ -79,9 +86,57 @@ async function checkDeprecations(options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
process.exitCode = 1
|
||||
return errors
|
||||
}
|
||||
|
||||
async function checkVariableDeprecations(options = {}) {
|
||||
const {version = 'latest'} = options
|
||||
|
||||
const currentVersion = require('../package.json').version
|
||||
const varsPath = `dist/variables.json`
|
||||
|
||||
const local = require(`../${varsPath}`)
|
||||
const remote = await fetch(`https://unpkg.com/@primer/css@${version}/${varsPath}`).then(res => res.json())
|
||||
|
||||
const {changed, added, removed} = diffLists(Object.keys(remote), Object.keys(local))
|
||||
if (changed === 0) {
|
||||
console.log(`no variables added or removed in version ${currentVersion}`)
|
||||
return
|
||||
}
|
||||
|
||||
const deprecations = versionDeprecations[currentVersion] || []
|
||||
const deprecatedVariables = deprecations.reduce((list, deprecation) => list.concat(deprecation.variables), [])
|
||||
console.log(`${I} ${removed.length} variables removed locally (compared with ${version})`)
|
||||
console.log(`${I} ${deprecatedVariables.length} variables deprecated in v${currentVersion}`)
|
||||
if (added.length) {
|
||||
console.log(`${I} ${added.length} variables added`)
|
||||
}
|
||||
|
||||
const errors = []
|
||||
for (const deprecation of deprecations) {
|
||||
for (const variable of deprecation.variables) {
|
||||
if (!removed.includes(variable)) {
|
||||
const error = `variable "${variable}" deprecated, but not removed`
|
||||
errors.push(error)
|
||||
console.log(`${X} ${error}`)
|
||||
} else {
|
||||
console.log(`${V} "${variable}" is officially deprecated`)
|
||||
}
|
||||
deprecatedVariables.push(variable)
|
||||
}
|
||||
}
|
||||
|
||||
for (const removedVariable of removed) {
|
||||
if (!deprecatedVariables.includes(removedVariable)) {
|
||||
const error = `"${removedVariable}" has been removed, but was not listed in versionDeprecations['${currentVersion}']`
|
||||
errors.push(error)
|
||||
console.log(`${X} ${error}`)
|
||||
} else {
|
||||
// console.log(`${V} "${removedVariable}" removed and deprecated!`)
|
||||
}
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
function diffLists(before, after) {
|
||||
|
Loading…
Reference in New Issue
Block a user