@@ -2,28 +2,16 @@ const pjson = require('../package.json');
22const shelljs = require ( 'shelljs' ) ;
33
44const getVersion = ( ) => {
5- const sfdxVersion = pjson . version ;
6-
7- // Get all npm dist-tags for sfdx-cli
8- const distTags = JSON . parse ( shelljs . exec ( 'npm view sfdx-cli dist-tags --json' , { silent : true } ) . stdout . trim ( ) ) ;
9-
10- // Attempt to find a dist-tag that matches the sfdx-cli package.json version
11- const distTag = Object . entries ( distTags ) . find ( ( [ , version ] ) => version === sfdxVersion ) ;
12-
13- // If we found a dist-tag, get the version of @salesforce/cli for the same dist-tag
14- // Note: the --silent flag causes the command to return an empty string if the version is not found
15- let sfVersion = distTag ?. [ 0 ]
16- ? shelljs . exec ( `npm view @salesforce/cli@${ distTag [ 0 ] } version --silent` , { silent : true } ) . stdout . trim ( )
17- : undefined ;
5+ // Now that `sf@2.x` is released, we will only ever bundle sf@legacy
6+ const sfVersion = shelljs . exec ( 'npm view @salesforce/cli@legacy version --silent' , { silent : true } ) . stdout . trim ( ) ;
187
198 // Make sure that sfVersion is set and it does not start with 2
20- if ( ! sfVersion || sfVersion . startsWith ( '2' ) ) {
21- // If it does, get the latest version that starts with 1 (we do not want to ever bundle version 2 of @salesforce/cli)
22- // We cannot use @salesforce /cli@^1 because that will not get versions higher than what is tagged as "latest"
23- const versions = JSON . parse (
24- shelljs . exec ( 'npm view @salesforce/cli versions --json' , { silent : true } ) . stdout . trim ( )
25- ) ;
26- sfVersion = versions . reverse ( ) . find ( ( v ) => v . startsWith ( '1.' ) && ! v . includes ( '-' ) ) ;
9+ if ( ! sfVersion ) {
10+ throw new Error ( 'Unable to determine the version of @salesforce/cli@legacy' ) ;
11+ }
12+
13+ if ( sfVersion . startsWith ( '2' ) ) {
14+ throw new Error ( `@salesforce/cli@legacy version ${ sfVersion } starts with 2. Only bundle 1.x versions.` ) ;
2715 }
2816
2917 // Leave this console.log so that we can pull this value from stdout when running this script from the command line
0 commit comments