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");