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

feat(convert-outputs): add migrations for new output() function #301

Merged
merged 3 commits into from
Mar 28, 2024

Conversation

eneajaho
Copy link
Collaborator

@eneajaho eneajaho commented Mar 9, 2024

Added migration support for:

  • EventEmitters -> output
  • Observable/Subject/BehaviorSubject -> outputFromObservable
  • support for aliases
  • docs

@eneajaho eneajaho added the enhancement New feature or request label Mar 9, 2024
@eneajaho eneajaho requested a review from nartc March 9, 2024 01:00
@eneajaho eneajaho self-assigned this Mar 9, 2024
Copy link

nx-cloud bot commented Mar 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 12ae362. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@eneajaho
Copy link
Collaborator Author

eneajaho commented Mar 9, 2024

cc @joshuamorony you may like this too 😄

@eneajaho eneajaho requested a review from tomalaforge March 19, 2024 16:36
@eneajaho eneajaho enabled auto-merge (squash) March 19, 2024 16:38
);
} else {
node.replaceWithText(newProperty.print());
// remove old class property Output
Copy link

Choose a reason for hiding this comment

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

after node.replaceWithText(newProperty.print());
this code is needed for something like 'this.someOutput.next() to be replaced with this.someOutput.emit()' as this was actually possible on EventEmiter

newProperty.findReferencesAsNodes().forEach((reference) => {
								try {
									//we are looking for something like 'this.someOutput.next() as we want to replace it with this.someOutput.emit()'
									//for each identifier we go someOutput, this.someOutput , then DotNotation , then Indentifier and we check that this identifier is 'next'
									const nextIdentifier = reference
										.getParentIfKindOrThrow(SyntaxKind.PropertyAccessExpression)
										.getNextSiblingIfKindOrThrow(SyntaxKind.DotToken)
										.getNextSiblingIfKindOrThrow(SyntaxKind.Identifier);
									if (nextIdentifier.getText() === 'next') {
										if (
											nextIdentifier
												.getParent()
												.getParent()
												.isKind(SyntaxKind.CallExpression)
										) {
											console.log(
												nextIdentifier.getParent().getParent().getText(),
											);
											console.log('\nFOUND next - replacng with emit');
											nextIdentifier.replaceWithText('emit');
										}
									}
								} catch (err) {}
							});

I have large project that I'm migrating so I will be adding coments like this if you are ok with it with next things that I stumbled on

now working on types as EventEmitter() is typed EventEmitter but output() is OutputEmitterRef, also found usages of accessing valueChanges on eventEmitters etc so will take care of those as well

Copy link

Choose a reason for hiding this comment

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

of course here simple regex could be used but I feel like this is much safer in terms of migration

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hello @kbrilla
Thanks for all this 🙌🙏
Would you mind send a PR that we can merge into this PRs branch?
And then we can merge this PR into main and cut a release?

@eneajaho eneajaho merged commit 432c290 into main Mar 28, 2024
6 checks passed
@eneajaho eneajaho deleted the feat/migrate-outputs branch March 28, 2024 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants