@@ -22,8 +22,7 @@ const PAGES_AND_APP_FUNCTION_DIR = join(
2222
2323export async function onBuildComplete (
2424 nextAdapterContext : OnBuildCompleteContext ,
25- // eslint-disable-next-line @typescript-eslint/no-unused-vars
26- _netlifyAdapterContext : NetlifyAdapterContext ,
25+ netlifyAdapterContext : NetlifyAdapterContext ,
2726) {
2827 const requiredFiles = new Set < string > ( )
2928 const pathnameToEntry : Record < string , string > = { }
@@ -66,68 +65,55 @@ export async function onBuildComplete(
6665
6766 await copyRuntime ( join ( PAGES_AND_APP_FUNCTION_DIR , RUNTIME_DIR ) )
6867
68+ const functionsPaths = Object . keys ( pathnameToEntry )
69+
6970 // generate needed runtime files
7071 const entrypoint = /* javascript */ `
71- import { AsyncLocalStorage } from 'node:async_hooks'
72- import { createRequire } from 'node:module'
73- import { runNextHandler } from './${ RUNTIME_DIR } /dist/adapter/run/pages-and-app-handler.js'
72+ import { AsyncLocalStorage } from 'node:async_hooks'
73+ import { createRequire } from 'node:module'
74+ import { runNextHandler } from './${ RUNTIME_DIR } /dist/adapter/run/pages-and-app-handler.js'
7475
75- globalThis.AsyncLocalStorage = AsyncLocalStorage
76+ globalThis.AsyncLocalStorage = AsyncLocalStorage
7677
77- const require = createRequire(import.meta.url)
78+ const require = createRequire(import.meta.url)
7879
79- const pathnameToEntry = ${ JSON . stringify ( pathnameToEntry , null , 2 ) }
80+ const pathnameToEntry = ${ JSON . stringify ( pathnameToEntry , null , 2 ) }
8081
81- export default async function handler(request, context) {
82- const url = new URL(request.url)
82+ export default async function handler(request, context) {
83+ const url = new URL(request.url)
8384
84- const entry = pathnameToEntry[url.pathname]
85- if (!entry) {
86- return new Response('Not Found', { status: 404 })
87- }
85+ const entry = pathnameToEntry[url.pathname]
86+ if (!entry) {
87+ return new Response('Not Found', { status: 404 })
88+ }
8889
89- const nextHandler = require('./' + entry).handler
90+ const nextHandler = require('./' + entry).handler
9091
91- return runNextHandler(request, context, nextHandler)
92- }
92+ return runNextHandler(request, context, nextHandler)
93+ }
9394
94- export const config = {
95-
96- path: ${ JSON . stringify ( Object . keys ( pathnameToEntry ) , null , 2 ) } ,
97- }
95+ export const config = {
96+
97+ path: ${ JSON . stringify ( functionsPaths , null , 2 ) } ,
98+ }
9899 `
99100 await writeFile (
100101 join ( PAGES_AND_APP_FUNCTION_DIR , `${ PAGES_AND_APP_FUNCTION_INTERNAL_NAME } .mjs` ) ,
101102 entrypoint ,
102103 )
103104
104105 // configuration
105- // TODO: ideally allow to set `includedFilesBasePath` via frameworks api config
106- // frameworksAPIConfig.functions ??= { '*': {} }
107- // frameworksAPIConfig.functions[PAGES_AND_APP_FUNCTION_INTERNAL_NAME] = {
108- // node_bundler: 'none',
109- // included_files: ['**'],
110- // // we can't define includedFilesBasePath via Frameworks API
111- // // included_files_base_path: PAGES_AND_APP_FUNCTION_DIR,
112- // }
113-
114- // not using frameworks api because ... it doesn't allow to set includedFilesBasePath
115- await writeFile (
116- join ( PAGES_AND_APP_FUNCTION_DIR , `${ PAGES_AND_APP_FUNCTION_INTERNAL_NAME } .json` ) ,
117- JSON . stringify (
118- {
119- config : {
120- name : DISPLAY_NAME_PAGES_AND_APP ,
121- generator : GENERATOR ,
122- node_bundler : 'none' ,
123- included_files : [ '**' ] ,
124- includedFilesBasePath : PAGES_AND_APP_FUNCTION_DIR ,
125- } ,
126- } ,
127- null ,
128- 2 ,
129- ) ,
130- )
106+ netlifyAdapterContext . frameworksAPIConfig ??= { }
107+ netlifyAdapterContext . frameworksAPIConfig . functions ??= { '*' : { } }
108+ netlifyAdapterContext . frameworksAPIConfig . functions [ PAGES_AND_APP_FUNCTION_INTERNAL_NAME ] = {
109+ node_bundler : 'none' ,
110+ included_files : [ '**' ] ,
111+ // TODO(pieh): allow to set `includedFilesBasePath` via frameworks api config
112+ // @ts -expect-error we can't define includedFilesBasePath via Frameworks API, this only works because of local monkey patching of CLI
113+ included_files_base_path : PAGES_AND_APP_FUNCTION_DIR ,
114+ }
115+
116+ netlifyAdapterContext . preparedOutputs . endpoints . push ( ...functionsPaths )
131117}
132118
133119const copyRuntime = async ( handlerDirectory : string ) : Promise < void > => {
0 commit comments