diff --git a/src/jsTyping/jsTyping.ts b/src/jsTyping/jsTyping.ts index 1278b8bff5b36..e647298f6762e 100644 --- a/src/jsTyping/jsTyping.ts +++ b/src/jsTyping/jsTyping.ts @@ -31,7 +31,6 @@ import { versionMajorMinor, } from "./_namespaces/ts"; -/** @internal */ export interface TypingResolutionHost { directoryExists(path: string): boolean; fileExists(fileName: string): boolean; diff --git a/src/jsTyping/types.ts b/src/jsTyping/types.ts index f9db607a09f37..bf10bfa45105d 100644 --- a/src/jsTyping/types.ts +++ b/src/jsTyping/types.ts @@ -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; diff --git a/src/server/_namespaces/ts.server.ts b/src/server/_namespaces/ts.server.ts index 91d9a909ae7f8..62b2d8a3b563d 100644 --- a/src/server/_namespaces/ts.server.ts +++ b/src/server/_namespaces/ts.server.ts @@ -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"; diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index e7efc71154e55..22a1de22f93b9 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -8,6 +8,7 @@ "references": [ { "path": "../compiler" }, { "path": "../jsTyping" }, + { "path": "../typingsInstallerCore" }, { "path": "../services" }, { "path": "../deprecatedCompat" } ], diff --git a/src/typingsInstallerCore/typingsInstaller.ts b/src/typingsInstallerCore/typingsInstaller.ts index b57d585e2f9a9..bf2c4c90a9b35 100644 --- a/src/typingsInstallerCore/typingsInstaller.ts +++ b/src/typingsInstallerCore/typingsInstaller.ts @@ -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; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 8507f14d8afd5..4f9785d123f55 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -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; @@ -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>; + 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; @@ -9789,6 +9846,14 @@ declare namespace ts { emit(writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): EmitResult | BuildInvalidedProject | undefined; } type InvalidatedProject = UpdateOutputFileStampsProject | BuildInvalidedProject | UpdateBundleProject; + 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 diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a7ad7f9448614..2f46e1ddf2456 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5846,6 +5846,14 @@ declare namespace ts { emit(writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): EmitResult | BuildInvalidedProject | undefined; } type InvalidatedProject = UpdateOutputFileStampsProject | BuildInvalidedProject | UpdateBundleProject; + 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"; @@ -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;