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.
Fixes https://github.com/yeoman/environment/issues/497
When there is a local path for a generator, i.e.
./my-directory/my-generator
, theyeoman-environment
cannot locate the generator and throws an error sayingYou 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'screate
function detects that thenamespaceOrPath
is astring
and callsget
on it, which in turn uses theresolveModulePath
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 aresolvedOrigin
passed into the function. In the case of these local paths, theget
function does not pass theresolvedOrigin
parameter, so it'sundefined
.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 noresolvedOrigin
, just go ahead and do the lookups further in the function. When I made this change locally in mynode_modules
folder, it then allowed me to run a generator from a local path.