@nuasite/nua 0.66.0 → 0.67.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuasite/nua",
3
- "version": "0.66.0",
3
+ "version": "0.67.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.js",
@@ -39,12 +39,12 @@
39
39
  "@astrojs/markdown-remark": "7.3.4",
40
40
  "@astrojs/mdx": "8.1.1",
41
41
  "@astrojs/sitemap": "3.7.4",
42
- "@nuasite/checks": "0.66.0",
43
- "@nuasite/llm-enhancements": "0.66.0",
44
- "@nuasite/cli": "0.66.0",
45
- "@nuasite/cms": "0.66.0",
46
- "@nuasite/components": "0.66.0",
47
- "@nuasite/core": "0.66.0",
42
+ "@nuasite/checks": "0.67.0",
43
+ "@nuasite/llm-enhancements": "0.67.0",
44
+ "@nuasite/cli": "0.67.0",
45
+ "@nuasite/cms": "0.67.0",
46
+ "@nuasite/components": "0.67.0",
47
+ "@nuasite/core": "0.67.0",
48
48
  "@tailwindcss/vite": "^4.2.2",
49
49
  "@tailwindcss/typography": "^0.5.19",
50
50
  "astro": "7.4.2",
@@ -52,5 +52,8 @@
52
52
  "tailwindcss": "4.2.2",
53
53
  "typescript": "^6.0.2",
54
54
  "vite": "^8.3.4"
55
+ },
56
+ "devDependencies": {
57
+ "@nuasite/agent-summary": "0.67.0"
55
58
  }
56
59
  }
@@ -5,6 +5,7 @@ import cms, { addMarkdownPlugins, cmsRemarkPlugins, inlineNuasitePackages, merge
5
5
  import pageMarkdown from '@nuasite/llm-enhancements'
6
6
  import tailwindcss from '@tailwindcss/vite'
7
7
  import type { AstroConfig, AstroIntegration } from 'astro'
8
+ import { redirectsAstroServes } from './redirects.ts'
8
9
  import { type NuaIntegrationOptions, resolveOptions } from './types.ts'
9
10
 
10
11
  export default function nua(options: NuaIntegrationOptions = {}): AstroIntegration {
@@ -72,9 +73,12 @@ export default function nua(options: NuaIntegrationOptions = {}): AstroIntegrati
72
73
  )
73
74
  }
74
75
 
75
- // Captured for `_redirects`. The `redirects: {}` passed to `updateConfig` below does not clear
76
- // them: Astro deep-merges config updates, so it still renders its own meta-refresh pages.
76
+ // A static build ships them as `_redirects` rules only. `updateConfig` deep-merges, so it cannot
77
+ // clear them; the config Astro reads them from is the one passed here. An adapter may serve them
78
+ // as routes, so Astro keeps them; dev has no `_redirects`, so Astro keeps the ones it accepts.
77
79
  capturedRedirects = config.redirects ?? {}
80
+ if (command === 'build' && config.adapter === undefined) config.redirects = {}
81
+ if (command === 'dev') config.redirects = redirectsAstroServes(capturedRedirects, message => logger.warn(message))
78
82
 
79
83
  // CMS list-style directives (`:::list{.class}`) need `remark-directive`
80
84
  // in the markdown pipeline, both to render `<ul class="class">` and to
@@ -92,7 +96,6 @@ export default function nua(options: NuaIntegrationOptions = {}): AstroIntegrati
92
96
 
93
97
  // Inject Vite plugins and integrations.
94
98
  updateConfig({
95
- redirects: {},
96
99
  vite: {
97
100
  plugins: vitePlugins,
98
101
  ssr: {
@@ -0,0 +1,40 @@
1
+ import type { AstroConfig } from 'astro'
2
+
3
+ // Astro's own checks on a redirect that need no routes (astro/dist/core/routing: `createRedirectRoutes`
4
+ // and `getParts` in create-manifest.js, `validateSegment` in segment.js). One that fails them stops
5
+ // the dev server, as Astro builds its route manifest from every redirect.
6
+ const ROUTE_DYNAMIC_SPLIT = /\[([^[\]()]+(?:\([^)]+\))?)\]/
7
+ const PARAM_NAME = /^(?:\.\.\.)?[\w$]+$/
8
+
9
+ /**
10
+ * Why Astro's route manifest refuses the redirect from `from` to `destination`, or `null` when it passes
11
+ * the checks that need no routes. A source with params whose destination is not a page is refused too,
12
+ * but the routes are not known while the config is set up.
13
+ */
14
+ export function astroRedirectRejection(from: string, destination: string): string | null {
15
+ for (const segment of from.split('/').filter(Boolean)) {
16
+ if (segment.includes('][')) return 'its parameters must be separated'
17
+ if (segment.split('[').length !== segment.split(']').length) return 'its brackets are unbalanced'
18
+ const parts = segment.split(ROUTE_DYNAMIC_SPLIT)
19
+ for (let i = 1; i < parts.length; i += 2) {
20
+ const name = /([^(]+)$/.exec(parts[i] ?? '')?.[1]
21
+ if (name === undefined || !PARAM_NAME.test(name)) return `its parameter "[${parts[i]}]" is not named with letters, digits, _ or $`
22
+ }
23
+ }
24
+ if (URL.canParse(destination) && !/^https?:\/\//.test(destination)) return `its destination "${destination}" is not an http(s) URL`
25
+ return null
26
+ }
27
+
28
+ /**
29
+ * The config's redirects without the ones Astro's route manifest refuses, each of which is reported.
30
+ * The dev server answers redirects through that manifest, and a single refused one keeps it from starting.
31
+ */
32
+ export function redirectsAstroServes(redirects: AstroConfig['redirects'], warn: (message: string) => void): AstroConfig['redirects'] {
33
+ const served: AstroConfig['redirects'] = {}
34
+ for (const [from, value] of Object.entries(redirects)) {
35
+ const rejection = astroRedirectRejection(from, typeof value === 'string' ? value : value.destination)
36
+ if (rejection === null) served[from] = value
37
+ else warn(`The dev server leaves out the redirect from "${from}", which Astro rejects: ${rejection}.`)
38
+ }
39
+ return served
40
+ }