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

INTL-1608 : Activate _over_react_codemod executables separately #246

Merged
merged 16 commits into from
Nov 9, 2023

Conversation

akshaybhardwaj-wk
Copy link
Contributor

@akshaybhardwaj-wk akshaybhardwaj-wk commented Sep 25, 2023

Problem

AS per Ticket INTL-1322 we need to run the sorting command with ddev format

Solution

  1. Create a sperate file in the Executable directory lib/src/executables/sort_intl.dart
  2. Make bin file for the same i.e. bin/sort_intl.dart

How To QA

A. Local system : To check this in the Local system as debug mode do the following steps

  1. To activate over_react_codemod in local system as debug mode run the command dart pub global activate --source path over_react_codemod
  2. To activate executables in the local system run command
    dart pub global activate --source path . -x sort_intl
    this will show message on terminal
Installed executable intl_sorting.
Activated over_react_codemod 2.26.0 at path
  1. Also added intl_sorting as an executable in pubspec.yaml here

  2. Run codemod with executables only in any repo run this command
    dart pub global run over_react_codemod: sort_intl

B. As a global package (This will work when this logic done as a Package in pub.workiva)

  1. Activate over_react_codemod run this command dart pub global activate over_react_codemod
  2. Activate Executables dart pub global activate over_react_codemod -x sort_intl

@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@akshaybhardwaj-wk akshaybhardwaj-wk marked this pull request as ready for review September 26, 2023 12:35
bin/intl_sorting.dart Outdated Show resolved Hide resolved
lib/src/executables/intl_sorting.dart Outdated Show resolved Hide resolved
bin/intl_sorting.dart Outdated Show resolved Hide resolved
lib/src/executables/intl_sorting.dart Outdated Show resolved Hide resolved
lib/src/executables/intl_sorting.dart Outdated Show resolved Hide resolved
lib/src/executables/sorting_test.dart Outdated Show resolved Hide resolved
lib/src/executables/intl_sorting.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@alanknight-wk alanknight-wk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better without that in a migrator, but we shouldn't need all of the codemod stuff at all. We want to strip this down into something we might be able to move out of the codemod.

bin/sort_intl.dart Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
bin/sort_intl.dart Show resolved Hide resolved
// Example:
// final intlPropMigrator = IntlMigrator(messages.className, messages);

Future<int> runMigrators(List<String> packageDartPaths,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and I'm saying we shouldn't run migrators at all.

@dustinlessard-wf dustinlessard-wf changed the title INTL-1608 : Activate _over_react_codemod excutables seprate INTL-1608 : Activate _over_react_codemod executables separately Oct 11, 2023
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
final packageName = packageNameLookup[packageRoot] ?? 'fix_me_bad_name';
_log.info('Starting migration for $packageName');
final IntlMessages messages = IntlMessages(packageName);
messages.write();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to put force: true on the write call, so it will always write.

for (String package in packageRoots) {
final packageRoot = p.basename(package);
final packageName = packageNameLookup[packageRoot] ?? 'fix_me_bad_name';
_log.info('Starting migration for $packageName');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logger info doesn't actually print anything. I would just turn this into a print statement.
And change the text to something like Sorting and formatting INTL files for $packageName.

final packageRoot = p.basename(package);
final packageName = packageNameLookup[packageRoot] ?? 'fix_me_bad_name';
_log.info('Starting migration for $packageName');
final IntlMessages messages = IntlMessages(packageName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe add a print statement that says something like
Wrote ${messages.outputFile.path} so it's clear which file(s) were changed

}

void printUsage() {
stderr.writeln('Activating Excutables and Sort INTL file.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be more like 'Sort and format INTL files'

return;
}

// If we have specified paths on the command line, limit our processing to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two cases we have to consider for this. The first is when we have a normal repo with a single package that has a file lib/src/intl/packagename_intl.dart in it. For example, wdesk. This executable works for that. But the reason it works is that this code finds every Dart file underneath /lib and finds a single package root which is the root of the repo. But in that case, finding the package root is not really necessary, because it's the known root of the repo.

The more complicated case is when a repo has multiple subpackages, for example ml_ui_client. In that case finding the package roots would be useful, but this doesn't do it properly because it only looks for files underneath /lib. There is no top-level lib directory in ml_ui_client, so it doesn't find anything and throws an exception. Could not find package root for file /Users/alanknight/dart/ml_ui_client/lib

lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
}

// If we have specified paths on the command line, limit our processing to
// those, and make sure they're absolute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are two directions this could go.

  1. Don't find all the Dart files. Find all the _intl.dart files under the root directory, but exclude test. Then I think this code would more or less work.
  2. Don't do any of this. Do what I said the last time, which you marked as resolved without doing it or explaining. The only difficulty is that it requires the package name. But the only thing that's used for is to name the intl file. So you could derive the package name from the pubspec as before, but knowing that it's in the root directory and there's only one. Or you could derive it from the name of the intl.dart file, whose position is known.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanknight-wk I have updated the code

  1. To derive the package name from pubspec.yaml create the following method
  2. Also tested in ml_ui_client if we run this executable at root level where no pubspec.yaml this shows an error
    could not determine the package name but under ml_ui_client directory it works .
  3. Also tested in DPC where we have pubspec.yaml on root it not shows error but sorting not working because intl.dart files are under subpackage/package/lib/src eg: subpackage/datatables/lib/src

Copy link
Contributor

@alanknight-wk alanknight-wk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, a couple of tiny nits and then I think we're good.

lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
lib/src/executables/sort_intl.dart Outdated Show resolved Hide resolved
@alanknight-wk
Copy link
Contributor

@Workiva/release-management-p

@alanknight-wk
Copy link
Contributor

QA +1
Ran it, works.

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from RM

@rmconsole7-wk rmconsole7-wk merged commit bb73b48 into master Nov 9, 2023
8 checks passed
@rmconsole7-wk rmconsole7-wk deleted the intl_1608 branch November 9, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants