Exclude legacy safelist files in external projects

This commit is contained in:
Ryan Cavanaugh
2017-10-27 16:24:12 -07:00
parent 325538262a
commit da63c2c579
4 changed files with 40 additions and 9 deletions
+7
View File
@@ -2413,6 +2413,13 @@ namespace ts {
return <T>(removeFileExtension(path) + newExtension);
}
/**
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
*/
export function removeMinAndVersionNumbers(fileName: string) {
return fileName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
}
export interface ObjectAllocator {
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
+27 -6
View File
@@ -110,7 +110,7 @@ namespace ts.server {
export interface TypesMapFile {
typesMap: SafeList;
simpleMap: string[];
simpleMap: { [libName: string]: string };
}
/**
@@ -374,6 +374,7 @@ namespace ts.server {
private readonly hostConfiguration: HostConfiguration;
private safelist: SafeList = defaultTypeSafeList;
private legacySafelist: { [key: string]: string } = {};
private changedFiles: ScriptInfo[];
private pendingProjectUpdates = createMap<Project>();
@@ -426,9 +427,12 @@ namespace ts.server {
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
if (opts.typesMapLocation) {
if (this.typesMapLocation) {
this.loadTypesMap();
}
else {
this.logger.info("No types map provided; using the default");
}
this.typingsInstaller.attach(this);
@@ -518,10 +522,12 @@ namespace ts.server {
}
// raw is now fixed and ready
this.safelist = raw.typesMap;
this.legacySafelist = raw.simpleMap;
}
catch (e) {
this.logger.info(`Error loading types map: ${e}`);
this.safelist = defaultTypeSafeList;
this.legacySafelist = {};
}
}
@@ -1393,7 +1399,7 @@ namespace ts.server {
return false;
}
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition) {
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition, excludedFiles: NormalizedPath[]) {
const compilerOptions = convertCompilerOptions(options);
const project = new ExternalProject(
projectFileName,
@@ -1402,6 +1408,7 @@ namespace ts.server {
compilerOptions,
/*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(projectFileName, compilerOptions, files, externalFilePropertyReader),
options.compileOnSave === undefined ? true : options.compileOnSave);
project.excludedFiles = excludedFiles;
this.addFilesToNonInferredProjectAndUpdateGraph(project, files, externalFilePropertyReader, typeAcquisition);
this.externalProjects.push(project);
@@ -2204,7 +2211,22 @@ namespace ts.server {
excludedFiles.push(normalizedNames[i]);
}
else {
filesToKeep.push(proj.rootFiles[i]);
let exclude = false;
if (typeAcquisition && (typeAcquisition.enable || typeAcquisition.enableAutoDiscovery)) {
const baseName = getBaseFileName(normalizedNames[i].toLowerCase());
if (fileExtensionIs(baseName, "js")) {
const inferredTypingName = removeFileExtension(baseName);
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
if (this.legacySafelist[cleanedTypingName]) {
this.logger.info(`Excluded '${normalizedNames[i]}'`);
excludedFiles.push(normalizedNames[i]);
exclude = true;
}
}
}
if (!exclude) {
filesToKeep.push(proj.rootFiles[i]);
}
}
}
proj.rootFiles = filesToKeep;
@@ -2312,8 +2334,7 @@ namespace ts.server {
else {
// no config files - remove the item from the collection
this.externalProjectToConfiguredProjectMap.delete(proj.projectFileName);
const newProj = this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition);
newProj.excludedFiles = excludedFiles;
this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition, excludedFiles);
}
if (!suppressRefreshOfInferredProjects) {
this.ensureProjectStructuresUptoDate(/*refreshInferredProjects*/ true);
+1 -1
View File
@@ -180,7 +180,7 @@ namespace ts.JsTyping {
if (!hasJavaScriptFileExtension(j)) return undefined;
const inferredTypingName = removeFileExtension(getBaseFileName(j.toLowerCase()));
const cleanedTypingName = inferredTypingName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
return safeList.get(cleanedTypingName);
});
if (fromFileNames.length) {
+5 -2
View File
@@ -7391,7 +7391,9 @@ declare namespace ts.server {
}
interface TypesMapFile {
typesMap: SafeList;
simpleMap: string[];
simpleMap: {
[libName: string]: string;
};
}
function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings;
function convertCompilerOptions(protocolOptions: protocol.ExternalProjectCompilerOptions): CompilerOptions & protocol.CompileOnSaveMixin;
@@ -7468,6 +7470,7 @@ declare namespace ts.server {
private readonly throttledOperations;
private readonly hostConfiguration;
private safelist;
private legacySafelist;
private changedFiles;
private pendingProjectUpdates;
private pendingInferredProjectUpdate;
@@ -7576,7 +7579,7 @@ declare namespace ts.server {
private findExternalProjectByProjectName(projectFileName);
private convertConfigFileContentToProjectOptions(configFilename, cachedDirectoryStructureHost);
private exceededTotalSizeLimitForNonTsFiles<T>(name, options, fileNames, propertyReader);
private createExternalProject(projectFileName, files, options, typeAcquisition);
private createExternalProject(projectFileName, files, options, typeAcquisition, excludedFiles);
private sendProjectTelemetry(projectKey, project, projectOptions?);
private addFilesToNonInferredProjectAndUpdateGraph<T>(project, files, propertyReader, typeAcquisition);
private createConfiguredProject(configFileName);