Skip to content

Commit

Permalink
Add yarn 3 to create redwood app template (redwoodjs#4761)
Browse files Browse the repository at this point in the history
* add files to crwa for yarn 3

* optionally re-enable yarn1 for crwa

* set build:test-project to use Yarn 3

* update test project to default to yarn 3

* improve descriptions

* only use --silent if yarn1

* enable lock file creation in ci

* make dm invocations consistent

* Revert "make dm invocations consistent"

This reverts commit 2ba009b.

* try moving the generate step

* Revert "try moving the generate step"

This reverts commit 59b8965.

* mv dm to run after generate

this'll still probably fail but going to see

* try migrate reset

* try running dm up before install

* remove yarn engine max version

Co-authored-by: David Price <[email protected]>
  • Loading branch information
jtoar and thedavidprice authored Mar 18, 2022
1 parent 1d2e0eb commit 1521edb
Show file tree
Hide file tree
Showing 13 changed files with 1,667 additions and 51 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
uses: ./.github/actions/setup_test_project
env:
REDWOOD_DISABLE_TELEMETRY: 1
YARN_ENABLE_IMMUTABLE_INSTALLS: false

- name: Install Playwright deps
run: npx playwright install --with-deps chromium
Expand Down Expand Up @@ -116,6 +117,11 @@ jobs:
yarn rw prisma generate
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "rw data-migrate"
run: |
yarn rw dataMigrate up
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "data-migrate install"
run: |
yarn rw data-migrate install
Expand All @@ -126,11 +132,6 @@ jobs:
yarn rw prisma migrate dev --name ci-test
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "rw data-migrate"
run: |
yarn rw dataMigrate up
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run `rw deploy --help`
run: yarn rw setup deploy --help && yarn rw deploy --help
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}
Expand Down
7 changes: 7 additions & 0 deletions __fixtures__/test-project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ 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
785 changes: 785 additions & 0 deletions __fixtures__/test-project/.yarn/releases/yarn-3.2.0.cjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions __fixtures__/test-project/.yarnrc.yml
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
7 changes: 4 additions & 3 deletions __fixtures__/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
},
"engines": {
"node": ">=14.19 <=16.x",
"yarn": ">=1.15 <2"
"yarn": ">=1.15"
},
"prisma": {
"seed": "yarn rw exec seed"
},
"scripts": {
"postinstall": ""
}
}
},
"packageManager": "[email protected]"
}
33 changes: 33 additions & 0 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
typescript,
overwrite,
telemetry: telemetry,
yarn1,
} = yargs
.scriptName(name)
.usage('Usage: $0 <project directory> [option]')
Expand Down Expand Up @@ -77,6 +78,11 @@ const {
describe:
'Enables sending telemetry events for this create command and all Redwood CLI commands https://telemetry.redwoodjs.com',
})
.option('yarn1', {
default: false,
type: 'boolean',
describe: 'Use yarn 1. yarn 3 by default',
})
.version(version)
.strict().argv

Expand Down Expand Up @@ -164,6 +170,33 @@ const createProjectTasks = ({ newAppDir, overwrite }) => {
)
},
},
{
title: 'Converting to yarn 1',
enabled: () => yarn1,
task: () => {
// rm files:
// - .yarnrc.yml
// - .yarn
fs.rmSync(path.join(newAppDir, '.yarnrc.yml'))
fs.rmdirSync(path.join(newAppDir, '.yarn'), { recursive: true })

// rm after `.pnp.*`
const gitignore = fs.readFileSync(path.join(newAppDir, '.gitignore'), {
encoding: 'utf-8',
})
const [yarn1Gitignore, _yarn3Gitignore] = gitignore.split('.pnp.*')
fs.writeFileSync(path.join(newAppDir, '.gitignore'), yarn1Gitignore)

// rm `packageManager` from package.json
const packageJSON = fs.readJSONSync(
path.join(newAppDir, 'package.json')
)
delete packageJSON.packageManager
fs.writeJSONSync(path.join(newAppDir, 'package.json'), packageJSON, {
spaces: 2,
})
},
},
]
}

Expand Down
785 changes: 785 additions & 0 deletions packages/create-redwood-app/template/.yarn/releases/yarn-3.2.0.cjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/create-redwood-app/template/.yarnrc.yml
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
7 changes: 7 additions & 0 deletions packages/create-redwood-app/template/gitignore.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ 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
5 changes: 3 additions & 2 deletions packages/create-redwood-app/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
},
"engines": {
"node": ">=14.19 <=16.x",
"yarn": ">=1.15 <2"
"yarn": ">=1.15"
},
"prisma": {
"seed": "yarn rw exec seed"
}
},
"packageManager": "[email protected]"
}
30 changes: 6 additions & 24 deletions tasks/run-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const buildRedwoodFramework = () => {
}
}

