How to install composer packages in different directories - composer-php

I have installed Composer on Ubuntu server using the global command. I have two folders named folder1 and folder2; both of them have their own composer.json files.
I want to install a package in only a folder. What happens after I edit the required composer.json file and I run composer install?

The dependencies will be installed into the current project directory.
When you run composer install, Composer will read the composer.json file from the current directory and then resolve the dependencies you defined and finally install them into a vendor subfolder.
See https://getcomposer.org/doc/03-cli.md#install
folder1
|- composer.json // <-- dependency "VendorA/PackageA"
|- vendor
|- composer
|- VendorA // <-- lands here after "composer install"
|- PackageA
folder2
|- composer.json // <-- dependency "VendorB/PackageB"
|- vendor
|- composer
|- VendorB // <-- lands here after "composer install"
|- PackageB

Related

wheel pollutes project folder with build & project.egg-info

I use the pip install c:\path\to\project command to install my local package from a pyproject.toml configuration. It works fine and I can also uninstall the package with pip uninstall project. The only thing that makes me unhappy is the project folder being polluted with two extra folders: build & project.egg-info. The same happens when I try to build it with python -m pip wheel . -w .dist. Is there any way to suppress or modify this behavior and keep the project folder clean?
project
|- pyproject.toml
|- project/
| | - test.py
|- build/ <-- extra folder
|- project.egg-info/ <-- extra folder

Update yarn.lock after removing a workspace

Suppose I have a monorepo using the standard workspace structure:
monorepo
|- package.json
|- yarn.lock
|- packages
|- package_a
|- package_b
I want to completely get rid of package_a while also updating the yarn.lock accordingly.
The following doesn't update the lockfile:
$ rm -rf packages/package_a
$ yarn install
Running this in the root of the monorepo doesn't work either:
$ yarn remove -W package_a
error This module isn't specified in a package.json file.
This does work, but bumps all packages where the range allows which is not desired.
$ rm -rf packages/package_a
$ yarn upgrade
How can I accomplish this?
I may misunderstand your question... But it appears that you need to include each package in your package.json as mentioned with each workspace here: https://classic.yarnpkg.com/en/docs/workspaces/.
Needed in package.json:
{
"private": true,
"packages": ["package_a", "package_b"]
}
I'm guessing this is why you are getting the error error This module isn't specified in a package.json file. when attempting yarn remove -W package_a. When it is included in the package.json then just yarn remove package_a this will also update your yarn.lock automatically.
https://classic.yarnpkg.com/en/docs/cli/remove

How can we manage the front-end projects dependency packages like Maven in IDEA

There are more and more front-end projects, and each project has its own node_modules folder.
There are a lot of duplicate files in the modules folder.
How can we manage the dependency packages of all front-end projects in one folder like Maven in IDEA?
Demand:
When running and packaging different projects, WebStorm can refer to the dependent packages in a specified folder.
When run npm install, computer will check whether the public dependency package folder has the dependency version that the current project needs to use.
If so, you will not download the installation.
If not, you will download your own dependency to the public folder.
When multiple versions exist in the same dependent package, the project can automatically reference the correct version.
Maybe after reading my question, you know my actual needs better than I do. Thank you.
If you look in the package.json file in any front-end project with npm you will see all the dependencies in the current project and can manage the versions there. npm install installs the dependencies listed in that file.
Read more about package.json here: package.json
Using the yarn workspace
Yarn workspace features, and solves
multiple projects repeat node in large quantities_ Black hole problem of modules disk
when NPM install is executed for a project, all dependent packages will be placed in the node of the project in the current project_ Install it again under the modules folder
2.1 when installing a new dependency package, you should update the package.json of the subproject, and then execute the yarn install in the root directory to install it
Install the yarn tool first
npm i yarn -g
If there are projects project-a and project-b in the root folder, the directory structure is as follows:
root
project-a
project-b
create package.json in the root folder, with the following contents:
{
"private": true,
"workspaces": ["project-a", "project-b"]
}
ensure that the name attribute values in the package.json of project-a and project-b projects are:
Package.json in project-a:
{
...
"name": "project-a"
...
}
Package.json in project-b:
{
...
"name": "project-b"
...
}
use the command line tool to enter the root folder and execute the yarn install
3.1 after installation, you can enter the normal start-up project
tips:
4.1 all dependent packages will be installed at root/node_ Under modules folder
4.2 node of subproject_ The related link file will be generated under the modules folder, do not delete it
4.3 when installing a new dependency package, you should update the package.json of the subproject, and then execute the yarn install in the root directory to install it

How to generate composer.json from the Laravel vendor directory

Unfortunately, I deleted composer.json and composer.lock, but my vendor folder is intact and has all dependency packages installed. Is there a way to generate composer.json through the vendor folder? Any way to reverse engineer?

Create folder when installing composer package

Is it possible for a composer package to create a folder (or folders) in the root directory of the project?
For example:
/ansible
/application
/public
/composer.json
/composer.lock
I run composer install to install my package (framework).
Can this framework create the folders /logs in my root directory?
You might want to have a look at https://getcomposer.org/doc/articles/scripts.md and check the post-install-cmd event name and supply your own script to create your needed directories.

Resources