Skip to content
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

fix: content types sync in dev #11727

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-buckets-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a type issue when using the Content Layer in dev
8 changes: 3 additions & 5 deletions packages/astro/src/content/types-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,9 @@ async function writeContentFiles({

// If it's the first time, we inject types the usual way. sync() will handle creating files and references. If it's not the first time, we just override the dts content
if (settings.injectedTypes.some((t) => t.filename === CONTENT_TYPES_FILE)) {
fs.promises.writeFile(
new URL(CONTENT_TYPES_FILE, settings.dotAstroDir),
typeTemplateContent,
'utf-8',
);
const filePath = fileURLToPath(new URL(CONTENT_TYPES_FILE, settings.dotAstroDir));
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
await fs.promises.writeFile(filePath, typeTemplateContent, 'utf-8');
} else {
settings.injectedTypes.push({
filename: CONTENT_TYPES_FILE,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { Logger } from '../logger/core.js';
import { formatErrorMessage } from '../messages.js';
import { ensureProcessNodeEnv } from '../util.js';
import { writeFiles } from './write-files.js';
import { fileURLToPath } from 'node:url';

export type SyncOptions = {
/**
Expand Down Expand Up @@ -124,7 +125,7 @@ export async function syncInternal({
});
await contentLayer.sync();
settings.timer.end('Sync content layer');
} else if (fs.existsSync(getContentPaths(settings.config, fs).contentDir.href)) {
} else if (fs.existsSync(fileURLToPath(getContentPaths(settings.config, fs).contentDir))) {
// 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
Expand Down
Loading