From 42d65a980641a9374473907d521f008e859c9ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Mon, 3 Jun 2024 22:45:06 +0300 Subject: [PATCH] Redesign registry; Allow publishing to registry (#86) ## Description This changes registry to from *one* file that is *manually updated* to *multiple* files that are *auto-generated*. Now, the registry should be only updated with the new `nupm publish` command. See the [doc page](https://github.com/nushell/nupm/blob/bde509cfd9a53939c7a4df01564136e1f9c0b2ee/docs/design/registry.md) for more details and the `registry/` directory for the new proposed structure. ### Misc changes * The structure of the registry is also different. The git/local package type is now encoded in a flat table instead of being a separate record. See `registry/` and `tests/packages/registry/` for examples. * The `path` field can be `null`, not requiring the "." ### TODO - [x] Add package file hashing to stop redownloading them all the time --------- Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Co-authored-by: amtoine --- docs/design/registry.md | 103 +++++ nupm.nuon | 2 +- nupm/install.nu | 38 +- nupm/mod.nu | 3 +- nupm/publish.nu | 243 ++++++++++++ nupm/search.nu | 17 +- nupm/utils/dirs.nu | 2 +- nupm/utils/misc.nu | 35 +- nupm/utils/registry.nu | 94 +++-- nupm/utils/version.nu | 14 +- registry.nuon | 373 ------------------ registry/nu-clippy.nuon | 1 + registry/nu-discord-update.nuon | 1 + registry/nu-fonts-install.nuon | 1 + registry/nu-git-manager-sugar.nuon | 1 + registry/nu-git-manager.nuon | 1 + registry/nu-hooks.nuon | 1 + registry/nu-logout.nuon | 1 + registry/nu-monitor-manager.nuon | 1 + registry/nu-pomodoro.nuon | 1 + registry/nu-right-prompt.nuon | 1 + registry/nu-scripts.nuon | 1 + registry/nu-sound-manager.nuon | 1 + registry/nu-themes.nuon | 1 + registry/nu-zellij.nuon | 1 + registry/nu_plugin_audio_hook.nuon | 1 + registry/nu_plugin_clipboard.nuon | 1 + registry/nu_plugin_desktop_notifications.nuon | 1 + registry/nu_plugin_explore.nuon | 1 + registry/nu_plugin_image.nuon | 1 + registry/nu_plugin_port_list.nuon | 1 + registry/nu_plugin_port_scan.nuon | 1 + registry/nu_plugin_qr_maker.nuon | 1 + registry/nupm_pkg.nuon | 1 + registry/registry.nuon | 1 + registry/tmux-sessionizer.nuon | 1 + tests/mod.nu | 33 +- tests/packages/registry.nuon | 10 - tests/packages/registry/registry.nuon | 1 + tests/packages/registry/spam_custom.nuon | 1 + tests/packages/registry/spam_module.nuon | 1 + tests/packages/registry/spam_script.nuon | 1 + toolkit.nu | 29 +- 43 files changed, 571 insertions(+), 454 deletions(-) create mode 100644 docs/design/registry.md create mode 100644 nupm/publish.nu delete mode 100644 registry.nuon create mode 100644 registry/nu-clippy.nuon create mode 100644 registry/nu-discord-update.nuon create mode 100644 registry/nu-fonts-install.nuon create mode 100644 registry/nu-git-manager-sugar.nuon create mode 100644 registry/nu-git-manager.nuon create mode 100644 registry/nu-hooks.nuon create mode 100644 registry/nu-logout.nuon create mode 100644 registry/nu-monitor-manager.nuon create mode 100644 registry/nu-pomodoro.nuon create mode 100644 registry/nu-right-prompt.nuon create mode 100644 registry/nu-scripts.nuon create mode 100644 registry/nu-sound-manager.nuon create mode 100644 registry/nu-themes.nuon create mode 100644 registry/nu-zellij.nuon create mode 100644 registry/nu_plugin_audio_hook.nuon create mode 100644 registry/nu_plugin_clipboard.nuon create mode 100644 registry/nu_plugin_desktop_notifications.nuon create mode 100644 registry/nu_plugin_explore.nuon create mode 100644 registry/nu_plugin_image.nuon create mode 100644 registry/nu_plugin_port_list.nuon create mode 100644 registry/nu_plugin_port_scan.nuon create mode 100644 registry/nu_plugin_qr_maker.nuon create mode 100644 registry/nupm_pkg.nuon create mode 100644 registry/registry.nuon create mode 100644 registry/tmux-sessionizer.nuon delete mode 100644 tests/packages/registry.nuon create mode 100644 tests/packages/registry/registry.nuon create mode 100644 tests/packages/registry/spam_custom.nuon create mode 100644 tests/packages/registry/spam_module.nuon create mode 100644 tests/packages/registry/spam_script.nuon diff --git a/docs/design/registry.md b/docs/design/registry.md new file mode 100644 index 0000000..dc225ed --- /dev/null +++ b/docs/design/registry.md @@ -0,0 +1,103 @@ +# Registry + +Registry is a collection of .nuon files that tell nupm where to look for packages when doing tasks like `nupm search` or `nupm install`. + +Two types of files compose a registry: +* The "main" registry file containing the list of "registry package files" +* Registry package files containing the details of each package. + +These files **should not** be edited manually. They are intended to be auto-generated and updated with `nupm publish` only. They also shouldn't contain any newlines to avoid potential problems with file hashes between Windows and non-Windows platforms. + +## "Main" registry file + +Table with one package per row and the following columns: +* `name`: Name of the package +* `path`: Path to the "registry package file", relative* to the main registry file. When looking up a package, nupm joins this path to the path/URL of the "main" registry file and fetches it. Both local paths and URLs are handled the same way. +* `hash`: Hash of the "registry package file" to avoid re-downloading them all the time. + +The file is sorted by `name`. No duplicate package names allowed. + +## "Registry package file" + +These files contain the actual information about the package that is used do fetch and install the package. Multiple versions of the same package are supported. It has exactly the following columns: +* `name`: Name of the package +* `version`: Version of the package +* `path`: Path where to look for nupm.nuon (relative to the package root*, in the case of git packages, or the main registry file, if local package) +* `type`: Type of the package. Currently only "git" and "local" +* `info`: Package-specific info based on `type`. It can be one of the following: + * `null` if `type` is "local" + * `record` if `type` is "git" + +This file is sorted by `version`. No duplicate versions allowed. + +_*absolute paths work, but are discouraged, only to be used for local testing etc._ + +## Example registry structure + +_See the new `registry/` directory, the following example slightly differs from it._ + +``` +./registry + +-- registry.nuon + +-- amtoine + +-- nu-git-manager.nuon + +-- nu-git-manager-sugar.nuon +``` + +```nushell +> open registry/registry.nuon + # name path hash +─────────────────────────────────────────────────────────────────────────── + 0 nu-git-manager amtoine/nu-git-manager.nuon md5-4aaae15412fb84233fcb19716f6b7e89 + 1 nu-git-manager-sugar amtoine/nu-git-manager-sugar.nuon md5-d0c7641c0b369e7c944cc668741734d9 + +> open amtoine/nu-git-manager.nuon | table -e + # name version path type info +──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + 0 nu-git-manager 0.1.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.1.0 + 1 nu-git-manager 0.2.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.2.0 + 2 nu-git-manager 0.3.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.3.0 + 3 nu-git-manager 0.4.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.4.0 + 4 nu-git-manager 0.5.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.5.0 + 5 nu-git-manager 0.6.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.6.0 + 6 nu-git-manager 0.7.0 pkgs/nu-git-manager git url https://github.com/amtoine/nu-git-manager + revision 0.7.0 + +> open amtoine/nu-git-manager-sugar.nuon | table -e + # name version path type info +──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + 0 nu-git-manager-sugar 0.1.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.1.0 + 1 nu-git-manager-sugar 0.2.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.2.0 + 2 nu-git-manager-sugar 0.3.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.3.0 + 3 nu-git-manager-sugar 0.4.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.4.0 + 4 nu-git-manager-sugar 0.5.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.5.0 + 5 nu-git-manager-sugar 0.6.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.6.0 + 6 nu-git-manager-sugar 0.7.0 pkgs/nu-git-manager-sugar git url https://github.com/amtoine/nu-git-manager + revision 0.7.0 +``` + +## Publishing a package + +It is possible to only publish to a registry stored on your file system because we don't have a web service or anything like that. + +The intented workflow for publishing a package is: +1. Check out the git repository with the registry +2. `cd` into the package you want to publish +3. Run `nupm publish chosen_registry` to preview the changes +4. Repeat 3 by adjusting the `nupm publish` flags until you have the desired output +5. Run the final command with the `--save` flag which will save the registry files +6. Commit the changes to the registry, create a PR upstream, etc. + +The reason for steps 3. and 4. is that `nupm publish` tries to guess some values to make publishing less tedious. For example, if you're in a git repository, nupm tries to get the URL of the "origin", or the first available remote by default. This should be a sane default for most packages and frees you from having to pass the `--info` flag every time. The guess can be wrong, however, that's why you should check the output of step 3 and make the desired changes before saving the changes with `--save`. diff --git a/nupm.nuon b/nupm.nuon index 7d93255..e5804c3 100644 --- a/nupm.nuon +++ b/nupm.nuon @@ -1,7 +1,7 @@ { name: nupm type: module - version: "0.1.0" + version: "0.2.0" description: "Nushell package manager" license: "LICENSE" } diff --git a/nupm/install.nu b/nupm/install.nu index 50c0f8b..f42abe7 100644 --- a/nupm/install.nu +++ b/nupm/install.nu @@ -3,7 +3,7 @@ use std log use utils/completions.nu complete-registries use utils/dirs.nu [ nupm-home-prompt cache-dir module-dir script-dir tmp-dir ] use utils/log.nu throw-error -use utils/misc.nu check-cols +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 @@ -130,10 +130,9 @@ def download-pkg [ pkg: record< name: string, version: string, - url: string, - revision: string, path: string, type: string, + info: any, > ]: nothing -> path { # TODO: Add some kind of hashing to check that files really match @@ -149,11 +148,15 @@ def download-pkg [ mkdir $git_dir cd $git_dir - let repo_name = $pkg.url | url parse | get path | path parse | get stem - let url_hash = $pkg.url | hash md5 # in case of git repo name collision - let clone_dir = $'($repo_name)-($url_hash)-($pkg.revision)' + let repo_name = $pkg.info.url | url stem + let url_hash = $pkg.info.url | hash-fn # in case of git repo name collision + let clone_dir = $'($repo_name)-($url_hash)-($pkg.info.revision)' - let pkg_dir = $env.PWD | path join $clone_dir $pkg.path + let pkg_dir = if $pkg.path == null { + $env.PWD | path join $clone_dir + } else { + $env.PWD | path join $clone_dir ($pkg.path | path dirname) + } if ($pkg_dir | path exists) { print $'Package ($pkg.name) found in cache' @@ -161,21 +164,21 @@ def download-pkg [ } try { - git clone $pkg.url $clone_dir + git clone $pkg.info.url $clone_dir } catch { - throw-error $'Error cloning repository ($pkg.url)' + throw-error $'Error cloning repository ($pkg.info.url)' } cd $clone_dir try { - git checkout $pkg.revision + git checkout $pkg.info.revision } catch { - throw-error $'Error checking out revision ($pkg.revision)' + throw-error $'Error checking out revision ($pkg.info.revision)' } if not ($pkg_dir | path exists) { - throw-error $'Path ($pkg.path) does not exist' + throw-error $'Path ($pkg_dir) does not exist' } $pkg_dir @@ -187,10 +190,7 @@ def fetch-package [ --registry: string # Which registry to use --version: string # Package version to install (string or null) ]: nothing -> path { - let regs = (search-package $package - --registry $registry - --version $version - --exact-match) + let regs = search-package $package --registry $registry --exact-match if ($regs | is-empty) { throw-error $'Package ($package) not found in any registry' @@ -216,7 +216,11 @@ def fetch-package [ } else { # local package path is relative to the registry file (absolute paths # are discouraged but work) - $reg.path | path dirname | path join $pkg.path + if $pkg.path == null { + $reg.registry_path | path dirname + } else { + $reg.registry_path | path dirname | path join $pkg.path + } } } diff --git a/nupm/mod.nu b/nupm/mod.nu index e75f799..97954f3 100644 --- a/nupm/mod.nu +++ b/nupm/mod.nu @@ -4,9 +4,10 @@ use utils/dirs.nu [ ] export module install.nu -export module test.nu +export module publish.nu export module search.nu export module status.nu +export module test.nu export-env { # Ensure that $env.NUPM_HOME is always set when running nupm. Any missing diff --git a/nupm/publish.nu b/nupm/publish.nu new file mode 100644 index 0000000..37957b0 --- /dev/null +++ b/nupm/publish.nu @@ -0,0 +1,243 @@ +use utils/log.nu throw-error +use utils/misc.nu hash-fn +use utils/package.nu open-package-file +use utils/registry.nu [ search-package REG_COLS REG_PKG_COLS ] +use utils/version.nu sort-by-version + +# Publish package to registry +# +# The package being published is determined by the current working directory. +# +# By default, changes are only previewed. To apply them, use the --save flag. +# Needs to run from package root, i.e., where nupm.nuon is. +# +# The --path flag defines the `path` field of the registry package file. Its +# meaning depends on the package type: +# * git packages : Path to the package relative to git repo root +# * local packages : Path to the package relative to registry file +# Furthermore, `\` inside the `path` field are replaced with `/` to avoid +# conflicts between Windows and non-Windows platforms. +export def main [ + registry: string # Registry file to publish to (local file or name pointing + # at a local registry) + --git # Publish package as a git package + --local # Publish package as a local package + --info: record # Package info based on package type (e.g., `url` and + # `revision` for a git package) + --path: string # `path` field of the registry entry file + --save # Write changes to registry instead of printing changes +] { + if $git and $local { + throw-error ("Cannot have more than one package type. Choose one of" + + " --git or --local or neither, not both.") + } + + let pkg = open-package-file $env.PWD + + # Registry must point to a local path + let reg_path = $registry | get-registry-path + + if ($reg_path | path type) != 'file' { + throw-error $'Registry path ($reg_path) must be a path to a local file.' + } + + # Guess package type + let pkg_type = if $git { + "git" + } else if $local { + "local" + } else { + let res = search-package $pkg.name --registry $reg_path --exact-match + | first # there will be only one result because we passed local path + | get pkgs + | sort-by-version + + if ($res | is-empty) { + throw-error ($"Cannot guess package type because pacakge" + + $" ($pkg.name) was not found in registry ($registry). Specify" + + " the type manually with --git or --local flag.") + } + + $res | last | get type + } + + # Preparation + mut reg_content = $reg_path | open-registry-file + + let name_matches = if ($reg_content | length) > 0 { + $reg_content | where name == $pkg.name + } else { + [] + } + + mut existing_entry = null + + if ($name_matches | length) == 1 { + $existing_entry = ($name_matches | first) + } else if ($name_matches | length) > 1 { + throw-error ($"Registry ($registry) contains multiple packages named" + + $" ($pkg.name). This shouldn't happen.") + } + + let pkg_file_path = if $existing_entry == null { + $'($pkg.name).nuon' + } else { + $existing_entry.path + } + + # Create entry to the package file + mut info = $info + + if $pkg_type == 'git' { + $info = ($info | default { + url: (guess-url) + revision: (guess-revision) + }) + } + + match $pkg_type { + 'git' => { + if $info == null or ($info | columns) != [url revision] { + throw-error ("Package type 'git' requires info with url and" + + " revision fields.") + } + } + 'local' => { + if $info != null { + throw-error "Package type 'local' must have null info." + } + } + } + + let path = if $path != null { $path | str replace --all '\' '/' } + + let pkg_entry = { + name: $pkg.name + version: $pkg.version + path: $path + type: $pkg_type + info: $info + } + + let pkg_file_path_full = $reg_path + | path dirname + | path join $pkg_file_path + | path expand + + print "" + print ("New entry to package file" + + $" (ansi cyan_bold)($pkg_file_path_full)(ansi reset):") + print ($pkg_entry | table --expand) + + # add the entry to the package file + let pkg_file_content = $pkg_file_path_full | open-reg-pkg-file + + if $pkg.version in $pkg_file_content.version { + throw-error ($"Version ($pkg.version) of package ($pkg.name) is already" + + $" published in registry ($registry)") + } + + let pkg_file_nuon = $pkg_file_content + | append $pkg_entry + | sort-by-version + | to nuon + + if $save { + print $"(ansi yellow)=> SAVED!(ansi reset)" + $pkg_file_nuon | save --raw --force $pkg_file_path_full + } + + # Create entry to the registry file + let hash = $pkg_file_nuon | hash-fn + + let reg_entry = { + name: $pkg.name + path: $pkg_file_path + hash: $hash + } + + print "" + print $"New entry to registry file (ansi cyan_bold)($reg_path)(ansi reset):" + print ($reg_entry | table --expand) + + # add the entry to the registry file + let reg_nuon = $reg_content + | where name != $pkg.name + | append $reg_entry + | sort-by name + | to nuon + + if $save { + print $"(ansi yellow)=> SAVED!(ansi reset)" + $reg_nuon | save --raw --force $reg_path + } else { + print "" + print $"(ansi yellow)If the changes look good, re-run with --save to apply them.(ansi reset)" + } +} + +def guess-url [] -> string { + mut url = (do -i { ^git remote get-url origin | complete } | get stdout) + + if ($url | is-empty) { + let first_remote = do -i { ^git remote | lines | first } | get stdout + + if not ($first_remote | is-empty) { + $url = (do -i { ^git remote get-url $first_remote | complete } + | get stdout) + } + } + + $url | str trim +} + +def guess-revision [] -> string { + mut revision = (do -i { ^git describe --tags --abbrev=0 | complete } + | get stdout) + + if ($revision | is-empty) { + $revision = (do -i { ^git rev-parse HEAD | complete } | get stdout) + } + + $revision | str trim +} + +def get-registry-path []: string -> path { + let registry = $in + $env.NUPM_REGISTRIES | get -i $registry | default ($registry | path expand) +} + +def open-registry-file []: path -> table { + let reg_path = $in + + let reg_content = try { open $reg_path } + let exp_cols = $REG_COLS + + if (($reg_content | is-not-empty) + and ($reg_content | columns) != $exp_cols) { + throw-error ($"Unexpected columns of registry ($reg_path)." + + $" Got ($reg_content | columns), needs ($exp_cols).") + } + + $reg_content | default [] +} + +def open-reg-pkg-file []: [ path -> table< + name: string + version: string + path: string + type: string + info: record> ] { + let pkg_path = $in + + let pkg_content = try { open $pkg_path } + let exp_cols = $REG_PKG_COLS + + if (($pkg_content | is-not-empty) + and ($pkg_content | columns) != $exp_cols) { + throw-error ($"Unexpected columns of package file ($pkg_path)." + + $" Got ($pkg_content | columns), needs ($exp_cols).") + } + + $pkg_content | default [] +} diff --git a/nupm/search.nu b/nupm/search.nu index 4695826..e4dc200 100644 --- a/nupm/search.nu +++ b/nupm/search.nu @@ -1,5 +1,6 @@ use utils/completions.nu complete-registries use utils/registry.nu search-package +use utils/version.nu filter-by-version # Search for a package export def main [ @@ -7,6 +8,20 @@ export def main [ --registry: string@complete-registries # Which registry to use (either a name # in $env.NUPM_REGISTRIES or a path) --pkg-version(-v): string # Package version to install + --exact-match(-e) # Match package name exactly ]: nothing -> table { - search-package $package --registry $registry --version $pkg_version + search-package $package --registry $registry --exact-match=$exact_match + | flatten + | each {|row| + { + 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 + } + } + | filter-by-version $pkg_version } diff --git a/nupm/utils/dirs.nu b/nupm/utils/dirs.nu index 1c8b732..5bcfae2 100644 --- a/nupm/utils/dirs.nu +++ b/nupm/utils/dirs.nu @@ -12,7 +12,7 @@ export const DEFAULT_NUPM_TEMP = ($nu.temp-path | path join "nupm") # Default registry export const DEFAULT_NUPM_REGISTRIES = { - nupm_test: 'https://raw.githubusercontent.com/nushell/nupm/main/registry.nuon' + nupm_test: 'https://raw.githubusercontent.com/nushell/nupm/main/registry/registry.nuon' } # Prompt to create $env.NUPM_HOME if it does not exist and some sanity checks. diff --git a/nupm/utils/misc.nu b/nupm/utils/misc.nu index c82742c..3f3e7be 100644 --- a/nupm/utils/misc.nu +++ b/nupm/utils/misc.nu @@ -2,7 +2,7 @@ # Make sure input has requested columns and no extra columns export def check-cols [ - what: string, + what: string, required_cols: list --extra-ok --missing-ok @@ -16,7 +16,7 @@ export def check-cols [ let cols = $inp | columns if not $missing_ok { let missing_cols = $required_cols | where {|req_col| $req_col not-in $cols } - + if not ($missing_cols | is-empty) { throw-error ($"Missing the following required columns in ($what):" + $" ($missing_cols | str join ', ')") @@ -34,3 +34,34 @@ export def check-cols [ $inp } + +# Compute a hash of a string +export def hash-fn []: string -> string { + let hash = $in | hash md5 + [ 'md5' $hash ] | str join '-' +} + +# Compute a hash of file contents +export def hash-file []: path -> string { + open --raw | hash-fn +} + +# Extensions to the `url ...` commands +export module url { + + # Get the stem of a URL path + export def stem []: string -> string { + url parse | get path | path parse | get stem + } + + # Update the last element of a URL path with a new name + export def update-name [new_name: string]: string -> string { + url parse + | update path {|url| + # skip the first '/' and replace last elemnt with the new name + let parts = $url.path | path split | skip 1 | drop 1 + $parts | append $new_name | str join '/' + } + | url join + } +} diff --git a/nupm/utils/registry.nu b/nupm/utils/registry.nu index 5ad32cb..006e105 100644 --- a/nupm/utils/registry.nu +++ b/nupm/utils/registry.nu @@ -1,10 +1,19 @@ # Utilities related to nupm registries +use dirs.nu cache-dir +use log.nu throw-error +use misc.nu [check-cols url hash-file] + +# Columns of a registry file +export const REG_COLS = [ name path hash ] + +# Columns of a registry package file +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 - --version: any # Package version to install (string or null) + --registry: string # Which registry to use (name or path) --exact-match # Searched package name must match exactly ] -> table { let registries = if (not ($registry | is-empty)) and ($registry in $env.NUPM_REGISTRIES) { @@ -15,59 +24,80 @@ export def search-package [ let reg_name = $registry | path parse | get stem { $reg_name: $registry } } else { - # Otherwise use $env.NUPM_REGISTRIES + # Otherwise use $env.NUPM_REGISTRIES as-is $env.NUPM_REGISTRIES } let name_matcher: closure = if $exact_match { - {|row| $row.name == $package } + {|row| $package == $row.name } } else { {|row| $package in $row.name } } # Collect all registries matching the package and all matching packages let regs = $registries - | items {|name, path| + | items {|name, url_or_path| # Open registry (online or offline) - let registry = if ($path | path type) == file { - open $path + let registry = if ($url_or_path | path type) == file { + { + reg: (open $url_or_path) + path: $url_or_path + is_url: false + } + } else { try { - let reg = http get $path + let reg = http get $url_or_path - if local in $reg { - throw-error ("Can't have local packages in online registry" - + $" '($path)'.") - } + let reg_file = cache-dir --ensure + | path join registry $'($name).nuon' + + mkdir ($reg_file | path dirname) + $reg | save --force $reg_file - $reg + { + reg: $reg + path: $reg_file + is_url: true + } } catch { - throw-error $"Cannot open '($path)' as a file or URL." + throw-error $"Cannot open '($url_or_path)' as a file or URL." } } - $registry | check-cols --missing-ok "registry" [ git local ] | ignore + $registry.reg | check-cols "registry" $REG_COLS | ignore # Find all packages matching $package in the registry - let pkgs_local = $registry.local? - | default [] - | check-cols "local packages" [ name version path ] - | filter $name_matcher - - let pkgs_git = $registry.git? - | default [] - | check-cols "git packages" [ name version url revision path ] - | filter $name_matcher - - let pkgs = $pkgs_local - | insert type local - | insert url null - | insert revision null - | append ($pkgs_git | insert type git) + let pkg_files = $registry.reg | filter $name_matcher + + let pkgs = $pkg_files | each {|row| + let pkg_file_path = $registry.path + | path dirname + | path join $row.path + + let hash = if ($pkg_file_path | path type) == file { + $pkg_file_path | hash-file + } + + if $registry.is_url and $hash != $row.hash { + let url = $url_or_path | url update-name $row.path + http get $url | save --force $pkg_file_path + } + + let new_hash = $pkg_file_path | hash-file + + if $new_hash != $row.hash { + throw-error ($'Content of package file ($pkg_file_path)' + + $' does not match expected hash ($row.hash)') + } + + open $pkg_file_path + } + | flatten { - name: $name - path: $path + registry_name: $name + registry_path: $registry.path pkgs: $pkgs } } diff --git a/nupm/utils/version.nu b/nupm/utils/version.nu index 58eb36a..0a24b3b 100644 --- a/nupm/utils/version.nu +++ b/nupm/utils/version.nu @@ -3,16 +3,10 @@ # We might move some of this to Nushell builtins # Sort packages by version -def sort-by-version []: table -> table { +export def sort-by-version []: table -> table { sort-by version } -# Check if the target version is equal or higher than the target version -def matches-version [version: string]: string -> bool { - # TODO: Add proper version matching - $in == $version -} - # Filter packages by version and sort them by version export def filter-by-version [version: any]: table -> table { if $version == null { @@ -22,3 +16,9 @@ export def filter-by-version [version: any]: table -> table bool { + # TODO: Add proper version matching + $in == $version +} diff --git a/registry.nuon b/registry.nuon deleted file mode 100644 index c6c2346..0000000 --- a/registry.nuon +++ /dev/null @@ -1,373 +0,0 @@ -# Registry is a NUON file that tells nupm where to look for packages -# -# Currently, these package types are supported: -# * git ..... package is an online git repository -# * local ... package is on a local filesystem -# -# The package type defines the columns of the registry record. Each column holds -# holds a table of packages. -# -# Git packages accept the following columns: -# * name ....... name of the package -# * version .... version of the package -# * url ........ Git URL of the package -# * revision ... Git revision to check out when installing the package (commit -# hash, version, branch name, ...) -# * path ....... Path relative to the repository root where to look for nupm.nuon -# -# Local packages accept the following columns: -# * name ....... name of the package -# * version .... version of the package -# * path ....... Path where to look for nupm.nuon. It can be absolute, or -# relative. If relative, then relative to the registry file. -# -# One registry can contain packages with the same name, but they must be of -# different version. - -{ - git: [ - [ - name, - version, - url, - revision, - path - ]; - [ - nu_plugin_audio_hook, - "0.1.12", - "https://github.com/FMotalleb/nu_plugin_audio_hook", - "v0.1.12", - . - ], - [ - nu_plugin_clipboard, - "0.3.4", - "https://github.com/FMotalleb/nu_plugin_clipboard", - "27faf8d", - . - ], - [ - nu_plugin_clipboard, - "0.91.0", - "https://github.com/FMotalleb/nu_plugin_clipboard", - "2cd2a67", - . - ], - [ - nu_plugin_clipboard, - "0.92.1", - "https://github.com/FMotalleb/nu_plugin_clipboard", - "98d7102", - . - ], - [ - nu_plugin_desktop_notifications, - "1.0.7", - "https://github.com/FMotalleb/nu_plugin_desktop_notifications", - "7556310", - . - ], - [ - nu_plugin_image, - "0.3.2", - "https://github.com/FMotalleb/nu_plugin_image", - "7703e79", - . - ], - [ - nu_plugin_port_list, - "1.2.10", - "https://github.com/FMotalleb/nu_plugin_port_list", - "dddd72d", - . - ], - [ - nu_plugin_port_list, - "1.2.11", - "https://github.com/FMotalleb/nu_plugin_port_list", - "6bef9d8", - . - ], - [ - nu_plugin_port_scan, - "1.0.10", - "https://github.com/FMotalleb/nu_plugin_port_scan", - "7424a69", - . - ], - [ - nu_plugin_port_scan, - "1.0.11", - "https://github.com/FMotalleb/nu_plugin_port_scan", - "d4e6c8d", - . - ], - [ - nu_plugin_qr_maker, - "1.0.2", - "https://github.com/FMotalleb/nu_plugin_qr_maker", - "73bf1e4", - . - ], - [ - nu-git-manager, - "0.7.0", - "https://github.com/amtoine/nu-git-manager", - "0.7.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.7.0", - "https://github.com/amtoine/nu-git-manager", - "0.7.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.6.0", - "https://github.com/amtoine/nu-git-manager", - "0.6.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.6.0", - "https://github.com/amtoine/nu-git-manager", - "0.6.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.5.0", - "https://github.com/amtoine/nu-git-manager", - "0.5.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.5.0", - "https://github.com/amtoine/nu-git-manager", - "0.5.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.4.0", - "https://github.com/amtoine/nu-git-manager", - "0.4.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.4.0", - "https://github.com/amtoine/nu-git-manager", - "0.4.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.3.0", - "https://github.com/amtoine/nu-git-manager", - "0.3.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.3.0", - "https://github.com/amtoine/nu-git-manager", - "0.3.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.2.0", - "https://github.com/amtoine/nu-git-manager", - "0.2.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.2.0", - "https://github.com/amtoine/nu-git-manager", - "0.2.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-git-manager, - "0.1.0", - "https://github.com/amtoine/nu-git-manager", - "0.1.0", - pkgs/nu-git-manager - ], - [ - nu-git-manager-sugar, - "0.1.0", - "https://github.com/amtoine/nu-git-manager", - "0.1.0", - pkgs/nu-git-manager-sugar - ], - [ - nu-pomodoro, - "0.1.0", - "https://github.com/amtoine/nu-pomodoro", - "main", - . - ], - [ - nu-right-prompt, - "0.1.0", - "https://github.com/amtoine/nu-right-prompt", - "main", - . - ], - [ - nu_plugin_explore, - "0.1.2", - "https://github.com/amtoine/nu_plugin_explore", - "0.1.2", - . - ], - [ - nu_plugin_explore, - "0.2.0", - "https://github.com/amtoine/nu_plugin_explore", - "0.2.0", - . - ], - [ - nu_plugin_explore, - "0.92.0", - "https://github.com/amtoine/nu_plugin_explore", - "0.92.", - . - ], - [ - nu_plugin_explore, - "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1", - "https://github.com/amtoine/nu_plugin_explore", - "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1", - . - ], - [ - nu_plugin_explore, - "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc", - "https://github.com/amtoine/nu_plugin_explore", - "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc", - . - ], - [ - nu_plugin_explore, - "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c", - "https://github.com/amtoine/nu_plugin_explore", - "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c", - . - ], - [ - nu_plugin_explore, - "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89", - "https://github.com/amtoine/nu_plugin_explore", - "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89", - . - ], - [ - nu_plugin_explore, - "0.93.0", - "https://github.com/amtoine/nu_plugin_explore", - "0.93.0", - . - ], - [ - nu-clippy, - "0.1.0", - "https://github.com/amtoine/scripts", - "b7c3401b4d2019909af203bfe89207aa39d52a1e", - nu-clippy - ], - [ - nu-logout, - "0.1.0", - "https://github.com/amtoine/scripts", - "b7c3401b4d2019909af203bfe89207aa39d52a1e", - nu-logout - ], - [ - nu-monitor-manager, - "0.1.0", - "https://github.com/amtoine/scripts", - "b7c3401b4d2019909af203bfe89207aa39d52a1e", - nu-monitor-manager - ], - [ - nu-scripts, - "0.1.0", - "https://github.com/amtoine/scripts", - "b7c3401b4d2019909af203bfe89207aa39d52a1e", - nu-scripts - ], - [ - nu-sound-manager, - "0.1.0", - "https://github.com/amtoine/scripts", - "b7c3401b4d2019909af203bfe89207aa39d52a1e", - nu-sound-manager - ], - [ - nu-zellij, - "0.1.0", - "https://github.com/amtoine/zellij-layouts", - "46f4ded194a13b6acfb7b5b25ea9d179e4e74e12", - nu-zellij - ], - [ - nu-hooks, - "0.1.0", - "https://github.com/nushell/nu_scripts", - "f04cb44", - nu-hooks - ], - [ - nu-themes, - "0.1.0", - "https://github.com/nushell/nu_scripts", - "f04cb44", - themes - ], - [ - nupm, - "0.1.0", - "https://github.com/nushell/nupm", - "29916fc", - . - ], - [ - tmux-sessionizer, - "0.1.0", - "https://github.com/amtoine/tmux-sessionizer", - "18f5cef534b8b494e4dee645e453231dd5d1bc4c", - . - ], - [ - tmux-sessionizer, - "main", - "https://github.com/amtoine/tmux-sessionizer", - "main", - . - ], - [ - nu-discord-update, - "0.1.0", - "https://github.com/amtoine/nu-discord-update", - "0284223340519630ee94d56c224cf8611abe2d0b", - . - ], - [ - nu-fonts-install, - "0.1.0", - "https://github.com/amtoine/nu-fonts-install", - "6b03e9eec09c6784393a725308c34d301a67f7e4", - . - ] - ] -} diff --git a/registry/nu-clippy.nuon b/registry/nu-clippy.nuon new file mode 100644 index 0000000..81ebc5c --- /dev/null +++ b/registry/nu-clippy.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-clippy, "0.1.0", nu-clippy, git, {url: "https://github.com/amtoine/scripts", revision: "b7c3401b4d2019909af203bfe89207aa39d52a1e"}]] \ No newline at end of file diff --git a/registry/nu-discord-update.nuon b/registry/nu-discord-update.nuon new file mode 100644 index 0000000..e6b6c76 --- /dev/null +++ b/registry/nu-discord-update.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-discord-update, "0.1.0", null, git, {url: "https://github.com/amtoine/nu-discord-update", revision: "0284223340519630ee94d56c224cf8611abe2d0b"}]] \ No newline at end of file diff --git a/registry/nu-fonts-install.nuon b/registry/nu-fonts-install.nuon new file mode 100644 index 0000000..e795e1f --- /dev/null +++ b/registry/nu-fonts-install.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-fonts-install, "0.1.0", null, git, {url: "https://github.com/amtoine/nu-fonts-install", revision: "6b03e9eec09c6784393a725308c34d301a67f7e4"}]] \ No newline at end of file diff --git a/registry/nu-git-manager-sugar.nuon b/registry/nu-git-manager-sugar.nuon new file mode 100644 index 0000000..dfb58f6 --- /dev/null +++ b/registry/nu-git-manager-sugar.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-git-manager-sugar, "0.1.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.1.0"}], [nu-git-manager-sugar, "0.2.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.2.0"}], [nu-git-manager-sugar, "0.3.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.3.0"}], [nu-git-manager-sugar, "0.4.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.4.0"}], [nu-git-manager-sugar, "0.5.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.5.0"}], [nu-git-manager-sugar, "0.6.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.6.0"}], [nu-git-manager-sugar, "0.7.0", pkgs/nu-git-manager-sugar, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.7.0"}]] \ No newline at end of file diff --git a/registry/nu-git-manager.nuon b/registry/nu-git-manager.nuon new file mode 100644 index 0000000..aaf66a5 --- /dev/null +++ b/registry/nu-git-manager.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-git-manager, "0.1.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.1.0"}], [nu-git-manager, "0.2.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.2.0"}], [nu-git-manager, "0.3.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.3.0"}], [nu-git-manager, "0.4.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.4.0"}], [nu-git-manager, "0.5.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.5.0"}], [nu-git-manager, "0.6.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.6.0"}], [nu-git-manager, "0.7.0", pkgs/nu-git-manager, git, {url: "https://github.com/amtoine/nu-git-manager", revision: "0.7.0"}]] \ No newline at end of file diff --git a/registry/nu-hooks.nuon b/registry/nu-hooks.nuon new file mode 100644 index 0000000..348ce89 --- /dev/null +++ b/registry/nu-hooks.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-hooks, "0.1.0", nu-hooks, git, {url: "https://github.com/nushell/nu_scripts", revision: "f04cb44"}]] \ No newline at end of file diff --git a/registry/nu-logout.nuon b/registry/nu-logout.nuon new file mode 100644 index 0000000..59ae01b --- /dev/null +++ b/registry/nu-logout.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-logout, "0.1.0", nu-logout, git, {url: "https://github.com/amtoine/scripts", revision: "b7c3401b4d2019909af203bfe89207aa39d52a1e"}]] \ No newline at end of file diff --git a/registry/nu-monitor-manager.nuon b/registry/nu-monitor-manager.nuon new file mode 100644 index 0000000..a2fd2e0 --- /dev/null +++ b/registry/nu-monitor-manager.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-monitor-manager, "0.1.0", nu-monitor-manager, git, {url: "https://github.com/amtoine/scripts", revision: "b7c3401b4d2019909af203bfe89207aa39d52a1e"}]] \ No newline at end of file diff --git a/registry/nu-pomodoro.nuon b/registry/nu-pomodoro.nuon new file mode 100644 index 0000000..4bfa1dd --- /dev/null +++ b/registry/nu-pomodoro.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-pomodoro, "0.1.0", null, git, {url: "https://github.com/amtoine/nu-pomodoro", revision: main}]] \ No newline at end of file diff --git a/registry/nu-right-prompt.nuon b/registry/nu-right-prompt.nuon new file mode 100644 index 0000000..d55d578 --- /dev/null +++ b/registry/nu-right-prompt.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-right-prompt, "0.1.0", null, git, {url: "https://github.com/amtoine/nu-right-prompt", revision: main}]] \ No newline at end of file diff --git a/registry/nu-scripts.nuon b/registry/nu-scripts.nuon new file mode 100644 index 0000000..9c09b9e --- /dev/null +++ b/registry/nu-scripts.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-scripts, "0.1.0", nu-scripts, git, {url: "https://github.com/amtoine/scripts", revision: "b7c3401b4d2019909af203bfe89207aa39d52a1e"}]] \ No newline at end of file diff --git a/registry/nu-sound-manager.nuon b/registry/nu-sound-manager.nuon new file mode 100644 index 0000000..712c145 --- /dev/null +++ b/registry/nu-sound-manager.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-sound-manager, "0.1.0", nu-sound-manager, git, {url: "https://github.com/amtoine/scripts", revision: "b7c3401b4d2019909af203bfe89207aa39d52a1e"}]] \ No newline at end of file diff --git a/registry/nu-themes.nuon b/registry/nu-themes.nuon new file mode 100644 index 0000000..45752e3 --- /dev/null +++ b/registry/nu-themes.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-themes, "0.1.0", themes, git, {url: "https://github.com/nushell/nu_scripts", revision: "f04cb44"}]] \ No newline at end of file diff --git a/registry/nu-zellij.nuon b/registry/nu-zellij.nuon new file mode 100644 index 0000000..dcf0cb3 --- /dev/null +++ b/registry/nu-zellij.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu-zellij, "0.1.0", nu-zellij, git, {url: "https://github.com/amtoine/zellij-layouts", revision: "46f4ded194a13b6acfb7b5b25ea9d179e4e74e12"}]] \ No newline at end of file diff --git a/registry/nu_plugin_audio_hook.nuon b/registry/nu_plugin_audio_hook.nuon new file mode 100644 index 0000000..948ddc1 --- /dev/null +++ b/registry/nu_plugin_audio_hook.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_audio_hook, "0.1.12", null, git, {url: "https://github.com/FMotalleb/nu_plugin_audio_hook", revision: "v0.1.12"}]] \ No newline at end of file diff --git a/registry/nu_plugin_clipboard.nuon b/registry/nu_plugin_clipboard.nuon new file mode 100644 index 0000000..a65b5f7 --- /dev/null +++ b/registry/nu_plugin_clipboard.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_clipboard, "0.3.1", nu_plugin_clipboard.nuon, git, {url: "https://github.com/FMotalleb/nu_plugin_clipboard", revision: "1aa1cf99b3edec3ea7d962e91bac8af2b47d56b6"}], [nu_plugin_clipboard, "0.3.3", nu_plugin_clipboard.nuon, git, {url: "https://github.com/FMotalleb/nu_plugin_clipboard", revision: "97deea6845e2ae80e31b32892b6fc8357045e579"}], [nu_plugin_clipboard, "0.3.4", nu_plugin_clipboard.nuon, git, {url: "https://github.com/FMotalleb/nu_plugin_clipboard", revision: "27faf8d987cda6400f1a0f98a58c27fda4435d5e"}], [nu_plugin_clipboard, "0.91.0", nu_plugin_clipboard.nuon, git, {url: "https://github.com/FMotalleb/nu_plugin_clipboard", revision: "089cc15a168ffe790cae6ed608c84e51e689752c"}], [nu_plugin_clipboard, "0.93.0", nu_plugin_clipboard.nuon, git, {url: "https://github.com/FMotalleb/nu_plugin_clipboard", revision: "163bbb7617d24527e1a367a33922ec24ff57a26c"}]] \ No newline at end of file diff --git a/registry/nu_plugin_desktop_notifications.nuon b/registry/nu_plugin_desktop_notifications.nuon new file mode 100644 index 0000000..9e59ebd --- /dev/null +++ b/registry/nu_plugin_desktop_notifications.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_desktop_notifications, "1.0.7", null, git, {url: "https://github.com/FMotalleb/nu_plugin_desktop_notifications", revision: "7556310"}]] \ No newline at end of file diff --git a/registry/nu_plugin_explore.nuon b/registry/nu_plugin_explore.nuon new file mode 100644 index 0000000..d54119c --- /dev/null +++ b/registry/nu_plugin_explore.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_explore, "0.1.2", nu_plugin_registry.nuon, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "e5518c7f25cec3537bf897a7ef8d1818eb76aa94"}], [nu_plugin_explore, "0.93.0", nu_plugin_registry.nuon, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "15d87012538084d73571718af5b5e858de447065"}]] \ No newline at end of file diff --git a/registry/nu_plugin_image.nuon b/registry/nu_plugin_image.nuon new file mode 100644 index 0000000..b7c890e --- /dev/null +++ b/registry/nu_plugin_image.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_image, "0.3.2", null, git, {url: "https://github.com/FMotalleb/nu_plugin_image", revision: "7703e79"}]] \ No newline at end of file diff --git a/registry/nu_plugin_port_list.nuon b/registry/nu_plugin_port_list.nuon new file mode 100644 index 0000000..26fff62 --- /dev/null +++ b/registry/nu_plugin_port_list.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_port_list, "1.2.10", null, git, {url: "https://github.com/FMotalleb/nu_plugin_port_list", revision: "dddd72d"}], [nu_plugin_port_list, "1.2.11", null, git, {url: "https://github.com/FMotalleb/nu_plugin_port_list", revision: "6bef9d8"}]] \ No newline at end of file diff --git a/registry/nu_plugin_port_scan.nuon b/registry/nu_plugin_port_scan.nuon new file mode 100644 index 0000000..99f69d3 --- /dev/null +++ b/registry/nu_plugin_port_scan.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_port_scan, "1.0.10", null, git, {url: "https://github.com/FMotalleb/nu_plugin_port_scan", revision: "7424a69"}], [nu_plugin_port_scan, "1.0.11", null, git, {url: "https://github.com/FMotalleb/nu_plugin_port_scan", revision: "d4e6c8d"}]] \ No newline at end of file diff --git a/registry/nu_plugin_qr_maker.nuon b/registry/nu_plugin_qr_maker.nuon new file mode 100644 index 0000000..9586636 --- /dev/null +++ b/registry/nu_plugin_qr_maker.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nu_plugin_qr_maker, "1.0.2", null, git, {url: "https://github.com/FMotalleb/nu_plugin_qr_maker", revision: "73bf1e4"}]] \ No newline at end of file diff --git a/registry/nupm_pkg.nuon b/registry/nupm_pkg.nuon new file mode 100644 index 0000000..737f62d --- /dev/null +++ b/registry/nupm_pkg.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [nupm, "0.1.0", null, git, {url: "https://github.com/nushell/nupm", revision: "29916fc"}]] \ No newline at end of file diff --git a/registry/registry.nuon b/registry/registry.nuon new file mode 100644 index 0000000..c0e02ff --- /dev/null +++ b/registry/registry.nuon @@ -0,0 +1 @@ +[[name, path, hash]; [nu-clippy, nu-clippy.nuon, "md5-15ccbe07dfb7d5f2de260b2b40bf36b5"], [nu-discord-update, nu-discord-update.nuon, "md5-d593c0f41ffd71873028871fcd74b5a9"], [nu-fonts-install, nu-fonts-install.nuon, "md5-cd57f47aeece1679e2febc438d195e8d"], [nu-git-manager, nu-git-manager.nuon, "md5-4aaae15412fb84233fcb19716f6b7e89"], [nu-git-manager-sugar, nu-git-manager-sugar.nuon, "md5-d0c7641c0b369e7c944cc668741734d9"], [nu-hooks, nu-hooks.nuon, "md5-5368e1bc61e9a567263fa4cc55c29783"], [nu-logout, nu-logout.nuon, "md5-9cb6e927f4823dafa8b48867ef1cf70f"], [nu-monitor-manager, nu-monitor-manager.nuon, "md5-15f64df367e8b59606f9b29347cce8a9"], [nu-pomodoro, nu-pomodoro.nuon, "md5-53e18e3476358a813e3ba289dbc5609c"], [nu-right-prompt, nu-right-prompt.nuon, "md5-8a684d7720f0703943317709abfc87bb"], [nu-scripts, nu-scripts.nuon, "md5-733ba206358f545ba9274854fda1c4a5"], [nu-sound-manager, nu-sound-manager.nuon, "md5-f305740d2e93cfeb76c40302f7f5246a"], [nu-themes, nu-themes.nuon, "md5-e303b8f08b1158aacef80a53c5432662"], [nu-zellij, nu-zellij.nuon, "md5-5b0c46f155261507c08c693366639c7a"], [nu_plugin_audio_hook, nu_plugin_audio_hook.nuon, "md5-b2f7807acf002c5e02e1c43e2f80eb16"], [nu_plugin_clipboard, nu_plugin_clipboard.nuon, "md5-6b639ea8c8db03e0148cd00ec6ff9e69"], [nu_plugin_desktop_notifications, nu_plugin_desktop_notifications.nuon, "md5-f682e6fd6eecf2743686a3da71c1917c"], [nu_plugin_explore, nu_plugin_explore.nuon, "md5-3ae85f18e11c0e830f450c5882f9dc47"], [nu_plugin_image, nu_plugin_image.nuon, "md5-d842828405fa74d1056767fa4c3de248"], [nu_plugin_port_list, nu_plugin_port_list.nuon, "md5-59cf1913f6041f45d8c4b4a99d518501"], [nu_plugin_port_scan, nu_plugin_port_scan.nuon, "md5-c4a8347de871a0f626c78d1b05740e19"], [nu_plugin_qr_maker, nu_plugin_qr_maker.nuon, "md5-3eb8130c45318fe8a90abaf0680574de"], [nupm, nupm_pkg.nuon, "md5-2cf3b52cb9535f74d94d7b68abe0acd1"], [tmux-sessionizer, tmux-sessionizer.nuon, "md5-252d0e1da316ff5f597402d2a2bb09b5"]] \ No newline at end of file diff --git a/registry/tmux-sessionizer.nuon b/registry/tmux-sessionizer.nuon new file mode 100644 index 0000000..bde119b --- /dev/null +++ b/registry/tmux-sessionizer.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [tmux-sessionizer, "0.1.0", null, git, {url: "https://github.com/amtoine/tmux-sessionizer", revision: "18f5cef534b8b494e4dee645e453231dd5d1bc4c"}], [tmux-sessionizer, main, null, git, {url: "https://github.com/amtoine/tmux-sessionizer", revision: main}]] \ No newline at end of file diff --git a/tests/mod.nu b/tests/mod.nu index 8b25aab..3acc556 100644 --- a/tests/mod.nu +++ b/tests/mod.nu @@ -3,7 +3,7 @@ use std assert use ../nupm/utils/dirs.nu tmp-dir use ../nupm -const TEST_REGISTRY_PATH = ([tests packages registry.nuon] | path join) +const TEST_REGISTRY_PATH = ([tests packages registry registry.nuon] | path join) def with-test-env [closure: closure]: nothing -> nothing { @@ -119,7 +119,7 @@ export def install-package-not-found [] { export def search-registry [] { with-test-env { - assert ((nupm search spam | get pkgs.0 | length) == 4) + assert ((nupm search spam | length) == 4) } } @@ -147,3 +147,32 @@ export def env-vars-are-set [] { assert equal $env.NUPM_CACHE $dirs.DEFAULT_NUPM_CACHE assert equal $env.NUPM_REGISTRIES $dirs.DEFAULT_NUPM_REGISTRIES } + +export def generate-local-registry [] { + with-test-env { + mkdir ($env.NUPM_TEMP | path join packages registry) + + let reg_file = [tests packages registry registry.nuon] | path join + let tmp_reg_file = [ + $env.NUPM_TEMP packages registry test_registry.nuon + ] + | path join + + touch $tmp_reg_file + + [spam_script spam_script_old spam_custom spam_module] | each {|pkg| + cd ([tests packages $pkg] | path join) + nupm publish $tmp_reg_file --local --save --path (".." | path join $pkg) + } + + let actual = open $tmp_reg_file | to nuon + let expected = open $reg_file | to nuon + + 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)) }) +} diff --git a/tests/packages/registry.nuon b/tests/packages/registry.nuon deleted file mode 100644 index 5eed899..0000000 --- a/tests/packages/registry.nuon +++ /dev/null @@ -1,10 +0,0 @@ -# Testing registry for testing packages -{ - local: [ - [name version path]; - [spam_script 0.2.0 spam_script] - [spam_script 0.1.0 spam_script_old] - [spam_custom 0.1.0 spam_custom] - [spam_module 0.1.0 spam_module] - ] -} diff --git a/tests/packages/registry/registry.nuon b/tests/packages/registry/registry.nuon new file mode 100644 index 0000000..bc4ae11 --- /dev/null +++ b/tests/packages/registry/registry.nuon @@ -0,0 +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"]] \ No newline at end of file diff --git a/tests/packages/registry/spam_custom.nuon b/tests/packages/registry/spam_custom.nuon new file mode 100644 index 0000000..2cbe70e --- /dev/null +++ b/tests/packages/registry/spam_custom.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [spam_custom, "0.1.0", ../spam_custom, local, null]] \ No newline at end of file diff --git a/tests/packages/registry/spam_module.nuon b/tests/packages/registry/spam_module.nuon new file mode 100644 index 0000000..aab116b --- /dev/null +++ b/tests/packages/registry/spam_module.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [spam_module, "0.1.0", ../spam_module, local, null]] \ No newline at end of file diff --git a/tests/packages/registry/spam_script.nuon b/tests/packages/registry/spam_script.nuon new file mode 100644 index 0000000..618d532 --- /dev/null +++ b/tests/packages/registry/spam_script.nuon @@ -0,0 +1 @@ +[[name, version, path, type, info]; [spam_script, "0.1.0", ../spam_script_old, local, null], [spam_script, "0.2.0", ../spam_script, local, null]] \ No newline at end of file diff --git a/toolkit.nu b/toolkit.nu index 0d15bfe..65f6c1c 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -1,10 +1,24 @@ -export def --env set-nupm-env [] { - $env.NUPM_HOME = ('./_nupm_dev' | path expand) - $env.NUPM_CACHE = ('./_nupm_dev/cache' | path expand) - $env.NUPM_TEMP = ('./_nupm_dev/tmp' | path expand) +export def --env set-nupm-env [--clear] { + if ($env.PWD | path basename) != 'nupm' { + print 'Run from nupm repo root' + return + } - $env.PATH ++= [('./_nupm_dev/scripts' | path expand)] - $env.NU_LIB_DIRS ++= [('./_nupm_dev/modules' | path expand)] + if $clear { + rm -rf _nupm_dev + } + + $env.NUPM_HOME = ($env.PWD | path join _nupm_dev) + $env.NUPM_CACHE = ($env.PWD | path join _nupm_dev cache) + $env.NUPM_TEMP = ($env.PWD | path join _nupm_dev tmp) + $env.NUPM_REGISTRIES = { nupm_dev: ($env.PWD | path join registry registry.nuon) } + + if $nu.os-info.family == 'windows' and 'Path' in $env { + $env.Path = ($env.Path | prepend ($env.PWD | path join _nupm_dev scripts)) + } else if 'PATH' in $env { + $env.PATH = ($env.PATH | prepend ($env.PWD | path join _nupm_dev scripts)) + } + $env.NU_LIB_DIRS = ($env.NU_LIB_DIRS | prepend ($env.PWD | path join _nupm_dev modules)) print-nupm-env } @@ -13,6 +27,7 @@ export def print-nupm-env [] { print $'NUPM_HOME: ($env.NUPM_HOME?)' print $'NUPM_CACHE: ($env.NUPM_CACHE?)' print $'NUPM_TEMP: ($env.NUPM_TEMP?)' - print $'PATH: ($env.PATH?)' + print $"PATH: ($env.PATH? | default $env.Path? | default [])" print $'NU_LIB_DIRS: ($env.NU_LIB_DIRS?)' + print $'NUPM_REGISTRIES: ($env.NUPM_REGISTRIES?)' }