mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Proposal: importModuleSpecifierPreference: project-relative (#40637)
* Add new importModuleSpecifierPreference value * Add second test * Update API baselines * Clean up and add some comments * Rename option value
This commit is contained in:
@@ -3878,7 +3878,7 @@ namespace ts.server {
|
||||
const info = packageJsonCache.getInDirectory(directory);
|
||||
if (info) result.push(info);
|
||||
}
|
||||
if (rootPath && rootPath === this.toPath(directory)) {
|
||||
if (rootPath && rootPath === directory) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -3887,6 +3887,20 @@ namespace ts.server {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
getNearestAncestorDirectoryWithPackageJson(fileName: string): string | undefined {
|
||||
return forEachAncestorDirectory(fileName, directory => {
|
||||
switch (this.packageJsonCache.directoryHasPackageJson(this.toPath(directory))) {
|
||||
case Ternary.True: return directory;
|
||||
case Ternary.False: return undefined;
|
||||
case Ternary.Maybe:
|
||||
return this.host.fileExists(combinePaths(directory, "package.json"))
|
||||
? directory
|
||||
: undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
private watchPackageJsonFile(path: Path) {
|
||||
const watchers = this.packageJsonFilesMap || (this.packageJsonFilesMap = new Map());
|
||||
|
||||
@@ -1651,6 +1651,11 @@ namespace ts.server {
|
||||
return this.projectService.getPackageJsonsVisibleToFile(fileName, rootDir);
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
getNearestAncestorDirectoryWithPackageJson(fileName: string): string | undefined {
|
||||
return this.projectService.getNearestAncestorDirectoryWithPackageJson(fileName);
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
getPackageJsonsForAutoImport(rootDir?: string): readonly PackageJsonInfo[] {
|
||||
const packageJsons = this.getPackageJsonsVisibleToFile(combinePaths(this.currentDirectory, inferredTypesContainingFile), rootDir);
|
||||
@@ -1994,6 +1999,10 @@ namespace ts.server {
|
||||
return super.updateGraph();
|
||||
}
|
||||
|
||||
hasRoots() {
|
||||
return !!this.rootFileNames?.length;
|
||||
}
|
||||
|
||||
markAsDirty() {
|
||||
this.rootFileNames = undefined;
|
||||
super.markAsDirty();
|
||||
|
||||
@@ -3231,7 +3231,7 @@ namespace ts.server.protocol {
|
||||
* values, with insertion text to replace preceding `.` tokens with `?.`.
|
||||
*/
|
||||
readonly includeAutomaticOptionalChainCompletions?: boolean;
|
||||
readonly importModuleSpecifierPreference?: "auto" | "relative" | "non-relative";
|
||||
readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative";
|
||||
/** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */
|
||||
readonly importModuleSpecifierEnding?: "auto" | "minimal" | "index" | "js";
|
||||
readonly allowTextChangesInNewFiles?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user