1- const { copyFile, ensureDir, writeFile, writeJSON } = require ( 'fs-extra' )
2- const { join, relative } = require ( 'pathe' )
1+ import { NetlifyConfig , NetlifyPluginConstants } from '@netlify/build'
2+ import { copyFile , ensureDir , writeFile , writeJSON } from 'fs-extra'
3+ import type { ImageConfigComplete } from 'next/dist/server/image-config'
4+ import { join , relative } from 'pathe'
35
4- const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME } = require ( '../constants' )
5- const getHandler = require ( '../templates/getHandler' )
6- const { getPageResolver } = require ( '../templates/getPageResolver' )
6+ import { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME , DEFAULT_FUNCTIONS_SRC } from '../constants'
7+ import getHandler from '../templates/getHandler'
8+ import { getPageResolver } from '../templates/getPageResolver'
79
8- const DEFAULT_FUNCTIONS_SRC = 'netlify/functions'
9-
10- exports . generateFunctions = async (
11- { FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , PUBLISH_DIR } ,
12- appDir ,
13- ) => {
10+ export const generateFunctions = async (
11+ { FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , PUBLISH_DIR } : NetlifyPluginConstants ,
12+ appDir : string ,
13+ ) : Promise < void > => {
1414 const functionsDir = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
1515 const bridgeFile = require . resolve ( '@vercel/node/dist/bridge' )
1616
1717 const functionDir = join ( process . cwd ( ) , functionsDir , HANDLER_FUNCTION_NAME )
1818 const publishDir = relative ( functionDir , join ( process . cwd ( ) , PUBLISH_DIR ) )
1919
20- const writeHandler = async ( func , isODB ) => {
20+ const writeHandler = async ( func : string , isODB : boolean ) => {
2121 const handlerSource = await getHandler ( { isODB, publishDir, appDir : relative ( functionDir , appDir ) } )
2222 await ensureDir ( join ( functionsDir , func ) )
2323 await writeFile ( join ( functionsDir , func , `${ func } .js` ) , handlerSource )
@@ -36,11 +36,15 @@ exports.generateFunctions = async (
3636 * Writes a file in each function directory that contains references to every page entrypoint.
3737 * This is just so that the nft bundler knows about them. We'll eventually do this better.
3838 */
39- exports . generatePagesResolver = async ( {
39+ export const generatePagesResolver = async ( {
4040 constants : { INTERNAL_FUNCTIONS_SRC , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
4141 netlifyConfig,
4242 target,
43- } ) => {
43+ } : {
44+ constants : NetlifyPluginConstants
45+ netlifyConfig : NetlifyConfig
46+ target : string
47+ } ) : Promise < void > => {
4448 const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
4549
4650 const jsSource = await getPageResolver ( {
@@ -53,12 +57,17 @@ exports.generatePagesResolver = async ({
5357}
5458
5559// Move our next/image function into the correct functions directory
56- exports . setupImageFunction = async ( {
60+ export const setupImageFunction = async ( {
5761 constants : { INTERNAL_FUNCTIONS_SRC , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
5862 imageconfig = { } ,
5963 netlifyConfig,
6064 basePath,
61- } ) => {
65+ } : {
66+ constants : NetlifyPluginConstants
67+ netlifyConfig : NetlifyConfig
68+ basePath : string
69+ imageconfig : Partial < ImageConfigComplete >
70+ } ) : Promise < void > => {
6271 const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
6372 const functionName = `${ IMAGE_FUNCTION_NAME } .js`
6473 const functionDirectory = join ( functionsPath , IMAGE_FUNCTION_NAME )
0 commit comments