uniweb 1.31.6 → 1.31.7
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 +6 -6
- package/partials/guides/data.md +1 -1
- package/partials/guides/foundation.md +2 -2
- package/src/backend/foundation-bring-along.js +5 -2
- package/src/backend/library-types.js +64 -0
- package/src/backend/unregistered-types.js +56 -0
- package/src/commands/add-library.js +9 -3
- package/src/commands/publish.js +1 -1
- package/src/commands/push.js +1 -1
- package/src/commands/register.js +216 -48
- package/src/commands/status.js +101 -3
- package/src/framework-index.json +2 -2
- package/src/index.js +19 -1
- package/src/utils/closed-reader.js +6 -1
- package/src/utils/stale-export.js +33 -0
- package/templates/workspace/README.md.hbs +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniweb",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.7",
|
|
4
4
|
"description": "Create structured Vite + React sites with content/code separation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"js-yaml": "^4.3.2",
|
|
42
42
|
"prompts": "^2.4.2",
|
|
43
43
|
"tar": "^7.5.21",
|
|
44
|
-
"@uniweb/content-writer": "~1.3.1",
|
|
45
|
-
"@uniweb/schemas": "~1.7.1",
|
|
46
44
|
"@uniweb/core": "~1.6.11",
|
|
47
|
-
"@uniweb/semantic-parser": "~1.13.2"
|
|
45
|
+
"@uniweb/semantic-parser": "~1.13.2",
|
|
46
|
+
"@uniweb/schemas": "~1.7.1",
|
|
47
|
+
"@uniweb/content-writer": "~1.3.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@uniweb/
|
|
50
|
+
"@uniweb/build": "~1.20.7",
|
|
51
51
|
"@uniweb/content-reader": "~1.5.9",
|
|
52
|
-
"@uniweb/
|
|
52
|
+
"@uniweb/semantic-parser": "~1.13.2"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@uniweb/build": {
|
package/partials/guides/data.md
CHANGED
|
@@ -136,7 +136,7 @@ data: {
|
|
|
136
136
|
|
|
137
137
|
`single`/`whole` are refused over a schema whose root is a list (`@std/nav`, `@std/form`). A `whole` key its source cannot answer whole is `null`. An optional `schemas.config.js` routes a scope to a directory: `export default { '@acme': '../shared/acme-schemas' }` — a routed scope wins, has no package fallback, and `@/`/`@uniweb` are never routable. Worked examples: `development/schemas-in-practice.md`.
|
|
138
138
|
|
|
139
|
-
**Any foundation can use a data schema another defines, by its full name** — `data: { members: '@acme/member' }`, `schema: '@acme/member'` in `queries.yml`. No backend is involved, and nothing to configure: a local build, `uniweb dev` included, reads the type from the package of the workspace that defines it (a foundation whose name gives the `@acme` scope, with the type in its own `schemas/`), or from a library the foundation bundles whose package.json gives that scope (`uniweb guide foundation` § Libraries). Two packages defining it stop the build, naming both. A type no such package defines comes from `schemas.config.js` (`'@acme/member': '../elsewhere/member.yml'`, or the scope's directory), which wins over both, or an installed `@acme/schemas` package. A scope is a namespace that keeps names from colliding, not a limit on who uses a type. So a type another foundation defines is named, never copied: a copy of its file is a second definition of the same type, which `doctor` points out where the two foundations' names give one scope (`type-defined-twice`). Registering, which only a site with a backend does, names such a type and sends no definition of it. A push also needs one of the site's foundations to declare the type, as a section type's data key or a schema of its own: the backend refuses a query whose type none of them declares, since nothing there would render it. A site can hold another site's records of a type too: `paths: { 'records/acme/member': '../../hub/site/records/acme/member' }` in its `site.yml` reads them as its own, a push adds them by reference rather than as copies once their own site has pushed them, and a pull leaves those files alone. A site's records of it sit in `records/acme/member/`; in `records/member/` they'd be the foundation's own `@/member`.
|
|
139
|
+
**Any foundation can use a data schema another defines, by its full name** — `data: { members: '@acme/member' }`, `schema: '@acme/member'` in `queries.yml`. No backend is involved, and nothing to configure: a local build, `uniweb dev` included, reads the type from the package of the workspace that defines it (a foundation whose name gives the `@acme` scope, with the type in its own `schemas/`), or from a library the foundation bundles whose package.json gives that scope (`uniweb guide foundation` § Libraries). Two packages defining it stop the build, naming both. A type no such package defines comes from `schemas.config.js` (`'@acme/member': '../elsewhere/member.yml'`, or the scope's directory), which wins over both, or an installed `@acme/schemas` package. A scope is a namespace that keeps names from colliding, not a limit on who uses a type. So a type another foundation defines is named, never copied: a copy of its file is a second definition of the same type, which `doctor` points out where the two foundations' names give one scope (`type-defined-twice`). Registering, which only a site with a backend does, names such a type and sends no definition of it; a type a library defines is registered from the library, first (`uniweb guide foundation` § Libraries). A push also needs one of the site's foundations to declare the type, as a section type's data key or a schema of its own: the backend refuses a query whose type none of them declares, since nothing there would render it. A site can hold another site's records of a type too: `paths: { 'records/acme/member': '../../hub/site/records/acme/member' }` in its `site.yml` reads them as its own, a push adds them by reference rather than as copies once their own site has pushed them, and a pull leaves those files alone. A site's records of it sit in `records/acme/member/`; in `records/member/` they'd be the foundation's own `@/member`.
|
|
140
140
|
|
|
141
141
|
```jsx
|
|
142
142
|
function Article({ content, block }) { // data: { article: { schema: '@std/article', single: true } }
|
|
@@ -171,8 +171,8 @@ A section type is a front desk; a **library** is the back office several foundat
|
|
|
171
171
|
- A worker takes ordinary props and reads every design decision from foundation vars and theme tokens (`var(--card-radius)`, `bg-card`), never a fixed radius or color. That is what lets one worker look classic in one foundation and modern in another.
|
|
172
172
|
- Import `@uniweb/core` by its bare name only, as kit does: a subpath bundles a second core.
|
|
173
173
|
- A section type the library holds stays each foundation's to offer: a directory in the foundation's `sections/` whose `index.jsx` is `export { default } from 'ui/sections/Banner/index.jsx'`, with a `meta.js` that re-exports the library's the same way. Share one only when both vocabularies offer that type with the same content and params; otherwise each foundation writes its own over the same workers.
|
|
174
|
-
- Data types: `uniweb add library libraries/data --schemas --scope @acme` gives it a `schemas/` folder and its scope (`"uniweb": { "scope": "@acme" }` in its package.json). Foundations name its types in full (`data: { plans: '@acme/plan' }`), with nothing to configure (`uniweb guide data`).
|
|
175
|
-
- Each foundation bundles the library, so a build after a change in the library rebuilds every foundation that uses it. A registered foundation version keeps the library as it was built, as it keeps kit: a fix reaches a hosted site when that site's foundation releases again, which `uniweb publish` from the site does.
|
|
174
|
+
- Data types: `uniweb add library libraries/data --schemas --scope @acme` gives it a `schemas/` folder and its scope (`"uniweb": { "scope": "@acme" }` in its package.json). Foundations name its types in full (`data: { plans: '@acme/plan' }`), with nothing to configure (`uniweb guide data`). On a synced site, `register` in a foundation registers the types it names from the library first, since a foundation is taken only once they are; `push` and `publish` release the foundation through `register`, so they do too, and a change to a type releases each foundation that names it on its site's next push. `uniweb register` in the library registers them alone.
|
|
175
|
+
- Each foundation bundles the library, so a build after a change in the library rebuilds every foundation that uses it, and `uniweb status` run in the library names those foundations and their sites. A registered foundation version keeps the library as it was built, as it keeps kit: a fix reaches a hosted site when that site's foundation releases again, which `uniweb publish` from the site does.
|
|
176
176
|
- Keep a library inside the workspace. Outside it, under npm a build cannot resolve what the library's own code imports (kit); under pnpm a `file:` library is a copy that misses new files until a reinstall, and a `link:` one has the site load a copy of the foundation.
|
|
177
177
|
|
|
178
178
|
### The Front Desk pattern
|
|
@@ -37,8 +37,11 @@
|
|
|
37
37
|
* posture as `uniweb status` on a 404).
|
|
38
38
|
*
|
|
39
39
|
* "Release" here is literally `uniweb register` run in the foundation directory
|
|
40
|
-
* — same build-if-stale →
|
|
41
|
-
* verb does, so there is exactly one
|
|
40
|
+
* — same build-if-stale → the types its libraries define → schema submit → code
|
|
41
|
+
* upload → digest the standalone verb does, so there is exactly one
|
|
42
|
+
* foundation-release path. A library's types reach the registry this way: a change
|
|
43
|
+
* to one changes the foundation's built schema, which the digest folds in, so the
|
|
44
|
+
* foundation is released, and its register sends them first.
|
|
42
45
|
*
|
|
43
46
|
* ⭐ **`push` runs it too, and for a reason publish's framing does not cover.**
|
|
44
47
|
* [Diego, 2026-08-19] — *"A published site can only reference a registered
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ THE TYPES A FOUNDATION NAMES THAT A LIBRARY DEFINES ARE REGISTERED WITH IT. A foundation is
|
|
3
|
+
* released only once the data types it names are registered: the registry refuses one that names a
|
|
4
|
+
* Model it doesn't hold. A type a library defines is read by the foundation's build from that
|
|
5
|
+
* library's `schemas/` (`workspaceTypeFiles`), so `register` in the foundation registers it from
|
|
6
|
+
* there first, and `push` and `publish`, which release a site's foundation with `register`, do too
|
|
7
|
+
* *[Diego, 2026-11-10: "yes, push and publish should register a library's types automatically"]*.
|
|
8
|
+
*
|
|
9
|
+
* A library here is what the build read the type from: a schemas package (`isSchemasPackage`, not a
|
|
10
|
+
* foundation) outside the foundation that gives its scope, bundled by the foundation or a package of
|
|
11
|
+
* its workspace. A type another FOUNDATION defines is registered when that foundation is, and a
|
|
12
|
+
* refused release names it (`unregistered-types.js`).
|
|
13
|
+
*
|
|
14
|
+
* ⚖️ Registered whole, as `uniweb register` in the library would: what is unchanged the registry
|
|
15
|
+
* answers as such, and a changed definition replaces the registered one, which every site naming the
|
|
16
|
+
* type then reads. The registry judges the change: one it can't make where records of the type are
|
|
17
|
+
* kept it refuses (`destructive_republish`), and the release stops there.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync } from 'node:fs'
|
|
21
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
22
|
+
|
|
23
|
+
const within = (dir, path) => {
|
|
24
|
+
const rel = relative(resolve(dir), resolve(path))
|
|
25
|
+
return rel === '' || (!rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The package `file` is in: the nearest folder above it with a package.json. */
|
|
29
|
+
function packageDirOf(file) {
|
|
30
|
+
for (let at = dirname(resolve(file)); ; at = dirname(at)) {
|
|
31
|
+
if (existsSync(join(at, 'package.json'))) return at
|
|
32
|
+
if (dirname(at) === at) return null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The libraries that define types the foundation names, each once, with the types it names from
|
|
38
|
+
* each. A type its own `schemas/` defines (`@/x`), one nothing local defines, and one two packages
|
|
39
|
+
* define (which the build refused) are left out.
|
|
40
|
+
*
|
|
41
|
+
* @param {object} o
|
|
42
|
+
* @param {string[]} o.named - every type the foundation names (its schema's `dataSchemas`)
|
|
43
|
+
* @param {string} o.foundationDir
|
|
44
|
+
* @returns {Promise<Array<{ dir: string, scope: string, refs: string[] }>>} in the order named
|
|
45
|
+
*/
|
|
46
|
+
export async function typesFromLibraries({ named, foundationDir }) {
|
|
47
|
+
const { workspaceTypeFiles, packageTypeScope, classifyPackage, isSchemasPackage } = await import('@uniweb/build')
|
|
48
|
+
if (typeof workspaceTypeFiles !== 'function' || typeof packageTypeScope !== 'function') return []
|
|
49
|
+
const byDir = new Map()
|
|
50
|
+
for (const ref of named) {
|
|
51
|
+
// `@uniweb` is reserved, and nothing registers under it.
|
|
52
|
+
if (!/^@[^/]+\/./.test(ref) || ref.startsWith('@uniweb/')) continue
|
|
53
|
+
const files = await workspaceTypeFiles(ref, foundationDir).catch(() => [])
|
|
54
|
+
if (files.length !== 1) continue
|
|
55
|
+
const dir = packageDirOf(files[0])
|
|
56
|
+
if (!dir || within(foundationDir, dir)) continue
|
|
57
|
+
if (classifyPackage(dir) === 'foundation' || !isSchemasPackage(dir)) continue
|
|
58
|
+
const scope = await packageTypeScope(dir, 'schemas')
|
|
59
|
+
if (!scope) continue
|
|
60
|
+
if (!byDir.has(dir)) byDir.set(dir, { dir, scope, refs: [] })
|
|
61
|
+
byDir.get(dir).refs.push(ref)
|
|
62
|
+
}
|
|
63
|
+
return [...byDir.values()]
|
|
64
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ THE TYPES A FOUNDATION NAMES THAT ANOTHER LOCAL PACKAGE DEFINES, AND THE REGISTRY DOESN'T HOLD.
|
|
3
|
+
* A foundation is released only once the data types it names are registered: the registry refuses
|
|
4
|
+
* one that depends on a Model it doesn't have. Measured 2026-11-10 on a local backend: a site's push
|
|
5
|
+
* released its foundation, which names `@acme/libplan` from a library it bundles, and the registry
|
|
6
|
+
* answered 400, "no such data-schema is registered on this deployment and this package does not
|
|
7
|
+
* publish one"; after `uniweb register` in the library, the push went through.
|
|
8
|
+
*
|
|
9
|
+
* A library's types `register` now sends before the foundation (`library-types.js`), so what this
|
|
10
|
+
* names after a refusal is a type ANOTHER FOUNDATION of the workspace defines: that foundation
|
|
11
|
+
* registers it, with `uniweb register` there.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { existsSync } from 'node:fs'
|
|
15
|
+
import { dirname, join, relative, resolve, sep, isAbsolute } from 'node:path'
|
|
16
|
+
|
|
17
|
+
const within = (dir, path) => {
|
|
18
|
+
const rel = relative(resolve(dir), resolve(path))
|
|
19
|
+
return rel === '' || (!rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The package `file` is in: the nearest folder above it with a package.json. */
|
|
23
|
+
function packageDirOf(file) {
|
|
24
|
+
for (let at = dirname(resolve(file)); ; at = dirname(at)) {
|
|
25
|
+
if (existsSync(join(at, 'package.json'))) return at
|
|
26
|
+
if (dirname(at) === at) return null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Each type `named` that the foundation does not define, that one other local package does, and that
|
|
32
|
+
* the registry answers it does not hold (`readDataSchema` → null). A type the registry could not be
|
|
33
|
+
* asked about is left out: this explains a refusal, and says nothing it could not check.
|
|
34
|
+
*
|
|
35
|
+
* @param {object} o
|
|
36
|
+
* @param {string[]} o.named - every type the foundation names (its schema's `dataSchemas`)
|
|
37
|
+
* @param {string[]} o.defined - the ones it defines, which its register sends
|
|
38
|
+
* @param {string} o.foundationDir
|
|
39
|
+
* @param {{ readDataSchema(name: string): Promise<object|null> }} o.client
|
|
40
|
+
* @returns {Promise<Array<{ ref: string, dir: string }>>} each type and the folder of the package that defines it
|
|
41
|
+
*/
|
|
42
|
+
export async function unregisteredLocalTypes({ named, defined, foundationDir, client }) {
|
|
43
|
+
const { workspaceTypeFiles } = await import('@uniweb/build')
|
|
44
|
+
if (typeof workspaceTypeFiles !== 'function') return []
|
|
45
|
+
const out = []
|
|
46
|
+
for (const ref of named) {
|
|
47
|
+
if (defined.includes(ref) || /^@(?:std|uniweb)\//.test(ref)) continue
|
|
48
|
+
const files = await workspaceTypeFiles(ref, foundationDir).catch(() => [])
|
|
49
|
+
if (files.length !== 1) continue
|
|
50
|
+
const dir = packageDirOf(files[0])
|
|
51
|
+
if (!dir || within(foundationDir, dir)) continue
|
|
52
|
+
const held = await client.readDataSchema(ref).catch(() => undefined)
|
|
53
|
+
if (held === null) out.push({ ref, dir })
|
|
54
|
+
}
|
|
55
|
+
return out
|
|
56
|
+
}
|
|
@@ -81,16 +81,22 @@ export function libraryManifest({ name, projectName, scope = null, versions = ge
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
// The two example lines are aligned on the longer, which the library's name decides.
|
|
85
|
+
const INDEX = (name) => {
|
|
86
|
+
const here = `export { default as PlanCard } from './components/PlanCard.jsx'`
|
|
87
|
+
const there = `import { PlanCard } from '${name}'`
|
|
88
|
+
const width = Math.max(here.length, there.length) + 3
|
|
89
|
+
return `// What this library shares with the foundations that depend on it. Export each component, hook
|
|
85
90
|
// or helper here, and a foundation imports it by the library's name:
|
|
86
91
|
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
92
|
+
// ${here.padEnd(width)}(here)
|
|
93
|
+
// ${there.padEnd(width)}(in a foundation)
|
|
89
94
|
//
|
|
90
95
|
// A component here takes ordinary props, and reads its look from the foundation's vars and the
|
|
91
96
|
// theme's tokens (var(--card-radius), bg-card), so each foundation that uses it keeps its own.
|
|
92
97
|
export {}
|
|
93
98
|
`
|
|
99
|
+
}
|
|
94
100
|
|
|
95
101
|
// The form kit's own stylesheet uses, which holds wherever a package manager puts the package.
|
|
96
102
|
const STYLES = `/* Tailwind reads this library's files wherever it is installed: each foundation that uses it imports this stylesheet. */
|
package/src/commands/publish.js
CHANGED
|
@@ -562,7 +562,7 @@ export async function publish(args = []) {
|
|
|
562
562
|
}
|
|
563
563
|
// A scope you are not a member of is said as that, with the ways on (`explainReleaseFailure`).
|
|
564
564
|
say.err(err.notMember ? err.message : `Foundation release failed: ${err.message}`)
|
|
565
|
-
for (const line of err.notMember ? err.ways : ['
|
|
565
|
+
for (const line of err.notMember ? err.ways : ['Nothing was sent. Settle what the release said above, then re-run `uniweb publish`.']) say.dim(line)
|
|
566
566
|
return { exitCode: 1 }
|
|
567
567
|
}
|
|
568
568
|
|
package/src/commands/push.js
CHANGED
|
@@ -340,7 +340,7 @@ export async function push(args = [], deps = {}) {
|
|
|
340
340
|
}
|
|
341
341
|
// A scope you are not a member of is said as that, with the ways on (`explainReleaseFailure`).
|
|
342
342
|
error(err.notMember ? err.message : `Foundation release failed: ${err.message}`)
|
|
343
|
-
for (const line of err.notMember ? err.ways : ['
|
|
343
|
+
for (const line of err.notMember ? err.ways : ['Nothing was sent. Settle what the release said above, then re-run `uniweb push`.']) note(line)
|
|
344
344
|
return { exitCode: 1 }
|
|
345
345
|
}
|
|
346
346
|
if (!fnd.proceed) return { exitCode: 1 }
|
package/src/commands/register.js
CHANGED
|
@@ -12,10 +12,16 @@
|
|
|
12
12
|
* — `register` builds it first. Preview paths (`--dry-run`, `-o`) never write to
|
|
13
13
|
* `dist/`; they require a pre-built foundation.
|
|
14
14
|
*
|
|
15
|
-
* Run from a foundation, or from a schemas-only package — a package
|
|
16
|
-
* schemas (
|
|
17
|
-
*
|
|
18
|
-
* standalone (foundation-less); same flags, `--scope`
|
|
15
|
+
* Run from a foundation, or from a schemas-only package — a package holding a
|
|
16
|
+
* `schemas/*.yml` folder (a library's), or one that exports schemas (e.g.
|
|
17
|
+
* `@uniweb/schemas`, any `@org/schemas`). The schemas-only package is auto-detected
|
|
18
|
+
* and submits its data schemas standalone (foundation-less); same flags, `--scope`
|
|
19
|
+
* names them.
|
|
20
|
+
*
|
|
21
|
+
* A foundation's register first registers the types it names that a library
|
|
22
|
+
* defines, from the library (`backend/library-types.js`): the registry takes a
|
|
23
|
+
* foundation only once the types it names are registered. So `push` and `publish`,
|
|
24
|
+
* which release a site's foundation with this command, register them too.
|
|
19
25
|
*
|
|
20
26
|
* Usage:
|
|
21
27
|
* uniweb register Build the .uwx, submit it, then deliver
|
|
@@ -93,6 +99,8 @@ import { BackendClient } from '../backend/client.js'
|
|
|
93
99
|
import { resolveWorkspace, scopeOfWorkspace, topOfChildHandle, SOURCE_LABEL } from '../backend/workspace.js'
|
|
94
100
|
import { writeJsonPreservingStyleAsync } from '../utils/json-file.js'
|
|
95
101
|
import { newerInput } from '../utils/foundation-freshness.js'
|
|
102
|
+
import { unregisteredLocalTypes } from '../backend/unregistered-types.js'
|
|
103
|
+
import { typesFromLibraries } from '../backend/library-types.js'
|
|
96
104
|
import {
|
|
97
105
|
findWorkspaceRoot,
|
|
98
106
|
findFoundations,
|
|
@@ -188,6 +196,152 @@ function readPkgName(dir) {
|
|
|
188
196
|
}
|
|
189
197
|
}
|
|
190
198
|
|
|
199
|
+
// Whether the account is a member of `scope`: true, false, or null when that can't be told. Read to
|
|
200
|
+
// explain a refusal, never to gate one; a 401 is the credential itself, so it asks nothing.
|
|
201
|
+
async function memberOfScope(res, scope, client) {
|
|
202
|
+
return res.status === 401 ? null : belongsToScope(scope, await client.fetchOrgs().catch(() => null))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Say why the registry refused a submission: a foundation's, a schemas package's, or a library's
|
|
207
|
+
* registered before its foundation.
|
|
208
|
+
*
|
|
209
|
+
* ⭐ NOT A MEMBER OF THE SCOPE IS SAID AS THAT *[Diego, 2026-10-06]*. The registry decides who may
|
|
210
|
+
* release into a scope — its account, or an org's members — and when the orgs read says you are
|
|
211
|
+
* neither, that is the refusal to name. ⛔ Until then a 403 here printed "log in again", the wrong
|
|
212
|
+
* advice for a scope that is not yours.
|
|
213
|
+
*
|
|
214
|
+
* @param {object} o
|
|
215
|
+
* @param {Response} o.res
|
|
216
|
+
* @param {object|null} o.parsedBody
|
|
217
|
+
* @param {string} o.rawBody
|
|
218
|
+
* @param {string} o.scope
|
|
219
|
+
* @param {boolean|null} o.member - `memberOfScope`
|
|
220
|
+
* @param {string} o.what - what was refused, for the not-a-member sentence
|
|
221
|
+
*/
|
|
222
|
+
function sayRefused({ res, parsedBody, rawBody, scope, member, what }) {
|
|
223
|
+
if (member === false) {
|
|
224
|
+
error(`You can't release ${what}: you're not a member of ${scope}.`)
|
|
225
|
+
log(
|
|
226
|
+
` ${colors.dim}A member of ${scope} can release it. (The registry answered HTTP ${res.status}.)${colors.reset}`
|
|
227
|
+
)
|
|
228
|
+
} else {
|
|
229
|
+
error(
|
|
230
|
+
`Registry rejected the submission: HTTP ${res.status} ${res.statusText}`
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
if (member !== false && (res.status === 401 || res.status === 403)) {
|
|
234
|
+
log(
|
|
235
|
+
` ${colors.dim}The registry didn't accept your credentials — it may use different ones than \`uniweb login\`.${colors.reset}`
|
|
236
|
+
)
|
|
237
|
+
log(
|
|
238
|
+
` ${colors.dim}Log in again (uniweb login --server <url>), or check UNIWEB_TOKEN — an existing one may be wrong or expired.${colors.reset}`
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
// ⭐ **Surface `detail` as a sentence, not as a JSON dump.** The registry
|
|
242
|
+
// answers with problem+json (RFC 9457), and its `detail` is written for a
|
|
243
|
+
// human — it carries the actual next step, which for a rejected
|
|
244
|
+
// re-register is "bump the version". Printing the whole body dimmed put
|
|
245
|
+
// that sentence inside a blob, at the end of a 500-char truncation, in the
|
|
246
|
+
// one moment the reader most needs it.
|
|
247
|
+
//
|
|
248
|
+
// ⚖️ Keyed on the SHAPE, not on any particular code: a new refusal the CLI
|
|
249
|
+
// has never seen explains itself the day the backend ships it, with no
|
|
250
|
+
// release here. That is the property worth having — this branch exists
|
|
251
|
+
// because a 422 the CLI did not know about arrived exactly that way.
|
|
252
|
+
if (parsedBody?.detail) {
|
|
253
|
+
log(` ${parsedBody.detail}`)
|
|
254
|
+
const code = parsedBody.code ?? parsedBody.reason
|
|
255
|
+
if (code) {
|
|
256
|
+
log(` ${colors.dim}(${code})${colors.reset}`)
|
|
257
|
+
}
|
|
258
|
+
} else if (rawBody) {
|
|
259
|
+
log(` ${colors.dim}${rawBody.slice(0, 500)}${colors.reset}`)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Register the data schemas a library defines, before the foundation that names them
|
|
265
|
+
* (`backend/library-types.js`): the library's package whole, as `uniweb register` there sends it.
|
|
266
|
+
*
|
|
267
|
+
* ⚖️ A library of a scope the account isn't a member of can't be registered from here, and needn't
|
|
268
|
+
* be once its types are: the foundation is released against them as the registry holds them, which
|
|
269
|
+
* only that scope's members change. A library made by another org, kept in this workspace, is used
|
|
270
|
+
* so.
|
|
271
|
+
*
|
|
272
|
+
* @param {{ dir: string, scope: string, refs: string[] }} lib - its folder, scope, and the types the
|
|
273
|
+
* foundation names from it
|
|
274
|
+
* @param {object} o
|
|
275
|
+
* @param {BackendClient} o.client
|
|
276
|
+
* @param {object} o.exporter - the `.uwx` envelope's exporter
|
|
277
|
+
* @param {string} o.at - its folder as the person sees it
|
|
278
|
+
* @returns {Promise<{ names: string[], body: object|null }|null>} the names sent and the registry's
|
|
279
|
+
* answer; null when the release stops, which is said already
|
|
280
|
+
*/
|
|
281
|
+
async function registerLibraryTypes(lib, { client, exporter, at }) {
|
|
282
|
+
let doc
|
|
283
|
+
try {
|
|
284
|
+
doc = buildSchemaOnlyPackage({
|
|
285
|
+
schemas: await collectStandaloneSchemas(lib.dir),
|
|
286
|
+
scope: lib.scope,
|
|
287
|
+
exporter
|
|
288
|
+
})
|
|
289
|
+
} catch (err) {
|
|
290
|
+
error(`Could not read the data schemas in ${at}: ${err.message}`)
|
|
291
|
+
return null
|
|
292
|
+
}
|
|
293
|
+
const names = doc.entities.map((e) => e.name)
|
|
294
|
+
info(`Registering the data schemas in ${at} (${names.join(', ')}) …`)
|
|
295
|
+
let res
|
|
296
|
+
try {
|
|
297
|
+
res = await client.register(JSON.stringify(doc, null, 2))
|
|
298
|
+
} catch (err) {
|
|
299
|
+
error(`Could not reach the registry at ${client.origin}: ${err.message}`)
|
|
300
|
+
return null
|
|
301
|
+
}
|
|
302
|
+
const rawBody = await res.text().catch(() => '')
|
|
303
|
+
let body = null
|
|
304
|
+
try {
|
|
305
|
+
body = rawBody ? JSON.parse(rawBody) : null
|
|
306
|
+
} catch {
|
|
307
|
+
body = null
|
|
308
|
+
}
|
|
309
|
+
if (res.ok) {
|
|
310
|
+
const answers = Array.isArray(body?.data_schemas) ? body.data_schemas : []
|
|
311
|
+
if (answers.length === names.length && answers.every((a) => a?.unchanged === true)) {
|
|
312
|
+
log(` ${colors.dim}Unchanged: the registry holds them as they are.${colors.reset}`)
|
|
313
|
+
} else {
|
|
314
|
+
success(`Registered ${names.length} data schema(s) under ${lib.scope}, from ${at}`)
|
|
315
|
+
}
|
|
316
|
+
return { names, body }
|
|
317
|
+
}
|
|
318
|
+
const member = await memberOfScope(res, lib.scope, client)
|
|
319
|
+
if (member === false) {
|
|
320
|
+
const held = await Promise.all(
|
|
321
|
+
lib.refs.map((ref) => client.readDataSchema(ref).catch(() => undefined))
|
|
322
|
+
)
|
|
323
|
+
if (held.every(Boolean)) {
|
|
324
|
+
const one = lib.refs.length === 1
|
|
325
|
+
info(
|
|
326
|
+
`${lib.refs.join(', ')} ${one ? 'is' : 'are'} registered under ${lib.scope}, whose members change ${one ? 'it' : 'them'}: the foundation is released against ${one ? 'it' : 'them'} as registered.`
|
|
327
|
+
)
|
|
328
|
+
return { names: [], body: null }
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
sayRefused({
|
|
332
|
+
res,
|
|
333
|
+
parsedBody: body,
|
|
334
|
+
rawBody,
|
|
335
|
+
scope: lib.scope,
|
|
336
|
+
member,
|
|
337
|
+
what: `data schemas under ${lib.scope}`
|
|
338
|
+
})
|
|
339
|
+
log(
|
|
340
|
+
` ${colors.dim}The foundation was not submitted: the registry takes a foundation only once the types it names are registered.${colors.reset}`
|
|
341
|
+
)
|
|
342
|
+
return null
|
|
343
|
+
}
|
|
344
|
+
|
|
191
345
|
/**
|
|
192
346
|
* Resolve which foundation to register: the cwd if it's a foundation, else the
|
|
193
347
|
* single foundation in the workspace, else prompt (or error in non-interactive).
|
|
@@ -731,6 +885,18 @@ async function runRegister(args = []) {
|
|
|
731
885
|
}
|
|
732
886
|
}
|
|
733
887
|
|
|
888
|
+
// ⭐ The types it names that a library defines: registered from the library before the
|
|
889
|
+
// foundation, which the registry refuses while a type it names is missing (`library-types.js`).
|
|
890
|
+
const fromLibraries = standalone
|
|
891
|
+
? []
|
|
892
|
+
: await typesFromLibraries({
|
|
893
|
+
named: Object.keys(schema?.dataSchemas || {}),
|
|
894
|
+
foundationDir: targetDir
|
|
895
|
+
}).catch(() => [])
|
|
896
|
+
// Where each is, said from the workspace root, which is where its person is.
|
|
897
|
+
const workspaceRoot = standalone ? null : findWorkspaceRoot(targetDir) || targetDir
|
|
898
|
+
const shownAt = (dir) => `${relative(workspaceRoot, dir) || '.'}/`
|
|
899
|
+
|
|
734
900
|
// A schemas-only package with no scope, on a real submit → the workspace you work in,
|
|
735
901
|
// else derived from your orgs (`deriveScopeFromLogin`), and persisted to package.json.
|
|
736
902
|
// (A foundation's was settled before its build — `settleFoundationScope`.)
|
|
@@ -805,6 +971,11 @@ async function runRegister(args = []) {
|
|
|
805
971
|
log(
|
|
806
972
|
` ${colors.dim}data schemas ${standalone ? 'registered' : 'defined'}: ${defined.length ? defined.join(', ') : '(none)'}${colors.reset}`
|
|
807
973
|
)
|
|
974
|
+
for (const lib of fromLibraries) {
|
|
975
|
+
log(
|
|
976
|
+
` ${colors.dim}data schemas from ${shownAt(lib.dir)}: ${lib.refs.join(', ')} — ${isPreview ? 'would be registered' : 'registered'} from there first${colors.reset}`
|
|
977
|
+
)
|
|
978
|
+
}
|
|
808
979
|
if (scope)
|
|
809
980
|
log(` ${colors.dim}scope: ${scope} (${scopeSource})${colors.reset}`)
|
|
810
981
|
if (digest) log(` ${colors.dim}digest: ${digest}${colors.reset}`)
|
|
@@ -848,6 +1019,14 @@ async function runRegister(args = []) {
|
|
|
848
1019
|
)
|
|
849
1020
|
return { exitCode: 2 }
|
|
850
1021
|
}
|
|
1022
|
+
// The libraries' types first: the registry checks a foundation's types when it takes it.
|
|
1023
|
+
const fromLibrariesSent = []
|
|
1024
|
+
for (const lib of fromLibraries) {
|
|
1025
|
+
const sent = await registerLibraryTypes(lib, { client, exporter, at: shownAt(lib.dir) })
|
|
1026
|
+
if (!sent) return { exitCode: 1 }
|
|
1027
|
+
fromLibrariesSent.push(sent)
|
|
1028
|
+
}
|
|
1029
|
+
|
|
851
1030
|
// Submit — the client carries the bearer (UNIWEB_TOKEN › stored
|
|
852
1031
|
// session › login), resolved lazily on this first authed call.
|
|
853
1032
|
info(`Submitting to ${colors.dim}${client.origin}${colors.reset} …`)
|
|
@@ -892,53 +1071,37 @@ async function runRegister(args = []) {
|
|
|
892
1071
|
`${colors.dim}Schema for this version is already registered — resuming code delivery.${colors.reset}`
|
|
893
1072
|
)
|
|
894
1073
|
} else {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
const what = standalone
|
|
1074
|
+
const member = await memberOfScope(res, scope, client)
|
|
1075
|
+
sayRefused({
|
|
1076
|
+
res,
|
|
1077
|
+
parsedBody,
|
|
1078
|
+
rawBody,
|
|
1079
|
+
scope,
|
|
1080
|
+
member,
|
|
1081
|
+
what: standalone
|
|
904
1082
|
? `data schemas under ${scope}`
|
|
905
1083
|
: doc.entities.find((e) => e.model === '@uniweb/foundation-schema')?.info?.name || `a foundation under ${scope}`
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
// re-register is "bump the version". Printing the whole body dimmed put
|
|
927
|
-
// that sentence inside a blob, at the end of a 500-char truncation, in the
|
|
928
|
-
// one moment the reader most needs it.
|
|
929
|
-
//
|
|
930
|
-
// ⚖️ Keyed on the SHAPE, not on any particular code: a new refusal the CLI
|
|
931
|
-
// has never seen explains itself the day the backend ships it, with no
|
|
932
|
-
// release here. That is the property worth having — this branch exists
|
|
933
|
-
// because a 422 the CLI did not know about arrived exactly that way.
|
|
934
|
-
if (parsedBody?.detail) {
|
|
935
|
-
log(` ${parsedBody.detail}`)
|
|
936
|
-
const code = parsedBody.code ?? parsedBody.reason
|
|
937
|
-
if (code) {
|
|
938
|
-
log(` ${colors.dim}(${code})${colors.reset}`)
|
|
1084
|
+
})
|
|
1085
|
+
// ⭐ A type it names that another foundation here defines, and the registry doesn't hold:
|
|
1086
|
+
// that foundation registers it first (`unregistered-types.js`). A library's were sent above.
|
|
1087
|
+
if (!standalone && member !== false) {
|
|
1088
|
+
const missing = await unregisteredLocalTypes({
|
|
1089
|
+
named: Object.keys(schema?.dataSchemas || {}),
|
|
1090
|
+
defined,
|
|
1091
|
+
foundationDir: targetDir,
|
|
1092
|
+
client
|
|
1093
|
+
}).catch(() => [])
|
|
1094
|
+
if (missing.length) {
|
|
1095
|
+
// ⚖️ From the workspace root: `push` and `publish` run this in the foundation's folder,
|
|
1096
|
+
// which is not where their person is.
|
|
1097
|
+
const root = findWorkspaceRoot(targetDir) || targetDir
|
|
1098
|
+
log('')
|
|
1099
|
+
for (const { ref, dir } of missing) {
|
|
1100
|
+
const at = relative(root, dir) || '.'
|
|
1101
|
+
log(` ${ref} is defined in ${at}/, which has not registered it. Register it there first, from the workspace root:`)
|
|
1102
|
+
log(` ${colors.blue}cd ${at} && npx uniweb register${colors.reset}`)
|
|
1103
|
+
}
|
|
939
1104
|
}
|
|
940
|
-
} else if (rawBody) {
|
|
941
|
-
log(` ${colors.dim}${rawBody.slice(0, 500)}${colors.reset}`)
|
|
942
1105
|
}
|
|
943
1106
|
return { exitCode: 1 }
|
|
944
1107
|
}
|
|
@@ -1078,7 +1241,12 @@ async function runRegister(args = []) {
|
|
|
1078
1241
|
parsedBody.data_schemas.forEach(addMint)
|
|
1079
1242
|
if (parsedBody.foundation_schema) addMint(parsedBody.foundation_schema)
|
|
1080
1243
|
}
|
|
1244
|
+
for (const sent of fromLibrariesSent) {
|
|
1245
|
+
if (Array.isArray(sent.body?.data_schemas)) sent.body.data_schemas.forEach(addMint)
|
|
1246
|
+
}
|
|
1081
1247
|
const names = [
|
|
1248
|
+
// A library's types, registered first (and none for one registered by its own scope's members).
|
|
1249
|
+
...fromLibrariesSent.flatMap((sent) => sent.names),
|
|
1082
1250
|
...doc.entities
|
|
1083
1251
|
.filter((e) => e.model === '@uniweb/data-schema')
|
|
1084
1252
|
.map((e) => e.name),
|
package/src/commands/status.js
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
import { execFileSync } from 'node:child_process'
|
|
46
|
-
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
46
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
47
47
|
import { basename, dirname, join, posix, relative, resolve, sep } from 'node:path'
|
|
48
48
|
import yaml from 'js-yaml'
|
|
49
49
|
|
|
@@ -1169,6 +1169,92 @@ function workspaceLine(ws) {
|
|
|
1169
1169
|
return `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)} in this workspace${from}.`
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* ⭐ THE LIBRARY `cwd` IS IN, when it is one: a package of the workspace that is neither a site nor a
|
|
1174
|
+
* foundation, and that a foundation or an extension of the workspace bundles (`librariesOf`, the one
|
|
1175
|
+
* rule). With the foundations that bundle it and the sites each serves, which is what a change in it
|
|
1176
|
+
* reaches. Null for anything else, which `status` answers as before.
|
|
1177
|
+
*/
|
|
1178
|
+
async function libraryAround(cwd) {
|
|
1179
|
+
const root = findWorkspaceRoot(cwd)
|
|
1180
|
+
if (!root) return null
|
|
1181
|
+
let dir = resolve(cwd)
|
|
1182
|
+
while (!existsSync(join(dir, 'package.json')) && dir !== root && dirname(dir) !== dir) dir = dirname(dir)
|
|
1183
|
+
if (dir === resolve(root) || !existsSync(join(dir, 'package.json'))) return null
|
|
1184
|
+
if (await classifyPackage(dir)) return null
|
|
1185
|
+
const { librariesOf } = await import('@uniweb/build')
|
|
1186
|
+
let real = dir
|
|
1187
|
+
try {
|
|
1188
|
+
real = realpathSync(dir)
|
|
1189
|
+
} catch {
|
|
1190
|
+
// as it is
|
|
1191
|
+
}
|
|
1192
|
+
const ws = await workspaceFacts(root)
|
|
1193
|
+
const bundling = [
|
|
1194
|
+
...ws.foundations.map((f) => ({ ...f, extension: false })),
|
|
1195
|
+
...ws.extensions.map((f) => ({ ...f, extension: true }))
|
|
1196
|
+
].filter((f) => librariesOf(resolve(root, f.path)).some((lib) => lib.dir === real))
|
|
1197
|
+
if (!bundling.length) return null
|
|
1198
|
+
let name = basename(dir)
|
|
1199
|
+
try {
|
|
1200
|
+
name = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).name || name
|
|
1201
|
+
} catch {
|
|
1202
|
+
// named for its folder
|
|
1203
|
+
}
|
|
1204
|
+
const foundations = []
|
|
1205
|
+
for (const f of bundling) {
|
|
1206
|
+
const abs = resolve(root, f.path)
|
|
1207
|
+
const sites = []
|
|
1208
|
+
for (const site of ws.sites) {
|
|
1209
|
+
const siteDir = resolve(root, site.path)
|
|
1210
|
+
const yml = readSiteYml(siteDir)
|
|
1211
|
+
if (f.extension) {
|
|
1212
|
+
const exts = await extensionsOf(siteDir, yml, root)
|
|
1213
|
+
if (exts.some((e) => e.kind === 'local' && resolve(root, e.path) === abs)) sites.push(site.path)
|
|
1214
|
+
} else {
|
|
1215
|
+
const fnd = await foundationOf(siteDir, yml, root)
|
|
1216
|
+
if (fnd.kind === 'local' && fnd.abs === abs) sites.push(site.path)
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
foundations.push({ name: f.name, path: f.path, extension: f.extension, sites })
|
|
1220
|
+
}
|
|
1221
|
+
return { root, path: relative(root, dir) || '.', name, foundations }
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/** `status` in a library: what bundles it, and so what a change in it reaches. */
|
|
1225
|
+
function libraryOverview(lib, { json }) {
|
|
1226
|
+
const { path, name, foundations } = lib
|
|
1227
|
+
const kinds = foundations.some((f) => f.extension) ? 'foundations and extensions' : 'foundations'
|
|
1228
|
+
const summary = `${name} — a library in ${path}/, bundled by ${count(foundations.length, foundations.some((f) => f.extension) ? 'package' : 'foundation')}`
|
|
1229
|
+
const sites = [...new Set(foundations.flatMap((f) => f.sites))]
|
|
1230
|
+
const reach =
|
|
1231
|
+
'A change here reaches each of those sites when its foundation next builds, and a hosted site when its foundation releases again (`uniweb publish` from the site).'
|
|
1232
|
+
if (json) {
|
|
1233
|
+
console.log(
|
|
1234
|
+
JSON.stringify({
|
|
1235
|
+
schema: STATUS_SCHEMA,
|
|
1236
|
+
uniweb: getCliVersion(),
|
|
1237
|
+
scope: 'library',
|
|
1238
|
+
summary,
|
|
1239
|
+
library: { name, path },
|
|
1240
|
+
foundations,
|
|
1241
|
+
sites,
|
|
1242
|
+
checks: [],
|
|
1243
|
+
next: []
|
|
1244
|
+
})
|
|
1245
|
+
)
|
|
1246
|
+
return { exitCode: 0 }
|
|
1247
|
+
}
|
|
1248
|
+
const out = ['', `${c.bold}${summary}${c.reset}`, '']
|
|
1249
|
+
for (const f of foundations) {
|
|
1250
|
+
const what = `${f.extension ? 'extension' : 'foundation'} ${f.name} (${f.path}/)`
|
|
1251
|
+
out.push(` ${what} — ${f.sites.length ? `${f.sites.length === 1 ? 'site' : 'sites'} ${f.sites.join(', ')}` : 'no site in this workspace'}`)
|
|
1252
|
+
}
|
|
1253
|
+
out.push('', sites.length ? reach : `No site in this workspace uses those ${kinds} yet.`, '')
|
|
1254
|
+
console.log(out.join('\n'))
|
|
1255
|
+
return { exitCode: 0 }
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1172
1258
|
/**
|
|
1173
1259
|
* A site's foundation, as the build finds it — the one resolver (`detectFoundationType`), so
|
|
1174
1260
|
* what status names is what the build would build. A catalog ref, which a build refuses, is
|
|
@@ -1265,11 +1351,18 @@ async function projectChecks(siteDir, siteYml) {
|
|
|
1265
1351
|
: `Extension \`${e.value}\` names ${e.name ? `\`${e.name}\`, which no folder here holds` : 'nothing this site can find'}.`
|
|
1266
1352
|
)
|
|
1267
1353
|
if (extensions.some((e) => e.kind === 'unresolved')) state = 'attention'
|
|
1354
|
+
// And the libraries it bundles (`librariesOf`): a change in one reaches this site too.
|
|
1355
|
+
let libraries = []
|
|
1356
|
+
if (fnd.kind === 'local') {
|
|
1357
|
+
const { librariesOf } = await import('@uniweb/build')
|
|
1358
|
+
libraries = librariesOf(fnd.abs).map((lib) => ({ name: lib.name, path: relative(root, lib.dir) || '.' }))
|
|
1359
|
+
}
|
|
1360
|
+
const libraryLines = libraries.map((lib) => `Library ${lib.name}, in ${lib.path}/ — the foundation bundles it, so a change there reaches this site too.`)
|
|
1268
1361
|
checks.push({
|
|
1269
1362
|
id: 'project.foundation',
|
|
1270
1363
|
state,
|
|
1271
1364
|
summary,
|
|
1272
|
-
lines: extensionLines,
|
|
1365
|
+
lines: [...extensionLines, ...libraryLines],
|
|
1273
1366
|
detail: {
|
|
1274
1367
|
kind: fnd.kind,
|
|
1275
1368
|
name: fnd.name ?? null,
|
|
@@ -1277,7 +1370,8 @@ async function projectChecks(siteDir, siteYml) {
|
|
|
1277
1370
|
url: fnd.url ?? null,
|
|
1278
1371
|
editable: fnd.kind === 'local',
|
|
1279
1372
|
sharedWith,
|
|
1280
|
-
extensions: extensions.map(({ value, kind, name, path }) => ({ value, kind, name: name ?? null, path: path ?? null }))
|
|
1373
|
+
extensions: extensions.map(({ value, kind, name, path }) => ({ value, kind, name: name ?? null, path: path ?? null })),
|
|
1374
|
+
libraries
|
|
1281
1375
|
}
|
|
1282
1376
|
})
|
|
1283
1377
|
|
|
@@ -1772,6 +1866,10 @@ export async function status(args = []) {
|
|
|
1772
1866
|
const json = args.includes('--json')
|
|
1773
1867
|
const offline = args.includes('--offline')
|
|
1774
1868
|
|
|
1869
|
+
// In a library, what bundles it: its foundations and their sites.
|
|
1870
|
+
const library = await libraryAround(process.cwd())
|
|
1871
|
+
if (library) return libraryOverview(library, { json })
|
|
1872
|
+
|
|
1775
1873
|
const found = await findSite(process.cwd())
|
|
1776
1874
|
if (!found.siteDir) {
|
|
1777
1875
|
// ⭐ A WORKSPACE OF SEVERAL SITES IS ANSWERED, not refused: what each one is, from its
|
package/src/framework-index.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-10T14:14:47.610Z",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@uniweb/api": {
|
|
6
6
|
"version": "1.7.0"
|
|
7
7
|
},
|
|
8
8
|
"@uniweb/build": {
|
|
9
|
-
"version": "1.20.
|
|
9
|
+
"version": "1.20.7"
|
|
10
10
|
},
|
|
11
11
|
"@uniweb/content-reader": {
|
|
12
12
|
"version": "1.5.9"
|
package/src/index.js
CHANGED
|
@@ -73,6 +73,7 @@ import {
|
|
|
73
73
|
} from './utils/interactive.js'
|
|
74
74
|
import { findWorkspaceRoot } from './utils/workspace.js'
|
|
75
75
|
import { exitWhenDrained } from './utils/exit.js'
|
|
76
|
+
import { staleFrameworkExport, installedVersion } from './utils/stale-export.js'
|
|
76
77
|
import { outliveTheReader } from './utils/closed-reader.js'
|
|
77
78
|
import { isGitRepo } from './utils/git.js'
|
|
78
79
|
|
|
@@ -256,6 +257,18 @@ async function importProjectCommand(modulePath) {
|
|
|
256
257
|
try {
|
|
257
258
|
return await import(modulePath)
|
|
258
259
|
} catch (err) {
|
|
260
|
+
// A @uniweb/* package older than this CLI: an export it needs is not there (`stale-export.js`).
|
|
261
|
+
const stale = staleFrameworkExport(err)
|
|
262
|
+
if (stale) {
|
|
263
|
+
const have = installedVersion(stale.pkg)
|
|
264
|
+
error(
|
|
265
|
+
`This uniweb (${getCliVersion()}) needs a newer ${stale.pkg} than the one installed${have ? ` (${have})` : ''}, ` +
|
|
266
|
+
`which has no \`${stale.name}\`.`
|
|
267
|
+
)
|
|
268
|
+
log(`Bring the project's framework packages to the versions this CLI goes with:`)
|
|
269
|
+
log(` ${colors.cyan}npx uniweb@latest update --yes${colors.reset}`)
|
|
270
|
+
await exitWhenDrained(1)
|
|
271
|
+
}
|
|
259
272
|
if (
|
|
260
273
|
err.code !== 'ERR_MODULE_NOT_FOUND' ||
|
|
261
274
|
!err.message?.includes('@uniweb/')
|
|
@@ -1435,10 +1448,15 @@ async function main() {
|
|
|
1435
1448
|
const recPm = isPnpmAvailable() ? 'pnpm' : pm
|
|
1436
1449
|
|
|
1437
1450
|
if (isBlank) {
|
|
1451
|
+
// ⛔ The install comes first. `add` loads @uniweb/build, which reaches a blank workspace only
|
|
1452
|
+
// with its own install: it is an optional peer of the CLI, so `npx uniweb` and a bare global
|
|
1453
|
+
// install hold none. Until 2026-11-10 these steps put `add project` first, and it stopped with
|
|
1454
|
+
// "Cannot load @uniweb/build, which this command needs" (measured on 1.30.0, 1.31.5, 1.31.6).
|
|
1438
1455
|
log(`Next steps:\n`)
|
|
1439
1456
|
if (!inPlace) log(` ${colors.cyan}cd ${projectName}${colors.reset}`)
|
|
1457
|
+
log(` ${colors.cyan}${installCmd(recPm)}${colors.reset} ${colors.dim}# the build tools \`add\` needs${colors.reset}`)
|
|
1440
1458
|
log(` ${colors.cyan}${prefix} add project${colors.reset}`)
|
|
1441
|
-
log(` ${colors.cyan}${installCmd(recPm)}${colors.reset}`)
|
|
1459
|
+
log(` ${colors.cyan}${installCmd(recPm)}${colors.reset} ${colors.dim}# links what you added${colors.reset}`)
|
|
1442
1460
|
log(
|
|
1443
1461
|
` ${colors.cyan}${runCmd(recPm, 'dev')}${colors.reset} ${colors.dim}# start the dev server${colors.reset}`
|
|
1444
1462
|
)
|
|
@@ -14,11 +14,16 @@ import { spawn } from 'node:child_process'
|
|
|
14
14
|
import { fstatSync } from 'node:fs'
|
|
15
15
|
import { whenDrained } from './exit.js'
|
|
16
16
|
|
|
17
|
+
// What a write says when its reader has gone: EPIPE from a pipe, and from a socket also ENOTCONN or
|
|
18
|
+
// ECONNRESET. ⛔ Until 2026-11-10 only EPIPE was taken for it, and a reader leaving a socket at the
|
|
19
|
+
// wrong moment ended `create` with "Error: write ENOTCONN" (the closed-reader test, once in six runs).
|
|
20
|
+
const READER_GONE = new Set(['EPIPE', 'ENOTCONN', 'ECONNRESET'])
|
|
21
|
+
|
|
17
22
|
/** For the CLI's own process, once, before it prints. Any other write error stays an error. */
|
|
18
23
|
export function outliveTheReader() {
|
|
19
24
|
for (const stream of [process.stdout, process.stderr]) {
|
|
20
25
|
stream.on('error', (err) => {
|
|
21
|
-
if (err.code
|
|
26
|
+
if (!READER_GONE.has(err.code)) throw err
|
|
22
27
|
})
|
|
23
28
|
}
|
|
24
29
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ A @uniweb/* package older than this CLI: an export the CLI imports is not there. It happens
|
|
3
|
+
* when a project's CLI moves without its framework packages, and Node then says only which name is
|
|
4
|
+
* missing. ⛔ Measured 2026-11-10: uniweb 1.31.6 over @uniweb/build 1.20.5 stopped every build with
|
|
5
|
+
* "The requested module '@uniweb/build' does not provide an export named 'librariesOf'".
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
9
|
+
import { dirname, join } from 'node:path'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The framework package and the export it lacks, when `err` is that failure; else null.
|
|
14
|
+
*
|
|
15
|
+
* @param {unknown} err - what an `import()` of a command threw
|
|
16
|
+
* @returns {{ pkg: string, name: string }|null}
|
|
17
|
+
*/
|
|
18
|
+
export function staleFrameworkExport(err) {
|
|
19
|
+
if (!(err instanceof SyntaxError)) return null
|
|
20
|
+
const m = /module '(@uniweb\/[^'/]+)[^']*' does not provide an export named '([^']+)'/.exec(err.message || '')
|
|
21
|
+
return m ? { pkg: m[1], name: m[2] } : null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The installed version of `pkg`, as this module resolves it, or null. */
|
|
25
|
+
export function installedVersion(pkg) {
|
|
26
|
+
try {
|
|
27
|
+
let dir = dirname(fileURLToPath(import.meta.resolve(pkg)))
|
|
28
|
+
while (!existsSync(join(dir, 'package.json')) && dirname(dir) !== dir) dir = dirname(dir)
|
|
29
|
+
return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).version ?? null
|
|
30
|
+
} catch {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -30,8 +30,9 @@ Edit a page or a section type and the page updates as you save. With npm, use `n
|
|
|
30
30
|
This workspace started empty. Add a foundation and a site, then run them:
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
+
pnpm install # the build tools `uniweb add` needs
|
|
33
34
|
npx uniweb add project <name> # a foundation in <name>/src, a site in <name>/site
|
|
34
|
-
pnpm install
|
|
35
|
+
pnpm install # links what you added
|
|
35
36
|
pnpm uniweb dev # prints the address it serves the site at
|
|
36
37
|
```
|
|
37
38
|
{{/if}}
|