-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Exclude legacy safelist files in external projects #19542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
da63c2c
5830bb9
5395d0d
5dc02ef
ddd8c95
19cc427
0e105ad
b043edd
0d5dec9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also removes digits without the min, for example "jquery.4.2-test" also becomes "jquery-test". Probably not intended. (Also why use non-capturing groups (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly should the rule be? Remove all characters after the first . if the thing after the . is min or a number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielRosenwasser wrote us a nice regex |
||
} | ||
|
||
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>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]}'`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it would be helpful (and consistent) to indicate why the file is being excluded (i.e. legacy safelist). |
||
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this function in compiler? Can it be part of services\utilities instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functions needs to be used in the typings installer and in tsserver; I couldn't find another file that was shared by them. services\utilities isn't involved in the typings installer and adding it introduced more errors because it needs references to e.g. Project