@@ -35,49 +35,6 @@ interface ApiBackgroundConfig {
35
35
36
36
type ApiConfig = ApiStandardConfig | ApiScheduledConfig | ApiBackgroundConfig
37
37
38
- export async function getAPIRoutesConfigs ( ctx : PluginContext ) {
39
- const functionsConfigManifestPath = join (
40
- ctx . publishDir ,
41
- 'server' ,
42
- 'functions-config-manifest.json' ,
43
- )
44
- if ( ! existsSync ( functionsConfigManifestPath ) ) {
45
- // before https://github.com/vercel/next.js/pull/60163 this file might not have been produced if there were no API routes at all
46
- return [ ]
47
- }
48
-
49
- const functionsConfigManifest = JSON . parse (
50
- await readFile ( functionsConfigManifestPath , 'utf-8' ) ,
51
- ) as FunctionsConfigManifest
52
-
53
- const appDir = ctx . resolveFromSiteDir ( '.' )
54
- const pagesDir = join ( appDir , 'pages' )
55
- const srcPagesDir = join ( appDir , 'src' , 'pages' )
56
- const { pageExtensions } = ctx . requiredServerFiles . config
57
-
58
- return Promise . all (
59
- Object . keys ( functionsConfigManifest . functions ) . map ( async ( apiRoute ) => {
60
- const filePath = getSourceFileForPage ( apiRoute , [ pagesDir , srcPagesDir ] , pageExtensions )
61
-
62
- const sharedFields = {
63
- apiRoute,
64
- filePath,
65
- config : { } as ApiConfig ,
66
- }
67
-
68
- if ( filePath ) {
69
- const config = await extractConfigFromFile ( filePath , appDir )
70
- return {
71
- ...sharedFields ,
72
- config,
73
- }
74
- }
75
-
76
- return sharedFields
77
- } ) ,
78
- )
79
- }
80
-
81
38
// Next.js already defines a default `pageExtensions` array in its `required-server-files.json` file
82
39
// In case it gets `undefined`, this is a fallback
83
40
const SOURCE_FILE_EXTENSIONS = [ 'js' , 'jsx' , 'ts' , 'tsx' ]
@@ -186,3 +143,46 @@ const extractConfigFromFile = async (apiFilePath: string, appDir: string): Promi
186
143
return { }
187
144
}
188
145
}
146
+
147
+ export async function getAPIRoutesConfigs ( ctx : PluginContext ) {
148
+ const functionsConfigManifestPath = join (
149
+ ctx . publishDir ,
150
+ 'server' ,
151
+ 'functions-config-manifest.json' ,
152
+ )
153
+ if ( ! existsSync ( functionsConfigManifestPath ) ) {
154
+ // before https://github.com/vercel/next.js/pull/60163 this file might not have been produced if there were no API routes at all
155
+ return [ ]
156
+ }
157
+
158
+ const functionsConfigManifest = JSON . parse (
159
+ await readFile ( functionsConfigManifestPath , 'utf-8' ) ,
160
+ ) as FunctionsConfigManifest
161
+
162
+ const appDir = ctx . resolveFromSiteDir ( '.' )
163
+ const pagesDir = join ( appDir , 'pages' )
164
+ const srcPagesDir = join ( appDir , 'src' , 'pages' )
165
+ const { pageExtensions } = ctx . requiredServerFiles . config
166
+
167
+ return Promise . all (
168
+ Object . keys ( functionsConfigManifest . functions ) . map ( async ( apiRoute ) => {
169
+ const filePath = getSourceFileForPage ( apiRoute , [ pagesDir , srcPagesDir ] , pageExtensions )
170
+
171
+ const sharedFields = {
172
+ apiRoute,
173
+ filePath,
174
+ config : { } as ApiConfig ,
175
+ }
176
+
177
+ if ( filePath ) {
178
+ const config = await extractConfigFromFile ( filePath , appDir )
179
+ return {
180
+ ...sharedFields ,
181
+ config,
182
+ }
183
+ }
184
+
185
+ return sharedFields
186
+ } ) ,
187
+ )
188
+ }
0 commit comments