-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Publish deprecation data #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0cff296
bump semver
shawnbot 81ae8d9
add deprecations/index.js; write dist/deprecations.json
shawnbot 5ab29b5
better deprecation data key naming
shawnbot c5ada08
add deprecations page, nav item
shawnbot 034f1e0
fix semver links
shawnbot 2484b33
add title front matter
shawnbot 988bc9f
"whos" → "whose"
shawnbot bfc2e2e
rename deprecations/index.js -> deprecations.js
shawnbot c85b18f
add [Map] link, move [changelog] href to footer
shawnbot eadec4c
lint, "dep" -> "deprecation"
shawnbot 5c43eea
fix path to package.json
shawnbot 3077a09
lint deprecations.js
shawnbot bdd1208
lint script/dist
shawnbot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* This object's keys are (semver) version numbers, and the | ||
* values are arrays of objects each with a "selectors" | ||
* array and a "message" string. | ||
*/ | ||
const versionDeprecations = { | ||
'13.0.0': [ | ||
{ | ||
selectors: ['.btn-purple'], | ||
message: `Please don't make purple buttons.` | ||
}, | ||
{ | ||
selectors: ['.text-pending'], | ||
message: `Please use the "text-yellow" class instead of "text-pending".` | ||
}, | ||
{ | ||
selectors: ['.bg-pending'], | ||
message: `Please use the "bg-yellow-dark" class instead of "bg-pending".` | ||
}, | ||
{ | ||
selectors: [ | ||
'.columns', | ||
'.column', | ||
'.one-third', | ||
'.two-thirds', | ||
'.one-fourth', | ||
'.one-half', | ||
'.three-fourths', | ||
'.one-fifth', | ||
'.four-fifths' | ||
], | ||
message: `Please use [grid classes](https://primer.style/css/objects/grid).` | ||
}, | ||
{ | ||
selectors: ['.centered'], | ||
message: `You can use the "mx-auto" class to center any element.` | ||
} | ||
] | ||
} | ||
|
||
const {version: CURRENT_VERSION} = require('./package.json') | ||
const semver = require('semver') | ||
|
||
// map selectors to the version and message of their deprecation | ||
const selectorDeprecations = new Map() | ||
for (const [version, deps] of Object.entries(versionDeprecations)) { | ||
for (const {selectors, message} of deps) { | ||
for (const selector of selectors) { | ||
selectorDeprecations.set(selector, {version, message}) | ||
} | ||
} | ||
} | ||
|
||
function isSelectorDeprecated(selector, version = CURRENT_VERSION) { | ||
const deprecation = selectorDeprecations.get(selector) | ||
return deprecation ? semver.gte(deprecation.version, version) : false | ||
} | ||
|
||
module.exports = {versionDeprecations, selectorDeprecations, isSelectorDeprecated} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: Deprecation data | ||
--- | ||
|
||
As of version 12.7.0, we publish CSS selector deprecation data with | ||
`@primer/css`. You can access the data via the [Node API](#node) or as | ||
[JSON](#json). | ||
|
||
Deprecation messages strings may include Markdown so that they can be included | ||
in the [changelog]. | ||
|
||
**Keep in mind that this data includes both active and _planned_ | ||
deprecations.** You can determine whether a CSS selector is deprecated for the | ||
version of `@primer/css` you've installed via the [Node API](#node), or by | ||
comparing the version of a selector deprecation with the installed version in | ||
your own environment. | ||
|
||
## JSON | ||
|
||
The JSON data is available in the unpacked node module's `dist/deprecations.json`, and is an object with the following structure: | ||
|
||
* `versions` is an object whose keys are version numbers (e.g. `13.0.0`) and values are deprecation messages: objects with a `selectors` array and a `message`: | ||
|
||
```json | ||
{ | ||
"versions": { | ||
"13.0.0": [ | ||
{ | ||
"selectors": [".btn-purple"], | ||
"message": "Please don't make purple buttons." | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
* `selectors` is an object mapping CSS selectors (e.g. `.btn-purple`) to the version in which they are _or will be_ deprecated: | ||
|
||
```json | ||
{ | ||
"selectors": { | ||
".btn-purple": { | ||
"version": "13.0.0", | ||
"message": "Please don't make purple buttons." | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Node | ||
|
||
The Node API for selector deprecations is available at | ||
`@primer/css/deprecations`. | ||
|
||
**Note:** Because we have chosen not to bundle any runtime dependencies with | ||
`@primer/css`, you will need to install the [semver] dependency yourself: | ||
|
||
```shell | ||
npm install semver | ||
``` | ||
|
||
### `versionDeprecations` | ||
This is the object literal form of the [JSON data's](#json) `versions` object. | ||
For instance, to list all of the deprecations: | ||
|
||
```js | ||
const {versionDeprecations} = require('@primer/css/deprecations') | ||
for (const [version, deprecations] of Object.entries(versionDeprecations)) { | ||
console.log(`${version}: ${deprecations.length} deprecations`) | ||
} | ||
``` | ||
|
||
### `selectorDeprecations` | ||
This is a [Map] object with keys for each CSS selector mapped to the deprecation info: | ||
|
||
```js | ||
const {selectorDeprecations} = require('@primer/css/deprecations') | ||
console.log(`Purple buttons are going away? ${selectorDeprecations.has('.btn-purple')}`) | ||
// "Purple buttons are going away? true" | ||
``` | ||
|
||
### `isSelectorDeprecated(selector[, version])` | ||
Returns `true` if the CSS `selector` will have been deprecated (removed) _by_ the specified [semver] version. | ||
|
||
```js | ||
const {isSelectorDeprecated} = require('@primer/css/deprecations') | ||
console.log(`Purple buttons are bad? ${isSelectorDeprecated('.btn-purple')}`) | ||
// "Purple buttons are bad? true" | ||
console.log(`Primary buttons are bad? ${isSelectorDeprecated('.btn-primary')}`) | ||
// "Primary buttons are bad? false" | ||
``` | ||
|
||
[semver]: https://npm.im/semver | ||
[changelog]: https://github.com/primer/css/tree/master/CHANGELOG.md | ||
[Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.