Skip to content

Commit

Permalink
Update to no longer add wsd namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Oct 31, 2024
1 parent cfca080 commit 2f61fe1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 47 deletions.
9 changes: 0 additions & 9 deletions lib/src/executables/unify_package_rename.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ 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 = """
Expand Down Expand Up @@ -88,13 +86,6 @@ void main(List<String> args) async {
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(
Expand Down
3 changes: 0 additions & 3 deletions lib/src/unify_package_rename_suggestors/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,5 @@ const rmuiToUnifyIdentifierRenames = {
'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';
36 changes: 24 additions & 12 deletions lib/src/unify_package_rename_suggestors/unify_rename_suggestor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:logging/logging.dart';
import '../util.dart';
import '../util/class_suggestor.dart';
import '../util/element_type_helpers.dart';
import '../util/importer.dart';
import 'constants.dart';

final _log = Logger('UnifyRenameSuggestor');
Expand All @@ -35,6 +36,9 @@ final _log = Logger('UnifyRenameSuggestor');
class UnifyRenameSuggestor extends GeneralizingAstVisitor with ClassSuggestor {
UnifyRenameSuggestor();

/// Whether or not to add [unifyWsdUri] import.
late bool needsWsdImport;

@override
visitIdentifier(Identifier node) {
super.visitIdentifier(node);
Expand All @@ -54,13 +58,11 @@ class UnifyRenameSuggestor extends GeneralizingAstVisitor with ClassSuggestor {
isUriWithinPackage(uri, 'unify_ui'))) {
// Update components and objects that were renamed in unify_ui.
final newName = rmuiToUnifyIdentifierRenames[identifier?.name];
var isFromWsdEntrypoint = newName?.startsWith('Wsd') ?? false;
if (identifier != null && newName != null) {
if (isFromWsdEntrypoint) {
// Overwrite or add import namespace for components that will be imported from the separate
// unify_ui/components/wsd.dart entrypoint so we can keep the namespace of the import
// we add consistent with the components that use it.
yieldPatch('$unifyWsdNamespace.$newName', node.offset, node.end);
if (newName.startsWith('Wsd')) {
needsWsdImport = true;
// Overwrite namespace as well because wsd import will be added with no namespace.
yieldPatch(newName, node.offset, node.end);
} else {
yieldPatch(newName, identifier.offset, identifier.end);
}
Expand All @@ -81,13 +83,11 @@ class UnifyRenameSuggestor extends GeneralizingAstVisitor with ClassSuggestor {
];
if (objectName == 'ButtonColor' &&
(propertyName?.startsWith('wsd') ?? false)) {
isFromWsdEntrypoint = true;
yieldPatch('$unifyWsdNamespace.WsdButtonColor.$propertyName',
node.offset, node.end);
needsWsdImport = true;
yieldPatch('WsdButtonColor.$propertyName', node.offset, node.end);
} else if (wsdConstantNames.contains(objectName)) {
isFromWsdEntrypoint = true;
yieldPatch('$unifyWsdNamespace.Wsd$objectName.$propertyName',
node.offset, node.end);
needsWsdImport = true;
yieldPatch('Wsd$objectName.$propertyName', node.offset, node.end);
}
}

Expand Down Expand Up @@ -126,7 +126,19 @@ class UnifyRenameSuggestor extends GeneralizingAstVisitor with ClassSuggestor {
throw Exception(
'Could not get resolved result for "${context.relativePath}"');
}
needsWsdImport = false;
result.unit.visitChildren(this);

if (needsWsdImport) {
final insertInfo = insertionLocationForPackageImport(
unifyWsdUri, result.unit, result.lineInfo);
yieldPatch(
insertInfo.leadingNewlines +
"import '$unifyWsdUri';" +
insertInfo.trailingNewlines,
insertInfo.offset,
insertInfo.offset);
}
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,32 @@ void main() {
import 'package:react_material_ui/react_material_ui.dart';
import 'package:react_material_ui/react_material_ui.dart' as random_rmui_namespace;
import 'package:react_material_ui/components/providers/workiva_mui_theme_provider.dart';
import 'package:unify_ui/components/wsd.dart';
content() {
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `Alert` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlert()();
WsdAlert()();
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `Alert` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlert();
WsdAlert();
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `Alert` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlert;
WsdAlert;
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `AlertPropsMixin` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlertPropsMixin;
unify_wsd.WsdAlertSize.small;
unify_wsd.WsdAlertSize.small;
unify_wsd.WsdLinkButtonSize.small;
unify_wsd.WsdLinkButtonType.submit;
unify_wsd.WsdAlertSeverity.error;
unify_wsd.WsdAlertColor.warning;
unify_wsd.WsdAlertVariant.outlined;
unify_wsd.WsdLinkButtonSize.xxsmall;
WsdAlertPropsMixin;
WsdAlertSize.small;
WsdAlertSize.small;
WsdLinkButtonSize.small;
WsdLinkButtonType.submit;
WsdAlertSeverity.error;
WsdAlertColor.warning;
WsdAlertVariant.outlined;
WsdLinkButtonSize.xxsmall;
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `Alert` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlert()();
WsdAlert()();
// FIXME(unify_package_rename) Check what theme provider is wrapping this component: if it is a UnifyThemeProvider, update this to `Alert` from `unify_ui/components/alert.dart`, manually QA this component, and remove this FIXME; otherwise, remove this FIXME.
unify_wsd.WsdAlert()();
unify_wsd.WsdLinkButton()();
unify_wsd.WsdLinkButton()();
unify_wsd.WsdLinkButton()();
WsdAlert()();
WsdLinkButton()();
WsdLinkButton()();
WsdLinkButton()();
mui.UnifyList()();
UnifyList()();
random_rmui_namespace.UnifyList()();
Expand Down Expand Up @@ -176,16 +177,17 @@ void main() {
expectedOutput: /*language=dart*/ '''
import 'package:react_material_ui/react_material_ui.dart' as mui;
import 'package:react_material_ui/react_material_ui.dart';
import 'package:unify_ui/components/wsd.dart';
content() {
mui.ButtonColor.success;
unify_wsd.WsdButtonColor.wsdBtnInverse;
unify_wsd.WsdButtonColor.wsdBtnLight;
unify_wsd.WsdButtonColor.wsdBtnWhite;
WsdButtonColor.wsdBtnInverse;
WsdButtonColor.wsdBtnLight;
WsdButtonColor.wsdBtnWhite;
ButtonColor.success;
unify_wsd.WsdButtonColor.wsdBtnInverse;
unify_wsd.WsdButtonColor.wsdBtnLight;
unify_wsd.WsdButtonColor.wsdBtnWhite;
WsdButtonColor.wsdBtnInverse;
WsdButtonColor.wsdBtnLight;
WsdButtonColor.wsdBtnWhite;
}
''',
);
Expand Down

0 comments on commit 2f61fe1

Please sign in to comment.