Skip to content

Commit 5064473

Browse files
committed
fix: check for version in node modules instead of package
1 parent 528832a commit 5064473

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/runtime/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const HANDLER_FUNCTION_NAME = '___netlify-handler'
22
export const ODB_FUNCTION_NAME = '___netlify-odb-handler'
33
export const IMAGE_FUNCTION_NAME = '_ipx'
44
export const NEXT_PLUGIN_NAME = '@netlify/next-runtime'
5+
export const NEXT_PLUGIN = '@netlify/plugin-nextjs'
56
export const HANDLER_FUNCTION_TITLE = 'Next.js SSR handler'
67
export const ODB_FUNCTION_TITLE = 'Next.js ISR handler'
78
export const IMAGE_FUNCTION_TITLE = "'next/image handler'"

packages/runtime/src/helpers/functions.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ODB_FUNCTION_NAME,
1313
IMAGE_FUNCTION_NAME,
1414
DEFAULT_FUNCTIONS_SRC,
15+
NEXT_PLUGIN,
1516
NEXT_PLUGIN_NAME,
1617
HANDLER_FUNCTION_TITLE,
1718
ODB_FUNCTION_TITLE,
@@ -31,17 +32,20 @@ export interface ApiRouteConfig {
3132
compiled: string
3233
}
3334

34-
const checkForPackage = async (packageDir: string) => {
35+
const checkForPackage = async (packageDir: string, nodeModule: boolean) => {
3536
const packagePlugin = existsSync(packageDir) ? await readJSON(packageDir) : null
36-
const nextPlugin = packagePlugin ? packagePlugin.dependencies['@netlify/plugin-nextjs'] : null
37-
return nextPlugin
37+
const nextPlugin =
38+
packagePlugin?.dependencies[NEXT_PLUGIN] && !nodeModule ? packagePlugin.dependencies[NEXT_PLUGIN] : null
39+
const checkModule = packagePlugin && nodeModule ? packagePlugin.version : null
40+
41+
return checkModule || nextPlugin
3842
}
3943

4044
const writeFunctionConfiguration = async (functionName: string, functionTitle: string, functionsDir: string) => {
4145
const pluginPackagePath = '.netlify/plugins/package.json'
42-
const depsPackagePath = './package.json'
43-
44-
const nextPluginVersion = (await checkForPackage(pluginPackagePath)) || (await checkForPackage(depsPackagePath))
46+
const nodeModulesPath = join('node_modules', NEXT_PLUGIN, 'package.json')
47+
const nextPluginVersion =
48+
(await checkForPackage(nodeModulesPath, true)) || (await checkForPackage(pluginPackagePath, false))
4549

4650
const metadata = {
4751
config: {

0 commit comments

Comments
 (0)