From f0e9a4fa4e7bc886286886992f18c2f5c9f4ead9 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 21 Jan 2024 16:04:53 +0100 Subject: [PATCH 1/2] feat(crwa): Offer to install with all yarn versions --- .../src/create-redwood-app.js | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 7f53b18731e9..bd3d75d9596d 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -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( @@ -250,7 +235,10 @@ async function installNodeModules(newAppDir) { }) tui.startReactive(tuiContent) - const yarnInstallSubprocess = execa('yarn install', { + const oldCwd = process.cwd() + process.chdir(newAppDir) + + const yarnInstallSubprocess = execa(`yarn install`, { shell: true, cwd: newAppDir, }) @@ -271,9 +259,12 @@ async function installNodeModules(newAppDir) { ) recordErrorViaTelemetry(error) await shutdownTelemetry() + process.chdir(oldCwd) process.exit(1) } + process.chdir(oldCwd) + tuiContent.update({ header: '', content: `${RedwoodStyling.green('✔')} Installed node modules`, @@ -611,6 +602,11 @@ async function handleCommitMessagePreference(commitMessageFlag) { async function handleYarnInstallPreference(yarnInstallFlag) { // Handle case where flag is set if (yarnInstallFlag !== null) { + tui.drawText( + `${RedwoodStyling.green('✔')} ${ + yarnInstallFlag ? 'Will' : 'Will not' + } run yarn install based on command line flag` + ) return yarnInstallFlag } @@ -673,6 +669,11 @@ 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('telemetry', { default: true, type: 'boolean', @@ -692,22 +693,10 @@ 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 yarnInstallFlag = parsedFlags['yarn-install'] ?? parsedFlags.yes const typescriptFlag = parsedFlags.typescript ?? parsedFlags.yes const overwrite = parsedFlags.overwrite const gitInitFlag = parsedFlags['git-init'] ?? parsedFlags.yes @@ -745,11 +734,7 @@ async function createRedwoodApp() { commitMessage = await handleCommitMessagePreference(commitMessageFlag) } - let yarnInstall = false - - if (!_isYarnBerryOrNewer) { - yarnInstall = await handleYarnInstallPreference(yarnInstallFlag) - } + const yarnInstall = await handleYarnInstallPreference(yarnInstallFlag) let newAppDir = path.resolve(process.cwd(), targetDir) @@ -765,9 +750,7 @@ async function createRedwoodApp() { .getActiveSpan() ?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart) } else { - if (!_isYarnBerryOrNewer) { - tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`) - } + tui.drawText(`${RedwoodStyling.info('ℹ')} Skipped yarn install step`) } // Generate types From f0ede66827f8dbce8648361738814af0f395fe0c Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 21 Jan 2024 22:13:12 +0100 Subject: [PATCH 2/2] update crwa e2e tests --- packages/create-redwood-app/tests/e2e.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/create-redwood-app/tests/e2e.test.ts b/packages/create-redwood-app/tests/e2e.test.ts index 50ea12a89793..d81e411c58d7 100644 --- a/packages/create-redwood-app/tests/e2e.test.ts +++ b/packages/create-redwood-app/tests/e2e.test.ts @@ -28,6 +28,8 @@ describe('create-redwood-app', () => { --git-init, --git Initialize a git repository [boolean] [default: null] -m, --commit-message Commit message for the initial commit [string] [default: null] + --yarn-install Install node modules. Skip via --no-yarn-install. + [boolean] [default: null] --telemetry Enables sending telemetry events for this create command and all Redwood CLI commands https://telemetry.redwoodjs.com @@ -64,6 +66,7 @@ describe('create-redwood-app', () => { [?25h✔ Creating your Redwood app in ./redwood-app based on command line argument ✔ Using TypeScript based on command line flag ✔ Will initialize a git repo based on command line flag + ✔ Will run yarn install based on command line flag [?25l⠋ Creating project files [?25h[?25l✔ Project files created [?25h[?25l⠋ Initializing a git repo