{"action":"created","comment":{"url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/comments/83535609","pull_request_review_id":4374862,"id":83535609,"diff_hunk":"@@ -0,0 +1,54 @@\n+module.exports.createHandler = createHandler\n+\n+var fs = require('fs')\n+\n+var log = require('npmlog')\n+var bundleClient = require('./bundle')\n+\n+function createHandler (hoodieClientPath, bundleTargetPath, bundleConfig) {\n+  var bundlePromise\n+\n+  return function (request, reply) {\n+    if (!bundlePromise) {\n+      bundlePromise = new Promise(function (resolve, reject) {\n+        log.silly('client', 'bundling')\n+        bundleClient(hoodieClientPath, bundleTargetPath, bundleConfig, function (error, bundleBuffer, hasUpdate) {\n+          if (error) {\n+            return reject(error)\n+          }\n+\n+          writeClientBundle(hasUpdate, bundleConfig.inMemory, bundleTargetPath, bundleBuffer)\n+\n+          resolve(bundleBuffer)\n+        })\n+      })\n+    }\n+\n+    bundlePromise.then(function (buffer) {\n+      reply(buffer).bytes(buffer.length).type('application/javascript')\n+    }).catch(reply)\n+  }\n+}\n+\n+function writeClientBundle (hasUpdate, inMemory, bundleTargetPath, bundleBuffer) {\n+  if (!hasUpdate) {\n+    log.info('client', 'bundle is up to date')\n+    return\n+  }\n+\n+  if (inMemory) {\n+    log.silly('client', 'running in memory, not writing bundle to ' + bundleTargetPath)\n+    return\n+  }\n+\n+  log.info('client', 'bundle is out of date')\n+  log.silly('client', 'writing bundle to ' + bundleTargetPath)\n+  fs.writeFile(bundleTargetPath, bundleBuffer, function (error) {\n+    if (error) {\n+      log.warn('client', 'could not write to ' + bundleTargetPath + '. Bundle cannot be cached and will be re-generated on server restart')\n+      return\n+    }\n+\n+    log.info('client', 'bundle written to ' + bundleTargetPath)\n+  })\n+}","path":"server/plugins/client/bundle-handler-factory.js","position":54,"original_position":54,"commit_id":"e7246fe6fb8b5a888e5b286e718308588ad0aae6","original_commit_id":"e7246fe6fb8b5a888e5b286e718308588ad0aae6","user":{"login":"gr2m","id":39992,"avatar_url":"https://avatars.githubusercontent.com/u/39992?v=3","gravatar_id":"","url":"https://api.github.com/users/gr2m","html_url":"https://github.com/gr2m","followers_url":"https://api.github.com/users/gr2m/followers","following_url":"https://api.github.com/users/gr2m/following{/other_user}","gists_url":"https://api.github.com/users/gr2m/gists{/gist_id}","starred_url":"https://api.github.com/users/gr2m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gr2m/subscriptions","organizations_url":"https://api.github.com/users/gr2m/orgs","repos_url":"https://api.github.com/users/gr2m/repos","events_url":"https://api.github.com/users/gr2m/events{/privacy}","received_events_url":"https://api.github.com/users/gr2m/received_events","type":"User","site_admin":false},"body":"we could also move this into its own file or exporting at `module.exports.internals.writeClientBundle` for unit testing?","created_at":"2016-10-15T16:44:02Z","updated_at":"2016-10-15T16:44:02Z","html_url":"https://github.com/hoodiehq/hoodie/pull/606#discussion_r83535609","pull_request_url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606","_links":{"self":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/comments/83535609"},"html":{"href":"https://github.com/hoodiehq/hoodie/pull/606#discussion_r83535609"},"pull_request":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606"}}},"pull_request":{"url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606","id":89489740,"html_url":"https://github.com/hoodiehq/hoodie/pull/606","diff_url":"https://github.com/hoodiehq/hoodie/pull/606.diff","patch_url":"https://github.com/hoodiehq/hoodie/pull/606.patch","issue_url":"https://api.github.com/repos/hoodiehq/hoodie/issues/606","number":606,"state":"open","locked":false,"title":"Refactor client/index.js for better testability","user":{"login":"davelosert","id":4287128,"avatar_url":"https://avatars.githubusercontent.com/u/4287128?v=3","gravatar_id":"","url":"https://api.github.com/users/davelosert","html_url":"https://github.com/davelosert","followers_url":"https://api.github.com/users/davelosert/followers","following_url":"https://api.github.com/users/davelosert/following{/other_user}","gists_url":"https://api.github.com/users/davelosert/gists{/gist_id}","starred_url":"https://api.github.com/users/davelosert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davelosert/subscriptions","organizations_url":"https://api.github.com/users/davelosert/orgs","repos_url":"https://api.github.com/users/davelosert/repos","events_url":"https://api.github.com/users/davelosert/events{/privacy}","received_events_url":"https://api.github.com/users/davelosert/received_events","type":"User","site_admin":false},"body":"PR for #594 .\r\n\r\nAs stated I extracted a factory functions and added several more tests for the paths given to the `bundleClient` and `fs` functions.\r\n\r\nI also added a first test for the paths that get built within the `client/index.js`. I realized quickly that thre is made use of `require.resolve` - which is not mockable and therefore the built path is not testable right now.\r\n\r\n`require.resolve` is also used within the `server/public.js` file. I think it could be a good idea to take all those `require.resolve` calls into an own separate module like `modulePathResolver` that could look like this:\r\n\r\n```\r\nvar path = require('path')\r\nvar modulePathResolver = {\r\n   getClientPath() : function () {\r\n      return require.resolve('@hoodie/client/package.json')\r\n  }\r\n  getPublicPath : function () {\r\n    return path.join(require.resolve('../../package.json'), '..', 'public')\r\n  }\r\n  getAccountPublicPath : function () {\r\n    return path.join(require.resolve('@hoodie/account/package.json'), '..', 'public')\r\n  }\r\n  // ... and so on for all modulePaths\r\n}\r\n```\r\n\r\n@gr2m What do you think about that? Should I raise another issue for it?","created_at":"2016-10-15T10:57:34Z","updated_at":"2016-10-15T16:45:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e4e5b342443307ecb49656032350cdf947a31ce","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606/commits","review_comments_url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606/comments","review_comment_url":"https://api.github.com/repos/hoodiehq/hoodie/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hoodiehq/hoodie/issues/606/comments","statuses_url":"https://api.github.com/repos/hoodiehq/hoodie/statuses/e7246fe6fb8b5a888e5b286e718308588ad0aae6","head":{"label":"davelosert:create-client-handler-factory","ref":"create-client-handler-factory","sha":"e7246fe6fb8b5a888e5b286e718308588ad0aae6","user":{"login":"davelosert","id":4287128,"avatar_url":"https://avatars.githubusercontent.com/u/4287128?v=3","gravatar_id":"","url":"https://api.github.com/users/davelosert","html_url":"https://github.com/davelosert","followers_url":"https://api.github.com/users/davelosert/followers","following_url":"https://api.github.com/users/davelosert/following{/other_user}","gists_url":"https://api.github.com/users/davelosert/gists{/gist_id}","starred_url":"https://api.github.com/users/davelosert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davelosert/subscriptions","organizations_url":"https://api.github.com/users/davelosert/orgs","repos_url":"https://api.github.com/users/davelosert/repos","events_url":"https://api.github.com/users/davelosert/events{/privacy}","received_events_url":"https://api.github.com/users/davelosert/received_events","type":"User","site_admin":false},"repo":{"id":69788079,"name":"hoodie","full_name":"davelosert/hoodie","owner":{"login":"davelosert","id":4287128,"avatar_url":"https://avatars.githubusercontent.com/u/4287128?v=3","gravatar_id":"","url":"https://api.github.com/users/davelosert","html_url":"https://github.com/davelosert","followers_url":"https://api.github.com/users/davelosert/followers","following_url":"https://api.github.com/users/davelosert/following{/other_user}","gists_url":"https://api.github.com/users/davelosert/gists{/gist_id}","starred_url":"https://api.github.com/users/davelosert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davelosert/subscriptions","organizations_url":"https://api.github.com/users/davelosert/orgs","repos_url":"https://api.github.com/users/davelosert/repos","events_url":"https://api.github.com/users/davelosert/events{/privacy}","received_events_url":"https://api.github.com/users/davelosert/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davelosert/hoodie","description":":dog: A backend for Offline First applications","fork":true,"url":"https://api.github.com/repos/davelosert/hoodie","forks_url":"https://api.github.com/repos/davelosert/hoodie/forks","keys_url":"https://api.github.com/repos/davelosert/hoodie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davelosert/hoodie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davelosert/hoodie/teams","hooks_url":"https://api.github.com/repos/davelosert/hoodie/hooks","issue_events_url":"https://api.github.com/repos/davelosert/hoodie/issues/events{/number}","events_url":"https://api.github.com/repos/davelosert/hoodie/events","assignees_url":"https://api.github.com/repos/davelosert/hoodie/assignees{/user}","branches_url":"https://api.github.com/repos/davelosert/hoodie/branches{/branch}","tags_url":"https://api.github.com/repos/davelosert/hoodie/tags","blobs_url":"https://api.github.com/repos/davelosert/hoodie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davelosert/hoodie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davelosert/hoodie/git/refs{/sha}","trees_url":"https://api.github.com/repos/davelosert/hoodie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davelosert/hoodie/statuses/{sha}","languages_url":"https://api.github.com/repos/davelosert/hoodie/languages","stargazers_url":"https://api.github.com/repos/davelosert/hoodie/stargazers","contributors_url":"https://api.github.com/repos/davelosert/hoodie/contributors","subscribers_url":"https://api.github.com/repos/davelosert/hoodie/subscribers","subscription_url":"https://api.github.com/repos/davelosert/hoodie/subscription","commits_url":"https://api.github.com/repos/davelosert/hoodie/commits{/sha}","git_commits_url":"https://api.github.com/repos/davelosert/hoodie/git/commits{/sha}","comments_url":"https://api.github.com/repos/davelosert/hoodie/comments{/number}","issue_comment_url":"https://api.github.com/repos/davelosert/hoodie/issues/comments{/number}","contents_url":"https://api.github.com/repos/davelosert/hoodie/contents/{+path}","compare_url":"https://api.github.com/repos/davelosert/hoodie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davelosert/hoodie/merges","archive_url":"https://api.github.com/repos/davelosert/hoodie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davelosert/hoodie/downloads","issues_url":"https://api.github.com/repos/davelosert/hoodie/issues{/number}","pulls_url":"https://api.github.com/repos/davelosert/hoodie/pulls{/number}","milestones_url":"https://api.github.com/repos/davelosert/hoodie/milestones{/number}","notifications_url":"https://api.github.com/repos/davelosert/hoodie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davelosert/hoodie/labels{/name}","releases_url":"https://api.github.com/repos/davelosert/hoodie/releases{/id}","deployments_url":"https://api.github.com/repos/davelosert/hoodie/deployments","created_at":"2016-10-02T09:03:07Z","updated_at":"2016-10-02T09:03:08Z","pushed_at":"2016-10-15T10:51:03Z","git_url":"git://github.com/davelosert/hoodie.git","ssh_url":"git@github.com:davelosert/hoodie.git","clone_url":"https://github.com/davelosert/hoodie.git","svn_url":"https://github.com/davelosert/hoodie","homepage":"http://hood.ie","size":10350,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"hoodiehq:master","ref":"master","sha":"35072299c979a8f33ac8fafaca513880a0f883b4","user":{"login":"hoodiehq","id":1888826,"avatar_url":"https://avatars.githubusercontent.com/u/1888826?v=3","gravatar_id":"","url":"https://api.github.com/users/hoodiehq","html_url":"https://github.com/hoodiehq","followers_url":"https://api.github.com/users/hoodiehq/followers","following_url":"https://api.github.com/users/hoodiehq/following{/other_user}","gists_url":"https://api.github.com/users/hoodiehq/gists{/gist_id}","starred_url":"https://api.github.com/users/hoodiehq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hoodiehq/subscriptions","organizations_url":"https://api.github.com/users/hoodiehq/orgs","repos_url":"https://api.github.com/users/hoodiehq/repos","events_url":"https://api.github.com/users/hoodiehq/events{/privacy}","received_events_url":"https://api.github.com/users/hoodiehq/received_events","type":"Organization","site_admin":false},"repo":{"id":4780572,"name":"hoodie","full_name":"hoodiehq/hoodie","owner":{"login":"hoodiehq","id":1888826,"avatar_url":"https://avatars.githubusercontent.com/u/1888826?v=3","gravatar_id":"","url":"https://api.github.com/users/hoodiehq","html_url":"https://github.com/hoodiehq","followers_url":"https://api.github.com/users/hoodiehq/followers","following_url":"https://api.github.com/users/hoodiehq/following{/other_user}","gists_url":"https://api.github.com/users/hoodiehq/gists{/gist_id}","starred_url":"https://api.github.com/users/hoodiehq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hoodiehq/subscriptions","organizations_url":"https://api.github.com/users/hoodiehq/orgs","repos_url":"https://api.github.com/users/hoodiehq/repos","events_url":"https://api.github.com/users/hoodiehq/events{/privacy}","received_events_url":"https://api.github.com/users/hoodiehq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hoodiehq/hoodie","description":":dog: A backend for Offline First applications","fork":false,"url":"https://api.github.com/repos/hoodiehq/hoodie","forks_url":"https://api.github.com/repos/hoodiehq/hoodie/forks","keys_url":"https://api.github.com/repos/hoodiehq/hoodie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hoodiehq/hoodie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hoodiehq/hoodie/teams","hooks_url":"https://api.github.com/repos/hoodiehq/hoodie/hooks","issue_events_url":"https://api.github.com/repos/hoodiehq/hoodie/issues/events{/number}","events_url":"https://api.github.com/repos/hoodiehq/hoodie/events","assignees_url":"https://api.github.com/repos/hoodiehq/hoodie/assignees{/user}","branches_url":"https://api.github.com/repos/hoodiehq/hoodie/branches{/branch}","tags_url":"https://api.github.com/repos/hoodiehq/hoodie/tags","blobs_url":"https://api.github.com/repos/hoodiehq/hoodie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hoodiehq/hoodie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hoodiehq/hoodie/git/refs{/sha}","trees_url":"https://api.github.com/repos/hoodiehq/hoodie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hoodiehq/hoodie/statuses/{sha}","languages_url":"https://api.github.com/repos/hoodiehq/hoodie/languages","stargazers_url":"https://api.github.com/repos/hoodiehq/hoodie/stargazers","contributors_url":"https://api.github.com/repos/hoodiehq/hoodie/contributors","subscribers_url":"https://api.github.com/repos/hoodiehq/hoodie/subscribers","subscription_url":"https://api.github.com/repos/hoodiehq/hoodie/subscription","commits_url":"https://api.github.com/repos/hoodiehq/hoodie/commits{/sha}","git_commits_url":"https://api.github.com/repos/hoodiehq/hoodie/git/commits{/sha}","comments_url":"https://api.github.com/repos/hoodiehq/hoodie/comments{/number}","issue_comment_url":"https://api.github.com/repos/hoodiehq/hoodie/issues/comments{/number}","contents_url":"https://api.github.com/repos/hoodiehq/hoodie/contents/{+path}","compare_url":"https://api.github.com/repos/hoodiehq/hoodie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hoodiehq/hoodie/merges","archive_url":"https://api.github.com/repos/hoodiehq/hoodie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hoodiehq/hoodie/downloads","issues_url":"https://api.github.com/repos/hoodiehq/hoodie/issues{/number}","pulls_url":"https://api.github.com/repos/hoodiehq/hoodie/pulls{/number}","milestones_url":"https://api.github.com/repos/hoodiehq/hoodie/milestones{/number}","notifications_url":"https://api.github.com/repos/hoodiehq/hoodie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hoodiehq/hoodie/labels{/name}","releases_url":"https://api.github.com/repos/hoodiehq/hoodie/releases{/id}","deployments_url":"https://api.github.com/repos/hoodiehq/hoodie/deployments","created_at":"2012-06-25T10:44:38Z","updated_at":"2016-10-15T07:55:36Z","pushed_at":"2016-10-15T10:57:34Z","git_url":"git://github.com/hoodiehq/hoodie.git","ssh_url":"git@github.com:hoodiehq/hoodie.git","clone_url":"https://github.com/hoodiehq/hoodie.git","svn_url":"https://github.com/hoodiehq/hoodie","homepage":"http://hood.ie","size":10794,"stargazers_count":2071,"watchers_count":2071,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":163,"mirror_url":null,"open_issues_count":17,"forks":163,"open_issues":17,"watchers":2071,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606"},"html":{"href":"https://github.com/hoodiehq/hoodie/pull/606"},"issue":{"href":"https://api.github.com/repos/hoodiehq/hoodie/issues/606"},"comments":{"href":"https://api.github.com/repos/hoodiehq/hoodie/issues/606/comments"},"review_comments":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606/comments"},"review_comment":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hoodiehq/hoodie/pulls/606/commits"},"statuses":{"href":"https://api.github.com/repos/hoodiehq/hoodie/statuses/e7246fe6fb8b5a888e5b286e718308588ad0aae6"}}}}
{"actor":{"display_login":"gr2m"}}