Skip to content

Commit

Permalink
fix(crwa): remove yarn install pref for yarn 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar committed Jan 25, 2024
1 parent 675f3ad commit 786f0d0
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ const { telemetry } = Parser(hideBin(process.argv))

const tui = new RedwoodTUI()

function isYarnBerryOrNewer() {
const { npm_config_user_agent: npmConfigUserAgent } = process.env

if (npmConfigUserAgent) {
const match = npmConfigUserAgent.match(/yarn\/(\d+)/)

if (match && match[1]) {
return parseInt(match[1], 10) >= 2
}
}

return false
}

const USE_GITPOD_TEXT = [
` As an alternative solution, you can launch a Redwood project using GitPod instead. GitPod is a an online IDE.`,
` See: ${terminalLink(
Expand Down Expand Up @@ -711,11 +725,6 @@ async function createRedwoodApp() {
type: 'string',
describe: 'Commit message for the initial commit.',
})
.option('yarn-install', {
default: null,
type: 'boolean',
describe: 'Install node modules. Skip via --no-yarn-install.',
})
.option('yes', {
alias: 'y',
default: null,
Expand All @@ -724,12 +733,24 @@ async function createRedwoodApp() {
})
.version(version)

const _isYarnBerryOrNewer = isYarnBerryOrNewer()

// Only add the yarn-install flag if the yarn version is >= 2
if (_isYarnBerryOrNewer) {
cli.option('yarn-install', {
default: null,
type: 'boolean',
describe: 'Install node modules. Skip via --no-yarn-install.',
})
}

const parsedFlags = cli.parse()

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

const yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
let yarnInstall = false

if (_isYarnBerryOrNewer) {
yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
}

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

Expand All @@ -784,7 +809,9 @@ async function createRedwoodApp() {
.getActiveSpan()
?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
} else {
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
if (_isYarnBerryOrNewer) {
tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`)
}
}

// Generate types
Expand Down

0 comments on commit 786f0d0

Please sign in to comment.