Problem/Motivation

In #3086081: Name of composer:scaffold command is awkward, we propose changing the name of the scaffold command from composer:scaffold to drupal:scaffold. If we do this, it would also be good for consistency to rename the key for the Scaffold extra data and the pre and post scaffold command identifiers to match.

The existing drupal-composer/drupal-scaffold plugin has the following definitions:

  const PRE_DRUPAL_SCAFFOLD_CMD = 'pre-drupal-scaffold-cmd';
  const POST_DRUPAL_SCAFFOLD_CMD = 'post-drupal-scaffold-cmd';

Maintaining these constants would mean less effort for any client using these events. This is uncommon.

Proposed resolution

Change the key in the "extra" section from "composer-scaffold" to "drupal-scaffold".

Change the pre and post command identifiers from pre-composer-scaffold command to pre-drupal-scaffold command, and post-composer-scaffold-command to post-drupal-scaffold command.

Remaining tasks

Consider in concert with #3086081: Name of composer:scaffold command is awkward.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

tbd.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson created an issue. See original summary.

hussainweb’s picture

Status: Active » Needs review
FileSize
26.07 KB

I was initially going to suggest doing this in #3086081: Name of composer:scaffold command is awkward itself, but then I saw the number of files we have to change. I think a separate issue makes sense. Here's the first attempt.

Also, the change makes sense and it is better to do it now rather than after 8.8.x release when it will be much more difficult to change.

hussainweb’s picture

The documentation at https://www.drupal.org/docs/develop/using-composer/using-drupals-compose... should be updated once we commit this or just before.

hussainweb’s picture

The Drupal tests are passing but composer tests don't pass because it loads the scaffold plugin from here: https://github.com/drupal/core-composer-scaffold. How do we get past this failure?

The only idea I have is to define a path repository in those composer.json files, but I am not sure if that is an acceptable approach. It may not be acceptable if those composer.json is meant to be a template for users and not only for the testing script.

hussainweb’s picture

Another idea is that we make it support both composer-scaffold and drupal-scaffold for now (in this issue or a new one). Once that change is committed and mirrored in the Github repo, we can test this patch again.

hussainweb’s picture

Created #3086201: Support "drupal-scaffold" as the key for scaffolding plugin for the approach I mentioned in #5. I guess we should mark this as postponed on that issue unless there are other ways to do this?

greg.1.anderson’s picture

Oh, I fixed that in #3084369: Look up scaffold [web-root] from installation location of drupal/core, but that issue got postponed. You can compare my technique to yours; sounds like you might have done the same thing.

hussainweb’s picture

@greg.1.anderson, it doesn't look like that. All I am doing is having an alternate of "drupal-scaffold" along with "composer-scaffold". It's just a few lines change.

greg.1.anderson’s picture

I only had a couple of minutes online when I posted #7, and wanted to draw your attention to that other issue in case it was helpful. I did so without reading the background here. I will do that now.

greg.1.anderson’s picture

I'll roll a new patch to fix the tests here. I'll do it right now, if I can finish in a few minutes.

greg.1.anderson’s picture

Here's a fix to the tests that will hopefully get us a pass.

hussainweb’s picture

Nice one. But I think you missed the patch. :)

Maybe we should be doing this for all Drupal repositories? Also, will this add the scaffold path repository at the top? I believe composer checks for a package in the order it is listed in the repositories key.

hussainweb’s picture

Nevermind my last comment. I believe Composer checks the official packagist last, so this should work (once you upload the patch as well).

greg.1.anderson’s picture

Whoops, here's the patch.

I think that Packagist has lowest priority, so I don't think it matters where we put our path repository.

If we actually were going to run tests on the site we install, then we'd want to do the same with drupal/core et.al.; let's put that off until we're using #3031379: Add a new test type to do real update testing, though.

greg.1.anderson’s picture

I found one more instance of 'composer-scaffold' in a comment.

The next big question is, do we also want to rename the component itself from drupal/core-composer-scaffold? This is a more difficult change because it involves the subtree split. I suppose we could leave it as-is, under the assumption that the full name of the plugin is "Drupal Core Composer Scaffold" aka "Drupal Composer Scaffold" aka "Drupal Scaffold".

