@nera-static/core 4.17.0 → 4.18.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.
package/README.md CHANGED
@@ -82,9 +82,11 @@ Subpath exports (`@nera-static/core/resolve`, `/site-model`, `/core`, `/render`,
82
82
  import { resolveSiteModel } from '@nera-static/core/site-model'
83
83
 
84
84
  const model = resolveSiteModel({ cwd: '/path/to/site' })
85
- // → { folders, theme, roots, appConfigError, themeError, ... } (never throws)
85
+ // → { folders, theme, roots, appConfigError, appConfigErrorLine, themeError, ... } (never throws)
86
86
  ```
87
87
 
88
+ A malformed `config/app.yaml` comes back as `appConfigError` (the parser's message) and `appConfigErrorLine` (its 1-based line, core ≥ 4.18.0; `null` when the file is missing or parses, or the parser gives no position).
89
+
88
90
  ---
89
91
 
90
92
  ## 🔌 Plugin contract
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/core",
3
- "version": "4.17.0",
3
+ "version": "4.18.1",
4
4
  "description": "The Nera static site generator engine — the build pipeline and the layered theme/view resolver, importable by the Nera CLI, @nera-static/validate and tooling",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/site-model.js CHANGED
@@ -16,7 +16,9 @@ import { resolveTheme } from './theme.js'
16
16
  // pages, never warns, and never throws on a missing or broken theme. A theme
17
17
  // that cannot be resolved (unset package, missing `views/`) is returned as
18
18
  // `themeError` and a malformed app.yaml as `appConfigError`, for the caller to
19
- // surface as a validation finding rather than aborting.
19
+ // surface as a validation finding rather than aborting. `appConfigErrorLine`
20
+ // carries the parser's 1-based line for that error, or `null` when there is no
21
+ // error or the parser gives no position.
20
22
  export function resolveSiteModel({
21
23
  cwd = process.cwd(),
22
24
  settings = defaultSettings,
@@ -27,11 +29,13 @@ export function resolveSiteModel({
27
29
 
28
30
  let appConfig = {}
29
31
  let appConfigError = null
32
+ let appConfigErrorLine = null
30
33
  if (fs.existsSync(appConfigPath)) {
31
34
  try {
32
35
  appConfig = yaml.parse(fs.readFileSync(appConfigPath, 'utf-8')) || {}
33
36
  } catch (err) {
34
37
  appConfigError = err.message
38
+ appConfigErrorLine = err.linePos?.[0]?.line ?? null
35
39
  }
36
40
  }
37
41
 
@@ -55,6 +59,7 @@ export function resolveSiteModel({
55
59
  cwd,
56
60
  appConfig,
57
61
  appConfigError,
62
+ appConfigErrorLine,
58
63
  folders,
59
64
  viewsRoot,
60
65
  theme,
package/src/theme.js CHANGED
@@ -49,7 +49,10 @@ export function resolveTheme({
49
49
 
50
50
  if (!fs.existsSync(viewsRoot)) {
51
51
  throw new Error(
52
- `theme: "${spec}" resolved to ${root}, but ${viewsRoot} does not exist`
52
+ `theme: "${spec}" resolved to ${siteRelative(cwd, root)}, but it ` +
53
+ 'has no views/ folder — point `theme:` in config/app.yaml (or ' +
54
+ 'NERA_THEME) at a theme folder with views/, or remove it to ' +
55
+ 'build without a theme'
53
56
  )
54
57
  }
55
58
 
@@ -65,6 +68,26 @@ export function resolveTheme({
65
68
  }
66
69
  }
67
70
 
71
+ // A theme root as the site sees it, for error messages: relative to cwd, `.`
72
+ // when it is the site itself. A resolved package root is already a realpath, so
73
+ // when the root exists both sides go through realpath — otherwise a macOS temp
74
+ // dir (/var → /private/var) or an `npm link`ed theme reads `../../private/…`. A
75
+ // root that does not exist has no realpath, and its plain path is relative to
76
+ // the plain cwd it was resolved from.
77
+ function siteRelative(cwd, root) {
78
+ const real = (p) => {
79
+ try {
80
+ return fs.realpathSync(p)
81
+ } catch {
82
+ return p
83
+ }
84
+ }
85
+ const exists = fs.existsSync(root)
86
+ const from = exists ? real(cwd) : cwd
87
+ const to = exists ? real(root) : root
88
+ return path.relative(from, to) || '.'
89
+ }
90
+
68
91
  // The theme spec in effect: NERA_THEME over `app.theme`. An empty NERA_THEME is
69
92
  // treated as unset, so `NERA_THEME= nera build` falls back to app.yaml rather
70
93
  // than silently building themeless.
@@ -148,8 +171,8 @@ function resolvePackageRoot(spec, cwd) {
148
171
  return path.dirname(requireFromSite.resolve(`${pkg}/package.json`))
149
172
  } catch {
150
173
  throw new Error(
151
- `theme: "${spec}" — package ${pkg} is not installed. ` +
152
- `Run: npm install ${pkg}`
174
+ `theme: "${spec}" — package ${pkg} is not installed; ` +
175
+ `run \`npm install ${pkg}\``
153
176
  )
154
177
  }
155
178
  }
@@ -240,9 +263,9 @@ function checkGeneratorCompatibility(theme, themePkg, generatorVersion) {
240
263
  if (!satisfies(generatorVersion, range)) {
241
264
  throw new Error(
242
265
  `theme "${theme.name}" requires Nera generator ${range}, but this ` +
243
- `generator is ${generatorVersion}. Update the generator ` +
244
- '(nera update) or install a theme version compatible with ' +
245
- `${generatorVersion}.`
266
+ `generator is ${generatorVersion} — update the generator ` +
267
+ '(`nera update`) or install a theme version compatible with ' +
268
+ generatorVersion
246
269
  )
247
270
  }
248
271
  }