Allow resetting so tests pass

This commit is contained in:
Ryan Cavanaugh 2017-04-05 12:56:14 -07:00
parent c6338c3e20
commit b4e871ba10
2 changed files with 38 additions and 27 deletions

View File

@ -17,27 +17,13 @@ namespace ts.projectSystem {
})
};
const typeMapList = {
const customSafeList = {
path: <Path>"/typeMapList.json",
content: JSON.stringify({
"jquery": {
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
"match": "/jquery(-(\\.?\\d+)+)?(\\.intellisense)?(\\.min)?\\.js$",
"types": ["jquery"]
"quack": {
"match": "/duckquack-(\\d+)\\.min\\.js",
"types": ["duck-types"]
},
"WinJS": {
"match": "^(.*/winjs)/base\\.js$", // If the winjs/base.js file is found..
"exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder
"types": ["winjs"] // And fetch the @types package for WinJS
},
"Office Nuget": {
"match": "^(.*/1/office)/excel\\.debug\\.js$", // 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": {
"match": "^.*\\.min\\.js$" // Catch-all for minified files. Default exclude is the matched file.
}
})
};
@ -1432,17 +1418,20 @@ namespace ts.projectSystem {
content: "export let x = 5"
};
const office = {
path: "lib/1/office/excel.debug.js",
path: "/lib/duckquack-3.min.js",
content: "whoa do @@ not parse me ok thanks!!!"
};
const host = createServerHost([typeMapList, file1, office]);
const host = createServerHost([customSafeList, file1, office]);
const projectService = createProjectService(host);
projectService.loadSafeList(typeMapList.path);
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
const proj = projectService.externalProjects[0];
assert.deepEqual(proj.getFileNames(true), [file1.path]);
assert.deepEqual(proj.getTypeAcquisition().include, ["office"]);
projectService.loadSafeList(customSafeList.path);
try {
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
const proj = projectService.externalProjects[0];
assert.deepEqual(proj.getFileNames(true), [file1.path]);
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
} finally {
projectService.resetSafeList();
}
});
it("open file become a part of configured project if it is referenced from root file", () => {

View File

@ -61,6 +61,24 @@ namespace ts.server {
"smart": IndentStyle.Smart
});
const defaultTypeSafeList: SafeList = {
"jquery": {
// jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
"match": /jquery(-(\.?\d+)+)?(\.intellisense)?(\.min)?\.js$/gi,
"types": ["jquery"]
},
"WinJS": {
"match": /^(.*\/winjs)\/base\.js$/gi, // If the winjs/base.js file is found..
"exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder
"types": ["winjs"] // And fetch the @types package for WinJS
},
"Office Nuget": {
"match": /^(.*\/1\/office)\/excel\.debug\.js$/gi, // 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
}
};
export function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings {
if (typeof protocolOptions.indentStyle === "string") {
protocolOptions.indentStyle = indentStyle.get(protocolOptions.indentStyle.toLowerCase());
@ -263,7 +281,7 @@ namespace ts.server {
private readonly throttledOperations: ThrottledOperations;
private readonly hostConfiguration: HostConfiguration;
private static safelist: SafeList = {};
private static safelist: SafeList = defaultTypeSafeList;
private changedFiles: ScriptInfo[];
@ -1407,6 +1425,10 @@ namespace ts.server {
return filename.replace(this.filenameEscapeRegexp, "\\$&");
}
resetSafeList(): void {
ProjectService.safelist = defaultTypeSafeList;
}
loadSafeList(fileName: string): void {
const raw: SafeList = JSON.parse(this.host.readFile(fileName, "utf-8"));
// Parse the regexps