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

feat(resolve): add fallback path to be able to resolve modules relatively to babel-plugin-macros #138

Merged
merged 2 commits into from
Dec 1, 2019

Conversation

wintercounter
Copy link
Contributor

What: #87

Why: In case you have babel-plugin-macros loaded outside of process.cwd() it cannot resolve modules realtively to itself.

How: Added the node_modules folder including babel-plugin-macros as a fallback path.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Interesting. I'm curious what your use case is.

return resolve.sync(source, {basedir})
return resolve.sync(source, {
basedir,
paths: [p.resolve(__dirname, '../../')]
Copy link
Owner

Choose a reason for hiding this comment

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

Should we include process.cwd() in this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because it is a fallback only. If it cannot resolve relatively to basedir using node's built in resolve mechanism, then it tries with the provided paths as well (in the fallback case there is no travesing up to the parent, that's why ../../ is necessary).

I was using with process.cwd() included tho, but removing it didn't cause any issues. That case can only happen if plugin is installed outside of cwd and basedir is also not with-in cwd, which is highly unlikely imo. Should I add it just for safety?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My use case is that I have my devtools globally installed, so at project level I basically don't have any node_modules folder. This means babel-plugin-macros also being installed globally.

Copy link
Owner

Choose a reason for hiding this comment

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

That's pretty odd. But as this doesn't break anything I'm fine with it.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thank you!

@kentcdodds kentcdodds merged commit 2cac571 into kentcdodds:master Dec 1, 2019
@kentcdodds
Copy link
Owner

@all-contributors please add @wintercounter for code

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @wintercounter! 🎉

@wintercounter
Copy link
Contributor Author

Any ETA on the release?

@kentcdodds
Copy link
Owner

Sorry, there appears to be a problem with the build/release. Will try to resolve as soon as possible.

@kentcdodds
Copy link
Owner

🎉 This PR is included in version 2.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants