14

I've just installed Symfony 4 project and found this section in composer.json:

"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ],
...

I've found that section auto-scripts is handled somehow differently by the Composer: key is a command to bin/console and value is a command "type" (In this case it's Symfony's). As it is not documented on Composer website, I assume it's not legal definition, but it works, and my question is how the Composer knows how to execute such commands? How Composer knows what is symfony-cmd?

1
  • 4
    It is part of the Symfony Flex composer plugin so it is legal. I have never tracked down exactly where it is defined but probably somewhere in here. It is the same code that lets you do thing like "composer require server" and other magic. Commented Jun 5, 2018 at 15:15

2 Answers 2

15

It's as Cerad says. auto-script is parsed by Symfony/Flex and the "right side" of a command:executable pair is processed by this switch-case.

switch ($type) {
    case 'symfony-cmd':
        return $this->expandSymfonyCmd($cmd);
    case 'php-script':
        return $this->expandPhpScript($cmd);
    case 'script':
        return $cmd;

Therefore Composer documentation can not say a word about that as it is Symfony-specific.

Personally don't like the mixing of standard Composer sections with custom ones on the composer.json root level. It simply confuses me and draws me into silent Composer documentation. Also the naming itself, auto-script, should be better. Something less magic and more self-explanatory, like flex-script.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess it uses extra configuration located in composer.json

"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-var-dir": "var",
    "symfony-bin-dir": "bin",
    "symfony-tests-dir": "tests",

    ...
},

Few days ago when I was migrating an application from 2.8 to 3.4, I had some trouble with these definitions.

I also had to clear composer's cache.

1 Comment

Good guess but nope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.