You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node version:14.16.1 (run node --version in your terminal)
npm version:6.14.12 (run npm --version in your terminal)
Version of yo :4.0.0 (run yo --version in your terminal)
Expected behavior
Yo correctly determines tmp (or whatever folder it was first run in) as the project root, and places files correctly even when run from a subdirectory. The subdirectory is not mistakenly marked as a new project root, the subdirectory does not mistakenly include a yo-rc.json itself.
Current behavior
Instead of creating new files in tmp/files, the following file structure occurs
Create a "new" BaseGenerator, which all other generators extend from
Write an initialise function as follows
_initialize() {
const defaults: Config = {
// Some defaults here
}
this.config.defaults(defaults)
}
In each Generator or Subgenerator, call _initialise in the initializing context. Generators create files either with this.destinationRoot or any configuration option in the config
Setup Generator with npm link
Create a directory, we'll call it tmp
Run generator in tmp
Observe it working as intended. Files are created in tmp/files. Config file yo-rc.json is created in tmp, marking project root
Now, create a subdirectory, tmp/subdir
Cd into subdir
Run Generator again
Observe wrong behaviour, as seen above
The text was updated successfully, but these errors were encountered:
@mshima Is there any way to get the intended behaviour? Otherwise, the whole deal with yo-rc.json doesn't seem to make sense to me, or the documentation about it is outdated
I used the solution suggested by @mshima and found an incompleteness: the rootPath value at the end includes the '.yo-rc.json' filename. Consider removing it before passing rootPath to this.destinationRoot, or you will get an error on writing.
Also keep in mind that since version 6.0.0 find-up uses ESM. The last CJS version of it is 5.0.0.
Type of issue: Bug
My environment
MacOs 11.13
14.16.1
(runnode --version
in your terminal)6.14.12
(runnpm --version
in your terminal)4.0.0
(runyo --version
in your terminal)Expected behavior
Yo correctly determines
tmp
(or whatever folder it was first run in) as the project root, and places files correctly even when run from a subdirectory. The subdirectory is not mistakenly marked as a new project root, the subdirectory does not mistakenly include ayo-rc.json
itself.Current behavior
tmp/files
, the following file structure occursSteps to reproduce the behavior
initialise
function as follows_initialise
in theinitializing
context. Generators create files either withthis.destinationRoot
or any configuration option in the confignpm link
tmp
tmp
tmp/files
. Config fileyo-rc.json
is created intmp
, marking project roottmp/subdir
subdir
The text was updated successfully, but these errors were encountered: