-
Notifications
You must be signed in to change notification settings - Fork 451
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
Make typegen generate idempotent #8521
Comments
I am not able to reproduce the behavior you described. This command seems to me to be idempotent. Can you provide a minimal reproduceable example? The order of the types in my I tried changing the order of the imports in import { defineConfig } from 'sanity';
// Changing the order of these imports has no effect.
import a from 'sanity/schemas/a';
import b from 'sanity/schemas/b';
import c from 'sanity/schemas/c';
export default defineConfig({
...
schema: {
types: [
// Changing the order of these items has no effect.
a,
b,
c,
],
},
}) |
For the record, I think it is perfectly acceptable to commit these files to version control. I do this. Without the types file, my code would seem to have broken imports and would be impossible to read without generating that file locally. |
I was wrong. Changing the order of the import { defineConfig } from 'sanity';
// Changing the order of these imports has no effect.
import a from 'sanity/schemas/a';
import b from 'sanity/schemas/b';
import c from 'sanity/schemas/c';
export default defineConfig({
...
schema: {
types: [
// Changing the order of these items effects the order of the schema.json file.
a,
b,
c,
],
},
}) |
Thanks for trying to reproduce. Creating a minimal reproducable example might be tricky. I have a feeling that perhaps this is caused by having a relatively large codebase and our queries spread out in many different files (keeping them close to the components that use the data):
To be clear the problem is that even when not changing any code at all, but literally running the typegen command repeatedly in a row, the resulting file may be different every run. An assumption of mine is that this might be based on the way workers are used in processing the source files in the typegen script. Small changes in the speed of the file system reading the files might then be the determining factor for how the types are ordered in the resulting file. |
Small world, I had also started a thread on the slack @ https://sanity-io-land.slack.com/archives/CT03N628J/p1739121346906409 about the same issue. |
Is your feature request related to a problem? Please describe.
When repeatedly running
sanity typegen generate
on the same codebase, the generated file differs between runs. Types are ordered seemingly randomly within the file, resulting in unnecessary and often large diffs in version control.Describe the solution you'd like
Ensure the generated file uses a consistent, controlled order so that multiple runs produce identical output.
Describe alternatives you've considered
A post-processing step to reorder the file was considered, but it adds unnecessary complexity and could easily break on future updates.
Additional context
While keeping generated files in version control may not be ideal, our Next.js TypeScript build process requires these types to be available at build time, and generating them as part of the build process could introduce other issues.
The text was updated successfully, but these errors were encountered: