Skip to content

Instantly share code, notes, and snippets.

@shengjie
Created September 17, 2019 08:19
Show Gist options
  • Save shengjie/2d0a544ac21223af604a6bd2f952ff34 to your computer and use it in GitHub Desktop.
Save shengjie/2d0a544ac21223af604a6bd2f952ff34 to your computer and use it in GitHub Desktop.
Update composer lock given package reference fastly
<?php
$lockFile = $argv[1];
$packageName = $argv[2];
$ref = $argv[3];
if ($argc !== 4) {
echo "Usage update_lock.php composer.lock mypackage 123abc\n";
exit;
}
$lockData = json_decode(file_get_contents($lockFile), true);
foreach($lockData['packages'] as &$package) {
if ($package['name'] === $packageName) {
$package['source']['reference'] = $ref;
$package['dist']['url'] = sprintf('https://api.github.com/repos/%s/zipball/%s', $packageName, $ref);
$package['dist']['reference'] = $ref;
}
}
file_put_contents($lockFile, json_encode($lockData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES). PHP_EOL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment