fxpio / foxy

A fast, reliable, and secure NPM/Yarn/pnpm bridge for Composer
https://foxypkg.com
MIT License
173 stars 21 forks source link

Install npm dependencies of composer dependency #28

Closed btamas closed 5 years ago

btamas commented 5 years ago

I'm working on a project that has multiple composer dependencies. One of these dependencies has a frontend dependency. When I run composer install on dependency directory, foxy works like a charm. When I run composer install in the project directory, it installs extension as a composer dependency, but npm install runs in the project directory instead of the dependency directory, so package.json file is not found and npm dependencies are not installed. And an empty package.json file appears in the project directory. Is it a not supported feature or my configuration is wrong?

Extension:

composer.json

...
"type": "extension",
"require": {
    "foxy/foxy": "^1.0.0"
},
"config": {
    "foxy": {
        "manager": "npm",
        "manager-options": "--prefix views"
    }
},
...

views/package.json // some npm dependency

Project

composer.json

...
"require": {
    "extension": "^1.0.0"
}
...
francoispluchino commented 5 years ago

The installation of NPM/Yarn dependencies is always in the node_modules folder (by default) of the project folder. It is normal that it is not in the folder of the PHP extension. This is the behavior of NPM and Yarn, and all package managers, because ultimately, these are the dependencies of the project. This avoids duplicate libraries, allows to analyze the dependency tree, check conflicts, etc... and therefore to solve all the dependencies of the project. In addition, if you install the dependencies in the PHP library folder, this will be removed when the PHP library is updated. For more information on how Foxy works, feel free to read the FAQ How does the plugin work?.

You get an empty package.json file because Foxy detects that your composer.json file requires Foxy, but it can not find the package.json file from the PHP library. From what I understand, the package.json file is in the views folder, however, it must be placed in the same folder as the composer.json file.

Regarding your configuration, the config.foxy section is used only for the composer.json file of the project, and not the one of the library (see the doc of config.