Skip to content

Commit

Permalink
Merge pull request #2098 from Automattic/update/nodejs_versions_and_f…
Browse files Browse the repository at this point in the history
…ormat

Updating Node.js versions and standardize the format
  • Loading branch information
luiztiago authored Nov 14, 2024
2 parents 7eb1f15 + daad20e commit af2ae4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/bin/vip-validate-preflight.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { parseEnvAliasFromArgv } from '../lib/cli/envAlias';
import * as exit from '../lib/cli/exit';
import { trackEvent } from '../lib/tracker';

const ALLOWED_NODEJS_VERSIONS = [ '14', '16', '18' ];
const ALLOWED_NODEJS_VERSIONS = [ '18', '20', '22' ];

export const appQuery = `
id
Expand All @@ -50,7 +50,7 @@ export const appQuery = `
`;

let suppressOutput = false;
let outputJson = false;
let outputFormat = 'table';

let harmoniaArgs = [];

Expand Down Expand Up @@ -382,7 +382,7 @@ async function handleResults( harmonia, results ) {
} );

// If the output is JSON, reenable the logToConsole output and print-out the json format.
if ( outputJson ) {
if ( outputFormat === 'json' ) {
suppressOutput = false;
logToConsole( harmonia.resultsJSON() );
process.exit( 0 );
Expand Down Expand Up @@ -490,9 +490,9 @@ async function validateArgs( opt ) {
}

// If the JSON option is enabled, all the stdout should be suppressed to prevent polluting the output.
if ( opt.json ) {
if ( opt.format === 'json' ) {
suppressOutput = true;
outputJson = true;
outputFormat = 'json';
}

if ( opt.app ) {
Expand Down Expand Up @@ -588,7 +588,9 @@ command( commandOpts )
)
.option(
'node-version',
'Select a specific target Node.JS version in semver format (MAJOR.MINOR.PATCH) or a MAJOR'
`Select a specific target Node.JS version in semver format (MAJOR.MINOR.PATCH) or a MAJOR (${ ALLOWED_NODEJS_VERSIONS.join(
', '
) })`
)
.option(
'wait',
Expand All @@ -599,7 +601,7 @@ command( commandOpts )
[ 'p', 'port' ],
'Configure the port to use for the app (defaults to a random port between 3001 and 3999)'
)
.option( 'json', 'Output the results as JSON', false )
.option( 'format', 'Output the log lines in CSV or JSON format', 'table' )
.option( [ 'P', 'path' ], 'Path to the app to be tested', process.cwd() )
.examples( [
{
Expand All @@ -608,7 +610,7 @@ command( commandOpts )
'Runs the preflight tests to validate if your application is ready to be deployed to VIP Go',
},
{
usage: 'vip @mysite.production validate preflight --json > results.json',
usage: 'vip @mysite.production validate preflight --format json > results.json',
description:
'Runs the preflight tests, but output the results in JSON format, and redirect the output to a file',
},
Expand Down
11 changes: 9 additions & 2 deletions src/lib/config/software.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ interface VersionChoice {
message: string;
value: string;
disabled?: boolean;
deprecated?: boolean;
}

interface VersionChoices {
Expand All @@ -175,16 +176,19 @@ const _optionsForVersion = ( softwareSettings: SoftwareSetting ): VersionChoice[
versionChoices.deprecated.push( {
message: `${ option.version } (deprecated)`,
value: option.version,
deprecated: option.deprecated,
} );
} else if ( option.unstable ) {
versionChoices.test.push( {
message: `${ option.version } (test)`,
value: option.version,
deprecated: option.deprecated,
} );
} else {
versionChoices.supported.push( {
message: option.version,
value: option.version,
deprecated: option.deprecated,
} );
}
}
Expand Down Expand Up @@ -431,9 +435,12 @@ export const formatSoftwareSettings = (
};

if ( includes.includes( 'available_versions' ) ) {
result.available_versions = _optionsForVersion( softwareSetting ).map( option => option.value );
result.available_versions = _optionsForVersion( softwareSetting )
.filter( option => ! option.deprecated )
.map( option => option.value );

if ( format !== 'json' ) {
result.available_versions = result.available_versions.join( ',' );
result.available_versions = result.available_versions.sort().join( ',' );
}
}

Expand Down

0 comments on commit af2ae4e

Please sign in to comment.