@@ -2,6 +2,7 @@ import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
2
2
import bridgeFile from '@vercel/node-bridge'
3
3
import chalk from 'chalk'
4
4
import destr from 'destr'
5
+ import { resolveModuleRoot } from './config'
5
6
import { copyFile , ensureDir , existsSync , readJSON , writeFile , writeJSON } from 'fs-extra'
6
7
import type { ImageConfigComplete , RemotePattern } from 'next/dist/shared/lib/image-config'
7
8
import { outdent } from 'outdent'
@@ -34,16 +35,21 @@ export interface ApiRouteConfig {
34
35
35
36
const checkForPackage = async ( packageDir : string , nodeModule : boolean ) => {
36
37
const packagePlugin = existsSync ( packageDir ) ? await readJSON ( packageDir ) : null
37
- const nextPlugin =
38
- ! nodeModule && packagePlugin . dependencies [ NEXT_PLUGIN ] ? packagePlugin . dependencies [ NEXT_PLUGIN ] : null
39
- const checkModule = nodeModule && packagePlugin ?. version ? packagePlugin . version : null
38
+ let nextPlugin
39
+ if ( ! nodeModule && packagePlugin ) {
40
+ nextPlugin = packagePlugin . dependencies [ NEXT_PLUGIN ] ? packagePlugin . dependencies [ NEXT_PLUGIN ] : null
41
+ } else if ( nodeModule && packagePlugin ) {
42
+ nextPlugin = packagePlugin . version ? packagePlugin . version : null
43
+ }
40
44
41
- return checkModule || nextPlugin
45
+ return nextPlugin
42
46
}
43
47
44
48
const writeFunctionConfiguration = async ( functionName : string , functionTitle : string , functionsDir : string ) => {
45
49
const pluginPackagePath = '.netlify/plugins/package.json'
46
- const nodeModulesPath = join ( 'node_modules' , NEXT_PLUGIN , 'package.json' )
50
+ const ProjDir = resolveModuleRoot ( NEXT_PLUGIN )
51
+ const nodeModulesPath = `${ ProjDir } /package.json`
52
+
47
53
const nextPluginVersion =
48
54
( await checkForPackage ( nodeModulesPath , true ) ) || ( await checkForPackage ( pluginPackagePath , false ) )
49
55
0 commit comments