How to change default vendor name for "composer init" command - composer-php

I have an issue when I create a new composer package.
For instance when I start creating the package, I create an empty folder and then I run composer init.
Then, Composer propose me already a default value for the Package name.
In this case:
Package name (<vendor>/<name>) [namesurname/testdirectory]
But since in Github my username has a - in between. I need to change my vendor name from namesurname to name-surname.
I'm checking on the composer documentation if there is a setting in the composer configuration to change the vendor name but I cannot find anything about.
How can I change it?

You may use COMPOSER_DEFAULT_VENDOR environment variable to set default vendor name:
export COMPOSER_DEFAULT_VENDOR=name-surname
composer init
You may add export COMPOSER_DEFAULT_VENDOR=name-surname to your .bashrc to make it permanent.
AFAIK it is undocumented, but it was implemented in this PR.

Related

Laravel - Why laravel ask to rename .env.example to .env while .env already exist?

In Laravel 6 Documentation second paragraph of Application Key written like this
Typically, this string should be 32 characters long. The key can be
set in the .env environment file. If you have not renamed the
.env.example file to .env, you should do that now. If the application
key is not set, your user sessions and other encrypted data will not
be secure!
Why did they ask to rename it? I also found this paragraph in the Laravel older version. Is there any difference between those since they have the same content but different name?
If you've install Laravel using composer command.
composer create-project laravel/laravel projectname
you don't need renamed the .env.example file to .env. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command.
If you clone project using git clone some folder is ignored by git so you might not get env file as well as vendor folder. Therefore, they will have to manually enter php artisan key:generate for their app to function correctly.
More info SO answer
Laravel need to use .env file to define a database connection, some general setting like application key as well. So if you have no .env file, your Laravel has not a setting for now.
Like they said, If the application key is not set, your user sessions and other encrypted data will not be secure! You need to create / copy /remove the .env.example to the new .env for this reason. for letting our Laravel knows about general config.
By the way, do not use the .env.example like copy-and-paste because it's an example. you need to change the value config to your own.
The simplest way is move it on your server with Filezilla or another FTP program. Rename file, and re-download it on your computer. It works for me last time :)
The .env.example the file is just an example of the .env file. It is not used by the app. It is used to serve as a base for you to edit and rename.
In a fresh Laravel installation, the root directory of your application will contain a .env.example file. If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.

How to get pnpm store directory

Is there any way how to check directory/path of pnpm store?
I know you can set it with npm config set store /path/to/.pnpm-store, but npm config get store in my case returns undefined, which I guess means to pnpm to use some default, but where can I find this default value?
Nowadays you can do
pnpm store path
which, according to pnpm's documentation:
Returns the path to the active store directory.
The default locations of the store are:
If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
On Windows: ~/AppData/Local/pnpm/store
On macOS: ~/Library/pnpm/store
On Linux: ~/.local/share/pnpm/store
Related docs: https://pnpm.io/npmrc#store-dir
Seems like as of v3.0.1, you cannot get it. pnpm should probably update pnpm get store so that it returns the default location.
As of v3, the pnpm store is located at ~/.pnpm-store by default.
You could also open the file node_modules/.modules.yaml in your project. It will contain a field called "store" with the location of the store that was used to hardlink packages to your project.
Update 2022:
As of v7, refer to #renardesque's or #nouvist's answer's below.
previously, pnpm store is located on user home folder.
Linux : ~/.pnpm-store
Windows : C:\Users\YOUR_NAME\.pnpm-store
macOS : ~/.pnpm-store
but from now on (v7.0.0), pnpm store is located on different folder. it will located on $XDG_DATA_HOME on Linux, and %LOCALAPPDATA% on Windows. take a look to this issue.
Linux : ~/.local/share/pnpm/store (default)
Windows : C:\Users\YOUR_NAME\AppData\Local\pnpm\store
macOS : ~/Library/pnpm/store
or, you can check where is located with pnpm store path command
Possible locaiton:
~/.pnpm-store
If project is on the same partition as user home.
$partition_root/.pnpm-store
If project is on different partition as user home.
Why not just use ~/.pnpm-store:
On linux/mac, pnpm use hard link to reuse file.
And hard link, can be created only on the same partition.

