1
+ /* eslint-disable max-lines */
1
2
import type { NetlifyConfig } from '@netlify/build'
2
3
import destr from 'destr'
3
4
import { readJSON , writeJSON } from 'fs-extra'
@@ -80,7 +81,28 @@ const resolveModuleRoot = (moduleName) => {
80
81
81
82
const DEFAULT_EXCLUDED_MODULES = [ 'sharp' , 'electron' ]
82
83
83
- export const configureHandlerFunctions = async ( { netlifyConfig, publish, ignore = [ ] } ) => {
84
+ export const hasManuallyAddedModule = ( {
85
+ netlifyConfig,
86
+ moduleName,
87
+ } : {
88
+ netlifyConfig : NetlifyConfig
89
+ moduleName : string
90
+ } ) =>
91
+ /* eslint-disable camelcase */
92
+ Object . values ( netlifyConfig . functions ) . some ( ( { included_files = [ ] } ) =>
93
+ included_files . some ( ( inc ) => inc . includes ( `node_modules/${ moduleName } ` ) ) ,
94
+ )
95
+ /* eslint-enable camelcase */
96
+
97
+ export const configureHandlerFunctions = async ( {
98
+ netlifyConfig,
99
+ publish,
100
+ ignore = [ ] ,
101
+ } : {
102
+ netlifyConfig : NetlifyConfig
103
+ publish : string
104
+ ignore : Array < string >
105
+ } ) => {
84
106
const config = await getRequiredServerFiles ( publish )
85
107
const files = config . files || [ ]
86
108
const cssFilesToInclude = files . filter ( ( f ) => f . startsWith ( `${ publish } /static/css/` ) )
@@ -91,6 +113,11 @@ export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore
91
113
netlifyConfig . functions . _ipx . node_bundler = 'nft'
92
114
}
93
115
116
+ // If the user has manually added the module to included_files, then don't exclude it
117
+ const excludedModules = DEFAULT_EXCLUDED_MODULES . filter (
118
+ ( moduleName ) => ! hasManuallyAddedModule ( { netlifyConfig, moduleName } ) ,
119
+ )
120
+
94
121
/* eslint-enable no-underscore-dangle */
95
122
; [ HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , '_api_*' ] . forEach ( ( functionName ) => {
96
123
netlifyConfig . functions [ functionName ] ||= { included_files : [ ] , external_node_modules : [ ] }
@@ -109,6 +136,7 @@ export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore
109
136
`${ publish } /BUILD_ID` ,
110
137
`${ publish } /static/chunks/webpack-middleware*.js` ,
111
138
`!${ publish } /server/**/*.js.nft.json` ,
139
+ '!**/node_modules/@next/swc*/**/*' ,
112
140
...cssFilesToInclude ,
113
141
...ignore . map ( ( path ) => `!${ slash ( path ) } ` ) ,
114
142
)
@@ -123,7 +151,7 @@ export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore
123
151
)
124
152
}
125
153
126
- DEFAULT_EXCLUDED_MODULES . forEach ( ( moduleName ) => {
154
+ excludedModules . forEach ( ( moduleName ) => {
127
155
const moduleRoot = resolveModuleRoot ( moduleName )
128
156
if ( moduleRoot ) {
129
157
netlifyConfig . functions [ functionName ] . included_files . push ( `!${ moduleRoot } /**/*` )
@@ -156,11 +184,11 @@ const buildHeader = (buildHeaderParams: BuildHeaderParams) => {
156
184
const sanitizePath = ( path : string ) => path . replace ( / : [ ^ * / ] + \* $ / , '*' )
157
185
158
186
/**
159
- * Persist NEXT .js custom headers to the Netlify configuration so the headers work with static files
187
+ * Persist Next .js custom headers to the Netlify configuration so the headers work with static files
160
188
* See {@link https://nextjs.org/docs/api-reference/next.config.js/headers} for more information on custom
161
189
* headers in Next.js
162
190
*
163
- * @param nextConfig - The NextJS configuration
191
+ * @param nextConfig - The Next.js configuration
164
192
* @param netlifyHeaders - Existing headers that are already configured in the Netlify configuration
165
193
*/
166
194
export const generateCustomHeaders = ( nextConfig : NextConfig , netlifyHeaders : NetlifyHeaders = [ ] ) => {
@@ -210,3 +238,4 @@ export const generateCustomHeaders = (nextConfig: NextConfig, netlifyHeaders: Ne
210
238
}
211
239
}
212
240
}
241
+ /* eslint-enable max-lines */
0 commit comments