Skip to content

Commit 34e3f5f

Browse files
Merge pull request #15111 from RyanCavanaugh/typesMap2
Add tests, comments, and min.js exclusion
2 parents c38d2a1 + 2b3c2b3 commit 34e3f5f

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ namespace ts.projectSystem {
14551455
checkProjectActualFiles(projectService.inferredProjects[1], [file3.path]);
14561456
});
14571457

1458-
it("ignores files excluded by the safe type list", () => {
1458+
it("ignores files excluded by a custom safe type list", () => {
14591459
const file1 = {
14601460
path: "/a/b/f1.ts",
14611461
content: "export let x = 5"
@@ -1477,6 +1477,44 @@ namespace ts.projectSystem {
14771477
}
14781478
});
14791479

1480+
it("ignores files excluded by the default type list", () => {
1481+
const file1 = {
1482+
path: "/a/b/f1.ts",
1483+
content: "export let x = 5"
1484+
};
1485+
const minFile = {
1486+
path: "/c/moment.min.js",
1487+
content: "unspecified"
1488+
};
1489+
const kendoFile1 = {
1490+
path: "/q/lib/kendo/kendo.all.min.js",
1491+
content: "unspecified"
1492+
};
1493+
const kendoFile2 = {
1494+
path: "/q/lib/kendo/kendo.ui.min.js",
1495+
content: "unspecified"
1496+
};
1497+
const officeFile1 = {
1498+
path: "/scripts/Office/1/excel-15.debug.js",
1499+
content: "unspecified"
1500+
};
1501+
const officeFile2 = {
1502+
path: "/scripts/Office/1/powerpoint.js",
1503+
content: "unspecified"
1504+
};
1505+
const files = [file1, minFile, kendoFile1, kendoFile2, officeFile1, officeFile2];
1506+
const host = createServerHost(files);
1507+
const projectService = createProjectService(host);
1508+
try {
1509+
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles(files.map(f => f.path)) });
1510+
const proj = projectService.externalProjects[0];
1511+
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
1512+
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
1513+
} finally {
1514+
projectService.resetSafeList();
1515+
}
1516+
});
1517+
14801518
it("open file become a part of configured project if it is referenced from root file", () => {
14811519
const file1 = {
14821520
path: "/a/b/f1.ts",

src/server/editorServices.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ namespace ts.server {
6161
"smart": IndentStyle.Smart
6262
});
6363

64+
/**
65+
* How to understand this block:
66+
* * The 'match' property is a regexp that matches a filename.
67+
* * If 'match' is successful, then:
68+
* * All files from 'exclude' are removed from the project. See below.
69+
* * All 'types' are included in ATA
70+
* * What the heck is 'exclude' ?
71+
* * An array of an array of strings and numbers
72+
* * Each array is:
73+
* * An array of strings and numbers
74+
* * The strings are literals
75+
* * The numbers refer to capture group indices from the 'match' regexp
76+
* * Remember that '1' is the first group
77+
* * These are concatenated together to form a new regexp
78+
* * Filenames matching these regexps are excluded from the project
79+
* This default value is tested in tsserverProjectSystem.ts; add tests there
80+
* if you are changing this so that you can be sure your regexp works!
81+
*/
6482
const defaultTypeSafeList: SafeList = {
6583
"jquery": {
6684
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
@@ -84,6 +102,11 @@ namespace ts.server {
84102
"match": /^(.*\/office\/1)\/excel-\d+\.debug\.js$/i, // Office NuGet package is installed under a "1/office" folder
85103
"exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it
86104
"types": ["office"] // @types package to fetch instead
105+
},
106+
"Minified files": {
107+
// e.g. /whatever/blah.min.js
108+
"match": /^(.+\.min\.js)$/i,
109+
"exclude": [["^", 1, "$"]]
87110
}
88111
};
89112

@@ -1507,7 +1530,7 @@ namespace ts.server {
15071530

15081531
// Copy back this field into the project if needed
15091532
if (types.length > 0) {
1510-
proj.typeAcquisition = proj.typeAcquisition || { };
1533+
proj.typeAcquisition = proj.typeAcquisition || {};
15111534
proj.typeAcquisition.include = types;
15121535
}
15131536
}

0 commit comments

Comments
 (0)