astro-helmet 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Helmet.astro +17 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-helmet",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "A document head manager for astro.",
6
6
  "author": "Ryan Voitiskis <ryanvoitiskis@pm.me> (https://ryanvoitiskis.com/)",
package/src/Helmet.astro CHANGED
@@ -6,24 +6,29 @@ interface Props {
6
6
  options?: {
7
7
  omitHeadTags?: boolean
8
8
  applyPriority?: (tag: Tag) => Required<Tag>
9
+ csp?: boolean
9
10
  }
10
11
  }
11
12
 
12
13
  const { headItems, options = {} } = Astro.props
13
- const { applyPriority, omitHeadTags = false } = options
14
+ const { applyPriority, omitHeadTags = false, csp: cspEnabled = false } = options
14
15
  const head = renderHead(headItems, applyPriority)
15
16
 
16
- // Register CSP hashes and resources when running on Astro 6+ with CSP enabled.
17
- // Cast avoids typecheck failures for downstream consumers on Astro 4/5 where
18
- // `csp` isn't declared on `AstroGlobal`.
19
- const csp = (Astro as unknown as {
20
- csp?: {
21
- insertScriptHash(hash: string): void
22
- insertStyleHash(hash: string): void
23
- insertScriptResource(url: string): void
24
- insertStyleResource(url: string): void
25
- }
26
- }).csp
17
+ // Register CSP hashes and resources when the consumer opts in via `options.csp`
18
+ // AND is running on Astro 6+ with CSP configured. Reading `Astro.csp` warns in
19
+ // production when CSP isn't configured, so the opt-in keeps the component
20
+ // silent for users who don't need CSP integration. Cast avoids typecheck
21
+ // failures for downstream consumers on Astro 4/5.
22
+ const csp = cspEnabled
23
+ ? (Astro as unknown as {
24
+ csp?: {
25
+ insertScriptHash(hash: string): void
26
+ insertStyleHash(hash: string): void
27
+ insertScriptResource(url: string): void
28
+ insertStyleResource(url: string): void
29
+ }
30
+ }).csp
31
+ : undefined
27
32
  if (csp) {
28
33
  for (const { type, content } of getInlineContent(headItems)) {
29
34
  const hashBuffer = await crypto.subtle.digest(