JsTyping: Remove "safeList" global variable (#17304)

This commit is contained in:
Andy
2017-07-27 10:54:47 -07:00
committed by GitHub
parent 977d907417
commit 3330f2a33b
5 changed files with 32 additions and 19 deletions
+12 -11
View File
@@ -25,10 +25,6 @@ namespace ts.JsTyping {
typings?: string;
}
// A map of loose file names to library names
// that we are confident require typings
let safeList: Map<string>;
/* @internal */
export const nodeCoreModuleList: ReadonlyArray<string> = [
"buffer", "querystring", "events", "http", "cluster",
@@ -40,6 +36,16 @@ namespace ts.JsTyping {
const nodeCoreModules = arrayToMap(<string[]>nodeCoreModuleList, x => x);
/**
* A map of loose file names to library names that we are confident require typings
*/
export type SafeList = ReadonlyMap<string>;
export function loadSafeList(host: TypingResolutionHost, safeListPath: Path): SafeList {
const result = readConfigFile(safeListPath, path => host.readFile(path));
return createMapFromTemplate<string>(result.config);
}
/**
* @param host is the object providing I/O related operations.
* @param fileNames are the file names that belong to the same project
@@ -54,8 +60,8 @@ namespace ts.JsTyping {
log: ((message: string) => void) | undefined,
fileNames: string[],
projectRootPath: Path,
safeListPath: Path,
packageNameToTypingLocation: Map<string>,
safeList: SafeList,
packageNameToTypingLocation: ReadonlyMap<string>,
typeAcquisition: TypeAcquisition,
unresolvedImports: ReadonlyArray<string>):
{ cachedTypingPaths: string[], newTypingNames: string[], filesToWatch: string[] } {
@@ -75,11 +81,6 @@ namespace ts.JsTyping {
}
});
if (!safeList) {
const result = readConfigFile(safeListPath, (path: string) => host.readFile(path));
safeList = createMapFromTemplate<string>(result.config);
}
const filesToWatch: string[] = [];
forEach(typeAcquisition.include, addInferredTyping);
+6 -2
View File
@@ -1005,6 +1005,7 @@ namespace ts {
class CoreServicesShimObject extends ShimBase implements CoreServicesShim {
private logPerformance = false;
private safeList: JsTyping.SafeList | undefined;
constructor(factory: ShimFactory, public readonly logger: Logger, private readonly host: CoreServicesShimHostAdapter) {
super(factory);
@@ -1114,12 +1115,15 @@ namespace ts {
const getCanonicalFileName = createGetCanonicalFileName(/*useCaseSensitivefileNames:*/ false);
return this.forwardJSONCall("discoverTypings()", () => {
const info = <DiscoverTypingsInfo>JSON.parse(discoverTypingsJson);
return ts.JsTyping.discoverTypings(
if (this.safeList === undefined) {
this.safeList = JsTyping.loadSafeList(this.host, toPath(info.safeListPath, info.safeListPath, getCanonicalFileName));
}
return JsTyping.discoverTypings(
this.host,
msg => this.logger.log(msg),
info.fileNames,
toPath(info.projectRootPath, info.projectRootPath, getCanonicalFileName),
toPath(info.safeListPath, info.safeListPath, getCanonicalFileName),
this.safeList,
info.packageNameToTypingLocation,
info.typeAcquisition,
info.unresolvedImports);