运行全局composer命令时使用composer.json文件中的外部变量

问题描述 投票:0回答:1

我想将私人项目加载到更大的项目中。多个私有存储库属于不同的 GitHub 用户和组织。因此,我需要使用至少2个代币。我找到了解决方案,但它需要将令牌存储在

composer.json
文件中。

在composer.json文件中直接使用token

{
  "require": {
    "organization-name/repository-1": "^1.2",
    "organization-name/repository-2": "^1.2",
    "username/repository-3": "^1.2"
  },
  "repositories": [
    {
      "type": "git",
      "url": "https://[email protected]/organization-name/repository-1.git"
    },
    {
      "type": "git",
      "url": "https://[email protected]/organization-name/repository-2.git"
    },
    {
      "type": "git",
      "url": "https://[email protected]/username/repository-3.git"
    }
  ]
}

但是,我不想在将项目上传到网络服务器时暴露令牌。 如何在运行全局

composer
命令时用变量替换标记并声明这些变量?(例如,当运行
composer install
composer update
时)

声明外部变量(只是我想要实现的目标的一个说明)

{
  "firstToken": "token-first",
  "secondToken": "token-second",
}
{
  "require": {
    "organization-name/repository-1": "^1.2",
    "organization-name/repository-2": "^1.2",
    "username/repository-3": "^1.2"
  },
  "repositories": [
    {
      "type": "git",
      "url": "https://github_pat_${firstToken}@github.com/organization-name/repository-1.git"
    },
    {
      "type": "git",
      "url": "https://github_pat_${firstToken}@github.com/organization-name/repository-2.git"
    },
    {
      "type": "git",
      "url": "https://github_pat_${secondToken}@github.com/username/repository-3.git"
    }
  ]
}
composer-php
1个回答
0
投票

作曲家不支持。

您可以编写其他内容,根据模板生成新的composer.json,从变量推断内容...但这样就不再是“composer”问题,composer 只会看到生成的 JSON 文件。

© www.soinside.com 2019 - 2024. All rights reserved.