mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Types Map WIP
This commit is contained in:
1 parent
70e5c6b1e5
commit
5272ec6309
12 files changed
+642
-40
No files matched your search
@@ -17,10 +17,10 @@ namespace ts.server.typingsInstaller {
|
||||
constructor(private readonly logFile?: string) {
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
isEnabled = () => {
|
||||
return this.logEnabled && this.logFile !== undefined;
|
||||
}
|
||||
writeLine(text: string) {
|
||||
writeLine = (text: string) => {
|
||||
try {
|
||||
fs.appendFileSync(this.logFile, text + sys.newLine);
|
||||
}
|
||||
@@ -77,11 +77,12 @@ namespace ts.server.typingsInstaller {
|
||||
|
||||
private delayedInitializationError: InitializationFailedResponse;
|
||||
|
||||
constructor(globalTypingsCacheLocation: string, typingSafeListLocation: string, npmLocation: string | undefined, throttleLimit: number, log: Log) {
|
||||
constructor(globalTypingsCacheLocation: string, typingSafeListLocation: string, typesMapLocation: string, npmLocation: string | undefined, throttleLimit: number, log: Log) {
|
||||
super(
|
||||
sys,
|
||||
globalTypingsCacheLocation,
|
||||
typingSafeListLocation ? toPath(typingSafeListLocation, "", createGetCanonicalFileName(sys.useCaseSensitiveFileNames)) : toPath("typingSafeList.json", __dirname, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
|
||||
typesMapLocation ? toPath(typesMapLocation, "", createGetCanonicalFileName(sys.useCaseSensitiveFileNames)) : toPath("typesMap.json", __dirname, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
|
||||
throttleLimit,
|
||||
log);
|
||||
this.npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation(process.argv[0]);
|
||||
@@ -175,6 +176,7 @@ namespace ts.server.typingsInstaller {
|
||||
const logFilePath = findArgument(server.Arguments.LogFile);
|
||||
const globalTypingsCacheLocation = findArgument(server.Arguments.GlobalCacheLocation);
|
||||
const typingSafeListLocation = findArgument(server.Arguments.TypingSafeListLocation);
|
||||
const typesMapLocation = findArgument(server.Arguments.TypesMapLocation);
|
||||
const npmLocation = findArgument(server.Arguments.NpmLocation);
|
||||
|
||||
const log = new FileLog(logFilePath);
|
||||
@@ -189,6 +191,6 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
process.exit(0);
|
||||
});
|
||||
const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, typingSafeListLocation, npmLocation, /*throttleLimit*/5, log);
|
||||
const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, typingSafeListLocation, typesMapLocation, npmLocation, /*throttleLimit*/5, log);
|
||||
installer.listen();
|
||||
}
|
||||
@@ -97,10 +97,11 @@ namespace ts.server.typingsInstaller {
|
||||
protected readonly installTypingHost: InstallTypingHost,
|
||||
private readonly globalCachePath: string,
|
||||
private readonly safeListPath: Path,
|
||||
private readonly typesMapLocation: Path,
|
||||
private readonly throttleLimit: number,
|
||||
protected readonly log = nullLog) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}'`);
|
||||
this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}', types map path ${typesMapLocation}`);
|
||||
}
|
||||
this.processCacheLocation(this.globalCachePath);
|
||||
}
|
||||
@@ -145,7 +146,7 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
|
||||
if (this.safeList === undefined) {
|
||||
this.safeList = JsTyping.loadSafeList(this.installTypingHost, this.safeListPath);
|
||||
this.initializeSafeList();
|
||||
}
|
||||
const discoverTypingsResult = JsTyping.discoverTypings(
|
||||
this.installTypingHost,
|
||||
@@ -178,6 +179,20 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
private initializeSafeList() {
|
||||
// Prefer the safe list from the types map if it exists
|
||||
if (this.typesMapLocation) {
|
||||
const safeListFromMap = JsTyping.loadTypesMap(this.installTypingHost, this.typesMapLocation);
|
||||
if (safeListFromMap) {
|
||||
this.log.writeLine(`Loaded safelist from types map file '${this.typesMapLocation}'`);
|
||||
this.safeList = safeListFromMap;
|
||||
return;
|
||||
}
|
||||
this.log.writeLine(`Failed to load safelist from types map file '${this.typesMapLocation}'`);
|
||||
}
|
||||
this.safeList = JsTyping.loadSafeList(this.installTypingHost, this.safeListPath);
|
||||
}
|
||||
|
||||
private processCacheLocation(cacheLocation: string) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Processing cache location '${cacheLocation}'`);
|
||||
|
||||
Reference in new issue
Block a user