Skip to content

Commit 9d5b07e

Browse files
committed
Squash port of PR microsoft#19542
1 parent 6d19326 commit 9d5b07e

File tree

6 files changed

+7763
-16
lines changed

6 files changed

+7763
-16
lines changed

src/compiler/core.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ namespace ts {
6666
}
6767

6868
// The global Map object. This may not be available, so we must test for it.
69-
declare const Map: { new<T>(): Map<T> } | undefined;
69+
declare const Map: { new <T>(): Map<T> } | undefined;
7070
// Internet Explorer's Map doesn't support iteration, so don't use it.
7171
// tslint:disable-next-line:no-in-operator
7272
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();
7373

7474
// Keep the class inside a function so it doesn't get compiled if it's not used.
75-
function shimMap(): { new<T>(): Map<T> } {
75+
function shimMap(): { new <T>(): Map<T> } {
7676

7777
class MapIterator<T, U extends (string | T | [string, T])> {
7878
private data: MapLike<T>;
@@ -95,7 +95,7 @@ namespace ts {
9595
}
9696
}
9797

98-
return class<T> implements Map<T> {
98+
return class <T> implements Map<T> {
9999
private data = createDictionaryObject<T>();
100100
public size = 0;
101101

@@ -158,8 +158,8 @@ namespace ts {
158158
}
159159

160160
export const enum Comparison {
161-
LessThan = -1,
162-
EqualTo = 0,
161+
LessThan = -1,
162+
EqualTo = 0,
163163
GreaterThan = 1
164164
}
165165

@@ -2512,8 +2512,7 @@ namespace ts {
25122512
return findBestPatternMatch(patterns, _ => _, candidate);
25132513
}
25142514

2515-
/* @internal */
2516-
export function patternText({prefix, suffix}: Pattern): string {
2515+
export function patternText({ prefix, suffix }: Pattern): string {
25172516
return `${prefix}*${suffix}`;
25182517
}
25192518

@@ -2545,7 +2544,7 @@ namespace ts {
25452544
return matchedValue;
25462545
}
25472546

2548-
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
2547+
function isPatternMatch({ prefix, suffix }: Pattern, candidate: string) {
25492548
return candidate.length >= prefix.length + suffix.length &&
25502549
startsWith(candidate, prefix) &&
25512550
endsWith(candidate, suffix);

src/harness/unittests/tsserverProjectSystem.ts

+36
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,42 @@ namespace ts.projectSystem {
15421542
}
15431543
});
15441544

1545+
it("removes version numbers correctly", () => {
1546+
const testData: [string, string][] = [
1547+
["jquery-max", "jquery-max"],
1548+
["jquery.min", "jquery"],
1549+
["jquery-min.4.2.3", "jquery"],
1550+
["jquery.min.4.2.1", "jquery"],
1551+
["minimum", "minimum"],
1552+
["min", "min"],
1553+
["min.3.2", "min"],
1554+
["jquery", "jquery"]
1555+
];
1556+
for (const t of testData) {
1557+
assert.equal(removeMinAndVersionNumbers(t[0]), t[1], t[0]);
1558+
}
1559+
});
1560+
1561+
it("ignores files excluded by a legacy safe type list", () => {
1562+
const file1 = {
1563+
path: "/a/b/bliss.js",
1564+
content: "let x = 5"
1565+
};
1566+
const file2 = {
1567+
path: "/a/b/foo.js",
1568+
content: ""
1569+
};
1570+
const host = createServerHost([file1, file2, customTypesMap]);
1571+
const projectService = createProjectService(host);
1572+
try {
1573+
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, file2.path]), typeAcquisition: { enable: true } });
1574+
const proj = projectService.externalProjects[0];
1575+
assert.deepEqual(proj.getFileNames(), [file2.path]);
1576+
} finally {
1577+
projectService.resetSafeList();
1578+
}
1579+
});
1580+
15451581
it("open file become a part of configured project if it is referenced from root file", () => {
15461582
const file1 = {
15471583
path: "/a/b/f1.ts",

src/harness/unittests/typingsInstaller.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,15 @@ namespace ts.projectSystem {
473473
installer.installAll(/*expectedCount*/ 1);
474474

475475
checkNumberOfProjects(projectService, { externalProjects: 1 });
476-
checkProjectActualFiles(p, [file1.path, file2.path, file3.path, commander.path, express.path, jquery.path, moment.path]);
476+
host.checkTimeoutQueueLength(2);
477+
host.runQueuedTimeoutCallbacks();
478+
checkNumberOfProjects(projectService, { externalProjects: 1 });
479+
// Commander: Existed as a JS file
480+
// JQuery: Specified in 'include'
481+
// Moment: Specified in 'include'
482+
// Express: Specified in package.json
483+
// lodash: Excluded (not present)
484+
checkProjectActualFiles(p, [file3.path, commander.path, express.path, jquery.path, moment.path]);
477485
});
478486

479487
it("Throttle - delayed typings to install", () => {
@@ -552,7 +560,7 @@ namespace ts.projectSystem {
552560
}
553561

554562
checkNumberOfProjects(projectService, { externalProjects: 1 });
555-
checkProjectActualFiles(p, [lodashJs.path, commanderJs.path, file3.path, commander.path, express.path, jquery.path, moment.path, lodash.path]);
563+
checkProjectActualFiles(p, [file3.path, commander.path, express.path, jquery.path, moment.path, lodash.path]);
556564
});
557565

558566
it("Throttle - delayed run install requests", () => {
@@ -1050,11 +1058,12 @@ namespace ts.projectSystem {
10501058
const host = createServerHost([app, jquery, chroma]);
10511059
const logger = trackingLogger();
10521060
const result = JsTyping.discoverTypings(host, logger.log, [app.path, jquery.path, chroma.path], getDirectoryPath(<Path>app.path), safeList, emptyMap, { enable: true }, emptyArray);
1053-
assert.deepEqual(logger.finish(), [
1061+
const finish = logger.finish();
1062+
assert.deepEqual(finish, [
10541063
'Inferred typings from file names: ["jquery","chroma-js"]',
10551064
"Inferred typings from unresolved imports: []",
10561065
'Result: {"cachedTypingPaths":[],"newTypingNames":["jquery","chroma-js"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
1057-
]);
1066+
], finish.join("\r\n"));
10581067
assert.deepEqual(result.newTypingNames, ["jquery", "chroma-js"]);
10591068
});
10601069

src/server/editorServices.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,15 @@ namespace ts.server {
426426
Debug.assert(!!this.host.createHash, "'ServerHost.createHash' is required for ProjectService");
427427

428428
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
429-
this.directoryWatchers = new DirectoryWatchers(this);
430429
this.throttledOperations = new ThrottledOperations(this.host);
431430

431+
if (this.typesMapLocation) {
432+
this.loadTypesMap();
433+
}
434+
else {
435+
this.logger.info("No types map provided; using the default");
436+
}
437+
432438
this.typingsInstaller.attach(this);
433439

434440
this.typingsCache = new TypingsCache(this.typingsInstaller);
@@ -1085,7 +1091,7 @@ namespace ts.server {
10851091
return false;
10861092
}
10871093

1088-
private createAndAddExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition) {
1094+
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition, excludedFiles: NormalizedPath[]) {
10891095
const compilerOptions = convertCompilerOptions(options);
10901096
const project = new ExternalProject(
10911097
projectFileName,
@@ -1094,6 +1100,7 @@ namespace ts.server {
10941100
compilerOptions,
10951101
/*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(projectFileName, compilerOptions, files, externalFilePropertyReader),
10961102
options.compileOnSave === undefined ? true : options.compileOnSave);
1103+
project.excludedFiles = excludedFiles;
10971104

10981105
this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined, typeAcquisition, /*configFileErrors*/ undefined);
10991106
this.externalProjects.push(project);
@@ -1749,7 +1756,7 @@ namespace ts.server {
17491756
const rule = this.safelist[name];
17501757
for (const root of normalizedNames) {
17511758
if (rule.match.test(root)) {
1752-
this.logger.info(`Excluding files based on rule ${name}`);
1759+
this.logger.info(`Excluding files based on rule ${name} matching file '${root}'`);
17531760

17541761
// If the file matches, collect its types packages and exclude rules
17551762
if (rule.types) {
@@ -1906,7 +1913,11 @@ namespace ts.server {
19061913
else {
19071914
// no config files - remove the item from the collection
19081915
this.externalProjectToConfiguredProjectMap.delete(proj.projectFileName);
1916+
<<<<<<< HEAD
19091917
this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition);
1918+
=======
1919+
this.createExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition, excludedFiles);
1920+
>>>>>>> b9a548cd13... Squash port of PR #19542
19101921
}
19111922
if (!suppressRefreshOfInferredProjects) {
19121923
this.refreshInferredProjects();

src/services/jsTyping.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace ts.JsTyping {
172172
if (!hasJavaScriptFileExtension(j)) return undefined;
173173

174174
const inferredTypingName = removeFileExtension(getBaseFileName(j.toLowerCase()));
175-
const cleanedTypingName = inferredTypingName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
175+
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
176176
return safeList.get(cleanedTypingName);
177177
});
178178
if (fromFileNames.length) {

0 commit comments

Comments
 (0)