@@ -2,7 +2,6 @@ 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'
6
5
import { copyFile , ensureDir , existsSync , readJSON , writeFile , writeJSON } from 'fs-extra'
7
6
import type { ImageConfigComplete , RemotePattern } from 'next/dist/shared/lib/image-config'
8
7
import { outdent } from 'outdent'
@@ -13,8 +12,6 @@ import {
13
12
ODB_FUNCTION_NAME ,
14
13
IMAGE_FUNCTION_NAME ,
15
14
DEFAULT_FUNCTIONS_SRC ,
16
- NEXT_PLUGIN ,
17
- NEXT_PLUGIN_NAME ,
18
15
HANDLER_FUNCTION_TITLE ,
19
16
ODB_FUNCTION_TITLE ,
20
17
IMAGE_FUNCTION_TITLE ,
@@ -25,6 +22,7 @@ import { getResolverForPages, getResolverForSourceFiles } from '../templates/get
25
22
26
23
import { ApiConfig , ApiRouteType , extractConfigFromFile } from './analysis'
27
24
import { getSourceFileForPage } from './files'
25
+ import { writeFunctionConfiguration } from './utilities/functions'
28
26
import { getFunctionNameForPage } from './utils'
29
27
30
28
export interface ApiRouteConfig {
@@ -33,37 +31,6 @@ export interface ApiRouteConfig {
33
31
compiled : string
34
32
}
35
33
36
- const checkForPackage = async ( packageDir : string , nodeModule : boolean ) => {
37
- const packagePlugin = existsSync ( packageDir ) ? await readJSON ( packageDir ) : 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
- }
44
-
45
- return nextPlugin
46
- }
47
-
48
- const writeFunctionConfiguration = async ( functionName : string , functionTitle : string , functionsDir : string ) => {
49
- const pluginPackagePath = '.netlify/plugins/package.json'
50
- const ProjDir = resolveModuleRoot ( NEXT_PLUGIN )
51
- const nodeModulesPath = `${ ProjDir } /package.json`
52
-
53
- const nextPluginVersion =
54
- ( await checkForPackage ( nodeModulesPath , true ) ) || ( await checkForPackage ( pluginPackagePath , false ) )
55
-
56
- const metadata = {
57
- config : {
58
- name : functionTitle ,
59
- generator : nextPluginVersion ? `${ NEXT_PLUGIN_NAME } @${ nextPluginVersion } ` : 'Next Runtime Version Not Found' ,
60
- } ,
61
- version : 1 ,
62
- }
63
-
64
- await writeFile ( join ( functionsDir , functionName , `${ functionName } .json` ) , JSON . stringify ( metadata ) )
65
- }
66
-
67
34
export const generateFunctions = async (
68
35
{ FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , PUBLISH_DIR } : NetlifyPluginConstants ,
69
36
appDir : string ,
0 commit comments