Skip to content

Commit

Permalink
Pickup PackageJsonInfo renames from #50088
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Aug 1, 2022
1 parent 7e272d6 commit a9aa65f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ namespace ts {
}

/*@internal*/
interface PackageJsonInfo {
export interface PackageJsonInfo {
packageDirectory: string;
packageJsonContent: PackageJsonPathFields;
versionPaths: VersionPaths | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ namespace ts {
*/
setExternalModuleIndicator?: (file: SourceFile) => void;
/*@internal*/ packageJsonLocations?: readonly string[];
/*@internal*/ packageJsonScope?: ReturnType<typeof getPackageScopeForPath>;
/*@internal*/ packageJsonScope?: PackageJsonInfo;
}

function setExternalModuleIndicator(sourceFile: SourceFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,7 @@ namespace ts {
*/
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
/*@internal*/ packageJsonLocations?: readonly string[];
/*@internal*/ packageJsonScope?: ReturnType<typeof getPackageScopeForPath>;
/*@internal*/ packageJsonScope?: PackageJsonInfo;

/* @internal */ scriptKind: ScriptKind;

Expand Down
4 changes: 2 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4185,11 +4185,11 @@ namespace ts.server {
}

/*@internal*/
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly PackageJsonInfo[] {
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly ProjectPackageJsonInfo[] {
const packageJsonCache = this.packageJsonCache;
const rootPath = rootDir && this.toPath(rootDir);
const filePath = this.toPath(fileName);
const result: PackageJsonInfo[] = [];
const result: ProjectPackageJsonInfo[] = [];
const processDirectory = (directory: Path): boolean | undefined => {
switch (packageJsonCache.directoryHasPackageJson(directory)) {
// Sync and check same directory again
Expand Down
8 changes: 4 additions & 4 deletions src/server/packageJsonCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
namespace ts.server {
export interface PackageJsonCache {
addOrUpdate(fileName: Path): void;
forEach(action: (info: PackageJsonInfo, fileName: Path) => void): void;
forEach(action: (info: ProjectPackageJsonInfo, fileName: Path) => void): void;
delete(fileName: Path): void;
get(fileName: Path): PackageJsonInfo | false | undefined;
getInDirectory(directory: Path): PackageJsonInfo | undefined;
get(fileName: Path): ProjectPackageJsonInfo | false | undefined;
getInDirectory(directory: Path): ProjectPackageJsonInfo | undefined;
directoryHasPackageJson(directory: Path): Ternary;
searchDirectoryAndAncestors(directory: Path): void;
}

export function createPackageJsonCache(host: ProjectService): PackageJsonCache {
const packageJsons = new Map<string, PackageJsonInfo>();
const packageJsons = new Map<string, ProjectPackageJsonInfo>();
const directoriesWithoutPackageJson = new Map<string, true>();
return {
addOrUpdate,
Expand Down
5 changes: 2 additions & 3 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ namespace ts.server {
}

/*@internal*/
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly PackageJsonInfo[] {
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly ProjectPackageJsonInfo[] {
if (this.projectService.serverMode !== LanguageServiceMode.Semantic) return emptyArray;
return this.projectService.getPackageJsonsVisibleToFile(fileName, rootDir);
}
Expand All @@ -1762,7 +1762,7 @@ namespace ts.server {
}

/*@internal*/
getPackageJsonsForAutoImport(rootDir?: string): readonly PackageJsonInfo[] {
getPackageJsonsForAutoImport(rootDir?: string): readonly ProjectPackageJsonInfo[] {
const packageJsons = this.getPackageJsonsVisibleToFile(combinePaths(this.currentDirectory, inferredTypesContainingFile), rootDir);
this.packageJsonsForAutoImport = new Set(packageJsons.map(p => p.fileName));
return packageJsons;
Expand Down Expand Up @@ -2177,7 +2177,6 @@ namespace ts.server {
}
}

type PackageJsonInfo = NonNullable<ReturnType<typeof resolvePackageNameToPackageJson>>;
function getRootNamesFromPackageJson(packageJson: PackageJsonInfo, program: Program, symlinkCache: SymlinkCache, resolveJs?: boolean) {
const entrypoints = getEntrypointsFromPackageJsonInfo(
packageJson,
Expand Down
6 changes: 3 additions & 3 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ namespace ts {
}

/* @internal */
export interface PackageJsonInfo {
export interface ProjectPackageJsonInfo {
fileName: string;
parseable: boolean;
dependencies?: ESMap<string, string>;
Expand Down Expand Up @@ -311,9 +311,9 @@ namespace ts {

/* @internal */ getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
/* @internal */ getSourceFileLike?(fileName: string): SourceFileLike | undefined;
/* @internal */ getPackageJsonsVisibleToFile?(fileName: string, rootDir?: string): readonly PackageJsonInfo[];
/* @internal */ getPackageJsonsVisibleToFile?(fileName: string, rootDir?: string): readonly ProjectPackageJsonInfo[];
/* @internal */ getNearestAncestorDirectoryWithPackageJson?(fileName: string): string | undefined;
/* @internal */ getPackageJsonsForAutoImport?(rootDir?: string): readonly PackageJsonInfo[];
/* @internal */ getPackageJsonsForAutoImport?(rootDir?: string): readonly ProjectPackageJsonInfo[];
/* @internal */ getCachedExportInfoMap?(): ExportInfoMap;
/* @internal */ getModuleSpecifierCache?(): ModuleSpecifierCache;
/* @internal */ setCompilerHost?(host: CompilerHost): void;
Expand Down
8 changes: 4 additions & 4 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3004,12 +3004,12 @@ namespace ts {
return packageJson;
}

export function getPackageJsonsVisibleToFile(fileName: string, host: LanguageServiceHost): readonly PackageJsonInfo[] {
export function getPackageJsonsVisibleToFile(fileName: string, host: LanguageServiceHost): readonly ProjectPackageJsonInfo[] {
if (!host.fileExists) {
return [];
}

const packageJsons: PackageJsonInfo[] = [];
const packageJsons: ProjectPackageJsonInfo[] = [];
forEachAncestorDirectory(getDirectoryPath(fileName), ancestor => {
const packageJsonFileName = combinePaths(ancestor, "package.json");
if (host.fileExists(packageJsonFileName)) {
Expand All @@ -3023,7 +3023,7 @@ namespace ts {
return packageJsons;
}

export function createPackageJsonInfo(fileName: string, host: { readFile?(fileName: string): string | undefined }): PackageJsonInfo | undefined {
export function createPackageJsonInfo(fileName: string, host: { readFile?(fileName: string): string | undefined }): ProjectPackageJsonInfo | undefined {
if (!host.readFile) {
return undefined;
}
Expand All @@ -3032,7 +3032,7 @@ namespace ts {
const dependencyKeys = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"] as const;
const stringContent = host.readFile(fileName) || "";
const content = tryParseJson(stringContent) as PackageJsonRaw | undefined;
const info: Pick<PackageJsonInfo, typeof dependencyKeys[number]> = {};
const info: Pick<ProjectPackageJsonInfo, typeof dependencyKeys[number]> = {};
if (content) {
for (const key of dependencyKeys) {
const dependencies = content[key];
Expand Down

0 comments on commit a9aa65f

Please sign in to comment.