@@ -30,6 +30,20 @@ const { telemetry } = Parser(hideBin(process.argv))
30
30
31
31
const tui = new RedwoodTUI ( )
32
32
33
+ function isYarnBerryOrNewer ( ) {
34
+ const { npm_config_user_agent : npmConfigUserAgent } = process . env
35
+
36
+ if ( npmConfigUserAgent ) {
37
+ const match = npmConfigUserAgent . match ( / y a r n \/ ( \d + ) / )
38
+
39
+ if ( match && match [ 1 ] ) {
40
+ return parseInt ( match [ 1 ] , 10 ) >= 2
41
+ }
42
+ }
43
+
44
+ return false
45
+ }
46
+
33
47
const USE_GITPOD_TEXT = [
34
48
` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.` ,
35
49
` See: ${ terminalLink (
@@ -711,11 +725,6 @@ async function createRedwoodApp() {
711
725
type : 'string' ,
712
726
describe : 'Commit message for the initial commit.' ,
713
727
} )
714
- . option ( 'yarn-install' , {
715
- default : null ,
716
- type : 'boolean' ,
717
- describe : 'Install node modules. Skip via --no-yarn-install.' ,
718
- } )
719
728
. option ( 'yes' , {
720
729
alias : 'y' ,
721
730
default : null ,
@@ -724,12 +733,24 @@ async function createRedwoodApp() {
724
733
} )
725
734
. version ( version )
726
735
736
+ const _isYarnBerryOrNewer = isYarnBerryOrNewer ( )
737
+
738
+ // Only add the yarn-install flag if the yarn version is >= 2
739
+ if ( _isYarnBerryOrNewer ) {
740
+ cli . option ( 'yarn-install' , {
741
+ default : null ,
742
+ type : 'boolean' ,
743
+ describe : 'Install node modules. Skip via --no-yarn-install.' ,
744
+ } )
745
+ }
746
+
727
747
const parsedFlags = cli . parse ( )
728
748
729
749
// Extract the args as provided by the user in the command line
730
750
// TODO: Make all flags have the 'flag' suffix
731
751
const args = parsedFlags . _
732
- const yarnInstallFlag = parsedFlags [ 'yarn-install' ] ?? parsedFlags . yes
752
+ const yarnInstallFlag =
753
+ parsedFlags [ 'yarn-install' ] ?? _isYarnBerryOrNewer ? parsedFlags . yes : null
733
754
const typescriptFlag = parsedFlags . typescript ?? parsedFlags . yes
734
755
const overwrite = parsedFlags . overwrite
735
756
// telemetry, // Extracted above to check if telemetry is disabled before we even reach this point
@@ -768,7 +789,11 @@ async function createRedwoodApp() {
768
789
commitMessage = await handleCommitMessagePreference ( commitMessageFlag )
769
790
}
770
791
771
- const yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
792
+ let yarnInstall = false
793
+
794
+ if ( _isYarnBerryOrNewer ) {
795
+ yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
796
+ }
772
797
773
798
let newAppDir = path . resolve ( process . cwd ( ) , targetDir )
774
799
@@ -784,7 +809,9 @@ async function createRedwoodApp() {
784
809
. getActiveSpan ( )
785
810
?. setAttribute ( 'yarn-install-time' , Date . now ( ) - yarnInstallStart )
786
811
} else {
787
- tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
812
+ if ( _isYarnBerryOrNewer ) {
813
+ tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
814
+ }
788
815
}
789
816
790
817
// Generate types
0 commit comments