Skip to content

Commit

Permalink
fix(next): #397 double execution if next.config.ts is used on canary
Browse files Browse the repository at this point in the history
Closes: #397
  • Loading branch information
sdorra committed Nov 16, 2024
1 parent 070f9d4 commit 2677acc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-bikes-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@content-collections/next": patch
---

Fix double execution if next.config.ts is used on canary #397
7 changes: 5 additions & 2 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ const defaultOptions: Options = {
configPath: "content-collections.ts",
};

const initializedState: Record<string, boolean> = {};

export function createContentCollectionPlugin(pluginOptions: Options) {
let initialized = false;
return async (
nextConfig: Partial<NextConfig> | Promise<Partial<NextConfig>> = {},
): Promise<Partial<NextConfig>> => {
const [command] = process.argv
.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");

Expand Down

0 comments on commit 2677acc

Please sign in to comment.