@@ -38,21 +38,6 @@ const { telemetry } = Parser(hideBin(process.argv), {
38
38
39
39
const tui = new RedwoodTUI ( )
40
40
41
- // Credit to esbuild: https://github.com/rtsao/esbuild/blob/c35a4cebf037237559213abc684504658966f9d6/lib/install.ts#L190-L199
42
- function isYarnBerryOrNewer ( ) {
43
- const { npm_config_user_agent : npmConfigUserAgent } = process . env
44
-
45
- if ( npmConfigUserAgent ) {
46
- const match = npmConfigUserAgent . match ( / y a r n \/ ( \d + ) / )
47
-
48
- if ( match && match [ 1 ] ) {
49
- return parseInt ( match [ 1 ] , 10 ) >= 2
50
- }
51
- }
52
-
53
- return false
54
- }
55
-
56
41
const USE_GITPOD_TEXT = [
57
42
` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.` ,
58
43
` See: ${ terminalLink (
@@ -250,7 +235,10 @@ async function installNodeModules(newAppDir) {
250
235
} )
251
236
tui . startReactive ( tuiContent )
252
237
253
- const yarnInstallSubprocess = execa ( 'yarn install' , {
238
+ const oldCwd = process . cwd ( )
239
+ process . chdir ( newAppDir )
240
+
241
+ const yarnInstallSubprocess = execa ( `yarn install` , {
254
242
shell : true ,
255
243
cwd : newAppDir ,
256
244
} )
@@ -271,9 +259,12 @@ async function installNodeModules(newAppDir) {
271
259
)
272
260
recordErrorViaTelemetry ( error )
273
261
await shutdownTelemetry ( )
262
+ process . chdir ( oldCwd )
274
263
process . exit ( 1 )
275
264
}
276
265
266
+ process . chdir ( oldCwd )
267
+
277
268
tuiContent . update ( {
278
269
header : '' ,
279
270
content : `${ RedwoodStyling . green ( '✔' ) } Installed node modules` ,
@@ -611,6 +602,11 @@ async function handleCommitMessagePreference(commitMessageFlag) {
611
602
async function handleYarnInstallPreference ( yarnInstallFlag ) {
612
603
// Handle case where flag is set
613
604
if ( yarnInstallFlag !== null ) {
605
+ tui . drawText (
606
+ `${ RedwoodStyling . green ( '✔' ) } ${
607
+ yarnInstallFlag ? 'Will' : 'Will not'
608
+ } run yarn install based on command line flag`
609
+ )
614
610
return yarnInstallFlag
615
611
}
616
612
@@ -673,6 +669,11 @@ async function createRedwoodApp() {
673
669
type : 'string' ,
674
670
describe : 'Commit message for the initial commit' ,
675
671
} )
672
+ . option ( 'yarn-install' , {
673
+ default : null ,
674
+ type : 'boolean' ,
675
+ describe : 'Install node modules. Skip via --no-yarn-install.' ,
676
+ } )
676
677
. option ( 'telemetry' , {
677
678
default : true ,
678
679
type : 'boolean' ,
@@ -692,22 +693,10 @@ async function createRedwoodApp() {
692
693
] . join ( '\n' )
693
694
)
694
695
695
- const _isYarnBerryOrNewer = isYarnBerryOrNewer ( )
696
-
697
- // Only permit the yarn install flag on yarn 1.
698
- if ( ! _isYarnBerryOrNewer ) {
699
- cli . option ( 'yarn-install' , {
700
- default : null ,
701
- type : 'boolean' ,
702
- describe : 'Install node modules. Skip via --no-yarn-install.' ,
703
- } )
704
- }
705
-
706
696
// Extract the args as provided by the user in the command line
707
697
// TODO: Make all flags have the 'flag' suffix
708
698
const args = parsedFlags . _
709
- const yarnInstallFlag =
710
- parsedFlags [ 'yarn-install' ] ?? ! _isYarnBerryOrNewer ? parsedFlags . yes : null
699
+ const yarnInstallFlag = parsedFlags [ 'yarn-install' ] ?? parsedFlags . yes
711
700
const typescriptFlag = parsedFlags . typescript ?? parsedFlags . yes
712
701
const overwrite = parsedFlags . overwrite
713
702
const gitInitFlag = parsedFlags [ 'git-init' ] ?? parsedFlags . yes
@@ -745,11 +734,7 @@ async function createRedwoodApp() {
745
734
commitMessage = await handleCommitMessagePreference ( commitMessageFlag )
746
735
}
747
736
748
- let yarnInstall = false
749
-
750
- if ( ! _isYarnBerryOrNewer ) {
751
- yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
752
- }
737
+ const yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
753
738
754
739
let newAppDir = path . resolve ( process . cwd ( ) , targetDir )
755
740
@@ -765,9 +750,7 @@ async function createRedwoodApp() {
765
750
. getActiveSpan ( )
766
751
?. setAttribute ( 'yarn-install-time' , Date . now ( ) - yarnInstallStart )
767
752
} else {
768
- if ( ! _isYarnBerryOrNewer ) {
769
- tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
770
- }
753
+ tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
771
754
}
772
755
773
756
// Generate types
0 commit comments