In my Laravel 5.4 composer.json file I have the following that autoloads my custom package. Note, that this package is not published and is being loaded locally.
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Module\\": "packages/vendor/module/src"
}
},
And then in my package composer.json file I have the following
{
"name": "vendor/module",
"description": "A custom package",
"version": "1.0.0",
"type": "project",
"authors": [
],
"minimum-stability": "dev",
"require": {
"laravelcollective/html": "^5.4.0"
}
}
However, when I run composer install from the root Laravel directory, it never picks up the laravelcollective/html package that I am requiring.
Is there a way to load in dependencies on a local package that is not published?
I believe I found a solution, all though it may not be the best method for local package development it is working for me.
In the root composer.json file, I added the following and running a composer update from the root of the application seems to now pick up the package and it's dependencies and installs everything into the main vendor directory of the root application.
"repositories": [
{
"type": "path",
"url": "packages/vendor/module"
}
],
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7",
"vendor/module": "1.0.*"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Module\\": "packages/vendor/module/src"
}
},
The good thing about this method is it creates a symbolic link only for the custom package, thus you can continue to write updates in the packages directory and the changes will take affect instead of having to commit to your local git repository if you set the type to vcs in the repositories field of the composer.json.
I also had to specify in the require-dev field the version number so that it passes the version constraint, otherwise you would get a warning that the package does not meet the minimum version requirements when running composer.
Related
In my following composer.json I am requiring extensions, which are in the same Git repository as the whole project. So I add in the repositories section and later I do composer req vendor/site_package:#dev in order to require my local extension.
Now I realized, that some classes of the extension are not autoloaded.
Do I need to additional add the autoload part as shown below in the composer.json of the project?
{
"name": "site-package",
"description": "Base composer.json",
"repositories": [
{
"type": "path",
"url": "./packages/*"
}
],
"require": {
"typo3/cms-backend": "^10.4",
"typo3/cms-belog": "^10.4",
"typo3/cms-beuser": "^10.4",
"typo3/cms-core": "^10.4",
...
"vendor/site_package": "#dev",
"georgringer/news": "^8",
...
},
"autoload": {
"classmap": [
"public/typo3conf/ext/site_package/Classes"
],
"psr-4": {
"Vendor\\SitePackage\\": "public/typo3conf/ext/site_package/Classes"
}
},
"extra": {
"typo3/cms": {
"root-dir": "public",
"web-dir": "public"
}
},
"config": {
"vendor-dir": "vendor",
"bin-dir": "bin"
},
"scripts": {
"typo3-cms-scripts": [
"typo3cms install:generatepackagestates",
"typo3cms install:fixfolderstructure"
],
"post-autoload-dump": [
"#typo3-cms-scripts"
]
}
}
In ext:site_package I have the following autoload section as well:
"autoload": {
"psr-4": {
"Vendor\\SitePackage\\": "Classes",
}
},
Do I need both? Why?
You should never mix those 2 composer.json.
As you already follow the approach of having a directory packages (which is a good thing) each extension inside there needs an own composer.json file which of course also needs a section
"psr-4": {
"Vendor\\MyExt\\": "Classes"
}
By requiring this package, this autoload information will be used.
If you would still have the custom extension inside typo3conf/ext/my_ext, that composer.jsonfile would not be taken into account and you need something like
"psr-4": {
"Vendor\\MyExt\\": "typo3conf/ext/myext/Classes"
}
The autoload part is only needed in your site package composer.json. It's not necessary to put it also in the composer.json in your root folder.
Please refer to the documentation how the composer.json of your site package should look like.
If you still have problems with autoloading, try composer dump-autoload or remove the extension and require it again. And make sure to check the upper-/lowercase of your namespace. It's case sensitive. If you change that after you required the site package, you need to remove and require the package again.
I'm trying to create a package to publish in packagist, for this I am using the package level composer.json to install the dependencies.
my package level composer.json is as follow
{
"name": "my-company/my-package",
"description": "Package Desciption",
"authors": [
{
"name": "xxxxx",
"email": "xxxxx#gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"propaganistas/laravel-phone": "^4.1"
}
}
I declare this on my main root autoload in composer.json as follow:
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"MyCompany\\MyPackage\\": "packages/my-company/my-package/"
}
},
when I run the composer install in the root composer.json the child composer.json is not triggered.
finally, I solve this by adding repository block and define the path in the root composer.json and also adding the newly create package name into the require-dev
"repositories": [
{
"type": "path",
"url": "packages/my-company/my-package"
}
],
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0",
"my-company/my-package": "1.0.*"
},
I forked a library on Github and now want to load my fork into the project without adding the forked library into packagist. I get the following error after adding the repository and require to my composer.json:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package cnizzardini/ssl-certificate could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Here is my full composer.json
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "http://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "~3.4",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "*",
"guzzlehttp/guzzle": "^6.2",
"donatj/phpuseragentparser": "^0.7.0",
"cnizzardini/ssl-certificate": "dev-master"
},
"require-dev": {
"psy/psysh": "#stable",
"cakephp/debug_kit": "~3.2",
"cakephp/bake": "~1.1",
"phpunit/phpunit": "^5.5"
},
"suggest": {
"phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
"cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP."
},
"autoload": {
"psr-4": {
"App\\": "src",
"Api\\": "./plugins/Api/src",
"Channel\\": "./plugins/Channel/src",
"System\\": "./plugins/System/src",
"Admin\\": "./plugins/Admin/src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
"Api\\Test\\": "./plugins/Api/tests",
"Channel\\Test\\": "./plugins/Channel/tests",
"System\\Test\\": "./plugins/System/tests",
"Admin\\Test\\": "./plugins/Admin/tests"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/cnizzardini/ssl-certificate.git"
}
],
"minimum-stability": "stable",
"prefer-stable": true
}
I have tried adding https://github.com/cnizzardini/ssl-certificate with and without the .git. I have also tried setting minimum-stability to dev and prefer-stable to false.
Nothing works :-(
The composer.json file on your fork still calls the package "spatie/ssl-certificate", so that's the name of the package you need to require.
This should work:
{
...
"require": {
...
"spatie/ssl-certificate": "dev-master"
},
...
"repositories": [
{
"type": "vcs",
"url": "https://github.com/cnizzardini/ssl-certificate.git"
}
],
...
}
If it doesn't, you can rename the package on your own fork by changing the name property in its composer.json file:
{
"name": "cnizzardini/ssl-certificate",
"description": "A class to easily query the properties of an ssl certificate ",
...
}
I am trying to install laravel Spark but getting a lot of errors no matter which method I try.
Upon adding "laravel/spark": "*#dev" in the composer.js file I am getting this error.
The requested package laravel/spark could not be found in any version,
there may be a typo in the package name.
Any clue what the issue is?
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.",
"laravel/cashier": "~6.0",
"laravel/spark": "#dev"
}
Added to the composer.js file and ran composer update. Got the couldn't found error.
In your composer.json file, add the following to the require section (note that, compared to what you currently listed, this one has an asterisk * before the # symbol):
"laravel/spark": "*#dev"
Then add this in its own section (or update accordingly):
"repositories": [
{
"type": "path",
"url": "./spark",
"options": {
"symlink": false
}
}
],
The options portion is optional and you can leave it out
You can then run your composer install command. You can confirm that things are good by running composer validate, which will trigger a warning and it's fine to ignore that. You should also check the composer.lock file to make sure you have something similar to this in there:
{
"name": "laravel/spark",
"version": "dev-develop",
"dist": {
"type": "path",
"url": "./spark",
"reference": "072b0bf217fbbe5018fc062612bb1fb5566d94e1",
"shasum": null
},
"require": {
"erusev/parsedown": "~1.0",
"firebase/php-jwt": "~3.0|~4.0",
"guzzlehttp/guzzle": "~6.0",
"intervention/image": "^2.3",
"php": ">=5.5.9",
"ramsey/uuid": "^3.1"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"mpociot/vat-calculator": "^1.6",
"phpunit/phpunit": "~5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\Spark\\": "src/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell#gmail.com"
}
],
"description": "Laravel Spark provides scaffolding for Laravel SaaS applications.",
"keywords": [
"billing",
"laravel",
"saas",
"scaffolding",
"stripe"
],
"transport-options": {
"symlink": false
}
},
Also, depending on your version and how you set things up, you'll have to check on the documentation because there's a few different ways to set this up:
https://spark.laravel.com/docs/6.0/installation#installation-via-composer
I'd also add that, you should never modify files in the ./spark directory. All changes are made in either ./resources/assets/js/spark or ./resources/views/vendor/spark (and, as always, you can override anything in the app directory unless you changed the namespace).
Oh, and these commands may be useful for you (obviously turn these into an actual alias or function that's aliased):
alias reset
rm -rf composer.lock node_modules package-lock.json vendor
composer install
npm install
gulp
composer validate
alias update
rm -rf node_modules vendor
composer install
npm install
composer update
npm update
reset
I would only run these as the branch master though, team members shouldn't have to do dependency updates for Composer and npm.
I have composer.json on project:
{
"repositories": [
{
"type": "vcs",
"url": "git#git.test.ua:bmp/composer.git"
}
],
"require": {
"pack/composer": "dev-master"
},
"minimum-stability": "dev"
}
git#git.test.ua:bmp/composer.git - it's my repo, that containe next composer.json file:
{
"name": "pack/composer",
"repositories": [
{
"type": "vcs",
"url": "git#git.test.ua:components/curl.git"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"pack/curl": "dev-master"
},
"autoload": {
"psr-4": {
"pack\\composer\\": ""
}
}
}
git#git.test.ua:components/curl.git - also my repo, that containe next composer.json file:
{
"name": "pack/curl",
"autoload": {
"psr-4": {
"pack\\curl\\": ""
}
},
"minimum-stability": "dev"
}
When I try to do composer install on my project, I receive next error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for pack/composer dev-master -> satisfiable by pack/composer[dev-master].
- pack/composer dev-master requires pack/curl dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
I already add param:
"minimum-stability": "dev"
If I remove require section from the seckond composer.json file the no error any more.
"pack/curl": "dev-master"
How fix it, I need this require?
Update:
{
"repositories": [
{"type": "vcs", "url": "https://git.test.ua/components/composer.git"},
{"type": "vcs", "url": "https://git.test.ua/components/curl.git"}
],
"require-dev": {
"pack/composer": "dev-master"
},
"minimum-stability": "dev"
}
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing pack/composer (dev-master 886d220)
Cloning 886d22082d4aa341731ebd87f280ee0f5a05fe37
Writing lock file
Generating autoload files
Update2 composer.lock file
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is #generated automatically"
],
"hash": "cc5c1fc7000544f6cfd9ba03a3ee4567",
"packages": [],
"packages-dev": [
{
"name": "pack/composer",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://git.test.ua/components/composer.git",
"reference": "886d22082d4aa341731ebd87f280ee0f5a05fe37"
},
"require-dev": {
"pack/curl": "dev-master"
},
"type": "library",
"autoload": {
"psr-4": {
"pack\\composer\\": ""
}
},
"time": "2015-04-24 07:13:31"
}
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"pack/composer": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
Composer does not browse repositories recursively, i.e. ALL repositories that may contain software have to be mentioned in the root composer.json file.
You don't mention the repository of the pack/curl package there, so Composer cannot find this package.
I assume that "pack" is the vendor name you added partially in your question, because the error message still mentions "shkarbatov" as the vendor name.
Best way to avoid having to add hundreds of personal repositories everywhere is to have a packagist-like Composer repo that is mentioned everywhere and contains the metadata of all code repositories. Have a look at Satis.
Update:
Now after seeing your composer.lock file, the situation is clear: You are NOT using require to add your packages, but require-dev. This is for development dependencies (like adding PHPUnit or stuff needed to develop the package) of the root package only - any dev dependencies of packages added to the root package are NOT installed.
Change the dependencies of packages you need for production use to require all levels!