11/* eslint-disable max-lines */
22
3- const { yellowBright } = require ( 'chalk' )
4- const { readJSON, existsSync } = require ( 'fs-extra' )
5- const { outdent } = require ( 'outdent' )
6- const { join, dirname, relative } = require ( 'pathe' )
7- const slash = require ( 'slash' )
3+ import { NetlifyConfig } from '@netlify/build'
4+ import { yellowBright } from 'chalk'
5+ import { readJSON } from 'fs-extra'
6+ import { PrerenderManifest } from 'next/dist/build'
7+ import { outdent } from 'outdent'
8+ import { join , dirname , relative } from 'pathe'
9+ import slash from 'slash'
810
9- const defaultFailBuild = ( message , { error } ) => {
11+ import { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , HIDDEN_PATHS } from '../constants'
12+
13+ import { RequiredServerFiles } from './requiredServerFilesType'
14+
15+ const defaultFailBuild = ( message : string , { error } ) : never => {
1016 throw new Error ( `${ message } \n${ error && error . stack } ` )
1117}
1218
13- const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , HIDDEN_PATHS } = require ( '../constants' )
14-
1519const ODB_FUNCTION_PATH = `/.netlify/builders/${ ODB_FUNCTION_NAME } `
1620const HANDLER_FUNCTION_PATH = `/.netlify/functions/${ HANDLER_FUNCTION_NAME } `
1721
1822const CATCH_ALL_REGEX = / \/ \[ \. { 3 } ( .* ) ] ( .j s o n ) ? $ /
1923const OPTIONAL_CATCH_ALL_REGEX = / \/ \[ { 2 } \. { 3 } ( .* ) ] { 2 } ( .j s o n ) ? $ /
2024const DYNAMIC_PARAMETER_REGEX = / \/ \[ ( .* ?) ] / g
2125
22- const getNetlifyRoutes = ( nextRoute ) => {
26+ const getNetlifyRoutes = ( nextRoute : string ) : Array < string > => {
2327 let netlifyRoutes = [ nextRoute ]
2428
2529 // If the route is an optional catch-all route, we need to add a second
@@ -54,8 +58,12 @@ const getNetlifyRoutes = (nextRoute) => {
5458 return netlifyRoutes
5559}
5660
57- exports . generateRedirects = async ( { netlifyConfig, basePath, i18n } ) => {
58- const { dynamicRoutes, routes : staticRoutes } = await readJSON (
61+ export const generateRedirects = async ( { netlifyConfig, basePath, i18n } : {
62+ netlifyConfig : NetlifyConfig ,
63+ basePath : string ,
64+ i18n
65+ } ) => {
66+ const { dynamicRoutes, routes : staticRoutes } : PrerenderManifest = await readJSON (
5967 join ( netlifyConfig . build . publish , 'prerender-manifest.json' ) ,
6068 )
6169
@@ -123,6 +131,8 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
123131 from : `${ basePath } /*` ,
124132 to : HANDLER_FUNCTION_PATH ,
125133 status : 200 ,
134+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
135+ // @ts -ignore
126136 conditions : { Cookie : [ '__prerender_bypass' , '__next_preview_data' ] } ,
127137 force : true ,
128138 } ,
@@ -158,14 +168,16 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
158168 }
159169}
160170
161- exports . getNextConfig = async function getNextConfig ( { publish, failBuild = defaultFailBuild } ) {
171+ export const getNextConfig = async function getNextConfig ( { publish, failBuild = defaultFailBuild } ) {
162172 try {
163- const { config, appDir, ignore } = await readJSON ( join ( publish , 'required-server-files.json' ) )
173+ const { config, appDir, ignore } : RequiredServerFiles = await readJSON ( join ( publish , 'required-server-files.json' ) )
164174 if ( ! config ) {
175+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
176+ // @ts -ignore
165177 return failBuild ( 'Error loading your Next config' )
166178 }
167179 return { ...config , appDir, ignore }
168- } catch ( error ) {
180+ } catch ( error : unknown ) {
169181 return failBuild ( 'Error loading your Next config' , { error } )
170182 }
171183}
@@ -180,7 +192,7 @@ const resolveModuleRoot = (moduleName) => {
180192
181193const DEFAULT_EXCLUDED_MODULES = [ 'sharp' , 'electron' ]
182194
183- exports . configureHandlerFunctions = ( { netlifyConfig, publish, ignore = [ ] } ) => {
195+ export const configureHandlerFunctions = ( { netlifyConfig, publish, ignore = [ ] } ) => {
184196 /* eslint-disable no-underscore-dangle */
185197 netlifyConfig . functions . _ipx ||= { }
186198 netlifyConfig . functions . _ipx . node_bundler = 'nft'
0 commit comments