Resolver for tarball dependencies that handles HTTP/HTTPS URLs and manages immutable cache redirects
npx @tessl/cli install tessl/npm-pnpm--tarball-resolver@1002.1.0@pnpm/tarball-resolver is a resolver for tarball dependencies that handles HTTP/HTTPS URLs. It processes tarball URLs from npm registries and other sources, managing redirects for immutable cache responses and filtering out direct repository URLs.
npm install @pnpm/tarball-resolverimport { resolveFromTarball, type TarballResolveResult } from "@pnpm/tarball-resolver";For CommonJS:
const { resolveFromTarball } = require("@pnpm/tarball-resolver");Note: Some older examples show require('@pnpm/tarball-resolver').default, but the named import is preferred.
import { resolveFromTarball } from "@pnpm/tarball-resolver";
import { createFetchFromRegistry } from "@pnpm/fetch";
// Create a fetch function for registry requests
const fetch = createFetchFromRegistry({});
// Resolve a tarball from npm registry
const result = await resolveFromTarball(fetch, {
bareSpecifier: "https://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz"
});
if (result) {
console.log("Resolved tarball:");
console.log("ID:", result.id);
console.log("Tarball URL:", result.resolution.tarball);
console.log("Resolved via:", result.resolvedVia);
}Resolves tarball dependencies from HTTP/HTTPS URLs, handling redirects for immutable responses and filtering out repository URLs.
async function resolveFromTarball(
fetchFromRegistry: FetchFromRegistry,
wantedDependency: { bareSpecifier: string }
): Promise<TarballResolveResult | null>;Parameters:
fetchFromRegistry: Function that performs HTTP requests to package registrieswantedDependency: Object containing the tarball URL to resolveReturns:
Promise<TarballResolveResult | null>: Resolution result or null if URL is not a valid tarballBehavior:
http: or https:null for non-HTTP/HTTPS URLsnull for direct repository URLs (GitHub, GitLab, Bitbucket)Usage Examples:
Resolving an immutable tarball (npm registry):
const result = await resolveFromTarball(fetch, {
bareSpecifier: "http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz"
});
// Returns result with HTTPS redirected URLResolving a mutable tarball:
const result = await resolveFromTarball(fetch, {
bareSpecifier: "https://github.com/hegemonic/taffydb/tarball/master"
});
// Returns result with original URLNon-tarball URLs (returns null):
// Repository URLs are filtered out
const result1 = await resolveFromTarball(fetch, {
bareSpecifier: "https://github.com/foo/bar"
});
// Returns null
// Non-HTTP URLs are filtered out
const result2 = await resolveFromTarball(fetch, {
bareSpecifier: "file:///path/to/local.tgz"
});
// Returns nullinterface TarballResolveResult extends ResolveResult {
normalizedBareSpecifier: string;
resolution: TarballResolution;
resolvedVia: 'url';
}The result object returned by resolveFromTarball when successful.
Properties:
id: Package resolution identifier (inherited from ResolveResult)normalizedBareSpecifier: The final tarball URL (after any redirects)resolution: Tarball resolution metadata containing the tarball URLresolvedVia: Always set to 'url' for tarball resolutionsinterface TarballResolution {
type?: undefined;
tarball: string;
integrity?: string;
path?: string;
}Resolution metadata for tarball dependencies.
Properties:
tarball: The URL of the tarball fileintegrity: Optional integrity hash for verificationpath: Optional path within the tarballtype: Always undefined for tarball resolutionstype FetchFromRegistry = (
url: string,
opts?: RequestInit & {
authHeaderValue?: string;
compress?: boolean;
retry?: RetryTimeoutOptions;
timeout?: number;
}
) => Promise<Response>;Function type for making HTTP requests to package registries.
Parameters:
url: The URL to fetchopts: Optional request options including authentication, compression, retry, and timeout settingsReturns:
Promise<Response>: Standard HTTP Response objecttype ResolveResult = {
id: PkgResolutionId;
latest?: string;
publishedAt?: string;
manifest?: DependencyManifest;
resolution: Resolution;
resolvedVia: string;
normalizedBareSpecifier?: string;
alias?: string;
};Base interface for all resolution results (from @pnpm/resolver-base).
type PkgResolutionId = string;Unique identifier for a resolved package (from @pnpm/resolver-base).