From ec563fbe5565f22efb607630ed755da95939db03 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sat, 18 Oct 2025 19:19:35 +0330 Subject: [PATCH 01/12] feat: add `--git` and `--branch` flag --- nupm/install.nu | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 213582b..a5961f2 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -227,6 +227,28 @@ def fetch-package [ } } +# Fetch a package from a git repository (clone into a temp-directory) +def fetch-package-git [ + package: string # Git URL + --branch: string # Branch or tag name + --depth: int = 5 # Shallow clone depth +]: nothing -> path { + let target_dir = (mktemp --directory) + mut clone_args = ["clone", $package, "--depth", $depth] + + if $branch { + $clone_args = ($clone_args | append ["--branch", $branch]) + } + + if ($env.NUPM_GIT_CLONE_ARGS? | length) > 0 { + $clone_args = ($clone_args | append $env.NUPM_GIT_CLONE_ARGS?) + } + + $clone_args = ($clone_args | append [$target_dir]) + git ...$clone_args + return $target_dir +} + # Install a nupm package # # Installation consists of two parts: @@ -240,19 +262,22 @@ export def main [ --path # Install package from a directory with nupm.nuon given by 'name' --force(-f) # Overwrite already installed package --no-confirm # Allows to bypass the interactive confirmation, useful for scripting + --git # Install package from remote git repository, (shorthand for git clone + install) + --branch # Branch or tag name to pull ]: nothing -> nothing { if not (nupm-home-prompt --no-confirm=$no_confirm) { return } - - let pkg: path = if not $path { - fetch-package $package --registry $registry --version $pkg_version - } else { - if $pkg_version != null { + + let pkg: path = if $path { + if $pkg_version != null { throw-error "Use only --path or --pkg-version, not both" } - $package + } else if $git { + fetch-package-git $package --branch $branch + } else { + fetch-package $package --registry $registry --version $pkg_version } install-path $pkg --force=$force From c5365fe70b42920069d0d3788363f2c9d5879bc5 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sat, 18 Oct 2025 19:23:01 +0330 Subject: [PATCH 02/12] docs: update doc to cover new `--git` flag on `install` subcommand --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 761e5d3..5597adc 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,12 @@ git clone https://github.com/nushell/foo.git nupm install foo --path ``` +or + +```nushell +nupm install https://github.com/nushell/foo.git --git +``` + ### update a package [[toc](#table-of-content)] Assuming the repository is already cloned, you can update the module package with the following: From 3c0d89e0955f73616601f1c330ccc70ba9c93901 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sat, 18 Oct 2025 20:26:03 +0330 Subject: [PATCH 03/12] fix: `branch` argument type --- nupm/install.nu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index a5961f2..0424356 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -236,7 +236,7 @@ def fetch-package-git [ let target_dir = (mktemp --directory) mut clone_args = ["clone", $package, "--depth", $depth] - if $branch { + if ($branch | is-not-empty) { $clone_args = ($clone_args | append ["--branch", $branch]) } @@ -263,7 +263,7 @@ export def main [ --force(-f) # Overwrite already installed package --no-confirm # Allows to bypass the interactive confirmation, useful for scripting --git # Install package from remote git repository, (shorthand for git clone + install) - --branch # Branch or tag name to pull + --branch: string # Branch or tag name to pull ]: nothing -> nothing { if not (nupm-home-prompt --no-confirm=$no_confirm) { return From f1cc662b7a6a49801d07a109f6a9bc65c0428433 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sun, 19 Oct 2025 11:21:27 +0330 Subject: [PATCH 04/12] minor: add `nupm-module` suffix to temp feat: shallow clone depth can be set using `NUPM_GIT_CLONE_DEPTH` env var --- nupm/install.nu | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 0424356..a9361a6 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -231,9 +231,10 @@ def fetch-package [ def fetch-package-git [ package: string # Git URL --branch: string # Branch or tag name - --depth: int = 5 # Shallow clone depth ]: nothing -> path { - let target_dir = (mktemp --directory) + let target_dir = (mktemp --directory --suffix "nupm-module") + let depth = ($env.NUPM_GIT_CLONE_DEPTH? | default 1) + mut clone_args = ["clone", $package, "--depth", $depth] if ($branch | is-not-empty) { @@ -270,7 +271,7 @@ export def main [ } let pkg: path = if $path { - if $pkg_version != null { + if $pkg_version != null { throw-error "Use only --path or --pkg-version, not both" } $package From 1ebab7a5f034e0d7f7bf6a6d6d524feb615059e4 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sun, 19 Oct 2025 11:30:02 +0330 Subject: [PATCH 05/12] tests: add test for `--git` installation --- tests/mod.nu | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/mod.nu b/tests/mod.nu index ddb2af1..5c710fc 100644 --- a/tests/mod.nu +++ b/tests/mod.nu @@ -65,6 +65,15 @@ export def install-custom [] { } } + +export def install-custom-git [] { + with-test-env { + nupm install --git https://github.com/nushell/nupm.git + + assert installed [modules nupm] + } +} + export def install-from-local-registry [] { with-test-env { $env.NUPM_REGISTRIES = {} From 8b8c9e3e7a710c91adc52bfcc6b57f46742400ad Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sun, 19 Oct 2025 21:12:24 +0330 Subject: [PATCH 06/12] feat: add `revision` arg to git clone add `directory` arg to git-clone --- nupm/install.nu | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index a9361a6..b210b06 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -231,23 +231,42 @@ def fetch-package [ def fetch-package-git [ package: string # Git URL --branch: string # Branch or tag name + --directory: path # Target directory to clone into + --revision: string # Revision to checkout to ]: nothing -> path { - let target_dir = (mktemp --directory --suffix "nupm-module") let depth = ($env.NUPM_GIT_CLONE_DEPTH? | default 1) - - mut clone_args = ["clone", $package, "--depth", $depth] + mut clone_args = ["clone", $package] + + if ($revision | is-empty) { + $clone_args = ($clone_args | append [$"--depth=($depth)"]) + } if ($branch | is-not-empty) { - $clone_args = ($clone_args | append ["--branch", $branch]) + $clone_args = ($clone_args | append [$"--branch=($branch)"]) } if ($env.NUPM_GIT_CLONE_ARGS? | length) > 0 { $clone_args = ($clone_args | append $env.NUPM_GIT_CLONE_ARGS?) } - $clone_args = ($clone_args | append [$target_dir]) - git ...$clone_args - return $target_dir + $clone_args = ($clone_args | append [$directory]) + try { + git ...$clone_args + } catch { + throw-error $'Error cloning repository ($package)' + } + + if ($revision | is-not-empty) { + { + cd $directory + try { + git checkout $revision + } catch { + throw-error $'Error checking out revision ($revision)' + } + } + } + return $directory } # Install a nupm package From 3c45975047d735d4056a8f19c2d1f9846e67c4b9 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Sun, 19 Oct 2025 21:14:04 +0330 Subject: [PATCH 07/12] refactor: streamline git cloning process with new `git-clone` function --- nupm/install.nu | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index b210b06..6a3b84c 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -162,19 +162,11 @@ def download-pkg [ } try { - git clone $pkg.info.url $clone_dir + git-clone $pkg.info.url --revision=$pkg.info.revision --directory=$clone_dir } catch { throw-error $'Error cloning repository ($pkg.info.url)' } - cd $clone_dir - - try { - git checkout $pkg.info.revision - } catch { - throw-error $'Error checking out revision ($pkg.info.revision)' - } - if not ($pkg_dir | path exists) { throw-error $'Path ($pkg_dir) does not exist' } @@ -228,7 +220,7 @@ def fetch-package [ } # Fetch a package from a git repository (clone into a temp-directory) -def fetch-package-git [ +def git-clone [ package: string # Git URL --branch: string # Branch or tag name --directory: path # Target directory to clone into @@ -295,7 +287,7 @@ export def main [ } $package } else if $git { - fetch-package-git $package --branch $branch + git-clone $package --branch=$branch --directory=(tmp-dir git-clone --ensure) } else { fetch-package $package --registry $registry --version $pkg_version } From 86695ddb20de142dcad5eb794c2d245054b3fd40 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Mon, 20 Oct 2025 09:15:59 +0330 Subject: [PATCH 08/12] feat: added `assert` helper --- nupm/utils/log.nu | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nupm/utils/log.nu b/nupm/utils/log.nu index 4982e35..adf5e15 100644 --- a/nupm/utils/log.nu +++ b/nupm/utils/log.nu @@ -26,6 +26,17 @@ export def throw-error [ } } +export def assert [ + condition: bool + error: string + text?: string + --span: record +] { + if not $condition { + throw-error $error $text --span=$span + } +} + # Append a formatted help line to mimic `error make` in core export def append-help [help_msg: string]: string -> string { $in + $"\n (ansi cyan)help:(ansi reset) " + $help_msg From b0a6c54cb23b34e9cdf93c1531f8b9d2d38a8754 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Mon, 20 Oct 2025 09:54:34 +0330 Subject: [PATCH 09/12] swapped `if not then throw` with `assert` --- nupm/install.nu | 87 +++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 6a3b84c..9a8c817 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -1,6 +1,6 @@ use utils/completions.nu complete-registries use utils/dirs.nu [ nupm-home-prompt cache-dir module-dir script-dir tmp-dir PACKAGE_FILENAME ] -use utils/log.nu throw-error +use utils/log.nu [throw-error assert] use utils/misc.nu [check-cols hash-fn url] use utils/package.nu open-package-file use utils/registry.nu search-package @@ -17,20 +17,19 @@ def install-scripts [ each {|script| let src_path = $pkg_dir | path join $script - if ($src_path | path type) != file { - throw-error "script_not_found" $"Script ($src_path) does not exist" - } - - if (($scripts_dir - | path join ($script | path basename) - | path type) == file - and (not $force) - ) { - throw-error "package_already_installed" ( - $"Script ($src_path) is already installed in" - + $" ($scripts_dir). Use `--force` to override the package." - ) - } + assert (($src_path | path type) == file) "script_not_found" $"Script ($src_path) does not exist" + + ( + assert ($force + or ( + $scripts_dir + | path join ($script | path basename) + | path type + ) != file + ) + "package_already_installed" + $"Script ($src_path) is already installed in ($scripts_dir). Use `--force` to override the package." + ) log debug $"installing script `($src_path)` to `($scripts_dir)`" cp $src_path $scripts_dir @@ -134,10 +133,11 @@ def download-pkg [ > ]: nothing -> path { # TODO: Add some kind of hashing to check that files really match - - if ($pkg.type != 'git') { - throw-error 'Downloading non-git packages is not supported yet' - } + ( + assert ($pkg.type != 'git') + "package_type_not_supported" + "Downloading non-git packages is not supported yet" + ) let cache_dir = cache-dir --ensure cd $cache_dir @@ -167,9 +167,11 @@ def download-pkg [ throw-error $'Error cloning repository ($pkg.info.url)' } - if not ($pkg_dir | path exists) { - throw-error $'Path ($pkg_dir) does not exist' - } + ( + assert (not ($pkg_dir | path exists)) + "invalid_package_path" + $'Package path ($pkg.path) does not exist in cloned repository' + ) $pkg_dir } @@ -182,12 +184,16 @@ def fetch-package [ ]: nothing -> path { let regs = search-package $package --registry $registry --exact-match - if ($regs | is-empty) { - throw-error $'Package ($package) not found in any registry' - } else if ($regs | length) > 1 { - # TODO: Here could be interactive prompt - throw-error $'Multiple registries contain package ($package)' - } + ( + assert (not ($regs | is-empty)) + "package_not_found" + $'Package ($package) not found in any registry' + ) + ( + assert (($regs | length) == 1) + "multiple_registries_found" + $'Multiple registries contain package ($package)' + ) # Now, only one registry contains the package let reg = $regs | first @@ -198,11 +204,11 @@ def fetch-package [ } catch { throw-error $'No package matching version `($version)`' } - - if $pkg.hash_mismatch == true { - throw-error ($'Content of package file ($pkg.path)' - + $' does not match expected hash') - } + ( + assert ($pkg.hash_mismatch == false) + "package_hash_mismatch" + ($'Content of package file ($pkg.path) does not match expected hash') + ) print $pkg @@ -226,6 +232,17 @@ def git-clone [ --directory: path # Target directory to clone into --revision: string # Revision to checkout to ]: nothing -> path { + ( + assert (($directory | path type | default 'dir') == 'dir') + "invalid_directory" + $"Target directory ($directory) is not a directory" + ) + ( + assert (not ([$revision,$branch] | all {|| $in | is-not-empty})) + "invalid_arguments" + "You must specify at least one of --branch or --revision" + ) + let depth = ($env.NUPM_GIT_CLONE_DEPTH? | default 1) mut clone_args = ["clone", $package] @@ -282,9 +299,7 @@ export def main [ } let pkg: path = if $path { - if $pkg_version != null { - throw-error "Use only --path or --pkg-version, not both" - } + assert ($pkg_version == null) "invalid_arguments" "Use only --path or --pkg-version, not both" $package } else if $git { git-clone $package --branch=$branch --directory=(tmp-dir git-clone --ensure) From 4a71166130c014199ff39e16ec97b4f7de30ea46 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Mon, 20 Oct 2025 09:56:05 +0330 Subject: [PATCH 10/12] fix: `$pkg.path` was forced to be string but it could be `null` --- nupm/install.nu | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nupm/install.nu b/nupm/install.nu index 9a8c817..08325f0 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -127,11 +127,16 @@ def download-pkg [ pkg: record< name: string, version: string, - path: string, + path: any, type: string, info: any, > ]: nothing -> path { + ( + assert ([string,nothing] | any {|| $in == ($pkg.path | describe)}) + "package_path_type_invalid" + "Package path must be a string or null" + ) # TODO: Add some kind of hashing to check that files really match ( assert ($pkg.type != 'git') From 39545174c8bb0f83c97f7d6d2573919ff1fcc427 Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Mon, 20 Oct 2025 15:05:15 +0330 Subject: [PATCH 11/12] refactor: use `std/assert` instead of custom `assert` helper --- nupm/install.nu | 78 ++++++++++++++++------------------------------- nupm/utils/log.nu | 11 ------- 2 files changed, 26 insertions(+), 63 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 08325f0..1cb7201 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -1,11 +1,11 @@ use utils/completions.nu complete-registries use utils/dirs.nu [ nupm-home-prompt cache-dir module-dir script-dir tmp-dir PACKAGE_FILENAME ] -use utils/log.nu [throw-error assert] +use utils/log.nu [throw-error] use utils/misc.nu [check-cols hash-fn url] use utils/package.nu open-package-file use utils/registry.nu search-package use utils/version.nu filter-by-version - +use std/assert # Install list of scripts into a directory # # Input: Scripts taken from 'nupm.nuon' @@ -17,19 +17,15 @@ def install-scripts [ each {|script| let src_path = $pkg_dir | path join $script - assert (($src_path | path type) == file) "script_not_found" $"Script ($src_path) does not exist" + assert (($src_path | path type) == file) $"Script ($src_path) does not exist" - ( - assert ($force + assert ($force or ( $scripts_dir | path join ($script | path basename) | path type ) != file - ) - "package_already_installed" - $"Script ($src_path) is already installed in ($scripts_dir). Use `--force` to override the package." - ) + ) $"Script ($src_path) is already installed in ($scripts_dir). Use `--force` to override the package." log debug $"installing script `($src_path)` to `($scripts_dir)`" cp $src_path $scripts_dir @@ -132,17 +128,12 @@ def download-pkg [ info: any, > ]: nothing -> path { - ( - assert ([string,nothing] | any {|| $in == ($pkg.path | describe)}) - "package_path_type_invalid" - "Package path must be a string or null" - ) # TODO: Add some kind of hashing to check that files really match - ( - assert ($pkg.type != 'git') - "package_type_not_supported" - "Downloading non-git packages is not supported yet" - ) + assert ( + [string,nothing] + | any {|| $in == ($pkg.path | describe)} + ) "Package path must be a string or null" + assert ($pkg.type != 'git') "Downloading non-git packages is not supported yet" let cache_dir = cache-dir --ensure cd $cache_dir @@ -172,12 +163,8 @@ def download-pkg [ throw-error $'Error cloning repository ($pkg.info.url)' } - ( - assert (not ($pkg_dir | path exists)) - "invalid_package_path" - $'Package path ($pkg.path) does not exist in cloned repository' - ) - + assert (not ($pkg_dir | path exists)) $'Package path ($pkg.path) does not exist in cloned repository' + $pkg_dir } @@ -189,17 +176,9 @@ def fetch-package [ ]: nothing -> path { let regs = search-package $package --registry $registry --exact-match - ( - assert (not ($regs | is-empty)) - "package_not_found" - $'Package ($package) not found in any registry' - ) - ( - assert (($regs | length) == 1) - "multiple_registries_found" - $'Multiple registries contain package ($package)' - ) - + assert (not ($regs | is-empty)) $'Package ($package) not found in any registry' + assert (($regs | length) == 1) $'Multiple registries contain package ($package)' + # Now, only one registry contains the package let reg = $regs | first let pkgs = $reg.pkgs | filter-by-version $version @@ -209,11 +188,8 @@ def fetch-package [ } catch { throw-error $'No package matching version `($version)`' } - ( - assert ($pkg.hash_mismatch == false) - "package_hash_mismatch" - ($'Content of package file ($pkg.path) does not match expected hash') - ) + + assert ($pkg.hash_mismatch == false) ($'Content of package file ($pkg.path) does not match expected hash') print $pkg @@ -237,16 +213,14 @@ def git-clone [ --directory: path # Target directory to clone into --revision: string # Revision to checkout to ]: nothing -> path { - ( - assert (($directory | path type | default 'dir') == 'dir') - "invalid_directory" - $"Target directory ($directory) is not a directory" - ) - ( - assert (not ([$revision,$branch] | all {|| $in | is-not-empty})) - "invalid_arguments" - "You must specify at least one of --branch or --revision" - ) + assert (($directory | path type | default 'dir') == 'dir') $"Target directory ($directory) is not a directory" + assert ( + not ( + [$revision,$branch] + | all {|| $in | is-not-empty} + ) + ) "You must specify only one of --branch or --revision" + let depth = ($env.NUPM_GIT_CLONE_DEPTH? | default 1) mut clone_args = ["clone", $package] @@ -304,7 +278,7 @@ export def main [ } let pkg: path = if $path { - assert ($pkg_version == null) "invalid_arguments" "Use only --path or --pkg-version, not both" + assert ($pkg_version == null) "Use only --path or --pkg-version, not both" $package } else if $git { git-clone $package --branch=$branch --directory=(tmp-dir git-clone --ensure) diff --git a/nupm/utils/log.nu b/nupm/utils/log.nu index adf5e15..4982e35 100644 --- a/nupm/utils/log.nu +++ b/nupm/utils/log.nu @@ -26,17 +26,6 @@ export def throw-error [ } } -export def assert [ - condition: bool - error: string - text?: string - --span: record -] { - if not $condition { - throw-error $error $text --span=$span - } -} - # Append a formatted help line to mimic `error make` in core export def append-help [help_msg: string]: string -> string { $in + $"\n (ansi cyan)help:(ansi reset) " + $help_msg From 156a6b234fd9f4b3d5822b11448da56e2c198dbc Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Mon, 20 Oct 2025 15:16:41 +0330 Subject: [PATCH 12/12] fix: add error labels to assert --- nupm/install.nu | 77 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/nupm/install.nu b/nupm/install.nu index 1cb7201..73d6a82 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -17,15 +17,22 @@ def install-scripts [ each {|script| let src_path = $pkg_dir | path join $script - assert (($src_path | path type) == file) $"Script ($src_path) does not exist" - - assert ($force + ( + assert (($src_path | path type) == file) + $"Script ($src_path) does not exist" + --error-label={text: "script_missing", span:(metadata $src_path | get span)} + ) + ( + assert ($force or ( $scripts_dir | path join ($script | path basename) | path type ) != file - ) $"Script ($src_path) is already installed in ($scripts_dir). Use `--force` to override the package." + ) + $"Script ($src_path) is already installed in ($scripts_dir). Use `--force` to override the package." + --error-label={text: "already_installed", span:(metadata $src_path | get span)} + ) log debug $"installing script `($src_path)` to `($scripts_dir)`" cp $src_path $scripts_dir @@ -129,12 +136,16 @@ def download-pkg [ > ]: nothing -> path { # TODO: Add some kind of hashing to check that files really match - assert ( - [string,nothing] - | any {|| $in == ($pkg.path | describe)} - ) "Package path must be a string or null" - assert ($pkg.type != 'git') "Downloading non-git packages is not supported yet" - + ( + assert ([string,nothing] | any {|| $in == ($pkg.path | describe)}) + "Package path must be a string or null" + --error-label={text: "invalid_arguments", span:(metadata $pkg.path | get span)} + ) + ( + assert ($pkg.type == 'git') + "Downloading non-git packages is not supported yet" + --error-label={text: "invalid_arguments", span:(metadata $pkg.type | get span)} + ) let cache_dir = cache-dir --ensure cd $cache_dir @@ -162,9 +173,12 @@ def download-pkg [ } catch { throw-error $'Error cloning repository ($pkg.info.url)' } + ( + assert (not ($pkg_dir | path exists)) + $'Package path ($pkg.path) does not exist in cloned repository' + --error-label={text: "path_missing", span:(metadata $pkg_dir | get span)} + ) - assert (not ($pkg_dir | path exists)) $'Package path ($pkg.path) does not exist in cloned repository' - $pkg_dir } @@ -176,9 +190,16 @@ def fetch-package [ ]: nothing -> path { let regs = search-package $package --registry $registry --exact-match - assert (not ($regs | is-empty)) $'Package ($package) not found in any registry' - assert (($regs | length) == 1) $'Multiple registries contain package ($package)' - + ( + assert ($regs | is-not-empty) + $'Package ($package) not found in any registry' + --error-label={text: "registry_not_found", span:(metadata $regs| get span)} + ) + ( + assert (($regs | length) == 1) + $'Multiple registries contain package ($package)' + --error-label={text: "multiple_registries_found", span:(metadata $regs| get span)} + ) # Now, only one registry contains the package let reg = $regs | first let pkgs = $reg.pkgs | filter-by-version $version @@ -189,7 +210,11 @@ def fetch-package [ throw-error $'No package matching version `($version)`' } - assert ($pkg.hash_mismatch == false) ($'Content of package file ($pkg.path) does not match expected hash') + ( + assert (not $pkg.hash_mismatch) + $'Content of package file ($pkg.path) does not match expected hash' + --error-label={text: "hash_mismatch", span:(metadata $pkg.hash_mismatch| get span)} + ) print $pkg @@ -213,14 +238,18 @@ def git-clone [ --directory: path # Target directory to clone into --revision: string # Revision to checkout to ]: nothing -> path { - assert (($directory | path type | default 'dir') == 'dir') $"Target directory ($directory) is not a directory" - assert ( - not ( + ( + assert (($directory | path type | default 'dir') == 'dir') + $"Target directory ($directory) is not a directory" + --error-label={text: "invalid_arguments", span:(metadata $directory| get span)} + ) + ( + assert (not ( [$revision,$branch] - | all {|| $in | is-not-empty} - ) - ) "You must specify only one of --branch or --revision" - + | all {|| $in | is-not-empty})) + "You must specify only one of --branch or --revision" + --error-label={text: "invalid_arguments", span:(metadata $branch| get span)} + ) let depth = ($env.NUPM_GIT_CLONE_DEPTH? | default 1) mut clone_args = ["clone", $package] @@ -278,7 +307,7 @@ export def main [ } let pkg: path = if $path { - assert ($pkg_version == null) "Use only --path or --pkg-version, not both" + assert ($pkg_version == null) "Use only --path or --pkg-version, not both" --error-label={text: "invalid_arguments", span:(metadata $path | get span)} $package } else if $git { git-clone $package --branch=$branch --directory=(tmp-dir git-clone --ensure)