Skip to content

Commit aec7ac2

Browse files
committed
fix lint
1 parent 4817063 commit aec7ac2

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

src/build/advanced-api-routes.ts

+43-43
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,6 @@ interface ApiBackgroundConfig {
3535

3636
type ApiConfig = ApiStandardConfig | ApiScheduledConfig | ApiBackgroundConfig
3737

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-
8138
// Next.js already defines a default `pageExtensions` array in its `required-server-files.json` file
8239
// In case it gets `undefined`, this is a fallback
8340
const SOURCE_FILE_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']
@@ -186,3 +143,46 @@ const extractConfigFromFile = async (apiFilePath: string, appDir: string): Promi
186143
return {}
187144
}
188145
}
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+
}

src/build/content/server.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ function isError(error: unknown): error is NodeJS.ErrnoException {
2929
return error instanceof Error
3030
}
3131

32+
/**
33+
* Generates a copy of the middleware manifest without any middleware in it. We
34+
* do this because we'll run middleware in an edge function, and we don't want
35+
* to run it again in the server handler.
36+
*/
37+
const replaceMiddlewareManifest = async (sourcePath: string, destPath: string) => {
38+
await mkdir(dirname(destPath), { recursive: true })
39+
40+
const data = await readFile(sourcePath, 'utf8')
41+
const manifest = JSON.parse(data)
42+
43+
// TODO: Check for `manifest.version` and write an error to the system log
44+
// when we find a value that is not equal to 2. This will alert us in case
45+
// Next.js starts using a new format for the manifest and we're writing
46+
// one with the old version.
47+
const newManifest = {
48+
...manifest,
49+
middleware: {},
50+
}
51+
const newData = JSON.stringify(newManifest)
52+
53+
await writeFile(destPath, newData)
54+
}
55+
3256
/**
3357
* Copy App/Pages Router Javascript needed by the server handler
3458
*/
@@ -311,30 +335,6 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
311335
})
312336
}
313337

314-
/**
315-
* Generates a copy of the middleware manifest without any middleware in it. We
316-
* do this because we'll run middleware in an edge function, and we don't want
317-
* to run it again in the server handler.
318-
*/
319-
const replaceMiddlewareManifest = async (sourcePath: string, destPath: string) => {
320-
await mkdir(dirname(destPath), { recursive: true })
321-
322-
const data = await readFile(sourcePath, 'utf8')
323-
const manifest = JSON.parse(data)
324-
325-
// TODO: Check for `manifest.version` and write an error to the system log
326-
// when we find a value that is not equal to 2. This will alert us in case
327-
// Next.js starts using a new format for the manifest and we're writing
328-
// one with the old version.
329-
const newManifest = {
330-
...manifest,
331-
middleware: {},
332-
}
333-
const newData = JSON.stringify(newManifest)
334-
335-
await writeFile(destPath, newData)
336-
}
337-
338338
export const verifyHandlerDirStructure = async (ctx: PluginContext) => {
339339
const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), 'utf-8'))
340340

src/build/functions/edge.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const augmentMatchers = (
5353
})
5454
}
5555

56+
const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
57+
`${EDGE_HANDLER_NAME}-${name.replace(/\W/g, '-')}`
58+
5659
const writeHandlerFile = async (ctx: PluginContext, { matchers, name, page }: NextDefinition) => {
5760
const nextConfig = ctx.buildConfig
5861
const handlerName = getHandlerName({ name })
@@ -149,9 +152,6 @@ const createEdgeHandler = async (ctx: PluginContext, definition: NextDefinition)
149152
await writeHandlerFile(ctx, definition)
150153
}
151154

152-
const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
153-
`${EDGE_HANDLER_NAME}-${name.replace(/\W/g, '-')}`
154-
155155
const buildHandlerDefinition = (
156156
ctx: PluginContext,
157157
{ name, matchers, page }: NextDefinition,

0 commit comments

Comments
 (0)