{"action":"created","comment":{"url":"https://api.github.com/repos/sindresorhus/ava/pulls/comments/48635185","id":48635185,"diff_hunk":"@@ -0,0 +1,95 @@\n+var cachingTransform = require('caching-transform');\n+var fs = require('fs');\n+var path = require('path');\n+var md5Hex = require('md5-hex');\n+var stripBom = require('strip-bom');\n+\n+module.exports = CachingPrecompiler;\n+\n+function CachingPrecompiler(cacheDir) {\n+\tif (!(this instanceof CachingPrecompiler)) {\n+\t\tthrow new Error('CachingPrecompiler must be called with new');\n+\t}\n+\tthis.cacheDir = cacheDir;\n+\tthis.filenameToHash = {};\n+\tthis.transform = this._createTransform();\n+}\n+\n+CachingPrecompiler.prototype._factory = function (cacheDir) {\n+\t// This factory method is only called once per process, and only as needed, to defer loading expensive dependencies.\n+\tvar babel = require('babel-core');\n+\tvar convertSourceMap = require('convert-source-map');\n+\tvar presetStage2 = require('babel-preset-stage-2');\n+\tvar presetES2015 = require('babel-preset-es2015');\n+\tvar transformRuntime = require('babel-plugin-transform-runtime');\n+\n+\tvar powerAssert = this._createEspowerPlugin(babel);\n+\n+\tfunction buildOptions(filename, code) {\n+\t\t// Extract existing source maps from the code.\n+\t\tvar sourceMap = convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, path.dirname(filename));\n+\n+\t\treturn {\n+\t\t\tpresets: [presetStage2, presetES2015],\n+\t\t\tplugins: [powerAssert, transformRuntime],\n+\t\t\tfilename: filename,\n+\t\t\tsourceMaps: true,\n+\t\t\tast: false,\n+\t\t\tinputSourceMap: sourceMap && sourceMap.toObject()\n+\t\t};\n+\t}\n+\n+\treturn function (code, filename, hash) {\n+\t\tcode = code.toString('utf8');\n+\t\tvar options = buildOptions(filename, code);\n+\t\tvar result = babel.transform(code, options);\n+\t\tvar mapFile = path.join(cacheDir, hash + '.map');\n+\t\tfs.writeFileSync(mapFile, JSON.stringify(result.map));\n+\t\treturn result.code;\n+\t};\n+};\n+\n+CachingPrecompiler.prototype._createEspowerPlugin = function (babel) {\n+\tvar createEspowerPlugin = require('babel-plugin-espower/create');\n+\tvar enhanceAssert = require('./enhance-assert');\n+\n+\t// initialize power-assert\n+\treturn createEspowerPlugin(babel, {\n+\t\tpatterns: enhanceAssert.PATTERNS\n+\t});\n+};\n+\n+CachingPrecompiler.prototype._createTransform = function () {\n+\tvar self = this;","path":"lib/caching-precompiler.js","position":63,"original_position":63,"commit_id":"f58dfe630f7c5cf571594a8dd0645cb1c587dac7","original_commit_id":"f58dfe630f7c5cf571594a8dd0645cb1c587dac7","user":{"login":"ariporad","id":1817508,"avatar_url":"https://avatars.githubusercontent.com/u/1817508?v=3","gravatar_id":"","url":"https://api.github.com/users/ariporad","html_url":"https://github.com/ariporad","followers_url":"https://api.github.com/users/ariporad/followers","following_url":"https://api.github.com/users/ariporad/following{/other_user}","gists_url":"https://api.github.com/users/ariporad/gists{/gist_id}","starred_url":"https://api.github.com/users/ariporad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ariporad/subscriptions","organizations_url":"https://api.github.com/users/ariporad/orgs","repos_url":"https://api.github.com/users/ariporad/repos","events_url":"https://api.github.com/users/ariporad/events{/privacy}","received_events_url":"https://api.github.com/users/ariporad/received_events","type":"User","site_admin":false},"body":"@jamestalmage: Why is this here? There are no closures?","created_at":"2015-12-30T22:09:17Z","updated_at":"2015-12-30T22:09:17Z","html_url":"https://github.com/sindresorhus/ava/pull/390#discussion_r48635185","pull_request_url":"https://api.github.com/repos/sindresorhus/ava/pulls/390","_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/comments/48635185"},"html":{"href":"https://github.com/sindresorhus/ava/pull/390#discussion_r48635185"},"pull_request":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/390"}}},"pull_request":{"url":"https://api.github.com/repos/sindresorhus/ava/pulls/390","id":54782086,"html_url":"https://github.com/sindresorhus/ava/pull/390","diff_url":"https://github.com/sindresorhus/ava/pull/390.diff","patch_url":"https://github.com/sindresorhus/ava/pull/390.patch","issue_url":"https://api.github.com/repos/sindresorhus/ava/issues/390","number":390,"state":"open","locked":false,"title":"Transpile in main thread","user":{"login":"jamestalmage","id":4082216,"avatar_url":"https://avatars.githubusercontent.com/u/4082216?v=3","gravatar_id":"","url":"https://api.github.com/users/jamestalmage","html_url":"https://github.com/jamestalmage","followers_url":"https://api.github.com/users/jamestalmage/followers","following_url":"https://api.github.com/users/jamestalmage/following{/other_user}","gists_url":"https://api.github.com/users/jamestalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/jamestalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamestalmage/subscriptions","organizations_url":"https://api.github.com/users/jamestalmage/orgs","repos_url":"https://api.github.com/users/jamestalmage/repos","events_url":"https://api.github.com/users/jamestalmage/events{/privacy}","received_events_url":"https://api.github.com/users/jamestalmage/received_events","type":"User","site_admin":false},"body":"Manual reimplementation of #349.\r\n\r\nThis moves Babel transforms to the main process, and caches the transpiled results.\r\n\r\nIt uses `caching-transform` to provide caching. Expensive requires (like babel) are placed inside the factory function, which caching-transform only calls when it determines it needs to transform a file.\r\n\r\nThe path to each precompiled test is passed in the options object to fork:\r\n\r\n```js\r\nfork('/path/to/file.js', {\r\n  precompiled: {\r\n    '/path/to/file.js': '/path/to/cached/file.js'\r\n  }\r\n});\r\n```\r\n\r\nIt uses `require-precompiled` to install a require hook that pulls the transformed file from the cache.\r\n\r\nThe caching directory is used by the users `package.json`, and installing in `node_modules/.cache/ava`.\r\nIf the cache directory cannot be found (i.e. if they have no package.json), or the user provides a --no-cache flag, pre-compilation still happens on the main thread - but results are published to a temp directory.\r\n\r\n","created_at":"2015-12-30T07:30:04Z","updated_at":"2015-12-30T22:09:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32e2d7a8743af4edd47c328d9f254235517aeb33","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sindresorhus/ava/pulls/390/commits","review_comments_url":"https://api.github.com/repos/sindresorhus/ava/pulls/390/comments","review_comment_url":"https://api.github.com/repos/sindresorhus/ava/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sindresorhus/ava/issues/390/comments","statuses_url":"https://api.github.com/repos/sindresorhus/ava/statuses/f58dfe630f7c5cf571594a8dd0645cb1c587dac7","head":{"label":"jamestalmage:transpile-in-main-thread","ref":"transpile-in-main-thread","sha":"f58dfe630f7c5cf571594a8dd0645cb1c587dac7","user":{"login":"jamestalmage","id":4082216,"avatar_url":"https://avatars.githubusercontent.com/u/4082216?v=3","gravatar_id":"","url":"https://api.github.com/users/jamestalmage","html_url":"https://github.com/jamestalmage","followers_url":"https://api.github.com/users/jamestalmage/followers","following_url":"https://api.github.com/users/jamestalmage/following{/other_user}","gists_url":"https://api.github.com/users/jamestalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/jamestalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamestalmage/subscriptions","organizations_url":"https://api.github.com/users/jamestalmage/orgs","repos_url":"https://api.github.com/users/jamestalmage/repos","events_url":"https://api.github.com/users/jamestalmage/events{/privacy}","received_events_url":"https://api.github.com/users/jamestalmage/received_events","type":"User","site_admin":false},"repo":{"id":45423629,"name":"ava","full_name":"jamestalmage/ava","owner":{"login":"jamestalmage","id":4082216,"avatar_url":"https://avatars.githubusercontent.com/u/4082216?v=3","gravatar_id":"","url":"https://api.github.com/users/jamestalmage","html_url":"https://github.com/jamestalmage","followers_url":"https://api.github.com/users/jamestalmage/followers","following_url":"https://api.github.com/users/jamestalmage/following{/other_user}","gists_url":"https://api.github.com/users/jamestalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/jamestalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamestalmage/subscriptions","organizations_url":"https://api.github.com/users/jamestalmage/orgs","repos_url":"https://api.github.com/users/jamestalmage/repos","events_url":"https://api.github.com/users/jamestalmage/events{/privacy}","received_events_url":"https://api.github.com/users/jamestalmage/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jamestalmage/ava","description":"Futuristic test runner :rocket:","fork":true,"url":"https://api.github.com/repos/jamestalmage/ava","forks_url":"https://api.github.com/repos/jamestalmage/ava/forks","keys_url":"https://api.github.com/repos/jamestalmage/ava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jamestalmage/ava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jamestalmage/ava/teams","hooks_url":"https://api.github.com/repos/jamestalmage/ava/hooks","issue_events_url":"https://api.github.com/repos/jamestalmage/ava/issues/events{/number}","events_url":"https://api.github.com/repos/jamestalmage/ava/events","assignees_url":"https://api.github.com/repos/jamestalmage/ava/assignees{/user}","branches_url":"https://api.github.com/repos/jamestalmage/ava/branches{/branch}","tags_url":"https://api.github.com/repos/jamestalmage/ava/tags","blobs_url":"https://api.github.com/repos/jamestalmage/ava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jamestalmage/ava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jamestalmage/ava/git/refs{/sha}","trees_url":"https://api.github.com/repos/jamestalmage/ava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jamestalmage/ava/statuses/{sha}","languages_url":"https://api.github.com/repos/jamestalmage/ava/languages","stargazers_url":"https://api.github.com/repos/jamestalmage/ava/stargazers","contributors_url":"https://api.github.com/repos/jamestalmage/ava/contributors","subscribers_url":"https://api.github.com/repos/jamestalmage/ava/subscribers","subscription_url":"https://api.github.com/repos/jamestalmage/ava/subscription","commits_url":"https://api.github.com/repos/jamestalmage/ava/commits{/sha}","git_commits_url":"https://api.github.com/repos/jamestalmage/ava/git/commits{/sha}","comments_url":"https://api.github.com/repos/jamestalmage/ava/comments{/number}","issue_comment_url":"https://api.github.com/repos/jamestalmage/ava/issues/comments{/number}","contents_url":"https://api.github.com/repos/jamestalmage/ava/contents/{+path}","compare_url":"https://api.github.com/repos/jamestalmage/ava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jamestalmage/ava/merges","archive_url":"https://api.github.com/repos/jamestalmage/ava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jamestalmage/ava/downloads","issues_url":"https://api.github.com/repos/jamestalmage/ava/issues{/number}","pulls_url":"https://api.github.com/repos/jamestalmage/ava/pulls{/number}","milestones_url":"https://api.github.com/repos/jamestalmage/ava/milestones{/number}","notifications_url":"https://api.github.com/repos/jamestalmage/ava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jamestalmage/ava/labels{/name}","releases_url":"https://api.github.com/repos/jamestalmage/ava/releases{/id}","created_at":"2015-11-02T21:35:12Z","updated_at":"2015-11-02T21:35:13Z","pushed_at":"2015-12-30T07:36:00Z","git_url":"git://github.com/jamestalmage/ava.git","ssh_url":"git@github.com:jamestalmage/ava.git","clone_url":"https://github.com/jamestalmage/ava.git","svn_url":"https://github.com/jamestalmage/ava","homepage":"","size":3112,"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":"sindresorhus:master","ref":"master","sha":"b83e4f5d68fcf47365dab7684d89be8b2e17808e","user":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"repo":{"id":26820798,"name":"ava","full_name":"sindresorhus/ava","owner":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sindresorhus/ava","description":"Futuristic test runner :rocket:","fork":false,"url":"https://api.github.com/repos/sindresorhus/ava","forks_url":"https://api.github.com/repos/sindresorhus/ava/forks","keys_url":"https://api.github.com/repos/sindresorhus/ava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sindresorhus/ava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sindresorhus/ava/teams","hooks_url":"https://api.github.com/repos/sindresorhus/ava/hooks","issue_events_url":"https://api.github.com/repos/sindresorhus/ava/issues/events{/number}","events_url":"https://api.github.com/repos/sindresorhus/ava/events","assignees_url":"https://api.github.com/repos/sindresorhus/ava/assignees{/user}","branches_url":"https://api.github.com/repos/sindresorhus/ava/branches{/branch}","tags_url":"https://api.github.com/repos/sindresorhus/ava/tags","blobs_url":"https://api.github.com/repos/sindresorhus/ava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sindresorhus/ava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sindresorhus/ava/git/refs{/sha}","trees_url":"https://api.github.com/repos/sindresorhus/ava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sindresorhus/ava/statuses/{sha}","languages_url":"https://api.github.com/repos/sindresorhus/ava/languages","stargazers_url":"https://api.github.com/repos/sindresorhus/ava/stargazers","contributors_url":"https://api.github.com/repos/sindresorhus/ava/contributors","subscribers_url":"https://api.github.com/repos/sindresorhus/ava/subscribers","subscription_url":"https://api.github.com/repos/sindresorhus/ava/subscription","commits_url":"https://api.github.com/repos/sindresorhus/ava/commits{/sha}","git_commits_url":"https://api.github.com/repos/sindresorhus/ava/git/commits{/sha}","comments_url":"https://api.github.com/repos/sindresorhus/ava/comments{/number}","issue_comment_url":"https://api.github.com/repos/sindresorhus/ava/issues/comments{/number}","contents_url":"https://api.github.com/repos/sindresorhus/ava/contents/{+path}","compare_url":"https://api.github.com/repos/sindresorhus/ava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sindresorhus/ava/merges","archive_url":"https://api.github.com/repos/sindresorhus/ava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sindresorhus/ava/downloads","issues_url":"https://api.github.com/repos/sindresorhus/ava/issues{/number}","pulls_url":"https://api.github.com/repos/sindresorhus/ava/pulls{/number}","milestones_url":"https://api.github.com/repos/sindresorhus/ava/milestones{/number}","notifications_url":"https://api.github.com/repos/sindresorhus/ava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sindresorhus/ava/labels{/name}","releases_url":"https://api.github.com/repos/sindresorhus/ava/releases{/id}","created_at":"2014-11-18T17:20:26Z","updated_at":"2015-12-30T21:19:35Z","pushed_at":"2015-12-30T21:51:59Z","git_url":"git://github.com/sindresorhus/ava.git","ssh_url":"git@github.com:sindresorhus/ava.git","clone_url":"https://github.com/sindresorhus/ava.git","svn_url":"https://github.com/sindresorhus/ava","homepage":"","size":3268,"stargazers_count":2111,"watchers_count":2111,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":56,"forks":67,"open_issues":56,"watchers":2111,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/390"},"html":{"href":"https://github.com/sindresorhus/ava/pull/390"},"issue":{"href":"https://api.github.com/repos/sindresorhus/ava/issues/390"},"comments":{"href":"https://api.github.com/repos/sindresorhus/ava/issues/390/comments"},"review_comments":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/390/comments"},"review_comment":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sindresorhus/ava/pulls/390/commits"},"statuses":{"href":"https://api.github.com/repos/sindresorhus/ava/statuses/f58dfe630f7c5cf571594a8dd0645cb1c587dac7"}}}}