Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module.parent fallback #18

Merged
merged 2 commits into from
Jun 7, 2017

Conversation

DenisCarriere
Copy link
Contributor

@DenisCarriere DenisCarriere commented Jun 3, 2017

Getting an linting error.

Unexpected mix of && and ||.

@sindresorhus Might need some help :)


Fixes #17

@SamVerschueren
Copy link
Contributor

module.parent ? module.parent.filename : '.'

@DenisCarriere
Copy link
Contributor Author

@SamVerschueren That wouldn't catch if module.parent.filename is undefined.

@DenisCarriere
Copy link
Contributor Author

DenisCarriere commented Jun 4, 2017

This would look at lot nicer once Null Propagation Operators is implemented in Javascript.

https://docs.google.com/presentation/d/11O_wIBBbZgE1bMVRJI8kGnmC6dWCBOwutbN9SWOK0fU/view#slide=id.p

module.parent?.filename || '.'

index.js Outdated
@@ -10,7 +10,7 @@ const obj = () => Object.create(null);

// Prevent caching of this module so module.parent is always accurate
delete require.cache[__filename];
const parentDir = path.dirname(module.parent.filename || '.');
const parentDir = path.dirname(module.parent && module.parent.filename || '.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(module.parent && module.parent.filename) || '.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that's way better! Thanks forgot the ( )

@DenisCarriere
Copy link
Contributor Author

@SamVerschueren Fixed this PR

@sindresorhus sindresorhus changed the title Add module.parent fallback #17 Add module.parent fallback Jun 7, 2017
@sindresorhus sindresorhus merged commit 14e8ee8 into sindresorhus:master Jun 7, 2017
@DenisCarriere DenisCarriere deleted the patch-1 branch June 7, 2017 17:35
@DenisCarriere
Copy link
Contributor Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants