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

Issues with changes not detected immediately after ts-morph exits #755

Closed
Roaders opened this issue Nov 12, 2019 · 5 comments
Closed

Issues with changes not detected immediately after ts-morph exits #755

Roaders opened this issue Nov 12, 2019 · 5 comments

Comments

@Roaders
Copy link

Roaders commented Nov 12, 2019

Describe the bug
It seems that writing of source files happens after ts-morph has exited (and after subsequent tasks run).

Version: 5.0.0

A migration script that runs ts-morph to replace imports then immediately runs tslint --fix to reorder imports does not successfully reorder the imports. If I run the script a second time the out of place imports are correctly picked up by tslint and are fixed.
I am wondering if the actual writing of the source files is happening after ts-morph exits.

I am kind of expecting the response to be no you're crazy this can't happen but at the moment I can't see anything else that explains what I am seeing...

If I add a 2 second delay between ts-morph finishing and lint starting it DOES work correctly.

@dsherret
Copy link
Owner

This is probably my fault. I’ve been meaning to update the docs. Are you awaiting the result of calling .save()?

Side note: probably don’t use .saveSync() on a project because it will be super slow in comparison.

@Roaders
Copy link
Author

Roaders commented Nov 12, 2019

yes, that sounds like that's the problem. Is there a callback I can use to be informed when it's finished?

@dsherret
Copy link
Owner

@Roaders it returns a promise so you should be able to do project.save().then(() => console.log("Done.")) or use the await keyword in certain contexts.

@Roaders
Copy link
Author

Roaders commented Nov 12, 2019

ok, thanks. I'll give that a try.

@dsherret
Copy link
Owner

@Roaders please reopen this if it's still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants