{"action":"created","comment":{"url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/comments/171729201","pull_request_review_id":100634466,"id":171729201,"diff_hunk":"@@ -129,17 +130,47 @@ Proxyquire.prototype.load = function (request, stubs) {\n   return this._withoutCache(this._parent, stubs, request, this._parent.require.bind(this._parent, request))\n }\n \n+// Resolves a stub relative to a module.  Note that this only resolves\n+// \"relative\" paths (e.g. \"./foo\") but not non-relative modules (e.g. \"react\").\n+// Also, if noPreserveCache(), then we won't throw if the module can't\n+// be resolved.\n+Proxyquire.prototype._resolveRelativePath = function (path, moduleFilename) {\n+  try {\n+    return resolve.sync(path, {\n+      basedir: dirname(moduleFilename),\n+      extensions: Object.keys(require.extensions),\n+      paths: Module.globalPaths\n+    })\n+  } catch (err) {\n+    // If this is not a relative path (e.g. \"foo\" as opposed to \"./foo\"), and\n+    // we couldn't resolve it, then we just let the path through unchanged.\n+    if (path[0] !== '.') {\n+      return path\n+    }\n+\n+    // If !this._preserveCache, then we don't want to throw, since we can\n+    // resolve modules that don't exist.  Resolve as best we can.\n+    if (!this._preserveCache) {\n+      return pathResolve(dirname(moduleFilename), path)\n+    }\n+\n+    throw err\n+  }\n+}\n+\n // This replaces a module's require function\n Proxyquire.prototype._require = function (module, stubs, path) {\n   assert(typeof path === 'string', 'path must be a string')\n   assert(path, 'missing path')\n \n-  if (hasOwnProperty.call(stubs, path)) {\n-    var stub = stubs[path]\n+  var resolvedPath = this._resolveRelativePath(path, module.filename)\n+","path":"lib/proxyquire.js","position":48,"original_position":48,"commit_id":"cbceb8fcd612102b600262af523ecf6f28bf8e6f","original_commit_id":"cbceb8fcd612102b600262af523ecf6f28bf8e6f","user":{"login":"bendrucker","id":808808,"avatar_url":"https://avatars0.githubusercontent.com/u/808808?v=4","gravatar_id":"","url":"https://api.github.com/users/bendrucker","html_url":"https://github.com/bendrucker","followers_url":"https://api.github.com/users/bendrucker/followers","following_url":"https://api.github.com/users/bendrucker/following{/other_user}","gists_url":"https://api.github.com/users/bendrucker/gists{/gist_id}","starred_url":"https://api.github.com/users/bendrucker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendrucker/subscriptions","organizations_url":"https://api.github.com/users/bendrucker/orgs","repos_url":"https://api.github.com/users/bendrucker/repos","events_url":"https://api.github.com/users/bendrucker/events{/privacy}","received_events_url":"https://api.github.com/users/bendrucker/received_events","type":"User","site_admin":false},"body":"- linebreak since this gets used into the if block immediately after","created_at":"2018-03-01T23:42:26Z","updated_at":"2018-03-01T23:49:11Z","html_url":"https://github.com/thlorenz/proxyquire/pull/190#discussion_r171729201","pull_request_url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/comments/171729201"},"html":{"href":"https://github.com/thlorenz/proxyquire/pull/190#discussion_r171729201"},"pull_request":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190"}}},"pull_request":{"url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190","id":172140986,"html_url":"https://github.com/thlorenz/proxyquire/pull/190","diff_url":"https://github.com/thlorenz/proxyquire/pull/190.diff","patch_url":"https://github.com/thlorenz/proxyquire/pull/190.patch","issue_url":"https://api.github.com/repos/thlorenz/proxyquire/issues/190","number":190,"state":"open","locked":false,"title":"Make it so relative proxyquired paths are relative to the module being required.","user":{"login":"jwalton","id":1771003,"avatar_url":"https://avatars1.githubusercontent.com/u/1771003?v=4","gravatar_id":"","url":"https://api.github.com/users/jwalton","html_url":"https://github.com/jwalton","followers_url":"https://api.github.com/users/jwalton/followers","following_url":"https://api.github.com/users/jwalton/following{/other_user}","gists_url":"https://api.github.com/users/jwalton/gists{/gist_id}","starred_url":"https://api.github.com/users/jwalton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwalton/subscriptions","organizations_url":"https://api.github.com/users/jwalton/orgs","repos_url":"https://api.github.com/users/jwalton/repos","events_url":"https://api.github.com/users/jwalton/events{/privacy}","received_events_url":"https://api.github.com/users/jwalton/received_events","type":"User","site_admin":false},"body":"Fixes https://github.com/thlorenz/proxyquire/issues/189.\r\n\r\nI added a test case that fails without this fix, and passes with it.\r\n\r\nThis should definitely be a major version rev.  It's possible someone is currently doing something like:\r\n\r\n```js\r\n// src/a.js\r\nrequire('../b.js');\r\n```\r\n```js\r\n// b.js\r\nrequire('./c.js');\r\n```\r\n```\r\n// test.js\r\nproxyquire('./src/a.js', {'./c.js': ...});\r\n```\r\n\r\nWhich would no longer work with this change.  I can do a writeup for the README.md that explains this breaking change.\r\n","created_at":"2018-03-01T04:32:19Z","updated_at":"2018-03-01T23:49:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8300e96b7e5176cf2d629e686e5ead55dc8a3a93","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190/commits","review_comments_url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190/comments","review_comment_url":"https://api.github.com/repos/thlorenz/proxyquire/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thlorenz/proxyquire/issues/190/comments","statuses_url":"https://api.github.com/repos/thlorenz/proxyquire/statuses/cbceb8fcd612102b600262af523ecf6f28bf8e6f","head":{"label":"jwalton:master","ref":"master","sha":"cbceb8fcd612102b600262af523ecf6f28bf8e6f","user":{"login":"jwalton","id":1771003,"avatar_url":"https://avatars1.githubusercontent.com/u/1771003?v=4","gravatar_id":"","url":"https://api.github.com/users/jwalton","html_url":"https://github.com/jwalton","followers_url":"https://api.github.com/users/jwalton/followers","following_url":"https://api.github.com/users/jwalton/following{/other_user}","gists_url":"https://api.github.com/users/jwalton/gists{/gist_id}","starred_url":"https://api.github.com/users/jwalton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwalton/subscriptions","organizations_url":"https://api.github.com/users/jwalton/orgs","repos_url":"https://api.github.com/users/jwalton/repos","events_url":"https://api.github.com/users/jwalton/events{/privacy}","received_events_url":"https://api.github.com/users/jwalton/received_events","type":"User","site_admin":false},"repo":{"id":123376849,"name":"proxyquire","full_name":"jwalton/proxyquire","owner":{"login":"jwalton","id":1771003,"avatar_url":"https://avatars1.githubusercontent.com/u/1771003?v=4","gravatar_id":"","url":"https://api.github.com/users/jwalton","html_url":"https://github.com/jwalton","followers_url":"https://api.github.com/users/jwalton/followers","following_url":"https://api.github.com/users/jwalton/following{/other_user}","gists_url":"https://api.github.com/users/jwalton/gists{/gist_id}","starred_url":"https://api.github.com/users/jwalton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwalton/subscriptions","organizations_url":"https://api.github.com/users/jwalton/orgs","repos_url":"https://api.github.com/users/jwalton/repos","events_url":"https://api.github.com/users/jwalton/events{/privacy}","received_events_url":"https://api.github.com/users/jwalton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jwalton/proxyquire","description":"🔮 Proxies nodejs require in order to allow overriding dependencies during testing.","fork":true,"url":"https://api.github.com/repos/jwalton/proxyquire","forks_url":"https://api.github.com/repos/jwalton/proxyquire/forks","keys_url":"https://api.github.com/repos/jwalton/proxyquire/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jwalton/proxyquire/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jwalton/proxyquire/teams","hooks_url":"https://api.github.com/repos/jwalton/proxyquire/hooks","issue_events_url":"https://api.github.com/repos/jwalton/proxyquire/issues/events{/number}","events_url":"https://api.github.com/repos/jwalton/proxyquire/events","assignees_url":"https://api.github.com/repos/jwalton/proxyquire/assignees{/user}","branches_url":"https://api.github.com/repos/jwalton/proxyquire/branches{/branch}","tags_url":"https://api.github.com/repos/jwalton/proxyquire/tags","blobs_url":"https://api.github.com/repos/jwalton/proxyquire/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jwalton/proxyquire/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jwalton/proxyquire/git/refs{/sha}","trees_url":"https://api.github.com/repos/jwalton/proxyquire/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jwalton/proxyquire/statuses/{sha}","languages_url":"https://api.github.com/repos/jwalton/proxyquire/languages","stargazers_url":"https://api.github.com/repos/jwalton/proxyquire/stargazers","contributors_url":"https://api.github.com/repos/jwalton/proxyquire/contributors","subscribers_url":"https://api.github.com/repos/jwalton/proxyquire/subscribers","subscription_url":"https://api.github.com/repos/jwalton/proxyquire/subscription","commits_url":"https://api.github.com/repos/jwalton/proxyquire/commits{/sha}","git_commits_url":"https://api.github.com/repos/jwalton/proxyquire/git/commits{/sha}","comments_url":"https://api.github.com/repos/jwalton/proxyquire/comments{/number}","issue_comment_url":"https://api.github.com/repos/jwalton/proxyquire/issues/comments{/number}","contents_url":"https://api.github.com/repos/jwalton/proxyquire/contents/{+path}","compare_url":"https://api.github.com/repos/jwalton/proxyquire/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jwalton/proxyquire/merges","archive_url":"https://api.github.com/repos/jwalton/proxyquire/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jwalton/proxyquire/downloads","issues_url":"https://api.github.com/repos/jwalton/proxyquire/issues{/number}","pulls_url":"https://api.github.com/repos/jwalton/proxyquire/pulls{/number}","milestones_url":"https://api.github.com/repos/jwalton/proxyquire/milestones{/number}","notifications_url":"https://api.github.com/repos/jwalton/proxyquire/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jwalton/proxyquire/labels{/name}","releases_url":"https://api.github.com/repos/jwalton/proxyquire/releases{/id}","deployments_url":"https://api.github.com/repos/jwalton/proxyquire/deployments","created_at":"2018-03-01T03:27:40Z","updated_at":"2018-03-01T03:27:42Z","pushed_at":"2018-03-01T18:10:49Z","git_url":"git://github.com/jwalton/proxyquire.git","ssh_url":"git@github.com:jwalton/proxyquire.git","clone_url":"https://github.com/jwalton/proxyquire.git","svn_url":"https://github.com/jwalton/proxyquire","homepage":"","size":236,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":0,"default_branch":"master"}},"base":{"label":"thlorenz:master","ref":"master","sha":"d20312e05a84b7b7461d746f3afdcb633236f764","user":{"login":"thlorenz","id":192891,"avatar_url":"https://avatars0.githubusercontent.com/u/192891?v=4","gravatar_id":"","url":"https://api.github.com/users/thlorenz","html_url":"https://github.com/thlorenz","followers_url":"https://api.github.com/users/thlorenz/followers","following_url":"https://api.github.com/users/thlorenz/following{/other_user}","gists_url":"https://api.github.com/users/thlorenz/gists{/gist_id}","starred_url":"https://api.github.com/users/thlorenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thlorenz/subscriptions","organizations_url":"https://api.github.com/users/thlorenz/orgs","repos_url":"https://api.github.com/users/thlorenz/repos","events_url":"https://api.github.com/users/thlorenz/events{/privacy}","received_events_url":"https://api.github.com/users/thlorenz/received_events","type":"User","site_admin":false},"repo":{"id":4878628,"name":"proxyquire","full_name":"thlorenz/proxyquire","owner":{"login":"thlorenz","id":192891,"avatar_url":"https://avatars0.githubusercontent.com/u/192891?v=4","gravatar_id":"","url":"https://api.github.com/users/thlorenz","html_url":"https://github.com/thlorenz","followers_url":"https://api.github.com/users/thlorenz/followers","following_url":"https://api.github.com/users/thlorenz/following{/other_user}","gists_url":"https://api.github.com/users/thlorenz/gists{/gist_id}","starred_url":"https://api.github.com/users/thlorenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thlorenz/subscriptions","organizations_url":"https://api.github.com/users/thlorenz/orgs","repos_url":"https://api.github.com/users/thlorenz/repos","events_url":"https://api.github.com/users/thlorenz/events{/privacy}","received_events_url":"https://api.github.com/users/thlorenz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thlorenz/proxyquire","description":"🔮 Proxies nodejs require in order to allow overriding dependencies during testing.","fork":false,"url":"https://api.github.com/repos/thlorenz/proxyquire","forks_url":"https://api.github.com/repos/thlorenz/proxyquire/forks","keys_url":"https://api.github.com/repos/thlorenz/proxyquire/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thlorenz/proxyquire/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thlorenz/proxyquire/teams","hooks_url":"https://api.github.com/repos/thlorenz/proxyquire/hooks","issue_events_url":"https://api.github.com/repos/thlorenz/proxyquire/issues/events{/number}","events_url":"https://api.github.com/repos/thlorenz/proxyquire/events","assignees_url":"https://api.github.com/repos/thlorenz/proxyquire/assignees{/user}","branches_url":"https://api.github.com/repos/thlorenz/proxyquire/branches{/branch}","tags_url":"https://api.github.com/repos/thlorenz/proxyquire/tags","blobs_url":"https://api.github.com/repos/thlorenz/proxyquire/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thlorenz/proxyquire/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thlorenz/proxyquire/git/refs{/sha}","trees_url":"https://api.github.com/repos/thlorenz/proxyquire/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thlorenz/proxyquire/statuses/{sha}","languages_url":"https://api.github.com/repos/thlorenz/proxyquire/languages","stargazers_url":"https://api.github.com/repos/thlorenz/proxyquire/stargazers","contributors_url":"https://api.github.com/repos/thlorenz/proxyquire/contributors","subscribers_url":"https://api.github.com/repos/thlorenz/proxyquire/subscribers","subscription_url":"https://api.github.com/repos/thlorenz/proxyquire/subscription","commits_url":"https://api.github.com/repos/thlorenz/proxyquire/commits{/sha}","git_commits_url":"https://api.github.com/repos/thlorenz/proxyquire/git/commits{/sha}","comments_url":"https://api.github.com/repos/thlorenz/proxyquire/comments{/number}","issue_comment_url":"https://api.github.com/repos/thlorenz/proxyquire/issues/comments{/number}","contents_url":"https://api.github.com/repos/thlorenz/proxyquire/contents/{+path}","compare_url":"https://api.github.com/repos/thlorenz/proxyquire/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thlorenz/proxyquire/merges","archive_url":"https://api.github.com/repos/thlorenz/proxyquire/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thlorenz/proxyquire/downloads","issues_url":"https://api.github.com/repos/thlorenz/proxyquire/issues{/number}","pulls_url":"https://api.github.com/repos/thlorenz/proxyquire/pulls{/number}","milestones_url":"https://api.github.com/repos/thlorenz/proxyquire/milestones{/number}","notifications_url":"https://api.github.com/repos/thlorenz/proxyquire/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thlorenz/proxyquire/labels{/name}","releases_url":"https://api.github.com/repos/thlorenz/proxyquire/releases{/id}","deployments_url":"https://api.github.com/repos/thlorenz/proxyquire/deployments","created_at":"2012-07-03T23:15:15Z","updated_at":"2018-03-01T13:16:26Z","pushed_at":"2018-03-01T18:11:46Z","git_url":"git://github.com/thlorenz/proxyquire.git","ssh_url":"git@github.com:thlorenz/proxyquire.git","clone_url":"https://github.com/thlorenz/proxyquire.git","svn_url":"https://github.com/thlorenz/proxyquire","homepage":"","size":235,"stargazers_count":1915,"watchers_count":1915,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":84,"mirror_url":null,"archived":false,"open_issues_count":11,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":84,"open_issues":11,"watchers":1915,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190"},"html":{"href":"https://github.com/thlorenz/proxyquire/pull/190"},"issue":{"href":"https://api.github.com/repos/thlorenz/proxyquire/issues/190"},"comments":{"href":"https://api.github.com/repos/thlorenz/proxyquire/issues/190/comments"},"review_comments":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190/comments"},"review_comment":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thlorenz/proxyquire/pulls/190/commits"},"statuses":{"href":"https://api.github.com/repos/thlorenz/proxyquire/statuses/cbceb8fcd612102b600262af523ecf6f28bf8e6f"}},"author_association":"NONE"}}
{"actor":{"display_login":"bendrucker"}}