packaton 0.0.25 → 0.0.26

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.
package/index.d.ts CHANGED
@@ -19,4 +19,5 @@ export interface Config {
19
19
  minifyHTML?: (html: string) => Promise<string>
20
20
  sitemapDomain?: string
21
21
  cspMapEnabled?: boolean
22
+ routeHeaders?: [name: string, value: string][]
22
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "packaton",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "author": "Eric Fortis",
6
6
  "license": "MIT",
package/src/app-prod.js CHANGED
@@ -55,6 +55,11 @@ export async function buildStaticPages(config) {
55
55
  const pages = await crawlRoutes(server.address(), docs.routes)
56
56
  const mediaHashes = await renameMediaWithHashes(pDist, MEDIA_REL_URL)
57
57
 
58
+ const headers = {
59
+ ['/' + MEDIA_REL_URL + '/*']: [
60
+ ['Cache-Control', 'public,max-age=31536000,immutable']
61
+ ]
62
+ }
58
63
  const cspByRoute = []
59
64
  for (const [route, rawHtml] of pages) {
60
65
  const doc = new HtmlCompiler(rawHtml, pSource, {
@@ -71,13 +76,18 @@ export async function buildStaticPages(config) {
71
76
  await doc.inlineMinifiedCSS()
72
77
  await doc.inlineMinifiedJS()
73
78
  write(join(pDist, route + config.outputExtension), doc.html)
74
- cspByRoute.push([route, doc.csp()])
79
+
80
+ const r = route === '/index' ? '/' : route
81
+ headers[r] ??= []
82
+ headers[r].push(['Content-Security-Policy', doc.csp()])
83
+ for (const h of config.routeHeaders)
84
+ headers[r].push(h)
75
85
  }
76
86
 
77
87
  sitemapPlugin(config, docs.routes)
78
88
  reportSizesPlugin(config, docs.routes)
79
89
  cspNginxMapPlugin(config, cspByRoute)
80
- netiflyAndCloudflareHeadersPlugin(config, cspByRoute, MEDIA_REL_URL)
90
+ write(join(config.outputDir, '_headers'), netiflyAndCloudflareHeadersPlugin(headers))
81
91
  }
82
92
  catch (error) {
83
93
  reject(error)
package/src/config.js CHANGED
@@ -35,6 +35,7 @@ const schema = {
35
35
  minifyHTML: [minifyHTML, optional(Function)],
36
36
  sitemapDomain: ['', optional(String)],
37
37
  cspMapEnabled: [true, optional(Boolean)],
38
+ routeHeaders: [[], Array.isArray]
38
39
  }
39
40
  // TODO watch New Routes?
40
41
 
@@ -1,28 +1,10 @@
1
- import { join } from 'node:path'
2
- import { write } from '../utils/fs-utils.js'
3
-
4
-
5
- /**
6
- * @param {Config} config
7
- * @param {string} cspByRoute
8
- * @param {string} relMediaURL
9
- */
10
- export function netiflyAndCloudflareHeadersPlugin(config, cspByRoute, relMediaURL) {
11
- const out = join(join(config.outputDir), '_headers')
12
-
13
- const cspHeaders = cspByRoute.map(([route, csp]) => {
14
- const r = route === '/index'
15
- ? '/'
16
- : route
17
- return [
18
- r,
19
- ` Content-Security-Policy: ${csp}`,
20
- ` Cache-Control: public,max-age=60`
21
- ].join('\n')
22
- })
23
- cspHeaders.push(`/${relMediaURL}/*`)
24
- cspHeaders.push(' Cache-Control: public,max-age=31536000,immutable')
25
-
26
- write(out, cspHeaders.join('\n'))
1
+ export function netiflyAndCloudflareHeadersPlugin(opts) {
2
+ let result = []
3
+ for (const [route, headers] of Object.entries(opts)) {
4
+ result.push(route)
5
+ for (const [h, v] of headers)
6
+ result.push(` ${h}: ${v}`)
7
+ }
8
+ return result.join('\n')
27
9
  }
28
10