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

Enable yarn 3 for Redwood projects #4444

Merged
merged 48 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d14490d
get redwood working
redwoodjsbot Feb 24, 2022
8b54fe7
get storybook working
redwoodjsbot Feb 24, 2022
7b11c48
get lint working
redwoodjsbot Feb 24, 2022
a5b89f2
get build working
redwoodjsbot Feb 24, 2022
714e294
Update packages/cli/src/lib/generatePrismaClient.js
jtoar Feb 19, 2022
1c6045a
get dev working
redwoodjsbot Feb 24, 2022
7fa682d
get test working
redwoodjsbot Feb 19, 2022
d700136
get type-check working
redwoodjsbot Feb 19, 2022
1d93acb
get upgrade working
redwoodjsbot Feb 19, 2022
03a4beb
get setup ui tailwindcss working
redwoodjsbot Feb 19, 2022
5ee4f29
get rwfw working
redwoodjsbot Feb 19, 2022
9bae87e
get crwa working
redwoodjsbot Feb 24, 2022
8bf0a2b
[wip] get contributing flow and ci working
redwoodjsbot Feb 24, 2022
f7a7738
use project:deps:yarn3 script to link
redwoodjsbot Feb 24, 2022
c5f4439
rm non-interactive flag
redwoodjsbot Feb 24, 2022
66e18d6
revert engines req
redwoodjsbot Feb 24, 2022
ac50664
add script preamble
redwoodjsbot Feb 24, 2022
5def5a0
handle project:deps:yarn3 script on v1
redwoodjsbot Feb 24, 2022
411a384
handle upgrade on v1
redwoodjsbot Feb 24, 2022
f5ea110
handle type-check on v1
redwoodjsbot Feb 24, 2022
076a112
get build --stats, --perf working
redwoodjsbot Feb 24, 2022
5da7111
Merge branch 'main' into ds-upgrade-projects-to-yarn-3
thedavidprice Feb 25, 2022
5d8d1a9
update yarn.lock
thedavidprice Feb 25, 2022
45105f2
revert test project to yarn 1
redwoodjsbot Feb 25, 2022
31358db
test-project: use same yarn release
redwoodjsbot Feb 25, 2022
12d72f9
revert to using deps to link test project
redwoodjsbot Feb 25, 2022
ac62acd
[wip] add codemod
redwoodjsbot Feb 25, 2022
9ea6015
refactor e2e to run codemod, make it optional
redwoodjsbot Feb 25, 2022
c36a87d
try reverting test project fix
redwoodjsbot Feb 25, 2022
6009ab1
consider yarn3 deps temporary
redwoodjsbot Feb 25, 2022
3abc9af
iterate on ci
redwoodjsbot Feb 25, 2022
f4bce34
Revert "try reverting test project fix"
redwoodjsbot Feb 25, 2022
de6bc2f
fix bin permissions
redwoodjsbot Feb 25, 2022
656932e
get sb --build working
redwoodjsbot Feb 25, 2022
790d008
get serverless working
redwoodjsbot Feb 25, 2022
f9803f6
get test working
redwoodjsbot Feb 25, 2022
4f91533
finalizing things
redwoodjsbot Feb 25, 2022
50503d9
make project:deps:yarn3 a little cleaner
redwoodjsbot Feb 25, 2022
00a41c8
finalize e2e
redwoodjsbot Feb 25, 2022
bd10f97
get rw g types working
redwoodjsbot Feb 25, 2022
ebb021f
fix failing windows test
redwoodjsbot Feb 25, 2022
44d1d9f
Merge branch 'main' into ds-upgrade-projects-to-yarn-3
jtoar Feb 25, 2022
cb97ddd
fix ci
redwoodjsbot Feb 25, 2022
900de0c
fix regex, rm file
redwoodjsbot Feb 26, 2022
a14c7c0
Merge branch 'main' into ds-upgrade-projects-to-yarn-3
jtoar Feb 26, 2022
51e03ba
Merge branch 'main' into ds-upgrade-projects-to-yarn-3
thedavidprice Feb 28, 2022
8e4c774
fix(yarn3): Update cwd for yarn 1 backwards compatibility in bins
dac09 Mar 3, 2022
653df96
Merge branch 'main' of github.com:redwoodjs/redwood into ds-upgrade-p…
dac09 Mar 3, 2022
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
2 changes: 1 addition & 1 deletion __fixtures__/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"scripts": {
"postinstall": ""
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lint:fix": "yarn lint --fix",
"project:copy": "node ./tasks/framework-tools/frameworkFilesToProject.mjs",
"project:deps": "node ./tasks/framework-tools/frameworkDepsToProject.mjs",
"project:deps:yarn3": "node ./tasks/framework-tools/frameworkDepsToYarn3Project.mjs",
"project:sync": "node ./tasks/framework-tools/frameworkSyncToProject.mjs",
"publish:canary": "lerna publish --force-publish --canary --include-merged-tags --preid canary --dist-tag canary --yes --loglevel verbose",
"release": "node ./tasks/release/cli.mjs",
Expand Down
6 changes: 6 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"redwood": "./dist/bins/redwood.js",
"rw": "./dist/bins/redwood.js",
"rwfw": "./dist/bins/rwfw.js",
"tsc": "./dist/bins/tsc.js"
},
"files": [
"dist",
"logger",
Expand Down
11 changes: 11 additions & 0 deletions packages/api/src/bins/redwood.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
import { createRequire } from 'module'

const requireFromCli = createRequire(
require.resolve('@redwoodjs/cli/package.json')
)

const bins = requireFromCli('./package.json')['bin']

process.chdir('../')
requireFromCli(bins['redwood'])
11 changes: 11 additions & 0 deletions packages/api/src/bins/rwfw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
import { createRequire } from 'module'

const requireFromCli = createRequire(
require.resolve('@redwoodjs/cli/package.json')
)

const bins = requireFromCli('./package.json')['bin']

process.chdir('../')
requireFromCli(bins['rwfw'])
10 changes: 10 additions & 0 deletions packages/api/src/bins/tsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node
import { createRequire } from 'module'

const requireFromTypeScript = createRequire(
require.resolve('typescript/package.json')
)

const bins = requireFromTypeScript('./package.json')['bin']

requireFromTypeScript(bins['tsc'])
16 changes: 11 additions & 5 deletions packages/cli/src/commands/__tests__/type-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jest.mock('../../lib', () => {
}
})

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

