@@ -3,7 +3,7 @@ import { parse, posix } from 'path'
33
44import { writeFile , existsSync } from 'fs-extra'
55import kebabHash from 'kebab-hash'
6- import _ from 'lodash'
6+ import mergeWith from 'lodash.mergewith '
77
88import {
99 HEADER_COMMENT ,
@@ -15,14 +15,15 @@ import {
1515 NETLIFY_HEADERS_FILENAME ,
1616 PAGE_DATA_DIR ,
1717} from './constants'
18+ import { isBoolean , flow } from './util'
1819
1920const getHeaderName = ( header : any ) => {
2021 const matches = header . match ( / ^ ( [ ^ : ] + ) : / )
2122 return matches && matches [ 1 ]
2223}
2324
2425const validHeaders = ( headers : any , reporter : any ) => {
25- if ( ! headers || ! _ . isObject ( headers ) ) {
26+ if ( ! headers || typeof headers !== 'object' ) {
2627 return false
2728 }
2829
@@ -97,7 +98,7 @@ const preloadHeadersByPage = ({
9798 }
9899
99100 pages . forEach ( ( page : any ) => {
100- const scripts = _ . flatMap ( COMMON_BUNDLES , ( file ) => getScriptPath ( file , manifest ) )
101+ const scripts = COMMON_BUNDLES . flatMap ( ( file ) => getScriptPath ( file , manifest ) )
101102 scripts . push (
102103 ...getScriptPath ( pathChunkName ( page . path ) , manifest ) ,
103104 ...getScriptPath ( page . componentChunkName , manifest ) ,
@@ -124,17 +125,15 @@ const preloadHeadersByPage = ({
124125 return linksByPage
125126}
126127
127- const defaultMerge = ( ...headers : any [ ] ) => {
128- const unionMerge = ( objValue : any , srcValue : any ) => {
129- if ( Array . isArray ( objValue ) ) {
130- return _ . union ( objValue , srcValue )
131- }
132- // opt into default merge behavior
128+ const unionMerge = ( objValue : any , srcValue : any ) => {
129+ if ( Array . isArray ( objValue ) ) {
130+ return [ ...new Set ( [ ...objValue , ...srcValue ] ) ]
133131 }
134-
135- return _ . mergeWith ( { } , ...headers , unionMerge )
132+ // opt into default merge behavior
136133}
137134
135+ const defaultMerge = ( ...headers : any [ ] ) => mergeWith ( { } , ...headers , unionMerge )
136+
138137const headersMerge = ( userHeaders : any , defaultHeaders : any ) => {
139138 const merged = { }
140139 Object . keys ( defaultHeaders ) . forEach ( ( path ) => {
@@ -196,7 +195,7 @@ const validateUserOptions = (pluginOptions: any, reporter: any) => (headers: any
196195 }
197196
198197 [ `mergeSecurityHeaders` , `mergeLinkHeaders` , `mergeCachingHeaders` ] . forEach ( ( mergeOption ) => {
199- if ( ! _ . isBoolean ( pluginOptions [ mergeOption ] ) ) {
198+ if ( ! isBoolean ( pluginOptions [ mergeOption ] ) ) {
200199 throw new TypeError (
201200 `The "${ mergeOption } " option to gatsby-plugin-netlify must be a boolean. Check your gatsby-config.js.` ,
202201 )
@@ -314,11 +313,16 @@ const applyCachingHeaders =
314313 return defaultMerge ( headers , cachingHeaders , CACHING_HEADERS )
315314 }
316315
317- const applyTransfromHeaders =
316+ const applyTransformHeaders =
318317 ( {
319318 transformHeaders
320319 } : any ) =>
321- ( headers : any ) => _ . mapValues ( headers , transformHeaders )
320+ ( headers : any ) =>
321+ Object . entries ( headers ) . reduce ( ( temp , [ key , value ] ) => {
322+ temp [ key ] = transformHeaders ( value )
323+ return temp
324+ } , { } )
325+
322326
323327const transformToString = ( headers : any ) => `${ HEADER_COMMENT } \n\n${ stringifyHeaders ( headers ) } `
324328
@@ -328,18 +332,22 @@ const writeHeadersFile =
328332 } : any ) =>
329333 ( contents : any ) => writeFile ( publicFolder ( NETLIFY_HEADERS_FILENAME ) , contents )
330334
331- const buildHeadersProgram = ( pluginData : any , pluginOptions : any , reporter : any ) =>
332- _ . flow (
335+ const buildHeadersProgram = ( pluginData : any , pluginOptions : any , reporter : any ) => {
336+ const returnVal = flow (
337+ [
333338 validateUserOptions ( pluginOptions , reporter ) ,
334339 mapUserLinkHeaders ( pluginData ) ,
335340 applySecurityHeaders ( pluginOptions ) ,
336341 applyCachingHeaders ( pluginData , pluginOptions ) ,
337342 mapUserLinkAllPageHeaders ( pluginData , pluginOptions ) ,
338343 applyLinkHeaders ( pluginData , pluginOptions ) ,
339- applyTransfromHeaders ( pluginOptions ) ,
344+ applyTransformHeaders ( pluginOptions ) ,
340345 transformToString ,
341346 writeHeadersFile ( pluginData ) ,
342- ) ( pluginOptions . headers )
347+ ] ) ( pluginOptions . headers )
348+ console . log ( { returnVal} )
349+ return returnVal
350+ }
343351
344352export default buildHeadersProgram
345353/* eslint-enable max-lines */
0 commit comments