Skip to content
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 31 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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 Sep 20, 2023
c629b02
Add tests
sydneyjodon-wk Sep 20, 2023
351db4f
Add component renames
sydneyjodon-wk Sep 20, 2023
dab9ea6
Add FIXME comments
sydneyjodon-wk Sep 21, 2023
55fce19
Add updated namespace for wsd entrypoint
sydneyjodon-wk Sep 22, 2023
e5f1cfc
Add ImportRenamer suggestor
sydneyjodon-wk Sep 29, 2023
b897413
Namespace updater attempt
sydneyjodon-wk Oct 6, 2023
026c209
Update importer suggestor
sydneyjodon-wk Oct 10, 2023
a7e86ec
Add object renamer logic
sydneyjodon-wk Oct 11, 2023
3b90e49
Add ButtonColor updates for WSD colors
sydneyjodon-wk Oct 12, 2023
c18ca59
Merge branch 'master' into FED-570-unify-package-rename
sydneyjodon-wk Oct 12, 2023
fcdef76
Do some clean up
sydneyjodon-wk Oct 12, 2023
0c8e1cb
Do some more clean up
sydneyjodon-wk Oct 17, 2023
1ce7068
More clean up
sydneyjodon-wk Oct 17, 2023
ad9a1d6
Try to fix diff
sydneyjodon-wk Oct 17, 2023
b2d70f7
Try to fix diff
sydneyjodon-wk Oct 17, 2023
254c3c4
Try to fix diff
sydneyjodon-wk Oct 17, 2023
bd6e194
Format
sydneyjodon-wk Oct 17, 2023
1315278
Update tests
sydneyjodon-wk Oct 17, 2023
b6af6c9
Fix dep validator issue
sydneyjodon-wk Oct 17, 2023
5077b62
Try fixing test
sydneyjodon-wk Oct 17, 2023
0244d3a
Try fixing test
sydneyjodon-wk Oct 17, 2023
42d2f85
Try fixing test
sydneyjodon-wk Oct 17, 2023
20d7c9e
Remove fixme
sydneyjodon-wk Oct 17, 2023
fddc460
Apply suggestions from code review
sydneyjodon-wk Oct 24, 2023
e9e5eb7
Merge branch 'master' into FED-570-unify-package-rename
sydneyjodon-wk Oct 27, 2023
dbc4af6
Fix AlertIconMappingObject
sydneyjodon-wk Oct 30, 2023
dda4812
Fix Alert constant updates
sydneyjodon-wk Oct 30, 2023
cb67268
Format
sydneyjodon-wk Oct 30, 2023
e1ff537
Format
sydneyjodon-wk Oct 30, 2023
80a9c4d
Fix show / hide import updates
sydneyjodon-wk Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bin/unify_package_rename.dart
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';
12 changes: 8 additions & 4 deletions lib/src/executables/mui_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import 'package:logging/logging.dart';
import 'package:over_react_codemod/src/util.dart';
import 'package:over_react_codemod/src/ignoreable.dart';
import 'package:over_react_codemod/src/mui_suggestors/components.dart';
import 'package:over_react_codemod/src/mui_suggestors/mui_importer.dart';
import 'package:over_react_codemod/src/mui_suggestors/unused_wsd_import_remover.dart';
import 'package:over_react_codemod/src/util/package_util.dart';
import 'package:over_react_codemod/src/util/pubspec_upgrader.dart';
import 'package:over_react_codemod/src/util/logging.dart';

import '../mui_suggestors/constants.dart';
import '../util/importer.dart';
import '../util/unused_import_remover.dart';

final _log = Logger('orcm.mui_migration');

const _componentOption = 'component';
Expand Down Expand Up @@ -188,8 +190,10 @@ void main(List<String> args) async {
// should only be handled by a single migrator, and shouldn't depend on the
// output of previous migrators.
[aggregate(migratorsToRun)],
[muiImporter],
[unusedWsdImportRemover],
[
importerSuggestorBuilder(importUri: rmuiImportUri, importNamespace: muiNs)
],
[unusedImportRemoverSuggestorBuilder('web_skin_dart')],
]);
if (exitCode != 0) return;

Expand Down
114 changes: 114 additions & 0 deletions lib/src/executables/unify_package_rename.dart
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;
}
3 changes: 3 additions & 0 deletions lib/src/mui_suggestors/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
/// is what `muiImporter` picks up on to add the react_material_ui import to
/// libraries only when it's needed.
const muiNs = 'mui';

/// The import uri for the main react_material_ui entrypoint.
const rmuiImportUri = 'package:react_material_ui/react_material_ui.dart';
55 changes: 0 additions & 55 deletions lib/src/mui_suggestors/unused_wsd_import_remover.dart
Copy link
Contributor Author

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

This file was deleted.

6 changes: 6 additions & 0 deletions lib/src/rmui_bundle_update_suggestors/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const rmuiBundleDevUpdated =
const rmuiBundleProdUpdated =
'packages/react_material_ui/js/react-material-ui.browser.min.esm.js';

/// The script for the dev Unify bundle.
const unifyBundleDev = 'packages/unify_ui/js/unify-ui.browser.dev.esm.js';

/// The script for the prod Unify bundle.
const unifyBundleProd = 'packages/unify_ui/js/unify-ui.browser.min.esm.js';

/// The type attribute that needs to be added to script tags for the new RMUI bundles.
final typeModuleAttribute = 'type="module"';

Expand Down
129 changes: 129 additions & 0 deletions lib/src/unify_package_rename_suggestors/constants.dart
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';
Loading
Loading