import path from 'path'

import concurrently from 'concurrently'
Expand All @@ -70,12 +76,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 -s 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 -s 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 @@ -95,9 +101,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 -s tsc --noEmit --skipLibCheck',
command: 'yarn tsc --noEmit --skipLibCheck',
})
expect(runCommandTask.mock.results[0].value[0]).toEqual(
'yarn prisma generate --schema="../../__fixtures__/example-todo-main/api/prisma"'
expect(runCommandTask.mock.results[0].value[0]).toMatch(
/.+(\\|\/)prisma(\\|\/)build(\\|\/)index.js.+/
)
})
4 changes: 2 additions & 2 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const handler = async ({
`yarn cross-env NODE_ENV=production webpack --config ${require.resolve(
'@redwoodjs/core/config/webpack.perf.js'
)}`,
{ stdio: 'inherit', shell: true }
{ stdio: 'inherit', shell: true, cwd: rwjsPaths.web.base }
)
// We do not want to continue building...
return
Expand All @@ -110,7 +110,7 @@ export const handler = async ({
`yarn cross-env NODE_ENV=production webpack --config ${require.resolve(
'@redwoodjs/core/config/webpack.stats.js'
)}`,
{ stdio: 'inherit', shell: true }
{ stdio: 'inherit', shell: true, cwd: rwjsPaths.web.base }
)
// We do not want to continue building...
return
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/commands/setup/deploy/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from 'child_process'
import fs from 'fs'
import path from 'path'

Expand Down Expand Up @@ -114,10 +115,14 @@ export const addPackagesTask = ({
].filter(Boolean),
]
} else {
const { stdout } = spawnSync('yarn', ['--version'])

const yarnVersion = stdout.toString()

installCommand = [
'yarn',
[
'-W',
yarnVersion.startsWith('1') && '-W',
'add',
devDependency && '--dev',
...packagesWithSameRWVersion,
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/commands/setup/deploy/providers/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,22 @@ const updateRedwoodTomlTask = () => {
}

export const handler = async ({ force }) => {
const [serverless, serverlessLift, ...rest] = projectDevPackages

const tasks = new Listr(
[
addPackagesTask({
packages: projectDevPackages,
packages: [serverless, ...rest],
devDependency: true,
}),
addPackagesTask({
packages: [serverless, serverlessLift],
side: 'web',
devDependency: true,
}),
addPackagesTask({
packages: [serverless],
side: 'api',
devDependency: true,
}),
addFilesTask({
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/setup/ui/libraries/tailwindcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export const handler = async ({ force, install }) => {
}
}

await execa('yarn', ['tailwindcss', 'init', tailwindConfigPath])
await execa('yarn', ['tailwindcss', 'init', tailwindConfigPath], {
cwd: rwPaths.web.base,
})
Comment on lines +127 to +129
Copy link
Contributor

Choose a reason for hiding this comment

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

@jtoar curious if you tried setup ui chakra-ui?


// Replace `content`.
const tailwindConfig = fs.readFileSync(tailwindConfigPath, 'utf-8')
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/commands/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import terminalLink from 'terminal-link'
import { getProject } from '@redwoodjs/structure'
import { errorTelemetry } from '@redwoodjs/telemetry'

import { getCmdMajorVersion } from '../commands/upgrade'
import { getPaths } from '../lib'
import c from '../lib/colors'
import { generatePrismaClient } from '../lib/generatePrismaClient'
Expand Down Expand Up @@ -55,13 +56,17 @@ export const handler = async ({ sides, verbose, prisma, generate }) => {
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 -s tsc --noEmit --skipLibCheck`,
command: `yarn ${
Copy link
Contributor

Choose a reason for hiding this comment

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

@jtoar what if we created a helper for running yarn commands so all the logic is in one place? Something like runYarnCommand

yarnVersion > 1 ? '' : '-s'
} tsc --noEmit --skipLibCheck`,
}
})

Expand Down
19 changes: 13 additions & 6 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
}
}
async function yarnInstall({ verbose }) {
const yarnVersion = await getCmdMajorVersion('yarn')

try {
await execa('yarn install', ['--force', '--non-interactive'], {
shell: true,
stdio: verbose ? 'inherit' : 'pipe',
await execa(
'yarn install',
yarnVersion > 1 ? [] : ['--force', '--non-interactive'],
{
shell: true,
stdio: verbose ? 'inherit' : 'pipe',

cwd: getPaths().base,
})
cwd: getPaths().base,
}
)
} catch (e) {
throw new Error(
'Could not finish installation. Please run `yarn install --force`, before continuing'
Expand Down Expand Up @@ -253,11 +259,12 @@ async function refreshPrismaClient(task, { verbose }) {
}
}

const getCmdMajorVersion = async (command) => {
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.`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/generatePrismaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const generatePrismaCommand = (schema) => {
}

return {
cmd: 'yarn prisma',
cmd: `node "${require.resolve('prisma/build/index.js')}"`,
dac09 marked this conversation as resolved.
Show resolved Hide resolved
args: ['generate', schema && `--schema="${schema}"`],
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/rwfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ if (!command.length || command.some((cmd) => helpCommands.includes(cmd))) {
}

try {
execa.sync('yarn', ['--cwd', absRwFwPath, ...command], {
execa.sync('yarn', [...command], {
stdio: 'inherit',
shell: true,
cwd: absRwFwPath,
env: {
RWJS_CWD: projectPath,
},
Expand Down
21 changes: 21 additions & 0 deletions packages/codemods/src/codemods/v0.48.x/upgradeYarn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Upgrade Yarn

This codemod upgrades Redwood projects from yarn 1 to yarn 3.

The first thing it does is enable corepack:

```
corepack enable
```

Corepack is a new thing in the Node.js core—it essentially packages yarn with node so that it doesn't have to be installed separately.
Its only available on node >= `v14.9.0`, so we check for that first.

After enabling corepack, we set the yarn version:

```
yarn set version stable
```

Finally, before installing, we have to update `.yarnrc.yml` and `.gitignore`.
We have to update the `.yarnc.yml` because we only support the `node_modules` install strategy.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.idea
.DS_Store
.env
.netlify
.redwood
dev.db*
dist
dist-babel
node_modules
yarn-error.log
web/public/mockServiceWorker.js
web/types/graphql.d.ts
api/types/graphql.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"private": true,
"workspaces": {
"packages": [
"api",
"web",
"packages/*"
]
},
"devDependencies": {
"@redwoodjs/core": "0.47.0"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config",
"root": true
},
"engines": {
"node": ">=14.17 <=16.x",
"yarn": ">=1.15 <2"
},
"prisma": {
"seed": "yarn rw exec seed"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.idea
.DS_Store
.env
.netlify
.redwood
dev.db*
dist
dist-babel
node_modules
yarn-error.log
web/public/mockServiceWorker.js
web/types/graphql.d.ts
api/types/graphql.d.ts
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
compressionLevel: 0

enableGlobalCache: true

nmMode: hardlinks-local

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.0.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"private": true,
"workspaces": {
"packages": [
"api",
"web",
"packages/*"
]
},
"devDependencies": {
"@redwoodjs/core": "0.47.0"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config",
"root": true
},
"engines": {
"node": ">=14.17 <=16.x",
"yarn": ">=1.15 <2"
},
"prisma": {
"seed": "yarn rw exec seed"
},
"packageManager": "[email protected]"
}
Loading