~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.17.0 Latest 2 packages, 1 image

1
10

The releases page shows how to install an npm package

Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:web/npm
.changeset/npm-releases-page.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: patch
---
# The releases page shows how to install an npm package
A release published with `npm publish` shows the `.npmrc` line naming its repository's registry and the `npm install` that installs it, or for an unscoped package, the `npm install` of its tarball, rather than its `.tgz`.
crates/knotless-serve/src/web/releases.rs+3−0
@@ -42,6 +42,8 @@ pub struct ReleaseView {
yanked: bool,
#[serde(rename = "crate", skip_serializing_if = "std::ops::Not::not")]
is_crate: bool,
#[serde(skip_serializing_if = "std::ops::Not::not")]
npm: bool,
#[serde(skip_serializing_if = "Option::is_none")]
commit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -213,6 +215,7 @@ pub(super) async fn list_releases(
.map(|n| markdown(n, &base, &base, "", None)),
image: image(&r),
is_crate: r.cargo.is_some(),
npm: r.npm.is_some(),
uri,
package: r.package,
version: r.version,
crates/knotless-serve/tests/web.rs+5−0
@@ -4007,6 +4007,11 @@ fn an_npm_registry() {
);
assert_eq!(found["objects"].as_array().unwrap().len(), 1);
assert_eq!(site.json(&format!("{here}/-/v1/search"))["total"], 3);
// The releases page knows each for an npm package.
let repo = format!("at://{did}/dev.knotless.repo/packages");
let listed = site.json(&xrpc("listReleases", &[("repo", &repo)]));
let listed = listed["releases"].as_array().unwrap();
assert!(listed.iter().all(|r| r["npm"] == true), "{listed:?}");
// What npm would never send is refused too.
let tarball = |dir: &std::path::Path, file: &str| {
docs/design/packages.md+5−2
@@ -401,9 +401,12 @@ A Releases tab, with how many releases there are, opens the releases
page: every version of every package, newest first, each with its
notes, the commit it was built from and its files, each with its size
and SHA-256. An image shows the `docker pull` command for it rather than
its blobs, and a crate the lines naming its repository's
its blobs, a crate the lines naming its repository's
[registry](#crates) in `.cargo/config.toml` and the `cargo add` that
adds it, rather than its `.crate`.
adds it, rather than its `.crate`, and an npm package the line of
`.npmrc` sending its scope to its repository's
[registry](#npm-packages) and the `npm install` that installs it, or for
an unscoped package, the `npm install` of its tarball.
Each file's name links to download it, from
`/<owner>/<repo>/releases/download/<package>/<version>/<file>`.
docs/reference/api.md+1−1
@@ -658,7 +658,7 @@ name it has now.
| `dev.knotless.getActorGists?actor=` | an account's gists, newest first, found as `getActorRepos` finds its repositories: each with the first ten `files` at the root of its default branch (`{name}`, ignoring case), `fileCount`, all of them, read from its mirror (none when it has none, or nothing was pushed), `starCount` and `forkCount` from the index (0 without one), and `commentCount`, how many comments `getGistComments` lists on it (none without an index); `ProfileNotFound` for an unknown account |
| `dev.knotless.getGistComments?gist=` | what is said on a gist, oldest first: the comments whose `subject` is its record, each a `commentView` as `getThread` gives one, less those its owner hid, those by accounts it blocked, and those taken down; with an asker, `viewer.hide`, true for the gist's owner, who may hide them with `hideItem`. 404 `NotFound` for a repository that is not a gist, or with no index |
| `dev.knotless.getRepo?repo=` | a repository: its owner, `kind: "gist"` for a gist, description, `links` (only http and https ones), `topics`, default branch, counts, languages, `collaborators` (the first twenty its record names, besides its owner) and `collaboratorCount`, `private` if it is, `archivedAt` if its owner archived it, and `site` if it has a website this server serves: its `url`, `deployedAt`, the `commit` its deployer named, and its `check` only when that check is from a runner the repository names; with an asker, `viewer`: its `star`, a `transfer` offered to it, the `labels` it may put on the repository's pulls and issues, and `admin: true` when it may change the repository's settings, as its owner or an admin who joined the organization that owns it |
| `dev.knotless.listReleases?repo=&package=&limit=&cursor=` | its releases ([packages.md](../design/packages.md#on-the-pages)), newest first, 30 a page by default, of one `package` if given: each with `latest` when it is its package's latest, `yanked` when its owner withdrew it, `image` when its files are an OCI layout's, `crate` when it is a crate of the repository's Cargo registry, its notes as Markdown and as `html`, and its files' names, sizes and SHA-256; and every package it publishes, by name, with its latest version, how many releases it has and whether it is an image. None for a private repository or without an index |
| `dev.knotless.listReleases?repo=&package=&limit=&cursor=` | its releases ([packages.md](../design/packages.md#on-the-pages)), newest first, 30 a page by default, of one `package` if given: each with `latest` when it is its package's latest, `yanked` when its owner withdrew it, `image` when its files are an OCI layout's, `crate` when it is a crate of the repository's Cargo registry, `npm` when it is a package of its npm registry, its notes as Markdown and as `html`, and its files' names, sizes and SHA-256; and every package it publishes, by name, with its latest version, how many releases it has and whether it is an image. None for a private repository or without an index |
| `dev.knotless.getTree?repo=&ref=&path=` | a folder, its README and the newest checks of its last commit |
| `dev.knotless.listPaths?repo=&ref=&limit=` | every folder and file at a revision, the shallowest first, at most 50,000, and `truncated` when the deepest were left out: for Go to file |
| `dev.knotless.getLastCommits?repo=&ref=&path=` | the newest commit to change each entry of a folder, and at the root, how many commits the ref's history holds |
lexicons/dev/knotless/defs.json+1−0
@@ -373,6 +373,7 @@
"image": { "type": "boolean", "description": "True when its files are a container image's OCI layout: an `index.json` beside blobs named `sha256-<hex>`, pulled by `docker pull` rather than downloaded." },
"yanked": { "type": "boolean", "description": "True when its owner withdrew it, by a dev.knotless.releaseYank record: its files can still be read, but it is no one's latest." },
"crate": { "type": "boolean", "description": "True when it is a crate, added with Cargo from its repository's registry, at `/cargo/<owner's DID>/<repository's key>/`, rather than downloaded." },
"npm": { "type": "boolean", "description": "True when it is an npm package, installed with npm from its repository's registry, at `/npm/<owner's DID>/<repository's key>/`, rather than downloaded." },
"commit": { "type": "string", "description": "The hex object ID of the commit its files were built from, if its record names one." },
"check": { "type": "string", "format": "at-uri", "description": "The dev.knotless.check of the run that built it, if its record names one." },
"notes": { "type": "string", "description": "What changed since the version before, in Markdown, as its record says." },
web/src/lib/organisms/ReleaseCard.svelte+14−3
@@ -2,7 +2,7 @@
import type { ReleaseView } from '#lib/lexicons/dev/knotless/defs.ts';
import { page } from '$app/state';
import { ago, plural, repoHref, size } from '#lib/format.ts';
import { cargoUse, downloadHref, pullCommand, releaseAnchor } from '#lib/releases.ts';
import { cargoUse, downloadHref, npmUse, pullCommand, releaseAnchor } from '#lib/releases.ts';
import Sha from '#lib/atoms/Sha.svelte';
import Time from '#lib/atoms/Time.svelte';
import Command from '#lib/molecules/Command.svelte';
@@ -14,8 +14,9 @@
* commit, its notes, and its files, each with its size and SHA-256 and
* linked to download;
* or, for an image, the
* command that pulls it rather than its blobs, and for a crate, how
* Cargo adds it. A shared step's links to the step's page.
* command that pulls it rather than its blobs, and for a crate or an
* npm package, how Cargo or npm adds it. A shared step's links to the
* step's page.
*/
let { owner, name, release: r }: { owner: string; name: string; release: ReleaseView } = $props();
const step = $derived(stepOf(r.package));
@@ -23,6 +24,7 @@
const cargo = $derived(
r.crate ? cargoUse(page.url.origin, r.uri, name, r.package, r.version) : undefined
);
const npm = $derived(r.npm ? npmUse(page.url.origin, r.uri, r.package, r.version) : undefined);
</script>
<article class="box release" id={releaseAnchor(r)}>
@@ -54,6 +56,15 @@
A crate. Add the registry to <code>.cargo/config.toml</code>, then add the crate with Cargo.
</p>
</div>
{:else if npm}
<div class="release-pull">
{#if npm.config}<Command text={npm.config} />{/if}
<Command text={npm.add} />
<p class="mute">
{#if npm.config}An npm package. Add the registry to <code>.npmrc</code>, then install the
package with npm.{:else}An npm package, installed from its tarball.{/if}
</p>
</div>
{:else}
<ul class="list release-files" aria-label="Files">
{#each r.files as f (f.name)}
web/src/lib/releases.ts+34−7
@@ -1,5 +1,6 @@
// What the pages say of a repository's releases: which is a pre-release,
// how an image is pulled, how a crate is added, and where each is.
// how an image is pulled, how a crate or an npm package is added, and
// where each is.
import { repoHref, urlPath } from '#lib/format.ts';
@@ -22,12 +23,20 @@ export function pullCommand(
return `docker pull ${host}/${name}:${version}`;
}
/**
* The path of the registry a release, `uri`, is served from under `kind`
* (`cargo`, `npm`): at the owner's DID and the repository's key, which open
* its record's URI and key, as names can change and lockfiles keep it.
*/
function registryPath(kind: string, uri: string): string {
const [did, , rkey] = uri.replace(/^at:\/\//, '').split('/');
return `/${kind}/${did}/${rkey.split('.')[0]}/`;
}
/**
* What a crate's release, `uri`, says to Cargo, served from `origin`: the
* lines of `.cargo/config.toml` naming its repository's registry, as
* `registry`, and the command that adds the crate from it. The registry is
* at the owner's DID and the repository's key, which open its record's
* URI and key, as names can change and Cargo keeps it in `Cargo.lock`.
* `registry`, and the command that adds the crate from it.
*/
export function cargoUse(
origin: string,
@@ -36,15 +45,33 @@ export function cargoUse(
pkg: string,
version: string
): { config: string; add: string } {
const [did, , rkey] = uri.replace(/^at:\/\//, '').split('/');
const key = rkey.split('.')[0];
const name = registry.replace(/[^A-Za-z0-9_-]/g, '-').replace(/^[^A-Za-z_]/, 'r$&');
return {
config: `[registries.${name}]\nindex = "sparse+${origin}/cargo/${did}/${key}/"`,
config: `[registries.${name}]\nindex = "sparse+${origin}${registryPath('cargo', uri)}"`,
add: `cargo add ${pkg}@${version} --registry ${name}`
};
}
/**
* What an npm package's release, `uri`, says to npm, served from `origin`:
* for a scoped package, the line of `.npmrc` sending its scope to its
* repository's registry, and the command that installs it from there. An
* unscoped one is installed from its tarball, as sending every unscoped
* name to this registry would hide npm's own.
*/
export function npmUse(
origin: string,
uri: string,
pkg: string,
version: string
): { config?: string; add: string } {
const registry = `${origin}${registryPath('npm', uri)}`;
const scope = /^(@[^/]+)\//.exec(pkg)?.[1];
if (scope)
return { config: `${scope}:registry=${registry}`, add: `npm install ${pkg}@${version}` };
return { add: `npm install ${registry}${pkg}/-/${pkg}-${version}.tgz` };
}
/** The id a release has on the releases page, for a link to land on it. */
export const releaseAnchor = (r: { package: string; version: string }) =>
`${r.package}@${r.version}`;