diff options
author | 2024-08-15 11:08:18 +0200 | |
---|---|---|
committer | 2024-08-15 11:08:18 +0200 | |
commit | f4057c18c91f969e3e508545fb988aff94c3ff08 (patch) | |
tree | bc52f2f3822341e015229f5abfbaa60b53579c6e | |
parent | 791d809cbc22ed30dda1195ca026daa46a54b551 (diff) | |
download | astro-f4057c18c91f969e3e508545fb988aff94c3ff08.tar.gz astro-f4057c18c91f969e3e508545fb988aff94c3ff08.tar.zst astro-f4057c18c91f969e3e508545fb988aff94c3ff08.zip |
fix: content types sync in dev (#11716)
* fix: content types sync in dev
* fix: test
-rw-r--r-- | .changeset/angry-plants-guess.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/sync/index.ts | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/.changeset/angry-plants-guess.md b/.changeset/angry-plants-guess.md new file mode 100644 index 000000000..8798ef703 --- /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 c9b2ec235..9d9e5bc23 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); |