Open NeoPhi opened 1 week ago
Do you have an example of a CI situation where src
cannot be written to?
@NeoPhi is your env.d.ts
file committed in your repository?
@florian-lefebvre maybe we could add a check only during the build. If the file doesn't exist, we could throw a runtime error saying that the file should be committed. If it exists, we don't do any write operations. What do you think?
That sounds reasonable to me, and easy to implement
I suppose there's a risk breaking current setups where the src/env.d.ts
is not committed, but I'm not sure how common is that. Maybe it would be simpler to not write the file if the file content is the same? Though I also agree with Erika that this is kinda a niche situation.
True, definitely niche, but FS operations are always a big question mark and throw unexpected errors like in this case
You should be able to create a new Astro project, run astro build
having never run dev and it should work. It sounds like the suggestion here would break that. We don't have many required files in Astro and we shouldn't start adding them, imo. This is definitely a niche situation.
Could we add a --no-env
or something? It's always been a little "controversial" to create files inside src as some people simply don't like such a thing. Could solve this.
Our env.d.ts
is committed since we added custom entries to support TypeScript as per https://docs.astro.build/en/guides/environment-variables/#intellisense-for-typescript
The --no-env
suggestion seems like a nice solution, similar to yarn's --frozen-lockfile
.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
If
src/env.d.ts
is present but read-only by the user running a build, the build will fail. It seemssetUpEnvTs
will unconditionally rewrite this file even if there are no changes needed. This is problematic for CI/CD situations where the build user is not allowed to modify any files under thesrc/
directory.https://github.com/withastro/astro/blob/dbbd0a22e249bb62d406aed016ed626a651a332d/packages/astro/src/vite-plugin-inject-env-ts/index.ts#L99
What's the expected result?
No files under
src
are modified if changes are not needed.Link to Minimal Reproducible Example
N/A
Participation