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

Make providesModuleNodeModules ignore nested node_modules directories #3984

Merged
merged 1 commit into from
Jul 7, 2017

Conversation

ide
Copy link
Contributor

@ide ide commented Jul 7, 2017

Updates the _isNodeModules function so that nested node_modules subdirectories of whitelisted npm packages are not whitelisted. This is causing problems because arbitrary npm packages that aren't explicitly whitelisted can cause Haste map collisions.

Test plan: Added unit tests that were failing before and ensure that they are passing now in addition to older unit tests.

Updates the `_isNodeModules` function so that nested `node_modules` subdirectories of whitelisted npm packages are not whitelisted. This is causing problems because arbitrary npm packages that aren't explicitly whitelisted can cause Haste map collisions.

Test plan: Added unit tests that were failing before and ensure that they are passing now in addition to older unit tests.
@ide ide force-pushed the haste-ignore-node-modules branch from 7592a94 to a77e2d2 Compare July 7, 2017 10:41
Copy link
Contributor

@jeanlauliac jeanlauliac left a comment

Choose a reason for hiding this comment

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

Looks great, thanks. I've only got a little uncertainty about the Regexp usage, lemme know what you think

return !match || match.length > 1;
const whitelist = this._whitelist;
const match = whitelist.exec(filePath);
const matchEndIndex = whitelist.lastIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

Docs says lastIndex stays zero if the regexp doesn't have the g flag. Isn't this a problem? Can we use the result match to figure it out instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The regexp always has the g flag in this case, we control that here: https://github.com/ide/jest/blob/a77e2d255af4fbd7f6057664c3311aed3255b092/packages/jest-haste-map/src/index.js#L107

We could use match[0].length, I think both approaches are good enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return !match || match.length > 1;
const whitelist = this._whitelist;
const match = whitelist.exec(filePath);
const matchEndIndex = whitelist.lastIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jeanlauliac
Copy link
Contributor

I wanted to investigate the breakage in CircleCI, but it loads forever and doesn't show me the error logs. I'll try locally then ship it.

@jeanlauliac
Copy link
Contributor

Tests are passing locally, merging then.

@jeanlauliac jeanlauliac merged commit 1e40f63 into jestjs:master Jul 7, 2017
@ide ide deleted the haste-ignore-node-modules branch July 7, 2017 16:48
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants