Skip to content

Change package type to "composer-plugin".#45

Merged
ADmad merged 14 commits intomasterfrom
next
Oct 24, 2020
Merged

Change package type to "composer-plugin".#45
ADmad merged 14 commits intomasterfrom
next

Conversation

@ADmad
Copy link
Copy Markdown
Member

@ADmad ADmad commented Apr 23, 2020

Issues with current version

  • The current PluginInstaller updates the vendor/cakephp-plugins.php file to add/remove entry for the cakephp plugin that is installed/removed via composer.
    Later on the PluginInstaller::postAutoloadDump() which is set as post-autoload-dump hook through app's composer.json recreates the cakephp-plugins.php file making the changes done earlier for individual plugin addition/removal redundant.

Changes in this PR

  • The package type is changed to composer-plugin and the composer-plugin-api interface is used. This allows the package to rely on event subscription and run our postAutoloadDump() script itself and avoid calling it from app's composer.json.
  • The redundancy mentioned above is also removed. The cakephp-plugins.php is manipulated/created only once for the post-autoload-dump event.
  • The installer will remain compatible with both composer v1 and v2.

Compatibility

  • Existing 4.x apps will be able to upgrade to new major version of the installer without problems. They will just get a warning to remove the unneeded post-autoload-dump hook from app's composer.json.
  • From what I can tell existing v1 of our plugin installer should continue working with composer v2, so no changes would be required for CakePHP 3 plugins.
  • We can hold off releasing v2 until composer v2 stable is released.

@ADmad ADmad mentioned this pull request Sep 27, 2020
@markstory
Copy link
Copy Markdown
Member

If these changes are compatible with both composer 1 and 2 it would be preferable to me if we could release this as 1.3.0 and not require any significant changes in userland code.

Doing that seems like it would require at least a dummy method for Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump so that existing composer scripts don't fail. This method could emit a deprecation notice letting people know that this line is now redundant with the new installer.

I don't think the implementation of this installer hook requires a major version bump if we include the above shim because functionally it still does everything the old code did and wouldn't raise any runtime errors.

@ADmad ADmad marked this pull request as ready for review September 28, 2020 08:33
@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 28, 2020

If these changes are compatible with both composer 1 and 2 it would be preferable to me if we could release this as 1.3.0 and not require any significant changes in userland code.

Sounds good to me.

Doing that seems like it would require at least a dummy method for Cake\Composer\Installer\PluginInstaller::postAutoloadDump so that existing composer scripts don't fail. This method could emit a deprecation notice letting people know that this line is now redundant with the new installer.

Yes, I have already done that.

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 28, 2020

Would appreciate it if people could try out the next branch and confirm everything works smoothly.

Things to ensure:

  • vendor/cakephp-plugins.php file generation works properly when adding/removing plugins.
  • No errors with either composer v1 or v2
  • Warning is shown if "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump" has not been removed from scripts block of composer.json.

@othercorey
Copy link
Copy Markdown
Contributor

Want to release a beta or rc out of next branch for easier testing?

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 28, 2020

1.3.0-beta released

@markstory
Copy link
Copy Markdown
Member

I tried the beta out tonight and this was my composer log (with composer 1)

