Support customization of Keystone's esbuild configuration (Monorepos) #8406
Replies: 3 comments 2 replies
-
I am in the same boat as @acburdine, although for different reason (not monorepo). I have a project that has similar setup to nextjs-keystone example. Sometimes it is run as single nextjs app and sometimes as separate frontend and backend. Since I have been using the latter initially, I have some custom stuff in keystonte's Admin UI. If this is included, then config.js generated from esbuild is not valid js:
because in tsconfig.json I have
So for some time now, I have been maintaining my own patch which specifies tsconfig for keystone's esbuild purposes:
Would love to have some esbuild configuration for that or even make a PR, just not sure how to make it happen. |
Beta Was this translation helpful? Give feedback.
-
We are working with keystone and would find this useful as well. Thanks for the nice breakdown @acburdine |
Beta Was this translation helpful? Give feedback.
-
I concur that this is a common problem when working with monorepos! I have opened the following pull request #9235 to continue this discussion, as this is a feature that has been problematic for us in the past, but like you, we worked around it. |
Beta Was this translation helpful? Give feedback.
-
Some initial context - the team that I'm on develops a number of different applications, most of which use a Next.js Frontend and Keystone Backend. These applications all live in a single monorepo, managed via Nx using some custom-built Nx plugins. Nx has the concept of "apps", which are the actual deployed applications, and "libs", which are typically shared code libraries.
One of the unique things about Nx is that it doesn't use a package linker (i.e. pnpm or yarn workspaces) under the hood. Instead, it has a Typescript config file at the root of the repo that enables importing of local repo packages via Typescript path aliases. If a framework is configured correctly, this means that none of the local packages have to be "built" prior to their usage in monorepo apps - the typescript path aliases take care of resolving all of the files correctly.
When we first started using Keystone, it was still using babel-typescript via a pirates hook to compile the keystone.ts file. This didn't work with typescript path aliases at all, and as such, we had to write some custom scripts to
tsc
a given Keystone app's dependencies, then link them into that app's node_modules folder.Now that Keystone uses esbuild under the hood instead to compile the
keystone.ts
file - we realized recently that all the tooling exists to support Nx's way of doing things. This actually almost works out of the box too - the only thing preventing Typescript path aliases from working correctly is the esbuild plugin configuration that marks any non-relative path import as an "external" dependency. All of our internal repo packages share a common scope, so all that we had to do to enable tsconfig path support was make a tiny change to these three lines via patch-package:after adding that line, building Keystone worked flawlessly without the need to do any prior
tsc
-ing of local repo packages 🎉Now obviously pushing that exact change to Keystone itself doesn't make sense 😅 but it got me thinking if there might be some way to enable customizing the esbuild config without compromising on Keystone's excellent DX.
The simplest solution would be to add it to the
keystone.ts
config, but that doesn't work since it creates a chicken and egg problem.Some potential ideas I had:
keystone dev
/keystone build
.next.config.js
) - this would potentially allow more granular customization of esbuild settings beyond just monorepo typescript support.I also completely understand if this isn't something that the Keystone team wants to add 😄 I'm happy to maintain my local patch of Keystone to support our use-case if adding something like this would make it more difficult for everyone else to use Keystone.
I'd also be happy to submit a PR with whatever solution makes the most sense (if any). Thanks for making and maintaining a great project!
Beta Was this translation helpful? Give feedback.
All reactions