-
Notifications
You must be signed in to change notification settings - Fork 523
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
improvement(generate:typetests,list): Only write output file when contents differs #21798
base: main
Are you sure you want to change the base?
improvement(generate:typetests,list): Only write output file when contents differs #21798
Conversation
build-tools/packages/build-cli/src/library/writeFileIfContentsDiffers.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/library/writeFileIfContentsDiffers.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/library/writeFileIfContentsDiffers.ts
Show resolved
Hide resolved
Co-authored-by: Alex Villarreal <716334+alexvy86@users.noreply.github.com>
build-tools/packages/build-cli/src/library/writeFileIfContentsDiffers.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/commands/generate/typetests.ts
Outdated
Show resolved
Hide resolved
I think the motive I had for suggesting this work (avoid needless file churn as it could invalidate incremental build state) was flawed for multiple reasons:
In conclusion: If I was right about how our build worked (and I wasn't) this would be really bad. Since I don't actually know how this part of our build works, someone else should probably make the judgement on if we want to do this. |
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 still think it is a better idea to understand the root trouble with .done tracking before making things more complicated.
filePath: PathLike, | ||
contents: string, | ||
): Promise<boolean> { | ||
const fileContents = await readFile(filePath, { encoding: "utf8" }); |
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.
What happens if the file doesn't exist yet? I would guess it throws, but in that case we want an explicit write.
* @param filePath - The path to the file to write. | ||
* @param contents - The contents to write to the file. | ||
* @returns True if the file was written; false otherwise. | ||
*/ |
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 we add a note about performance improvements?
This helper fully reads and closes a file before writing it (if needed).
In the common case that writing is needed, it will be more efficient to open the file for read+write to start and keep it open until any writing is dealt with.
Adds a utility function to write to files only if the contents you're writing is different from what's already there. This function is used in the type test generation and
flub list
to ensure we only write changes when needed.This function may be useful for other commands as well, but those changes are left for separate PRs.
I also opportunistically replaced some synchronous function calls with async counterparts.