diff options
author | 2024-08-15 16:52:15 +0200 | |
---|---|---|
committer | 2024-08-15 16:52:15 +0200 | |
commit | 3c2f93b66c6b8e9d2ab58e2cbe941c14ffab89b5 (patch) | |
tree | 558225bee4f59a736f1367141a3ad14c8b76699e | |
parent | 6c1560fb0d19ce659bc9f9090f8050254d5c03f3 (diff) | |
download | astro-3c2f93b66c6b8e9d2ab58e2cbe941c14ffab89b5.tar.gz astro-3c2f93b66c6b8e9d2ab58e2cbe941c14ffab89b5.tar.zst astro-3c2f93b66c6b8e9d2ab58e2cbe941c14ffab89b5.zip |
fix: content types sync in dev (#11727)
Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
-rw-r--r-- | .changeset/ten-buckets-matter.md | 5 | ||||
-rw-r--r-- | packages/astro/src/content/types-generator.ts | 8 | ||||
-rw-r--r-- | packages/astro/src/core/sync/index.ts | 3 |
3 files changed, 10 insertions, 6 deletions
diff --git a/.changeset/ten-buckets-matter.md b/.changeset/ten-buckets-matter.md new file mode 100644 index 000000000..b70a244a0 --- /dev/null +++ b/.changeset/ten-buckets-matter.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a type issue when using the Content Layer in dev diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index 973a892fa..faf02d95d 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -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, diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index ce381537e..aecf6c9c3 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -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 = { /** @@ -122,7 +123,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 |