Skip to content

Commit

Permalink
Merge branch 'nushell:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxiaozhuox authored Jan 27, 2025
2 parents 9655894 + f4c4007 commit 335a577
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.nuon diff=nuon
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: hustcer/[email protected]
with:
version: nightly
version: "0.100.0"

- name: Show Nushell Version
run: version
Expand Down
2 changes: 1 addition & 1 deletion nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def install-scripts [
pkg_dir: path # Package directory
scripts_dir: path # Target directory where to install
--force(-f) # Overwrite already installed scripts
]: list<path> -> nothing {
]: [list<path> -> nothing] {
each {|script|
let src_path = $pkg_dir | path join $script

Expand Down
4 changes: 2 additions & 2 deletions nupm/publish.nu
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export def main [
}
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion nupm/status.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use utils/package.nu [open-package-file list-package-files]
# Display status of a package
export def main [
path?: path # path to the package
] -> record<filename: string> {
]: nothing -> record<filename: string> {
let path = $path | default $env.PWD | path expand

let pkg = open-package-file $path
Expand Down
8 changes: 5 additions & 3 deletions nupm/utils/package.nu
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export def open-package-file [dir: path] {
)
}

# TODO: Verify types of each field

$package
}

# Lists files of a package
#
# This will be useful for file integrity checks
export def list-package-files [pkg_dir: path, pkg: record] -> list<path> {
export def list-package-files [pkg_dir: path, pkg: record]: nothing -> list<path> {
let activation = match $pkg.type {
'module' => $'use ($pkg.name)'
'script' => {
Expand All @@ -60,9 +62,9 @@ export def list-package-files [pkg_dir: path, pkg: record] -> list<path> {
}
}

$files ++= ($pkg.scripts?
$files ++= [($pkg.scripts?
| default []
| each {|script| $pkg_dir | path join $script})
| each {|script| $pkg_dir | path join $script})]

$files
}
6 changes: 3 additions & 3 deletions nupm/utils/registry.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use dirs.nu cache-dir
use log.nu throw-error
use misc.nu [check-cols url hash-file]
use misc.nu [check-cols url hash-file hash-fn]

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

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

open $pkg_file_path | insert hash_mismatch ($new_hash != $row.hash)
}
Expand Down
31 changes: 31 additions & 0 deletions scripts/print-nuon.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env nu

def main [file: path]: [ nothing -> string ] {
if not ($file | path exists) {
error make {
msg: $"(ansi red_bold)file_not_found(ansi reset)",
label: {
text: "no such file",
span: (metadata $file).span,
},
help: $"`($file)` does not exist",
}
}

let content = open --raw $file

let data = try {
$content | from nuon
} catch {
error make {
msg: $"(ansi red_bold)invalid_nuon(ansi reset)",
label: {
text: "could not parse NUON",
span: (metadata $file).span,
},
help: $"`($file)` does not appear to be valid NUON",
}
}

$data | to nuon -i 4
}
7 changes: 1 addition & 6 deletions tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export def nupm-status-module [] {
let files = (nupm status tests/packages/spam_module).files
assert ($files.0 ends-with (
[tests packages spam_module spam_module mod.nu] | path join))
assert ($files.1 ends-with (
assert ($files.1.0 ends-with (
[tests packages spam_module script.nu] | path join))
}
}
Expand Down Expand Up @@ -171,8 +171,3 @@ export def generate-local-registry [] {
assert equal $actual $expected
}
}

export def registry-files-no-newlines [] {
assert (ls tests/packages/registry/*nuon
| all { not (open $in.name --raw | str contains (char nl)) })
}
8 changes: 7 additions & 1 deletion tests/packages/registry/registry.nuon
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
[[name, path, hash]; [spam_custom, spam_custom.nuon, "md5-90c14f51108a3c067d1f1e11f156ca98"], [spam_module, spam_module.nuon, "md5-c14d7a703fb0e587cf19934c5a397619"], [spam_script, spam_script.nuon, "md5-d7724c6282cc7eb878178b79f8617e29"]]
[
[name, path, hash];

[spam_custom, spam_custom.nuon, "md5-7b3a5119d1af5a025dae32bcfc7cab96"],
[spam_module, spam_module.nuon, "md5-618c7c8ed97b423f111790d97bcd8486"],
[spam_script, spam_script.nuon, "md5-ce1b060a68ebb42291e364b5daa6d47a"],
]
2 changes: 1 addition & 1 deletion tests/packages/spam_module/nupm.nuon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name: spam_module,
type: module,
version: "0.1.0"
scripts: script.nu
scripts: [script.nu]
}
5 changes: 5 additions & 0 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ export def print-nupm-env [] {
print $'NU_LIB_DIRS: ($env.NU_LIB_DIRS?)'
print $'NUPM_REGISTRIES: ($env.NUPM_REGISTRIES?)'
}

# turn on pretty diffs for NUON data files
export def set-nuon-diff [] {
git config diff.nuon.textconv (pwd | path join scripts print-nuon.nu)
}

0 comments on commit 335a577

Please sign in to comment.