-
Notifications
You must be signed in to change notification settings - Fork 369
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
feat(astro): add initial support for astro projects #2908
base: main
Are you sure you want to change the base?
Conversation
In general, I think projen wants to foster configuration as code. So if Astro already uses configuration as code - that's great! Provided it's not just a glorified JSON file. The issue we have is that in order to support projen's component based configuration model, we need to give projen at least some control over the config. As a minimum, projen at least needs to be able to synth required config and replace it with previously synthd config. This is all doable already, and there are various strategies to implement a hybrid approach. The main challenge is for users to provide "complex configuration via projen". That is anything that can't be represented by a simple data type (string, number, bool, list map) or an enum-like class. The latter is very flexible, but falls short of giving users full control, e.g. they can't provide any arbitrary JS expression. This is tricky to argue about without knowing much about astro's config or seeing some concrete examples.
|
@mrgrain Thanks for your input! Unfortunately Astro does not support JSON or YML, the only option is generating a .js or a .ts config that might contain arbitrary js expressions. https://docs.astro.build/en/reference/configuration-reference/ A simple case would look like that //astro.config.ts
import {defineConfig, sharpImageService} from 'astro/config';
import tailwind from "@astrojs/tailwind";
import react from '@astrojs/react';
// https://astro.build/config
export default defineConfig({
root: new URL("./foo", import.meta.url).toString(),
// Resolves to the "./public" directory, relative to this config file
publicDir: new URL("./public", import.meta.url).toString(),
integrations: [tailwind(), react()],
experimental: {
assets: true
},
image: {
service: sharpImageService(),
},
}); Do you suggest doing something like // astro.config.ts
import userConfig from './astro.user.config.ts;
const generatedConfig = defineConfig({
// synthd config
});
// mergeConfig might have special rules for merging in case of overlap
export default mergeConfig(generatedConfig, userConfig) Or we could do the merging during synth instead of the runtime approach? That way the user could preview the resulting merge output and make things easier to debug. |
That example looks like it would be feasible to generate with the existing tools (read: build the string) from a projen options object. The key question for me is, how complex configurations would get that we need to ship with projen. There are also other approaches we could explore when they get to complex, like publishing them as separate packages.
Yes, that's what I had in mind.
This would be ideal. I just don't know how we would do this if we want/have to to allow users to define their config as arbitrary expressions. |
This draft PR adds basic support for the emerging https://astro.build (https://github.com/withastro/astro) framework.
Before this is ready I plan to:
Also I'm looking for advice how to allow consumers to configure the
astro.config.ts
which is obviously not as straightforward compared to YAML or JSON. I've read other pull requests and issues and it is my understanding that there is no solution or best practice in place. I have thought of the following options:astro.config.ts
.projen.ts
Thanks
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.