问题 Composer无法运行安装后脚本


尝试在Composer post install / update挂钩中运行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

原始composer.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的术语来说,脚本可以是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/
...
...

11174
2017-11-05 16:43


起源

你有没有做 post-install.sh 可执行文件? (例如。 chmod 0755 post-install.sh你说是的,但我只是想我会证实。另外,Composer如何执行它?它是由一些人称之为 php 呼叫? - David C. Rankin
@ DavidC.Rankin是的,它是可执行文件。 Composer没有执行bash脚本。 (我不确定你在这里问的是什么) - grim
作曲家应该如何找到该剧本? - hek2mgl
使用时是否有效 sh post-install.sh ?但是,我想它应该是均匀的 sh vendor/you/yourproject/post-install.sh。手上没有测试设置 - hek2mgl
这很奇怪!.. - hek2mgl


答案:


注释 我建议用

bash post-install.sh

这似乎有效。


8
2017-11-05 20:58





实现单任务定义的其他方法是 引用脚本

{
  "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",
      ...
    ]
  }
}

7
2018-02-01 09:35