function listScopePackages
listScopePackages(options?: ScopeListingOptions): Promise<ScopeListing>

Lists the packages of the @binstruct scope, live from JSR.

The answer is cached under the OS cache directory for a day, so repeated invocations cost one request between them and an offline run that has listed before still gets a list. When the request fails an expired cache is used in preference to nothing, and when there is no cache either the result is an empty list carrying the reason — never an exception, so the caller can always fall back to explaining the shorthand rule instead of a listing.

Examples

A live listing, without the network

import { assertEquals } from "@std/assert";
import { stub } from "@std/testing/mock";
import { listScopePackages } from "./scope.ts";

using _fetch = stub(
  globalThis,
  "fetch",
  () =>
    Promise.resolve(
      Response.json({
        items: [{ name: "png", description: "PNG.", latestVersion: "0.4.0" }],
      }),
    ),
);

const listing = await listScopePackages({ cacheDir: null });

assertEquals(listing.source, "network");
assertEquals(listing.packages, [
  { name: "png", description: "PNG.", latestVersion: "0.4.0" },
]);

A failure is a reason and an empty list, never a throw

import { assertEquals } from "@std/assert";
import { stub } from "@std/testing/mock";
import { listScopePackages } from "./scope.ts";

using _fetch = stub(globalThis, "fetch", () => Promise.reject(new TypeError("offline")));

const listing = await listScopePackages({ cacheDir: null });

assertEquals(listing.source, "none");
assertEquals(listing.packages, []);
assertEquals(listing.reason, "offline");

Parameters

optional
options: ScopeListingOptions

Cache location, clock and TTL overrides

Return Type

Promise<ScopeListing>

The packages and where they came from