Skip to content

Commit 81259ac

Browse files
authored
feat(yarn): Remove code that handles yarn v1 (#507)
1 parent 78f2254 commit 81259ac

File tree

5 files changed

+19
-85
lines changed

5 files changed

+19
-85
lines changed

packages/cli/src/commands/__tests__/type-check.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ vi.mock('../../lib', async (importOriginal) => {
4343
}
4444
})
4545

46-
vi.mock('../../commands/upgrade', () => {
47-
return {
48-
getCmdMajorVersion: () => 3,
49-
}
50-
})
51-
5246
import path from 'path'
5347

5448
import concurrently from 'concurrently'
@@ -83,12 +77,12 @@ test('Should run tsc commands correctly, in order', async () => {
8377
// Ensure tsc command run correctly for web side
8478
expect(concurrentlyArgs.commands).toContainEqual({
8579
cwd: path.join('myBasePath', 'web'),
86-
command: 'yarn tsc --noEmit --skipLibCheck',
80+
command: 'yarn tsc --noEmit --skipLibCheck',
8781
})
8882
// Ensure tsc command run correctly for web side
8983
expect(concurrentlyArgs.commands).toContainEqual({
9084
cwd: path.join('myBasePath', 'api'),
91-
command: 'yarn tsc --noEmit --skipLibCheck',
85+
command: 'yarn tsc --noEmit --skipLibCheck',
9286
})
9387
// Ensure we have raw sequential output from tsc
9488
expect(concurrentlyArgs.options).toEqual({ group: true, raw: true })
@@ -108,8 +102,9 @@ test('Should generate prisma client', async () => {
108102
// Ensure tsc command run correctly for web side
109103
expect(concurrentlyArgs.commands).toContainEqual({
110104
cwd: path.join('myBasePath', 'api'),
111-
command: 'yarn tsc --noEmit --skipLibCheck',
105+
command: 'yarn tsc --noEmit --skipLibCheck',
112106
})
107+
113108
expect(runCommandTask.mock.results[0].value[0]).toMatch(
114109
/.+(\\|\/)prisma(\\|\/)build(\\|\/)index.js.+/,
115110
)

packages/cli/src/commands/setup/ui/libraries/tailwindcssHandler.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,9 @@ export const handler = async ({ force, install }) => {
116116
{
117117
title: `Install ${projectPackages.join(', ')}`,
118118
task: async () => {
119-
const yarnVersion = await execa('yarn', ['--version'])
120-
const isYarnV1 = yarnVersion.stdout.trim().startsWith('1')
121-
await execa(
122-
'yarn',
123-
[
124-
'add',
125-
'-D',
126-
...(isYarnV1 ? ['-W'] : []),
127-
...projectPackages,
128-
],
129-
{
130-
cwd: rwPaths.base,
131-
},
132-
)
119+
await execa('yarn', ['add', '-D', ...projectPackages], {
120+
cwd: rwPaths.base,
121+
})
133122
},
134123
},
135124
],

packages/cli/src/commands/type-checkHandler.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Listr } from 'listr2'
66

77
import { recordTelemetryAttributes } from '@cedarjs/cli-helpers'
88

9-
import { getCmdMajorVersion } from '../commands/upgrade.js'
109
import { generatePrismaClient } from '../lib/generatePrismaClient.js'
1110
import { getPaths } from '../lib/index.js'
1211

@@ -22,21 +21,14 @@ export const handler = async ({ sides, verbose, prisma, generate }) => {
2221
/**
2322
* Check types for the project directory : [web, api]
2423
*/
25-
2624
const typeCheck = async () => {
2725
let conclusiveExitCode = 0
2826

29-
const yarnVersion = await getCmdMajorVersion('yarn')
30-
3127
const tscForAllSides = sides.map((side) => {
3228
const projectDir = path.join(getPaths().base, side)
33-
// -s flag to suppress error output from yarn. For example yarn doc link on non-zero status.
34-
// Since it'll be printed anyways after the whole execution.
3529
return {
3630
cwd: projectDir,
37-
command: `yarn ${
38-
yarnVersion > 1 ? '' : '-s'
39-
} tsc --noEmit --skipLibCheck`,
31+
command: `yarn tsc --noEmit --skipLibCheck`,
4032
}
4133
})
4234

@@ -63,6 +55,7 @@ export const handler = async ({ sides, verbose, prisma, generate }) => {
6355
schema: getPaths().api.dbSchema,
6456
})
6557
}
58+
6659
if (generate) {
6760
await new Listr(
6861
[

packages/cli/src/commands/upgrade.js

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,12 @@ export const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => {
235235
await tasks.run()
236236
}
237237
async function yarnInstall({ verbose }) {
238-
const yarnVersion = await getCmdMajorVersion('yarn')
239-
240238
try {
241-
await execa(
242-
'yarn install',
243-
yarnVersion > 1 ? [] : ['--force', '--non-interactive'],
244-
{
245-
shell: true,
246-
stdio: verbose ? 'inherit' : 'pipe',
247-
248-
cwd: getPaths().base,
249-
},
250-
)
239+
await execa('yarn install', {
240+
shell: true,
241+
stdio: verbose ? 'inherit' : 'pipe',
242+
cwd: getPaths().base,
243+
})
251244
} catch (e) {
252245
throw new Error(
253246
'Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing',
@@ -515,41 +508,13 @@ async function refreshPrismaClient(task, { verbose }) {
515508
}
516509
}
517510

518-
export const getCmdMajorVersion = async (command) => {
519-
// Get current version
520-
const { stdout } = await execa(command, ['--version'], {
521-
cwd: getPaths().base,
522-
})
523-
524-
if (!SEMVER_REGEX.test(stdout)) {
525-
throw new Error(`Unable to verify ${command} version.`)
526-
}
527-
528-
// Get major version number
529-
const version = stdout.match(SEMVER_REGEX)[0]
530-
return parseInt(version.split('.')[0])
531-
}
532-
533511
const dedupeDeps = async (task, { verbose }) => {
534512
try {
535-
const yarnVersion = await getCmdMajorVersion('yarn')
536-
537-
const baseExecaArgsForDedupe = {
513+
await execa('yarn dedupe', {
538514
shell: true,
539515
stdio: verbose ? 'inherit' : 'pipe',
540516
cwd: getPaths().base,
541-
}
542-
if (yarnVersion > 1) {
543-
await execa('yarn', ['dedupe'], baseExecaArgsForDedupe)
544-
} else {
545-
// CedarJS projects should not be using yarn 1.x as we specify a version of yarn in the package.json
546-
// with "packageManager": "[email protected]" or similar.
547-
// Although we could (and previous did) automatically run `npx yarn-deduplicate` here, that would require
548-
// the user to have `npx` installed, which is not guaranteed and we do not wish to enforce that.
549-
task.skip(
550-
"Yarn 1.x doesn't support dedupe directly. Please upgrade yarn or use npx with `npx yarn-deduplicate` manually.",
551-
)
552-
}
517+
})
553518
} catch (e) {
554519
console.log(c.error(e.message))
555520
throw new Error(

packages/cli/src/lib/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { execSync } from 'child_process'
21
import https from 'https'
32
import path from 'path'
43

@@ -532,18 +531,11 @@ export const addPackagesTask = async ({
532531
].filter(Boolean),
533532
]
534533
} else {
535-
const stdout = execSync('yarn --version')
536-
537-
const yarnVersion = stdout.toString().trim()
538-
539534
installCommand = [
540535
'yarn',
541-
[
542-
yarnVersion.startsWith('1') && '-W',
543-
'add',
544-
devDependency && '--dev',
545-
...packagesWithSameRWVersion,
546-
].filter(Boolean),
536+
['add', devDependency && '--dev', ...packagesWithSameRWVersion].filter(
537+
Boolean,
538+
),
547539
]
548540
}
549541

0 commit comments

Comments
 (0)