Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/devenv-e2e/001-create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe( 'vip dev-env create', () => {
it( 'should use sane defaults', async () => {
const slug = getProjectSlug();
const expectedMultisite = false;
const expectedPhpVersion = '8.2';
const expectedPhpVersion = '8.4';
const expectedElasticsearch = false;
const expectedPhpMyAdmin = false;
const expectedXDebug = false;
Expand Down
17 changes: 9 additions & 8 deletions __tests__/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,14 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
expect( actual ).toStrictEqual( expected );
} );

it.each( [ [ '7.4' ], [ 'ghcr.io/automattic/vip-container-images/php-fpm-ubuntu:7.3' ] ] )(
'should throw an error for invalid version',
async version => {
expect( () => resolvePhpVersion( version ) ).toThrow(
`Unknown or unsupported PHP version: ${ version }`
);
}
);
it.each( [
[ '7.4' ],
[ 'ghcr.io/automattic/vip-container-images/php-fpm-ubuntu:7.3' ],
[ 'toString' ],
] )( 'should throw an error for invalid version', async version => {
expect( () => resolvePhpVersion( version ) ).toThrow(
`Unknown or unsupported PHP version: ${ version }`
);
} );
} );
} );
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import debugLib from 'debug';
import command from '../lib/cli/command';
import {
DEV_ENVIRONMENT_NOT_FOUND,
DEV_ENVIRONMENT_DEFAULT_PHP_VERSION,
DEV_ENVIRONMENT_PHP_VERSIONS,
} from '../lib/constants/dev-environment';
import {
Expand Down Expand Up @@ -109,7 +110,7 @@ cmd.argv( process.argv, async ( arg, opt ) => {
elasticsearch: currentInstanceData.elasticsearch,
php:
currentInstanceData.php ||
DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ].image,
DEV_ENVIRONMENT_PHP_VERSIONS[ DEV_ENVIRONMENT_DEFAULT_PHP_VERSION ].image,
mariadb: currentInstanceData.mariadb,
phpmyadmin: currentInstanceData.phpmyadmin,
xdebug: currentInstanceData.xdebug,
Expand Down
18 changes: 10 additions & 8 deletions src/lib/constants/dev-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,31 @@ interface PhpImage {
label: string;
}

export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, PhpImage > = {
8.2: {
export const DEV_ENVIRONMENT_PHP_VERSIONS = {
'8.2': {
image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2',
label: '8.2 (recommended)',
label: '8.2',
},
8.3: {
'8.3': {
image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.3',
label: '8.3',
},
8.4: {
'8.4': {
image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.4',
label: '8.4',
},
8.5: {
'8.5': {
image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.5',
label: '8.5 (experimental)',
},
} as const;
} as const satisfies Record< string, PhpImage >;

export const DEV_ENVIRONMENT_DEFAULT_PHP_VERSION: keyof typeof DEV_ENVIRONMENT_PHP_VERSIONS = '8.4';

export const DEV_ENVIRONMENT_DEFAULTS = {
title: 'VIP Dev',
multisite: false,
phpVersion: Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ],
phpVersion: DEV_ENVIRONMENT_DEFAULT_PHP_VERSION,
} as const;

export const DEV_ENVIRONMENT_VERSION = '2.3.3';
16 changes: 12 additions & 4 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import {
DEV_ENVIRONMENT_FULL_COMMAND,
DEV_ENVIRONMENT_DEFAULTS,
DEV_ENVIRONMENT_DEFAULT_PHP_VERSION,
DEV_ENVIRONMENT_PROMPT_INTRO,
DEV_ENVIRONMENT_COMPONENTS,
DEV_ENVIRONMENT_NOT_FOUND,
Expand Down Expand Up @@ -775,7 +776,7 @@
debug( `Resolving PHP version %j`, version );

let result: string;
if ( ! ( version in DEV_ENVIRONMENT_PHP_VERSIONS ) ) {
if ( ! Object.hasOwn( DEV_ENVIRONMENT_PHP_VERSIONS, version ) ) {

Check warning on line 779 in src/lib/dev-environment/dev-environment-cli.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=Automattic_vip-cli&issues=AZ5CK8D3k0uZeavvt_ng&open=AZ5CK8D3k0uZeavvt_ng&pullRequest=2846
const images = Object.values( DEV_ENVIRONMENT_PHP_VERSIONS );
const image = images.find( value => value.image === version );
if ( image ) {
Expand All @@ -784,7 +785,8 @@
throw new UserError( `Unknown or unsupported PHP version: ${ version }.` );
}
} else {
result = DEV_ENVIRONMENT_PHP_VERSIONS[ version ].image;
result =
DEV_ENVIRONMENT_PHP_VERSIONS[ version as keyof typeof DEV_ENVIRONMENT_PHP_VERSIONS ].image;
}

debug( 'Resolved PHP image: %j', result );
Expand All @@ -797,9 +799,15 @@
let answer = initialValue;
if ( isStdinTTY ) {
const choices = [];
Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS ).forEach( version => {
(
Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS ) as ( keyof typeof DEV_ENVIRONMENT_PHP_VERSIONS )[]
).forEach( version => {
Comment thread
rebeccahum marked this conversation as resolved.
const phpImage = DEV_ENVIRONMENT_PHP_VERSIONS[ version ];
choices.push( { message: phpImage.label, value: version } );
const label =
version === DEV_ENVIRONMENT_DEFAULT_PHP_VERSION
? `${ phpImage.label } (recommended)`
: phpImage.label;
choices.push( { message: label, value: version } );
} );
const images = Object.values( DEV_ENVIRONMENT_PHP_VERSIONS );
let initial = images.findIndex( version => version.image === initialValue );
Expand Down
4 changes: 2 additions & 2 deletions src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY,
DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL,
DEV_ENVIRONMENT_PHP_VERSIONS,
DEV_ENVIRONMENT_DEFAULT_PHP_VERSION,
DEV_ENVIRONMENT_VERSION,
} from '../constants/dev-environment';
import { createProxyAgent } from '../http/proxy-agent';
Expand Down Expand Up @@ -321,8 +322,7 @@ function preProcessInstanceData( instanceData: InstanceData ): Required< Instanc
mariadb: instanceData.mariadb ?? '',
elasticsearch: instanceData.elasticsearch || false, // NOSONAR
php:
instanceData.php ??
DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ].image,
instanceData.php ?? DEV_ENVIRONMENT_PHP_VERSIONS[ DEV_ENVIRONMENT_DEFAULT_PHP_VERSION ].image,
xdebug: Boolean( instanceData.xdebug ),
phpmyadmin: Boolean( instanceData.phpmyadmin ),
photon: Boolean( instanceData.photon ),
Expand Down
Loading