Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crwa): remove yarn install preference #9859

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 0 additions & 172 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ const { telemetry } = Parser(hideBin(process.argv), {

const tui = new RedwoodTUI()

// Credit to esbuild: https://github.com/rtsao/esbuild/blob/c35a4cebf037237559213abc684504658966f9d6/lib/install.ts#L190-L199
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 @@ -239,94 +224,6 @@ async function createProjectFiles(appDir, { templateDir, overwrite }) {
return newAppDir
}

async function installNodeModules(newAppDir) {
const tuiContent = new ReactiveTUIContent({
mode: 'text',
header: 'Installing node modules',
content: ' ⏱ This could take a while...',
spinner: {
enabled: true,
},
})
tui.startReactive(tuiContent)

const yarnInstallSubprocess = execa('yarn install', {
shell: true,
cwd: newAppDir,
})

try {
await yarnInstallSubprocess
} catch (error) {
tui.stopReactive(true)
tui.displayError(
"Couldn't install node modules",
[
`We couldn't install node modules via ${RedwoodStyling.info(
"'yarn install'"
)}. Please see below for the full error message.`,
'',
error,
].join('\n')
)
recordErrorViaTelemetry(error)
await shutdownTelemetry()
process.exit(1)
}

tuiContent.update({
header: '',
content: `${RedwoodStyling.green('βœ”')} Installed node modules`,
spinner: {
enabled: false,
},
})
tui.stopReactive()
}

async function generateTypes(newAppDir) {
const tuiContent = new ReactiveTUIContent({
mode: 'text',
content: 'Generating types',
spinner: {
enabled: true,
},
})
tui.startReactive(tuiContent)

const generateSubprocess = execa('yarn rw-gen', {
shell: true,
cwd: newAppDir,
})

try {
await generateSubprocess
} catch (error) {
tui.stopReactive(true)
tui.displayError(
"Couldn't generate types",
[
`We could not generate types using ${RedwoodStyling.info(
"'yarn rw-gen'"
)}. Please see below for the full error message.`,
'',
error,
].join('\n')
)
recordErrorViaTelemetry(error)
await shutdownTelemetry()
process.exit(1)
}

tuiContent.update({
content: `${RedwoodStyling.green('βœ”')} Generated types`,
spinner: {
enabled: false,
},
})
tui.stopReactive()
}

async function initializeGit(newAppDir, commitMessage) {
const tuiContent = new ReactiveTUIContent({
mode: 'text',
Expand Down Expand Up @@ -605,33 +502,6 @@ async function handleCommitMessagePreference(commitMessageFlag) {
}
}

/**
* @param {boolean?} yarnInstallFlag
*/
async function handleYarnInstallPreference(yarnInstallFlag) {
// Handle case where flag is set
if (yarnInstallFlag !== null) {
return yarnInstallFlag
}

// Prompt user for preference
try {
const response = await tui.prompt({
type: 'Toggle',
name: 'yarnInstall',
message: 'Do you want to run yarn install?',
enabled: 'Yes',
disabled: 'no',
initial: 'Yes',
})
return response.yarnInstall
} catch (_error) {
recordErrorViaTelemetry('User cancelled install at yarn install prompt')
await shutdownTelemetry()
process.exit(1)
}
}

/**
* This function creates a new RedwoodJS app.
*
Expand Down Expand Up @@ -692,22 +562,9 @@ async function createRedwoodApp() {
].join('\n')
)

const _isYarnBerryOrNewer = isYarnBerryOrNewer()

// Only permit the yarn install flag on yarn 1.
if (!_isYarnBerryOrNewer) {
cli.option('yarn-install', {
default: null,
type: 'boolean',
describe: 'Install node modules. Skip via --no-yarn-install.',
})
}

// 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'] ?? !_isYarnBerryOrNewer ? parsedFlags.yes : null
const typescriptFlag = parsedFlags.typescript ?? parsedFlags.yes
const overwrite = parsedFlags.overwrite
const gitInitFlag = parsedFlags['git-init'] ?? parsedFlags.yes
Expand All @@ -716,7 +573,6 @@ async function createRedwoodApp() {
(parsedFlags.yes ? INITIAL_COMMIT_MESSAGE : null)

// Record some of the arguments for telemetry
trace.getActiveSpan()?.setAttribute('yarn-install', yarnInstallFlag)
trace.getActiveSpan()?.setAttribute('overwrite', overwrite)

// Get the directory for installation from the args
Expand Down Expand Up @@ -745,36 +601,12 @@ async function createRedwoodApp() {
commitMessage = await handleCommitMessagePreference(commitMessageFlag)
}

let yarnInstall = false

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

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

// Create project files
// if this directory already exists then createProjectFiles may set a new directory name
newAppDir = await createProjectFiles(newAppDir, { templateDir, overwrite })

// Install the node packages
if (yarnInstall) {
const yarnInstallStart = Date.now()
await installNodeModules(newAppDir)
trace
.getActiveSpan()
?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
} else {
if (!_isYarnBerryOrNewer) {
tui.drawText(`${RedwoodStyling.info('β„Ή')} Skipped yarn install step`)
}
}

// Generate types
if (yarnInstall) {
await generateTypes(newAppDir)
}

// Initialize git repo
if (useGit) {
await initializeGit(newAppDir, commitMessage)
Expand All @@ -798,10 +630,6 @@ async function createRedwoodApp() {
`cd ${path.relative(process.cwd(), newAppDir)}`
)}`
)}`,
!yarnInstall &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic is flipped here. We should always include the instruction to run yarn install now, right?
(Hold changing anything, I'm still reviewing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you're right I think oversight on my part in making this too fast

`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`yarn install`)}`
)}`,
`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`yarn rw dev`)}`
)}`,
Expand Down
1 change: 0 additions & 1 deletion packages/create-redwood-app/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ describe('create-redwood-app', () => {
Fire it up! πŸš€

> cd redwood-app
> yarn install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change should be reverted

> yarn rw dev

[?25lβœ” Initialized a git repo with commit message "Initial commit"
Expand Down
Loading