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

feat: update lab 2 to nx 19.7 #37

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
64 changes: 61 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ When updating:
1. Use the migration generator to jump to the lab before the being updating

```sh
nx generate @nrwl/nx-react-workshop:complete-labs --from=1 --to=<the-prior-lab-number>
# Reset the repo (currently required as a separate step due to issue with getProjects)
# See comment in nx-workspace-e2e/tests/nx-workshop.spec.ts for more details
nx generate @nrwl/nx-react-workshop:complete-labs 1
nx migrate --run-migrations=migrations.json --verbose

# Run migrations to the prior lab
nx generate @nrwl/nx-react-workshop:complete-labs --from=2 --to=<the-prior-lab-number>
nx migrate --run-migrations=migrations.json --verbose
```

Expand All @@ -59,10 +65,62 @@ When updating:
# git commit
git add . && git commit -m 'manually run through completion steps'

# reset repo state and migrate to end of lab:
nx generate @nrwl/nx-react-workshop:complete-labs --from=1 --to=<the-lab-being-updated>
# reset repo state
nx generate @nrwl/nx-react-workshop:complete-labs 1
nx migrate --run-migrations=migrations.json --verbose

# migrate to end of lab
nx generate @nrwl/nx-react-workshop:complete-labs --from=2 --to=<the-lab-being-updated>
nx migrate --run-migrations=migrations.json --verbose

# Verify there are no differences
git status # should show no changes
```

<details>
<summary>A helper utility script</summary>

```bash
#! /usr/bin/env bash

set -euxo pipefail

if [ $# -ne 1 ]; then
echo "Usage: $0 <lab number>"
exit 1
fi

LAB_NUMBER="$1"
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

if [ ! -z "$(git status --porcelain)" ]; then
echo "Local changes detected. Please commit or stash them before running this script."
exit 1
fi

step () {
echo -e "\n\n${YELLOW}>>>> $1${NC}\n\n"
}

step "Updating to latest lab utility:"
npm i @nrwl/nx-react-workshop@latest
git add package*.json && git commit -m "chore: update to latest lab utility" || true


step "Resetting workspace to initial state:"
nx g complete-labs 1
nx migrate --run-migrations=migrations.json --verbose
nx reset
sleep 1 # give the daemon a chance to restart
nx show projects # should be empty

step "Migrating to lab $LAB_NUMBER:"
nx g complete-labs --from=2 --to=$LAB_NUMBER
nx migrate --run-migrations=migrations.json --verbose

step "Checking git status, this should be clean:"
git status

```
</details>
56 changes: 39 additions & 17 deletions apps/nx-workshop-e2e/tests/nx-workshop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('nx-react-workshop', () => {
projectDirectory
);
runNxCommand(
'run-many --target=e2e --parallel=false --exclude=internal-plugin-e2e',
'run-many --target=e2e --parallel=false',
projectDirectory
);
runNxCommand(
Expand All @@ -87,6 +87,44 @@ describe('nx-react-workshop', () => {
}
);

/**
* TODO: figure out what best approach for getProjects(tree) is
*
* Right now, if you call the removeGenerator for a project and then
* immediately call getProjects(tree), getProjects will throw.
*
* This is due to getProjects fetching a list of project.json files
* using globWithWorkspaceContextSync, which globs against the real
* filesystem rather than the in-memory tree.
*
* Once the list of project.json flies is fetched, the project details
* are they attempted to be fetched from the in-memory tree, which
* subsequently fails because we just deleted it.
*
* See: {@link https://github.com/nrwl/nx/blob/master/packages/nx/src/generators/utils/project-configuration.ts#L251}
*
* Re-enabling this test will recreate the issue as long as the current
* workspace has at least one project in it (which the previous test will create)
*/
Comment on lines +90 to +108
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reached out to @FrozenPandaz about this and will address it in a future update once we figure out what to do with getProjects(tree).

For now, we just need to run the "reset workspace" migration separately from all the rest.

it.skip('should support migrating from one version to another', () => {
runNxCommand(
`generate @nrwl/nx-react-workshop:complete-labs --from=1 --to=${LAB_COUNT}`,
projectDirectory
);
runNxCommand(
'migrate --run-migrations=migrations.json --verbose',
projectDirectory
);
runNxCommand(
'run-many --target=e2e --parallel=false',
projectDirectory
);
runNxCommand(
'run-many --target=lint --parallel=false',
projectDirectory
);
});

// NOTE: this test assumes that the current test project is in the final lab completed state
it('complete-lab-1 migration should match an empty create-nx-workspace', () => {
// Reset the test project to it's initial state using the "complete-lab-1" migration
Expand Down Expand Up @@ -119,22 +157,6 @@ describe('nx-react-workshop', () => {
expect(result.same).toBeTruthy();
});
});

it('should support migrating from one version to another', () => {
runNxCommand(
`generate @nrwl/nx-react-workshop:complete-labs --from=1 --to=${LAB_COUNT}`,
projectDirectory
);
runNxCommand(
'migrate --run-migrations=migrations.json --verbose',
projectDirectory
);
runNxCommand(
'run-many --target=e2e --parallel=false --exclude=internal-plugin-e2e',
projectDirectory
);
runNxCommand('run-many --target=lint --parallel=false', projectDirectory);
});
});
});

Expand Down
Binary file modified docs/assets/lab2_cmds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading