{"action":"created","comment":{"url":"https://api.github.com/repos/appium/appium-uiauto/pulls/comments/34934454","id":34934454,"diff_hunk":"@@ -1,76 +1,86 @@\n \"use strict\";\n+import path from 'path';\n+import _fs from 'fs';\n+import _ from 'lodash';\n+import B from 'bluebird';\n \n-var path = require('path'),\n-    fs = require('fs'),\n-    _ = require('lodash'),\n-    root = path.resolve(__dirname, \"../uiauto\");\n+let fs = {\n+  readFile: B.promisify(_fs.readFile)\n+};\n+\n+let root = path.resolve(__dirname, '../uiauto');\n \n // keep a list of files we examine for the purposes of making sure we're\n // not adding the same file to the collated version twice\n-var filesExamined;\n+let filesExamined;\n \n // this regex helps us get the file path of an import\n-var importRe = /^#import ('|\")([^('|\")]+)('|\")$/mg;\n+let importRe = /^#import ('|\")([^('|\")]+)('|\")$/mg;\n \n-var getDepsForFile = function (file, extraImports) {\n+async function getDepsForFile (file, extraImports) {\n   if (_.contains(filesExamined, file)) {\n-    throw new Error(\"Re-examining file \" + file + \"; you need to make sure \" +\n-                    \"the graph is set up so we don't require files twice\");\n+    throw new Error(`Re-examining file ${file}; you need to make sure ` +\n+                    `the graph is set up so we don't require files twice`);\n   }\n   filesExamined.push(file);\n-  var data = fs.readFileSync(file).toString('utf8');\n-  var deps = {};\n+  \n+  let data = await fs.readFile(file, 'utf8');\n+  let deps = {};\n   deps[file] = [];\n-  var matches = [];\n-  var match = importRe.exec(data);\n+  let matches = [];\n+  let match = importRe.exec(data);\n   while (match) {\n-    if (match) matches.push(match[2]);\n+    if (match) {\n+      matches.push(match[2]);\n+    }\n     match = importRe.exec(data);\n   }\n   if (extraImports && extraImports.length > 0) {\n     matches = extraImports.concat(matches);\n   }\n+\n   if (matches.length > 0) {\n-    _.each(matches, function (importedFile) {\n-      var importedPath = path.resolve(path.dirname(file), importedFile);\n+    for (let importedFile of matches) {\n+      let importedPath = path.resolve(path.dirname(file), importedFile);\n+      let importedDeps = await getDepsForFile(importedPath);\n+      deps[file].push(importedDeps);\n+    }\n       // recursively get dependencies for imported files\n-      deps[file].push(getDepsForFile(importedPath));\n-    });\n   }\n   return deps;\n-};\n+}\n \n-var buildScriptFromDeps = function (deps) {\n-  // when building the actual script we need to go as deep as we can first\n-  // to make sure the dependencies are available for code later on in\n-  // the resulting file\n-  var script = \"\";\n-  _.each(deps, function (subDepsArray, file) {\n+async function buildScriptFromDeps (deps) {\n+  let script = '';\n+  for (let [file, subDepsArray] of _.pairs(deps)) {\n     if (subDepsArray.length > 0) {\n-      _.each(subDepsArray, function (subDeps) {\n-        script += buildScriptFromDeps(subDeps);\n-      });\n+      for (let subDeps of subDepsArray) {\n+        script += await buildScriptFromDeps(subDeps);\n+      }  \n     }\n-    // add the actual code to our big script var\n-    var newFileData = stripImports(fs.readFileSync(file).toString('utf8'));\n-    var fileWithoutRoot = file.replace(root + '/', '');\n-    script += \"\\n/* begin file: \" + fileWithoutRoot + \" */\\n\";\n+    let fileContents = await fs.readFile(file, 'utf8');\n+    let newFileData = stripImports(fileContents);\n+    let fileWithoutRoot = file.replace(`${root}/`, '');\n+    script += `\\n/* begin file: ${fileWithoutRoot} */\\n`;\n     script += newFileData;\n-    script += \"\\n/* end file: \" + fileWithoutRoot + \" */\\n\";\n-  });\n+    script += `\\n/* end file: ${fileWithoutRoot} */\\n`;\n+  }\n   return script;\n-};\n+}\n+\n \n-var stripImports = function (data) {\n+function stripImports(data) {","path":"lib/resolve-deps.js","position":108,"original_position":108,"commit_id":"8989876e5f490a03c7cd64edafa0193f540eb537","original_commit_id":"8989876e5f490a03c7cd64edafa0193f540eb537","user":{"login":"imurchie","id":2614354,"avatar_url":"https://avatars.githubusercontent.com/u/2614354?v=3","gravatar_id":"","url":"https://api.github.com/users/imurchie","html_url":"https://github.com/imurchie","followers_url":"https://api.github.com/users/imurchie/followers","following_url":"https://api.github.com/users/imurchie/following{/other_user}","gists_url":"https://api.github.com/users/imurchie/gists{/gist_id}","starred_url":"https://api.github.com/users/imurchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imurchie/subscriptions","organizations_url":"https://api.github.com/users/imurchie/orgs","repos_url":"https://api.github.com/users/imurchie/repos","events_url":"https://api.github.com/users/imurchie/events{/privacy}","received_events_url":"https://api.github.com/users/imurchie/received_events","type":"User","site_admin":false},"body":"`function stripImports (data) {` (i.e., add a space before argument list).","created_at":"2015-07-17T21:55:07Z","updated_at":"2015-07-17T21:55:07Z","html_url":"https://github.com/appium/appium-uiauto/pull/76#discussion_r34934454","pull_request_url":"https://api.github.com/repos/appium/appium-uiauto/pulls/76","_links":{"self":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/comments/34934454"},"html":{"href":"https://github.com/appium/appium-uiauto/pull/76#discussion_r34934454"},"pull_request":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/76"}}},"pull_request":{"url":"https://api.github.com/repos/appium/appium-uiauto/pulls/76","id":40174636,"html_url":"https://github.com/appium/appium-uiauto/pull/76","diff_url":"https://github.com/appium/appium-uiauto/pull/76.diff","patch_url":"https://github.com/appium/appium-uiauto/pull/76.patch","issue_url":"https://api.github.com/repos/appium/appium-uiauto/issues/76","number":76,"state":"open","locked":false,"title":"sonia-rewrite resolve dependencies","user":{"login":"syang97","id":8731793,"avatar_url":"https://avatars.githubusercontent.com/u/8731793?v=3","gravatar_id":"","url":"https://api.github.com/users/syang97","html_url":"https://github.com/syang97","followers_url":"https://api.github.com/users/syang97/followers","following_url":"https://api.github.com/users/syang97/following{/other_user}","gists_url":"https://api.github.com/users/syang97/gists{/gist_id}","starred_url":"https://api.github.com/users/syang97/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syang97/subscriptions","organizations_url":"https://api.github.com/users/syang97/orgs","repos_url":"https://api.github.com/users/syang97/repos","events_url":"https://api.github.com/users/syang97/events{/privacy}","received_events_url":"https://api.github.com/users/syang97/received_events","type":"User","site_admin":false},"body":"I don't pass 9 of the tests :( Probably something to do with my placement of await statements. ","created_at":"2015-07-16T20:53:14Z","updated_at":"2015-07-17T21:55:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"67f248ae851356a3185a57b574853d03dec5a247","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/appium/appium-uiauto/pulls/76/commits","review_comments_url":"https://api.github.com/repos/appium/appium-uiauto/pulls/76/comments","review_comment_url":"https://api.github.com/repos/appium/appium-uiauto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/appium/appium-uiauto/issues/76/comments","statuses_url":"https://api.github.com/repos/appium/appium-uiauto/statuses/8989876e5f490a03c7cd64edafa0193f540eb537","head":{"label":"syang97:soniaresolvedp","ref":"soniaresolvedp","sha":"8989876e5f490a03c7cd64edafa0193f540eb537","user":{"login":"syang97","id":8731793,"avatar_url":"https://avatars.githubusercontent.com/u/8731793?v=3","gravatar_id":"","url":"https://api.github.com/users/syang97","html_url":"https://github.com/syang97","followers_url":"https://api.github.com/users/syang97/followers","following_url":"https://api.github.com/users/syang97/following{/other_user}","gists_url":"https://api.github.com/users/syang97/gists{/gist_id}","starred_url":"https://api.github.com/users/syang97/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syang97/subscriptions","organizations_url":"https://api.github.com/users/syang97/orgs","repos_url":"https://api.github.com/users/syang97/repos","events_url":"https://api.github.com/users/syang97/events{/privacy}","received_events_url":"https://api.github.com/users/syang97/received_events","type":"User","site_admin":false},"repo":{"id":39164818,"name":"appium-uiauto","full_name":"syang97/appium-uiauto","owner":{"login":"syang97","id":8731793,"avatar_url":"https://avatars.githubusercontent.com/u/8731793?v=3","gravatar_id":"","url":"https://api.github.com/users/syang97","html_url":"https://github.com/syang97","followers_url":"https://api.github.com/users/syang97/followers","following_url":"https://api.github.com/users/syang97/following{/other_user}","gists_url":"https://api.github.com/users/syang97/gists{/gist_id}","starred_url":"https://api.github.com/users/syang97/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syang97/subscriptions","organizations_url":"https://api.github.com/users/syang97/orgs","repos_url":"https://api.github.com/users/syang97/repos","events_url":"https://api.github.com/users/syang97/events{/privacy}","received_events_url":"https://api.github.com/users/syang97/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/syang97/appium-uiauto","description":"Appium uiauto ios driver","fork":true,"url":"https://api.github.com/repos/syang97/appium-uiauto","forks_url":"https://api.github.com/repos/syang97/appium-uiauto/forks","keys_url":"https://api.github.com/repos/syang97/appium-uiauto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/syang97/appium-uiauto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/syang97/appium-uiauto/teams","hooks_url":"https://api.github.com/repos/syang97/appium-uiauto/hooks","issue_events_url":"https://api.github.com/repos/syang97/appium-uiauto/issues/events{/number}","events_url":"https://api.github.com/repos/syang97/appium-uiauto/events","assignees_url":"https://api.github.com/repos/syang97/appium-uiauto/assignees{/user}","branches_url":"https://api.github.com/repos/syang97/appium-uiauto/branches{/branch}","tags_url":"https://api.github.com/repos/syang97/appium-uiauto/tags","blobs_url":"https://api.github.com/repos/syang97/appium-uiauto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/syang97/appium-uiauto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/syang97/appium-uiauto/git/refs{/sha}","trees_url":"https://api.github.com/repos/syang97/appium-uiauto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/syang97/appium-uiauto/statuses/{sha}","languages_url":"https://api.github.com/repos/syang97/appium-uiauto/languages","stargazers_url":"https://api.github.com/repos/syang97/appium-uiauto/stargazers","contributors_url":"https://api.github.com/repos/syang97/appium-uiauto/contributors","subscribers_url":"https://api.github.com/repos/syang97/appium-uiauto/subscribers","subscription_url":"https://api.github.com/repos/syang97/appium-uiauto/subscription","commits_url":"https://api.github.com/repos/syang97/appium-uiauto/commits{/sha}","git_commits_url":"https://api.github.com/repos/syang97/appium-uiauto/git/commits{/sha}","comments_url":"https://api.github.com/repos/syang97/appium-uiauto/comments{/number}","issue_comment_url":"https://api.github.com/repos/syang97/appium-uiauto/issues/comments{/number}","contents_url":"https://api.github.com/repos/syang97/appium-uiauto/contents/{+path}","compare_url":"https://api.github.com/repos/syang97/appium-uiauto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/syang97/appium-uiauto/merges","archive_url":"https://api.github.com/repos/syang97/appium-uiauto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/syang97/appium-uiauto/downloads","issues_url":"https://api.github.com/repos/syang97/appium-uiauto/issues{/number}","pulls_url":"https://api.github.com/repos/syang97/appium-uiauto/pulls{/number}","milestones_url":"https://api.github.com/repos/syang97/appium-uiauto/milestones{/number}","notifications_url":"https://api.github.com/repos/syang97/appium-uiauto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/syang97/appium-uiauto/labels{/name}","releases_url":"https://api.github.com/repos/syang97/appium-uiauto/releases{/id}","created_at":"2015-07-15T22:47:22Z","updated_at":"2015-07-15T22:47:22Z","pushed_at":"2015-07-17T19:57:15Z","git_url":"git://github.com/syang97/appium-uiauto.git","ssh_url":"git@github.com:syang97/appium-uiauto.git","clone_url":"https://github.com/syang97/appium-uiauto.git","svn_url":"https://github.com/syang97/appium-uiauto","homepage":"","size":14605,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"appium:2.0","ref":"2.0","sha":"57ddca8bb5dba7cc67413b7f0678e39b367914af","user":{"login":"appium","id":3221291,"avatar_url":"https://avatars.githubusercontent.com/u/3221291?v=3","gravatar_id":"","url":"https://api.github.com/users/appium","html_url":"https://github.com/appium","followers_url":"https://api.github.com/users/appium/followers","following_url":"https://api.github.com/users/appium/following{/other_user}","gists_url":"https://api.github.com/users/appium/gists{/gist_id}","starred_url":"https://api.github.com/users/appium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appium/subscriptions","organizations_url":"https://api.github.com/users/appium/orgs","repos_url":"https://api.github.com/users/appium/repos","events_url":"https://api.github.com/users/appium/events{/privacy}","received_events_url":"https://api.github.com/users/appium/received_events","type":"Organization","site_admin":false},"repo":{"id":17281799,"name":"appium-uiauto","full_name":"appium/appium-uiauto","owner":{"login":"appium","id":3221291,"avatar_url":"https://avatars.githubusercontent.com/u/3221291?v=3","gravatar_id":"","url":"https://api.github.com/users/appium","html_url":"https://github.com/appium","followers_url":"https://api.github.com/users/appium/followers","following_url":"https://api.github.com/users/appium/following{/other_user}","gists_url":"https://api.github.com/users/appium/gists{/gist_id}","starred_url":"https://api.github.com/users/appium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appium/subscriptions","organizations_url":"https://api.github.com/users/appium/orgs","repos_url":"https://api.github.com/users/appium/repos","events_url":"https://api.github.com/users/appium/events{/privacy}","received_events_url":"https://api.github.com/users/appium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/appium/appium-uiauto","description":"Appium uiauto ios driver","fork":false,"url":"https://api.github.com/repos/appium/appium-uiauto","forks_url":"https://api.github.com/repos/appium/appium-uiauto/forks","keys_url":"https://api.github.com/repos/appium/appium-uiauto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/appium/appium-uiauto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/appium/appium-uiauto/teams","hooks_url":"https://api.github.com/repos/appium/appium-uiauto/hooks","issue_events_url":"https://api.github.com/repos/appium/appium-uiauto/issues/events{/number}","events_url":"https://api.github.com/repos/appium/appium-uiauto/events","assignees_url":"https://api.github.com/repos/appium/appium-uiauto/assignees{/user}","branches_url":"https://api.github.com/repos/appium/appium-uiauto/branches{/branch}","tags_url":"https://api.github.com/repos/appium/appium-uiauto/tags","blobs_url":"https://api.github.com/repos/appium/appium-uiauto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/appium/appium-uiauto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/appium/appium-uiauto/git/refs{/sha}","trees_url":"https://api.github.com/repos/appium/appium-uiauto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/appium/appium-uiauto/statuses/{sha}","languages_url":"https://api.github.com/repos/appium/appium-uiauto/languages","stargazers_url":"https://api.github.com/repos/appium/appium-uiauto/stargazers","contributors_url":"https://api.github.com/repos/appium/appium-uiauto/contributors","subscribers_url":"https://api.github.com/repos/appium/appium-uiauto/subscribers","subscription_url":"https://api.github.com/repos/appium/appium-uiauto/subscription","commits_url":"https://api.github.com/repos/appium/appium-uiauto/commits{/sha}","git_commits_url":"https://api.github.com/repos/appium/appium-uiauto/git/commits{/sha}","comments_url":"https://api.github.com/repos/appium/appium-uiauto/comments{/number}","issue_comment_url":"https://api.github.com/repos/appium/appium-uiauto/issues/comments{/number}","contents_url":"https://api.github.com/repos/appium/appium-uiauto/contents/{+path}","compare_url":"https://api.github.com/repos/appium/appium-uiauto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/appium/appium-uiauto/merges","archive_url":"https://api.github.com/repos/appium/appium-uiauto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/appium/appium-uiauto/downloads","issues_url":"https://api.github.com/repos/appium/appium-uiauto/issues{/number}","pulls_url":"https://api.github.com/repos/appium/appium-uiauto/pulls{/number}","milestones_url":"https://api.github.com/repos/appium/appium-uiauto/milestones{/number}","notifications_url":"https://api.github.com/repos/appium/appium-uiauto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/appium/appium-uiauto/labels{/name}","releases_url":"https://api.github.com/repos/appium/appium-uiauto/releases{/id}","created_at":"2014-02-28T09:41:28Z","updated_at":"2015-04-28T05:16:43Z","pushed_at":"2015-07-17T19:57:15Z","git_url":"git://github.com/appium/appium-uiauto.git","ssh_url":"git@github.com:appium/appium-uiauto.git","clone_url":"https://github.com/appium/appium-uiauto.git","svn_url":"https://github.com/appium/appium-uiauto","homepage":"","size":14605,"stargazers_count":9,"watchers_count":9,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":15,"forks":28,"open_issues":15,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/76"},"html":{"href":"https://github.com/appium/appium-uiauto/pull/76"},"issue":{"href":"https://api.github.com/repos/appium/appium-uiauto/issues/76"},"comments":{"href":"https://api.github.com/repos/appium/appium-uiauto/issues/76/comments"},"review_comments":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/76/comments"},"review_comment":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/appium/appium-uiauto/pulls/76/commits"},"statuses":{"href":"https://api.github.com/repos/appium/appium-uiauto/statuses/8989876e5f490a03c7cd64edafa0193f540eb537"}}}}