Skip to content

Commit 786f0d0

Browse files
committed
fix(crwa): remove yarn install pref for yarn 1
1 parent 675f3ad commit 786f0d0

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

packages/create-redwood-app/src/create-redwood-app.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ const { telemetry } = Parser(hideBin(process.argv))
3030

3131
const tui = new RedwoodTUI()
3232

33+
function isYarnBerryOrNewer() {
34+
const { npm_config_user_agent: npmConfigUserAgent } = process.env
35+
36+
if (npmConfigUserAgent) {
37+
const match = npmConfigUserAgent.match(/yarn\/(\d+)/)
38+
39+
if (match && match[1]) {
40+
return parseInt(match[1], 10) >= 2
41+
}
42+
}
43+
44+
return false
45+
}
46+
3347
const USE_GITPOD_TEXT = [
3448
` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.`,
3549
` See: ${terminalLink(
@@ -711,11 +725,6 @@ async function createRedwoodApp() {
711725
type: 'string',
712726
describe: 'Commit message for the initial commit.',
713727
})
714-
.option('yarn-install', {
715-
default: null,
716-
type: 'boolean',
717-
describe: 'Install node modules. Skip via --no-yarn-install.',
718-
})
719728
.option('yes', {
720729
alias: 'y',
721730
default: null,
@@ -724,12 +733,24 @@ async function createRedwoodApp() {
724733
})
725734
.version(version)
726735

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+
727747
const parsedFlags = cli.parse()
728748

729749
// Extract the args as provided by the user in the command line
730750
// TODO: Make all flags have the 'flag' suffix
731751
const args = parsedFlags._
732-
const yarnInstallFlag = parsedFlags['yarn-install'] ?? parsedFlags.yes
752+
const yarnInstallFlag =
753+
parsedFlags['yarn-install'] ?? _isYarnBerryOrNewer ? parsedFlags.yes : null
733754
const typescriptFlag = parsedFlags.typescript ?? parsedFlags.yes
734755
const overwrite = parsedFlags.overwrite
735756
// telemetry, // Extracted above to check if telemetry is disabled before we even reach this point
@@ -768,7 +789,11 @@ async function createRedwoodApp() {
768789
commitMessage = await handleCommitMessagePreference(commitMessageFlag)
769790
}
770791

771-
const yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
792+
let yarnInstall = false
793+
794+
if (_isYarnBerryOrNewer) {
795+
yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
796+
}
772797

773798
let newAppDir = path.resolve(process.cwd(), targetDir)
774799

@@ -784,7 +809,9 @@ async function createRedwoodApp() {
784809
.getActiveSpan()
785810
?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
786811
} else {
787-
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
812+
if (_isYarnBerryOrNewer) {
813+
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
814+
}
788815
}
789816

790817
// Generate types

0 commit comments

Comments
 (0)