fix: module not found problem after ask installation#2716
fix: module not found problem after ask installation#2716alexander-akait wants to merge 2 commits intomasterfrom
Conversation
| } | ||
|
|
||
| return utils.packageExists(packageName); | ||
| return packageName; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
|
||
| const result = childProcess.spawnSync(nodePath, [...nodeOptions, '-e', command], { encoding: 'utf8', maxBuffer: 1000 * 1000 * 100 }); | ||
|
|
||
| return result.status === 0; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Yeah you are right. This seems much better check 😄
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
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