Mixologic’s picture

  1. +++ b/composer.lock
    @@ -716,7 +716,7 @@
    -                "symfony/psr-http-message-bridge": "^1.0",
    +                "symfony/psr-http-message-bridge": "^1.1.2",
    

    Why is this updating?

  2. +++ b/composer.lock
    @@ -845,13 +845,13 @@
    +                        "[project-root]/.editorconfig": "assets/scaffold/files/editorconfig",
    +                        "[project-root]/.gitattributes": "assets/scaffold/files/gitattributes",
                             "[web-root]/.csslintrc": "assets/scaffold/files/csslintrc",
    -                        "[web-root]/.editorconfig": "assets/scaffold/files/editorconfig",
                             "[web-root]/.eslintignore": "assets/scaffold/files/eslintignore",
                             "[web-root]/.eslintrc.json": "assets/scaffold/files/eslintrc.json",
    -                        "[web-root]/.gitattributes": "assets/scaffold/files/gitattributes",
    

    Are these changes a result of the [project-root] patch, that should have also updated the lock file?

  3. +++ b/core/tests/scripts/test_composer_project_templates.sh
    @@ -34,11 +34,13 @@
    +composer --working-dir="${SOURCE_DIR}/composer/Template/RecommendedProject" config repositories.scaffold path '../../Plugin/Scaffold'
    ...
    +composer --working-dir="${SOURCE_DIR}/composer/Template/LegacyProject" config repositories.scaffold path '../../Plugin/Scaffold'
    

    Are these fixing something with the tests?

+++ b/composer/Plugin/Scaffold/Handler.php
@@ -24,12 +24,12 @@ class Handler {
+  const PRE_COMPOSER_SCAFFOLD_CMD = 'pre-drupal-scaffold-cmd';
...
+  const POST_COMPOSER_SCAFFOLD_CMD = 'post-drupal-scaffold-cmd';

I think these were supposed to be renamed to PRE / POST_DRUPAL_SCAFFOLD_COMMAND.

If so, ensure to rename their usages too in line 151/180

Otherwise this is sensible and a better DX overall.

greg.1.anderson’s picture

1. I don't know, but we can re-do the composer.lock to avoid these updates, I think.

2. Yes.

3. These changes cause the tests to run against the code in the Scaffold plugin in the current patch. Without these lines, then the tests run against the last packaged version of the Scaffold plugin from Packagist, which is not useful.

I can make a new patch with #1 and POST_DRUPAL_SCAFFOLD_COMMAND in an hour or two, if someone else doesn't pick it up before then.

Mixologic’s picture

Would be nice to add a followup to convert #3 into one of the new build tests.

greg.1.anderson’s picture

#18: I think this is already covered by https://www.drupal.org/project/drupal/issues/2984031#comment-13289494. I'll add #2984031: Create Build Tests For Composer and Drupal as a follow-up of this issue.

greg.1.anderson’s picture

I looked into "symfony/psr-http-message-bridge": "^1.1.2",; it turns out that this is in core/composer.json now, but the commit that modified it did not update the drupal/core project in the composer.lock file. I think we should just leave this in here and let the lock file for drupal/core get brought up-to-date. We'll have to re-roll if some other patch does this as well, though.

greg.1.anderson’s picture

Here's patch with an update to the pre and post scaffold hook constants.

Mixologic’s picture

Status: Needs review » Reviewed & tested by the community

Great. This is much more betterer.

hussainweb’s picture

Regarding #16.1, the reason is the same as point 2 over there. I verified this by checking the package in core/composer.json as well.

hussainweb’s picture

Okay, I should have read the whole thread before commenting. This was already explained. :)

greg.1.anderson’s picture

Reroll against latest HEAD of 8.8.x.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Ok, looks like this is just some straight-forward renaming along the lines of #3086081: Name of composer:scaffold command is awkward.

Except for these two hunks, that is:

diff --git a/core/tests/scripts/test_composer_project_templates.sh b/core/tests/scripts/test_composer_project_templates.sh
index 0d32ec90c5..620f6ad29d 100755
--- a/core/tests/scripts/test_composer_project_templates.sh
+++ b/core/tests/scripts/test_composer_project_templates.sh
@@ -34,11 +34,13 @@
 SOURCE_DIR=$(realpath $(dirname $0))/../../..
 
 info "Installing recommended project composer template"
+composer --working-dir="${SOURCE_DIR}/composer/Template/RecommendedProject" config repositories.scaffold path '../../Plugin/Scaffold'
 composer --working-dir="${SOURCE_DIR}/composer/Template/RecommendedProject" install --no-suggest --no-progress --no-interaction
 info "Recommended project composer template installed successfully."
 assertScaffold "${SOURCE_DIR}/composer/Template/RecommendedProject/web"
 
 info "Installing legacy project composer template"
+composer --working-dir="${SOURCE_DIR}/composer/Template/LegacyProject" config repositories.scaffold path '../../Plugin/Scaffold'
 composer --working-dir="${SOURCE_DIR}/composer/Template/LegacyProject" install --no-suggest --no-progress --no-interaction
 info "Legacy project composer template installed successfully."
 assertScaffold "${SOURCE_DIR}/composer/Template/LegacyProject"

Inquired with Greg about that, he pointed out that this is to make the tests pass; those lines set up a "path repository" that causes the code in the patch to be installed instead of what's in Packagist. (Good to test the actual code that's in the patch. ;))

Great!

Committed and pushed to 8.8.x. Thanks!

webchick’s picture

Oopsie, credit.

  • webchick committed 1082bca on 8.8.x
    Issue #3086148 by greg.1.anderson, hussainweb, Mixologic: Make scaffold...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.