import { quote } from 'shlex' ; import { GlobalConfig } from '../../config/global' ; import { logger } from '../../logger' ; import type { ToolConstraint } from '../../util/exec/types' ; import { api , id as composerVersioningId } from '../../versioning/composer' ; import type { UpdateArtifactsConfig } from '../types' ; import type { ComposerConfig , ComposerLock } from './types' ; export { composerVersioningId } ; const depRequireInstall = new Set ( [ 'symfony/flex' ] ) ; export function getComposerArguments ( config , toolConstraint ) { let args = '' ; if ( config . composerIgnorePlatformReqs ) { if ( config . composerIgnorePlatformReqs . length === 0 ) { const major = api . getMajor ( toolConstraint . constraint ) ; const minor = api . getMinor ( toolConstraint . constraint ) ; args += api . matches ( `${ major }.${ minor }` , '^2.2' ) ? " --ignore-platform-req='ext-*' --ignore-platform-req='lib-*'" : ' --ignore-platform-reqs' ; } else { config . composerIgnorePlatformReqs . forEach ( ( req ) => { args += ' --ignore-platform-req ' + quote ( req ) ; } ) ; } } args += ' --no-ansi --no-interaction' ; if ( ! GlobalConfig . get ( 'allowScripts' ) || config . ignoreScripts ) { args += ' --no-scripts --no-autoloader' ; } if ( ! GlobalConfig . get ( 'allowPlugins' ) || config . ignorePlugins ) { args += ' --no-plugins' ; } return args ; } export function getPhpConstraint ( constraints ) { const { php } = constraints ; if ( php ) { logger . debug ( 'Using php constraint from config' ) ; return php ; } return null ; } export function requireComposerDependencyInstallation ( lock ) { return ( lock . packages ?. some ( ( p ) => depRequireInstall . has ( p . name ) ) === true || lock [ 'packages-dev' ] ?. some ( ( p ) => depRequireInstall . has ( p . name ) ) === true ) ; } export function extractContraints ( composerJson , lockParsed ) { const res = { composer : '1.*' } ; if ( composerJson . require ?. php ) { res . php = composerJson . require ?. php ; } if ( composerJson . require ?. [ 'composer/composer' ] ) { res . composer = composerJson . require ?. [ 'composer/composer' ] ; } else if ( composerJson [ 'require-dev' ] ?. [ 'composer/composer' ] ) { res . composer = composerJson [ 'require-dev' ] ?. [ 'composer/composer' ] ; } else if ( composerJson . require ?. [ 'composer' ] ) { res . composer = composerJson . require ?. [ 'composer' ] ; } else if ( composerJson [ 'require-dev' ] ?. [ 'composer' ] ) { res . composer = composerJson [ 'require-dev' ] ?. [ 'composer' ] ; } else if ( lockParsed ?. [ 'plugin-api-version' ] ) { const major = api . getMajor ( lockParsed ?. [ 'plugin-api-version' ] ) ; const minor = api . getMinor ( lockParsed ?. [ 'plugin-api-version' ] ) ; res . composer = `^${ major }.${ minor }` ; } else if ( composerJson . require ?. [ 'composer-runtime-api' ] ) { const major = api . getMajor ( composerJson . require ?. [ 'composer-runtime-api' ] ) ; const minor = api . getMinor ( composerJson . require ?. [ 'composer-runtime-api' ] ) ; res . composer = `^${ major }.${ minor }` ; } return res ; }