-
Notifications
You must be signed in to change notification settings - Fork 18
feat: nupm registry
subcommand
#122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mkatychev
wants to merge
34
commits into
nushell:main
Choose a base branch
from
mkatychev:feat/registry-submodule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+459
−55
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4d9d899
init commit
mkatychev 573100b
changed const
mkatychev 5409a71
get_index impl
mkatychev 3bcf1e9
removed TODOs for callout of registry subcommand
mkatychev 87ed5d1
Merge branch 'main' into feat/registry-submodule
mkatychev 26c3444
made nupm config declarative
mkatychev 67c2826
Merge branch 'main' into feat/registry-submodule
mkatychev fce3057
updated NUPM_ variables to match nested structure
mkatychev 354dc8e
typos
mkatychev 2efd004
updated initial test variables
mkatychev 5e96f1a
fixed registry typo
mkatychev 0821712
renamed tmp to temp
mkatychev 445be0f
revert temp
mkatychev 1f12490
fixed tmp-dir variable resolution issue
mkatychev f33f29e
updated with workaround
mkatychev 7d3a1cf
updated test cases for exitsting registry subcommands
mkatychev 12d95c1
initial naive registry describe impl
mkatychev fe5b26c
registry describe passing test
mkatychev 2907762
moved open-index to module root
mkatychev 11a7a38
removed log calls intest
mkatychev b054db3
update registry header comment
mkatychev aa12a95
update registry init shim
mkatychev d5d6699
partial test pass
mkatychev bac9659
all tests pass
mkatychev baaf4f4
revert test mod closuer
mkatychev 8542850
simplify variable setting
mkatychev af2a6ad
reverted nested nupm config
mkatychev 081677b
remove flaten-nupm-env
mkatychev 01b33b2
added registry_filename constants
mkatychev b2e85f2
removed fetch command
mkatychev 4c55581
remoted editorconfig
mkatychev 102d970
PR feedback on addtion of registry values
mkatychev 78848fe
revert README
mkatychev 919865b
updated formatting messages
mkatychev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# Registry management for nupm | ||
|
||
use utils/dirs.nu [nupm-home-prompt REGISTRY_FILENAME] | ||
use utils/log.nu [throw-error append-help UNIMPLEMENTED] | ||
use utils/registry.nu registry-cache | ||
|
||
# Manage nupm registires | ||
@example "List all configured registries" { nupm registry } | ||
export def main []: nothing -> table { | ||
list | ||
} | ||
|
||
# List all configured registries | ||
@example "List all registries with details" { nupm registry list } | ||
export def list []: nothing -> table { | ||
$env.NUPM_REGISTRIES | transpose name url | sort-by name | ||
} | ||
|
||
# Formatting convenience function that is passed in the presence of the `--save` flag, informing the user on | ||
# how to make their changes permanent | ||
export def success-msg [success_msg: string, write_path: path, saved_to_disk: bool]: nothing -> string { | ||
if $saved_to_disk { | ||
return $"($success_msg) and written to ($write_path)" | ||
} | ||
|
||
$success_msg | append-help "To commit the change to disk, use the `--save` flag." | ||
} | ||
|
||
|
||
def registry-names [] { list | get name } | ||
# Show detailed information about a specific registry | ||
# returning a list of package names, type, and version | ||
@example "Show registry information" { nupm registry describe nupm } | ||
export def describe [ | ||
registry: string@registry-names | ||
]: nothing -> table { | ||
use utils/dirs.nu cache-dir | ||
|
||
if not ($registry in $env.NUPM_REGISTRIES) { | ||
throw-error $"Registry '($registry)' not found" | ||
} | ||
|
||
let registry_url = $env.NUPM_REGISTRIES | get $registry | ||
let cache = registry-cache $registry | ||
let cached_registry = $cache.dir | path join $REGISTRY_FILENAME | ||
|
||
# Always check cache first, only fall back to URL if cache doesn't exist | ||
let registry_data = if ($cache.file | path exists) { | ||
open $cache.file | ||
} else if ($registry_url | path exists) { | ||
# Local registry file | ||
open $registry_url | ||
} else { | ||
# Remote registry - fetch and cache | ||
let data = http get $registry_url | ||
mkdir $cache.dir | ||
$data | save $cache.file | ||
$data | ||
} | ||
|
||
$registry_data | each {|entry| | ||
let package_cache_path = $cache.dir | path join $"($entry.name).nuon" | ||
|
||
# Always check cache first for package data too | ||
let package_file_data = if ($package_cache_path | path exists) { | ||
open $package_cache_path | ||
} else if ($registry_url | path exists) { | ||
# Local package file | ||
let package_path = $registry_url | path dirname | path join $entry.path | ||
open $package_path | ||
} else { | ||
# Remote package - fetch and cache | ||
let base_url = $registry_url | url parse | ||
let package_url = $base_url | update path ($base_url.path | path dirname | path join $entry.path) | url join | ||
let data = http get $package_url | ||
$data | save $package_cache_path | ||
$data | ||
} | ||
|
||
# Package data is a table of versions for this package | ||
$package_file_data | each {|pkg| | ||
{ | ||
name: $pkg.name, | ||
# TODO rename package metadata type field to source | ||
# to avoid confusion with custom|script|module type enumberable | ||
source: $pkg.type, | ||
version: $pkg.version, | ||
# description: ($pkg.description? | default "") | ||
} | ||
} | ||
} | flatten | ||
} | ||
|
||
# Add a new registry | ||
@example "Add a new registry" { nupm registry add my-registry https://example.com/registry.nuon } | ||
export def --env add [ | ||
name: string, # Name of the registry | ||
url: string, # URL or path to the registry | ||
--save, # Whether to commit the change to the registry index | ||
] { | ||
if ($name in $env.NUPM_REGISTRIES) { | ||
throw-error $"Registry '($name)' already exists. Use 'nupm registry update' to modify it." | ||
} | ||
$env.NUPM_REGISTRIES = $env.NUPM_REGISTRIES | insert $name $url | ||
|
||
if $save { | ||
$env.NUPM_REGISTRIES | save --force $env.NUPM_INDEX_PATH | ||
} | ||
|
||
print (success-msg $"Registry '($name)' added successfully" $env.NUPM_INDEX_PATH $save) | ||
|
||
} | ||
|
||
# Remove a registry | ||
@example "Remove a registry" { nupm registry remove my-registry } | ||
export def --env remove [ | ||
name: string # Name of the registry to remove | ||
--save, # Whether to commit the change to the registry index | ||
] { | ||
$env.NUPM_REGISTRIES = $env.NUPM_REGISTRIES | reject $name | ||
|
||
if $save { | ||
$env.NUPM_REGISTRIES | save --force $env.NUPM_INDEX_PATH | ||
} | ||
|
||
print (success-msg $"Registry '($name)' removed successfully" $env.NUPM_INDEX_PATH $save) | ||
} | ||
|
||
# Update a given registry url | ||
@example "Update registry URL" { nupm registry set-url my-registry https://new-url.com/registry.nuon } | ||
export def --env set-url [ | ||
name: string, # Name of the registry to update | ||
url: string, # Registry target URL | ||
--save, # Whether to commit the change to the registry index | ||
]: nothing -> nothing { | ||
$env.NUPM_REGISTRIES = $env.NUPM_REGISTRIES | update $name $url | ||
|
||
if $save { | ||
$env.NUPM_REGISTRIES | save --force $env.NUPM_INDEX_PATH | ||
} | ||
|
||
print (success-msg $"Registry '($name)' URL updated successfully" $env.NUPM_INDEX_PATH $save) | ||
} | ||
|
||
# https://www.nushell.sh/book/configuration.html#macos-keeping-usr-bin-open-as-open | ||
alias nu-rename = rename | ||
# Rename a registry | ||
@example "Rename a registry" { nupm registry rename my-registry our-registry } | ||
export def --env rename [ | ||
name: string, # Name of the registry to update | ||
new_name: string, # New registry name | ||
--save, # Whether to commit the change to the registry index | ||
] { | ||
$env.NUPM_REGISTRIES = $env.NUPM_REGISTRIES | nu-rename --column { $name: $new_name } | ||
|
||
if $save { | ||
$env.NUPM_REGISTRIES | save --force $env.NUPM_INDEX_PATH | ||
} | ||
|
||
print (success-msg $"Registry '($name)' renamed successfully" $env.NUPM_INDEX_PATH $save) | ||
} | ||
|
||
def init-index [] { | ||
if not (nupm-home-prompt) { | ||
throw-error "Cannot create NUPM_HOME directory." | ||
} | ||
|
||
|
||
if ($env.NUPM_INDEX_PATH | path exists) { | ||
print $"Registry list already exists at ($env.NUPM_INDEX_PATH)" | ||
return | ||
} | ||
|
||
$env.NUPM_REGISTRIES | save $env.NUPM_INDEX_PATH | ||
|
||
print $"Registry index initialized at ($env.NUPM_INDEX_PATH)" | ||
} | ||
|
||
|
||
# Initialize a new nupm registry or a registry index if the `--index` flag is | ||
# passed in | ||
@example "Initialize registry index" { nupm registry init --index } | ||
export def init [--index] { | ||
if $index { | ||
init-index | ||
return | ||
} | ||
# TODO initialize registry index here | ||
throw-error UNIMPLEMENTED "`nupm registry --index` is not implemented." | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.