diff --git a/packages/cli/src/commands/__tests__/type-check.test.js b/packages/cli/src/commands/__tests__/type-check.test.js index 0eb9923463..15729a189a 100644 --- a/packages/cli/src/commands/__tests__/type-check.test.js +++ b/packages/cli/src/commands/__tests__/type-check.test.js @@ -43,12 +43,6 @@ vi.mock('../../lib', async (importOriginal) => { } }) -vi.mock('../../commands/upgrade', () => { - return { - getCmdMajorVersion: () => 3, - } -}) - import path from 'path' import concurrently from 'concurrently' @@ -83,12 +77,12 @@ test('Should run tsc commands correctly, in order', async () => { // Ensure tsc command run correctly for web side expect(concurrentlyArgs.commands).toContainEqual({ cwd: path.join('myBasePath', 'web'), - command: 'yarn tsc --noEmit --skipLibCheck', + command: 'yarn tsc --noEmit --skipLibCheck', }) // Ensure tsc command run correctly for web side expect(concurrentlyArgs.commands).toContainEqual({ cwd: path.join('myBasePath', 'api'), - command: 'yarn tsc --noEmit --skipLibCheck', + command: 'yarn tsc --noEmit --skipLibCheck', }) // Ensure we have raw sequential output from tsc expect(concurrentlyArgs.options).toEqual({ group: true, raw: true }) @@ -108,8 +102,9 @@ test('Should generate prisma client', async () => { // Ensure tsc command run correctly for web side expect(concurrentlyArgs.commands).toContainEqual({ cwd: path.join('myBasePath', 'api'), - command: 'yarn tsc --noEmit --skipLibCheck', + command: 'yarn tsc --noEmit --skipLibCheck', }) + expect(runCommandTask.mock.results[0].value[0]).toMatch( /.+(\\|\/)prisma(\\|\/)build(\\|\/)index.js.+/, ) diff --git a/packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js b/packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js index bc14906e58..7b7d61e5b1 100644 --- a/packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js +++ b/packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js @@ -116,20 +116,9 @@ export const handler = async ({ force, install }) => { { title: `Install ${projectPackages.join(', ')}`, task: async () => { - const yarnVersion = await execa('yarn', ['--version']) - const isYarnV1 = yarnVersion.stdout.trim().startsWith('1') - await execa( - 'yarn', - [ - 'add', - '-D', - ...(isYarnV1 ? ['-W'] : []), - ...projectPackages, - ], - { - cwd: rwPaths.base, - }, - ) + await execa('yarn', ['add', '-D', ...projectPackages], { + cwd: rwPaths.base, + }) }, }, ], diff --git a/packages/cli/src/commands/type-checkHandler.js b/packages/cli/src/commands/type-checkHandler.js index 7757fd94c5..0eb59b79a8 100644 --- a/packages/cli/src/commands/type-checkHandler.js +++ b/packages/cli/src/commands/type-checkHandler.js @@ -6,7 +6,6 @@ import { Listr } from 'listr2' import { recordTelemetryAttributes } from '@cedarjs/cli-helpers' -import { getCmdMajorVersion } from '../commands/upgrade.js' import { generatePrismaClient } from '../lib/generatePrismaClient.js' import { getPaths } from '../lib/index.js' @@ -22,21 +21,14 @@ export const handler = async ({ sides, verbose, prisma, generate }) => { /** * Check types for the project directory : [web, api] */ - const typeCheck = async () => { let conclusiveExitCode = 0 - const yarnVersion = await getCmdMajorVersion('yarn') - const tscForAllSides = sides.map((side) => { const projectDir = path.join(getPaths().base, side) - // -s flag to suppress error output from yarn. For example yarn doc link on non-zero status. - // Since it'll be printed anyways after the whole execution. return { cwd: projectDir, - command: `yarn ${ - yarnVersion > 1 ? '' : '-s' - } tsc --noEmit --skipLibCheck`, + command: `yarn tsc --noEmit --skipLibCheck`, } }) @@ -63,6 +55,7 @@ export const handler = async ({ sides, verbose, prisma, generate }) => { schema: getPaths().api.dbSchema, }) } + if (generate) { await new Listr( [ diff --git a/packages/cli/src/commands/upgrade.js b/packages/cli/src/commands/upgrade.js index 844b351e19..750cf19ca2 100644 --- a/packages/cli/src/commands/upgrade.js +++ b/packages/cli/src/commands/upgrade.js @@ -235,19 +235,12 @@ export const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => { await tasks.run() } async function yarnInstall({ verbose }) { - const yarnVersion = await getCmdMajorVersion('yarn') - try { - await execa( - 'yarn install', - yarnVersion > 1 ? [] : ['--force', '--non-interactive'], - { - shell: true, - stdio: verbose ? 'inherit' : 'pipe', - - cwd: getPaths().base, - }, - ) + await execa('yarn install', { + shell: true, + stdio: verbose ? 'inherit' : 'pipe', + cwd: getPaths().base, + }) } catch (e) { throw new Error( 'Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing', @@ -515,41 +508,13 @@ async function refreshPrismaClient(task, { verbose }) { } } -export const getCmdMajorVersion = async (command) => { - // Get current version - const { stdout } = await execa(command, ['--version'], { - cwd: getPaths().base, - }) - - if (!SEMVER_REGEX.test(stdout)) { - throw new Error(`Unable to verify ${command} version.`) - } - - // Get major version number - const version = stdout.match(SEMVER_REGEX)[0] - return parseInt(version.split('.')[0]) -} - const dedupeDeps = async (task, { verbose }) => { try { - const yarnVersion = await getCmdMajorVersion('yarn') - - const baseExecaArgsForDedupe = { + await execa('yarn dedupe', { shell: true, stdio: verbose ? 'inherit' : 'pipe', cwd: getPaths().base, - } - if (yarnVersion > 1) { - await execa('yarn', ['dedupe'], baseExecaArgsForDedupe) - } else { - // CedarJS projects should not be using yarn 1.x as we specify a version of yarn in the package.json - // with "packageManager": "yarn@4.6.0" or similar. - // Although we could (and previous did) automatically run `npx yarn-deduplicate` here, that would require - // the user to have `npx` installed, which is not guaranteed and we do not wish to enforce that. - task.skip( - "Yarn 1.x doesn't support dedupe directly. Please upgrade yarn or use npx with `npx yarn-deduplicate` manually.", - ) - } + }) } catch (e) { console.log(c.error(e.message)) throw new Error( diff --git a/packages/cli/src/lib/index.js b/packages/cli/src/lib/index.js index b1866ba29c..9b325f99b5 100644 --- a/packages/cli/src/lib/index.js +++ b/packages/cli/src/lib/index.js @@ -1,4 +1,3 @@ -import { execSync } from 'child_process' import https from 'https' import path from 'path' @@ -532,18 +531,11 @@ export const addPackagesTask = async ({ ].filter(Boolean), ] } else { - const stdout = execSync('yarn --version') - - const yarnVersion = stdout.toString().trim() - installCommand = [ 'yarn', - [ - yarnVersion.startsWith('1') && '-W', - 'add', - devDependency && '--dev', - ...packagesWithSameRWVersion, - ].filter(Boolean), + ['add', devDependency && '--dev', ...packagesWithSameRWVersion].filter( + Boolean, + ), ] }