uniweb 1.31.5 → 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 +5 -5
- package/partials/agents.md +1 -0
- package/partials/guides/data.md +2 -2
- package/partials/guides/foundation.md +12 -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 +400 -0
- package/src/commands/add.js +26 -9
- package/src/commands/build.js +11 -70
- package/src/commands/clone.js +1 -1
- package/src/commands/doctor.js +18 -0
- package/src/commands/publish.js +1 -1
- package/src/commands/push.js +1 -1
- package/src/commands/register.js +233 -95
- package/src/commands/status.js +101 -3
- package/src/framework-index.json +3 -3
- package/src/index.js +33 -2
- package/src/utils/closed-reader.js +6 -1
- package/src/utils/foundation-freshness.js +89 -0
- package/src/utils/placement.js +36 -12
- package/src/utils/stale-export.js +33 -0
- package/templates/workspace/README.md.hbs +2 -1
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
|
)
|
|
@@ -1731,13 +1749,14 @@ ${colors.bright}Options:${colors.reset}
|
|
|
1731
1749
|
add: `
|
|
1732
1750
|
${colors.cyan}${colors.bright}Uniweb Add${colors.reset}
|
|
1733
1751
|
|
|
1734
|
-
Add projects, foundations, sites, extensions, section types, or CI workflows to your workspace.
|
|
1752
|
+
Add projects, foundations, sites, extensions, libraries, section types, or CI workflows to your workspace.
|
|
1735
1753
|
|
|
1736
1754
|
${colors.bright}Usage:${colors.reset}
|
|
1737
1755
|
uniweb add project [name] [options]
|
|
1738
1756
|
uniweb add foundation [name] [options]
|
|
1739
1757
|
uniweb add site [name] [options]
|
|
1740
1758
|
uniweb add extension <name> [options]
|
|
1759
|
+
uniweb add library <name> [options]
|
|
1741
1760
|
uniweb add section <name> [options]
|
|
1742
1761
|
uniweb add ci [options]
|
|
1743
1762
|
uniweb add version <name> [options]
|
|
@@ -1757,6 +1776,14 @@ ${colors.bright}Site Options:${colors.reset}
|
|
|
1757
1776
|
${colors.bright}Extension Options:${colors.reset}
|
|
1758
1777
|
--site <name> Site to wire extension URL into
|
|
1759
1778
|
|
|
1779
|
+
${colors.bright}Library Options:${colors.reset}
|
|
1780
|
+
--foundation <a,b> Foundations that use it: each gets the dependency and the
|
|
1781
|
+
stylesheet import (the workspace's one foundation if omitted;
|
|
1782
|
+
run again with another to wire one more)
|
|
1783
|
+
--schemas A schemas/ folder for the data types its foundations share
|
|
1784
|
+
--scope <@org> The scope those types are named under (default: the one
|
|
1785
|
+
the wired foundations share)
|
|
1786
|
+
|
|
1760
1787
|
${colors.bright}Section Options:${colors.reset}
|
|
1761
1788
|
--foundation <n> Foundation to add section to (prompted if multiple exist)
|
|
1762
1789
|
--in <folder> add version: the folder under pages/ holding the docs (. for all of pages/)
|
|
@@ -1798,6 +1825,9 @@ ${colors.bright}Examples:${colors.reset}
|
|
|
1798
1825
|
uniweb add site blog --foundation marketing # Create ./blog/ wired to marketing
|
|
1799
1826
|
uniweb add extension effects --site site # Create ./effects/ — the folder you name
|
|
1800
1827
|
uniweb add extension extensions/effects # Create ./extensions/effects/
|
|
1828
|
+
uniweb add library libraries/ui --foundation a,b # Create ./libraries/ui/, shared by a and b
|
|
1829
|
+
uniweb add library libraries/ui --foundation c # Wire one more foundation to it
|
|
1830
|
+
uniweb add library shared --schemas --scope @acme # With data types named @acme/<file>
|
|
1801
1831
|
uniweb add section Hero # Create Hero section type
|
|
1802
1832
|
uniweb add section Hero --foundation ui # Target specific foundation
|
|
1803
1833
|
uniweb add section Hero --starter # Starter content for an existing Hero
|
|
@@ -2432,6 +2462,7 @@ ${colors.bright}Add Subcommands:${colors.reset}
|
|
|
2432
2462
|
add foundation [name] Add a foundation (--from, --path, --project)
|
|
2433
2463
|
add site [name] Add a site (--from, --foundation, --path, --project)
|
|
2434
2464
|
add extension <name> Add an extension (--from, --site, --path)
|
|
2465
|
+
add library <name> Add a library foundations share (--foundation, --schemas)
|
|
2435
2466
|
add section <name> Add a section type to a foundation (--foundation, --starter)
|
|
2436
2467
|
add ci Add a CI workflow so every push deploys (--host, --target)
|
|
2437
2468
|
add version Freeze a site's docs as a version beside them (--in, --label)
|
|
@@ -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,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ IS A LOCAL FOUNDATION'S `dist/` OLDER THAN WHAT ITS BUILD READS? One rule, for every verb that
|
|
3
|
+
* uses a built foundation: `uniweb build` from a site, `export`, `deploy --host` and `dev` before
|
|
4
|
+
* they use it (`ensureFoundationFresh`), and `register` before it uploads it
|
|
5
|
+
* (`foundationNeedsBuild`). A build reads:
|
|
6
|
+
* - the foundation's source root, the folder `package.json::main` names (`resolveFoundationSrcPath`:
|
|
7
|
+
* the package itself when flat, `src/` when nested), and the files at its root that shape the
|
|
8
|
+
* build (`package.json`, `vite.config.js`, a legacy `foundation.js` or `meta.js`);
|
|
9
|
+
* - every library it bundles: any local package it depends on (`librariesOf`, `@uniweb/build`),
|
|
10
|
+
* wherever it is linked from.
|
|
11
|
+
* Dot-folders, `node_modules`, and what a foundation's build writes into one (`dist/`, the
|
|
12
|
+
* generated entry) are never sources. A library that is not a foundation keeps its `dist/`, which
|
|
13
|
+
* may be what the foundation imports.
|
|
14
|
+
*
|
|
15
|
+
* Ties count as fresh: a build writes its output after it reads its input, so equal times mean a
|
|
16
|
+
* build in the same millisecond, and on a fresh clone, where whole trees share a time, a tie
|
|
17
|
+
* counted stale would rebuild every foundation once for nothing.
|
|
18
|
+
*
|
|
19
|
+
* ⛔ Until 2026-11-09 only the foundation's own folder was walked, and the two verbs walked it two
|
|
20
|
+
* ways. Measured: with only a library's file changed, `uniweb build` kept the old `dist/`, so the
|
|
21
|
+
* prerendered page showed the old component while the site's JS had the new one; and `register`
|
|
22
|
+
* answered that nothing needed building. ⛔ Until 2026-10-13 `build` walked `<package>/src/`
|
|
23
|
+
* whatever the layout, and a flat package's edits never made it stale.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { existsSync, readdirSync, statSync } from 'node:fs'
|
|
27
|
+
import { join } from 'node:path'
|
|
28
|
+
import { classifyPackage, librariesOf, resolveFoundationSrcPath } from '@uniweb/build'
|
|
29
|
+
|
|
30
|
+
// The files at a foundation's root that shape its build, when its sources are in `src/`.
|
|
31
|
+
const ROOT_FILES = ['package.json', 'vite.config.js', 'foundation.js', 'meta.js']
|
|
32
|
+
|
|
33
|
+
// What a foundation's build writes into the foundation.
|
|
34
|
+
const BUILD_OUTPUT = new Set(['dist', '_entry.generated.js'])
|
|
35
|
+
|
|
36
|
+
/** The first file under `dir` newer than `builtAt`, or null. */
|
|
37
|
+
function newerUnder(dir, builtAt, { skipOutput }) {
|
|
38
|
+
const stack = [dir]
|
|
39
|
+
while (stack.length) {
|
|
40
|
+
const at = stack.pop()
|
|
41
|
+
let entries
|
|
42
|
+
try {
|
|
43
|
+
entries = readdirSync(at, { withFileTypes: true })
|
|
44
|
+
} catch {
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
for (const e of entries) {
|
|
48
|
+
if (e.name.startsWith('.') || e.name === 'node_modules' || (skipOutput && BUILD_OUTPUT.has(e.name))) continue
|
|
49
|
+
const full = join(at, e.name)
|
|
50
|
+
if (e.isDirectory()) {
|
|
51
|
+
stack.push(full)
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
if (!e.isFile()) continue
|
|
55
|
+
try {
|
|
56
|
+
if (statSync(full).mtimeMs > builtAt) return full
|
|
57
|
+
} catch {
|
|
58
|
+
// unreadable: not newer
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The first file a foundation's build reads that is newer than `builtAt`, and the library it is
|
|
67
|
+
* in; null when every one is as old as the build or older.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} foundationDir
|
|
70
|
+
* @param {number} builtAt - the built entry's mtime, epoch ms
|
|
71
|
+
* @returns {{ file: string, library: string|null }|null}
|
|
72
|
+
*/
|
|
73
|
+
export function newerInput(foundationDir, builtAt) {
|
|
74
|
+
for (const f of ROOT_FILES) {
|
|
75
|
+
const p = join(foundationDir, f)
|
|
76
|
+
try {
|
|
77
|
+
if (existsSync(p) && statSync(p).mtimeMs > builtAt) return { file: p, library: null }
|
|
78
|
+
} catch {
|
|
79
|
+
// unreadable: not newer
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const own = newerUnder(resolveFoundationSrcPath(foundationDir), builtAt, { skipOutput: true })
|
|
83
|
+
if (own) return { file: own, library: null }
|
|
84
|
+
for (const { name, dir } of librariesOf(foundationDir)) {
|
|
85
|
+
const file = newerUnder(dir, builtAt, { skipOutput: classifyPackage(dir) === 'foundation' })
|
|
86
|
+
if (file) return { file, library: name }
|
|
87
|
+
}
|
|
88
|
+
return null
|
|
89
|
+
}
|
package/src/utils/placement.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAbsolute, relative, sep } from 'node:path'
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Package placement resolution — shared by `add` and `clone`.
|
|
@@ -33,6 +33,21 @@ function normalizeParent(given, rootDir) {
|
|
|
33
33
|
return { relative: rel.split(sep).join('/') }
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* The folder a package is to be made in, as the root-relative path every consumer expects — or
|
|
38
|
+
* `outsideRoot` when it is not inside the workspace. ⛔ Until 2026-11-09 only `--path` was
|
|
39
|
+
* checked, and a name naming a path was taken as written: `add foundation /tmp/x` made
|
|
40
|
+
* `<workspace>/tmp/x/` while both manifests recorded `/tmp/x` (the split above), and
|
|
41
|
+
* `add foundation ../x` made a package outside the workspace and listed `../x`.
|
|
42
|
+
*/
|
|
43
|
+
function insideRoot(rootDir, path) {
|
|
44
|
+
if (!rootDir) return { relativePath: path }
|
|
45
|
+
const trimmed = String(path).replace(/\/+$/, '')
|
|
46
|
+
const rel = relative(rootDir, resolve(rootDir, trimmed))
|
|
47
|
+
if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return { outsideRoot: trimmed, relativePath: null, packageName: null }
|
|
48
|
+
return { relativePath: rel.split(sep).join('/') }
|
|
49
|
+
}
|
|
50
|
+
|
|
36
51
|
/** Foundation placement defaults (folder `src/`, package `src`). */
|
|
37
52
|
export const FOUNDATION_KIND = {
|
|
38
53
|
defaultDir: 'src',
|
|
@@ -61,6 +76,16 @@ export const EXTENSION_KIND = {
|
|
|
61
76
|
projectSub: null
|
|
62
77
|
}
|
|
63
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Library placement: as an extension's, no defaults. A library always has a name, or a `--path`
|
|
81
|
+
* naming its folder, and belongs to no one project, so `--project` places none.
|
|
82
|
+
*/
|
|
83
|
+
export const LIBRARY_KIND = {
|
|
84
|
+
defaultDir: null,
|
|
85
|
+
defaultPkg: null,
|
|
86
|
+
projectSub: null
|
|
87
|
+
}
|
|
88
|
+
|
|
64
89
|
/**
|
|
65
90
|
* Resolve where a foundation or site should be placed, given the user's input.
|
|
66
91
|
*
|
|
@@ -110,30 +135,29 @@ export function resolvePlacement(rootDir, name, opts, kind) {
|
|
|
110
135
|
const dir = parent.relative
|
|
111
136
|
if (name) {
|
|
112
137
|
const last = name.split('/').filter(Boolean).pop()
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
packageName: last
|
|
116
|
-
}
|
|
138
|
+
const at = insideRoot(rootDir, `${dir}/${name}`.replace(/\/+/g, '/'))
|
|
139
|
+
return at.outsideRoot ? at : { relativePath: at.relativePath, packageName: last }
|
|
117
140
|
}
|
|
118
141
|
const lastSegment = dir.split('/').filter(Boolean).pop() || dir
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
packageName: lastSegment
|
|
122
|
-
}
|
|
142
|
+
const at = insideRoot(rootDir, dir)
|
|
143
|
+
return at.outsideRoot ? at : { relativePath: at.relativePath, packageName: lastSegment }
|
|
123
144
|
}
|
|
124
145
|
|
|
125
146
|
// 2. name contains a slash → treat as a path.
|
|
126
147
|
if (name && name.includes('/')) {
|
|
127
|
-
const
|
|
128
|
-
|
|
148
|
+
const at = insideRoot(rootDir, name)
|
|
149
|
+
if (at.outsideRoot) return at
|
|
150
|
+
const lastSegment = at.relativePath.split('/').filter(Boolean).pop()
|
|
129
151
|
return {
|
|
130
|
-
relativePath,
|
|
152
|
+
relativePath: at.relativePath,
|
|
131
153
|
packageName: lastSegment
|
|
132
154
|
}
|
|
133
155
|
}
|
|
134
156
|
|
|
135
157
|
// 3. Bare name.
|
|
136
158
|
if (name) {
|
|
159
|
+
const at = insideRoot(rootDir, name)
|
|
160
|
+
if (at.outsideRoot) return at
|
|
137
161
|
return {
|
|
138
162
|
relativePath: name,
|
|
139
163
|
packageName: name
|
|
@@ -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}}
|