{"action":"created","comment":{"url":"https://api.github.com/repos/angular/devkit/pulls/comments/190353739","pull_request_review_id":122711947,"id":190353739,"diff_hunk":"@@ -0,0 +1,130 @@\n+/**\n+ * @license\n+ * Copyright Google Inc. All Rights Reserved.\n+ *\n+ * Use of this source code is governed by an MIT-style license that can be\n+ * found in the LICENSE file at https://angular.io/license\n+ */\n+import { JsonAstObject, JsonParseMode, parseJsonAst } from '@angular-devkit/core';\n+import { SchematicsException, Tree } from '@angular-devkit/schematics';\n+import { appendPropertyInAstObject, findPropertyInAstObject } from './json-utils';\n+\n+\n+const pkgJsonPath = '/package.json';\n+export enum NodeDependencyType {\n+  Default = 'dependencies',\n+  Dev = 'devDependencies',\n+  Peer = 'peerDependencies',\n+  Optional = 'optionalDependencies',\n+}\n+\n+export interface NodeDependency {\n+  type: NodeDependencyType;\n+  name: string;\n+  version: string;\n+  overwrite?: boolean;\n+}\n+\n+export function addPackageJsonDependency(tree: Tree, dependency: NodeDependency): void {\n+  const packageJsonAst = _readPackageJson(tree);\n+  const depsNode = findPropertyInAstObject(packageJsonAst, dependency.type);\n+  const recorder = tree.beginUpdate(pkgJsonPath);\n+\n+  if (!depsNode) {\n+    // Haven't found the dependencies key, add it to the root of the package.json.\n+    appendPropertyInAstObject(recorder, packageJsonAst, dependency.type, {\n+      [dependency.name]: dependency.version,\n+    });\n+  } else if (depsNode.kind === 'object') {\n+    // check if package already added\n+    const depNode = findPropertyInAstObject(depsNode, dependency.name);\n+\n+    if (!depNode) {\n+      // Package not found, add it.\n+      appendPropertyInAstObject(","path":"packages/schematics/angular/utility/dependencies.ts","position":44,"original_position":44,"commit_id":"8aeb4a19a4da6465191e7ff25f1d38b92c74380b","original_commit_id":"8aeb4a19a4da6465191e7ff25f1d38b92c74380b","user":{"login":"hansl","id":681969,"avatar_url":"https://avatars1.githubusercontent.com/u/681969?v=4","gravatar_id":"","url":"https://api.github.com/users/hansl","html_url":"https://github.com/hansl","followers_url":"https://api.github.com/users/hansl/followers","following_url":"https://api.github.com/users/hansl/following{/other_user}","gists_url":"https://api.github.com/users/hansl/gists{/gist_id}","starred_url":"https://api.github.com/users/hansl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hansl/subscriptions","organizations_url":"https://api.github.com/users/hansl/orgs","repos_url":"https://api.github.com/users/hansl/repos","events_url":"https://api.github.com/users/hansl/events{/privacy}","received_events_url":"https://api.github.com/users/hansl/received_events","type":"User","site_admin":false},"body":"We don't want to simply append it. Dependency list in package.json is sorted.","created_at":"2018-05-23T18:28:29Z","updated_at":"2018-05-23T18:28:29Z","html_url":"https://github.com/angular/devkit/pull/954#discussion_r190353739","pull_request_url":"https://api.github.com/repos/angular/devkit/pulls/954","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/angular/devkit/pulls/comments/190353739"},"html":{"href":"https://github.com/angular/devkit/pull/954#discussion_r190353739"},"pull_request":{"href":"https://api.github.com/repos/angular/devkit/pulls/954"}}},"pull_request":{"url":"https://api.github.com/repos/angular/devkit/pulls/954","id":189480437,"html_url":"https://github.com/angular/devkit/pull/954","diff_url":"https://github.com/angular/devkit/pull/954.diff","patch_url":"https://github.com/angular/devkit/pull/954.patch","issue_url":"https://api.github.com/repos/angular/devkit/issues/954","number":954,"state":"open","locked":false,"title":"refactor: Consolidate adding dependencies","user":{"login":"Brocco","id":1565117,"avatar_url":"https://avatars0.githubusercontent.com/u/1565117?v=4","gravatar_id":"","url":"https://api.github.com/users/Brocco","html_url":"https://github.com/Brocco","followers_url":"https://api.github.com/users/Brocco/followers","following_url":"https://api.github.com/users/Brocco/following{/other_user}","gists_url":"https://api.github.com/users/Brocco/gists{/gist_id}","starred_url":"https://api.github.com/users/Brocco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brocco/subscriptions","organizations_url":"https://api.github.com/users/Brocco/orgs","repos_url":"https://api.github.com/users/Brocco/repos","events_url":"https://api.github.com/users/Brocco/events{/privacy}","received_events_url":"https://api.github.com/users/Brocco/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-21T20:31:57Z","updated_at":"2018-05-23T18:28:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"adcc75607647a75bd8fc4aaf6a62dd4e5412df19","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":589074190,"url":"https://api.github.com/repos/angular/devkit/labels/cla:%20yes","name":"cla: yes","color":"0e8a16","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/angular/devkit/pulls/954/commits","review_comments_url":"https://api.github.com/repos/angular/devkit/pulls/954/comments","review_comment_url":"https://api.github.com/repos/angular/devkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/angular/devkit/issues/954/comments","statuses_url":"https://api.github.com/repos/angular/devkit/statuses/8aeb4a19a4da6465191e7ff25f1d38b92c74380b","head":{"label":"Brocco:add-pkg-json-deps","ref":"add-pkg-json-deps","sha":"8aeb4a19a4da6465191e7ff25f1d38b92c74380b","user":{"login":"Brocco","id":1565117,"avatar_url":"https://avatars0.githubusercontent.com/u/1565117?v=4","gravatar_id":"","url":"https://api.github.com/users/Brocco","html_url":"https://github.com/Brocco","followers_url":"https://api.github.com/users/Brocco/followers","following_url":"https://api.github.com/users/Brocco/following{/other_user}","gists_url":"https://api.github.com/users/Brocco/gists{/gist_id}","starred_url":"https://api.github.com/users/Brocco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brocco/subscriptions","organizations_url":"https://api.github.com/users/Brocco/orgs","repos_url":"https://api.github.com/users/Brocco/repos","events_url":"https://api.github.com/users/Brocco/events{/privacy}","received_events_url":"https://api.github.com/users/Brocco/received_events","type":"User","site_admin":false},"repo":{"id":93437934,"name":"devkit","full_name":"Brocco/devkit","owner":{"login":"Brocco","id":1565117,"avatar_url":"https://avatars0.githubusercontent.com/u/1565117?v=4","gravatar_id":"","url":"https://api.github.com/users/Brocco","html_url":"https://github.com/Brocco","followers_url":"https://api.github.com/users/Brocco/followers","following_url":"https://api.github.com/users/Brocco/following{/other_user}","gists_url":"https://api.github.com/users/Brocco/gists{/gist_id}","starred_url":"https://api.github.com/users/Brocco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brocco/subscriptions","organizations_url":"https://api.github.com/users/Brocco/orgs","repos_url":"https://api.github.com/users/Brocco/repos","events_url":"https://api.github.com/users/Brocco/events{/privacy}","received_events_url":"https://api.github.com/users/Brocco/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Brocco/devkit","description":null,"fork":true,"url":"https://api.github.com/repos/Brocco/devkit","forks_url":"https://api.github.com/repos/Brocco/devkit/forks","keys_url":"https://api.github.com/repos/Brocco/devkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Brocco/devkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Brocco/devkit/teams","hooks_url":"https://api.github.com/repos/Brocco/devkit/hooks","issue_events_url":"https://api.github.com/repos/Brocco/devkit/issues/events{/number}","events_url":"https://api.github.com/repos/Brocco/devkit/events","assignees_url":"https://api.github.com/repos/Brocco/devkit/assignees{/user}","branches_url":"https://api.github.com/repos/Brocco/devkit/branches{/branch}","tags_url":"https://api.github.com/repos/Brocco/devkit/tags","blobs_url":"https://api.github.com/repos/Brocco/devkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Brocco/devkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Brocco/devkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/Brocco/devkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Brocco/devkit/statuses/{sha}","languages_url":"https://api.github.com/repos/Brocco/devkit/languages","stargazers_url":"https://api.github.com/repos/Brocco/devkit/stargazers","contributors_url":"https://api.github.com/repos/Brocco/devkit/contributors","subscribers_url":"https://api.github.com/repos/Brocco/devkit/subscribers","subscription_url":"https://api.github.com/repos/Brocco/devkit/subscription","commits_url":"https://api.github.com/repos/Brocco/devkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/Brocco/devkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/Brocco/devkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/Brocco/devkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/Brocco/devkit/contents/{+path}","compare_url":"https://api.github.com/repos/Brocco/devkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Brocco/devkit/merges","archive_url":"https://api.github.com/repos/Brocco/devkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Brocco/devkit/downloads","issues_url":"https://api.github.com/repos/Brocco/devkit/issues{/number}","pulls_url":"https://api.github.com/repos/Brocco/devkit/pulls{/number}","milestones_url":"https://api.github.com/repos/Brocco/devkit/milestones{/number}","notifications_url":"https://api.github.com/repos/Brocco/devkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Brocco/devkit/labels{/name}","releases_url":"https://api.github.com/repos/Brocco/devkit/releases{/id}","deployments_url":"https://api.github.com/repos/Brocco/devkit/deployments","created_at":"2017-06-05T19:17:36Z","updated_at":"2018-05-23T15:56:24Z","pushed_at":"2018-05-23T16:59:21Z","git_url":"git://github.com/Brocco/devkit.git","ssh_url":"git@github.com:Brocco/devkit.git","clone_url":"https://github.com/Brocco/devkit.git","svn_url":"https://github.com/Brocco/devkit","homepage":null,"size":3214,"stargazers_count":1,"watchers_count":1,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"angular:master","ref":"master","sha":"0be99d3e3f5bc96ea57fd72b835ca83f95f4fe5f","user":{"login":"angular","id":139426,"avatar_url":"https://avatars3.githubusercontent.com/u/139426?v=4","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"repo":{"id":88288940,"name":"devkit","full_name":"angular/devkit","owner":{"login":"angular","id":139426,"avatar_url":"https://avatars3.githubusercontent.com/u/139426?v=4","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/angular/devkit","description":null,"fork":false,"url":"https://api.github.com/repos/angular/devkit","forks_url":"https://api.github.com/repos/angular/devkit/forks","keys_url":"https://api.github.com/repos/angular/devkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/angular/devkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/angular/devkit/teams","hooks_url":"https://api.github.com/repos/angular/devkit/hooks","issue_events_url":"https://api.github.com/repos/angular/devkit/issues/events{/number}","events_url":"https://api.github.com/repos/angular/devkit/events","assignees_url":"https://api.github.com/repos/angular/devkit/assignees{/user}","branches_url":"https://api.github.com/repos/angular/devkit/branches{/branch}","tags_url":"https://api.github.com/repos/angular/devkit/tags","blobs_url":"https://api.github.com/repos/angular/devkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/angular/devkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/angular/devkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/angular/devkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/angular/devkit/statuses/{sha}","languages_url":"https://api.github.com/repos/angular/devkit/languages","stargazers_url":"https://api.github.com/repos/angular/devkit/stargazers","contributors_url":"https://api.github.com/repos/angular/devkit/contributors","subscribers_url":"https://api.github.com/repos/angular/devkit/subscribers","subscription_url":"https://api.github.com/repos/angular/devkit/subscription","commits_url":"https://api.github.com/repos/angular/devkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/angular/devkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/angular/devkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/angular/devkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/angular/devkit/contents/{+path}","compare_url":"https://api.github.com/repos/angular/devkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/angular/devkit/merges","archive_url":"https://api.github.com/repos/angular/devkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/angular/devkit/downloads","issues_url":"https://api.github.com/repos/angular/devkit/issues{/number}","pulls_url":"https://api.github.com/repos/angular/devkit/pulls{/number}","milestones_url":"https://api.github.com/repos/angular/devkit/milestones{/number}","notifications_url":"https://api.github.com/repos/angular/devkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/angular/devkit/labels{/name}","releases_url":"https://api.github.com/repos/angular/devkit/releases{/id}","deployments_url":"https://api.github.com/repos/angular/devkit/deployments","created_at":"2017-04-14T17:35:26Z","updated_at":"2018-05-23T18:20:15Z","pushed_at":"2018-05-23T18:20:06Z","git_url":"git://github.com/angular/devkit.git","ssh_url":"git@github.com:angular/devkit.git","clone_url":"https://github.com/angular/devkit.git","svn_url":"https://github.com/angular/devkit","homepage":null,"size":3220,"stargazers_count":539,"watchers_count":539,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":194,"mirror_url":null,"archived":false,"open_issues_count":138,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":194,"open_issues":138,"watchers":539,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/angular/devkit/pulls/954"},"html":{"href":"https://github.com/angular/devkit/pull/954"},"issue":{"href":"https://api.github.com/repos/angular/devkit/issues/954"},"comments":{"href":"https://api.github.com/repos/angular/devkit/issues/954/comments"},"review_comments":{"href":"https://api.github.com/repos/angular/devkit/pulls/954/comments"},"review_comment":{"href":"https://api.github.com/repos/angular/devkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/angular/devkit/pulls/954/commits"},"statuses":{"href":"https://api.github.com/repos/angular/devkit/statuses/8aeb4a19a4da6465191e7ff25f1d38b92c74380b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"hansl"}}