-
Notifications
You must be signed in to change notification settings - Fork 30
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
improve codegen #40
improve codegen #40
Conversation
4195a92
to
043e798
Compare
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.
It's a big improvement! I like that there is some information for the user what happened during shield()
generation, even when it succeeded. Also good change that tsconfig.json
is taken into account, that means shield()
generation should work well with types defined outside of the *.telefunc.ts
source files.
You have to explain sometime to me why you keep a list of projects.
assertModuleScope('codegen/generateShield.ts') | ||
const generatedShields: GeneratedShield[] = [] | ||
const projects: Record<string, Project> = {} | ||
|
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.
Can these mutable (module scoped) 'global' variables be avoided?
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.
The lifetime of these global variables are during the build, e.g. during $ vite build
. That's what we want: we want these variables to contain all information during the entire build.
The server runtime never loads code/generateShield.ts
and these variables are not created at all.
} | ||
} | ||
|
||
function formatGeneratedShields(generatedShields: GeneratedShield[], root: string) { |
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.
Might get a bit too long with many telefunctions
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.
Too long?
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.
I was thinking it's fine to print GenerateShield[]
to the user after the build has finished, because that's what Vite does as well: upon$ vite build
Vite shows all generated dist/
files. So it aligns well with Vite. But yes I agree that for other stacks like Next.js we may not want to do that.
We can also just print something like shield()
generated for 14 telefunctions. Maybe with some kind of threshold e.g. if more than 7 then print a more compact log.
return typeToShieldSrc | ||
} | ||
|
||
function findTsConfig(telefuncFilePath: string): string | null { |
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.
This will not work as intended when people use Telefunc with a project that uses configuration file inheritance.
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.
Maybe this is a limitation we can address in the documentation, or perhaps ts-morph
has some tools that can bed used here.
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.
I'm probably missing something here, but the way I see it is that it should work because of the following.
From https://www.typescriptlang.org/docs/handbook/tsconfig-json.html:
The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project.
So AFAICT one tsconfig.json
= one TS project. With the only exception that a TS project may not have any tsconfig.json
(this PR also handles this case).
In case the user has multiple |
Co-authored-by: Bart Louwers <bart@emeel.net>
No description provided.