-
Notifications
You must be signed in to change notification settings - Fork 7
FED-3903 React 18 Upgrade Codemod #319
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a1cf774
Add initial codemod with test setup
sydneyjodon-wk 63110b5
Update removal
sydneyjodon-wk 1b5f083
Clean up dart part of script
sydneyjodon-wk 1104ae3
Fix broken test
sydneyjodon-wk 3a45f94
Format
sydneyjodon-wk 5bc71de
Fix html whitespace issue
sydneyjodon-wk 33472f9
Fix failing tests
sydneyjodon-wk c597041
Fix string const in dart file
sydneyjodon-wk 4df4e0b
Clean up
sydneyjodon-wk 98d67de
Clean up
sydneyjodon-wk 2ec5f5e
Fix lint
sydneyjodon-wk 4622c57
Address feedback
sydneyjodon-wk 89e33d1
Add indentation test to fail
sydneyjodon-wk ade7817
Update indentation removal for links
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 hidden or 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 2025 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/react_18_upgrade.dart'; |
This file contains hidden or 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,91 @@ | ||
| // Copyright 2025 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/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/util.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:react_18_upgrade | ||
| """; | ||
|
|
||
| /// Updates React JS paths in HTML and Dart files from the React 17 versions to the React 18 versions. | ||
| void main(List<String> args) async { | ||
| final parser = ArgParser.allowAnything(); | ||
|
|
||
| final parsedArgs = parser.parse(args); | ||
|
|
||
| // Work around allowAnything not allowing you to pass flags. | ||
| if (parsedArgs.arguments.contains('--help')) { | ||
| // Print command description; flags and other output will get printed via runInteractiveCodemodSequence. | ||
| print( | ||
| 'Updates React JS paths in HTML and Dart files from the React 17 versions to the React 18 versions.\n'); | ||
| } | ||
|
|
||
| exitCode = await runInteractiveCodemodSequence( | ||
| allHtmlPathsIncludingTemplates(), | ||
| [ | ||
| // Update react.js bundle files to React 18 versions in html files | ||
| ...react17to18ReactJsScriptNames.keys.map((key) => HtmlScriptUpdater( | ||
| key, react17to18ReactJsScriptNames[key]!, | ||
| updateAttributes: false)), | ||
| // Remove React 17 react_dom bundle files in html files | ||
| ...react17ReactDomJsOnlyScriptNames | ||
| .map((name) => HtmlScriptUpdater.remove(name)), | ||
| ], | ||
| defaultYes: true, | ||
| args: parsedArgs.rest, | ||
| additionalHelpOutput: parser.usage, | ||
| changesRequiredOutput: _changesRequiredOutput, | ||
| ); | ||
|
|
||
| if (exitCode != 0) return; | ||
|
|
||
| exitCode = await runInteractiveCodemodSequence( | ||
| allDartPathsExceptHidden(), | ||
| [ | ||
| // Update react.js bundle files to React 18 versions in Dart files | ||
| ...react17to18ReactJsScriptNames.keys.map((key) => DartScriptUpdater( | ||
| key, react17to18ReactJsScriptNames[key]!, | ||
| updateAttributes: false)), | ||
| // Remove React 17 react_dom bundle files in Dart files | ||
| ...react17ReactDomJsOnlyScriptNames | ||
| .map((name) => DartScriptUpdater.remove(name)), | ||
| ], | ||
| defaultYes: true, | ||
| args: parsedArgs.rest, | ||
| additionalHelpOutput: parser.usage, | ||
| changesRequiredOutput: _changesRequiredOutput, | ||
| ); | ||
| } | ||
|
|
||
| const reactPath = 'packages/react/'; | ||
|
|
||
| const react17to18ReactJsScriptNames = { | ||
| '${reactPath}react.js': '${reactPath}js/react.dev.js', | ||
| '${reactPath}react_with_addons.js': '${reactPath}js/react.dev.js', | ||
| '${reactPath}react_prod.js': '${reactPath}js/react.min.js', | ||
| '${reactPath}react_with_react_dom_prod.js': '${reactPath}js/react.min.js', | ||
| }; | ||
|
|
||
| const react17ReactDomJsOnlyScriptNames = [ | ||
| '${reactPath}react_dom.js', | ||
| '${reactPath}react_dom_prod.js', | ||
| ]; | ||
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.