-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from Workiva/FED-570-unify-package-rename
FED-570 Unify package rename codemod
- Loading branch information
Showing
21 changed files
with
1,414 additions
and
101 deletions.
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,141 @@ | ||
// 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, | ||
this.showHideInfo}); | ||
|
||
/// 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; | ||
|
||
/// Additional show / hide information used in [importRenamerSuggestorBuilder] to add to updated imports. | ||
String? showHideInfo; | ||
} | ||
|
||
/// 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', | ||
), | ||
UnifyImportInfo('package:unify_ui/styles/theme_provider.dart', | ||
rmuiUri: 'package:react_material_ui/styles/theme_provider.dart', | ||
namespace: 'unify_theme', | ||
possibleMuiNamespaces: ['mui_theme']) | ||
]; | ||
|
||
/// 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', | ||
// Alert objects | ||
'AlertIconMappingObject': 'WsdAlertIconMappingObject', | ||
// 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.