Skip to content

Commit 33e506b

Browse files
committed
using resolvemoduleroot to access correct package
1 parent 8982ab6 commit 33e506b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/runtime/src/helpers/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const updateRequiredServerFiles = async (publish: string, modifiedConfig:
7171
await writeJSON(configFile, modifiedConfig)
7272
}
7373

74-
const resolveModuleRoot = (moduleName) => {
74+
export const resolveModuleRoot = (moduleName) => {
7575
try {
7676
return dirname(relative(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths: [process.cwd()] })))
7777
} catch {

packages/runtime/src/helpers/functions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
22
import bridgeFile from '@vercel/node-bridge'
33
import chalk from 'chalk'
44
import destr from 'destr'
5+
import { resolveModuleRoot } from './config'
56
import { copyFile, ensureDir, existsSync, readJSON, writeFile, writeJSON } from 'fs-extra'
67
import type { ImageConfigComplete, RemotePattern } from 'next/dist/shared/lib/image-config'
78
import { outdent } from 'outdent'
@@ -34,16 +35,21 @@ export interface ApiRouteConfig {
3435

3536
const checkForPackage = async (packageDir: string, nodeModule: boolean) => {
3637
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+
}
4044

41-
return checkModule || nextPlugin
45+
return nextPlugin
4246
}
4347

4448
const writeFunctionConfiguration = async (functionName: string, functionTitle: string, functionsDir: string) => {
4549
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+
4753
const nextPluginVersion =
4854
(await checkForPackage(nodeModulesPath, true)) || (await checkForPackage(pluginPackagePath, false))
4955

0 commit comments

Comments
 (0)