From 8a551c1272a22ab7c3fb836d6685a0eb38c33071 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 5 Dec 2024 18:13:36 +0800 Subject: [PATCH] Clean up content layer sync in build and sync api (#12633) --- .changeset/stupid-teachers-yell.md | 5 +++++ packages/astro/src/core/dev/container.ts | 1 + packages/astro/src/core/sync/index.ts | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 .changeset/stupid-teachers-yell.md diff --git a/.changeset/stupid-teachers-yell.md b/.changeset/stupid-teachers-yell.md new file mode 100644 index 000000000000..a00ccceb5603 --- /dev/null +++ b/.changeset/stupid-teachers-yell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Cleans up content layer sync during builds and programmatic `sync()` calls diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 0ca40cd74b3a..063681f2717c 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -120,6 +120,7 @@ export async function createContainer({ logger, skip: { content: true, + cleanup: true, }, force: inlineConfig?.force, manifest, diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 823470e970b1..9e2a2de22d4c 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -45,6 +45,8 @@ export type SyncOptions = { skip?: { // Must be skipped in dev content?: boolean; + // Cleanup can be skipped in dev as some state can be reused on updates + cleanup?: boolean; }; manifest: ManifestData; }; @@ -141,6 +143,10 @@ export async function syncInternal({ store, }); await contentLayer.sync(); + if (!skip?.cleanup) { + // Free up memory (usually in builds since we only need to use this once) + contentLayer.dispose(); + } settings.timer.end('Sync content layer'); } else { const paths = getContentPaths(settings.config, fs);