n98-magerun2 v6.0.0

Published by Christian Münch on

Release 6.0.0 - City of Cologne in Germany

I hope you have have great day as admin or developer. Today we release a new version of the CLI tool n98-magerun2. The codename of the release is Cologne which is the place where the
Mage UnConference 2022 takes place this week. So it’s a Magento City.

With this release we increase the major version number, because we dropped support for EOL Magento versions (Read chapter at the end of the post).

If you need older phar files of the tool, then have a look into the Version Archive at files.magerun.net. There you can find all released version (even version 1.0.0 for Magento 1 released in 2012).

The new release offers new features and fixes as well. So let’s start with the features.

New route:list command

A great community contribution by gowrizrh introduces a new command to list the registered routes of your shop. The command comes with two filter options for the area and the module.

The result is a table which can be exported (via format option) as JSON, XML, CSV if needed.

$> n98-magerun2.phar route-list
Output of route:list command without any options.
$> n98-magerun2.phar route:list --area frontend --module=Magento_Catalog
Filtered list of routes

dev:console improvements

The dev:console command got some new options. The options are affecting the optional CMD argument which exist to directly pass commands to the console. The idea behind is that you can initialize the RELP by adding some commands from outside. This also works with STDIN. So the output of a file can be piped to the console. Super handy.

Use stdin

The dev:console reads from /dev/stdin device. That enables that you can pipe commands into the console command. If there are multiple command then we need to delimit them via a newline (\n).

Bash Example:

echo -e "1+1\nls" | n98-magerun2.phar dev:console

This allow us to read a file and redirect the output to the dev:console.

cat mycommands.txt | n98-magerun2.phar dev:console
n98-magerun2.phar dev:console < mycommands.txt

If data is read from stdin, the dev:console is always in non-interactive mode and will exit immediately after command processing.

Use CMD argument

A second way to pass commands from outside is the usage of the optional CMD argument.

n98-magerun2.phar dev:console "1+1; ls"

If commands are passed via the arguments, then the dev:console is acting in the interactive mode and provide then the prompt of the command shell.

There is a new option to change the way, the dev:console works in combination with the ARG argument.

–auto-exit | -e

The option appends an exit command to the command list. That stops the interactive mode if the commands where successful.

make:module command

Inside the dev:console we offer a command to create new modules. The command gets a option
–module-base-dir which let you define the directory where the module should be created in.

That’s super useful if you do not use the app/code directory. At netz98 we use the directory src in combination with a local Composer Path Repository with wildcards. We know that this new approach is more and more adopted in the wild.

Create a new module where ever you want (inside your root directory)

The default value (app/code) is now defined in the distribution config, bundled with n98-magerun2. That gives you a way to override the default value for new modules by a project or user specific config.

To override the value in your project, create a new config file app/etc/n98-magerun2.yaml.

The following example defines a new base path src as new default destination if the base dir is not specified as option.

commands:
  N98\Magento\Command\Developer\Console\MakeModuleCommand:
    defaultModulesBaseDir: 'src'

The command does allow any path inside your project root directory.

Some tips:

  • The make:module command is only a Code Generator. Including the module in the composer.json has to be done manually.
  • To generate code for existing modules use “module <module-name>” to set the context for the generator. Example “module Acme_Foo”.

PHPStan for a better Code Quality

The whole code base of n98-magerun2 is now compatible PHPStan level 1. Like promised by Stephan Hochdörfer during his talk at the Magento Meetup Rhein-Main, the tool will find issues. And he was right! We found a lot of smaller issues and some not right handled return types and exceptions.

PHPStan was added to the ddev based setup for n98-magerun2 contributors and as well to the Github Actions.

To reach level 2 is much harder. Let’s see …

Improvements of the contributor development setup

If you are a contributor and want to test you changed n98-magerun2 code then you can run the ddev qa command. The command runs the php-cs-fixer and PHPStan. We run a setup:di:compile on the first run to guarantee that all files are available for PHPStan.

The ddev setup contains a new command ddev get-magento-source which copies the Magento core framework and modules in the project root directory. That’s helpful to get full Code Completion in PhpStorm. Before it was only possible by manually adding a path to an existing code base on the host machine. The new setup is much easier and reproducible for everyone.

Dropped Magento 2.3.x support

To fix some issues in the code generator we had to change some code to support the used Laminas framework classes in Magento 2.4.x.

This also breaks some old Zend Framework calls in Magento 2.3.x. Before the 6.0.0 release we tested the tool with functional tests against the 2.3.x releases. The test setup does not execute the current existing tests anymore against EOL Magento versions.

That means that some command could be broken in Magento 2.3.x, but we will not recognize that anymore. If you find issues let us know but this does not mean that we can fix them in any case. With every platform change provided by newer Magento versions it’s more and more difficult to provide Backwards Compatibility. So we focus on the active supported versions.

Reference: https://devdocs.magento.com/release/lifecycle-policy.html

Full Changelog

  • Add: route:list command (by Gowri)
  • Add: installer command – Update installable versions (incl. mage-os) (by Christian Münch)
  • Add: ddev get-magento-source command for code completion in PhpStorm (by Christian Münch)
  • Add: Integrated phpstan in developer setup (by Christian Münch)
  • Add: New option to define the modules base dir for module creation in dev:console make:module command (by Christian Münch)
  • Add: Auto exit option for dev:console (by Christian Münch)
  • Add: New option to run dev:console in PHP script mode (by Christian Münch)
  • Imp: Update 3rd party dependencies (twig, phar-utils, phpunit, symfony)
  • Imp: Check phpstan in Github Actions (by Christian Münch)
  • Imp: Fix all phpstan warnings/errors of level 0 and level 1 (by Christian Münch)
  • Imp: ddev setup (installed Magento versions) (by Christian Münch)
  • Imp: Add some checks to secure customer:delete command (by Christian Münch)
  • Fix: #1028: Check if job config is set (by Christian Münch)
  • Fix: #1037: dev:console Code Generator (by Christian Münch)
  • Fix: typos and wrong infos in help text (by Christian Münch)
  • Del: Symfony Shell Command – Command was already broken (by Christian Münch)
  • Del: Drop active testing support for Magento 2.3.x (some commands could be incompatible due to platform changes)

Update 2022-09-29 19:21

We just released version 6.0.1 with a update of the bundled twig library containing a security update.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.