Skip to content
Permalink
Browse files

feat(gatsby-ssr): update checkpathexclusion to use RegExp instead of …

…an array of strings
  • Loading branch information
wmontgomery committed Jul 19, 2019
1 parent 057bc58 commit 3dc084a61a2b530fc03e3196f5c1fc209f255622
Showing with 7 additions and 5 deletions.
  1. +3 −2 src/gatsby-ssr.spec.ts
  2. +4 −3 src/gatsby-ssr.ts
@@ -37,8 +37,9 @@ describe('gatsby-ssr.js', () => {
})

it('does the pathname match any of the exclusions', () => {
expect(checkPathExclusion('/client/nerds', { excludePaths: ['/client/', '/tacos'] })).toBeTruthy()
expect(checkPathExclusion('/about/blerns', { excludePaths: ['/client/', '/tacos'] })).toBeFalsy()
expect(checkPathExclusion('/client/omegablerns', { excludePaths: /\/client/ })).toBeTruthy()
expect(checkPathExclusion('/about/blerns', { excludePaths: /(\/client)|(\/tacos)/ })).toBeFalsy()
expect(checkPathExclusion('/about/tacos', { excludePaths: /(\/client)|(\/about\/tacos)/ })).toBeTruthy()
expect(checkPathExclusion('/blerkstorm', {})).toBeFalsy()
})

@@ -19,7 +19,7 @@ export interface Script {

export interface PluginOptions {
excludeFiles?: RegExp | string
excludePaths?: any[]
excludePaths?: RegExp | string
}

let pageScripts: Script[]
@@ -50,8 +50,9 @@ export function onPreRenderHTML ({ getHeadComponents, pathname, replaceHeadCompo
}

export function checkPathExclusion (pathname: string, pluginOptions: PluginOptions): boolean {
const exclusion = pluginOptions.excludePaths || []
return exclusion.some(p => pathname.includes(p))
if (!pluginOptions.excludePaths) return false

return RegExp(pluginOptions.excludePaths).test(pathname)
}

function getHeadComponentsNoJS (headComponents: ReactNode[], pluginOptions: PluginOptions): ReactNode[] {

0 comments on commit 3dc084a

Please sign in to comment.
You can’t perform that action at this time.