vlite3 1.5.11 → 1.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/components/Accordion/AccordionContent.vue.js +2 -2
- package/components/CategoryManager/CategoryManager2.vue.js +1 -1
- package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
- package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
- package/components/Dropdown/DropdownMenu.vue.js +1 -1
- package/components/Form/{AccordionView.vue.js → AccordionView2.vue.js} +2 -2
- package/components/Form/Form.vue.js +2 -2
- package/components/Form/index2.vue.js +1 -1
- package/components/NavbarCommandPalette.vue.js +1 -1
- package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
- package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
- package/components/Screen/ScreenFilter.vue.js +1 -1
- package/components/Splitter/Splitter.vue.d.ts +7 -0
- package/components/Splitter/Splitter.vue.js +33 -29
- package/components/Tabes/Tabes.vue.js +2 -2
- package/docs/README.md +17 -0
- package/docs/all-components.md +89 -0
- package/docs/component-index.md +313 -0
- package/docs/components/accordion.md +52 -0
- package/docs/components/alert.md +34 -0
- package/docs/components/app-shell.md +371 -0
- package/docs/components/async-select.md +264 -0
- package/docs/components/attachments-list.md +231 -0
- package/docs/components/avatar-group.md +74 -0
- package/docs/components/avatar-uploader.md +61 -0
- package/docs/components/avatar.md +28 -0
- package/docs/components/badge.md +81 -0
- package/docs/components/barcode.md +42 -0
- package/docs/components/beacon.md +29 -0
- package/docs/components/breadcrumb.md +317 -0
- package/docs/components/button-group.md +35 -0
- package/docs/components/button.md +86 -0
- package/docs/components/calendar.md +95 -0
- package/docs/components/carousel.md +122 -0
- package/docs/components/cart.md +533 -0
- package/docs/components/category-manager.md +269 -0
- package/docs/components/category-menu.md +251 -0
- package/docs/components/charts.md +1456 -0
- package/docs/components/chat.md +330 -0
- package/docs/components/checkbox.md +31 -0
- package/docs/components/chip.md +137 -0
- package/docs/components/choice-box.md +40 -0
- package/docs/components/clipboard.md +105 -0
- package/docs/components/clock.md +70 -0
- package/docs/components/color-picker.md +82 -0
- package/docs/components/command-palette.md +214 -0
- package/docs/components/comment-thread.md +171 -0
- package/docs/components/confirmation-modal.md +50 -0
- package/docs/components/custom-fields-display.md +94 -0
- package/docs/components/custom-fields.md +97 -0
- package/docs/components/data-list.md +93 -0
- package/docs/components/data-table.md +922 -0
- package/docs/components/date-picker.md +58 -0
- package/docs/components/date-range-picker.md +24 -0
- package/docs/components/date-time.md +104 -0
- package/docs/components/dropdown.md +740 -0
- package/docs/components/empty.md +100 -0
- package/docs/components/export-data.md +320 -0
- package/docs/components/file-picker.md +83 -0
- package/docs/components/file-preview.md +42 -0
- package/docs/components/file-tree.md +144 -0
- package/docs/components/footer.md +251 -0
- package/docs/components/forms.md +776 -0
- package/docs/components/gantt-chart.md +767 -0
- package/docs/components/google-login.md +67 -0
- package/docs/components/google-map.md +128 -0
- package/docs/components/heatmap.md +80 -0
- package/docs/components/icon-picker.md +58 -0
- package/docs/components/icon.md +176 -0
- package/docs/components/image-comparison.md +51 -0
- package/docs/components/image-magnifier.md +26 -0
- package/docs/components/import-data.md +521 -0
- package/docs/components/input.md +58 -0
- package/docs/components/invoice.md +339 -0
- package/docs/components/kanban.md +302 -0
- package/docs/components/label.md +25 -0
- package/docs/components/list.md +419 -0
- package/docs/components/masonry.md +55 -0
- package/docs/components/modal.md +133 -0
- package/docs/components/multi-select.md +54 -0
- package/docs/components/navbar.md +403 -0
- package/docs/components/number-input.md +41 -0
- package/docs/components/otp-input.md +68 -0
- package/docs/components/pagination.md +83 -0
- package/docs/components/pan-zoom-viewport.md +245 -0
- package/docs/components/permission-editor.md +322 -0
- package/docs/components/persona.md +56 -0
- package/docs/components/price.md +106 -0
- package/docs/components/pricing-plan.md +68 -0
- package/docs/components/progress-bar.md +53 -0
- package/docs/components/qr-code.md +59 -0
- package/docs/components/rating.md +59 -0
- package/docs/components/rich-text-editor.md +210 -0
- package/docs/components/scale-generator.md +101 -0
- package/docs/components/screen.md +208 -0
- package/docs/components/seo-provider.md +189 -0
- package/docs/components/side-panel.md +94 -0
- package/docs/components/sidebar-menu.md +422 -0
- package/docs/components/skeleton.md +115 -0
- package/docs/components/slider.md +48 -0
- package/docs/components/spinner.md +27 -0
- package/docs/components/splitter.md +97 -0
- package/docs/components/stats.md +234 -0
- package/docs/components/status-chip.md +232 -0
- package/docs/components/switch.md +23 -0
- package/docs/components/tabs.md +335 -0
- package/docs/components/tag-input.md +55 -0
- package/docs/components/textarea.md +31 -0
- package/docs/components/theme-provider.md +130 -0
- package/docs/components/theme-toggle.md +36 -0
- package/docs/components/thumbnail-selector.md +186 -0
- package/docs/components/timeline.md +225 -0
- package/docs/components/toast-notification.md +89 -0
- package/docs/components/tooltip.md +31 -0
- package/docs/components/workbook.md +102 -0
- package/docs/composables/use-theme.md +59 -0
- package/docs/getting-started/setup.md +176 -0
- package/docs/guides/draggable.md +211 -0
- package/docs/guides/internationalization.md +281 -0
- package/docs/guides/performance.md +118 -0
- package/docs/guides/testing-forms.md +154 -0
- package/docs/guides/testing-overlays.md +131 -0
- package/docs/guides/theming.md +124 -0
- package/docs/utilities/search.md +580 -0
- package/docs/utilities/utilities.md +371 -0
- package/docs-manifest.json +339 -0
- package/package.json +6 -15
- package/scripts/generate-docs-manifest.js +207 -0
- package/scripts/sync-docs.js +754 -0
- package/style.css +1 -1
- /package/components/Dropdown/{DropdownMenu2.vue.js → DropdownMenu3.vue.js} +0 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Synchronize bundled vlite3 documentation into the consumer project.
|
|
4
|
+
*
|
|
5
|
+
* Destination: <consumer-root>/docs/vlite3/
|
|
6
|
+
*
|
|
7
|
+
* Invoked automatically via the published package `postinstall` script, or
|
|
8
|
+
* manually as a fallback:
|
|
9
|
+
*
|
|
10
|
+
* npx vlite3-docs
|
|
11
|
+
* node node_modules/vlite3/scripts/sync-docs.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs'
|
|
15
|
+
import os from 'node:os'
|
|
16
|
+
import path from 'node:path'
|
|
17
|
+
import { fileURLToPath } from 'node:url'
|
|
18
|
+
import {
|
|
19
|
+
CONSUMER_MANIFEST_NAME,
|
|
20
|
+
MANAGED_BY,
|
|
21
|
+
PACKAGE_MANIFEST_NAME,
|
|
22
|
+
isValidDocsManifest,
|
|
23
|
+
manifestsEqual,
|
|
24
|
+
readDocsManifest,
|
|
25
|
+
sha256File,
|
|
26
|
+
writeDocsManifest,
|
|
27
|
+
} from './generate-docs-manifest.js'
|
|
28
|
+
|
|
29
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
30
|
+
const __dirname = path.dirname(__filename)
|
|
31
|
+
|
|
32
|
+
const DEST_SEGMENT = path.join('docs', 'vlite3')
|
|
33
|
+
const LOCK_NAME = '.vlite3-docs.lock'
|
|
34
|
+
const STAGING_PREFIX = '.vlite3-staging-'
|
|
35
|
+
const LOCK_STALE_MS = 60_000
|
|
36
|
+
const PACKAGE_NAME = 'vlite3'
|
|
37
|
+
|
|
38
|
+
const isPostinstall = process.env.npm_lifecycle_event === 'postinstall'
|
|
39
|
+
|
|
40
|
+
function logInfo(message) {
|
|
41
|
+
console.log(`vlite3: ${message}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function logWarn(message) {
|
|
45
|
+
console.warn(`vlite3: ${message}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function fail(message, code = 1) {
|
|
49
|
+
console.error(`vlite3: ${message}`)
|
|
50
|
+
if (isPostinstall) {
|
|
51
|
+
// Never fail package installation because documentation sync failed.
|
|
52
|
+
process.exit(0)
|
|
53
|
+
}
|
|
54
|
+
process.exit(code)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isGlobalInstall() {
|
|
58
|
+
const flag = String(process.env.npm_config_global || '').toLowerCase()
|
|
59
|
+
if (flag === 'true' || flag === '1') return true
|
|
60
|
+
if (process.env.npm_config_global_prefix && process.env.npm_config_user_agent?.includes('global')) {
|
|
61
|
+
// Heuristic only; primary signal is npm_config_global.
|
|
62
|
+
}
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function pathContainsNodeModules(absPath) {
|
|
67
|
+
const parts = path.resolve(absPath).split(path.sep)
|
|
68
|
+
return parts.includes('node_modules')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isTempPath(absPath) {
|
|
72
|
+
const normalized = path.resolve(absPath).toLowerCase()
|
|
73
|
+
const tmp = os.tmpdir().toLowerCase()
|
|
74
|
+
if (normalized === tmp || normalized.startsWith(tmp + path.sep)) return true
|
|
75
|
+
return (
|
|
76
|
+
normalized.includes(`${path.sep}npm-cache${path.sep}`) ||
|
|
77
|
+
normalized.includes(`${path.sep}yarn${path.sep}cache${path.sep}`) ||
|
|
78
|
+
normalized.includes(`${path.sep}.pnpm-store${path.sep}`) ||
|
|
79
|
+
normalized.includes(`${path.sep}tmp${path.sep}`) ||
|
|
80
|
+
/\/var\/folders\//i.test(normalized)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolve package root (directory that contains package.json for vlite3).
|
|
86
|
+
* Works for both published layout (scripts/ next to package.json) and repo layout.
|
|
87
|
+
*/
|
|
88
|
+
function resolvePackageRoot() {
|
|
89
|
+
const candidates = [
|
|
90
|
+
path.resolve(__dirname, '..'),
|
|
91
|
+
path.resolve(__dirname, '../..'),
|
|
92
|
+
]
|
|
93
|
+
for (const candidate of candidates) {
|
|
94
|
+
const pkgPath = path.join(candidate, 'package.json')
|
|
95
|
+
if (!fs.existsSync(pkgPath)) continue
|
|
96
|
+
try {
|
|
97
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
98
|
+
if (pkg.name === PACKAGE_NAME) return candidate
|
|
99
|
+
} catch {
|
|
100
|
+
// ignore
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return path.resolve(__dirname, '..')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function readJson(filePath) {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
109
|
+
} catch {
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function declaresDirectDependency(pkg, name = PACKAGE_NAME) {
|
|
115
|
+
if (!pkg || typeof pkg !== 'object') return false
|
|
116
|
+
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
117
|
+
const block = pkg[field]
|
|
118
|
+
if (block && Object.prototype.hasOwnProperty.call(block, name)) return true
|
|
119
|
+
}
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function walkAncestors(startDir) {
|
|
124
|
+
const result = []
|
|
125
|
+
let current = path.resolve(startDir)
|
|
126
|
+
const { root } = path.parse(current)
|
|
127
|
+
while (true) {
|
|
128
|
+
result.push(current)
|
|
129
|
+
if (current === root) break
|
|
130
|
+
const parent = path.dirname(current)
|
|
131
|
+
if (parent === current) break
|
|
132
|
+
current = parent
|
|
133
|
+
}
|
|
134
|
+
return result
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Walk out of a node_modules install path to the nearest project directory.
|
|
139
|
+
* Handles npm/yarn hoisting and pnpm virtual store paths.
|
|
140
|
+
*/
|
|
141
|
+
function emergeFromNodeModules(packageRoot) {
|
|
142
|
+
const normalized = packageRoot.split(path.sep)
|
|
143
|
+
const idx = normalized.lastIndexOf('node_modules')
|
|
144
|
+
if (idx <= 0) return null
|
|
145
|
+
// Prefer the directory that owns the top-level node_modules folder.
|
|
146
|
+
return normalized.slice(0, idx).join(path.sep) || null
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function findDirectDepRoot(startDir) {
|
|
150
|
+
if (!startDir) return null
|
|
151
|
+
for (const dir of walkAncestors(startDir)) {
|
|
152
|
+
if (pathContainsNodeModules(dir)) continue
|
|
153
|
+
if (isTempPath(dir)) continue
|
|
154
|
+
const pkgPath = path.join(dir, 'package.json')
|
|
155
|
+
if (!fs.existsSync(pkgPath)) continue
|
|
156
|
+
const pkg = readJson(pkgPath)
|
|
157
|
+
if (!pkg) continue
|
|
158
|
+
// Never treat the vlite3 package itself as a consumer.
|
|
159
|
+
if (pkg.name === PACKAGE_NAME) continue
|
|
160
|
+
if (declaresDirectDependency(pkg)) return dir
|
|
161
|
+
}
|
|
162
|
+
return null
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function listWorkspacePackageDirs(monoRoot) {
|
|
166
|
+
const pkg = readJson(path.join(monoRoot, 'package.json'))
|
|
167
|
+
/** @type {string[]} */
|
|
168
|
+
const patterns = []
|
|
169
|
+
|
|
170
|
+
if (pkg?.workspaces) {
|
|
171
|
+
if (Array.isArray(pkg.workspaces)) patterns.push(...pkg.workspaces)
|
|
172
|
+
else if (Array.isArray(pkg.workspaces.packages)) patterns.push(...pkg.workspaces.packages)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const pnpmWorkspace = path.join(monoRoot, 'pnpm-workspace.yaml')
|
|
176
|
+
if (fs.existsSync(pnpmWorkspace)) {
|
|
177
|
+
const text = fs.readFileSync(pnpmWorkspace, 'utf8')
|
|
178
|
+
for (const line of text.split('\n')) {
|
|
179
|
+
const match = line.match(/^\s*-\s+['"]?([^'"#]+)['"]?\s*$/)
|
|
180
|
+
if (match) patterns.push(match[1].trim())
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (patterns.length === 0) return []
|
|
185
|
+
|
|
186
|
+
/** @type {Set<string>} */
|
|
187
|
+
const dirs = new Set()
|
|
188
|
+
for (const pattern of patterns) {
|
|
189
|
+
// Support simple glob forms: packages/*, apps/*, packages/**
|
|
190
|
+
const cleaned = pattern.replace(/\\/g, '/').replace(/\/+$/, '')
|
|
191
|
+
if (!cleaned || cleaned.startsWith('!')) continue
|
|
192
|
+
|
|
193
|
+
if (cleaned.endsWith('/**')) {
|
|
194
|
+
const base = cleaned.slice(0, -3)
|
|
195
|
+
collectPackageJsonDirs(path.join(monoRoot, base), dirs, 3)
|
|
196
|
+
continue
|
|
197
|
+
}
|
|
198
|
+
if (cleaned.endsWith('/*')) {
|
|
199
|
+
const base = path.join(monoRoot, cleaned.slice(0, -2))
|
|
200
|
+
if (!fs.existsSync(base) || !fs.statSync(base).isDirectory()) continue
|
|
201
|
+
for (const entry of fs.readdirSync(base, { withFileTypes: true })) {
|
|
202
|
+
if (!entry.isDirectory()) continue
|
|
203
|
+
const candidate = path.join(base, entry.name)
|
|
204
|
+
if (fs.existsSync(path.join(candidate, 'package.json'))) dirs.add(candidate)
|
|
205
|
+
}
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const exact = path.join(monoRoot, cleaned)
|
|
210
|
+
if (fs.existsSync(path.join(exact, 'package.json'))) dirs.add(exact)
|
|
211
|
+
}
|
|
212
|
+
return [...dirs]
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function collectPackageJsonDirs(base, out, depthLeft) {
|
|
216
|
+
if (depthLeft < 0 || !fs.existsSync(base)) return
|
|
217
|
+
let stat
|
|
218
|
+
try {
|
|
219
|
+
stat = fs.lstatSync(base)
|
|
220
|
+
} catch {
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) return
|
|
224
|
+
if (path.basename(base) === 'node_modules') return
|
|
225
|
+
|
|
226
|
+
if (fs.existsSync(path.join(base, 'package.json'))) out.add(base)
|
|
227
|
+
if (depthLeft === 0) return
|
|
228
|
+
|
|
229
|
+
for (const entry of fs.readdirSync(base, { withFileTypes: true })) {
|
|
230
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) continue
|
|
231
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue
|
|
232
|
+
collectPackageJsonDirs(path.join(base, entry.name), out, depthLeft - 1)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function findMonorepoRoot(startDir) {
|
|
237
|
+
for (const dir of walkAncestors(startDir)) {
|
|
238
|
+
if (pathContainsNodeModules(dir)) continue
|
|
239
|
+
if (
|
|
240
|
+
fs.existsSync(path.join(dir, 'pnpm-workspace.yaml')) ||
|
|
241
|
+
fs.existsSync(path.join(dir, 'lerna.json')) ||
|
|
242
|
+
fs.existsSync(path.join(dir, 'nx.json'))
|
|
243
|
+
) {
|
|
244
|
+
return dir
|
|
245
|
+
}
|
|
246
|
+
const pkg = readJson(path.join(dir, 'package.json'))
|
|
247
|
+
if (pkg?.workspaces) return dir
|
|
248
|
+
}
|
|
249
|
+
return null
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @returns {{ roots: string[], reason?: string }}
|
|
254
|
+
*/
|
|
255
|
+
function resolveConsumerRoots(packageRoot) {
|
|
256
|
+
if (isGlobalInstall()) {
|
|
257
|
+
return { roots: [], reason: 'skipped global installation' }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Local source checkout / linked package outside node_modules: not a consumer install.
|
|
261
|
+
if (!pathContainsNodeModules(packageRoot)) {
|
|
262
|
+
return {
|
|
263
|
+
roots: [],
|
|
264
|
+
reason: 'skipped: vlite3 is not installed inside node_modules (not a consumer install)',
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** @type {string[]} */
|
|
269
|
+
const candidates = []
|
|
270
|
+
if (process.env.INIT_CWD) candidates.push(process.env.INIT_CWD)
|
|
271
|
+
if (process.env.npm_config_local_prefix) candidates.push(process.env.npm_config_local_prefix)
|
|
272
|
+
if (process.env.PWD) candidates.push(process.env.PWD)
|
|
273
|
+
try {
|
|
274
|
+
candidates.push(process.cwd())
|
|
275
|
+
} catch {
|
|
276
|
+
// ignore cwd failures in unusual environments
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** @type {Set<string>} */
|
|
280
|
+
const roots = new Set()
|
|
281
|
+
|
|
282
|
+
for (const start of candidates) {
|
|
283
|
+
const found = findDirectDepRoot(start)
|
|
284
|
+
if (found && !pathContainsNodeModules(found) && !isTempPath(found)) {
|
|
285
|
+
roots.add(path.resolve(found))
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (roots.size > 0) return { roots: [...roots] }
|
|
290
|
+
|
|
291
|
+
const emerged = emergeFromNodeModules(packageRoot)
|
|
292
|
+
if (emerged) {
|
|
293
|
+
const found = findDirectDepRoot(emerged)
|
|
294
|
+
if (found && !pathContainsNodeModules(found) && !isTempPath(found)) {
|
|
295
|
+
roots.add(path.resolve(found))
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Hoisted install at a monorepo root that does not itself depend on vlite3:
|
|
299
|
+
// sync into every workspace package that directly declares the dependency.
|
|
300
|
+
if (roots.size === 0) {
|
|
301
|
+
const mono = findMonorepoRoot(emerged)
|
|
302
|
+
if (mono) {
|
|
303
|
+
for (const ws of listWorkspacePackageDirs(mono)) {
|
|
304
|
+
const pkg = readJson(path.join(ws, 'package.json'))
|
|
305
|
+
if (!declaresDirectDependency(pkg)) continue
|
|
306
|
+
if (pkg?.name === PACKAGE_NAME) continue
|
|
307
|
+
if (pathContainsNodeModules(ws) || isTempPath(ws)) continue
|
|
308
|
+
roots.add(path.resolve(ws))
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (roots.size === 0) {
|
|
315
|
+
return {
|
|
316
|
+
roots: [],
|
|
317
|
+
reason:
|
|
318
|
+
'skipped: no consumer project root found that directly depends on vlite3 (transitive-only or unsafe root)',
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return { roots: [...roots] }
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Safely resolve a managed relative path under destRoot.
|
|
327
|
+
* @param {string} destRoot
|
|
328
|
+
* @param {string} relativePath
|
|
329
|
+
*/
|
|
330
|
+
function resolveManagedPath(destRoot, relativePath) {
|
|
331
|
+
if (typeof relativePath !== 'string' || !relativePath || relativePath.includes('\0')) {
|
|
332
|
+
throw new Error(`invalid managed path: ${relativePath}`)
|
|
333
|
+
}
|
|
334
|
+
if (path.isAbsolute(relativePath)) {
|
|
335
|
+
throw new Error(`absolute managed path rejected: ${relativePath}`)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const posix = relativePath.replace(/\\/g, '/')
|
|
339
|
+
const parts = posix.split('/')
|
|
340
|
+
if (parts.some((p) => p === '..' || p === '')) {
|
|
341
|
+
throw new Error(`malformed managed path rejected: ${relativePath}`)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const destRootResolved = path.resolve(destRoot)
|
|
345
|
+
const full = path.resolve(destRootResolved, ...parts)
|
|
346
|
+
const prefix = destRootResolved.endsWith(path.sep)
|
|
347
|
+
? destRootResolved
|
|
348
|
+
: destRootResolved + path.sep
|
|
349
|
+
if (full !== destRootResolved && !full.startsWith(prefix)) {
|
|
350
|
+
throw new Error(`path escapes destination: ${relativePath}`)
|
|
351
|
+
}
|
|
352
|
+
return full
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function ensureNotSymlinkEscape(absPath, root) {
|
|
356
|
+
// Reject if any parent component under root is a symlink pointing outside root.
|
|
357
|
+
const rootResolved = path.resolve(root)
|
|
358
|
+
let current = absPath
|
|
359
|
+
while (current.startsWith(rootResolved)) {
|
|
360
|
+
try {
|
|
361
|
+
const st = fs.lstatSync(current)
|
|
362
|
+
if (st.isSymbolicLink()) {
|
|
363
|
+
const real = fs.realpathSync(current)
|
|
364
|
+
const prefix = rootResolved + path.sep
|
|
365
|
+
if (real !== rootResolved && !real.startsWith(prefix)) {
|
|
366
|
+
throw new Error(`symlink escapes destination: ${absPath}`)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} catch (err) {
|
|
370
|
+
if (err && err.code === 'ENOENT') {
|
|
371
|
+
current = path.dirname(current)
|
|
372
|
+
continue
|
|
373
|
+
}
|
|
374
|
+
throw err
|
|
375
|
+
}
|
|
376
|
+
if (current === rootResolved) break
|
|
377
|
+
const parent = path.dirname(current)
|
|
378
|
+
if (parent === current) break
|
|
379
|
+
current = parent
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function copyFileAtomic(src, dest) {
|
|
384
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
385
|
+
const tmp = `${dest}.${process.pid}.${Date.now()}.tmp`
|
|
386
|
+
fs.copyFileSync(src, tmp)
|
|
387
|
+
fs.renameSync(tmp, dest)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function removeEmptyParents(startDir, stopDir) {
|
|
391
|
+
let current = startDir
|
|
392
|
+
const stop = path.resolve(stopDir)
|
|
393
|
+
while (current.startsWith(stop + path.sep)) {
|
|
394
|
+
try {
|
|
395
|
+
const entries = fs.readdirSync(current)
|
|
396
|
+
if (entries.length > 0) return
|
|
397
|
+
fs.rmdirSync(current)
|
|
398
|
+
} catch {
|
|
399
|
+
return
|
|
400
|
+
}
|
|
401
|
+
current = path.dirname(current)
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function sleepSync(ms) {
|
|
406
|
+
try {
|
|
407
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
|
|
408
|
+
} catch {
|
|
409
|
+
const end = Date.now() + ms
|
|
410
|
+
while (Date.now() < end) {
|
|
411
|
+
// spin
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function acquireLock(lockPath) {
|
|
417
|
+
fs.mkdirSync(path.dirname(lockPath), { recursive: true })
|
|
418
|
+
const started = Date.now()
|
|
419
|
+
while (Date.now() - started < LOCK_STALE_MS) {
|
|
420
|
+
try {
|
|
421
|
+
const fd = fs.openSync(lockPath, 'wx')
|
|
422
|
+
fs.writeFileSync(
|
|
423
|
+
fd,
|
|
424
|
+
JSON.stringify({ pid: process.pid, at: new Date().toISOString() }),
|
|
425
|
+
'utf8'
|
|
426
|
+
)
|
|
427
|
+
fs.closeSync(fd)
|
|
428
|
+
return true
|
|
429
|
+
} catch (err) {
|
|
430
|
+
if (!err || err.code !== 'EEXIST') throw err
|
|
431
|
+
try {
|
|
432
|
+
const st = fs.statSync(lockPath)
|
|
433
|
+
if (Date.now() - st.mtimeMs > LOCK_STALE_MS) {
|
|
434
|
+
fs.unlinkSync(lockPath)
|
|
435
|
+
continue
|
|
436
|
+
}
|
|
437
|
+
} catch {
|
|
438
|
+
// retry
|
|
439
|
+
}
|
|
440
|
+
sleepSync(50)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return false
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function releaseLock(lockPath) {
|
|
447
|
+
try {
|
|
448
|
+
fs.unlinkSync(lockPath)
|
|
449
|
+
} catch {
|
|
450
|
+
// ignore
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function diskMatchesManifest(destRoot, manifest) {
|
|
455
|
+
for (const [rel, meta] of Object.entries(manifest.files)) {
|
|
456
|
+
let abs
|
|
457
|
+
try {
|
|
458
|
+
abs = resolveManagedPath(destRoot, rel)
|
|
459
|
+
} catch {
|
|
460
|
+
return false
|
|
461
|
+
}
|
|
462
|
+
if (!fs.existsSync(abs)) return false
|
|
463
|
+
try {
|
|
464
|
+
if (fs.lstatSync(abs).isSymbolicLink()) return false
|
|
465
|
+
if (sha256File(abs) !== meta.sha256) return false
|
|
466
|
+
} catch {
|
|
467
|
+
return false
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return true
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function hasOwnershipMarker(destRoot) {
|
|
474
|
+
const marker = path.join(destRoot, CONSUMER_MANIFEST_NAME)
|
|
475
|
+
return isValidDocsManifest(readDocsManifest(marker))
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* @param {string} consumerRoot
|
|
480
|
+
* @param {string} packageRoot
|
|
481
|
+
* @param {ReturnType<typeof readDocsManifest>} packageManifest
|
|
482
|
+
*/
|
|
483
|
+
function syncOneConsumer(consumerRoot, packageRoot, packageManifest) {
|
|
484
|
+
const docsSource = path.join(packageRoot, 'docs')
|
|
485
|
+
const destRoot = path.join(consumerRoot, DEST_SEGMENT)
|
|
486
|
+
const markerPath = path.join(destRoot, CONSUMER_MANIFEST_NAME)
|
|
487
|
+
const lockPath = path.join(consumerRoot, 'docs', LOCK_NAME)
|
|
488
|
+
|
|
489
|
+
if (!fs.existsSync(docsSource) || !fs.statSync(docsSource).isDirectory()) {
|
|
490
|
+
logWarn(`bundled docs missing at ${docsSource}; skipped ${consumerRoot}`)
|
|
491
|
+
return { status: 'skipped', reason: 'missing bundled docs' }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (pathContainsNodeModules(destRoot) || destRoot.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
495
|
+
logWarn(`refusing to sync into node_modules path: ${destRoot}`)
|
|
496
|
+
return { status: 'skipped', reason: 'unsafe destination' }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (fs.existsSync(destRoot)) {
|
|
500
|
+
let st
|
|
501
|
+
try {
|
|
502
|
+
st = fs.lstatSync(destRoot)
|
|
503
|
+
} catch (err) {
|
|
504
|
+
logWarn(`cannot inspect ${destRoot}: ${err.message}`)
|
|
505
|
+
return { status: 'error', reason: err.message }
|
|
506
|
+
}
|
|
507
|
+
if (!st.isDirectory()) {
|
|
508
|
+
logWarn(`conflict: ${destRoot} exists and is not a directory; skipped`)
|
|
509
|
+
return { status: 'conflict', reason: 'destination is not a directory' }
|
|
510
|
+
}
|
|
511
|
+
if (!hasOwnershipMarker(destRoot)) {
|
|
512
|
+
logWarn(
|
|
513
|
+
`conflict: ${destRoot} exists without a valid ${CONSUMER_MANIFEST_NAME} ownership marker; refusing to overwrite. Move or remove it, then run: npx vlite3-docs`
|
|
514
|
+
)
|
|
515
|
+
return { status: 'conflict', reason: 'unowned destination' }
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const previous = readDocsManifest(markerPath)
|
|
520
|
+
if (
|
|
521
|
+
previous &&
|
|
522
|
+
manifestsEqual(previous, packageManifest) &&
|
|
523
|
+
diskMatchesManifest(destRoot, packageManifest)
|
|
524
|
+
) {
|
|
525
|
+
logInfo(
|
|
526
|
+
`documentation already up to date (v${packageManifest.packageVersion}) at ${destRoot}`
|
|
527
|
+
)
|
|
528
|
+
return { status: 'noop', dest: destRoot }
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (!acquireLock(lockPath)) {
|
|
532
|
+
logWarn(`could not acquire docs sync lock at ${lockPath}; skipped`)
|
|
533
|
+
return { status: 'skipped', reason: 'lock busy' }
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const stagingRoot = path.join(
|
|
537
|
+
consumerRoot,
|
|
538
|
+
'docs',
|
|
539
|
+
`${STAGING_PREFIX}${process.pid}-${Date.now().toString(36)}`
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
try {
|
|
543
|
+
fs.mkdirSync(stagingRoot, { recursive: true })
|
|
544
|
+
|
|
545
|
+
// Stage the full managed tree + new manifest.
|
|
546
|
+
for (const rel of Object.keys(packageManifest.files)) {
|
|
547
|
+
const src = resolveManagedPath(docsSource, rel)
|
|
548
|
+
const staged = resolveManagedPath(stagingRoot, rel)
|
|
549
|
+
if (!fs.existsSync(src) || !fs.statSync(src).isFile()) {
|
|
550
|
+
throw new Error(`packaged docs file missing: ${rel}`)
|
|
551
|
+
}
|
|
552
|
+
if (fs.lstatSync(src).isSymbolicLink()) {
|
|
553
|
+
throw new Error(`refusing to copy symlink from package docs: ${rel}`)
|
|
554
|
+
}
|
|
555
|
+
fs.mkdirSync(path.dirname(staged), { recursive: true })
|
|
556
|
+
fs.copyFileSync(src, staged)
|
|
557
|
+
const hash = sha256File(staged)
|
|
558
|
+
if (hash !== packageManifest.files[rel].sha256) {
|
|
559
|
+
throw new Error(`checksum mismatch while staging ${rel}`)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const stagedManifest = {
|
|
564
|
+
...packageManifest,
|
|
565
|
+
syncedAt: new Date().toISOString(),
|
|
566
|
+
consumerRoot,
|
|
567
|
+
}
|
|
568
|
+
writeDocsManifest(path.join(stagingRoot, CONSUMER_MANIFEST_NAME), stagedManifest)
|
|
569
|
+
|
|
570
|
+
// Ensure destination directory exists before applying.
|
|
571
|
+
fs.mkdirSync(destRoot, { recursive: true })
|
|
572
|
+
ensureNotSymlinkEscape(destRoot, path.join(consumerRoot, 'docs'))
|
|
573
|
+
|
|
574
|
+
// Copy / replace managed files from staging.
|
|
575
|
+
for (const rel of Object.keys(packageManifest.files)) {
|
|
576
|
+
const staged = resolveManagedPath(stagingRoot, rel)
|
|
577
|
+
const dest = resolveManagedPath(destRoot, rel)
|
|
578
|
+
ensureNotSymlinkEscape(path.dirname(dest), destRoot)
|
|
579
|
+
if (fs.existsSync(dest) && fs.lstatSync(dest).isSymbolicLink()) {
|
|
580
|
+
throw new Error(`refusing to replace symlink at destination: ${rel}`)
|
|
581
|
+
}
|
|
582
|
+
copyFileAtomic(staged, dest)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Remove stale previously-managed files only.
|
|
586
|
+
if (previous && previous.files) {
|
|
587
|
+
for (const rel of Object.keys(previous.files)) {
|
|
588
|
+
if (Object.prototype.hasOwnProperty.call(packageManifest.files, rel)) continue
|
|
589
|
+
if (rel === CONSUMER_MANIFEST_NAME) continue
|
|
590
|
+
let dest
|
|
591
|
+
try {
|
|
592
|
+
dest = resolveManagedPath(destRoot, rel)
|
|
593
|
+
} catch {
|
|
594
|
+
continue
|
|
595
|
+
}
|
|
596
|
+
if (!fs.existsSync(dest)) continue
|
|
597
|
+
try {
|
|
598
|
+
if (fs.lstatSync(dest).isSymbolicLink()) continue
|
|
599
|
+
fs.unlinkSync(dest)
|
|
600
|
+
removeEmptyParents(path.dirname(dest), destRoot)
|
|
601
|
+
} catch (err) {
|
|
602
|
+
logWarn(`failed to remove stale managed file ${rel}: ${err.message}`)
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Write ownership manifest last (atomic replace).
|
|
608
|
+
copyFileAtomic(
|
|
609
|
+
path.join(stagingRoot, CONSUMER_MANIFEST_NAME),
|
|
610
|
+
markerPath
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
logInfo(
|
|
614
|
+
`synced documentation v${packageManifest.packageVersion} → ${destRoot}`
|
|
615
|
+
)
|
|
616
|
+
return { status: 'synced', dest: destRoot, version: packageManifest.packageVersion }
|
|
617
|
+
} finally {
|
|
618
|
+
try {
|
|
619
|
+
fs.rmSync(stagingRoot, { recursive: true, force: true })
|
|
620
|
+
} catch {
|
|
621
|
+
// ignore cleanup errors
|
|
622
|
+
}
|
|
623
|
+
releaseLock(lockPath)
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function loadPackageManifest(packageRoot) {
|
|
628
|
+
const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST_NAME)
|
|
629
|
+
const manifest = readDocsManifest(manifestPath)
|
|
630
|
+
if (!manifest) {
|
|
631
|
+
return {
|
|
632
|
+
ok: false,
|
|
633
|
+
reason: `package docs manifest missing or invalid at ${manifestPath}`,
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return { ok: true, manifest, manifestPath }
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export function syncVlite3Docs(options = {}) {
|
|
640
|
+
const packageRoot = path.resolve(options.packageRoot || resolvePackageRoot())
|
|
641
|
+
|
|
642
|
+
// Consumer installs always live under node_modules. Skip source checkouts /
|
|
643
|
+
// accidental runs from the vlite3 repository itself (unless --cwd is used
|
|
644
|
+
// against an explicit package root that still has a docs bundle).
|
|
645
|
+
if (!options.consumerRoot && !pathContainsNodeModules(packageRoot)) {
|
|
646
|
+
return {
|
|
647
|
+
ok: false,
|
|
648
|
+
reason:
|
|
649
|
+
'skipped: vlite3 is not installed inside node_modules (not a consumer install)',
|
|
650
|
+
results: [],
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const loaded = loadPackageManifest(packageRoot)
|
|
655
|
+
if (!loaded.ok) {
|
|
656
|
+
return { ok: false, reason: loaded.reason, results: [] }
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
let roots
|
|
660
|
+
if (options.consumerRoot) {
|
|
661
|
+
roots = [path.resolve(options.consumerRoot)]
|
|
662
|
+
} else {
|
|
663
|
+
const resolved = resolveConsumerRoots(packageRoot)
|
|
664
|
+
if (resolved.roots.length === 0) {
|
|
665
|
+
return { ok: false, reason: resolved.reason, results: [] }
|
|
666
|
+
}
|
|
667
|
+
roots = resolved.roots
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** @type {Array<Record<string, unknown>>} */
|
|
671
|
+
const results = []
|
|
672
|
+
for (const root of roots) {
|
|
673
|
+
try {
|
|
674
|
+
results.push({ root, ...syncOneConsumer(root, packageRoot, loaded.manifest) })
|
|
675
|
+
} catch (err) {
|
|
676
|
+
logWarn(
|
|
677
|
+
`documentation sync failed for ${root}: ${err?.message || err}` +
|
|
678
|
+
` (destination would be ${path.join(root, DEST_SEGMENT)}). ` +
|
|
679
|
+
`You can retry with: npx vlite3-docs`
|
|
680
|
+
)
|
|
681
|
+
results.push({ root, status: 'error', reason: err?.message || String(err) })
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const hardFailure = results.every((r) => r.status === 'error' || r.status === 'conflict')
|
|
686
|
+
return { ok: !hardFailure, results, packageVersion: loaded.manifest.packageVersion }
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function printHelp() {
|
|
690
|
+
console.log(`vlite3 documentation synchronizer
|
|
691
|
+
|
|
692
|
+
Usage:
|
|
693
|
+
npx vlite3-docs
|
|
694
|
+
node scripts/sync-docs.js [--cwd <projectRoot>] [--help]
|
|
695
|
+
|
|
696
|
+
Copies the documentation bundled with the installed vlite3 package into:
|
|
697
|
+
<project-root>/docs/vlite3/
|
|
698
|
+
|
|
699
|
+
Safe to re-run. Skips when already up to date. Refuses to overwrite an
|
|
700
|
+
unowned docs/vlite3/ directory.
|
|
701
|
+
`)
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function main() {
|
|
705
|
+
const args = process.argv.slice(2)
|
|
706
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
707
|
+
printHelp()
|
|
708
|
+
return
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
let consumerRoot
|
|
712
|
+
const cwdIdx = args.indexOf('--cwd')
|
|
713
|
+
if (cwdIdx !== -1) {
|
|
714
|
+
consumerRoot = args[cwdIdx + 1]
|
|
715
|
+
if (!consumerRoot) fail('missing value for --cwd')
|
|
716
|
+
consumerRoot = path.resolve(consumerRoot)
|
|
717
|
+
const pkg = readJson(path.join(consumerRoot, 'package.json'))
|
|
718
|
+
if (!declaresDirectDependency(pkg)) {
|
|
719
|
+
fail(
|
|
720
|
+
`--cwd ${consumerRoot} does not directly depend on ${PACKAGE_NAME} in package.json`
|
|
721
|
+
)
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const result = syncVlite3Docs({
|
|
726
|
+
consumerRoot,
|
|
727
|
+
packageRoot: resolvePackageRoot(),
|
|
728
|
+
})
|
|
729
|
+
|
|
730
|
+
if (!result.ok && result.results.length === 0) {
|
|
731
|
+
logWarn(result.reason || 'documentation sync skipped')
|
|
732
|
+
if (!isPostinstall) {
|
|
733
|
+
logWarn('Fallback: run this from a project that lists vlite3 as a direct dependency.')
|
|
734
|
+
process.exitCode = 0
|
|
735
|
+
}
|
|
736
|
+
return
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const conflicts = result.results.filter((r) => r.status === 'conflict' || r.status === 'error')
|
|
740
|
+
if (conflicts.length > 0 && !isPostinstall) {
|
|
741
|
+
process.exitCode = 1
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const isMain =
|
|
746
|
+
process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)
|
|
747
|
+
|
|
748
|
+
if (isMain) {
|
|
749
|
+
try {
|
|
750
|
+
main()
|
|
751
|
+
} catch (err) {
|
|
752
|
+
fail(`documentation sync crashed: ${err?.message || err}`)
|
|
753
|
+
}
|
|
754
|
+
}
|