【问题标题】:Composer unable to run post install scriptComposer 无法运行安装后脚本
【发布时间】:2016-02-06 14:48:32
【问题描述】:

尝试在 Composer 安装/更新后挂钩中运行 bash 脚本时出现以下错误:

> post-install.sh
sh: 1: post-install.sh: not found
Script post-install.sh handling the post-install-cmd event returned with an error



  [RuntimeException]
  Error Output: sh: 1: post-install.sh: not found

原作曲家.json

可以,但是更新后安装/更新命令以在两个地方运行很烦人。

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
    ...
  },
  "scripts": {
    "post-install-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
      ...
    ],
    "post-update-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
      ...
    ]
  }
}

根据Composer documentation

在 Composer 的术语中,脚本可以是 PHP 回调(定义 作为静态方法)或任何命令行可执行命令。

所以我的composer.json 应该可以这样工作:

需要 composer.json

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
    ...
  },
  "scripts": {
    "post-install-cmd": [
      "post-install.sh"
    ],
    "post-update-cmd": [
      "post-install.sh"
    ]
  }
}

post-install.sh

每个人都可以执行 (0775),并且与 composer.json 位于同一目录中

#!/bin/bash

mkdir -p _libraries
cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/
...
...

【问题讨论】:

  • 您是否使post-install.sh 可执行? (例如chmod 0755 post-install.sh)你说是,但我只是想我会确认。另外,它是如何被 Composer 执行的?它是通过一些php 调用来调用它的吗?
  • @DavidC.Rankin 是的,它是可执行的。 Composer 未执行 bash 脚本。 (我不确定你在这里问什么)
  • 作曲家应该如何找到那个脚本?
  • @hek2mgl 如果我知道,我不会问这个问题,但我认为它是通过将脚本放在与 composer.pharcomposer.json 相同的目录中并在 @ 下定义脚本来实现的987654333@composer.json...
  • 当你使用sh post-install.sh时它是否有效?但是,我想它甚至应该是sh vendor/you/yourproject/post-install.sh。没有手动测试设置

标签: bash composer-php


【解决方案1】:

其他实现单任务定义的方式是referencing scripts:

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
  },
  "scripts": {
    "your-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
    ],
    "post-install-cmd": [
      "@your-cmd",
      ...
    ],
    "post-update-cmd": [
      "@your-cmd",
      ...
    ]
  }
}

【讨论】:

    【解决方案2】:

    comments我建议使用

    bash post-install.sh
    

    这似乎有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-06
      • 2014-08-26
      • 2016-12-29
      • 1970-01-01
      • 2016-11-16
      • 2023-03-29
      • 2018-04-17
      • 1970-01-01
      相关资源
      最近更新 更多