@@ -241,108 +241,114 @@ const validateUserOptions = (pluginOptions, reporter) => headers => {
241
241
return headers
242
242
}
243
243
244
- const mapUserLinkHeaders = ( {
245
- manifest,
246
- pathPrefix,
247
- publicFolder,
248
- } ) => headers =>
249
- _ . mapValues ( headers , headerList =>
250
- _ . map ( headerList , transformLink ( manifest , publicFolder , pathPrefix ) )
251
- )
252
-
253
- const mapUserLinkAllPageHeaders = (
254
- pluginData ,
255
- { allPageHeaders }
256
- ) => headers => {
257
- if ( ! allPageHeaders ) {
258
- return headers
259
- }
244
+ const mapUserLinkHeaders =
245
+ ( { manifest, pathPrefix, publicFolder } ) =>
246
+ headers =>
247
+ _ . mapValues ( headers , headerList =>
248
+ _ . map ( headerList , transformLink ( manifest , publicFolder , pathPrefix ) )
249
+ )
260
250
261
- const { pages, manifest, publicFolder, pathPrefix } = pluginData
251
+ const mapUserLinkAllPageHeaders =
252
+ ( pluginData , { allPageHeaders } ) =>
253
+ headers => {
254
+ if ( ! allPageHeaders ) {
255
+ return headers
256
+ }
262
257
263
- const headersList = _ . map (
264
- allPageHeaders ,
265
- transformLink ( manifest , publicFolder , pathPrefix )
266
- )
258
+ const { pages, manifest, publicFolder, pathPrefix } = pluginData
267
259
268
- const duplicateHeadersByPage = { }
269
- pages . forEach ( page => {
270
- const pathKey = headersPath ( pathPrefix , page . path )
271
- duplicateHeadersByPage [ pathKey ] = headersList
272
- } )
260
+ const headersList = _ . map (
261
+ allPageHeaders ,
262
+ transformLink ( manifest , publicFolder , pathPrefix )
263
+ )
273
264
274
- return defaultMerge ( headers , duplicateHeadersByPage )
275
- }
265
+ const duplicateHeadersByPage = { }
266
+ pages . forEach ( page => {
267
+ const pathKey = headersPath ( pathPrefix , page . path )
268
+ duplicateHeadersByPage [ pathKey ] = headersList
269
+ } )
276
270
277
- const applyLinkHeaders = ( pluginData , { mergeLinkHeaders } ) => headers => {
278
- if ( ! mergeLinkHeaders ) {
279
- return headers
271
+ return defaultMerge ( headers , duplicateHeadersByPage )
280
272
}
281
273
282
- const { pages, manifest, pathPrefix, publicFolder } = pluginData
283
- const perPageHeaders = preloadHeadersByPage ( {
284
- pages,
285
- manifest,
286
- pathPrefix,
287
- publicFolder,
288
- } )
274
+ const applyLinkHeaders =
275
+ ( pluginData , { mergeLinkHeaders } ) =>
276
+ headers => {
277
+ if ( ! mergeLinkHeaders ) {
278
+ return headers
279
+ }
289
280
290
- return defaultMerge ( headers , perPageHeaders )
291
- }
281
+ const { pages, manifest, pathPrefix, publicFolder } = pluginData
282
+ const perPageHeaders = preloadHeadersByPage ( {
283
+ pages,
284
+ manifest,
285
+ pathPrefix,
286
+ publicFolder,
287
+ } )
292
288
293
- const applySecurityHeaders = ( { mergeSecurityHeaders } ) => headers => {
294
- if ( ! mergeSecurityHeaders ) {
295
- return headers
289
+ return defaultMerge ( headers , perPageHeaders )
296
290
}
297
291
298
- return headersMerge ( headers , SECURITY_HEADERS )
299
- }
292
+ const applySecurityHeaders =
293
+ ( { mergeSecurityHeaders } ) =>
294
+ headers => {
295
+ if ( ! mergeSecurityHeaders ) {
296
+ return headers
297
+ }
300
298
301
- const applyCachingHeaders = (
302
- pluginData ,
303
- { mergeCachingHeaders }
304
- ) => headers => {
305
- if ( ! mergeCachingHeaders ) {
306
- return headers
299
+ return headersMerge ( headers , SECURITY_HEADERS )
307
300
}
308
301
309
- let chunks = [ ]
310
- // Gatsby v3.5 added componentChunkName to store().components
311
- // So we prefer to pull chunk names off that as it gets very expensive to loop
312
- // over large numbers of pages.
313
- const isComponentChunkSet = ! ! pluginData . components . entries ( ) ?. next ( )
314
- ?. value [ 1 ] ?. componentChunkName
315
- if ( isComponentChunkSet ) {
316
- chunks = [ ...pluginData . components . values ( ) ] . map ( c => c . componentChunkName )
317
- } else {
318
- chunks = Array . from ( pluginData . pages . values ( ) ) . map (
319
- page => page . componentChunkName
320
- )
321
- }
302
+ const applyCachingHeaders =
303
+ ( pluginData , { mergeCachingHeaders } ) =>
304
+ headers => {
305
+ if ( ! mergeCachingHeaders ) {
306
+ return headers
307
+ }
322
308
323
- chunks . push ( `pages-manifest` , `app` )
309
+ let chunks = [ ]
310
+ // Gatsby v3.5 added componentChunkName to store().components
311
+ // So we prefer to pull chunk names off that as it gets very expensive to loop
312
+ // over large numbers of pages.
313
+ const isComponentChunkSet = ! ! pluginData . components . entries ( ) ?. next ( )
314
+ ?. value [ 1 ] ?. componentChunkName
315
+ if ( isComponentChunkSet ) {
316
+ chunks = [ ...pluginData . components . values ( ) ] . map (
317
+ c => c . componentChunkName
318
+ )
319
+ } else {
320
+ chunks = Array . from ( pluginData . pages . values ( ) ) . map (
321
+ page => page . componentChunkName
322
+ )
323
+ }
324
324
325
- const files = [ ] . concat ( ... chunks . map ( chunk => pluginData . manifest [ chunk ] ) )
325
+ chunks . push ( `pages- manifest` , `app` )
326
326
327
- const cachingHeaders = { }
327
+ const files = [ ] . concat ( ... chunks . map ( chunk => pluginData . manifest [ chunk ] ) )
328
328
329
- files . forEach ( file => {
330
- if ( typeof file === `string` ) {
331
- cachingHeaders [ `/` + file ] = [ IMMUTABLE_CACHING_HEADER ]
332
- }
333
- } )
329
+ const cachingHeaders = { }
334
330
335
- return defaultMerge ( headers , cachingHeaders , CACHING_HEADERS )
336
- }
331
+ files . forEach ( file => {
332
+ if ( typeof file === `string` ) {
333
+ cachingHeaders [ `/` + file ] = [ IMMUTABLE_CACHING_HEADER ]
334
+ }
335
+ } )
336
+
337
+ return defaultMerge ( headers , cachingHeaders , CACHING_HEADERS )
338
+ }
337
339
338
- const applyTransfromHeaders = ( { transformHeaders } ) => headers =>
339
- _ . mapValues ( headers , transformHeaders )
340
+ const applyTransfromHeaders =
341
+ ( { transformHeaders } ) =>
342
+ headers =>
343
+ _ . mapValues ( headers , transformHeaders )
340
344
341
345
const transformToString = headers =>
342
346
`${ HEADER_COMMENT } \n\n${ stringifyHeaders ( headers ) } `
343
347
344
- const writeHeadersFile = ( { publicFolder } ) => contents =>
345
- writeFile ( publicFolder ( NETLIFY_HEADERS_FILENAME ) , contents )
348
+ const writeHeadersFile =
349
+ ( { publicFolder } ) =>
350
+ contents =>
351
+ writeFile ( publicFolder ( NETLIFY_HEADERS_FILENAME ) , contents )
346
352
347
353
export default function buildHeadersProgram (
348
354
pluginData ,
0 commit comments