uniweb 1.31.12 → 1.32.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 +10 -5
- package/package.json +6 -6
- package/partials/agents.md +2 -2
- package/partials/guides/backend.md +4 -1
- package/partials/guides/i18n.md +4 -2
- package/partials/guides/ship.md +8 -6
- package/partials/guides/start.md +2 -2
- package/partials/guides/theme.md +1 -1
- package/partials/start.md +2 -2
- package/src/backend/blueprint-reach.js +123 -0
- package/src/backend/client.js +44 -39
- package/src/backend/site-sync.js +10 -0
- package/src/commands/add.js +5 -4
- package/src/commands/build.js +21 -12
- package/src/commands/doctor.js +1 -1
- package/src/commands/inspect.js +28 -24
- package/src/commands/publish.js +11 -1
- package/src/commands/push.js +17 -1
- package/src/commands/rename.js +8 -7
- package/src/commands/start.js +3 -2
- package/src/commands/status.js +8 -1
- package/src/commands/update.js +107 -3
- package/src/framework-index.json +8 -8
- package/src/index.js +12 -15
- package/src/utils/destination-prompt.js +8 -6
- package/src/utils/lockfile-uniweb.js +113 -0
- package/src/utils/pm.js +22 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The @uniweb packages a workspace's lockfile holds, and the command that moves each one to the
|
|
3
|
+
* newest version its range allows.
|
|
4
|
+
*
|
|
5
|
+
* ⭐ WHY `update` LIFTS THEM. `update` aligns what the workspace's package.json files declare, and
|
|
6
|
+
* its install keeps every other locked version that still meets its range. So a patch to a package
|
|
7
|
+
* a project reaches only through another never arrived in an existing project, though a new project
|
|
8
|
+
* got it at once. Measured 2026-11-10, twice: semantic-parser 1.13.3 stayed 1.13.2, because core
|
|
9
|
+
* 1.6.12's `~1.13.2` is met by the locked 1.13.2, and runtime 1.5.7 stayed 1.5.6 behind the peer pnpm
|
|
10
|
+
* had installed for a root by itself. Lifted, an existing project's @uniweb packages resolve as a
|
|
11
|
+
* new project's would, and no other package moves.
|
|
12
|
+
*
|
|
13
|
+
* ⛔ pnpm's `update` also writes a newer version into a range a package.json declares (`~1.20.9`
|
|
14
|
+
* becomes `~1.20.10` once 1.20.10 is out). The caller puts those files back as `update` aligned them
|
|
15
|
+
* and installs again, which keeps the newer version, since it meets the range.
|
|
16
|
+
*
|
|
17
|
+
* yarn is left as it is: classic yarn and berry spell this differently (`yarn upgrade`, `yarn up -R`).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
21
|
+
import { join } from 'node:path'
|
|
22
|
+
import yaml from 'js-yaml'
|
|
23
|
+
|
|
24
|
+
const LOCKFILES = { pnpm: 'pnpm-lock.yaml', npm: 'package-lock.json' }
|
|
25
|
+
|
|
26
|
+
/** A name that is the framework's, and not the CLI itself, which `update` aligns to the running one. */
|
|
27
|
+
const isUniwebPackage = (name) => typeof name === 'string' && name.startsWith('@uniweb/')
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Each @uniweb package a lockfile holds, with every version it holds of it.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} workspaceDir
|
|
33
|
+
* @param {'pnpm'|'npm'|'yarn'|null} pm
|
|
34
|
+
* @returns {Map<string, string[]>|null} name → versions, sorted; null when this package manager's
|
|
35
|
+
* lockfile isn't there, can't be read, or isn't one this reads (yarn)
|
|
36
|
+
*/
|
|
37
|
+
export function lockedUniwebPackages(workspaceDir, pm) {
|
|
38
|
+
const file = LOCKFILES[pm]
|
|
39
|
+
if (!file) return null
|
|
40
|
+
const path = join(workspaceDir, file)
|
|
41
|
+
if (!existsSync(path)) return null
|
|
42
|
+
try {
|
|
43
|
+
const text = readFileSync(path, 'utf8')
|
|
44
|
+
return pm === 'pnpm' ? fromPnpmLock(yaml.load(text)) : fromNpmLock(JSON.parse(text))
|
|
45
|
+
} catch {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `packages:` keys: `'@uniweb/core@1.6.12'` (v9), `/@uniweb/core@1.6.12(react@19.0.0)` (v6). */
|
|
51
|
+
function fromPnpmLock(lock) {
|
|
52
|
+
const found = new Map()
|
|
53
|
+
for (const key of Object.keys(lock?.packages || {})) {
|
|
54
|
+
const id = key.replace(/^\//, '').replace(/\(.*$/, '')
|
|
55
|
+
const at = id.lastIndexOf('@')
|
|
56
|
+
if (at <= 0) continue
|
|
57
|
+
add(found, id.slice(0, at), id.slice(at + 1))
|
|
58
|
+
}
|
|
59
|
+
return sorted(found)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `packages:` keys: `node_modules/@uniweb/core`, `node_modules/x/node_modules/@uniweb/core`. */
|
|
63
|
+
function fromNpmLock(lock) {
|
|
64
|
+
const found = new Map()
|
|
65
|
+
for (const [key, entry] of Object.entries(lock?.packages || {})) {
|
|
66
|
+
const at = key.lastIndexOf('node_modules/')
|
|
67
|
+
if (at < 0 || entry?.link || !entry?.version) continue
|
|
68
|
+
add(found, key.slice(at + 'node_modules/'.length), entry.version)
|
|
69
|
+
}
|
|
70
|
+
return sorted(found)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function add(found, name, version) {
|
|
74
|
+
if (!isUniwebPackage(name) || !version) return
|
|
75
|
+
if (!found.has(name)) found.set(name, new Set())
|
|
76
|
+
found.get(name).add(version)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function sorted(found) {
|
|
80
|
+
return new Map([...found.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, versions]) => [name, [...versions].sort()]))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The command that moves each named package, wherever the workspace holds it, to the newest version
|
|
85
|
+
* its range allows. Never `--latest`: a range is the project's promise.
|
|
86
|
+
*
|
|
87
|
+
* @param {'pnpm'|'npm'} pm
|
|
88
|
+
* @param {string[]} names
|
|
89
|
+
* @returns {string|null} null for a package manager this doesn't lift with, or no names
|
|
90
|
+
*/
|
|
91
|
+
export function liftCommand(pm, names) {
|
|
92
|
+
if (!names.length) return null
|
|
93
|
+
if (pm === 'pnpm') return `pnpm update ${names.join(' ')} -r`
|
|
94
|
+
if (pm === 'npm') return `npm update ${names.join(' ')}`
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* What a lift moved: each package whose versions differ between two readings of the lockfile.
|
|
100
|
+
*
|
|
101
|
+
* @param {Map<string, string[]>} before
|
|
102
|
+
* @param {Map<string, string[]>} after
|
|
103
|
+
* @returns {Array<{ name: string, from: string[], to: string[] }>}
|
|
104
|
+
*/
|
|
105
|
+
export function liftMoves(before, after) {
|
|
106
|
+
const moves = []
|
|
107
|
+
for (const name of new Set([...before.keys(), ...after.keys()])) {
|
|
108
|
+
const from = before.get(name) || []
|
|
109
|
+
const to = after.get(name) || []
|
|
110
|
+
if (from.join() !== to.join()) moves.push({ name, from, to })
|
|
111
|
+
}
|
|
112
|
+
return moves.sort((a, b) => a.name.localeCompare(b.name))
|
|
113
|
+
}
|
package/src/utils/pm.js
CHANGED
|
@@ -160,6 +160,28 @@ export function installCmd(pm) {
|
|
|
160
160
|
return 'npm install'
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* The package manager to tell someone to install a workspace with: the one its lockfile names; with
|
|
165
|
+
* no lockfile yet, pnpm where it is installed (the framework's own), else the one that ran this CLI.
|
|
166
|
+
*
|
|
167
|
+
* ⭐ THE ONE RULE FOR EVERY INSTALL LINE a command prints — `start`, `create`, `add`, `rename`,
|
|
168
|
+
* `update`, and the hint for a workspace that isn't installed — so someone going from one command
|
|
169
|
+
* to the next is told one thing. ⛔ Until 2026-11-11 each chose its own: `uniweb start` said
|
|
170
|
+
* `npm install` before a project existed while the `create` it sends you to said `pnpm install`
|
|
171
|
+
* wherever pnpm is installed (an agent building a site was told both in one session), `rename` said
|
|
172
|
+
* whatever ran it, so `npx uniweb rename` in a pnpm workspace said `npm install`, and `add` never
|
|
173
|
+
* said pnpm in a workspace not yet installed.
|
|
174
|
+
*
|
|
175
|
+
* It says what to run, not how a command writes a workspace's scripts (`filterArgs`), which each
|
|
176
|
+
* command decides apart.
|
|
177
|
+
*
|
|
178
|
+
* @param {string|null} [workspaceRoot] - the workspace, when there is one
|
|
179
|
+
* @returns {'pnpm' | 'yarn' | 'npm'}
|
|
180
|
+
*/
|
|
181
|
+
export function pmToInstall(workspaceRoot = null) {
|
|
182
|
+
return detectWorkspacePm(workspaceRoot) || (isPnpmAvailable() ? 'pnpm' : detectPackageManager())
|
|
183
|
+
}
|
|
184
|
+
|
|
163
185
|
/**
|
|
164
186
|
* The install to run right after a command edited the workspace's package.json files, and the one
|
|
165
187
|
* to tell someone to run then.
|