Skip to content

Handle packages inside another node modules package when auto importing #37561

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

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

sheetalkamat
Copy link
Member

Fixes #37542

if (!moduleFileNameForExtensionless) moduleFileNameForExtensionless = moduleFileToTry;

// try with next level of directory
packageRootIndex = moduleFileName.indexOf(directorySeparator, packageRootIndex + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure I’m understanding this correctly, the idea is:

  1. we’ve located the moduleFileName, say, /project/node_modules/preact/hooks/src/index.js
  2. we look at the structure of the path (as before) to call /project/node_modules/preact the “package root”
  3. we see if moduleFileName is accessible (via a package.json main field) from /project/node_modules/preact
  4. if not, go to step 3 but with one more directory appended to the end (in the first iteration of this case, /project/node_modules/preact/hooks)

As contrasted to the previous behavior, where we’d only try the package root before giving up and using the full moduleFileName (optionally with /index.js taken off the end).

@sheetalkamat sheetalkamat merged commit 84a3252 into master Mar 25, 2020
@sheetalkamat sheetalkamat deleted the packageInsideAnother branch March 25, 2020 23:27
@marvinhagemeister
Copy link

Thank you so much for fixing this 👍

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

Successfully merging this pull request may close these issues.

Import fix creates incorrect URL for symbols from preact/hooks
5 participants