Add support for reading PHP version from composer.lock or composer.json

This commit is contained in:
Jason Gill
2023-07-29 19:46:06 -04:00
parent 72ae4ccbe5
commit a5fb328c6a
3 changed files with 78 additions and 0 deletions

21
dist/index.js vendored
View File

@ -1371,6 +1371,27 @@ async function readPHPVersion() {
else if (versionFile !== '.php-version') {
throw new Error(`Could not find '${versionFile}' file.`);
}
const composerLock = 'composer.lock';
if (fs_1.default.existsSync(composerLock)) {
const lockFileContents = JSON.parse(fs_1.default.readFileSync(composerLock, 'utf8'));
if (lockFileContents['platform-overrides'] &&
lockFileContents['platform-overrides']['php']) {
return lockFileContents['platform-overrides']['php'];
}
}
const composerJson = 'composer.json';
if (fs_1.default.existsSync(composerJson)) {
const composerFileContents = JSON.parse(fs_1.default.readFileSync(composerJson, 'utf8'));
if (composerFileContents['config'] &&
composerFileContents['config']['platform'] &&
composerFileContents['config']['platform']['php']) {
return composerFileContents['config']['platform']['php'];
}
if (composerFileContents['require'] &&
composerFileContents['require']['php']) {
return composerFileContents['require']['php'];
}
}
return 'latest';
}
exports.readPHPVersion = readPHPVersion;