Skip to content

Comments

fix: module not found problem after ask installation#2716

Closed
alexander-akait wants to merge 2 commits intomasterfrom
fix-proble-with-installed-packages-and-require
Closed

fix: module not found problem after ask installation#2716
alexander-akait wants to merge 2 commits intomasterfrom
fix-proble-with-installed-packages-and-require

Conversation

@alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented May 13, 2021

What kind of change does this PR introduce?

bgufix

Did you add tests for your changes?

hard to test, maybe we can use smoke tests for this, I will look

If relevant, did you update the documentation?

No need

Summary

#2667

Does this PR introduce a breaking change?

No

Other information

/cc @rishabh3112 I think it is more clear

@alexander-akait alexander-akait requested a review from a team as a code owner May 13, 2021 15:31
}

return utils.packageExists(packageName);
return packageName;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we don't need check here, because require fails itself if we will have problem.

Before we have require.resolve(package) and then require(), it doesn't make sense, because require call require.resolve internally

Copy link
Member

Choose a reason for hiding this comment

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

Yes , we can skip it as we reach here after successful installation only.

P.S.
I guess this was added here to make sure webpack is avaliable before running CLI (talking about code at bin/cli.js) and as it is not being checked in then block.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see


const result = childProcess.spawnSync(nodePath, [...nodeOptions, '-e', command], { encoding: 'utf8', maxBuffer: 1000 * 1000 * 100 });

return result.status === 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we don't need check error message/path/something else, if it fail we should always try to install, even if something goes wrong we will catch it in require anyway

Copy link
Member

Choose a reason for hiding this comment

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

Yeah you are right. This seems much better check 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Here one bottleneck - perf, before it was fast, no it is not fast due external process, maybe we can cache result, need time to think

Copy link
Member

@sokra sokra May 18, 2021

Choose a reason for hiding this comment

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

Yeah, I also think this isn't the best solution performance-wise.

You can create a very simple lookup solution:

if(process.versions.pnp) return true;
let dir = __dirname;
do {
  try {
    if(fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()) return true;
  } catch(e) { }
} while(dir !== (dir = path.dirname(dir)));
return false;

@alexander-akait alexander-akait deleted the fix-proble-with-installed-packages-and-require branch April 21, 2023 12:49
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.

5 participants