feat: resolve Prettier config from file for payload generate:types
cmd
#11124
+38
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR extends the
generateTypes.ts
script to read from the appropriateprettier
config in a user's Payload application (if one exists), so that the output ofpayload generate:types
(payload-types.ts
) respects theprettier
configuration.Why?
The
payload-types.ts
file that was generated by Payload was previously not respecting theprettier
configuration when generated bypayload generate:types
. While not a major issue by any measure (i.e., there are workarounds, like formatting with commit hooks on downstream consumers ofpayload-types.ts
, it is nice to have it respect the existing config if possible.How?
I started with the prettier config resolution found in
packages/drizzle/src/utilities/createSchemaGenerator.ts
, but since I define myprettier
with the key inpackage.json
like the following:The resolution of the actual config was not working quite correctly as I guess the standard
prettier.resolveConfig()
does not play nice with ESM module configs (maybe I'm doing something wrong in my repo with that config?)Anyway, I stubbed it out into a function
loadPrettierConfig()
which does exactly that, otherwise returning the old default of just{ singleQuote: true }
.Maybe the contents of
loadPrettierConfig()
needs adjustment, but overall this does function with my personal Payload project at respecting my prettier settings when exportingpayload-types.ts
, and the thedev:generate-types
call seems to also respect changes to the config in thepayload
monorepo when testing, which I believe would be preferable.Please let me know if you have any thoughts or questions!