如何将一些dependecies从require转移到require-dev与composer?

时间:2016-10-29 11:34:20

标签: php composer-php

某些依赖项被错误地添加到require而不是require-dev。我尝试手动更改composer.json并运行composer install,但composer.lock未更改。所以我的猜测是,它忽略了composer.json中的更改,并确保安装的内容反映了composer.lock文件中的内容。我错了吗?如果没有错,我该怎么做?我想尽可能保留composer.lock文件中的软件包版本。

3 个答案:

答案 0 :(得分:3)

我已经重现了您的问题并找到了一个简单的解决方案:composer update

以下是我所做的步骤。

composer.json

{
  "require": {
    "meenie/javascript-packer": "1.1"
  }
}

$ composer install

保存composer.lock的备份以进行进一步比较:

$ cp composer.lock composer.lock-prev

composer.json

{
  "require-dev": {
    "meenie/javascript-packer": "1.1"
  }
}


$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update

我更新了Composer作为上面建议的输出:

$ composer update

Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

然后查看composer.lock的旧版本和新版本之间的差异:

$ diff -Nau composer.lock-prev composer.lock 
--- composer.lock-prev  2016-10-29 19:05:51.331588329 +0700
+++ composer.lock   2016-10-29 19:06:05.639809116 +0700
@@ -4,9 +4,10 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "f092e6d1418a7bb0db55b75f1099b4eb",
-    "content-hash": "774f074021977667a459f207616edfe2",
-    "packages": [
+    "hash": "0c81c48f9845635d47821bc0e965e4fe",
+    "content-hash": "cb194309c2a3fda3b07a46ed7ef36bdd",
+    "packages": [],
+    "packages-dev": [
         {
             "name": "meenie/javascript-packer",
             "version": "1.1",
@@ -45,7 +46,6 @@
             "time": "2013-03-25 21:54:33"
         }
     ],
-    "packages-dev": [],
     "aliases": [],
     "minimum-stability": "stable",
     "stability-flags": [],

我们可以看到在运行composer update之后实际应用了更改。

答案 1 :(得分:2)

看来import UIKit import AVFoundation class TestingViewController: UIViewController { let session: AVCaptureSession = AVCaptureSession() override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) session.sessionPreset = AVCaptureSession.Preset.high if let device = AVCaptureDevice.default(for: AVMediaType.video) { do { try session.addInput(AVCaptureDeviceInput(device: device)) } catch { print(error.localizedDescription) } let previewLayer = AVCaptureVideoPreviewLayer(session: session) self.view.layer.addSublayer(previewLayer) previewLayer.frame = self.view.layer.bounds } session.startRunning() let blur = UIBlurEffect(style: .regular) let blurView = UIVisualEffectView(effect: blur) blurView.frame = self.view.bounds blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(blurView) } } 可以解决您的问题。

答案 2 :(得分:1)

我愿意:

  

作曲家需要--dev drupal / devel

或以您的示例

  

composer require --dev meenie / javascript-packer:1.1

这使作曲家可以承担所有繁重的工作,并将这些依赖项移到require-dev部分。