const createRedwoodJSApp = () => {
const createRedwoodJSApp = ({ yarn1 }) => {
try {
execa.sync(
'yarn babel-node src/create-redwood-app.js',
Expand All @@ -55,7 +55,8 @@ const createRedwoodJSApp = () => {
'--no-yarn-install',
'--typescript',
'--no-telemetry',
],
yarn1 && '--yarn1',
].filter(Boolean),
{
cwd: path.join(REDWOODJS_FRAMEWORK_PATH, 'packages/create-redwood-app'),
env: { REDWOOD_CI: '1' },
Expand All @@ -70,24 +71,6 @@ const createRedwoodJSApp = () => {
}
}

const upgradeToYarn3 = () => {
try {
execa.sync(
`RWJS_CWD=${REDWOOD_PROJECT_DIRECTORY} yarn node ./packages/codemods/dist/codemods.js upgrade-yarn`,
{
cwd: REDWOODJS_FRAMEWORK_PATH,
env: { REDWOOD_CI: '1' },
shell: true,
stdio: 'inherit',
}
)
} catch (e) {
console.error('Error: Could not upgrade Redwood Project to yarn 3')
console.error(e)
process.exit(1)
}
}

const addFrameworkDepsToProject = () => {
try {
execa.sync('yarn project:deps', {
Expand Down Expand Up @@ -202,7 +185,7 @@ const args = yargs
.option('copy-framework', { default: true, type: 'boolean', alias: 'copy' })
.option('typescript', { default: false, type: 'boolean', alias: 'ts' })
.option('auto-start', { default: true, type: 'boolean', alias: 'start' })
.option('yarn3', { default: true, type: 'boolean' })
.option('yarn1', { default: false, type: 'boolean' })
.scriptName('run-e2e')
.example('run-e2e')
.example('run-e2e /tmp/redwood-app --ts')
Expand Down Expand Up @@ -232,12 +215,11 @@ let {
createProject,
typescript,
autoStart,
yarn3,
yarn1,
} = args
const tasks = [
buildFramework && buildRedwoodFramework,
createProject && createRedwoodJSApp,
yarn3 && upgradeToYarn3,
createProject && (() => createRedwoodJSApp({ yarn1 })),
copyFramework && addFrameworkDepsToProject,
copyFramework && runYarnInstall,
copyFramework && copyFrameworkPackages,
Expand Down
2 changes: 1 addition & 1 deletion tasks/test-project/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ async function webTasks(outputPath, { linkWithLatestFwBuild, verbose }) {
// @NOTE: use rwfw, because calling the copy function doesn't seem to work here
task: () =>
execa(
'yarn add -W -D postcss postcss-loader tailwindcss autoprefixer',
'yarn workspace web add -D postcss postcss-loader tailwindcss autoprefixer',
[],
getExecaOptions(outputPath)
),
Expand Down
28 changes: 12 additions & 16 deletions tasks/test-project/test-project
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const args = yargs
describe:
'Upgrade project to latest canary version. NOT compatible with --link.',
})
.option('yarn1', {
default: false,
type: 'boolean',
describe: 'Use yarn 1 instead of yarn 3',
})
.help()
.strict().argv

Expand All @@ -75,6 +80,7 @@ const {
clean,
copyFromFixture,
rebuildFixture,
yarn1,
} = args

// Do not use demandCommand becuase rebuildFixture doesn't require <project directory>
Expand Down Expand Up @@ -216,33 +222,23 @@ const globalTasks = () =>
enabled: () => link && !rebuildFixture,
},
{
title: 'Set yarn v1 version in test-project directory',
title: 'Setting yarn version to 1',
task: async () => {
await execa(
'yarn set version classic',
[],
getExecaOptions(OUTPUT_PROJECT_PATH)
)

// remove "packageManager": "[email protected]" from package.json
const packageJsonPath = path.join(OUTPUT_PROJECT_PATH, 'package.json')
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8')
)
delete packageJson.packageManager
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, undefined, 2)
)
},
skip: () => !copyFromFixture && rebuildFixture,
enabled: () => yarn1,
},
{
title: 'Installing node_modules',
task: async () => {
return execa(
'yarn install',
['--non-interactive', !verbose && '--silent'].filter(Boolean),
yarn1 &&
['--non-interactive', !verbose && '--silent'].filter(Boolean), // pass flags if using Yarn v1
getExecaOptions(OUTPUT_PROJECT_PATH)
)
},
Expand Down Expand Up @@ -326,8 +322,8 @@ const globalTasks = () =>
title: 'Generate dbAuth Secret',
task: async () => {
const { stdout: dbAuthSecret } = await execa(
`yarn --silent rw g secret --raw`,
[],
'yarn',
[yarn1 && '--silent', 'rw', 'g', 'secret', '--raw'].filter(Boolean),
{
...getExecaOptions(OUTPUT_PROJECT_PATH),
stdio: 'pipe',
Expand Down

0 comments on commit 1521edb

Please sign in to comment.