keystone
keystone copied to clipboard
Cannot customize index.js
How to reproduce
- add a new customized page under
admin/pages/index.js - run Keystone
Expected: Showing my customized page content Actual:
./pages/index.js
Error:
× Expected ';', got '__internal'
╭─[/app/.keystone/admin/pages/index.js:1:1]
1 │ export { default } from "../../../admin/pages/index.js"__internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage';
· ──────────
╰────
Caused by:
Syntax Error
Environment:
- macOS 13.3.1
- Node.js 16.20.0
@keystone-6/core5.2.0
I think it's the way writeAdminFile is written can have concurrency issues.
Keystone uses Promise.all to call writeAdminFile() to write all files https://github.com/keystonejs/keystone/blob/main/packages/core/src/admin-ui/system/generateAdminUI.ts#L125.
When there are 2 files of the same path, each get a piece written to the file, result in a dubious file.
A temporary solution would be to write the pages/index.js using getAdditionalFiles:
import { config } from '@keystone-6/core';
config({
...other configs
getAdditionalFiles: [async () => {
return [
{
mode: 'write',
src: 'export { default } from "../../../admin/pages/index.js";',
outputPath: 'pages/index.js',
},
]
}]
})
Keystone will then skip writing it to avoid conflicting with user defined writes.
What is the preferred handling here - it seems like it's a semi significant decision as it forces a stronger opinion on the extensibility of custom admin pages.
I would assume that we would want to prioritise the auto-generated files to ensure core functionality.
At the moment, if I have a Todo list, and I add a custom admin/pages/todos/index.js, it'll cause the same error. With the getAdditionalFiles approach, my version will overwrite the list-generated page.
Both approaches stop core functionality from working, without being immediately clear why.