Skip to content

Commit

Permalink
fix(composer): Always allow to create lockfiles
Browse files Browse the repository at this point in the history
The `composer.json` might have the `lock` option [1] (which defaults to
`true`) explicitly set to `false` to disallow the creation of lockfiles.

Previously, analyzing such projects resulted in

    Composer failed to resolve dependencies for path 'composer.json':
    FileNotFoundException: /tmp/.../composer.lock
    (No such file or directory)

because the implementation relies on either a lockfile to be present
or to be able to create one via `composer update` in order to parse it.
But if Composer is configured to work without a lockfile, none would be
created, resulting in the above error.

Fix this by unsetting the `lock` option before the call to `compose
update`. Unsetting the option instead of setting it to `false` has the
advantage that `composer.json` files without the setting are not modified.

[1]: https://getcomposer.org/doc/06-config.md#lock

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Dec 11, 2024
1 parent 750141b commit aef875e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/package-managers/composer/src/main/kotlin/Composer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ class Composer(
requireLockfile(workingDir) { hasLockfile }
if (hasLockfile) return lockfile

// Ensure that the build is not configured to disallow the creation of lockfiles.
run(workingDir, "--no-interaction", "config", "--unset", "lock").requireSuccess()

val composerVersion = Semver(getVersion(workingDir))
val args = buildList {
add("--no-interaction")
Expand Down

0 comments on commit aef875e

Please sign in to comment.