mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
JsTyping: Remove "safeList" global variable (#17304)
This commit is contained in:
+12
-11
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user