TL;DR: Should I use @dev
or dev-main
in my composer.json
for local packages?
In our project we have a central composer.json
which includes all the dependencies needed including local ones – code included in the git repo but isolated out as a separate composer packages.
We have a local folder set up as a repository:
{
"repositories": [
{
"type": "path",
"url": "./app/*/*"
}
]
}
I read somewhere that we should include the dependencies with the @dev
syntax – e.g.
{
"require": {
"app/local": "@dev"
}
}
However, this stores the current branch in the composer.lock
, so when a feature branch gets merged, the lock file references a non-existent branch until the next composer update
is run. Is this ok?
I like the idea of @dev
as it signifies which packages are local, but I don’t like that a non-existent branch could be referenced.
2
Answers
According to The composer.json schema:
If you are working with production build I would lock the package to certain branch and hash. In this case consider using Semantic Versioning.
Hope this helps!
You are mixing different concepts, that do have some overlap, but that ultimately mean different things.
This is wrong. The meaning of
@dev
is a "stability flag"The complete package link form is "[constraint][@stability flag]".
With the syntax
You are simply saying:
"I don’t care for the specific version for this package, install whatever available or dictated by other constraints; but the minimum stability for this package is "dev", instead of whatever minimum stability I had rest for the rest of the project".
If you use:
… then you are specifying an actual version constraint.
(Additionally, since the version constraint starts with
dev-
, composer will automatically infer that the minimum stability for this package is@dev
, so it will understand this constraint as:foo/package:dev-main@dev
).TLDR: You should very probably use actual version constraints. Stability flags do not do what you think they do. There are cases for simply specifying a stability flag without a version constraint in your package, but that’s generally just to override the project’s minimum stability for a single required package.