Skip to content

discoverTypings should look at typingSafelist.json values #16277

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

Merged
merged 2 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace ts.projectSystem {
express: "express",
jquery: "jquery",
lodash: "lodash",
moment: "moment"
moment: "moment",
chroma: "chroma-js"
})
};

Expand Down Expand Up @@ -61,7 +62,6 @@ namespace ts.projectSystem {
super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log);
}

safeFileList = safeList.path;
protected postExecActions: PostExecAction[] = [];

executePendingCommands() {
Expand Down
27 changes: 24 additions & 3 deletions src/harness/unittests/typingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,34 @@ namespace ts.projectSystem {
});

describe("discover typings", () => {
it("should use mappings from safe list", () => {
const app = {
path: "/a/b/app.js",
content: ""
};
const jquery = {
path: "/a/b/jquery.js",
content: ""
};
const chroma = {
path: "/a/b/chroma.min.js",
content: ""
};
const cache = createMap<string>();

const host = createServerHost([app, jquery, chroma]);
const result = JsTyping.discoverTypings(host, [app.path, jquery.path, chroma.path], getDirectoryPath(<Path>app.path), /*safeListPath*/ undefined, cache, { enable: true }, []);
assert.deepEqual(result.newTypingNames, ["jquery", "chroma-js"]);
});

it("should return node for core modules", () => {
const f = {
path: "/a/b/app.js",
content: ""
};
const host = createServerHost([f]);
const cache = createMap<string>();

for (const name of JsTyping.nodeCoreModuleList) {
const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(<Path>f.path), /*safeListPath*/ undefined, cache, { enable: true }, [name, "somename"]);
assert.deepEqual(result.newTypingNames.sort(), ["node", "somename"]);
Expand All @@ -1040,7 +1061,7 @@ namespace ts.projectSystem {
});

describe("telemetry events", () => {
it ("should be received", () => {
it("should be received", () => {
const f1 = {
path: "/a/app.js",
content: ""
Expand Down Expand Up @@ -1089,7 +1110,7 @@ namespace ts.projectSystem {
});

describe("progress notifications", () => {
it ("should be sent for success", () => {
it("should be sent for success", () => {
const f1 = {
path: "/a/app.js",
content: ""
Expand Down Expand Up @@ -1140,7 +1161,7 @@ namespace ts.projectSystem {
checkProjectActualFiles(projectService.inferredProjects[0], [f1.path, commander.path]);
});

it ("should be sent for error", () => {
it("should be sent for error", () => {
const f1 = {
path: "/a/app.js",
content: ""
Expand Down
4 changes: 2 additions & 2 deletions src/services/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace ts.JsTyping {
/**
* Merge a given list of typingNames to the inferredTypings map
*/
function mergeTypings(typingNames: string[]) {
function mergeTypings(typingNames: ReadonlyArray<string>) {
if (!typingNames) {
return;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace ts.JsTyping {
const cleanedTypingNames = map(inferredTypingNames, f => f.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, ""));

if (safeList !== EmptySafeList) {
mergeTypings(filter(cleanedTypingNames, f => safeList.has(f)));
mergeTypings(ts.mapDefined(cleanedTypingNames, f => safeList.get(f)));
}

const hasJsxFile = forEach(fileNames, f => ensureScriptKind(f, getScriptKindFromFileName(f)) === ScriptKind.JSX);
Expand Down