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

Fix module resolution for preval.require #38

Merged
merged 3 commits into from Oct 8, 2017

Conversation

sbekrin
Copy link
Contributor

@sbekrin sbekrin commented Oct 5, 2017

What: path.join -> path.resolve

Why: preval.require won't resolve non-top level paths

How: by updating code which resolves absolute path to module

This PR fixes an issue then using preval.require('../../foo'); for non-top level modules. This results in resolution from incorrect base parent directory and throws Module not found with actually correct (from project root perspective) path, which is super confusing.

@@ -121,7 +119,7 @@ function prevalPlugin({types: t, template, transformFromAst}) {
}
return result.value
})
const absolutePath = p.join(p.dirname(filename), source.node.value)
const absolutePath = p.resolve(p.dirname(filename), source.node.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actual change, rest of the stuff is formatted by prettier I believe

@codecov
Copy link

codecov bot commented Oct 5, 2017

Codecov Report

Merging #38 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #38   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          98     98           
  Branches       20     20           
=====================================
  Hits           98     98
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f25d4ca...2c304cc. Read the comment docs.

@kentcdodds
Copy link
Owner

Thanks! Could you add a test to verify that the bug you found has been fixed and make sure it doesn't come back? 👍

@sbekrin
Copy link
Contributor Author

sbekrin commented Oct 5, 2017

@kentcdodds will do 🙌 Meanwhile, can you suggest most suitable structure for that kind of test? Can't think of anything but creating nested directory in tests.

@kentcdodds
Copy link
Owner

You could do it in fixtures 👍

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.

Super! Thanks!

@kentcdodds kentcdodds merged commit dbd01c0 into kentcdodds:master Oct 8, 2017
@sbekrin
Copy link
Contributor Author

sbekrin commented Oct 8, 2017

That was quick! 👍

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.

None yet

2 participants