ᐉ composer up
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 11 updates, 0 removals
  - Removing cakephp/plugin-installer (1.2.0)
  - Installing cakephp/plugin-installer (1.3.0-beta): Downloading (100%)
  - Updating composer/semver (1.7.0 => 1.7.1): Downloading (100%)
  - Updating symfony/string (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating symfony/console (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating symfony/finder (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating symfony/process (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating symfony/filesystem (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating symfony/config (v5.1.5 => v5.1.6): Downloading (100%)
  - Updating phpspec/prophecy (1.11.1 => 1.12.0): Downloading (100%)
  - Updating nikic/php-parser (v4.10.1 => v4.10.2): Downloading (100%)
  - Updating symfony/var-dumper (v5.1.5 => v5.1.6): Downloading (100%)
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
31 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

The cakephp-plugins.php file was correctly generated.

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 29, 2020

Things works as expected for me too with both composer v1 and v2. The warning for removing post-autoload-dump hook doesn't show up the first time when upgrading from plugin-installer v1.2 to v1.3 but it does show up on subsequent autoload dumps. That's not a biggie as the warning is for cleanup only.

@othercorey
Copy link
Copy Markdown
Contributor

I can confirm cakephp-plugins.php is generated on windows as well with composer v1.

@LordSimal
Copy link
Copy Markdown
Contributor

I can also confirm, that the cakephp-plugins.php is generated correctly under

  • Composer v2 under MacOS and
  • Composer v1 under Debian

The only thing that can be quite confusing for users who are upgrading (to at least 1.3.0-beta for now) is the fact, that the following message is being shown after performing a composer install with the new composer.lock file under Composer v1

composer install


                                                                                
     Action required!                                                           
                                                                                
     The CakePHP plugin installer has been changed, please update your          
     application composer.json file to add the post-autoload-dump hook.         
     See the changes in https://github.com/cakephp/app/pull/216 for more        
     info.                                                                      
                                                                                


Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 0 installs, 3 updates, 0 removals
  - Removing cakephp/plugin-installer (dev-issue-47 6b968c1)
  - Installing cakephp/plugin-installer (1.3.0-beta): Downloading (100%)         
  - Updating dereuromark/cakephp-shim (2.0.1 => 2.1.0): Downloading (100%)         
  - Updating phpspec/prophecy (1.11.1 => 1.12.1): Downloading (100%)         
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
46 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> App\Console\Installer::postInstall
Created `<my-path>/tmp/cache/views` directory
Created `<my-path>/tmp/sessions` directory
Created `<my-path>/tmp/tests` directory
Set Folder Permissions ? (Default to Y) [Y,n]? Y
Permissions set on <my-path>/tmp/cache
Permissions set on <my-path>/tmp/cache/models
Permissions set on <my-path>/tmp/cache/persistent
Permissions set on <my-path>/tmp/cache/views
Permissions set on <my-path>/tmp/sessions
Permissions set on <my-path>/tmp/tests

Here what I did:

Updated my composer.json to have the following records adjusted/added

  "require": {
    ...
    "cakephp/plugin-installer": "^1.3",
    ...
  },
  "minimum-stability" : "beta",

Performed a composer update --with-dependencies on my machine with Composer v2 RC1

After that i removed all my vendor modules and performed a new composer install. This brought up the following message:

     Action required!                                                           
                                                                                
     The CakePHP plugin installer v1.3+ no longer requires the                  
     "post-autoload-dump" hook. Please update your app's composer.json          
     file and remove usage of                                                   
     Cake\Composer\Installer\PluginInstaller::postAutoloadDump   

Therefore i removed the postAutoloadDump hook from the composer.json.

Commited that in my repo and pulled it on my production machine

Performed a composer install on my production machine with Composer 1.10.10

And then the message from the start was shown.

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 30, 2020

The only thing that can be quite confusing for users who are upgrading (to at least 1.3.0-beta for now) is the fact, that the following message is being shown after performing a composer install with the new composer.lock file under Composer v1

Initially you got the message to add the post install hook because you were using a very old bugfix branch as evident from
- Removing cakephp/plugin-installer (dev-issue-47 6b968c1).

You should have updated to use stable release of the plugin installer years ago 🙂.

And then the message from the start was shown.

Which message exactly? What does your composer.json and composer.lock look like on production machine after running composer install?

@LordSimal
Copy link
Copy Markdown
Contributor

The only reason i used the DEV version is because I used your bugfix from #48

The message i was referring to was

     Action required!                                                           
                                                                                
     The CakePHP plugin installer has been changed, please update your          
     application composer.json file to add the post-autoload-dump hook.         
     See the changes in https://github.com/cakephp/app/pull/216 for more        
     info.      
composer.json

  {
  "name": "cakephp/app",
  "description": "CakePHP skeleton app",
  "homepage": "https://cakephp.org",
  "type": "project",
  "license": "MIT",
  "require": {
    "php": ">=7.2",
    "ext-mysqli": "*",
    "ext-curl": "*",
    "ext-ftp": "*",
    "ext-intl": "*",
    "ext-json": "*",
    "bitbucket/client": "^3.1",
    "cakephp/cakephp": "^4.1",
    "cakephp/migrations": "^3.0.0",
    "cakephp/plugin-installer": "^1.3",
    "dereuromark/cakephp-queue": "^5.0",
    "dereuromark/cakephp-tools": "^2.1",
    "dereuromark/cakephp-setup": "^2.0",
    "easybill/php-sdk": "^2.0",
    "gamez/mite": "^1.0",
    "guzzlehttp/guzzle": "^6.5",
    "http-interop/http-factory-guzzle": "^1.0",
    "jeroendesloovere/vcard": "^1.7",
    "lesstif/php-jira-rest-client": "^2.4",
    "mlocati/ip-lib": "^1.12",
    "mobiledetect/mobiledetectlib": "^2.8",
    "php-http/guzzle6-adapter": "^2.0.1",
    "phpoffice/phpspreadsheet": "^1.9",
    "phpseclib/phpseclib": "^2.0",
    "solarium/solarium": "^6.0",
    "stevenmaguire/oauth2-bitbucket": "^3.0",
    "symfony/event-dispatcher": "^5.1"
  },
  "require-dev": {
    "cakephp/bake": "^2.0",
    "cakephp/cakephp-codesniffer": "^4.1",
    "cakephp/debug_kit": "^4.0",
    "dereuromark/cakephp-ide-helper": "^1.5",
    "dereuromark/cakephp-test-helper": "^1.0",
    "josegonzalez/dotenv": "^3.2",
    "pakacuda/cakephp-fixture-factories": "^0.2.4",
    "phpunit/phpunit": "^8.5",
    "psy/psysh": "@stable",
    "phan/phan": "^2.4"
  },
  "suggest": {
    "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
    "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility."
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "App\\Test\\": "tests/",
      "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
    }
  },
  "scripts": {
    "post-install-cmd": "App\\Console\\Installer::postInstall",
    "post-create-project-cmd": "App\\Console\\Installer::postInstall",
    "check": [
      "@test",
      "@cs-check"
    ],
    "cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
    "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
    "stan": "phpstan analyse src/",
    "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan-shim:^0.11 && mv composer.backup composer.json",
    "local-test": "./local-phpunit --colors=always",
    "local-coverage": "./local-phpunit --coverage-html webroot/coverage",
    "local-setup": "./local-cake code_completion generate && ./local-cake phpstorm generate",
    "local-annotate": "./local-cake annotate all"
  },
  "minimum-stability" : "beta",
  "config": {
    "sort-packages": true,
    "process-timeout": 0
  }
}

composer.lock.zip

@LordSimal
Copy link
Copy Markdown
Contributor

But of course this can only be a special case just for users like me which were previously on that bugfix for Composer v2

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Sep 30, 2020

The only reason i used the DEV version is because I used your bugfix from #48

Oh sorry, yes that's a special case and normally no one will get that message.

You can run composer dumpautoload either locally or on production and you now won't get any message after removing post-autoload-dump hook.

@ADmad ADmad force-pushed the next branch 2 times, most recently from 2820e6d to 9ae955a Compare October 14, 2020 20:17
@othercorey
Copy link
Copy Markdown
Contributor

Let's merge and release. We won't get any more testing out of this.

@ADmad
Copy link
Copy Markdown
Member Author

ADmad commented Oct 15, 2020

We would have to keep composer v2 constraint with @RC if we want to merge and release now (I don't mind it). Composer v2's stable release is slated for end of October.

BTW our plugin installer v1.2 doesn't work at all now with the composer 2 RC releases. The composer update/install seems to go nicely and doesn't give any errors but the folders for the plugins under vendors are simply missing 🙂.

@othercorey
Copy link
Copy Markdown
Contributor

Ah right. I guess we could just wait.

@ADmad ADmad merged commit 549548a into master Oct 24, 2020
@ADmad ADmad deleted the next branch October 24, 2020 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants