Skip to content

Commit 4d4cad6

Browse files
committed
fix: use typed inline configs for produced functions
1 parent 1062a41 commit 4d4cad6

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/adapter/build/middleware.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { cp, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
22
import { dirname, join, parse, relative } from 'node:path/posix'
33

4+
import type { IntegrationsConfig } from '@netlify/edge-functions'
45
import { glob } from 'fast-glob'
56
import { pathToRegexp } from 'path-to-regexp'
67

@@ -183,6 +184,13 @@ const writeHandlerFile = async (
183184
),
184185
)
185186

187+
const functionConfig = {
188+
cache: undefined,
189+
generator: GENERATOR,
190+
name: DISPLAY_NAME_MIDDLEWARE,
191+
pattern: augmentMatchers(middleware, nextConfig).map((matcher) => matcher.regexp),
192+
} satisfies IntegrationsConfig
193+
186194
// Writing the function entry file. It wraps the middleware code with the
187195
// compatibility layer mentioned above.
188196
await writeFile(
@@ -198,12 +206,7 @@ const writeHandlerFile = async (
198206
199207
export default (req, context) => handleMiddleware(req, context, handler);
200208
201-
export const config = ${JSON.stringify({
202-
cache: undefined,
203-
generator: GENERATOR,
204-
name: DISPLAY_NAME_MIDDLEWARE,
205-
pattern: augmentMatchers(middleware, nextConfig).map((matcher) => matcher.regexp),
206-
})}
209+
export const config = ${JSON.stringify(functionConfig, null, 2)}
207210
`,
208211
)
209212
}

src/adapter/build/pages-and-app-handlers.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { cp, mkdir, writeFile } from 'node:fs/promises'
22
import { join, relative } from 'node:path/posix'
33

4+
import type { InSourceConfig } from '@netlify/zip-it-and-ship-it/dist/runtimes/node/in_source_config/index.js'
45
import { glob } from 'fast-glob'
56

67
import {
@@ -81,7 +82,13 @@ export async function onBuildComplete(
8182

8283
await copyRuntime(join(PAGES_AND_APP_FUNCTION_DIR, RUNTIME_DIR))
8384

84-
const functionsPaths = Object.keys(pathnameToEntry)
85+
const functionConfig = {
86+
path: Object.keys(pathnameToEntry),
87+
nodeBundler: 'none',
88+
includedFiles: ['**'],
89+
generator: GENERATOR,
90+
name: DISPLAY_NAME_PAGES_AND_APP,
91+
} as const satisfies InSourceConfig
8592

8693
// generate needed runtime files
8794
const entrypoint = /* javascript */ `
@@ -108,27 +115,14 @@ export async function onBuildComplete(
108115
return runNextHandler(request, context, nextHandler)
109116
}
110117
111-
export const config = {
112-
113-
path: ${JSON.stringify(functionsPaths, null, 2)},
114-
}
118+
export const config = ${JSON.stringify(functionConfig, null, 2)}
115119
`
116120
await writeFile(
117121
join(PAGES_AND_APP_FUNCTION_DIR, `${PAGES_AND_APP_FUNCTION_INTERNAL_NAME}.mjs`),
118122
entrypoint,
119123
)
120124

121-
// configuration
122-
netlifyAdapterContext.frameworksAPIConfig ??= {}
123-
netlifyAdapterContext.frameworksAPIConfig.functions ??= { '*': {} }
124-
netlifyAdapterContext.frameworksAPIConfig.functions[PAGES_AND_APP_FUNCTION_INTERNAL_NAME] = {
125-
node_bundler: 'none',
126-
included_files: ['**'],
127-
// TODO(pieh): below only works due to local patches, need to ship proper support
128-
included_files_base_path: PAGES_AND_APP_FUNCTION_DIR,
129-
}
130-
131-
netlifyAdapterContext.preparedOutputs.endpoints.push(...functionsPaths)
125+
netlifyAdapterContext.preparedOutputs.endpoints.push(...functionConfig.path)
132126
}
133127

134128
const copyRuntime = async (handlerDirectory: string): Promise<void> => {

0 commit comments

Comments
 (0)