@uniweb/build 1.20.7 → 1.20.9
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 +8 -8
- package/src/foundation/config.js +4 -0
- package/src/foundation/libraries.js +45 -3
- package/src/foundation/library-imports.js +101 -0
- package/src/foundation/stale-sources.js +79 -24
- package/src/index.js +3 -3
- package/src/resolve-data-schema.js +17 -1
- package/src/site/config.js +12 -1
- package/src/uwx/sync-store.js +3 -1
- package/src/vite-foundation-plugin.js +10 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.9",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"js-yaml": "^4.3.2",
|
|
58
58
|
"sharp": "^0.35.5",
|
|
59
59
|
"yaml": "^2.5.0",
|
|
60
|
-
"@uniweb/content-reader": "~1.5.9",
|
|
61
60
|
"@uniweb/content-writer": "~1.3.1",
|
|
62
|
-
"@uniweb/semantic-parser": "~1.13.2",
|
|
63
|
-
"@uniweb/projections": "~1.2.16",
|
|
64
61
|
"@uniweb/schemas": "~1.7.1",
|
|
65
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/content-reader": "~1.5.9",
|
|
63
|
+
"@uniweb/semantic-parser": "~1.13.2",
|
|
64
|
+
"@uniweb/theming": "~1.3.2",
|
|
65
|
+
"@uniweb/projections": "~1.2.16"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
|
-
"@uniweb/runtime": "~1.5.
|
|
68
|
+
"@uniweb/runtime": "~1.5.8"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@tailwindcss/vite": "^4.0.0",
|
|
75
75
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
76
76
|
"vite-plugin-svgr": "^4.0.0",
|
|
77
|
-
"@uniweb/
|
|
78
|
-
"@uniweb/
|
|
77
|
+
"@uniweb/runtime": "~1.5.8",
|
|
78
|
+
"@uniweb/core": "~1.6.12"
|
|
79
79
|
},
|
|
80
80
|
"peerDependenciesMeta": {
|
|
81
81
|
"vite": {
|
package/src/foundation/config.js
CHANGED
|
@@ -30,6 +30,7 @@ import { nodeEnvDefine } from './node-env.js'
|
|
|
30
30
|
import { foundationScopeDefine } from './scope-define.js'
|
|
31
31
|
import { compactOutput } from './compact-output.js'
|
|
32
32
|
import { resolveFoundationSrcDir } from '../utils/foundation-source-root.js'
|
|
33
|
+
import { libraryImports } from './library-imports.js'
|
|
33
34
|
// The ONE definition. This list used to be re-typed here, and again in
|
|
34
35
|
// vite-foundation-plugin.js — three hand-synced copies of "what a foundation
|
|
35
36
|
// externalizes", with nothing binding them. The failure mode of a drift is not
|
|
@@ -116,6 +117,9 @@ export async function defineFoundationConfig(options = {}) {
|
|
|
116
117
|
// foundationPlugin handles entry generation and schema building
|
|
117
118
|
const plugins = [
|
|
118
119
|
foundationPlugin({ srcDir, sections: sectionPaths }),
|
|
120
|
+
// A library outside the workspace's folder resolves what it imports as this foundation does
|
|
121
|
+
// (`library-imports.js`).
|
|
122
|
+
libraryImports({ foundationDir: foundationRoot }),
|
|
119
123
|
// JSX compiles only in .jsx files: a .js file holding it fails with that said.
|
|
120
124
|
jsxExtensionGuard(),
|
|
121
125
|
nodeEnvDefine(),
|
|
@@ -69,8 +69,8 @@ function libraryDir(fromDir, name, spec) {
|
|
|
69
69
|
* The libraries a package bundles, its libraries' libraries included, each once.
|
|
70
70
|
*
|
|
71
71
|
* @param {string} packageDir - a foundation (or a library)
|
|
72
|
-
* @returns {Array<{ name: string, dir: string }>} each by the name it is depended on
|
|
73
|
-
* real folder; in the order found
|
|
72
|
+
* @returns {Array<{ name: string, dir: string, from: string }>} each by the name it is depended on
|
|
73
|
+
* by, its real folder, and the real folder of the package that depends on it; in the order found
|
|
74
74
|
*/
|
|
75
75
|
export function librariesOf(packageDir) {
|
|
76
76
|
const start = real(packageDir) ?? resolve(packageDir)
|
|
@@ -84,7 +84,7 @@ export function librariesOf(packageDir) {
|
|
|
84
84
|
const lib = libraryDir(dir, name, spec)
|
|
85
85
|
if (!lib || seen.has(lib)) continue
|
|
86
86
|
seen.add(lib)
|
|
87
|
-
found.push({ name, dir: lib })
|
|
87
|
+
found.push({ name, dir: lib, from: dir })
|
|
88
88
|
visit(lib, ['dependencies', 'optionalDependencies'])
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -92,3 +92,45 @@ export function librariesOf(packageDir) {
|
|
|
92
92
|
visit(start, ['dependencies', 'devDependencies', 'optionalDependencies'])
|
|
93
93
|
return found
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* ⭐ A LIBRARY INSTALLED AS A COPY. pnpm copies a `file:` package that is no package of the
|
|
98
|
+
* workspace into its store, hard-linked, so a file added to the library's folder, or one an editor
|
|
99
|
+
* saves by writing a new file over the old, reaches the copy only with the next install: a build
|
|
100
|
+
* then reads code its developer has already changed. Listed in the workspace (`pnpm-workspace.yaml`
|
|
101
|
+
* and `package.json` `workspaces`), the folder is linked instead, wherever it is. Measured
|
|
102
|
+
* 2026-11-10 with pnpm 10.30: `packages: ['../ui']` linked `../ui` and installed its dependencies in
|
|
103
|
+
* its folder. So the builds say which libraries are copies, and the line that makes them links.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} packageDir - a foundation
|
|
106
|
+
* @returns {Array<{ name: string, dir: string, installed: string }>} each library Node finds as a
|
|
107
|
+
* copy from the package that depends on it, with where the copy is
|
|
108
|
+
*/
|
|
109
|
+
export function copiedLibraries(packageDir) {
|
|
110
|
+
const out = []
|
|
111
|
+
for (const lib of librariesOf(packageDir)) {
|
|
112
|
+
const installed = installedAt(lib.from, lib.name)
|
|
113
|
+
if (installed && installed !== lib.dir) out.push({ ...lib, installed })
|
|
114
|
+
}
|
|
115
|
+
return out
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* What a build prints when `copiedLibraries` finds any.
|
|
120
|
+
*
|
|
121
|
+
* @param {Array<{ name: string, dir: string }>} copied
|
|
122
|
+
* @param {string} [workspaceRoot] - where the folders are said from
|
|
123
|
+
*/
|
|
124
|
+
export function copiedLibrariesWarning(copied, workspaceRoot) {
|
|
125
|
+
const at = (dir) => {
|
|
126
|
+
const rel = workspaceRoot ? relative(workspaceRoot, dir).split(sep).join('/') : dir
|
|
127
|
+
return rel || '.'
|
|
128
|
+
}
|
|
129
|
+
const named = copied.map(({ name }) => name).join(', ')
|
|
130
|
+
const many = copied.length > 1
|
|
131
|
+
return [
|
|
132
|
+
`[uniweb] ${named} ${many ? 'are' : 'is'} installed as a copy, so a change to ${many ? 'their folders' : 'its folder'} reaches a build only after the next install. ` +
|
|
133
|
+
`List ${many ? 'each folder' : 'its folder'} in the workspace, and the package manager links ${many ? 'them' : 'it'} instead (\`uniweb add library <folder>\` does):`,
|
|
134
|
+
...copied.map(({ dir }) => ` pnpm-workspace.yaml: - '${at(dir)}'`)
|
|
135
|
+
].join('\n')
|
|
136
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ A LIBRARY OUTSIDE THE WORKSPACE'S FOLDER RESOLVES WHAT IT IMPORTS AS THE FOUNDATION THAT BUNDLES
|
|
3
|
+
* IT. A library is any local package a foundation depends on (`librariesOf`), and one may be a folder
|
|
4
|
+
* beside the workspace, another repository's say. The workspace lists it (`uniweb add library
|
|
5
|
+
* ../acme-shared` writes it into `pnpm-workspace.yaml` and `package.json` `workspaces`), so the
|
|
6
|
+
* package manager links its folder and the build reads the files its developer edits. pnpm also
|
|
7
|
+
* installs its dependencies in its folder; npm hoists them to the workspace's root `node_modules`,
|
|
8
|
+
* which Node never looks in from a folder outside the workspace's. ⛔ Until 2026-11-10 a foundation
|
|
9
|
+
* build under npm stopped there: `Rollup failed to resolve import "@uniweb/kit"` from the library.
|
|
10
|
+
*
|
|
11
|
+
* So whatever builds a foundation's source (its build, its SSR bundle, a site's build and dev
|
|
12
|
+
* server) resolves a bare import from such a library's own file:
|
|
13
|
+
* - its `peerDependencies` from the foundation, which provides them: one React, one kit;
|
|
14
|
+
* - anything else from the library's own install first, then from the foundation's.
|
|
15
|
+
*
|
|
16
|
+
* A library inside the workspace's folder reaches the workspace's installs on its own, so this leaves
|
|
17
|
+
* it alone, and nothing changes for one: measured 2026-11-10, byte-identical builds with and without.
|
|
18
|
+
* A library the package manager copied instead of linking is said by `copiedLibraries`.
|
|
19
|
+
*
|
|
20
|
+
* @module @uniweb/build/foundation/library-imports
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { readFileSync, realpathSync } from 'node:fs'
|
|
24
|
+
import { isAbsolute, join, relative, sep } from 'node:path'
|
|
25
|
+
import { librariesOf } from './libraries.js'
|
|
26
|
+
import { workspaceRootOf } from '../site/workspace-extension.js'
|
|
27
|
+
|
|
28
|
+
const real = (path) => {
|
|
29
|
+
try {
|
|
30
|
+
return realpathSync(path)
|
|
31
|
+
} catch {
|
|
32
|
+
return path
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const readPackage = (dir) => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
39
|
+
} catch {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `@scope/name/sub` → `@scope/name`; `name/sub` → `name`. */
|
|
45
|
+
const packageOf = (id) => (id.startsWith('@') ? id.split('/').slice(0, 2).join('/') : id.split('/')[0])
|
|
46
|
+
|
|
47
|
+
/** A specifier that names a package: not a path, a URL, a virtual module or a subpath import. */
|
|
48
|
+
const isBare = (id) =>
|
|
49
|
+
!!id && !/^[./\\#\0]/.test(id) && !isAbsolute(id) && !/^[a-z][a-z0-9+.-]*:/i.test(id)
|
|
50
|
+
|
|
51
|
+
/** `path` at or inside `dir`. */
|
|
52
|
+
const within = (dir, path) => {
|
|
53
|
+
const rel = relative(dir, path)
|
|
54
|
+
return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `file` inside `dir`, and not in a `node_modules` under it. */
|
|
58
|
+
const insideOwnFiles = (dir, file) => within(dir, file) && !relative(dir, file).split(sep).includes('node_modules')
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The libraries a foundation bundles whose folders are outside its workspace's folder (or, with no
|
|
62
|
+
* workspace, outside the foundation's), each with its peers.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} foundationDir
|
|
65
|
+
* @returns {Array<{ name: string, dir: string, peers: Set<string> }>}
|
|
66
|
+
*/
|
|
67
|
+
export function librariesOutside(foundationDir) {
|
|
68
|
+
const root = real(workspaceRootOf(foundationDir) || foundationDir)
|
|
69
|
+
return librariesOf(foundationDir)
|
|
70
|
+
.filter((lib) => !within(root, lib.dir))
|
|
71
|
+
.map((lib) => ({ ...lib, peers: new Set(Object.keys(readPackage(lib.dir)?.peerDependencies || {})) }))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The Vite plugin, for one foundation's libraries outside its workspace's folder. With none, it
|
|
76
|
+
* resolves nothing.
|
|
77
|
+
*
|
|
78
|
+
* @param {{ foundationDir: string }} options - the foundation whose libraries these are
|
|
79
|
+
* @returns {import('vite').Plugin}
|
|
80
|
+
*/
|
|
81
|
+
export function libraryImports({ foundationDir }) {
|
|
82
|
+
let outside = null
|
|
83
|
+
const all = () => (outside ??= librariesOutside(foundationDir))
|
|
84
|
+
const asFoundation = join(foundationDir, 'package.json')
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
name: 'uniweb:library-imports',
|
|
88
|
+
enforce: 'pre',
|
|
89
|
+
async resolveId(source, importer, options) {
|
|
90
|
+
if (!importer || !isBare(source) || !all().length) return null
|
|
91
|
+
const from = importer.split('?')[0]
|
|
92
|
+
if (!isAbsolute(from)) return null
|
|
93
|
+
const at = real(from)
|
|
94
|
+
const lib = all().find((l) => insideOwnFiles(l.dir, at))
|
|
95
|
+
if (!lib) return null
|
|
96
|
+
const opts = { ...options, skipSelf: true }
|
|
97
|
+
if (lib.peers.has(packageOf(source))) return this.resolve(source, asFoundation, opts)
|
|
98
|
+
return (await this.resolve(source, importer, opts)) ?? this.resolve(source, asFoundation, opts)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -160,7 +160,14 @@ function writesClasses(code) {
|
|
|
160
160
|
const NOT_THE_FOUNDATIONS_CODE = new Set(['node_modules', 'dist', 'public', 'test', 'tests', '__tests__'])
|
|
161
161
|
|
|
162
162
|
function codeFiles(dir, found = []) {
|
|
163
|
-
|
|
163
|
+
let entries
|
|
164
|
+
try {
|
|
165
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
166
|
+
} catch {
|
|
167
|
+
// A folder it may not read is no code it writes: said by nothing, and stopping nothing.
|
|
168
|
+
return found
|
|
169
|
+
}
|
|
170
|
+
for (const entry of entries) {
|
|
164
171
|
if (entry.name.startsWith('.') || NOT_THE_FOUNDATIONS_CODE.has(entry.name)) continue
|
|
165
172
|
const path = join(dir, entry.name)
|
|
166
173
|
if (entry.isDirectory()) codeFiles(path, found)
|
|
@@ -169,8 +176,40 @@ function codeFiles(dir, found = []) {
|
|
|
169
176
|
return found
|
|
170
177
|
}
|
|
171
178
|
|
|
179
|
+
/**
|
|
180
|
+
* The file a library's `exports` gives a subpath (`./styles.css`), or null when the map refuses it.
|
|
181
|
+
* With no map, every file is reachable by its path. A string or an array, or a map of conditions
|
|
182
|
+
* alone, exports `.` only.
|
|
183
|
+
*/
|
|
184
|
+
function exportedFile(libDir, subpath) {
|
|
185
|
+
let pkg = null
|
|
186
|
+
try {
|
|
187
|
+
pkg = JSON.parse(readFileSync(join(libDir, 'package.json'), 'utf8'))
|
|
188
|
+
} catch {
|
|
189
|
+
// no manifest to refuse it
|
|
190
|
+
}
|
|
191
|
+
const exp = pkg?.exports
|
|
192
|
+
if (exp === undefined || exp === null) return join(libDir, subpath)
|
|
193
|
+
if (typeof exp !== 'object' || Array.isArray(exp) || !Object.keys(exp).some((k) => k.startsWith('.'))) return null
|
|
194
|
+
const target = (value) =>
|
|
195
|
+
typeof value === 'string' ? value : value && typeof value === 'object' && !Array.isArray(value) ? [value.style, value.default, value.import].find((v) => typeof v === 'string') ?? null : null
|
|
196
|
+
if (subpath in exp) {
|
|
197
|
+
const t = target(exp[subpath])
|
|
198
|
+
return t ? join(libDir, t) : null
|
|
199
|
+
}
|
|
200
|
+
// A pattern: the longest key whose part before the star the subpath starts with, as Node takes it.
|
|
201
|
+
let best = null
|
|
202
|
+
for (const [key, value] of Object.entries(exp)) {
|
|
203
|
+
const t = target(value)
|
|
204
|
+
if (!key.endsWith('*') || !t?.includes('*')) continue
|
|
205
|
+
const prefix = key.slice(0, -1)
|
|
206
|
+
if (subpath.startsWith(prefix) && (!best || prefix.length > best.prefix.length)) best = { prefix, t }
|
|
207
|
+
}
|
|
208
|
+
return best ? join(libDir, best.t.replace('*', subpath.slice(best.prefix.length))) : null
|
|
209
|
+
}
|
|
210
|
+
|
|
172
211
|
/** The paths a stylesheet's `@source` lines start from, and those of the stylesheets it imports. */
|
|
173
|
-
function pathsRead(file, seen = new Set()) {
|
|
212
|
+
function pathsRead(file, seen = new Set(), libraries = []) {
|
|
174
213
|
if (seen.has(file)) return []
|
|
175
214
|
seen.add(file)
|
|
176
215
|
let css
|
|
@@ -184,13 +223,19 @@ function pathsRead(file, seen = new Set()) {
|
|
|
184
223
|
for (const [, , specifier] of css.matchAll(IMPORT)) {
|
|
185
224
|
// ⛔ Only a `.css` specifier, as in `readByAnImport`.
|
|
186
225
|
if (!specifier.endsWith('.css')) continue
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
226
|
+
// ⭐ A library's stylesheet is read from the library's folder, by its `exports`, so the answer
|
|
227
|
+
// holds before an install too. ⛔ Until 2026-11-10 it was resolved through `node_modules` alone,
|
|
228
|
+
// and in a fresh clone the import a foundation already had was the line it was told to add.
|
|
229
|
+
const lib = libraries.find((l) => specifier.startsWith(`${l.name}/`))
|
|
230
|
+
let imported = lib ? exportedFile(lib.dir, `.${specifier.slice(lib.name.length)}`) : null
|
|
231
|
+
if (!imported || !existsSync(imported)) {
|
|
232
|
+
try {
|
|
233
|
+
imported = require.resolve(specifier)
|
|
234
|
+
} catch {
|
|
235
|
+
continue
|
|
236
|
+
}
|
|
192
237
|
}
|
|
193
|
-
read.push(...pathsRead(imported, seen))
|
|
238
|
+
read.push(...pathsRead(imported, seen, libraries))
|
|
194
239
|
}
|
|
195
240
|
return read
|
|
196
241
|
}
|
|
@@ -264,23 +309,33 @@ export function unreadFoldersWarning(unread) {
|
|
|
264
309
|
].join('\n')
|
|
265
310
|
}
|
|
266
311
|
|
|
267
|
-
/**
|
|
312
|
+
/**
|
|
313
|
+
* The library's own stylesheet, when importing it reads the library: its line, else null. ⛔ An
|
|
314
|
+
* `exports` map that doesn't give `./styles.css` refuses the import, in Tailwind and in Node alike,
|
|
315
|
+
* and so does an `exports` that is a string (until 2026-11-10 that one was read as no map at all).
|
|
316
|
+
*/
|
|
268
317
|
function libraryStylesheetLine(lib) {
|
|
269
|
-
const sheet =
|
|
270
|
-
if (!existsSync(sheet)) return null
|
|
271
|
-
// ⛔ An `exports` map without the stylesheet refuses the import, in Tailwind and in Node alike.
|
|
272
|
-
let pkg = null
|
|
273
|
-
try {
|
|
274
|
-
pkg = JSON.parse(readFileSync(join(lib.dir, 'package.json'), 'utf8'))
|
|
275
|
-
} catch {
|
|
276
|
-
// no manifest to refuse it
|
|
277
|
-
}
|
|
278
|
-
const exp = pkg?.exports
|
|
279
|
-
if (exp && typeof exp === 'object' && !Object.keys(exp).some((k) => k === './styles.css' || k === './*')) return null
|
|
318
|
+
const sheet = exportedFile(lib.dir, './styles.css')
|
|
319
|
+
if (!sheet || !existsSync(sheet)) return null
|
|
280
320
|
const covers = pathsRead(sheet).some((path) => lib.dir === path || lib.dir.startsWith(path + sep))
|
|
281
321
|
return covers ? `@import "${lib.name}/styles.css";` : null
|
|
282
322
|
}
|
|
283
323
|
|
|
324
|
+
/**
|
|
325
|
+
* ⭐ THE LINE THAT HAS A FOUNDATION'S STYLESHEET READ A LIBRARY'S CLASSES: the library's own
|
|
326
|
+
* stylesheet imported, when it reads the library's files and the library exports it, else a
|
|
327
|
+
* `@source` to the library's folder. One rule, which `uniweb add library` writes and
|
|
328
|
+
* `unreadLibraries` names.
|
|
329
|
+
*
|
|
330
|
+
* @param {{ name: string, dir: string }} lib
|
|
331
|
+
* @param {string} stylesDir - the folder of the foundation's `styles.css`
|
|
332
|
+
* @returns {string}
|
|
333
|
+
*/
|
|
334
|
+
export function libraryLine(lib, stylesDir) {
|
|
335
|
+
const rel = relative(stylesDir, lib.dir).split(sep).join('/')
|
|
336
|
+
return libraryStylesheetLine(lib) ?? `@source "${rel.startsWith('.') ? rel : `./${rel}`}";`
|
|
337
|
+
}
|
|
338
|
+
|
|
284
339
|
/**
|
|
285
340
|
* ⭐ The libraries a foundation bundles whose classes no `@source` reads: local packages it depends
|
|
286
341
|
* on (`librariesOf`), outside the stylesheet's folder, that write classes.
|
|
@@ -312,9 +367,10 @@ export function unreadLibraries(stylesPath, packageDir) {
|
|
|
312
367
|
if (!USES_TAILWIND.test(css)) return []
|
|
313
368
|
|
|
314
369
|
const dir = dirname(stylesheet)
|
|
315
|
-
const
|
|
370
|
+
const libraries = librariesOf(packageDir)
|
|
371
|
+
const read = pathsRead(stylesheet, new Set(), libraries)
|
|
316
372
|
const unread = []
|
|
317
|
-
for (const lib of
|
|
373
|
+
for (const lib of libraries) {
|
|
318
374
|
if (lib.dir === dir || lib.dir.startsWith(dir + sep)) continue
|
|
319
375
|
if (read.some((path) => lib.dir === path || lib.dir.startsWith(path + sep) || path.startsWith(lib.dir + sep))) continue
|
|
320
376
|
let files = 0
|
|
@@ -322,8 +378,7 @@ export function unreadLibraries(stylesPath, packageDir) {
|
|
|
322
378
|
if (writesClasses(withoutComments(readFileSync(file, 'utf8')))) files++
|
|
323
379
|
}
|
|
324
380
|
if (!files) continue
|
|
325
|
-
|
|
326
|
-
unread.push({ name: lib.name, files, line: libraryStylesheetLine(lib) ?? `@source "${rel.startsWith('.') ? rel : `./${rel}`}";` })
|
|
381
|
+
unread.push({ name: lib.name, files, line: libraryLine(lib, dir) })
|
|
327
382
|
}
|
|
328
383
|
return unread
|
|
329
384
|
}
|
package/src/index.js
CHANGED
|
@@ -85,17 +85,17 @@ export {
|
|
|
85
85
|
|
|
86
86
|
// Foundation source root resolution (reads package.json::main)
|
|
87
87
|
export { resolveFoundationSrcDir, resolveFoundationSrcPath } from './utils/foundation-source-root.js'
|
|
88
|
-
export { staleSources, staleSourceNote, unreadFolders, unreadLibraries } from './foundation/stale-sources.js'
|
|
88
|
+
export { staleSources, staleSourceNote, unreadFolders, unreadLibraries, libraryLine } from './foundation/stale-sources.js'
|
|
89
89
|
|
|
90
90
|
// A library is any local package a foundation depends on: the one rule for what else a foundation's
|
|
91
91
|
// build reads, which the CLI's freshness check asks
|
|
92
|
-
export { librariesOf } from './foundation/libraries.js'
|
|
92
|
+
export { librariesOf, copiedLibraries, copiedLibrariesWarning } from './foundation/libraries.js'
|
|
93
93
|
|
|
94
94
|
// Package classification (foundation vs site vs standalone schemas package)
|
|
95
95
|
export { classifyPackage, isExtensionPackage, isSchemasPackage } from './utils/classify-package.js'
|
|
96
96
|
|
|
97
97
|
// Standalone schemas-package discovery (the foundation-less register input)
|
|
98
|
-
export { collectStandaloneSchemas } from './resolve-data-schema.js'
|
|
98
|
+
export { collectStandaloneSchemas, routedSchema } from './resolve-data-schema.js'
|
|
99
99
|
|
|
100
100
|
// One name in a scope is one type: the names a workspace's packages define twice
|
|
101
101
|
export { typesDefinedTwice, packageTypeScope, workspaceTypeFiles } from './foundation/shared-types.js'
|
|
@@ -294,7 +294,7 @@ export async function resolveSchemaRef(ref, { srcDir, aliases }) {
|
|
|
294
294
|
throw new Error(
|
|
295
295
|
`Data schema '${ref}' is defined by ${inWorkspace.length} packages this foundation reads: ` +
|
|
296
296
|
`${inWorkspace.join(', ')}. A type has one definition: keep one file, and name the type in ` +
|
|
297
|
-
`full in the others (\`uniweb doctor\` lists
|
|
297
|
+
`full in the others (\`uniweb doctor\` lists the types the workspace's packages define twice).`
|
|
298
298
|
)
|
|
299
299
|
}
|
|
300
300
|
if (inWorkspace.length === 1) return normalizeNamedSchema(await loadSchemaFile(inWorkspace[0]), ref)
|
|
@@ -532,6 +532,22 @@ function findSchemaFileInDir(dir, name) {
|
|
|
532
532
|
* @param {string} srcDir - Foundation source root (where main.js lives).
|
|
533
533
|
* @returns {Promise<Record<string, string>>}
|
|
534
534
|
*/
|
|
535
|
+
/**
|
|
536
|
+
* Whether the foundation's `schemas.config.js` routes `ref`: the type to a file, or its scope to a
|
|
537
|
+
* folder. A routed type is read from where the route says, ahead of the workspace, a library or a
|
|
538
|
+
* package (`resolveSchemaRef`), so whatever asks which package defines a type asks this first.
|
|
539
|
+
*
|
|
540
|
+
* @param {string} ref - `@scope/name`
|
|
541
|
+
* @param {string} srcDir - the foundation's source folder, which holds `schemas.config.js`
|
|
542
|
+
* @returns {Promise<boolean>}
|
|
543
|
+
*/
|
|
544
|
+
export async function routedSchema(ref, srcDir) {
|
|
545
|
+
const m = /^@([^/]+)\/(.+)$/.exec(ref || '')
|
|
546
|
+
if (!m) return false
|
|
547
|
+
const aliases = await loadSchemaAliases(srcDir)
|
|
548
|
+
return !!(aliases[ref] || aliases[`@${m[1]}`])
|
|
549
|
+
}
|
|
550
|
+
|
|
535
551
|
async function loadSchemaAliases(srcDir) {
|
|
536
552
|
const file = join(srcDir, 'schemas.config.js')
|
|
537
553
|
if (!existsSync(file)) return {}
|
package/src/site/config.js
CHANGED
|
@@ -38,6 +38,9 @@ import { resolveFoundationSrcPath } from '../utils/foundation-source-root.js'
|
|
|
38
38
|
import { checkFoundationResolution } from '../utils/foundation-resolution-check.js'
|
|
39
39
|
import { detectFoundationType } from './foundation-ref.js'
|
|
40
40
|
import { librariesOf } from '../foundation/libraries.js'
|
|
41
|
+
import { libraryImports } from '../foundation/library-imports.js'
|
|
42
|
+
import { copiedLibraries, copiedLibrariesWarning } from '../foundation/libraries.js'
|
|
43
|
+
import { workspaceRootOf } from './workspace-extension.js'
|
|
41
44
|
import { readPreview, PREVIEW_ENV } from './preview.js'
|
|
42
45
|
import { previewMediaPlugin } from './preview-media.js'
|
|
43
46
|
import { previewDirectoryIndexPlugin } from './preview-directory-index.js'
|
|
@@ -302,9 +305,12 @@ export async function defineSiteConfig(options = {}) {
|
|
|
302
305
|
// missing, in a site build and under `uniweb dev`, while its own build has them all.
|
|
303
306
|
const unread = unreadFolders(join(srcDir, 'styles.css'))
|
|
304
307
|
if (unread.length) console.warn(unreadFoldersWarning(unread))
|
|
305
|
-
// And a library it bundles that no `@source` reads, whose classes no CSS has
|
|
308
|
+
// And a library it bundles that no `@source` reads, whose classes no CSS has, or one the
|
|
309
|
+
// package manager copied, which a change to its folder doesn't reach.
|
|
306
310
|
const libraries = unreadLibraries(join(srcDir, 'styles.css'), foundationInfo.path)
|
|
307
311
|
if (libraries.length) console.warn(unreadLibrariesWarning(libraries))
|
|
312
|
+
const copied = copiedLibraries(foundationInfo.path)
|
|
313
|
+
if (copied.length) console.warn(copiedLibrariesWarning(copied, workspaceRootOf(foundationInfo.path)))
|
|
308
314
|
}
|
|
309
315
|
},
|
|
310
316
|
|
|
@@ -336,9 +342,14 @@ export async function defineSiteConfig(options = {}) {
|
|
|
336
342
|
} : null
|
|
337
343
|
|
|
338
344
|
// Build the plugins array
|
|
345
|
+
// ⭐ A library of the bundled foundation outside the workspace's folder resolves what it imports as
|
|
346
|
+
// the foundation does (`library-imports.js`).
|
|
347
|
+
const bundledFoundation = !isRuntimeMode && foundationInfo.type === 'local' && foundationInfo.path ? foundationInfo.path : null
|
|
348
|
+
|
|
339
349
|
const plugins = [
|
|
340
350
|
// Ensure foundation entry exists first (bundled mode only)
|
|
341
351
|
ensureFoundationEntryPlugin,
|
|
352
|
+
bundledFoundation && libraryImports({ foundationDir: bundledFoundation }),
|
|
342
353
|
|
|
343
354
|
// Standard plugins
|
|
344
355
|
// JSX compiles only in .jsx files — a bundled foundation's too.
|
package/src/uwx/sync-store.js
CHANGED
|
@@ -47,8 +47,10 @@ const VERSION = 1
|
|
|
47
47
|
* uuid too, each entry the data schema the backend holds it as, written whole from each folder the
|
|
48
48
|
* backend hands back (`setBackendMap`), so it names what the folder places. `retired` is the same
|
|
49
49
|
* shape: the records a push took out of the folder, which the backend keeps until they are deleted.
|
|
50
|
+
* `deleting` too: retired records this copy chose to delete that the backend kept, because another
|
|
51
|
+
* site's folder still placed them; a later push deletes them once none does (`retired-records.js`).
|
|
50
52
|
*/
|
|
51
|
-
const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files', 'types', 'retired'])
|
|
53
|
+
const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files', 'types', 'retired', 'deleting'])
|
|
52
54
|
|
|
53
55
|
const storePath = (siteDir) => join(siteDir, SYNC_STORE_FILE)
|
|
54
56
|
|
|
@@ -22,6 +22,9 @@ import { nodeEnvDefine } from './foundation/node-env.js'
|
|
|
22
22
|
import { foundationScopeDefine } from './foundation/scope-define.js'
|
|
23
23
|
import { ssrDormantDynamicImports } from './foundation/ssr-dormant-imports.js'
|
|
24
24
|
import { compactOutput } from './foundation/compact-output.js'
|
|
25
|
+
import { libraryImports } from './foundation/library-imports.js'
|
|
26
|
+
import { copiedLibraries, copiedLibrariesWarning } from './foundation/libraries.js'
|
|
27
|
+
import { workspaceRootOf } from './site/workspace-extension.js'
|
|
25
28
|
import { DEV_REBUILD_MARKER, hasDevRebuildMarker } from './foundation/dev-rebuild.js'
|
|
26
29
|
|
|
27
30
|
// Foundations already told that their prose has no stylesheet — once per process, so a dev
|
|
@@ -364,7 +367,7 @@ async function buildEntrySSR(foundationRoot, entrySourcePath, outDir) {
|
|
|
364
367
|
const svgr = (await import('vite-plugin-svgr')).default
|
|
365
368
|
// ssrDormantDynamicImports: a package imported dynamically stays `import('pkg')`, dormant,
|
|
366
369
|
// rather than folded in to run at load (see its module).
|
|
367
|
-
plugins.push(react(), svgr(), nodeEnvDefine(), foundationScopeDefine({ foundationDir: foundationRoot }), ssrDormantDynamicImports(), compactOutput())
|
|
370
|
+
plugins.push(libraryImports({ foundationDir: foundationRoot }), react(), svgr(), nodeEnvDefine(), foundationScopeDefine({ foundationDir: foundationRoot }), ssrDormantDynamicImports(), compactOutput())
|
|
368
371
|
|
|
369
372
|
await viteBuild({
|
|
370
373
|
root: foundationRoot,
|
|
@@ -471,13 +474,14 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
471
474
|
}
|
|
472
475
|
|
|
473
476
|
// A library it bundles whose classes no `@source` reads: missing from this CSS, which a hosted
|
|
474
|
-
// site loads with the foundation, and from a site build's (`unreadLibraries`).
|
|
477
|
+
// site loads with the foundation, and from a site build's (`unreadLibraries`). And one the
|
|
478
|
+
// package manager copied, which a change to its folder doesn't reach (`copiedLibraries`).
|
|
475
479
|
if (!warnedUnreadLibraries.has(resolvedSrcDir)) {
|
|
476
480
|
const unread = unreadLibraries(join(resolvedSrcDir, 'styles.css'), resolvedRoot)
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
+
const copied = copiedLibraries(resolvedRoot)
|
|
482
|
+
if (unread.length || copied.length) warnedUnreadLibraries.add(resolvedSrcDir)
|
|
483
|
+
if (unread.length) console.warn(unreadLibrariesWarning(unread, { build: 'foundation' }))
|
|
484
|
+
if (copied.length) console.warn(copiedLibrariesWarning(copied, workspaceRootOf(resolvedRoot)))
|
|
481
485
|
}
|
|
482
486
|
|
|
483
487
|
// What host services this foundation actually reaches for, read off the
|