Skip to content
Merged
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
13 changes: 4 additions & 9 deletions packages/cli/src/commands/__tests__/type-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ vi.mock('../../lib', async (importOriginal) => {
}
})

vi.mock('../../commands/upgrade', () => {
return {
getCmdMajorVersion: () => 3,
}
})

import path from 'path'

import concurrently from 'concurrently'
Expand Down Expand Up @@ -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 })
Expand All @@ -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.+/,
)
Expand Down
17 changes: 3 additions & 14 deletions packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
},
},
],
Expand Down
11 changes: 2 additions & 9 deletions packages/cli/src/commands/type-checkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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`,
}
})

Expand All @@ -63,6 +55,7 @@ export const handler = async ({ sides, verbose, prisma, generate }) => {
schema: getPaths().api.dbSchema,
})
}

if (generate) {
await new Listr(
[
Expand Down
49 changes: 7 additions & 42 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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": "[email protected]" 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(
Expand Down
14 changes: 3 additions & 11 deletions packages/cli/src/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { execSync } from 'child_process'
import https from 'https'
import path from 'path'

Expand Down Expand Up @@ -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,
),
]
}

Expand Down
Loading