@velcro/strategy-cdn
Version:
Velcro resolver strategy for resolving modules from a cdn such as Unpkg or JsDelivr
61 lines • 2.49 kB
TypeScript
import { CancellationToken, Thenable, Uri } from "@velcro/common";
import { AbstractResolverStrategyWithRoot, ResolverContext, ResolverStrategy, ResolverStrategyWithRoot } from "@velcro/resolver";
declare const version = "__VERSION__";
interface AbstractCdn {
name: string;
isValidUrl(url: Uri): boolean;
normalizePackageListing(result: unknown): CdnStrategy.Directory;
parseUrl(url: Uri | string): CdnStrategy.Spec;
urlForPackageFile(spec: string, pathname: string): Uri;
urlForPackageList(spec: string): Uri;
}
declare namespace CdnStrategy {
type Spec = {
spec: string;
name: string;
version: string;
pathname: string;
};
type Directory = {
type: ResolverStrategy.EntryKind.Directory;
path: string;
files?: ReadonlyArray<Entry>;
};
type File = {
type: ResolverStrategy.EntryKind.File;
path: string;
};
type Entry = Directory | File;
type UrlContentFetcher = (href: string, token: CancellationToken) => Thenable<ArrayBuffer | null>;
}
declare class CdnStrategy extends AbstractResolverStrategyWithRoot implements ResolverStrategyWithRoot {
readonly cdn: AbstractCdn;
private readonly contentCache;
private readonly locks;
private readonly packageEntriesCache;
private readonly packageJsonCache;
private readonly readUrlFn;
constructor(readUrlFn: CdnStrategy.UrlContentFetcher, cdn: AbstractCdn);
private _withRootUriCheck;
getUrlForBareModule(ctx: ResolverContext, name: string, spec: string, path: string): Promise<ResolverStrategy.BareModuleResult>;
getCanonicalUrl(ctx: ResolverContext, uri: Uri): Promise<ResolverStrategy.CanonicalizeResult>;
getResolveRoot(ctx: ResolverContext, uri: Uri): Promise<ResolverStrategy.ResolveRootResult>;
getRootUrl(): {
uri: Uri;
};
listEntries(ctx: ResolverContext, uri: Uri): Promise<ResolverStrategy.ListEntriesResult>;
readFileContent(ctx: ResolverContext, uri: Uri): {
content: ArrayBuffer;
} | Thenable<{
content: ArrayBuffer;
}>;
private _readPackageEntriesWithCache;
private _readPackageEntries;
private _readPackageJsonWithCache;
private _readPackageJson;
private _withLock;
static forJsDelivr(readUrlFn: CdnStrategy.UrlContentFetcher): CdnStrategy;
static forUnpkg(readUrlFn: CdnStrategy.UrlContentFetcher): CdnStrategy;
}
export { version, CdnStrategy };
//# sourceMappingURL=index.d.ts.map