mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
fix: do not generate a stub for content types (#12909)
This commit is contained in:
parent
96dade6778
commit
011fa0f00c
3 changed files with 12 additions and 6 deletions
5
.changeset/great-hotels-reply.md
Normal file
5
.changeset/great-hotels-reply.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a case where `astro:content` types would be erased when restarting the dev server
|
|
@ -150,17 +150,15 @@ export async function syncInternal({
|
|||
settings.timer.end('Sync content layer');
|
||||
} else {
|
||||
const paths = getContentPaths(settings.config, fs);
|
||||
// Content is synced after writeFiles. That means references are not created
|
||||
// To work around it, we create a stub so the reference is created and content
|
||||
// sync will override the empty file
|
||||
if (
|
||||
paths.config.exists ||
|
||||
// Legacy collections don't require a config file
|
||||
(settings.config.legacy?.collections && fs.existsSync(paths.contentDir))
|
||||
) {
|
||||
// We only create the reference, without a stub to avoid overriding the
|
||||
// already generated types
|
||||
settings.injectedTypes.push({
|
||||
filename: CONTENT_TYPES_FILE,
|
||||
content: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +180,9 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
|
|||
for (const { filename, content } of settings.injectedTypes) {
|
||||
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
|
||||
fs.mkdirSync(dirname(filepath), { recursive: true });
|
||||
fs.writeFileSync(filepath, content, 'utf-8');
|
||||
if (content) {
|
||||
fs.writeFileSync(filepath, content, 'utf-8');
|
||||
}
|
||||
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ export interface AstroSettings {
|
|||
latestAstroVersion: string | undefined;
|
||||
serverIslandMap: NonNullable<SSRManifest['serverIslandMap']>;
|
||||
serverIslandNameMap: NonNullable<SSRManifest['serverIslandNameMap']>;
|
||||
injectedTypes: Array<InjectedType>;
|
||||
// This makes content optional. Internal only so it's not optional on InjectedType
|
||||
injectedTypes: Array<Omit<InjectedType, 'content'> & Partial<Pick<InjectedType, 'content'>>>;
|
||||
/**
|
||||
* Determine if the build output should be a static, dist folder or a adapter-based server output
|
||||
* undefined when unknown
|
||||
|
|
Loading…
Add table
Reference in a new issue