Skip to content

Commit

Permalink
Fix: add a new flag --skip-dirty-pkg for search-package
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxiaozhuox committed Nov 21, 2024
1 parent c424b13 commit dd23d9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
5 changes: 0 additions & 5 deletions nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ def fetch-package [
throw-error $'No package matching version `($version)`'
}

if $pkg.dirty {
throw-error ($'Content of package file `($pkg.path)'
+ $'` does not match expected hash.')
}

print $pkg

if $pkg.type == 'git' {
Expand Down
24 changes: 10 additions & 14 deletions nupm/search.nu
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ export def main [
--pkg-version(-v): string # Package version to install
--exact-match(-e) # Match package name exactly
]: nothing -> table {
search-package $package --registry $registry --exact-match=$exact_match
search-package $package --registry $registry --exact-match=$exact_match --skip-dirty-pkg
| flatten
| each {|row|
if $row.pkgs.dirty {
null
} else {
{
registry_name: $row.registry_name
registry_path: $row.registry_path
name: $row.pkgs.name
version: $row.pkgs.version
path: $row.pkgs.path
type: $row.pkgs.type
info: $row.pkgs.info
}
{
registry_name: $row.registry_name
registry_path: $row.registry_path
name: $row.pkgs.name
version: $row.pkgs.version
path: $row.pkgs.path
type: $row.pkgs.type
info: $row.pkgs.info
}
}
| compact | filter-by-version $pkg_version
| filter-by-version $pkg_version
}
17 changes: 13 additions & 4 deletions nupm/utils/registry.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use misc.nu [check-cols url hash-file]
export const REG_COLS = [ name path hash ]

# Columns of a registry package file
export const REG_PKG_COLS = [ name version path type info dirty ]
export const REG_PKG_COLS = [ name version path type info ]

# Search for a package in a registry
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
--skip-dirty-pkg # Skip packages with failed hash checks
] -> 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
Expand Down Expand Up @@ -86,11 +87,19 @@ export def search-package [

let new_hash = $pkg_file_path | hash-file

# check package hash
let dirty = $new_hash != $row.hash

open $pkg_file_path | insert dirty $dirty
if $new_hash != $row.hash {
if $skip_dirty_pkg {
null
} else {
throw-error ($'Content of package file `($url_or_path)'
+ $' does not match expected hash `($row.hash)`.')
}
} else {
open $pkg_file_path | insert dirty $dirty
}
}
| compact
| flatten

{
Expand Down

0 comments on commit dd23d9a

Please sign in to comment.