feat: add Payload CMS plugin#1546
Conversation
commit: |
|
I checked the CI failure details for the tests, but even if I revert all changes in this pull request, the same tests still fail, so it seems unrelated to the changes in this pull request. |
webpro
left a comment
There was a problem hiding this comment.
Thanks for the PR! Before we can merge this, some work is probably needed to make it more usable/correct in more projects.
| 'payload-types.ts', | ||
| 'src/payload-types.ts', | ||
| 'payload.config.ts', | ||
| 'src/payload.config.ts', |
There was a problem hiding this comment.
Instead of having patterns like src/app/**/importMap.js, we should probably import the actual config file and then read config.admin.importMap.importMapFile. If it's not set, we can use default value (e.g. src/app/(payload)/admin/importMap.js).
This way, it would be accurate and works in any project using Payload CMS.
It starts by adding const config = ["src/payload.config.ts"] and implementing resolveConfig — please see https://knip.dev/writing-a-plugin.
It helps to demonstrate/test with public repos such as the templates at https://github.com/payloadcms/payload/tree/main/templates
There was a problem hiding this comment.
I've changed it to load the actual Payload config and determine the importMap path.
I tested the plugin with the templates available via npx create-payload-app excluding the plugin template, and it was able to load both config and importMap. While Knip did report some unused files and unused exports etc., all of those were valid.
With the plugin template, some files that are actually in use were reported as unused. This seems to be caused by the template’s project structure, since even some Next.js-related files are being flagged as unused. To make it work correctly for the plugin template as well, we’d probably need changes on Knip’s Next.js plugin too, so I’m currently unsure whether it makes sense to support that case.
…r/knip into add-payload-plugin
|
This is excellent, thank you very much! |
|
🚀 This pull request is included in v5.85.0. See Release 5.85.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Added a plugin for Payload CMS.
Add
payload.config.ts, which Payload CMS requires as a configuration file, andpayload-types.ts, its automatically generated type definitions, to the entry.In Payload CMS configurations, some components are loaded by specifying their path as a string instead of direct import. Resolved components are imported from the automatically generated
app/**/importMap.jsorsrc/app/**/importMap.js. By adding these files to the entry, we can correctly determine whether components are being used.Additionally, exclude automatically generated migration files from the project.