yeoman / environment

Yeoman runtime environment
BSD 2-Clause "Simplified" License
127 stars 71 forks source link

Do not throw error for local path resolution #504

Closed strmer15 closed 8 months ago

strmer15 commented 8 months ago

Fixes https://github.com/yeoman/environment/issues/497

When there is a local path for a generator, i.e. ./my-directory/my-generator, the yeoman-environment cannot locate the generator and throws an error saying You don't seem to have a generator with the name undefined installed. I had mistakenly thought that this was because the generator needed to be loaded with @yeoman/namespace, but that's only for package lookups. Instead, the base environment's create function detects that the namespaceOrPath is a string and calls get on it, which in turn uses the resolveModulePath function to find the file.

However, the resolveModulePath function checks if there is a . character in the front of the path and then throws an error if there is not a resolvedOrigin passed into the function. In the case of these local paths, the get function does not pass the resolvedOrigin parameter, so it's undefined.

The fix here is just to remove the else block that is throwing the error - if there is a path with a . in front and no resolvedOrigin, just go ahead and do the lookups further in the function. When I made this change locally in my node_modules folder, it then allowed me to run a generator from a local path.