From f4057c18c91f969e3e508545fb988aff94c3ff08 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Thu, 15 Aug 2024 11:08:18 +0200 Subject: [PATCH] fix: content types sync in dev (#11716) * fix: content types sync in dev * fix: test --- .changeset/angry-plants-guess.md | 5 +++++ packages/astro/src/core/sync/index.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/angry-plants-guess.md diff --git a/.changeset/angry-plants-guess.md b/.changeset/angry-plants-guess.md new file mode 100644 index 000000000000..8798ef7038d2 --- /dev/null +++ b/.changeset/angry-plants-guess.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes content types sync in dev diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index c9b2ec235b98..9d9e5bc23703 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -3,11 +3,11 @@ import { performance } from 'node:perf_hooks'; import { dim } from 'kleur/colors'; import { type HMRPayload, createServer } from 'vite'; import type { AstroConfig, AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; -import { DATA_STORE_FILE } from '../../content/consts.js'; +import { CONTENT_TYPES_FILE, DATA_STORE_FILE } from '../../content/consts.js'; import { globalContentLayer } from '../../content/content-layer.js'; import { DataStore, globalDataStore } from '../../content/data-store.js'; import { createContentTypesGenerator } from '../../content/index.js'; -import { globalContentConfigObserver } from '../../content/utils.js'; +import { getContentPaths, globalContentConfigObserver } from '../../content/utils.js'; import { syncAstroEnv } from '../../env/sync.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; @@ -124,6 +124,14 @@ export async function syncInternal({ }); await contentLayer.sync(); settings.timer.end('Sync content layer'); + } else if (fs.existsSync(getContentPaths(settings.config, fs).contentDir.href)) { + // 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 + settings.injectedTypes.push({ + filename: CONTENT_TYPES_FILE, + content: '', + }); } syncAstroEnv(settings, fs);