Premise: When a new Angular 2+ project is created using the Angular CLI NPM package, a local copy of the CLI is added as a dev dependency to the project: this ensures that when the CLI is used again to add some more elements to the project, the original version - which is installed locally - of the CLI is used even if the globally installed version has been updated in the meantime.
SPFX based projects are most of the time created using the Yeomand based generator provided by Microsoft (@microsoft/generator-sharepoint) or the community maintained PNP one (@pnp/spfx). In both cases, the results of the seeding process is a project with the correct dependencies, folder structure and files for that specific version of the generator.
Microsoft releases new version of the generator quite often. It is not uncommon for a new version of the generator to introduce new features (for example, recently beta support for search extensions was added) - for that reason, newer versions of the generator often also update the version of the depending packages (React, the ui-framework etc).
It is not uncommon as a dev to have to maintain multiple different projects that were created using different versions of the generators. This can result in severe problems: if a generator is run on an existing project - for example to add a new web part - the currently installed version of the generator is used. Obviously, this means that the new generator will uses templates whose dependencies will not match the original ones.
Since it is not always possible to update the old projects to the new dependencies set, I started looking for a way to run an old version of a generator on a project without having to constantly switch the currently installed version.
Sadly, contrarily to what Angular does with the Angular CLI, apparently there is no way to install a Yeoman generator to be used only "locally" in a specific project. Therefore, when Yeoman is used, only globally installed generators are available, with no ability to chose a specific generator version.
Is there a workaround for this? How can one invoke an old version of a Yeoman generator when a new version of the generator has already been (globally) installed?