Skip to content
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

Redesign registry; Allow publishing to registry #86

Merged
merged 46 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2f481af
Make test env more robust
kubouch Mar 22, 2024
e079bbb
Add nupm publish command
kubouch Mar 22, 2024
e66256f
Add registry doc
kubouch Mar 22, 2024
bcaa264
Remove top-level nupm publish
kubouch Mar 22, 2024
8e6fee5
Make test env more robust
kubouch Mar 22, 2024
3524db8
Add nupm publish command
kubouch Mar 22, 2024
1cefbe0
Add registry doc
kubouch Mar 22, 2024
5fc741b
Remove top-level nupm publish
kubouch Mar 22, 2024
30725d7
Fix toolkit env on Windows
kubouch Mar 25, 2024
852bef2
Reorder comparison
kubouch Mar 25, 2024
ed6172b
Add missing import
kubouch Mar 25, 2024
a8e5989
Revamp package search for new registry
kubouch Mar 25, 2024
d0c3f91
Add new registry style
kubouch Mar 25, 2024
1997de3
Merge
kubouch Mar 25, 2024
5ad5651
Change tests registry
kubouch Mar 25, 2024
9c8514c
Flatten search output
kubouch Mar 25, 2024
07c34b6
Fix online installs
kubouch Mar 25, 2024
0a86ddb
Rewrite nupm publish
kubouch Mar 26, 2024
7f16e18
Remove old registry
kubouch Mar 26, 2024
43411ae
Fix local publish and tests
kubouch Mar 26, 2024
638ba87
Remove comment
kubouch Mar 28, 2024
9e6bc4b
toolkit: Allow clearing dev directory
kubouch Mar 28, 2024
2704398
Remove 'url' column from registry file
kubouch Mar 28, 2024
fbdf282
Reword error message
kubouch Mar 28, 2024
156b688
Remove comments
kubouch Mar 28, 2024
a4ff708
Remove extra registry path print
kubouch Mar 28, 2024
66b9cb2
Add hashing of registry package files
kubouch Mar 28, 2024
bde509c
Add registry documentation
kubouch Mar 28, 2024
661865f
Change default registry to the new one
kubouch Mar 28, 2024
ecc8a00
Make path crossplatform
kubouch Apr 10, 2024
e9a952e
Remove comment
kubouch Apr 10, 2024
382728d
Compact PATH print
kubouch Apr 10, 2024
bb8b3c6
Try avoiding newlines when hashing nuon files
kubouch May 4, 2024
abba5c3
Merge branch 'main' into registry-revamp
kubouch May 4, 2024
4c80dbc
Revert "Try avoiding newlines when hashing nuon files"
kubouch May 4, 2024
714aaa6
Merge branch 'main' into registry-revamp
kubouch May 4, 2024
28326db
Better help msg
kubouch May 4, 2024
c428948
Replace \ with / in --path
kubouch May 4, 2024
c664440
Update docs
kubouch May 4, 2024
5c76423
Test for newlines in testing registry files
kubouch May 4, 2024
524e756
Update nupm/publish.nu
kubouch May 5, 2024
c20ccf9
Add usage note
kubouch May 5, 2024
4140560
publish missing versions of `nu_plugin_explore`
amtoine May 8, 2024
f1af612
Fix nu_plugin_explore registry entries
kubouch May 25, 2024
78b9baa
Fix nu_plugin_clipboard registry entries
kubouch May 25, 2024
b7003f1
Fix wrong pkg dir
kubouch May 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions docs/design/registry.md
Original file line number Diff line number Diff line change
@@ -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<url: string, revision: string>` 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`.
2 changes: 1 addition & 1 deletion nupm.nuon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
name: nupm
type: module
version: "0.1.0"
version: "0.2.0"
description: "Nushell package manager"
license: "LICENSE"
}
38 changes: 21 additions & 17 deletions nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -149,33 +148,37 @@ 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'
return $pkg_dir
}

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
Expand All @@ -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'
Expand All @@ -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
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion nupm/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading