-
Notifications
You must be signed in to change notification settings - Fork 237
/
nu_deps.nu
73 lines (60 loc) · 1.91 KB
/
nu_deps.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Go through Nushell dependencies in the first wave and find the right ordering
#
# Recommended usage is via a module which allows you to process the output
# further.
# Extract target-specific dependencies from an opened Cargo.toml
def get-target-dependencies [] {
let target = ($in | get -i target)
mut res = []
if ($target | is-empty) {
return $res
}
for col in ($target | columns) {
let deps = ($target | get -i $col | get -i dependencies)
if not ($deps | is-empty) {
$res ++= ($deps | columns)
}
}
$res
}
# For each Nushell crate in the first publishing wave, open its Cargo.toml and
# gather its dependencies.
def find-deps [] {
ls crates/nu-*/Cargo.toml | get name | each {|toml|
let crate = ($toml | path dirname | path basename)
let data = (open $toml)
mut deps = []
$deps ++= ($data | get -i 'dependencies' | default {} | columns)
$deps ++= ($data | get -i 'dev-dependencies' | default {} | columns)
$deps ++= ($data | get-target-dependencies)
let $deps = ($deps
| where ($it | str starts-with 'nu-')
| where not ($it == 'nu-ansi-term'))
{
'crate': $crate
'dependencies': $deps
}
}
}
# Find the right publish ordering of Nushell crates based on their dependencies
#
# Returns a list which you can process further, e.g.:
# > nu_deps | str join (',' + (char nl))
export def main [] {
let deps = (find-deps)
mut list = []
while ($list | length) < ($deps | length) {
for row in $deps {
mut nsubdeps = 0
for sub_dep in $row.dependencies {
if not ($sub_dep in $list) {
$nsubdeps += 1
}
}
if ($nsubdeps == 0) and ($row.crate not-in $list) {
$list ++= [$row.crate]
}
}
}
$list
}