From 61996ed738df20fbc1eb9a469a38a6f239692a20 Mon Sep 17 00:00:00 2001 From: Sam Brodie Date: Wed, 7 Aug 2024 09:09:59 -0400 Subject: [PATCH] fix: use next/package.json instead of project dependencies --- packages/next/src/config/withHeadstartWPConfig.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/next/src/config/withHeadstartWPConfig.ts b/packages/next/src/config/withHeadstartWPConfig.ts index cb4e1cacf..632deb2cc 100644 --- a/packages/next/src/config/withHeadstartWPConfig.ts +++ b/packages/next/src/config/withHeadstartWPConfig.ts @@ -1,12 +1,13 @@ import { ConfigError, HeadlessConfig } from '@headstartwp/core'; import { NextConfig } from 'next'; import fs from 'fs'; -import path from 'path'; import { ModifySourcePlugin, ConcatOperation } from './plugins/ModifySourcePlugin'; -// Get the path to the project's root package.json -const packageJsonPath = path.join(process.cwd(), 'package.json'); -const packageJson = packageJsonPath ? JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) : {}; +// Use require.resolve to get the path to the package.json +const nextPackageJsonPath = require.resolve('next/package.json'); +const nextPackageJson = nextPackageJsonPath + ? JSON.parse(fs.readFileSync(nextPackageJsonPath, 'utf8')) + : {}; type RemotePattern = { protocol?: 'http' | 'https'; @@ -148,7 +149,7 @@ export function withHeadstartWPConfig( } }); - const useImageRemotePatterns = meetsMinimumVersion(packageJson?.dependencies?.next, 14); + const useImageRemotePatterns = meetsMinimumVersion(nextPackageJson?.version, 14); const imageConfig: { domains?: string[]; remotePatterns?: RemotePattern[] } = {}; if (useImageRemotePatterns) {