Skip to content

feat: use local cache to avoid generating logics twice #52

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joshsny
Copy link

@joshsny joshsny commented Jun 19, 2025

Adds a --cache flag that uses a local cache stored in node_modules/kea-typegen/cache.json to avoid generating logics twice if a file is unchanged.

This speeds up running kea-typegen write a lot on subsequent calls since we were previously generating all of them. In most cases, only one logic has been changed.

We can also save this cache together with type files we've previously generated between CI runs to speed up type generation.

}
}

private getFileHash(filePath: string): string {
Copy link
Author

Choose a reason for hiding this comment

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

using a hash of the file contents rather than modified time so it's stable when run on different machines (e.g. in CI)

}
}

public getChangedFiles(filePaths: string[]): string[] {
Copy link
Author

Choose a reason for hiding this comment

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

We're basing this off the original logic file. If a user modifies their generated type file, this will ignore it, and they'd need to run without the cache flag to generate it again

Copy link
Author

Choose a reason for hiding this comment

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

we could also check hashes for the type files here, but if we run kea watch it'll basically negate all the benefit locally, as that'll keep writing over the logic type files (or at least that is what happens to me when running things locally)

@joshsny
Copy link
Author

joshsny commented Jun 19, 2025

@mariusandra I am rethinking this now and thinking that this implementation is very naive - we really need to check all imports of a logic file and their hashes to determine if the logic has changed and needs type generation. This will make caching much less productive for some changes e.g. if I make a change to something like the types.ts file in our repo, that'd cause all logics to be regenerated. But nonetheless I'd be interested in getting your thoughts on whether you think this is an approach we can take or not.

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.

1 participant