Skip to content

Commit

Permalink
chore: update lerna to 5.1 and enable nx (#5759)
Browse files Browse the repository at this point in the history
* chore: update lerna to 5.1 and enable nx

* Dedupe and prettier

* fix: builds should run in topological order

* Update e2e build script

* try increasing timeout for cli tests

* try limiting parallelization

trying a few things to get CI to pass on Windows

* try bumping timeout again

* refine the config to max the number of cache hits

* fix: make test glob more inclusive

* chore: update yarn.lock

* fix: build types for api-server and forms

* feat: configure test cpu cores for ci

* undo cli timeout change

Co-authored-by: Daniel Choudhury <[email protected]>
Co-authored-by: Dominic Saadi <[email protected]>
  • Loading branch information
3 people authored Jul 14, 2022
1 parent ee191ec commit 53ae908
Show file tree
Hide file tree
Showing 11 changed files with 1,220 additions and 920 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ jobs:
- name: 🔎 Lint
run: yarn lint

- name: Get number of CPU cores
if: always()
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v1

- name: 🧪 Test
run: yarn test
run: yarn test-ci ${{ steps.cpu-cores.outputs.count }}

build-lint-test-docs:
needs: only-doc-changes
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "2.1.0",
"npmClient": "yarn",
"useWorkspaces": true,
"useNx": true,
"command": {
"publish": {
"verifyAccess": false
Expand Down
39 changes: 39 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"test",
"build"
],
"parallel": 5
}
}
},
"namedInputs": {
"default": [
"{projectRoot}/**/*"
],
"prod": [
"!{projectRoot}/**/*.test.{js,jsx,ts,tsx}"
]
},
"targetDefaults": {
"build": {
"inputs": [
"prod",
"^prod"
],
"dependsOn": [
"^build"
]
},
"test": {
"inputs": [
"default",
"^prod"
]
}
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
"packages/*"
],
"scripts": {
"build": "yarn build:js && yarn build:types",
"build": "lerna run build",
"build:clean": "yarn clean:prisma && rimraf \"packages/**/dist\"",
"build:js": "lerna run build:js",
"build:link": "node ./tasks/build-and-copy",
"build:test-project": "node ./tasks/test-project/test-project",
"build:types": "tsc --build --verbose",
"build:watch": "lerna run build:watch --parallel; tsc --build",
"check": "yarn node ./tasks/check/check.mjs",
"check:deps": "yarn node ./tasks/checkDeps.mjs $INIT_CWD",
Expand All @@ -25,7 +23,8 @@
"release": "node ./tasks/release/cli.mjs",
"release:test": "NODE_OPTIONS=--experimental-vm-modules ./node_modules/.bin/jest --config ./tasks/release/jest.config.mjs",
"smoke-test": "cd ./tasks/smoke-test && npx playwright install && npx playwright test",
"test": "lerna run test --stream -- --colors --maxWorkers=4"
"test": "lerna run test --concurrency 2 -- --colors --maxWorkers=4",
"test-ci": "lerna run test --concurrency 2 -- --colors --maxWorkers"
},
"resolutions": {
"@types/react": "17.0.47",
Expand Down Expand Up @@ -81,14 +80,15 @@
"is-port-reachable": "3.1.0",
"jest": "27.5.1",
"jscodeshift": "0.13.1",
"lerna": "4.0.0",
"lerna": "5.1.4",
"lodash.template": "4.5.0",
"make-dir-cli": "3.0.0",
"msw": "0.40.2",
"ncp": "2.0.0",
"node-notifier": "10.0.1",
"nodemon": "2.0.19",
"npm-packlist": "5.1.1",
"nx": "14.4.2",
"octokit": "1.7.2",
"ora": "5.4.1",
"prompts": "2.4.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"dist"
],
"scripts": {
"build": "yarn build:js",
"build": "yarn build:js && yarn build:types",
"build:js": "babel src -d dist --extensions \".js,.ts,.tsx\"",
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
"fix:permissions": "chmod +x dist/index.js; chmod +x dist/watch.js",
"prepublishOnly": "NODE_ENV=production yarn build",
Expand Down
3 changes: 2 additions & 1 deletion packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"dist"
],
"scripts": {
"build": "yarn build:js",
"build": "yarn build:js && yarn build:types",
"build:js": "babel src -d dist --extensions \".js,.ts,.tsx\"",
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
Expand Down
20 changes: 3 additions & 17 deletions tasks/build-and-copy
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ const packagePaths = glob
.filter((packagePath) => (only ? packagePath.includes(only) : true))
.filter((packageName) => !packageName.includes('create-redwood-app'))

const buildAllTypes = () =>
execa('yarn build:types', {
shell: true,
stdio: 'inherit',
cleanup: true,
cwd: RW_BASEPATH,
})

const build = async ({ packageFolderName, types }) => {
const build = async ({ packageFolderName }) => {
const execaOptionsForBase = {
shell: true,
stdio: 'inherit',
Expand All @@ -66,7 +58,7 @@ const build = async ({ packageFolderName, types }) => {
await execa(
'yarn framework lerna run',
[
types ? 'build' : 'build:js',
'build',
'--parallel',
packageFolderName && `--scope @redwoodjs/${packageFolderName}`,
],
Expand Down Expand Up @@ -138,15 +130,9 @@ process.on('SIGINT', () => {
})

const runAsync = async () => {
// STEP 1: Run build:types from root of framework
try {
if (!only) {
await buildAllTypes()
}
// STEP 2: Run yarn lerna run build --parallel, ignore types as they've just been built
await build({
packageFolderName: only,
types: only ? true : false,
})

await copyDistFiles({
Expand All @@ -169,7 +155,7 @@ const runAsync = async () => {
const onChange = _.debounce(async (packageFolderName) => {
console.log('[rwt link] Building 📦...', packageFolderName)
try {
await build({ packageFolderName, types: true })
await build({ packageFolderName })
await copyDistFiles({ packageFolderName })
console.log(
`\n [rwt link] ${chalk.greenBright.bold(
Expand Down
11 changes: 1 addition & 10 deletions tasks/framework-tools/lib/framework.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,15 @@ export function cleanPackages(packages = frameworkPkgJsonFiles()) {
*/
export function buildPackages(packages = frameworkPkgJsonFiles()) {
const packageNames = packages.map(packageJsonName)

// Build JavaScript.
execa.sync(
'yarn lerna run build:js',
'yarn lerna run build',
['--parallel', `--scope={${packageNames.join(',') + ','}}`],
{
shell: true,
stdio: 'inherit',
cwd: path.resolve(__dirname, '../../../'),
}
)

// Build all TypeScript.
execa.sync('yarn build:types', undefined, {
shell: true,
stdio: 'inherit',
cwd: path.resolve(__dirname, '../../../'),
})
}

function sortObjectKeys(obj) {
Expand Down
2 changes: 1 addition & 1 deletion tasks/run-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const buildRedwoodFramework = () => {
})

execa.sync(
[files.length && 'yarn build:clean', 'yarn build:js']
[files.length && 'yarn build:clean', 'yarn build']
.filter(Boolean)
.join('&&'),
{
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{ "path": "packages/prerender" },
{ "path": "packages/graphql-server" },
{ "path": "packages/forms" },
{ "path": "packages/codemods" },
{ "path": "packages/codemods" }
],
"files": []
}
Loading

0 comments on commit 53ae908

Please sign in to comment.