{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/comments/56398712","id":56398712,"diff_hunk":"@@ -0,0 +1,123 @@\n+﻿//*********************************************************//\n+//    Copyright (c) Microsoft. All rights reserved.\n+//    \n+//    Apache 2.0 License\n+//    \n+//    You may obtain a copy of the License at\n+//    http://www.apache.org/licenses/LICENSE-2.0\n+//    \n+//    Unless required by applicable law or agreed to in writing, software \n+//    distributed under the License is distributed on an \"AS IS\" BASIS, \n+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or \n+//    implied. See the License for the specific language governing \n+//    permissions and limitations under the License.\n+//\n+//*********************************************************//\n+\n+using System.Threading.Tasks;\n+using Microsoft.VisualStudioTools.Project;\n+using Microsoft.NodejsTools.Npm;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.IO;\n+\n+using SR = Microsoft.NodejsTools.Project.SR;\n+\n+namespace Microsoft.NodejsTools {\n+    static class TypingsAcquisition {\n+        private const string TsdExe = \"tsd.cmd\";\n+        private const string TypingsDirecctoryName = \"typings\";\n+\n+        public static async Task<bool> AcquireTypings(\n+            string pathToRootNpmDirectory,\n+            string pathToRootProjectDirectory,\n+            IEnumerable<IPackage> packages,\n+            Redirector redirector) {\n+            var newPackages = TypingsToAcquire(pathToRootProjectDirectory, packages);\n+            return await DownloadTypings(\n+                pathToRootNpmDirectory,\n+                pathToRootProjectDirectory,\n+                newPackages,\n+                redirector);\n+        }\n+\n+        private static async Task<bool> DownloadTypings(\n+            string pathToRootNpmDirectory,\n+            string pathToRootProjectDirectory,\n+            IEnumerable<IPackage> packages,\n+            Redirector redirector) {\n+            if (!packages.Any()) {\n+                return true;\n+            }\n+\n+            var tsdPath = GetTsdPath(pathToRootNpmDirectory);\n+            if (tsdPath == null) {\n+                if (redirector != null)\n+                    redirector.WriteErrorLine(SR.GetString(SR.TsdNotInstalledError));\n+                return false;\n+            }\n+\n+            using (var process = ProcessOutput.Run(\n+                tsdPath,\n+                TsdInstallArguments(packages),\n+                pathToRootProjectDirectory,\n+                null,\n+                false,\n+                redirector,\n+                quoteArgs: true)) {\n+                if (!process.IsStarted) {\n+                    // Process failed to start, and any exception message has\n+                    // already been sent through the redirector\n+                    if (redirector != null) {\n+                        redirector.WriteErrorLine(\"could not start tsd\");\n+                    }\n+                    return false;\n+                }\n+                var i = await process;\n+                if (i == 0) {\n+                    if (redirector != null) {\n+                        redirector.WriteLine(SR.GetString(SR.TsdInstallCompleted));\n+                    }\n+                    return true;\n+                } else {\n+                    process.Kill();\n+                    if (redirector != null) {\n+                        redirector.WriteErrorLine(SR.GetString(SR.TsdInstallErrorOccurred));\n+                    }\n+                    return false;\n+                }\n+            }\n+        }\n+\n+        private static string GetTsdPath(string pathToRootNpmDirectory) {\n+            var path = Path.Combine(pathToRootNpmDirectory, TsdExe);\n+            return File.Exists(path) ? path : null;\n+        }\n+\n+        private static string GetPackageTsdName(IPackage package) {\n+            return package.Name;\n+        }\n+\n+        private static IEnumerable<string> TsdInstallArguments(IEnumerable<IPackage> packages) {\n+            return new[] { \"install\", }.Concat(packages.Select(GetPackageTsdName)).Concat(new[] { \"--save\" });\n+        }\n+\n+        private static IEnumerable<IPackage> TypingsToAcquire(string pathToRootProjectDirectory, IEnumerable<IPackage> packages) {\n+            var currentTypings = new HashSet<string>(CurrentTypingsPackages(pathToRootProjectDirectory));\n+            return packages.Where(package =>\n+                !currentTypings.Contains(GetPackageTsdName(package)));\n+        }\n+\n+        private static IEnumerable<string> CurrentTypingsPackages(string pathToRootProjectDirectory) {","path":"Nodejs/Product/Nodejs/TypingsAcquisition.cs","position":111,"original_position":111,"commit_id":"ca934f76ab001cc6b3b9ee9eb74ca41d0ac5b242","original_commit_id":"ca934f76ab001cc6b3b9ee9eb74ca41d0ac5b242","user":{"login":"mousetraps","id":762848,"avatar_url":"https://avatars.githubusercontent.com/u/762848?v=3","gravatar_id":"","url":"https://api.github.com/users/mousetraps","html_url":"https://github.com/mousetraps","followers_url":"https://api.github.com/users/mousetraps/followers","following_url":"https://api.github.com/users/mousetraps/following{/other_user}","gists_url":"https://api.github.com/users/mousetraps/gists{/gist_id}","starred_url":"https://api.github.com/users/mousetraps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mousetraps/subscriptions","organizations_url":"https://api.github.com/users/mousetraps/orgs","repos_url":"https://api.github.com/users/mousetraps/repos","events_url":"https://api.github.com/users/mousetraps/events{/privacy}","received_events_url":"https://api.github.com/users/mousetraps/received_events","type":"User","site_admin":false},"body":"In addition to this, we should be storing a list of files we've already tried to acquire, and we shouldn't attempt to acquire them again for the duration of that session. ","created_at":"2016-03-16T19:24:04Z","updated_at":"2016-03-16T19:24:04Z","html_url":"https://github.com/Microsoft/nodejstools/pull/747#discussion_r56398712","pull_request_url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/comments/56398712"},"html":{"href":"https://github.com/Microsoft/nodejstools/pull/747#discussion_r56398712"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747","id":62815293,"html_url":"https://github.com/Microsoft/nodejstools/pull/747","diff_url":"https://github.com/Microsoft/nodejstools/pull/747.diff","patch_url":"https://github.com/Microsoft/nodejstools/pull/747.patch","issue_url":"https://api.github.com/repos/Microsoft/nodejstools/issues/747","number":747,"state":"open","locked":false,"title":"Merge auto-dts branch into master","user":{"login":"mjbvz","id":12821956,"avatar_url":"https://avatars.githubusercontent.com/u/12821956?v=3","gravatar_id":"","url":"https://api.github.com/users/mjbvz","html_url":"https://github.com/mjbvz","followers_url":"https://api.github.com/users/mjbvz/followers","following_url":"https://api.github.com/users/mjbvz/following{/other_user}","gists_url":"https://api.github.com/users/mjbvz/gists{/gist_id}","starred_url":"https://api.github.com/users/mjbvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjbvz/subscriptions","organizations_url":"https://api.github.com/users/mjbvz/orgs","repos_url":"https://api.github.com/users/mjbvz/repos","events_url":"https://api.github.com/users/mjbvz/events{/privacy}","received_events_url":"https://api.github.com/users/mjbvz/received_events","type":"User","site_admin":false},"body":"This change merges the auto-dts branch work into master.","created_at":"2016-03-14T20:51:47Z","updated_at":"2016-03-16T19:24:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"426f878295b574dce848d87c63e909df1c808b1f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747/commits","review_comments_url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747/comments","review_comment_url":"https://api.github.com/repos/Microsoft/nodejstools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/nodejstools/issues/747/comments","statuses_url":"https://api.github.com/repos/Microsoft/nodejstools/statuses/ca934f76ab001cc6b3b9ee9eb74ca41d0ac5b242","head":{"label":"mjbvz:auto-dts-merge","ref":"auto-dts-merge","sha":"ca934f76ab001cc6b3b9ee9eb74ca41d0ac5b242","user":{"login":"mjbvz","id":12821956,"avatar_url":"https://avatars.githubusercontent.com/u/12821956?v=3","gravatar_id":"","url":"https://api.github.com/users/mjbvz","html_url":"https://github.com/mjbvz","followers_url":"https://api.github.com/users/mjbvz/followers","following_url":"https://api.github.com/users/mjbvz/following{/other_user}","gists_url":"https://api.github.com/users/mjbvz/gists{/gist_id}","starred_url":"https://api.github.com/users/mjbvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjbvz/subscriptions","organizations_url":"https://api.github.com/users/mjbvz/orgs","repos_url":"https://api.github.com/users/mjbvz/repos","events_url":"https://api.github.com/users/mjbvz/events{/privacy}","received_events_url":"https://api.github.com/users/mjbvz/received_events","type":"User","site_admin":false},"repo":{"id":52391688,"name":"nodejstools","full_name":"mjbvz/nodejstools","owner":{"login":"mjbvz","id":12821956,"avatar_url":"https://avatars.githubusercontent.com/u/12821956?v=3","gravatar_id":"","url":"https://api.github.com/users/mjbvz","html_url":"https://github.com/mjbvz","followers_url":"https://api.github.com/users/mjbvz/followers","following_url":"https://api.github.com/users/mjbvz/following{/other_user}","gists_url":"https://api.github.com/users/mjbvz/gists{/gist_id}","starred_url":"https://api.github.com/users/mjbvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjbvz/subscriptions","organizations_url":"https://api.github.com/users/mjbvz/orgs","repos_url":"https://api.github.com/users/mjbvz/repos","events_url":"https://api.github.com/users/mjbvz/events{/privacy}","received_events_url":"https://api.github.com/users/mjbvz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mjbvz/nodejstools","description":"Node.js Tools for Visual Studio","fork":true,"url":"https://api.github.com/repos/mjbvz/nodejstools","forks_url":"https://api.github.com/repos/mjbvz/nodejstools/forks","keys_url":"https://api.github.com/repos/mjbvz/nodejstools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mjbvz/nodejstools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mjbvz/nodejstools/teams","hooks_url":"https://api.github.com/repos/mjbvz/nodejstools/hooks","issue_events_url":"https://api.github.com/repos/mjbvz/nodejstools/issues/events{/number}","events_url":"https://api.github.com/repos/mjbvz/nodejstools/events","assignees_url":"https://api.github.com/repos/mjbvz/nodejstools/assignees{/user}","branches_url":"https://api.github.com/repos/mjbvz/nodejstools/branches{/branch}","tags_url":"https://api.github.com/repos/mjbvz/nodejstools/tags","blobs_url":"https://api.github.com/repos/mjbvz/nodejstools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mjbvz/nodejstools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mjbvz/nodejstools/git/refs{/sha}","trees_url":"https://api.github.com/repos/mjbvz/nodejstools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mjbvz/nodejstools/statuses/{sha}","languages_url":"https://api.github.com/repos/mjbvz/nodejstools/languages","stargazers_url":"https://api.github.com/repos/mjbvz/nodejstools/stargazers","contributors_url":"https://api.github.com/repos/mjbvz/nodejstools/contributors","subscribers_url":"https://api.github.com/repos/mjbvz/nodejstools/subscribers","subscription_url":"https://api.github.com/repos/mjbvz/nodejstools/subscription","commits_url":"https://api.github.com/repos/mjbvz/nodejstools/commits{/sha}","git_commits_url":"https://api.github.com/repos/mjbvz/nodejstools/git/commits{/sha}","comments_url":"https://api.github.com/repos/mjbvz/nodejstools/comments{/number}","issue_comment_url":"https://api.github.com/repos/mjbvz/nodejstools/issues/comments{/number}","contents_url":"https://api.github.com/repos/mjbvz/nodejstools/contents/{+path}","compare_url":"https://api.github.com/repos/mjbvz/nodejstools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mjbvz/nodejstools/merges","archive_url":"https://api.github.com/repos/mjbvz/nodejstools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mjbvz/nodejstools/downloads","issues_url":"https://api.github.com/repos/mjbvz/nodejstools/issues{/number}","pulls_url":"https://api.github.com/repos/mjbvz/nodejstools/pulls{/number}","milestones_url":"https://api.github.com/repos/mjbvz/nodejstools/milestones{/number}","notifications_url":"https://api.github.com/repos/mjbvz/nodejstools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mjbvz/nodejstools/labels{/name}","releases_url":"https://api.github.com/repos/mjbvz/nodejstools/releases{/id}","deployments_url":"https://api.github.com/repos/mjbvz/nodejstools/deployments","created_at":"2016-02-23T21:06:55Z","updated_at":"2016-02-23T21:07:01Z","pushed_at":"2016-03-16T19:09:09Z","git_url":"git://github.com/mjbvz/nodejstools.git","ssh_url":"git@github.com:mjbvz/nodejstools.git","clone_url":"https://github.com/mjbvz/nodejstools.git","svn_url":"https://github.com/mjbvz/nodejstools","homepage":"http://aka.ms/explorentvs","size":92558,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"e5e2e1f9694144157786a26a8bdc5be7888c104d","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":33017149,"name":"nodejstools","full_name":"Microsoft/nodejstools","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/nodejstools","description":"Node.js Tools for Visual Studio","fork":false,"url":"https://api.github.com/repos/Microsoft/nodejstools","forks_url":"https://api.github.com/repos/Microsoft/nodejstools/forks","keys_url":"https://api.github.com/repos/Microsoft/nodejstools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/nodejstools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/nodejstools/teams","hooks_url":"https://api.github.com/repos/Microsoft/nodejstools/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/nodejstools/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/nodejstools/events","assignees_url":"https://api.github.com/repos/Microsoft/nodejstools/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/nodejstools/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/nodejstools/tags","blobs_url":"https://api.github.com/repos/Microsoft/nodejstools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/nodejstools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/nodejstools/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/nodejstools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/nodejstools/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/nodejstools/languages","stargazers_url":"https://api.github.com/repos/Microsoft/nodejstools/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/nodejstools/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/nodejstools/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/nodejstools/subscription","commits_url":"https://api.github.com/repos/Microsoft/nodejstools/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/nodejstools/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/nodejstools/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/nodejstools/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/nodejstools/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/nodejstools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/nodejstools/merges","archive_url":"https://api.github.com/repos/Microsoft/nodejstools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/nodejstools/downloads","issues_url":"https://api.github.com/repos/Microsoft/nodejstools/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/nodejstools/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/nodejstools/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/nodejstools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/nodejstools/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/nodejstools/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/nodejstools/deployments","created_at":"2015-03-28T01:37:20Z","updated_at":"2016-03-16T18:38:13Z","pushed_at":"2016-03-16T19:09:10Z","git_url":"git://github.com/Microsoft/nodejstools.git","ssh_url":"git@github.com:Microsoft/nodejstools.git","clone_url":"https://github.com/Microsoft/nodejstools.git","svn_url":"https://github.com/Microsoft/nodejstools","homepage":"http://aka.ms/explorentvs","size":93736,"stargazers_count":1103,"watchers_count":1103,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":167,"mirror_url":null,"open_issues_count":255,"forks":167,"open_issues":255,"watchers":1103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747"},"html":{"href":"https://github.com/Microsoft/nodejstools/pull/747"},"issue":{"href":"https://api.github.com/repos/Microsoft/nodejstools/issues/747"},"comments":{"href":"https://api.github.com/repos/Microsoft/nodejstools/issues/747/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/nodejstools/pulls/747/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/nodejstools/statuses/ca934f76ab001cc6b3b9ee9eb74ca41d0ac5b242"}}}}