{"action":"created","issue":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/652","labels_url":"https://api.github.com/repos/keystonejs/keystone/issues/652/labels{/name}","comments_url":"https://api.github.com/repos/keystonejs/keystone/issues/652/comments","events_url":"https://api.github.com/repos/keystonejs/keystone/issues/652/events","html_url":"https://github.com/keystonejs/keystone/issues/652","id":43858600,"number":652,"title":"keystone should not be sensitive to module.parent","user":{"login":"indexzero","id":4624,"avatar_url":"https://avatars.githubusercontent.com/u/4624?v=3","gravatar_id":"","url":"https://api.github.com/users/indexzero","html_url":"https://github.com/indexzero","followers_url":"https://api.github.com/users/indexzero/followers","following_url":"https://api.github.com/users/indexzero/following{/other_user}","gists_url":"https://api.github.com/users/indexzero/gists{/gist_id}","starred_url":"https://api.github.com/users/indexzero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indexzero/subscriptions","organizations_url":"https://api.github.com/users/indexzero/orgs","repos_url":"https://api.github.com/users/indexzero/repos","events_url":"https://api.github.com/users/indexzero/events{/privacy}","received_events_url":"https://api.github.com/users/indexzero/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/keystonejs/keystone/labels/bug","name":"bug","color":"eb3d31"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-09-25T05:20:04Z","updated_at":"2015-01-25T12:40:46Z","closed_at":null,"body":"This is a problem we encountered recently:\r\n\r\n**bin/some-file.js**\r\n``` js\r\nvar Schema = require('../schemas/some-schema'),\r\n      keystone = require('keystone');\r\n\r\n// Where there is a ../models directory\r\nkeystone.import('../models');\r\n```\r\n\r\n**schemas/some-schema.js**\r\n``` js\r\nvar keystone = require('keystone');\r\n\r\n/* Other code is irrelevant */\r\n```\r\n\r\nThis caused the `keystone` module to have a parent that was different than our other main `index.js` script which because of [this code](https://github.com/keystonejs/keystone/blob/master/index.js#L14-L24) made many `keystone` helpers impossible to use until we reordered the requires.\r\n\r\nThis is a very subtle and very important bug because most novices will have absolutely no idea what is going on. You should not be using `module.parent`, but instead have some way to configure this that is required on setup to be  __the project root.__ Otherwise all of your requires can be borked for no reason just because of a different `require` ordering."},"comment":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/comments/71370905","html_url":"https://github.com/keystonejs/keystone/issues/652#issuecomment-71370905","issue_url":"https://api.github.com/repos/keystonejs/keystone/issues/652","id":71370905,"user":{"login":"JohnnyEstilles","id":5514878,"avatar_url":"https://avatars.githubusercontent.com/u/5514878?v=3","gravatar_id":"","url":"https://api.github.com/users/JohnnyEstilles","html_url":"https://github.com/JohnnyEstilles","followers_url":"https://api.github.com/users/JohnnyEstilles/followers","following_url":"https://api.github.com/users/JohnnyEstilles/following{/other_user}","gists_url":"https://api.github.com/users/JohnnyEstilles/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnnyEstilles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnnyEstilles/subscriptions","organizations_url":"https://api.github.com/users/JohnnyEstilles/orgs","repos_url":"https://api.github.com/users/JohnnyEstilles/repos","events_url":"https://api.github.com/users/JohnnyEstilles/events{/privacy}","received_events_url":"https://api.github.com/users/JohnnyEstilles/received_events","type":"User","site_admin":false},"created_at":"2015-01-25T12:40:46Z","updated_at":"2015-01-25T12:40:46Z","body":"@alanshaw, I personally don't consider this a code small, but that's just my opinion. I sincerely do not believe this is a symptom of a deeper issue in our code base, IMHO. \r\n\r\nSuggesting that making the minor changes I suggested in order to make your code testable is \"restructuring your app\" is a bit of an overstatement. I was just trying to give you a temporary solution while we implement a more permanent one. \r\n\r\nThe changes I'm proposing will make Keystone \"configurable\" as per your suggestion. Please bear with us while we make the required changes. \r\n\r\nI do agree that we should update the yeoman generator to make the generated Keystone app testable out of the box. \r\n\r\nI will be submitting PR with suggested corrections for both of these issues within then next couple of days (unless someone beats me to it). :-)"}}