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

improve codegen #40

Merged
merged 7 commits into from
Oct 18, 2022
Merged

improve codegen #40

merged 7 commits into from
Oct 18, 2022

Conversation

brillout
Copy link
Owner

No description provided.

@louwers louwers self-requested a review October 14, 2022 20:40
Copy link
Collaborator

@louwers louwers left a 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.

telefunc/node/server/shield/codegen/generateShield.ts Outdated Show resolved Hide resolved
assertModuleScope('codegen/generateShield.ts')
const generatedShields: GeneratedShield[] = []
const projects: Record<string, Project> = {}

Copy link
Collaborator

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?

Copy link
Owner Author

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) {
Copy link
Collaborator

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Too long?

Copy link
Owner Author

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 {
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Owner Author

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).

telefunc/node/server/shield/codegen/generateShield.ts Outdated Show resolved Hide resolved
telefunc/node/server/shield/codegen/generateShield.ts Outdated Show resolved Hide resolved
@brillout
Copy link
Owner Author

You have to explain sometime to me why you keep a list of projects.

In case the user has multiple tsconfig.json => multiple TS roots => multiple Project.

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

Successfully merging this pull request may close these issues.

2 participants