Skip to content

Commit 335a577

Browse files
authored
Merge branch 'nushell:main' into main
2 parents 9655894 + f4c4007 commit 335a577

File tree

12 files changed

+59
-19
lines changed

12 files changed

+59
-19
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.nuon diff=nuon

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
- uses: hustcer/[email protected]
3030
with:
31-
version: nightly
31+
version: "0.100.0"
3232

3333
- name: Show Nushell Version
3434
run: version

nupm/install.nu

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def install-scripts [
1313
pkg_dir: path # Package directory
1414
scripts_dir: path # Target directory where to install
1515
--force(-f) # Overwrite already installed scripts
16-
]: list<path> -> nothing {
16+
]: [list<path> -> nothing] {
1717
each {|script|
1818
let src_path = $pkg_dir | path join $script
1919

nupm/publish.nu

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export def main [
176176
}
177177
}
178178

179-
def guess-url [] -> string {
179+
def guess-url []: nothing -> string {
180180
mut url = (do -i { ^git remote get-url origin | complete } | get stdout)
181181

182182
if ($url | is-empty) {
@@ -191,7 +191,7 @@ def guess-url [] -> string {
191191
$url | str trim
192192
}
193193

194-
def guess-revision [] -> string {
194+
def guess-revision []: nothing -> string {
195195
mut revision = (do -i { ^git describe --tags --abbrev=0 | complete }
196196
| get stdout)
197197

nupm/status.nu

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use utils/package.nu [open-package-file list-package-files]
55
# Display status of a package
66
export def main [
77
path?: path # path to the package
8-
] -> record<filename: string> {
8+
]: nothing -> record<filename: string> {
99
let path = $path | default $env.PWD | path expand
1010

1111
let pkg = open-package-file $path

nupm/utils/package.nu

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ export def open-package-file [dir: path] {
2727
)
2828
}
2929

30+
# TODO: Verify types of each field
31+
3032
$package
3133
}
3234

3335
# Lists files of a package
3436
#
3537
# This will be useful for file integrity checks
36-
export def list-package-files [pkg_dir: path, pkg: record] -> list<path> {
38+
export def list-package-files [pkg_dir: path, pkg: record]: nothing -> list<path> {
3739
let activation = match $pkg.type {
3840
'module' => $'use ($pkg.name)'
3941
'script' => {
@@ -60,9 +62,9 @@ export def list-package-files [pkg_dir: path, pkg: record] -> list<path> {
6062
}
6163
}
6264

63-
$files ++= ($pkg.scripts?
65+
$files ++= [($pkg.scripts?
6466
| default []
65-
| each {|script| $pkg_dir | path join $script})
67+
| each {|script| $pkg_dir | path join $script})]
6668

6769
$files
6870
}

nupm/utils/registry.nu

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use dirs.nu cache-dir
44
use log.nu throw-error
5-
use misc.nu [check-cols url hash-file]
5+
use misc.nu [check-cols url hash-file hash-fn]
66

77
# Columns of a registry file
88
export const REG_COLS = [ name path hash ]
@@ -15,7 +15,7 @@ export def search-package [
1515
package: string # Name of the package
1616
--registry: string # Which registry to use (name or path)
1717
--exact-match # Searched package name must match exactly
18-
] -> table {
18+
]: nothing -> table {
1919
let registries = if (not ($registry | is-empty)) and ($registry in $env.NUPM_REGISTRIES) {
2020
# If $registry is a valid column in $env.NUPM_REGISTRIES, use that
2121
{ $registry : ($env.NUPM_REGISTRIES | get $registry) }
@@ -84,7 +84,7 @@ export def search-package [
8484
http get $url | save --force $pkg_file_path
8585
}
8686

87-
let new_hash = $pkg_file_path | hash-file
87+
let new_hash = open $pkg_file_path | to nuon | hash-fn
8888

8989
open $pkg_file_path | insert hash_mismatch ($new_hash != $row.hash)
9090
}

scripts/print-nuon.nu

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env nu
2+
3+
def main [file: path]: [ nothing -> string ] {
4+
if not ($file | path exists) {
5+
error make {
6+
msg: $"(ansi red_bold)file_not_found(ansi reset)",
7+
label: {
8+
text: "no such file",
9+
span: (metadata $file).span,
10+
},
11+
help: $"`($file)` does not exist",
12+
}
13+
}
14+
15+
let content = open --raw $file
16+
17+
let data = try {
18+
$content | from nuon
19+
} catch {
20+
error make {
21+
msg: $"(ansi red_bold)invalid_nuon(ansi reset)",
22+
label: {
23+
text: "could not parse NUON",
24+
span: (metadata $file).span,
25+
},
26+
help: $"`($file)` does not appear to be valid NUON",
27+
}
28+
}
29+
30+
$data | to nuon -i 4
31+
}

tests/mod.nu

+1-6
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export def nupm-status-module [] {
128128
let files = (nupm status tests/packages/spam_module).files
129129
assert ($files.0 ends-with (
130130
[tests packages spam_module spam_module mod.nu] | path join))
131-
assert ($files.1 ends-with (
131+
assert ($files.1.0 ends-with (
132132
[tests packages spam_module script.nu] | path join))
133133
}
134134
}
@@ -171,8 +171,3 @@ export def generate-local-registry [] {
171171
assert equal $actual $expected
172172
}
173173
}
174-
175-
export def registry-files-no-newlines [] {
176-
assert (ls tests/packages/registry/*nuon
177-
| all { not (open $in.name --raw | str contains (char nl)) })
178-
}

tests/packages/registry/registry.nuon

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
[[name, path, hash]; [spam_custom, spam_custom.nuon, "md5-90c14f51108a3c067d1f1e11f156ca98"], [spam_module, spam_module.nuon, "md5-c14d7a703fb0e587cf19934c5a397619"], [spam_script, spam_script.nuon, "md5-d7724c6282cc7eb878178b79f8617e29"]]
1+
[
2+
[name, path, hash];
3+
4+
[spam_custom, spam_custom.nuon, "md5-7b3a5119d1af5a025dae32bcfc7cab96"],
5+
[spam_module, spam_module.nuon, "md5-618c7c8ed97b423f111790d97bcd8486"],
6+
[spam_script, spam_script.nuon, "md5-ce1b060a68ebb42291e364b5daa6d47a"],
7+
]

tests/packages/spam_module/nupm.nuon

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
name: spam_module,
33
type: module,
44
version: "0.1.0"
5-
scripts: script.nu
5+
scripts: [script.nu]
66
}

toolkit.nu

+5
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ export def print-nupm-env [] {
3131
print $'NU_LIB_DIRS: ($env.NU_LIB_DIRS?)'
3232
print $'NUPM_REGISTRIES: ($env.NUPM_REGISTRIES?)'
3333
}
34+
35+
# turn on pretty diffs for NUON data files
36+
export def set-nuon-diff [] {
37+
git config diff.nuon.textconv (pwd | path join scripts print-nuon.nu)
38+
}

0 commit comments

Comments
 (0)