-
Notifications
You must be signed in to change notification settings - Fork 534
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
Deprecate utility components #1316
Merged
Merged
Changes from 16 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
e97fdc7
add utility props to Box
VanAnderson 4ccefb0
update box docs
VanAnderson 26d08f6
export box props
VanAnderson 29e6d9f
update snapshots
VanAnderson 64adf68
Create green-worms-nail.md
VanAnderson 6556f3f
AvatarStack story in storybook
VanAnderson ca4884f
Deprecate components with JSDoc
VanAnderson eddac82
Update documentation
VanAnderson 50aa394
Create metal-swans-allow.md
VanAnderson 3a04406
deprecate utility components
VanAnderson 5d76285
deprecate utility components
VanAnderson 07d6f51
fix linter errors
VanAnderson 4c4e183
fix build errors
VanAnderson a1d3c9f
fix build errors
VanAnderson 2b93818
progress
VanAnderson 3b3ccd7
code mode for deprecating utility components
VanAnderson aa3e8ea
Merge remote-tracking branch 'origin/main' into VanAnderson/deprecate…
colebemis 4cf24a2
Update snapshots
colebemis 699250b
BorderBox and additional test cases for codemod
VanAnderson 2c61036
changeset documentation for utility component deprecation
VanAnderson 7d0edf5
update codemod and test coverage
VanAnderson d696220
deprecate BorderBox
VanAnderson 0b3d5db
better deprecation comments
VanAnderson 96bc59d
correct codemod in changeset docs
VanAnderson d8ae367
run codemod on stories folder
VanAnderson 9b96c60
complete borderBox deprecation
VanAnderson fc37baf
remove duplicate identifier
VanAnderson 0b383df
border box is deprecated in docs
VanAnderson b1ca888
Update src/Grid.tsx
VanAnderson 651b574
adjust codemod changeset docs
VanAnderson e192a0a
safe nav operator for codemod find operation
VanAnderson de80479
Update src/Position.tsx
VanAnderson 90e5885
Update .changeset/metal-swans-allow.md
VanAnderson 87def33
Update src/Popover.tsx
VanAnderson 9d5e8b4
Update .changeset/metal-swans-allow.md
colebemis 47f3a2e
Update snapshot
colebemis 997286f
Edit changeset
colebemis a1408d1
Merge branch 'main' into VanAnderson/deprecate-utility-components
colebemis 4b67a09
Update deprecated docs
colebemis 1965269
Merge branch 'VanAnderson/deprecate-utility-components' of github.com…
colebemis 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 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,5 @@ | ||
--- | ||
"@primer/components": patch | ||
--- | ||
|
||
Box may accept all system props. |
This file contains 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,5 @@ | ||
--- | ||
"@primer/components": minor | ||
--- | ||
|
||
Deprecate utility components. | ||
This file contains 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,156 @@ | ||
import {defineInlineTest} from 'jscodeshift/dist/testUtils' | ||
import deprecateUtilityComponents from '../deprecateUtilityComponents' | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Flex} from '@primer/components' | ||
export default () => ( | ||
<Flex> | ||
<div /> | ||
</Flex> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box display="flex"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test that other props are preserved? Example: - <Flex flexDirection="column">
+ <Box display="flex" flexDirection="column"> |
||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Grid} from '@primer/components' | ||
export default () => ( | ||
<Grid> | ||
<div /> | ||
</Grid> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box display="grid"> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Position} from '@primer/components' | ||
export default () => ( | ||
<Position> | ||
<div /> | ||
</Position> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Absolute} from '@primer/components' | ||
export default () => ( | ||
<Absolute> | ||
<div /> | ||
</Absolute> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box position="absolute"> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Relative} from '@primer/components' | ||
export default () => ( | ||
<Relative> | ||
<div /> | ||
</Relative> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box position="relative"> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Fixed} from '@primer/components' | ||
export default () => ( | ||
<Fixed> | ||
<div /> | ||
</Fixed> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box position="fixed"> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) | ||
|
||
defineInlineTest( | ||
deprecateUtilityComponents, | ||
{}, | ||
` | ||
import {Sticky} from '@primer/components' | ||
export default () => ( | ||
<Sticky> | ||
<div /> | ||
</Sticky> | ||
) | ||
`.trim(), | ||
` | ||
import {Box} from '@primer/components' | ||
export default () => ( | ||
<Box position="sticky"> | ||
<div /> | ||
</Box> | ||
) | ||
`.trim(), | ||
'deprecateUtilityComponents' | ||
) |
This file contains 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,98 @@ | ||
const prettify = require('./lib/prettify') | ||
|
||
module.exports = (file, api) => { | ||
const j = api.jscodeshift | ||
const ast = j(file.source) | ||
|
||
deprecateComponents(ast, j, '@primer/components', { | ||
Flex: { | ||
identifier: 'Box', | ||
attributes: { | ||
display: 'flex' | ||
} | ||
}, | ||
Grid: { | ||
identifier: 'Box', | ||
attributes: { | ||
display: 'grid' | ||
} | ||
}, | ||
Position: { | ||
identifier: 'Box', | ||
attributes: {} | ||
}, | ||
Absolute: { | ||
identifier: 'Box', | ||
attributes: { | ||
position: 'absolute' | ||
} | ||
}, | ||
Relative: { | ||
identifier: 'Box', | ||
attributes: { | ||
position: 'relative' | ||
} | ||
}, | ||
Fixed: { | ||
identifier: 'Box', | ||
attributes: { | ||
position: 'fixed' | ||
} | ||
}, | ||
Sticky: { | ||
identifier: 'Box', | ||
attributes: { | ||
position: 'sticky' | ||
} | ||
} | ||
}) | ||
|
||
return prettify(ast, file) | ||
} | ||
|
||
function deprecateComponents(ast, j, importSource, importMap) { | ||
const imports = ast.find(j.ImportDeclaration, {source: {value: importSource}}) | ||
const importsByName = {} | ||
|
||
imports.forEach(decl => { | ||
j(decl) | ||
.find(j.ImportSpecifier) | ||
.forEach(spec => { | ||
importsByName[spec.node.imported.name] = spec | ||
}) | ||
}) | ||
|
||
for (const [from, to] of Object.entries(importMap)) { | ||
rewriteImport(from, to.identifier, to.attributes) | ||
} | ||
|
||
function rewriteImport(from, to, attributes) { | ||
imports.forEach(decl => { | ||
j(decl) | ||
.find(j.ImportSpecifier, {imported: {name: from}}) | ||
.forEach(spec => { | ||
if (importsByName[to]) { | ||
// if the destination import already exists and there are members | ||
// in this identifier, then this one is a dupe | ||
j(spec).remove() | ||
} else { | ||
// otherwise, we can safely rename this one to the new identifier | ||
spec.node.imported.name = to | ||
importsByName[to] = spec | ||
} | ||
}) | ||
}) | ||
|
||
ast.find(j.JSXOpeningElement, {name: {name: from}}).forEach(nodePath => { | ||
for (const [attr, value] of Object.entries(attributes || {})) { | ||
nodePath.value.attributes.push(j.jsxAttribute(j.jsxIdentifier(attr), j.literal(value))) | ||
} | ||
}) | ||
|
||
// replace all of the rewritten identifiers with member expressions | ||
ast | ||
.find(j.Identifier, {name: from}) | ||
.filter(id => id.parent.node.type !== 'ImportSpecifier') | ||
.replaceWith(j.jsxIdentifier(to)) | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful for consumers if we listed all the deprecated components explicitly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to a list of deprecated components, let's also include instructions on how to run the codemod here.