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

Emitter framework async source file #2183

Conversation

timotheeguerin
Copy link
Member

@timotheeguerin timotheeguerin commented Jul 13, 2023

Extracted this part of the breaking change from #2157

With prettier 3.0.0 the formatter is async. Which requires the emitter framework to provide a way to deal with async content mutation.

This only breaks in the emitter framework is calling this.emitter.emitSourceFile directly which would happen if you wrote a custom writeOutput. If usage only include sourceFile override then it still allows returning a non promise.

-const emittedSf = this.emitter.emitSourceFile(sf);
+const emittedSf = await this.emitter.emitSourceFile(sf);

@timotheeguerin timotheeguerin added the breaking-change A change that might cause specs or code to break label Jul 13, 2023
@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2183/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2183/

@timotheeguerin timotheeguerin force-pushed the emitter-framework-async-source-file branch from 9fd55a4 to 7edb82e Compare July 13, 2023 15:55
@timotheeguerin timotheeguerin enabled auto-merge (squash) July 24, 2023 15:33
@timotheeguerin timotheeguerin merged commit 5dbe73a into microsoft:main Jul 24, 2023
11 checks passed
@markcowl
Copy link
Contributor

markcowl commented Jul 27, 2023

Breaking Change Review

Describe the breaking change
The emitter.formatTypeSpec helper in the emitter framework is now asynchronous. Callers must now await the call. Only users of the emitter framework who wrote a custom writeOuput function will be affected.

-const emittedSf = this.emitter.emitSourceFile(sf);
+const emittedSf = await this.emitter.emitSourceFile(sf);
  • This was necessary to adapt to prettier 3.0
  • DPG emitters do not use this API

Back-compat design to avoid immediate breaking
Any back-compat design: None

Impact
This change affecting:

  • ARM
  • Data-plane
  • Existing specs: approx. # of service/spec impacted
  • New specs
  • Emitters
  • SDK

Targeted Sprint
Sprint: August (release: 8/8)

Additional information
Add any other information about the change including fixes for here.

@bterlson
Copy link
Member

I would also say that an async sourceFile is the correct design because many async things might be required to assemble your final source text. Prettier is one example but there could be many others folks would want to do (like invoke other CLI tools, make service requests, etc.)

@timotheeguerin timotheeguerin deleted the emitter-framework-async-source-file branch July 27, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A change that might cause specs or code to break
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants