-
Notifications
You must be signed in to change notification settings - Fork 995
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
enable typescript services and sdl #515
Conversation
Check out the |
@cannikin thanks, I'll mark this as draft until i add tests |
@jmreidy another approach that we've been thinking of is to make the templates typescript by default, but to transpile them to JavaScript and to format them through prettier once they're generated. The reason for this is because I think having to maintain two separate files for the same template might be a bit cumbersome. |
@peterp makes sense. How would a consumer enable JS instead of TS? Pass a |
@jmreidy Yeah, I think that makes sense. Once we fully support TypeScript I think we'll store the type of project in |
Excited about this. Thanks @jmreidy
Just to be clear, for the near-term any I'm suggesting we maintain JS default across the entire project until JS is no longer the default across the entire project. Does this make sense and do you agree @peterp? |
Ah, also some potential overlap here with scaffold generation that will need to be handled. @cannikin If the SDL and Service templates are written as TS files, then the |
That's true, the scaffold generator makes a call over to the sdl and service generators' |
If I can throw in a flag idea, if we're defaulting to typescript I would think just passing along |
💯, agreed. |
@cannikin realizing as well that if we generate TS SDL files, and then run I'm hesitant to add I'm considering the following:
What do y'all think? |
Hmm, I don't love the idea of only the sdl and services generators supporting TS and not the others...ideally all the generators should offer the same experience. But I guess we have to start somewhere? What do you think @thedavidprice and @mojombo? How's the developer experience with only those two generators being typescript enabled? Maybe if you try the |
A couple other options:
* we enable TS for scaffold, but only for non-web files
* we update all generators to support TS, but don't land it until router
support lands
…On Fri, May 8, 2020 at 12:27 PM Rob Cameron ***@***.***> wrote:
Hmm, I don't *love* the idea of only the sdl and services generators
supporting TS and not the others...ideally all the generators should offer
the same experience. But I guess we have to start somewhere?
What do you think @thedavidprice <https://github.com/thedavidprice> and
@mojombo <https://github.com/mojombo>? How's the developer experience
with only those two generators being typescript enabled? Maybe if you try
the --typescript flag with any of the other generators you get some
console output telling you "Typescript support is coming soon" and we can
replace them one at a time?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#515 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIY3N5LJ5QQBO6YHYDJUDRQQXIXANCNFSM4MZZJ6RQ>
.
|
Handling existing files
I think this should be true of all the generators, i.e. check for the existence of both TS and JS when executing, and then throw an Error if either exists, regardless of the target being TS or JS. Users can override with @cannikin do all the generators currently check for existing files before running? Scaffold TS supportIf it's not going to result in a runtime Error, and if we can communicate the behavior clearly, I'm all for users being able to generate TS files for SDL and Services even though Web will be JS. Most likely this would require a pre-run explanation with user confirmation to proceed.
So maybe:
? Generators Requiring Router SupportWe can still make the conversion but only allow/enable target=JS (i.e. always transpile when the command is run) until dependencies like the Router are ready. Or am I missing something here? Making TS the default Target but enabling JS target as default (for now)[edit: this is outdated thinking on my part -- see #523 for a much clearer path to address this] If our goal is to make TS the eventual default for Redwood, I'm wondering how best to navigate user behavior changes during this transition. So imagining a future example:
So in the future, we'll have a default target to work with. But we don't right now.
I might be overthinking this as we can just add both ?? Organizing Effort with a Tracking issueSeems like we are going to need some organization here across the entire effort of converting generators to TS. I've created a Tracking Issue #523 Please take a look and definitely discuss and suggest edits. Once we have consensus on the plan, I'll see if we can get additional community support from these kind folks as well. (@jmreidy would be great to discuss how/if you and Mohsen might want to help with organizing the effort -- no pressure but let us know if interested.) |
Yup, they'll stop as soon as they run into a file that exists. You'll need to I like the idea of just adding |
@thedavidprice hats off for fantastic documentation and breakdown in that tracking issue. Thanks so much for the clarifying commentary both there and in this thread. Two last questions from me:
And yes, happy to help organize the effort and pull in folks from the community, just let me know if you have any specific guidance on how you'd like me to proceed there. |
@jmreidy We're going to modify the architecture of the CLI and generators slightly - I'll involve you in those discussions when they happen, but I don't think we'll get much value out of converting those now. |
711c520
to
2341368
Compare
Maybe it should look more like this? If you look at blitz they are using the generated types from prisma client. |
@jmreidy Thanks for your patience here as we catch up with your trailblazing! The core team discussed this yesterday. I've updated #523 to address questions here as well as provide a roadmap for proceeding (including some redundancy of previous decisions). I'm revising the 523 as we learn more, so please add your comments and questions as needed. Questions from previous comments in this PR
^^ I attempt to address the first part of this in #523 tl;dr generators need to be both TS/JS aware for creating, overwriting, and refusing to overwrite in the case of hybrid scenario. And for the second part, hybrid generators are fine during this transition. E.g. TS SDL and Services with JS web/ components is ok (for now).
^^ no, not at this time
^^ the goal is to transition in steps, meaning each PR will focus on incremental, working changes. This might not always be possible, so we'll adapt as we go. But in this case, it seems right now we can support SDL, Service, and hybrid-Scaffold as an incremental step that does not change existing JS behavior or expectations |
9694f99
to
387625d
Compare
Good news! I got it working! (video) Bad news - rebasing is a massive pain. Especially after https://github.com/redwoodjs/redwood/pull/611/files, which rewrote all the scaffold templates. I'll need to keep working through conflicts, if we can hold on making changes to templates in the meantime, I'd appreciate it... |
6faae33
to
95aac03
Compare
95aac03
to
ab53b6b
Compare
jest.mock('fs') | ||
jest.mock('@babel/core', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
babel is unhappy when you mock fs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're thinking of creating a wrapper around fs
with a few common operations like write, read, unlink in @redwoodjs/internal
that should be slightly more manageable to mock.
|
||
expect(Object.keys(files).length).toEqual(2) | ||
}) | ||
const itReturnsExactly2Files = (baseArgs) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted in a comment elsewhere - extracted tests into named function to reduce duplication across TS and JS versions
} | ||
|
||
const getBaseFile = (file) => file.replace(/\.\w*$/, '') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding typescript
as a flag to destroy
, it felt more ergonomic to me for it to just destroy whatever js/ts variation is found.
This should be good to go but will need someone to take it over the finish line - I just had a baby! |
@jmreidy Woah! Huge congrats to you and yours!! 🎉😍 We can't thank you enough for all the sustained effort you put into this, Justin. It's created so much momentum and paved the way by example. You're going to be missed. But you've made a huge impact here. And we'll be excited to see you again in the future when/if you're available months from now. One thing that might help --> could you give @peterp (and maybe me) commit access to If for some reason we get absolutely stuck, I’ll reach out to you directly apart from GitHub. Congrats again! |
Thanks for this @jmreidy! |
What
Enables the generation of
sdl
andservice
files in TypeScript. Uses the--typescript
boolean flag passed togenerate service
andgenerate sdl
. Default remains javascript, but we'll reduce templates to only include TS (and generate the JS via transpiling the TS output).Implements portions of #523.
Testing
Added unit tests to cover TS service and SDL files
Implementation Plan
scaffold
commanddestroy
andgenerate