{"action":"created","issue":{"url":"https://api.github.com/repos/sindresorhus/ava/issues/153","labels_url":"https://api.github.com/repos/sindresorhus/ava/issues/153/labels{/name}","comments_url":"https://api.github.com/repos/sindresorhus/ava/issues/153/comments","events_url":"https://api.github.com/repos/sindresorhus/ava/issues/153/events","html_url":"https://github.com/sindresorhus/ava/pull/153","id":115668933,"number":153,"title":"WIP: Improve babel runtime lookup","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},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-07T14:06:47Z","updated_at":"2015-11-07T14:46:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sindresorhus/ava/pulls/153","html_url":"https://github.com/sindresorhus/ava/pull/153","diff_url":"https://github.com/sindresorhus/ava/pull/153.diff","patch_url":"https://github.com/sindresorhus/ava/pull/153.patch"},"body":"Attempts to address #152 \r\n\r\nIt needs a bit more testing / follow up (I think there are a couple extra `requireFrom`s in there).\r\n\r\nSubmitted for feedback.\r\n\r\nInstead of mucking with module paths, it finds the dependencies and builds some wrapper code that will require them with absolute paths (pretty straightforward)\r\n\r\nThe difficult part is making sure we get module resolution correct.\r\n\r\nBasically, the way I see it there can be a few things happening:\r\n\r\n 1. User has `babel-runtime` installed locally\r\n 2. User has `regenerator` installed locally.\r\n 3. User has `babel-core` installed locally\r\n 4. User has `babel` installed locally\r\n 5. User has nothing installed and will rely on the local ava implementation.\r\n\r\nHere is what we should then resolve\r\n\r\n1.  `babel-runtime/regenerator` from `.`\r\n2.  `regenerator/runtime-module` from `.`\r\n3.  `regenerator/runtime-module` from `node_modeules/babel-core`\r\n4.  deeply nested at this point: `n_m/babel/n_m/babel-core/n_m/regenerator/runtime-module` (`n_m === node_modules`)\r\n\r\nAnd who knows how `npm dedupe` has flattened things (some of those deeply nested items may get promoted to higher level folders by the dedupe process).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sindresorhus/ava/issues/comments/154712052","html_url":"https://github.com/sindresorhus/ava/pull/153#issuecomment-154712052","issue_url":"https://api.github.com/repos/sindresorhus/ava/issues/153","id":154712052,"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},"created_at":"2015-11-07T14:46:36Z","updated_at":"2015-11-07T14:46:36Z","body":"Here is a snippet of the runtime plugin (I would link to the repo, but it is 404'ing, since they went monorepo - old url was: https://github.com/babel-plugins/babel-plugin-runtime)\r\n\r\n```\r\n  return new Plugin(\"runtime\", {\r\n    metadata: {\r\n      group: \"builtin-post-modules\"\r\n    },\r\n\r\n    pre: function pre(file) {\r\n      file.set(\"helperGenerator\", function (name) {\r\n        return file.addImport(RUNTIME_MODULE_NAME + \"/helpers/\" + name, name, \"absoluteDefault\");\r\n      });\r\n\r\n      file.setDynamic(\"regeneratorIdentifier\", function () {\r\n        return file.addImport(RUNTIME_MODULE_NAME + \"/regenerator\", \"regeneratorRuntime\", \"absoluteDefault\");\r\n      });\r\n    },\r\n```"}}