“钥匙:value”是什么?语法在作曲家脚本中执行

发布于 2025-02-09 05:07:12 字数 471 浏览 1 评论 0原文

从compser文档中,您可以像这样编写脚本:

{
    "scripts": {
        "some-event": [
            "command1",
            "command2",
            "command3"
        ],
    }
}

但是在Symfony中,我发现语法略有不同,而不是列表使用键:值对:

{
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
    },
}

此语法如何准确地工作? 它是否将命令重定向到另一个命令,在2个命令之间添加一个依赖关系?

From compser documentation you can write scripts like so:

{
    "scripts": {
        "some-event": [
            "command1",
            "command2",
            "command3"
        ],
    }
}

But in Symfony I found a slightly different syntax that instead of a list is using a key:value pair like this:

{
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
    },
}

How does this syntax work exactly?
Does it redirect commands to another one, adds a dependency between 2 commands or what?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2025-02-16 05:07:13

此语法如何完全工作?

该语法在作曲家中不确定。

要了解更多信息,请删除它,然后检查哪个组件断裂。然后咨询该组件的支持,以了解更多信息(和/或在此处发表评论)。

它是否将命令重定向到另一个命令,在2个命令之间添加一个依赖关系?

正如书面的那样,这是不确定的。至于您对作曲家的关注,您可以检查它是否被识别为脚本:

composer run-script --list

您可能会看到auto-scripts被列为脚本,也就是说,作曲家至少在识别自动订阅关键字。

然后,您可以执行该脚本以查看作曲家如何执行它(强烈建议您在孤立的环境中执行此操作):

composer run-script auto-scripts

要查看插件是否会有所不同,您也可以禁用插件来执行它:

composer --no-plugins run-script auto-scripts

请注意。

与作曲家在一起,总有-vvv


有关内部作曲家配置文件处理的一些注释:json文本文件(.jsonlock)通常被解析为关联阵列(不是stdclass :: class class class对象)。

因此,foreach'一个脚本成员 - 也可以是字符串,很可能是用(array) cast进行后处理的 - 不在乎键(属性名称),只是执行脚本行。

How does this syntax work exactly?

This syntax is undefined in Composer.

To learn more, remove it and then check which component(s) break(s). Then consult the support of that/these component(s) to learn more (and/or leave a comment here).

Does it redirect commands to another one, adds a dependency between 2 commands or what?

As written this is undefined. As far as you're concerned about Composer you can check if it is recognized as a script:

composer run-script --list

You'll likely see that auto-scripts is listed as a script, that is, Composer is recognizing at least the auto-scripts keyword.

You can then execute that script to see how Composer executes it (it is highly recommended you do this and the following in an isolated environment):

composer run-script auto-scripts

To see if a plugin would make a difference, you can also execute it with plugins disabled:

composer --no-plugins run-script auto-scripts

Take care.

And with Composer there is always -vvv.


Some notes on internal Composer configuration file handling: JSON Text files (.json, .lock) in Composer are typically parsed into associative arrays (not stdClass::class objects).

Therefore foreach'ing a script member - which can be a string as well, likely post-processed with an (array) cast - would not care about the key (attribute name), just executing the scripts lines.

流星番茄 2025-02-16 05:07:13

该语法由symfony/flex插件使用,仅在auto-scripts键下有效。
Flex中的代码看起来像这样:

        $json = new JsonFile(Factory::getComposerFile());
        $jsonContents = $json->read();

        $executor = new ScriptExecutor($this->composer, $this->io, $this->options);
        foreach ($jsonContents['scripts']['auto-scripts'] as $cmd => $type) {
            $executor->execute($type, $cmd);
        }

使用此代码处理执行:

        switch ($type) {
            case 'symfony-cmd':
                return $this->expandSymfonyCmd($cmd);
            case 'php-script':
                return $this->expandPhpScript($cmd);
            case 'script':
                return $cmd;
            default:
                throw new \InvalidArgumentException();
        }

This syntax is used by symfony/flex plugin and is only valid under auto-scripts key.
The code in flex looks like this:

        $json = new JsonFile(Factory::getComposerFile());
        $jsonContents = $json->read();

        $executor = new ScriptExecutor($this->composer, $this->io, $this->options);
        foreach ($jsonContents['scripts']['auto-scripts'] as $cmd => $type) {
            $executor->execute($type, $cmd);
        }

With execute being handled using this code:

        switch ($type) {
            case 'symfony-cmd':
                return $this->expandSymfonyCmd($cmd);
            case 'php-script':
                return $this->expandPhpScript($cmd);
            case 'script':
                return $cmd;
            default:
                throw new \InvalidArgumentException();
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文