@video-editor/devtools 0.0.1-beta.17
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/bin/check-reactivity.mjs +88 -0
- package/package.json +11 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
const dependencyKeys = [
|
|
5
|
+
'dependencies',
|
|
6
|
+
'devDependencies',
|
|
7
|
+
'optionalDependencies',
|
|
8
|
+
'peerDependencies',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
function readTree() {
|
|
12
|
+
const output = execSync('pnpm list --depth Infinity --json @vue/reactivity', {
|
|
13
|
+
encoding: 'utf8',
|
|
14
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
15
|
+
})
|
|
16
|
+
const data = JSON.parse(output)
|
|
17
|
+
return Array.isArray(data) ? data : [data]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function collectVersions(roots) {
|
|
21
|
+
const versions = new Map()
|
|
22
|
+
|
|
23
|
+
const record = (version, location) => {
|
|
24
|
+
if (!versions.has(version))
|
|
25
|
+
versions.set(version, new Set())
|
|
26
|
+
if (location)
|
|
27
|
+
versions.get(version).add(location)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const visit = (node, trail = []) => {
|
|
31
|
+
if (!node || typeof node !== 'object')
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
for (const key of dependencyKeys) {
|
|
35
|
+
const deps = node[key]
|
|
36
|
+
if (!deps || typeof deps !== 'object')
|
|
37
|
+
continue
|
|
38
|
+
for (const [name, dep] of Object.entries(deps)) {
|
|
39
|
+
const nextTrail = [...trail, name]
|
|
40
|
+
if (name === '@vue/reactivity') {
|
|
41
|
+
const version = dep?.version || dep?.from || 'unknown'
|
|
42
|
+
const location = dep?.path || nextTrail.join(' > ')
|
|
43
|
+
record(version, location)
|
|
44
|
+
}
|
|
45
|
+
visit(dep, nextTrail)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
roots.forEach(root => visit(root))
|
|
51
|
+
|
|
52
|
+
return versions
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function formatVersions(versions) {
|
|
56
|
+
return [...versions.entries()]
|
|
57
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
58
|
+
.map(([version, locations]) => {
|
|
59
|
+
const list = [...locations].sort().join(', ')
|
|
60
|
+
return `${version}${list ? ` (${list})` : ''}`
|
|
61
|
+
})
|
|
62
|
+
.join('\n')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const roots = readTree()
|
|
67
|
+
const versions = collectVersions(roots)
|
|
68
|
+
const versionCount = versions.size
|
|
69
|
+
|
|
70
|
+
if (versionCount === 0) {
|
|
71
|
+
console.warn('[reactivity-check] @vue/reactivity not found in dependency tree.')
|
|
72
|
+
process.exit(1)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (versionCount > 1) {
|
|
76
|
+
console.error('[reactivity-check] multiple @vue/reactivity versions detected:')
|
|
77
|
+
console.error(formatVersions(versions))
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const [[version]] = versions.entries()
|
|
82
|
+
console.log(`[reactivity-check] ok: single @vue/reactivity version (${version}).`)
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('[reactivity-check] failed to inspect dependency tree.')
|
|
86
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
87
|
+
process.exit(1)
|
|
88
|
+
}
|