Add tests, comments, and min.js exclusion

This commit is contained in:
Ryan Cavanaugh 2017-04-10 16:00:15 -07:00
parent 2ca90b7eb6
commit 2b3c2b3448
2 changed files with 63 additions and 2 deletions

View File

@ -1455,7 +1455,7 @@ namespace ts.projectSystem {
checkProjectActualFiles(projectService.inferredProjects[1], [file3.path]);
});
it("ignores files excluded by the safe type list", () => {
it("ignores files excluded by a custom safe type list", () => {
const file1 = {
path: "/a/b/f1.ts",
content: "export let x = 5"
@ -1477,6 +1477,44 @@ namespace ts.projectSystem {
}
});
it("ignores files excluded by the default type list", () => {
const file1 = {
path: "/a/b/f1.ts",
content: "export let x = 5"
};
const minFile = {
path: "/c/moment.min.js",
content: "unspecified"
};
const kendoFile1 = {
path: "/q/lib/kendo/kendo.all.min.js",
content: "unspecified"
};
const kendoFile2 = {
path: "/q/lib/kendo/kendo.ui.min.js",
content: "unspecified"
};
const officeFile1 = {
path: "/scripts/Office/1/excel-15.debug.js",
content: "unspecified"
};
const officeFile2 = {
path: "/scripts/Office/1/powerpoint.js",
content: "unspecified"
};
const files = [file1, minFile, kendoFile1, kendoFile2, officeFile1, officeFile2];
const host = createServerHost(files);
const projectService = createProjectService(host);
try {
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles(files.map(f => f.path)) });
const proj = projectService.externalProjects[0];
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
} finally {
projectService.resetSafeList();
}
});
it("open file become a part of configured project if it is referenced from root file", () => {
const file1 = {
path: "/a/b/f1.ts",

View File

@ -61,6 +61,24 @@ namespace ts.server {
"smart": IndentStyle.Smart
});
/**
* How to understand this block:
* * The 'match' property is a regexp that matches a filename.
* * If 'match' is successful, then:
* * All files from 'exclude' are removed from the project. See below.
* * All 'types' are included in ATA
* * What the heck is 'exclude' ?
* * An array of an array of strings and numbers
* * Each array is:
* * An array of strings and numbers
* * The strings are literals
* * The numbers refer to capture group indices from the 'match' regexp
* * Remember that '1' is the first group
* * These are concatenated together to form a new regexp
* * Filenames matching these regexps are excluded from the project
* This default value is tested in tsserverProjectSystem.ts; add tests there
* if you are changing this so that you can be sure your regexp works!
*/
const defaultTypeSafeList: SafeList = {
"jquery": {
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
@ -84,6 +102,11 @@ namespace ts.server {
"match": /^(.*\/office\/1)\/excel-\d+\.debug\.js$/i, // Office NuGet package is installed under a "1/office" folder
"exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it
"types": ["office"] // @types package to fetch instead
},
"Minified files": {
// e.g. /whatever/blah.min.js
"match": /^(.+\.min\.js)$/i,
"exclude": [["^", 1, "$"]]
}
};
@ -1507,7 +1530,7 @@ namespace ts.server {
// Copy back this field into the project if needed
if (types.length > 0) {
proj.typeAcquisition = proj.typeAcquisition || { };
proj.typeAcquisition = proj.typeAcquisition || {};
proj.typeAcquisition.include = types;
}
}