From 43d42fc00721429953b6ee3f2c8670164889d2f7 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 15 Jan 2025 13:56:19 +0000 Subject: [PATCH] Always regenerate content layer on sync --- packages/astro/src/content/content-layer.ts | 17 ++++---- packages/astro/src/core/sync/index.ts | 47 +++++++++------------ 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/packages/astro/src/content/content-layer.ts b/packages/astro/src/content/content-layer.ts index 71aca7d9113b..9faf48e6016e 100644 --- a/packages/astro/src/content/content-layer.ts +++ b/packages/astro/src/content/content-layer.ts @@ -32,10 +32,6 @@ export interface ContentLayerOptions { watcher?: FSWatcher; } -export function getAstroConfigDigest(config: AstroConfig) { - const { vite, integrations, adapter, ...hashableConfig } = config; - return safeStringify(hashableConfig); -} export class ContentLayer { #logger: Logger; @@ -146,9 +142,6 @@ export class ContentLayer { return this.#queue.add(() => this.#doSync(options)); } - configMatches(config: AstroConfig) { - return getAstroConfigDigest(config) === getAstroConfigDigest(this.#settings.config); - } async #doSync(options: RefreshContentOptions) { let contentConfig = globalContentConfigObserver.get(); @@ -184,8 +177,14 @@ export class ContentLayer { } logger.info('Syncing content'); - const astroConfigDigest = getAstroConfigDigest(this.#settings.config); - + const { + vite: _vite, + integrations: _integrations, + adapter: _adapter, + ...hashableConfig + } = this.#settings.config; + + const astroConfigDigest = safeStringify(hashableConfig); const { digest: currentConfigDigest } = contentConfig.config; this.#lastConfigDigest = currentConfigDigest; diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 05d73003d5bf..e73d87e922e3 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -50,7 +50,7 @@ export type SyncOptions = { }; manifest: ManifestData; command: 'build' | 'dev' | 'sync'; - watcher?: FSWatcher + watcher?: FSWatcher; }; export default async function sync( @@ -121,7 +121,7 @@ export async function syncInternal({ force, manifest, command, - watcher + watcher, }: SyncOptions): Promise { const isDev = command === 'dev'; if (force) { @@ -133,34 +133,27 @@ export async function syncInternal({ if (!skip?.content) { await syncContentCollections(settings, { mode, fs, logger, manifest }); settings.timer.start('Sync content layer'); - let contentLayer = globalContentLayer.get(); - if(contentLayer && !contentLayer.configMatches(settings.config)) { - logger.info('content', 'Astro config changed: reloading content layer.'); - contentLayer = null; + let store: MutableDataStore | undefined; + try { + const dataStoreFile = getDataStoreFile(settings, isDev); + store = await MutableDataStore.fromFile(dataStoreFile); + } catch (err: any) { + logger.error('content', err.message); + } + if (!store) { + logger.error('content', 'Failed to load content store'); + return; } - if (!contentLayer) { - let store: MutableDataStore | undefined; - try { - const dataStoreFile = getDataStoreFile(settings, isDev); - store = await MutableDataStore.fromFile(dataStoreFile); - } catch (err: any) { - logger.error('content', err.message); - } - if (!store) { - logger.error('content', 'Failed to load content store'); - return; - } - contentLayer = globalContentLayer.init({ - settings, - logger, - store, - watcher - }); - if(watcher) { - contentLayer.watchContentConfig(); - } + const contentLayer = globalContentLayer.init({ + settings, + logger, + store, + watcher, + }); + if (watcher) { + contentLayer.watchContentConfig(); } await contentLayer.sync(); if (!skip?.cleanup) {