Skip to content

Commit

Permalink
export TypingsInstaller from tsserverlibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 20, 2023
1 parent 79a414b commit ad45060
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/jsTyping/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
versionMajorMinor,
} from "./_namespaces/ts";

/** @internal */
export interface TypingResolutionHost {
directoryExists(path: string): boolean;
fileExists(fileName: string): boolean;
Expand Down
1 change: 0 additions & 1 deletion src/jsTyping/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export interface EndInstallTypes extends InstallTypes {
readonly installSuccess: boolean;
}

/** @internal */
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
useCaseSensitiveFileNames: boolean;
writeFile(path: string, content: string): void;
Expand Down
1 change: 1 addition & 0 deletions src/server/_namespaces/ts.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Generated file to emulate the ts.server namespace. */

export * from "../../jsTyping/_namespaces/ts.server";
export * from "../../typingsInstallerCore/_namespaces/ts.server";
export * from "../types";
export * from "../utilitiesPublic";
export * from "../utilities";
Expand Down
1 change: 1 addition & 0 deletions src/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"references": [
{ "path": "../compiler" },
{ "path": "../jsTyping" },
{ "path": "../typingsInstallerCore" },
{ "path": "../services" },
{ "path": "../deprecatedCompat" }
],
Expand Down
3 changes: 2 additions & 1 deletion src/typingsInstallerCore/typingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export function getNpmCommandForInstallation(npmPath: string, tsVersion: string,
}

export type RequestCompletedAction = (success: boolean) => void;
interface PendingRequest {

export interface PendingRequest {
requestId: number;
packageNames: string[];
cwd: string;
Expand Down
65 changes: 65 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ declare namespace ts {
readonly kind: EventEndInstallTypes;
readonly installSuccess: boolean;
}
interface InstallTypingHost extends JsTyping.TypingResolutionHost {
useCaseSensitiveFileNames: boolean;
writeFile(path: string, content: string): void;
createDirectory(path: string): void;
getCurrentDirectory?(): string;
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
}
interface SetTypings extends ProjectResponse {
readonly typeAcquisition: TypeAcquisition;
readonly compilerOptions: CompilerOptions;
Expand Down Expand Up @@ -2965,6 +2973,55 @@ declare namespace ts {
bigintLiteral = 25
}
}
namespace typingsInstaller {
interface Log {
isEnabled(): boolean;
writeLine(text: string): void;
}
type RequestCompletedAction = (success: boolean) => void;
interface PendingRequest {
requestId: number;
packageNames: string[];
cwd: string;
onRequestCompleted: RequestCompletedAction;
}
abstract class TypingsInstaller {
protected readonly installTypingHost: InstallTypingHost;
private readonly globalCachePath;
private readonly safeListPath;
private readonly typesMapLocation;
private readonly throttleLimit;
protected readonly log: Log;
private readonly packageNameToTypingLocation;
private readonly missingTypingsSet;
private readonly knownCachesSet;
private readonly projectWatchers;
private safeList;
readonly pendingRunRequests: PendingRequest[];
private readonly toCanonicalFileName;
private readonly globalCachePackageJsonPath;
private installRunCount;
private inFlightRequestCount;
abstract readonly typesRegistry: Map<string, MapLike<string>>;
constructor(installTypingHost: InstallTypingHost, globalCachePath: string, safeListPath: Path, typesMapLocation: Path, throttleLimit: number, log?: Log);
closeProject(req: CloseProject): void;
private closeWatchers;
install(req: DiscoverTypings): void;
private initializeSafeList;
private processCacheLocation;
private filterTypings;
protected ensurePackageDirectoryExists(directory: string): void;
private installTypings;
private ensureDirectoryExists;
private watchFiles;
private createSetTypings;
private installTypingsAsync;
private executeWithThrottling;
protected abstract installWorker(requestId: number, packageNames: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes): void;
protected readonly latestDistTag = "latest";
}
}
interface CompressedData {
length: number;
compressionKind: string;
Expand Down Expand Up @@ -9789,6 +9846,14 @@ declare namespace ts {
emit(writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): EmitResult | BuildInvalidedProject<T> | undefined;
}
type InvalidatedProject<T extends BuilderProgram> = UpdateOutputFileStampsProject | BuildInvalidedProject<T> | UpdateBundleProject<T>;
namespace JsTyping {
interface TypingResolutionHost {
directoryExists(path: string): boolean;
fileExists(fileName: string): boolean;
readFile(path: string, encoding?: string): string | undefined;
readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[] | undefined, depth?: number): string[];
}
}
function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings;
/**
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5846,6 +5846,14 @@ declare namespace ts {
emit(writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): EmitResult | BuildInvalidedProject<T> | undefined;
}
type InvalidatedProject<T extends BuilderProgram> = UpdateOutputFileStampsProject | BuildInvalidedProject<T> | UpdateBundleProject<T>;
namespace JsTyping {
interface TypingResolutionHost {
directoryExists(path: string): boolean;
fileExists(fileName: string): boolean;
readFile(path: string, encoding?: string): string | undefined;
readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[] | undefined, depth?: number): string[];
}
}
namespace server {
type ActionSet = "action::set";
type ActionInvalidate = "action::invalidate";
Expand Down Expand Up @@ -5911,6 +5919,14 @@ declare namespace ts {
readonly kind: EventEndInstallTypes;
readonly installSuccess: boolean;
}
interface InstallTypingHost extends JsTyping.TypingResolutionHost {
useCaseSensitiveFileNames: boolean;
writeFile(path: string, content: string): void;
createDirectory(path: string): void;
getCurrentDirectory?(): string;
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
}
interface SetTypings extends ProjectResponse {
readonly typeAcquisition: TypeAcquisition;
readonly compilerOptions: CompilerOptions;
Expand Down

0 comments on commit ad45060

Please sign in to comment.