-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Bugfix/require module regexp #368
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
Conversation
* handle cases where space occurs before, after and on either side of dep
Awesome, thanks! |
I think the regex should be /\brequire\s*?\(\s*?([\'"])([^"\']+)\1\s*?\)/g and then code.replace(REL_REQUIRE_STMT, function(codeMatch, _, depName) { Even before this diff it already accepted |
👍 updated |
If you updated this, let's update the one in DependencyGraph/index.js as well. Ideally let's export it from DependencyGraph as a a constant to be used here |
Hmm. Maybe I am missing something, but I am facing some issues when I try to export the requireRe regex from DependencyGraph and into DependencyResolver. I changed the requireRe in the DependencyGraph to
Then changed the exports
Then in the DependencyResolver/index.js
The requireRe regex does not seem to be importing properly as you can see in the Jest output. I will keep digging into this. Any help would be appreciated as well! |
…x.js & add note to export it
I changed the requireRe in the DependencyGraph to match REL_REQUIRE_STMT. As noted above, I was having issues when I tried to import regex into the DependencyResolver. As @amasad said, ideally we would export the const, however in the meantime this should provide a fix for the whitespace issues. I can submit another PR later exporting the requireRe when I can look at this code more objectively than I can now. What do you think? |
That's strange, maybe the problem is with jest console.log. Can you try |
This is the output from DependencyResolver/index.js: It does not seem limited to importing from DependencyGraph either. I tried creating a dummy file that exports only that regex and I get the same issue. I also tried exporting some simple regex:
but it seems to get imported as
as well. T.T |
* don't mock regex.js in jest tests
The issue was related to how Jest seems to auto-mock its dependencies (though I am not too familiar w/ Jest). When I tried to export the regex, jest would try to mock it and resulting in that strange looking regex that broke unit tests (even when I tried mocking it as a function that returns the regex). However, I tested the regex exporting manually and it was working just fine. I decided that the regex value should not be mocked in the unit tests. However, keeping this value inside the DependencyGraph/index.js was problematic as we still want to mock the rest of the DependencyGraph when testing the HasteDependencyResolver. Thus, I decided to move the regex value into a separate file that gets imported by both DependencyGraph/index.js & DependencyResolver/index.js allowing me to prevent the value from being mocked using jest.dontMock. I named it regex.js as I thought there may be other regex where sharing across files is desired. The shared regex is now successfully exported and the unit tests are now passing. @amasad thoughts? |
Related to #386 |
That looks good, I'll pull it. |
👍 |
Do we really need to force convert quotation style ( |
@pilwon why do you care about generated code? |
@amasad I agree it doesn't matter for code that is never meant to be read by humans. I imagined more potential complex case similar to and developed from how I implemented #386. The original code passes through multiple replace steps until it reaches the final relativized code. The complexity in this replace pipeline could potentially grow (though it's highly unlikely beyond supporting |
OK, this already landed internally though. @pilwon you can fix it in your "import" syntax pull requests because I haven't looked at it yet. |
Hmm...that explains the merge conflicts lol. I guess there must be a problem w/ Legal when taking PR's from random internet guys ☔ hehe |
@amasad |
Merged internally and synced. |
Summary: Resolves facebook#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome! Closes facebook#368 Github Author: daviskoh <koh.davis.0@gmail.com> Test Plan: ./runJestTests
Summary: Resolves facebook#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome! Closes facebook#368 Github Author: daviskoh <koh.davis.0@gmail.com> Test Plan: ./runJestTests
Summary: Resolves facebook#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome! Closes facebook#368 Github Author: daviskoh <koh.davis.0@gmail.com> Test Plan: ./runJestTests
Summary: Resolves facebook/react-native#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome! Closes facebook/react-native#368 Github Author: daviskoh <koh.davis.0@gmail.com> Test Plan: ./runJestTests
Resolves #316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome!