@@ -38,21 +38,6 @@ const { telemetry } = Parser(hideBin(process.argv), {
3838
3939const tui = new RedwoodTUI ( )
4040
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-
5641const USE_GITPOD_TEXT = [
5742 ` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.` ,
5843 ` See: ${ terminalLink (
@@ -250,7 +235,10 @@ async function installNodeModules(newAppDir) {
250235 } )
251236 tui . startReactive ( tuiContent )
252237
253- const yarnInstallSubprocess = execa ( 'yarn install' , {
238+ const oldCwd = process . cwd ( )
239+ process . chdir ( newAppDir )
240+
241+ const yarnInstallSubprocess = execa ( `yarn install` , {
254242 shell : true ,
255243 cwd : newAppDir ,
256244 } )
@@ -271,9 +259,12 @@ async function installNodeModules(newAppDir) {
271259 )
272260 recordErrorViaTelemetry ( error )
273261 await shutdownTelemetry ( )
262+ process . chdir ( oldCwd )
274263 process . exit ( 1 )
275264 }
276265
266+ process . chdir ( oldCwd )
267+
277268 tuiContent . update ( {
278269 header : '' ,
279270 content : `${ RedwoodStyling . green ( '✔' ) } Installed node modules` ,
@@ -611,6 +602,11 @@ async function handleCommitMessagePreference(commitMessageFlag) {
611602async function handleYarnInstallPreference ( yarnInstallFlag ) {
612603 // Handle case where flag is set
613604 if ( yarnInstallFlag !== null ) {
605+ tui . drawText (
606+ `${ RedwoodStyling . green ( '✔' ) } ${
607+ yarnInstallFlag ? 'Will' : 'Will not'
608+ } run yarn install based on command line flag`
609+ )
614610 return yarnInstallFlag
615611 }
616612
@@ -673,6 +669,11 @@ async function createRedwoodApp() {
673669 type : 'string' ,
674670 describe : 'Commit message for the initial commit' ,
675671 } )
672+ . option ( 'yarn-install' , {
673+ default : null ,
674+ type : 'boolean' ,
675+ describe : 'Install node modules. Skip via --no-yarn-install.' ,
676+ } )
676677 . option ( 'telemetry' , {
677678 default : true ,
678679 type : 'boolean' ,
@@ -692,22 +693,10 @@ async function createRedwoodApp() {
692693 ] . join ( '\n' )
693694 )
694695
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-
706696 // Extract the args as provided by the user in the command line
707697 // TODO: Make all flags have the 'flag' suffix
708698 const args = parsedFlags . _
709- const yarnInstallFlag =
710- parsedFlags [ 'yarn-install' ] ?? ! _isYarnBerryOrNewer ? parsedFlags . yes : null
699+ const yarnInstallFlag = parsedFlags [ 'yarn-install' ] ?? parsedFlags . yes
711700 const typescriptFlag = parsedFlags . typescript ?? parsedFlags . yes
712701 const overwrite = parsedFlags . overwrite
713702 const gitInitFlag = parsedFlags [ 'git-init' ] ?? parsedFlags . yes
@@ -745,11 +734,7 @@ async function createRedwoodApp() {
745734 commitMessage = await handleCommitMessagePreference ( commitMessageFlag )
746735 }
747736
748- let yarnInstall = false
749-
750- if ( ! _isYarnBerryOrNewer ) {
751- yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
752- }
737+ const yarnInstall = await handleYarnInstallPreference ( yarnInstallFlag )
753738
754739 let newAppDir = path . resolve ( process . cwd ( ) , targetDir )
755740
@@ -765,9 +750,7 @@ async function createRedwoodApp() {
765750 . getActiveSpan ( )
766751 ?. setAttribute ( 'yarn-install-time' , Date . now ( ) - yarnInstallStart )
767752 } else {
768- if ( ! _isYarnBerryOrNewer ) {
769- tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
770- }
753+ tui . drawText ( `${ RedwoodStyling . info ( 'ℹ' ) } Skipped yarn install step` )
771754 }
772755
773756 // Generate types
0 commit comments