@nera-static/nera 1.14.1 → 1.15.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/README.md +1 -1
- package/package.json +1 -1
- package/src/commands/update.js +75 -0
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ package is named after the folder (`My Bakery` → `my-bakery`).
|
|
|
31
31
|
| `nera build` | Render `pages/` → `public/`. With `--check`, then run `nera check` on the result — one command for CI. `--json` prints the result as one JSON object (see [Machine-readable output](#machine-readable-output)). |
|
|
32
32
|
| `nera dev` | Build, serve `public/`, and rebuild on change with live reload. Watches `pages/`, `config/`, `theme/` and a local theme (`theme: ./themes/<name>`). |
|
|
33
33
|
| `nera serve` | Serve the already-built `public/` folder. |
|
|
34
|
-
| `nera update` | Update the site's Nera packages, then create a missing `AGENTS.md`/`CLAUDE.md` and refresh the Nera part of `AGENTS.md` and the `nera` skill (see [Instructions for AI assistants](#instructions-for-ai-assistants)). On a legacy cloned site, `nera update --migrate` converts it to the thin model. |
|
|
34
|
+
| `nera update` | Update the site's Nera packages and raise their caret ranges in `package.json` (and `package-lock.json`) to the installed versions, then create a missing `AGENTS.md`/`CLAUDE.md` and refresh the Nera part of `AGENTS.md` and the `nera` skill (see [Instructions for AI assistants](#instructions-for-ai-assistants)). On a legacy cloned site, `nera update --migrate` converts it to the thin model. |
|
|
35
35
|
| `nera validate` | Check the site's sources (layouts, includes, YAML) before publishing; exits non-zero on any error. `--json` for machine-readable output. |
|
|
36
36
|
| `nera check` | Check the built `public/` for accessibility, privacy and legal-notice problems (see below). Build first. `--json` for machine-readable output. |
|
|
37
37
|
|
package/package.json
CHANGED
package/src/commands/update.js
CHANGED
|
@@ -18,6 +18,78 @@ export function neraDeps(pkg) {
|
|
|
18
18
|
)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// The caret range `range` raised to the installed `version`, or null when it
|
|
22
|
+
// stays: only a plain `^x.y.z` with x ≥ 1, only upwards, never across a major.
|
|
23
|
+
// Exact, tilde, tag, git and 0.x ranges are the user's choice and stay as
|
|
24
|
+
// they are. `npm update` installs within the range but never rewrites it.
|
|
25
|
+
export function raisedRange(range, version) {
|
|
26
|
+
const from = /^\^(\d+)\.(\d+)\.(\d+)$/.exec(range ?? '')
|
|
27
|
+
const to = /^(\d+)\.(\d+)\.(\d+)$/.exec(version ?? '')
|
|
28
|
+
if (!from || !to) return null
|
|
29
|
+
const [a, b] = [from, to].map((m) => m.slice(1).map(Number))
|
|
30
|
+
if (a[0] < 1 || a[0] !== b[0]) return null
|
|
31
|
+
const newer = b[1] > a[1] || (b[1] === a[1] && b[2] > a[2])
|
|
32
|
+
return newer ? `^${version}` : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const indentOf = (text) => /^[ \t]+(?=")/m.exec(text)?.[0] ?? ' '
|
|
36
|
+
|
|
37
|
+
// Raise the site's caret ranges of `names` to what is installed in its
|
|
38
|
+
// node_modules, keeping the file's own indentation, and the same ranges in
|
|
39
|
+
// the root entry of package-lock.json, so the two stay in sync. Returns the
|
|
40
|
+
// changes as [name, from, to].
|
|
41
|
+
export async function raiseRanges(cwd, names) {
|
|
42
|
+
const pkgPath = path.join(cwd, 'package.json')
|
|
43
|
+
const text = await fs.readFile(pkgPath, 'utf-8')
|
|
44
|
+
const pkg = JSON.parse(text)
|
|
45
|
+
const raised = {}
|
|
46
|
+
const changes = []
|
|
47
|
+
for (const field of ['dependencies', 'devDependencies']) {
|
|
48
|
+
for (const name of names) {
|
|
49
|
+
const range = pkg[field]?.[name]
|
|
50
|
+
if (typeof range !== 'string') continue
|
|
51
|
+
let version
|
|
52
|
+
try {
|
|
53
|
+
const installed = path.join(cwd, 'node_modules', ...name.split('/'), 'package.json')
|
|
54
|
+
version = JSON.parse(await fs.readFile(installed, 'utf-8')).version
|
|
55
|
+
} catch {
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
const to = raisedRange(range, version)
|
|
59
|
+
if (to) {
|
|
60
|
+
pkg[field][name] = to
|
|
61
|
+
raised[field] = { ...raised[field], [name]: [range, to] }
|
|
62
|
+
changes.push([name, range, to])
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (changes.length === 0) return changes
|
|
67
|
+
await fs.writeFile(pkgPath, `${JSON.stringify(pkg, null, indentOf(text))}\n`)
|
|
68
|
+
|
|
69
|
+
const lockPath = path.join(cwd, 'package-lock.json')
|
|
70
|
+
let lockText
|
|
71
|
+
try {
|
|
72
|
+
lockText = await fs.readFile(lockPath, 'utf-8')
|
|
73
|
+
} catch {
|
|
74
|
+
return changes
|
|
75
|
+
}
|
|
76
|
+
const lock = JSON.parse(lockText)
|
|
77
|
+
const root = lock.packages?.['']
|
|
78
|
+
let lockChanged = false
|
|
79
|
+
for (const [field, entries] of Object.entries(raised)) {
|
|
80
|
+
for (const [name, [from, to]] of Object.entries(entries)) {
|
|
81
|
+
if (root?.[field]?.[name] === from) {
|
|
82
|
+
root[field][name] = to
|
|
83
|
+
lockChanged = true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (lockChanged) {
|
|
88
|
+
await fs.writeFile(lockPath, `${JSON.stringify(lock, null, indentOf(lockText))}\n`)
|
|
89
|
+
}
|
|
90
|
+
return changes
|
|
91
|
+
}
|
|
92
|
+
|
|
21
93
|
// A THIN site depends on @nera-static/nera and carries no engine source.
|
|
22
94
|
// A LEGACY site is a clone of the old generator: it vendors the engine under
|
|
23
95
|
// src/ and has no @nera-static/nera dependency — the case `nera update` migrates.
|
|
@@ -193,6 +265,9 @@ export async function runUpdate(args = [], options = {}) {
|
|
|
193
265
|
const targets = neraDeps(pkg)
|
|
194
266
|
console.log(`🔄 Updating Nera packages: ${targets.join(', ')}`)
|
|
195
267
|
runNpm(['update', ...targets], cwd)
|
|
268
|
+
for (const [name, from, to] of await raiseRanges(cwd, targets)) {
|
|
269
|
+
console.log(` ✓ ${name}: ${from} → ${to} in package.json`)
|
|
270
|
+
}
|
|
196
271
|
await syncAndReportAgentFiles(cwd, templateDir)
|
|
197
272
|
await syncAndReportSkill(cwd, skillDir)
|
|
198
273
|
console.log('✅ Up to date.')
|