Initializing default ignored vendors/app.php after checkout/clone

The .gitignore is configured to ignore /vendor/*.
When I checkout the code on another machine, the vendors are missing. How do I initialize them into this other machine?
How about the default initialization of app.php (SALT for instance)?
Per #ndm's comment, simply run the following in your working copy:
composer install

Laravel 5 package installation

I want to install a laravel package but don't have any idea how to do it.
It is the Admin Architect package that I want to install.
http://docs.adminarchitect.com/Getting_Started
This is the getting started page, if you scroll down to Zip archive (Public way) you will see the installation.
They say that you have to extract it in the package directory. But I do not have a package directory in my laravel 5.1 project.
Does someone know if you have to make one and put all the files that I have in there?
You need to start at the Via Zip archive (Public way) section.
The way to do this is completely up to you. The best way is probably to create a packages folder in your main Laravel directory along with app, bootstrap, database directories etc...
Unzip the contents of the zip package and then add the required item to your repositories in your composer.json
"repositories": [
...
{
"type": "git",
"url": "./packages/administrator"
}
...
]
This will add the repository which contains the package terranet/administrator as long as the url is correct. You might have to modify it to get it to work correctly so that when you run composer require terranet/administrator, it will be able to actually find terranet/administrator from the repository.
From there, simply follow the rest of the instructions (adding the service provider, etc...).
The reason other answers are not working is because the package terranet/administrator is not available publicly and you need to add the repository to your composer.json file for that to become availble. You can see all packages available publicly by going to packagist.org where you will see searching for this package yields some results but not the one you are looking for.
I don't know if you missed the instruction on the documentation:
Open your terminal:
cd yourproject
then run:
composer require terranet/administrator
Add service provider in config/app.php file.
'providers' => [
...
Terranet\Administrator\ServiceProvider::class
]
Run this command to publish assets:
php artisan vendor:publish
OR
php artisan vendor:publish --provider=Terranet\\Administrator\\ServiceProvider to publish only administrator's files.
Optionally to create new administrator user run:
php artisan administrator:create
Finally open config/administrator.php and make settings
If you have composer installed you could run the following from your program directory:
composer require terranet/administrator
After the package installed, add a new service provider to the providers array in config/app.php file.
'providers' => [
...
Terranet\Administrator\ServiceProvider::class
]
Then, publish package's assets by running:
php artisan vendor:publish
OR
php artisan vendor:publish --provider=Terranet\\Administrator\\ServiceProvider
to publish only administrator's files.
Optionally you can run
php artisan administrator:create
to create new administrator user ->All this taken from the link you provided.
Update
The problem with minimum stability can be fixed using this link for reference:
Tell composer you want to use stable whenever possible:
"minimum-stability": "dev",
"prefer-stable" : true
This basically means it will always use stable UNLESS there is no way to install a stable dependency, and therefore use dev.

Set owner/user of package when using composer from root

I have composer installed globally on my server.
I have several different domains/accounts on this server.
As root i can ssh onto the server an can use composer to update packages.
However every packages then has the owner and user of root:root.
When i log in as the account owner I then have insufficient rights to access any of the packages if i need to alter something inside the package.
Is there any way to run composer update and set the user/owner to the account holder other than setup ssh on a per account level?
Many thanks.
I'd say that if you need to be root to deploy software, then you are doing something wrong.
Composer is no deployment tool, it's a dependency manager. And that's what it does: It will download the required software packages and unzip them to the file system - as the user account that is running the install command.
If you want to change that, you have several options, amongst them things like:
su
sudo
set group id flag on the directory (chmod g+s)
collect the files outside the server and put them into place via SCP/SFTP/FTPS as the correct user
not change the dependencies' code as that user, only configuration files
... etc.

Resources