Open jelhan opened 4 years ago
Continued my debugging session and noticed that the Project
is not initialized with closestSync
method directly but with projectOrnullProject
static method: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/cli/index.js#L135
It catches the error thrown by findupPath
if no package.json
is found at all. So maybe modifying findupPath
to ignore package.json
found if it contains workspaces
path might be all what is needed?
Ember CLI wrongly assumes being inside an Ember CLI project if
ember-cli
is installed in yarn workspace. When runningember new <app-name>
andember addon <addon-name>
it throwsYou cannot use the new/addon command inside an ember-cli project.
Use case
Installing
ember-cli
in workspace would have some benefits:ember-cli
globally or to usenpx
to create new ember projects.ember-cli
installed in workspace is as fast as if using a globally installed version. It's much faster than usingnpx
.Reproduction
To reproduce create a yarn workspace and install
ember-cli
in it:mkdir test-workspace && cd test-workspace/
package.json
with the following content:yarn add -W ember-cli
mkdir packages
Running
ember new test-app
orember new test-addon
in./packages
fails:Debug
The assertion is thrown here: https://github.com/ember-cli/ember-cli/blob/627934f91b2aa0e19b041fdb1b547873c1855793/lib/models/command.js#L279-L281
The
isWithinProject
method ofCommand
is initialized with return value ofisEmberCLIProject
method ofProject
: https://github.com/ember-cli/ember-cli/blob/627934f91b2aa0e19b041fdb1b547873c1855793/lib/models/command.js#L86The
isEmberCLIProject
method checks ifember-cli
is in dependencies: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/models/project.js#L187-L197The dependencies are read by
dependencies
method: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/models/project.js#L355-L374As no argument is passed it uses
pkg
property, which is passed in when initializing theProject
instance: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/models/project.js#L27-L43If I got the in-source comment right it should only be initialized using the static
closestSync
method: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/models/project.js#L645-L679That one uses the
findupPath
function to find apackage.json
in any parent directory: https://github.com/ember-cli/ember-cli/blob/066e9efc9034e8ddde57151ebf76d35398037c20/lib/models/project.js#L772-L779findupPath
throws if it does not find apackage.json
. But that should be the expected in most cases. :confused: