Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional parameter to run config.set() and config.save() in an explicit directory. #1186

Closed
jblevins1991 opened this issue Mar 5, 2020 · 2 comments
Labels
needs triage Awaiting triage

Comments

@jblevins1991
Copy link

jblevins1991 commented Mar 5, 2020

Explanation

I finished writing my first generator the last night and realized that one of two behaviors is happening with this.config.set(). I have not had the time to research what is truly happening yet and will do so later tonight after I have researched.

config.set() behaviors:

  • the config.set() overrides .yo-rc.json files in the current working directory
  • the config.set() does not override .yo-rc.json files in the current working directory AND it does not tell you that there is an existing .yo-rc.json file.

Proposed solution

If we can explicitly set a directory path for our .yo-rc.json file to be written to, we can void both of these terrible user-experiences. Yeoman should never not write the file, but it also should never override an existing one. This would also solve issues for monorepos, where you want your generator to create the directory in /packages, but cannot write the .yo-rc.json file to that directory. Instead you are forced to copy the config file to the right package.

Will do more research later tonight and make necessary updates and provide POC if necessary.

@jblevins1991 jblevins1991 added the needs triage Awaiting triage label Mar 5, 2020
@mshima
Copy link
Member

mshima commented Mar 7, 2020

The config attribute is destinationRoot aware.
So if you call this.destinationRoot('foo/bar');, then the .yo-rc.json will be written on that path.
https://yeoman.github.io/generator/Generator.html#destinationRoot

But be aware that most methods uses destinationPath which uses destinationRoot and there are others side effects like setting env.cwd:
https://yeoman.github.io/generator/index.js.html#line956
https://yeoman.github.io/generator/Generator.html#destinationPath

As an alternative you could call:
this.config = this.createStorate('some/custom/yo/path', 'some-custom-namespace');
But it will be destinationPath aware on the future.
#1187

@mshima
Copy link
Member

mshima commented Mar 8, 2020

Closing.
If you have another proposal, feel free to reopen.

@mshima mshima closed this as completed Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Awaiting triage
Projects
None yet
Development

No branches or pull requests

2 participants