Theme create wizard generates invalid JSON

I used bin/console plugin:create to create a theme plugin named IngoSDev6CertPrep. I don’t remember how excactly I typed the name, but the wizard tried to write an escaped kebab-case version into the composer.json that JsonLint warns is invalid:

  [Seld\JsonLint\ParsingException]                                                            
  "/var/www/html/custom/plugins/IngoSDev6CertPrep/composer.json" does not contain valid JSON  
  Parse error on line 2:                                                                      
  {    "name": "ingo-s\-dev6-cert-p                                                           
  ------------^                                                                               
  Invalid string, it appears you have an unescaped backslash at: \-dev

This affects the parts between vendor prefix and plugin name, maybe due to an unexpected capitalization. My vendor prefix ends with a capital „S“ which seemed to be valid so far. The plugin name starts with another capital letter, „D“, as I previously wrote everything together like „IngoSDev6CertPrep“. The theme wizard generates

  • „name“: „ingo-s-dev6-cert-prep/ingo-s-dev6-cert-prep“,
  • „shopware-plugin-class“: „IngoS\Dev6CertPrep\IngoSDev6CertPrep“,
  • „autoload“: { „psr-4“: { „IngoS\Dev6CertPrep\“: „src/“

Update: I add a screenshot, as the forum seems to hide backslashes even if they are inside code blocks:

To make things worse, other theme commands don’t complain, they seem to fail silently and my theme is just not visible in the theme list. It only occured to me to look into my theme plugin’s composer.json when I tried to add the Symfony profiler which is missing in the current latest dockware/dev container (Shopware 6.5.7.3) so I typed (at Shopware root):

composer require --dev symfony/profiler-pack

That also linted the subdirectories and stopped at my plugin error.

Expected behavior:

  • plugin:create never creates invalid JSON:
    • there should be no unnecessary escaping: \- could be -
    • optional escaping should always be correct: \- should be \\-
    • dashes/hyphens should be ecaped correctly: \\ between namespace parts
  • the theme name should not repeat both prefix and name: "ingo-s-dev6-cert-prep/ingo-s-dev6-cert-prep" should be "ingo-s/ingo-s-dev6-cert-prep"
  • theme commands should lint and warn
  • top-level composer commands can’t be broken by invalid plugin code.

Recommendations:

If anyone else wants to create plugins or themes using the wizard, always check and edit the generated files before proceeding! Keeep theme/plugin names short and simple, and if you haven’t chosen a vendor prefix yet, don’t use optional uppercase after the first character!

Similar error: we can create themes that are valid enough to install and activate and show up in the UI’s extensions → themes list, but throw an [ERROR] invalid theme name when trying to assign them to the storefront using bin/console theme:change.
I installed the additional optional SW CLI tools to use their plugin validator:
shopware-cli extension validate custom/plugins/MyTheme
only to see a successful INFO Validation has been successful.

But I still can’t apply the valid theme with the supposedly invalid name to the storefront.

I tried to mimic the structure of auto-generated themes so I have "name": "IngoSDemoTogetherTheme" in theme.json but "name": "ingo-s/ingo-s-demo-together-theme" in composer.json. PhpStorm + SW Plugin has no helpful warnings/recommendations either.

Related: shopware6 - Invalid theme name error when trying to install valid Shopware theme - Stack Overflow

As others suggested a corrupt database entry, I destroyed and rebuilt the container, reinstalled and activated the theme using the admin UI. Now I can even see and assign the theme to the storefront.

So far, so good. But I still don’t understand the error and how to fix and prevent it in the future.