Skip to content

Commit

Permalink
feat: allow RegEx for filter patterns in d2.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Aug 19, 2021
1 parent f8e1823 commit 9699330
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cli/src/lib/pwa/getPWAEnvVars.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* Handles patterns defined as strings or RegExps
* @param {Object} config
*/
function getPatternsToOmit(config) {
const patternsToOmit = config.pwa.caching.patternsToOmit.map(pattern => {
if (typeof pattern === 'string') {
return pattern
} else if (pattern instanceof RegExp) {
return pattern.source
} else {
throw new Error(
`Pattern ${pattern} to omit must be either a RegExp or a string`
)
}
})
return JSON.stringify(patternsToOmit)
}

/**
* If `config.type` === `app` and PWA is enabled, returns an object of env vars
* to be used for PWA setup.
Expand All @@ -13,9 +32,7 @@ function getPWAEnvVars(config) {
pwa_caching_omit_external_requests: JSON.stringify(
config.pwa.caching.omitExternalRequests
),
pwa_caching_patterns_to_omit: JSON.stringify(
config.pwa.caching.patternsToOmit
),
pwa_caching_patterns_to_omit: getPatternsToOmit(config),
}
}

Expand Down

0 comments on commit 9699330

Please sign in to comment.