Problem/Motivation
Sometimes a Composer command fails or prompts the user. This can usually be avoided by sprinkling some magic over it, for example -s dev or -n. At some point the underlying issue might get fixed, the project structure changes, or something else happens, and the option is no longer needed. But the magic lingers on in the documentation, and on the internet.
Ideally, a Drupal user who is not a Composer expert should now set off some time to study the intricacies of Symfony/Composer, when meeting such a challenge. But the new user simply wants a functioning Drupal installation with the least hassle, so this is often not realistic.
Many new users, who experience too many bumps and stops, while trying to get Drupal up and running, will eventually give up and look elsewhere for a CMS which is not as hard to install.
Proposed resolution
We should strive to remove as many obstacles as possible, to ease Drupal users' usage of Composer, by reducing or entirely removing options such as -s dev, -n, and --prefer-dist.
In #3086498: Parameters at the end in documentation, for better discoverability and legibility it was discussed to use composer create-project together with either --prefer-dist or --no-interaction|-n.
To keep it as simple as possible, no extra Composer options at all is the obvious solution, which actually works just fine.
We might want to add a note below: "NOTE: If for some reason you get a cryptic Composer "Keep/Yes/No/Aways" prompt, perhaps due to some left over .git folders, try adding --prefer-dist at the end of the command".
Remaining tasks
- Make sure there are no conflicts, lingering .git folders, etc. when running
composer create-projectwhich will result in a prompt, by creating a test which runscomposer create-projectwith no options. The command should go straight through, without Composer presenting a "Keep/Yes/No/Always" prompt. Also, a successful test should show the text "Congratulations, you’ve installed the Drupal codebase":
$ composer create-project drupal/recommended-project my-project ... Congratulations, you’ve installed the Drupal codebase from the drupal/recommended-project template! Next steps: .... - Update documentation where pertinent to the leanest possible version, in this case:
$ composer create-project drupal/recommended-project my-project - [Optional Extra Task] Go through other Composer commands (
update,require, etc.) with the ALAP (As Lean As Possible) philosophy, and get rid of options where possible
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
None
Comments
Comment #2
ressaComment #3
hansfn commentedI support this effort 100%. I have tried to do the same in the documentation for the updating Drupal with Composer, but people tend to add fixes for all special cases that often isn't relevant very long.
We should update the issue summary with links to the most relevant documentation page(s).
Comment #4
mmjvb commentedAbsolutely agree on ALAP. Closely related situations should be properly documented. Other stuff should find its way to Troubleshooting Composer for Drupal site.
As the create-project downloads dependencies and default configuration is auto for deciding on source or dist, that should document you might want to remove .git when not doing code development. It causes issues when deploying your site with git. Or prevent it by https://getcomposer.org/doc/06-config.md#preferred-install or --prefer-dist. Very much dislike the language used in IS. It suggests poor understanding and doesn't inform properly.
Comment #5
hansfn commentedSorry, could you explain what "IS" refers to in
I just don't get it ;-)
Comment #6
ressaIS = Issue Summary :-)
Comment #7
mile23The reason Composer does this is not up to Composer, and is really out of scope for the Composer initiative.
It happens because sometimes the dependency needed by Drupal core is one that Composer defaults to using a git repo to provide.
The *solution* to that problem is to add
--prefer-dist. That's why it's currently documented that way: A new user can just copy what the documentation says (currently using--prefer-dist), and hit the fewest roadblocks while also getting the most instructive errors worth taking to a slack channel or something.In the general spirit of this issue, I've added some related issues dealing with the various roadblocks.
Comment #8
mmjvb commentedReferring to
in `Proposed resolution`.
The usage of --prefer-dist should be documented and also point to the config option preferred-install. It shouldn't be in a `Note` as it is not something special.
The usage doesn't address everything and every possible situation. As you can see in the symfony/console documentation the order of options and parameters are not relevant. Only the order within the parameters are relevant. So, it is very much allowed to add options at the end. Very convenient when using options like --dry-run, --no-install, --no-update, -v, -vv, -vvv, --profile. Much easier to swap those options when they are at the end of the command.
Disagree on being out of scope of the Composer initiative, it should be in scope. It is ok not being in phase 1, needs to be addressed in later phases.
Comment #9
mile23Ok, we're talking about this sentence from the IS:
1) Excellent idea to have a test that builds the project. That issue is here: #3086644: LegacyProject composer templates wrongly reference 8.x + fix test coverage
2) Having a .git folder in a dependency in the vendor folder isn't a problem. In fact, that's just how you get some packages that you might need.
In the past, Drupal core has sometimes tied its needs on a specific commit of an external package (drupal/coder comes to mind). A package with a version like that can't be installed any other way than using a repo.
This would not be a UX issue at all, because normally Composer will just remove the repo if it needs to. But we in Drupal-world have the drupal/core-vendor-hardening plugin (and previously the vendor cleanup script) which modifies repos by deleting their test directories (for security reasons). Because we modify repos in the vendor directory, Composer then asks the user about it whenever it needs to change things. If our plugin hadn't modified it, Composer would just remove it.
So, in that case, Drupal core had specific dependency needs for drupal/coder, and users had specific site security needs, and that combination yielded a UX that was less than idea because that's just how Composer works. All as a consequence of allowing the vendor directory in the docroot. :-) One way to never, ever see that modified-git prompt is to use
--no-interaction, which is generally a not-great solution. Or don't use drupal/core-vendor-hardening, which leaves you open to SA-CORE-2017-001. Note that drupal/recommended-project doesn't use that plugin, since it stores vendor/ outside the docroot.It's entirely within the scope of the Composer Initiative to do all the things that reduce the headache factor of Drupal and Composer. And also to make sure the documentation is readable, and honor the Principle of Least Surprise. But it's not within the scope of the Composer Initiative to make sure that Composer never prompts you. It's the kind of promise no one can make.
Comment #10
mmjvb commentedCouldn't agree more, very well formulated. Thanks for elaborating.
Comment #11
greg.1.anderson commentedI removed the `--prefer-dist` option from the page Using Composer to Install Drupal and Manage Dependencies.
Comment #12
ressaThanks @greg.1.anderson. Just to explain the reason, here is the comment posted in Using Composer to Install Drupal and Manage Dependencies:
So in other words, no options are needed now, and the leanest possible version is the recommended method?
$ composer create-project drupal/recommended-project my-projectComment #13
greg.1.anderson commented@ressa: Well, it's a little complicated.
The options that are specified at `create-project` are used to select the version of drupal/recommended-project that will be downloaded. After the first run, the settings from whatever is inside the composer.json from the downloaded project. The actual behavior of Composer is a little confusing. Let's break it down with an example.
Suppose you run
composer create-project drupal/recommended-project --prefer-sourcetoday (at the time this comment was written).composer update, there's still prefer-source in the top-level composer.json file, but Composer remembers that --prefer-source was in effect when the vendor directory was composed, so no packages are changed (you still have sources)composer install, then Composer will use the prefer-source from the top-level composer.json file, and you will get dist (downloaded tarballs) packages in your vendor directoryThis is all a little complicated for an introductory document, so I thought it was better to gloss over the details and just advise folks to fall back on the default behavior.
Comment #14
ressaThanks for explaining the reasoning behind recommending the default commands @greg.1.anderson. You're absolutely right, it's fairly complicated stuff.
Comment #18
ressaSince
composer create-project drupal/recommended-project my-projecthas been working flawlessly for a few years now, I would say this issue has been fixed.Thanks to everybody here who participated in making
composer create-projectin Drupal ALAP :-)