-
Notifications
You must be signed in to change notification settings - Fork 7
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
FED-570 Unify package rename codemod #251
Merged
Merged
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c3c8755
Add updator to rename mui namespace to unify in component usages
sydneyjodon-wk c629b02
Add tests
sydneyjodon-wk 351db4f
Add component renames
sydneyjodon-wk dab9ea6
Add FIXME comments
sydneyjodon-wk 55fce19
Add updated namespace for wsd entrypoint
sydneyjodon-wk e5f1cfc
Add ImportRenamer suggestor
sydneyjodon-wk b897413
Namespace updater attempt
sydneyjodon-wk 026c209
Update importer suggestor
sydneyjodon-wk a7e86ec
Add object renamer logic
sydneyjodon-wk 3b90e49
Add ButtonColor updates for WSD colors
sydneyjodon-wk c18ca59
Merge branch 'master' into FED-570-unify-package-rename
sydneyjodon-wk fcdef76
Do some clean up
sydneyjodon-wk 0c8e1cb
Do some more clean up
sydneyjodon-wk 1ce7068
More clean up
sydneyjodon-wk ad9a1d6
Try to fix diff
sydneyjodon-wk b2d70f7
Try to fix diff
sydneyjodon-wk 254c3c4
Try to fix diff
sydneyjodon-wk bd6e194
Format
sydneyjodon-wk 1315278
Update tests
sydneyjodon-wk b6af6c9
Fix dep validator issue
sydneyjodon-wk 5077b62
Try fixing test
sydneyjodon-wk 0244d3a
Try fixing test
sydneyjodon-wk 42d2f85
Try fixing test
sydneyjodon-wk 20d7c9e
Remove fixme
sydneyjodon-wk fddc460
Apply suggestions from code review
sydneyjodon-wk e9e5eb7
Merge branch 'master' into FED-570-unify-package-rename
sydneyjodon-wk dbc4af6
Fix AlertIconMappingObject
sydneyjodon-wk dda4812
Fix Alert constant updates
sydneyjodon-wk cb67268
Format
sydneyjodon-wk e1ff537
Format
sydneyjodon-wk 80a9c4d
Fix show / hide import updates
sydneyjodon-wk 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,15 @@ | ||
// Copyright 2023 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
export 'package:over_react_codemod/src/executables/unify_package_rename.dart'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2023 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:codemod/codemod.dart'; | ||
import 'package:over_react_codemod/src/executables/mui_migration.dart'; | ||
import 'package:over_react_codemod/src/rmui_bundle_update_suggestors/constants.dart'; | ||
import 'package:over_react_codemod/src/rmui_bundle_update_suggestors/dart_script_updater.dart'; | ||
import 'package:over_react_codemod/src/rmui_bundle_update_suggestors/html_script_updater.dart'; | ||
import 'package:over_react_codemod/src/unify_package_rename_suggestors/constants.dart'; | ||
import 'package:over_react_codemod/src/unify_package_rename_suggestors/import_renamer.dart'; | ||
import 'package:over_react_codemod/src/unify_package_rename_suggestors/unify_rename_suggestor.dart'; | ||
import 'package:over_react_codemod/src/util.dart'; | ||
|
||
import '../util/importer.dart'; | ||
import '../util/unused_import_remover.dart'; | ||
|
||
const _changesRequiredOutput = """ | ||
To update your code, run the following commands in your repository: | ||
dart pub global activate over_react_codemod | ||
dart pub global run over_react_codemod:unify_package_rename | ||
"""; | ||
|
||
class CodemodInfo { | ||
CodemodInfo({required this.paths, required this.sequence}); | ||
Iterable<String> paths; | ||
Iterable<Suggestor> sequence; | ||
} | ||
|
||
void main(List<String> args) async { | ||
final parser = ArgParser.allowAnything(); | ||
|
||
final parsedArgs = parser.parse(args); | ||
|
||
/// Runs a list of codemods one after the other and returns exit code 0 if any fail. | ||
Future<int> runCodemods( | ||
Iterable<CodemodInfo> codemods, | ||
) async { | ||
for (final sequence in codemods) { | ||
final exitCode = await runInteractiveCodemodSequence( | ||
sequence.paths, | ||
sequence.sequence, | ||
defaultYes: true, | ||
args: parsedArgs.rest, | ||
additionalHelpOutput: parser.usage, | ||
changesRequiredOutput: _changesRequiredOutput, | ||
); | ||
if (exitCode != 0) return exitCode; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
exitCode = await runCodemods([ | ||
// Update RMUI bundle script in all HTML files (and templates) to Unify bundle. | ||
CodemodInfo(paths: allHtmlPathsIncludingTemplates(), sequence: [ | ||
HtmlScriptUpdater(rmuiBundleDevUpdated, unifyBundleDev), | ||
HtmlScriptUpdater(rmuiBundleProdUpdated, unifyBundleProd), | ||
]), | ||
// Update RMUI bundle script in all Dart files to Unify bundle. | ||
CodemodInfo(paths: allDartPathsExceptHidden(), sequence: [ | ||
DartScriptUpdater(rmuiBundleDevUpdated, unifyBundleDev), | ||
DartScriptUpdater(rmuiBundleProdUpdated, unifyBundleProd), | ||
]), | ||
]); | ||
|
||
if (exitCode != 0) return; | ||
|
||
final dartPaths = dartFilesToMigrate().toList(); | ||
// Work around parts being unresolved if you resolve them before their libraries. | ||
// TODO - reference analyzer issue for this once it's created | ||
sortPartsLast(dartPaths); | ||
|
||
await pubGetForAllPackageRoots(dartPaths); | ||
exitCode = await runCodemods([ | ||
// Make main rename updates. | ||
CodemodInfo(paths: dartPaths, sequence: [UnifyRenameSuggestor()]), | ||
// Add WSD entrypoint imports as needed. | ||
CodemodInfo(paths: dartPaths, sequence: [ | ||
importerSuggestorBuilder( | ||
importUri: unifyWsdUri, | ||
importNamespace: unifyWsdNamespace, | ||
) | ||
]), | ||
// Update rmui imports to unify. | ||
CodemodInfo(paths: dartPaths, sequence: [ | ||
importRenamerSuggestorBuilder( | ||
oldPackageName: 'react_material_ui', | ||
newPackageName: 'unify_ui', | ||
oldPackageNamespace: 'mui', | ||
newPackageNamespace: 'unify', | ||
) | ||
]), | ||
// Remove any left over unused imports. | ||
CodemodInfo(paths: dartPaths, sequence: [ | ||
unusedImportRemoverSuggestorBuilder('react_material_ui'), | ||
unusedImportRemoverSuggestorBuilder('unify_ui'), | ||
]), | ||
]); | ||
if (exitCode != 0) return; | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright 2023 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Info on a unify_ui import. | ||
class UnifyImportInfo { | ||
UnifyImportInfo(this.uri, | ||
{this.rmuiUri, this.namespace, this.possibleMuiNamespaces}); | ||
|
||
/// Unify import URI. | ||
String uri; | ||
|
||
/// Recommended Unify version of the import namespace, if applicable. | ||
String? namespace; | ||
|
||
/// List of common RMUI versions of the namespace for the import, if applicable. | ||
List<String>? possibleMuiNamespaces; | ||
|
||
/// Previous RMUI import URI (if it's different from the unify_ui path). | ||
String? rmuiUri; | ||
} | ||
|
||
/// A list of the standard imports for unify_ui that should be updated. | ||
/// | ||
/// Only adds namespace information if the import is commonly used with a namespace. | ||
/// Only adds RMUI uri information if it is different from a simple package name swap. | ||
final rmuiImportsToUpdate = [ | ||
UnifyImportInfo( | ||
'package:unify_ui/unify_ui.dart', | ||
rmuiUri: 'package:react_material_ui/react_material_ui.dart', | ||
namespace: 'unify', | ||
possibleMuiNamespaces: ['mui', 'rmui'], | ||
), | ||
UnifyImportInfo( | ||
'package:unify_ui/z_alpha_may_break_at_runtime_do_not_release_to_customers.dart', | ||
rmuiUri: | ||
'package:react_material_ui/z_alpha_may_break_at_runtime_do_not_release_to_customers.dart', | ||
namespace: 'alpha_unify', | ||
possibleMuiNamespaces: ['alpha_mui', 'mui_alpha'], | ||
), | ||
UnifyImportInfo( | ||
'package:unify_ui/components/list.dart', | ||
rmuiUri: 'package:react_material_ui/components/mui_list.dart', | ||
), | ||
UnifyImportInfo( | ||
'package:unify_ui/styles/styled.dart', | ||
rmuiUri: 'package:react_material_ui/for_cp_use_only/styled.dart', | ||
) | ||
greglittlefield-wf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; | ||
|
||
/// A map of RMUI component names to their new names in unify_ui. | ||
/// | ||
/// This is based on the list of changes in the migration guide: https://github.com/Workiva/react_material_ui/tree/master/react_material_ui#how-to-migrate-from-reactmaterialui-to-unifyui | ||
const rmuiToUnifyIdentifierRenames = { | ||
// Components | ||
'Alert': 'WsdAlert', | ||
'AlertPropsMixin': 'WsdAlertPropsMixin', | ||
'LinkButton': 'WsdLinkButton', | ||
'LinkButtonPropsMixin': 'WsdLinkButtonPropsMixin', | ||
'MuiList': 'UnifyList', | ||
'MuiListPropsMixin': 'UnifyListPropsMixin', | ||
'WorkivaMuiThemeProvider': 'UnifyThemeProvider', | ||
'WorkivaMuiThemeProviderPropsMixin': 'UnifyThemeProviderPropsMixin', | ||
// Autocomplete objects | ||
'AutocompleteFilterOptionsObject': 'AutocompleteFilterOptionsState', | ||
'AutocompleteOnChangeObject': 'AutocompleteChangeDetails', | ||
'AutocompleteRenderOptionObject': 'AutocompleteRenderOptionState', | ||
// Backdrop objects | ||
'BackdropTimeoutObject': 'BackdropObject', | ||
'BackdropTransitionDurationObject': 'BackdropObject', | ||
// Badge objects | ||
'BadgeAnchorOriginObject': 'BadgeOrigin', | ||
'BadgeAnchorOriginObjectVertical': 'BadgeOriginVertical', | ||
'BadgeAnchorOriginObjectHorizontal': 'BadgeOriginHorizontal', | ||
// Breadcrumb objects | ||
'BreadcrumbNavCrumbsObject': 'BreadcrumbNavBreadcrumbModel', | ||
// CSSTransition objects | ||
'CSSTransitionClassNamesObject': 'CSSTransitionClassNames', | ||
// DropdownButton objects | ||
'DropdownButtonOnPlacementUpdate': 'DropdownButtonPlacement', | ||
// Menu objects | ||
'MenuAnchorOriginObject': 'MenuPopoverOrigin', | ||
'MenuTransformOriginObject': 'MenuPopoverOrigin', | ||
'MenuAnchorOriginObjectVertical': 'MenuPopoverOriginVertical', | ||
'MenuTransformOriginObjectVertical': 'MenuPopoverOriginVertical', | ||
'MenuAnchorOriginObjectHorizontal': 'MenuPopoverOriginHorizontal', | ||
'MenuTransformOriginObjectHorizontal': 'MenuPopoverOriginHorizontal', | ||
'MenuAnchorPositionObject': 'MenuPopoverPosition', | ||
// Popover objects | ||
'PopoverAnchorOriginObject': 'PopoverOrigin', | ||
'PopoverTransformOriginObject': 'PopoverOrigin', | ||
'PopoverAnchorOriginObjectVertical': 'PopoverOriginVertical', | ||
'PopoverTransformOriginObjectVertical': 'PopoverOriginVertical', | ||
'PopoverAnchorOriginObjectHorizontal': 'PopoverOriginHorizontal', | ||
'PopoverTransformOriginObjectHorizontal': 'PopoverOriginHorizontal', | ||
'PopoverAnchorPositionObject': 'PopoverPosition', | ||
// Popper objects | ||
'PopperAnchorElObject': 'PopperVirtualElement', | ||
'PopperModifiersObject': 'PopperModifier', | ||
'PopperModifiersObjectPhase': 'PopperModifierPhases', | ||
'PopperPopperOptionsObject': 'PopperOptionsGeneric', | ||
'PopperPopperOptionsObjectPlacement': 'PopperPlacement', | ||
'PopperPopperOptionsObjectStrategy': 'PopperPositioningStrategy', | ||
// Slider objects | ||
'SliderMarksObject': 'SliderMark', | ||
// Snackbar objects | ||
'SnackbarAnchorOriginObject': 'SnackbarOrigin', | ||
'SnackbarAnchorOriginObjectVertical': 'SnackbarOriginVertical', | ||
'SnackbarAnchorOriginObjectHorizontal': 'SnackbarOriginHorizontal', | ||
// TablePagination objects | ||
'TablePaginationLabelDisplayedRowsObject': | ||
'TablePaginationLabelDisplayedRowsArgs', | ||
}; | ||
|
||
/// The namespace that will be used for the `unify_ui/components/wsd.dart` import that is added. | ||
const unifyWsdNamespace = 'unify_wsd'; | ||
|
||
/// The uri for the `unify_ui/components/wsd.dart` import that is added. | ||
const unifyWsdUri = 'package:unify_ui/components/wsd.dart'; |
Oops, something went wrong.
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.
This file was moved to the utils directory and generalized to take a package name argument