From 2677acc67409f7cecb51ecc2de5ef1417c9caeaf Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 16 Nov 2024 12:54:38 +0100 Subject: [PATCH] fix(next): #397 double execution if next.config.ts is used on canary Closes: #397 --- .changeset/odd-bikes-rule.md | 5 +++++ packages/next/src/index.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/odd-bikes-rule.md diff --git a/.changeset/odd-bikes-rule.md b/.changeset/odd-bikes-rule.md new file mode 100644 index 00000000..d6177e1e --- /dev/null +++ b/.changeset/odd-bikes-rule.md @@ -0,0 +1,5 @@ +--- +"@content-collections/next": patch +--- + +Fix double execution if next.config.ts is used on canary #397 diff --git a/packages/next/src/index.ts b/packages/next/src/index.ts index 28321cd7..26d0d378 100644 --- a/packages/next/src/index.ts +++ b/packages/next/src/index.ts @@ -9,8 +9,9 @@ const defaultOptions: Options = { configPath: "content-collections.ts", }; +const initializedState: Record = {}; + export function createContentCollectionPlugin(pluginOptions: Options) { - let initialized = false; return async ( nextConfig: Partial | Promise> = {}, ): Promise> => { @@ -18,11 +19,13 @@ export function createContentCollectionPlugin(pluginOptions: Options) { .slice(2) .filter((arg) => !arg.startsWith("-")); if (command === "build" || command === "dev") { + const initialized = initializedState[pluginOptions.configPath]; + if (initialized) { return nextConfig; } - initialized = true; + initializedState[pluginOptions.configPath] = true; const { createBuilder } = await import("@content-collections/core");