function inspectLocalTarget
inspectLocalTarget(specifier: string): Promise<LocalTarget>

Reports what a resolved specifier points at, before anything is run on it.

Called once per invocation, ahead of discovery, so that a directory is refused before deno doc gets a chance to answer about a module nobody asked about. A non-file: specifier is "elsewhere" and touches no filesystem.

Every way of failing to answer is a LocalTarget, including a file: specifier that will not parse as a URL: binstruct "file://a b/x" used to escape as an uncaught TypeError and a stack trace, because the URL was decoded outside the try that guards the stat.

Examples

A module, a directory and a registry specifier

import { assertEquals } from "@std/assert";
import { inspectLocalTarget } from "./target.ts";

const module = await inspectLocalTarget(import.meta.resolve("./target.ts"));

assertEquals(module.kind, "module");

const directory = await inspectLocalTarget(import.meta.resolve("./"));

assertEquals(directory.kind, "directory");
if (directory.kind === "directory") {
  assertEquals(directory.modules.includes("target.ts"), true);
  assertEquals(directory.modules.includes("deno.json"), false);
}

assertEquals((await inspectLocalTarget("jsr:@binstruct/png")).kind, "elsewhere");

Nothing there at all

import { assertEquals } from "@std/assert";
import { inspectLocalTarget } from "./target.ts";

const missing = await inspectLocalTarget(
  import.meta.resolve("./no-such-module.ts"),
);

assertEquals(missing.kind, "missing");

A file: specifier that is not a URL is refused, not thrown

import { assertEquals } from "@std/assert";
import { inspectLocalTarget } from "./target.ts";

const malformed = await inspectLocalTarget("file://a b/x");

assertEquals(malformed.kind, "unreadable");

Parameters

specifier: string

A resolved specifier, e.g. jsr:@binstruct/png or a file: URL

Return Type

Promise<LocalTarget>

What is at the target, or "elsewhere" when it is not on this machine