Compare commits
180 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a9bb68dde | |||
| 4f7bf97f21 | |||
| 7e74f941f8 | |||
| e319738152 | |||
| 6bec19b87a | |||
| d6b037b509 | |||
| 71faacb19b | |||
| 428b0d518e | |||
| 63429dc612 | |||
| ed2ffb087b | |||
| 2b5efdc6ec | |||
| 8fbf06f863 | |||
| bc07797d9c | |||
| 73a5705e93 | |||
| bd74a2b4b3 | |||
| 075e1ea0fa | |||
| 6ea19c2e7f | |||
| 0d25164bc7 | |||
| 88aa1966bc | |||
| 618096aeca | |||
| 1c186f6616 | |||
| 1c59acbdeb | |||
| 1e7f553417 | |||
| 3bac93e207 | |||
| 837656fbdd | |||
| 92474f0bfd | |||
| 756157c514 | |||
| a0014e1a04 | |||
| 4e947b09d8 | |||
| c798d65668 | |||
| c3c118f433 | |||
| 5f820076e8 | |||
| 6525d5fde9 | |||
| 4f43ac1db1 | |||
| 91cc154b0c | |||
| 56b0ee5ac1 | |||
| adb5ddce20 | |||
| 2eaf79b656 | |||
| 3bbb244baf | |||
| 5c70c37751 | |||
| 6b62686522 | |||
| ec7925e6fd | |||
| a6fc29acf8 | |||
| 7a72ce3d1d | |||
| def332e360 | |||
| d4ccb8fdae | |||
| d51c552548 | |||
| 675bd7615d | |||
| eb6461ba11 | |||
| 1f7775d7f3 | |||
| 4fb8663974 | |||
| b69b56079e | |||
| e4d1f52d83 | |||
| 2116acb350 | |||
| 37c1497ee4 | |||
| 40aca15c52 | |||
| 31236a152f | |||
| e610e2e5ba | |||
| a5713da4b7 | |||
| 49a4195788 | |||
| 20a3469890 | |||
| 7754c0cb84 | |||
| c0715906aa | |||
| 485bf1b5c1 | |||
| 1d147f1a8a | |||
| 65cd1aa11d | |||
| 264f8cf85f | |||
| 82ae3560e0 | |||
| 4926bd391e | |||
| 7b4bfd3dcd | |||
| 8f78d885de | |||
| 175a69c227 | |||
| dae21932c9 | |||
| f4448c84c5 | |||
| e9280b60ee | |||
| 43f4cf7113 | |||
| 147b210f59 | |||
| c726ae7c3e | |||
| 4e6a193f39 | |||
| 7ff68e5cd9 | |||
| 7da337e5a3 | |||
| d281489763 | |||
| 4dbfea7b89 | |||
| 3bf0a25bd2 | |||
| 77a4f69b1e | |||
| d3ea7c29a0 | |||
| 800376661c | |||
| 508e87f3de | |||
| 2cae2422a5 | |||
| 860d0b14ae | |||
| 55114ffc3c | |||
| 3144584597 | |||
| be5b8e7215 | |||
| 9186c977e4 | |||
| d75bab70a7 | |||
| d9c5fe9be0 | |||
| ad0c3d1a41 | |||
| 56b134dbf2 | |||
| 4342db3e8c | |||
| c240b4941a | |||
| 52d0b2dbc8 | |||
| b8d112c93d | |||
| ac1061efd8 | |||
| 29349b8096 | |||
| 3654f53e77 | |||
| 114346e95b | |||
| 0affa36a0c | |||
| f003703fe0 | |||
| 2c72f404bb | |||
| d06096b4d8 | |||
| 1482418c78 | |||
| 712e62b546 | |||
| 95317bbdfb | |||
| 868ac4c40b | |||
| 5875a234ef | |||
| e5a0a07cdc | |||
| f3dfe228ce | |||
| 4d03625301 | |||
| 956b360df6 | |||
| 2b5d9bd2ee | |||
| d2347a3d81 | |||
| 8c52e933db | |||
| c8341dcb0b | |||
| 1c63d71d10 | |||
| 6f85853b85 | |||
| b3f8bd9ff9 | |||
| b7bb1a268b | |||
| 6c720ebff0 | |||
| 759becfab4 | |||
| 963d2e04b0 | |||
| 54fa6d2237 | |||
| 447f147168 | |||
| 83e96a8a9a | |||
| 7448532d83 | |||
| 4de3917835 | |||
| a8ac9bd99f | |||
| ae03f5fcff | |||
| 61861be0f7 | |||
| e3afd8ac6d | |||
| 9eea4792e4 | |||
| 7a9044d4ec | |||
| 0a29df4ec5 | |||
| e42560d645 | |||
| 84399c8528 | |||
| f759e2e1d9 | |||
| 21ec0dab4a | |||
| 493cbe1aeb | |||
| 7c80c0bd17 | |||
| 6649869ccf | |||
| 534b24b851 | |||
| fe46c53761 | |||
| cf35bff45e | |||
| fca769430a | |||
| 122791ac6a | |||
| 6bf79f4495 | |||
| 29f65d6dc6 | |||
| 7cb104afc5 | |||
| af42c1a269 | |||
| 1054eeb030 | |||
| 72e7446219 | |||
| d2e1d6c51e | |||
| 04bb40e55e | |||
| 3367cc978d | |||
| 544a9093c5 | |||
| d403f19861 | |||
| 8ba5570c45 | |||
| 6106424fd0 | |||
| d3d0129edf | |||
| e3c183d25f | |||
| dd14a79d84 | |||
| 8eff7667f9 | |||
| c18d98a371 | |||
| 975387b9d6 | |||
| bf6963ba6a | |||
| 1356ecdf40 | |||
| 13b0b2373e | |||
| d71c748717 | |||
| 638f2c63a7 | |||
| 7173777110 | |||
| 0ac5c9a0d0 |
@@ -69,50 +69,6 @@ commands:
|
||||
- ~/.pnpm-store
|
||||
- ~/.cache/Cypress
|
||||
- node_modules
|
||||
install-sdkman:
|
||||
description: Install SDKMAN
|
||||
steps:
|
||||
- restore_cache:
|
||||
name: Restore SDKMAN executable and binaries from cache
|
||||
keys:
|
||||
- sdkman-cli-{{ arch }}-v2
|
||||
- run:
|
||||
name: Installing SDKMAN
|
||||
command: |
|
||||
if [ ! -d ~/.sdkman ]
|
||||
then
|
||||
curl -s "https://get.sdkman.io?rcupdate=false" | bash
|
||||
sed -i -e 's/sdkman_auto_answer=false/sdkman_auto_answer=true/g' ~/.sdkman/etc/config
|
||||
fi
|
||||
echo -e '\nsource "/home/circleci/.sdkman/bin/sdkman-init.sh"' >> $BASH_ENV
|
||||
source $BASH_ENV
|
||||
sdk version
|
||||
- save_cache:
|
||||
name: Save SDKMAN executable and binaries to cache
|
||||
key: sdkman-cli-{{ arch }}-v2
|
||||
paths:
|
||||
- ~/.sdkman
|
||||
install-gradle:
|
||||
description: Install gradle
|
||||
parameters:
|
||||
gradle-version:
|
||||
type: string
|
||||
default: ''
|
||||
steps:
|
||||
- restore_cache:
|
||||
name: Restore Gradle binary from cache
|
||||
keys:
|
||||
- gradle-cli-{{ arch }}-v1
|
||||
- run:
|
||||
name: Installing Gradle
|
||||
command: |
|
||||
sdk install gradle << parameters.gradle-version >>
|
||||
gradle --version
|
||||
- save_cache:
|
||||
name: Save Gradle binary to cache
|
||||
key: gradle-cli-{{ arch }}-v1
|
||||
paths:
|
||||
- ~/.sdkman/candidates/gradle/
|
||||
# -------------------------
|
||||
# JOBS
|
||||
# -------------------------
|
||||
@@ -140,10 +96,6 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ca-certificates lsof
|
||||
- browser-tools/install-chrome
|
||||
- browser-tools/install-chromedriver
|
||||
- install-sdkman
|
||||
- install-gradle:
|
||||
gradle-version: '8.5'
|
||||
- run-pnpm-install:
|
||||
os: linux
|
||||
- run:
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM mcr.microsoft.com/devcontainers/typescript-node:20-bullseye
|
||||
|
||||
# Update the underlying (Debian) OS, to make sure we have the latest security patches and libraries like 'GLIBC'
|
||||
RUN sudo apt-get update && sudo apt-get -y upgrade
|
||||
|
||||
# Update pnpm
|
||||
RUN npm install -g pnpm@8.15.7
|
||||
@@ -3,7 +3,10 @@
|
||||
{
|
||||
"name": "NxDevContainer",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/typescript-node:20-bullseye",
|
||||
"build": {
|
||||
// Path is relative to the devcontainer.json file.
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/rust:1": {}
|
||||
},
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Update the underlying (Debian) OS, to make sure we have the latest security patches and libraries like 'GLIBC'
|
||||
sudo apt-get update && sudo apt-get -y upgrade
|
||||
|
||||
# Update pnpm
|
||||
#npm install -g pnpm
|
||||
|
||||
# Install dependencies
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"ignorePatterns": ["**/*"],
|
||||
"plugins": ["@nx"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||
"rules": {
|
||||
"@nx/enforce-module-boundaries": [
|
||||
"error",
|
||||
{
|
||||
"enforceBuildableLibDependency": true,
|
||||
"allow": [],
|
||||
"depConstraints": [
|
||||
{
|
||||
"sourceTag": "*",
|
||||
"onlyDependOnLibsWithTags": ["*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.ts", "*.tsx"],
|
||||
"extends": ["plugin:@nx/typescript"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.js", "*.jsx"],
|
||||
"extends": ["plugin:@nx/javascript"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -55,6 +55,11 @@ jobs:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-modules-${{ matrix.node_version }}-${{ github.run_id }}
|
||||
|
||||
- name: Ensure Python setuptools Installed on Macos
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
id: brew-install-python-setuptools
|
||||
run: brew install python-setuptools
|
||||
|
||||
- name: Install packages
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: pnpm install --frozen-lockfile
|
||||
@@ -403,7 +408,7 @@ jobs:
|
||||
timeout-minutes: 15
|
||||
|
||||
process-result:
|
||||
if: ${{ always() }}
|
||||
if: ${{ always() && github.repository_owner == 'nrwl' }}
|
||||
runs-on: ubuntu-latest
|
||||
needs: e2e
|
||||
outputs:
|
||||
|
||||
@@ -4,7 +4,7 @@ on:
|
||||
|
||||
name: Stale Bot workflow
|
||||
|
||||
permissions: {}
|
||||
permissions: { }
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -16,163 +16,96 @@ jobs:
|
||||
name: stale
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# This handles issues that need more info
|
||||
- name: stale-more-info-needed
|
||||
id: stale-more-info-needed
|
||||
uses: actions/stale@v3.0.13
|
||||
uses: actions/stale@v9.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 14
|
||||
days-before-close: 14
|
||||
days-before-stale: 7
|
||||
days-before-close: 21
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "blocked: more info needed"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
This issue has been automatically marked as stale because more information has not been provided within 7 days.
|
||||
It will be closed in 21 days if no information is provided.
|
||||
If information has been provided, please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
# This handles PRs that need to be rebased
|
||||
- name: stale-needs-rebase
|
||||
id: stale-needs-rebase
|
||||
uses: actions/stale@v3.0.13
|
||||
uses: actions/stale@v9.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 14
|
||||
days-before-close: 14
|
||||
days-before-stale: 7
|
||||
days-before-close: 21
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "blocked: needs rebased"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
This PR has been automatically marked as stale because it has not been rebased in 7 days.
|
||||
It will be closed in 21 days if it is not rebased.
|
||||
If the PR has been rebased or you are working on rebasing it, please reply to keep it active.
|
||||
If you do not have time, please let us know and we can rebase it.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
# This handles issues that do not have a repro
|
||||
- name: stale-repro-needed
|
||||
id: stale-repro-needed
|
||||
uses: actions/stale@v3.0.13
|
||||
uses: actions/stale@v9.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 14
|
||||
days-before-close: 14
|
||||
days-before-stale: 7
|
||||
days-before-close: 21
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "blocked: repro needed"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
This issue has been automatically marked as stale because no reproduction was provided within 7 days.
|
||||
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
|
||||
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
|
||||
This issue will be closed in 21 days if a reproduction is not provided.
|
||||
If a reproduction has been provided, please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-retry-with-latest
|
||||
id: stale-retry-with-latest
|
||||
uses: actions/stale@v3.0.13
|
||||
uses: actions/stale@v9.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 14
|
||||
days-before-close: 14
|
||||
days-before-stale: 7
|
||||
days-before-close: 21
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "blocked: retry with latest"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days.
|
||||
It will be closed in 21 days if no results are provided.
|
||||
If the issue is still present, please reply to keep it active.
|
||||
If the issue was not present, please close this issue.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
|
||||
# This handles issues are really old and were made with a previous major
|
||||
- name: stale-bug
|
||||
id: stale-bug
|
||||
uses: actions/stale@v3.0.13
|
||||
uses: actions/stale@v9.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 180
|
||||
days-before-close: 14
|
||||
days-before-close: 21
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: bug"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-cleanup
|
||||
id: stale-cleanup
|
||||
uses: actions/stale@v3.0.13
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 180
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: cleanup"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-docs
|
||||
id: stale-docs
|
||||
uses: actions/stale@v3.0.13
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 180
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: docs"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-enhancement
|
||||
id: stale-enhancement
|
||||
uses: actions/stale@v3.0.13
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 250
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: enhancement"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-feature
|
||||
id: stale-feature
|
||||
uses: actions/stale@v3.0.13
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 250
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: feature"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
- name: stale-question
|
||||
id: stale-question
|
||||
uses: actions/stale@v3.0.13
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 45
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
operations-per-run: 300
|
||||
remove-stale-when-updated: true
|
||||
only-labels: "type: question / discussion"
|
||||
stale-issue-message: |
|
||||
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
|
||||
If we missed this issue please reply to keep it active.
|
||||
This issue has been automatically marked as stale because it hasn't had any activity for 6 months.
|
||||
Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore.
|
||||
If at this point, this is still an issue, please respond with updated information.
|
||||
It will be closed in 21 days if no further activity occurs.
|
||||
Thanks for being a part of the Nx community! 🙏
|
||||
|
||||
@@ -21,8 +21,6 @@ launch-templates:
|
||||
~/.cache/Cypress
|
||||
~/.cache/ms-playwright
|
||||
~/.pnpm-store
|
||||
~/.sdkman
|
||||
~/.sdkman/candidates/gradle
|
||||
BASE_BRANCH: 'master'
|
||||
- name: Install e2e deps
|
||||
script: |
|
||||
@@ -57,18 +55,3 @@ launch-templates:
|
||||
|
||||
- name: Install zip and unzip
|
||||
script: sudo apt-get -yqq install zip unzip
|
||||
|
||||
- name: Install SDKMAN and gradle
|
||||
script: |
|
||||
if [ ! -d $HOME/.sdkman ]
|
||||
then
|
||||
curl -s "https://get.sdkman.io" | bash
|
||||
source "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||
fi
|
||||
sdk version
|
||||
if [ ! -d $HOME/.sdkman/candidates/gradle/8.5 ]
|
||||
then
|
||||
sdk install gradle 8.5
|
||||
fi
|
||||
gradle --version
|
||||
echo "PATH=$HOME/.sdkman/candidates/gradle/8.5/bin:$PATH" >> $NX_CLOUD_ENV
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
"description": "Nx plugin integrations with Vite.",
|
||||
"url": "https://nx-plugins.netlify.app/"
|
||||
},
|
||||
{
|
||||
"name": "nx-serverless-cdk",
|
||||
"description": "Create CDK applications and construct libraries. Test and debug infrastructure code and AWS Lambda functions locally.",
|
||||
"url": "https://github.com/castleadmin/nx-plugins/tree/main/nx-serverless-cdk/plugin"
|
||||
},
|
||||
{
|
||||
"name": "@ago-dev/nx-aws-cdk-v2",
|
||||
"description": "An nx plugin for the aws-cdk v2.",
|
||||
@@ -473,5 +478,10 @@
|
||||
"name": "@getlarge/nx-heroku",
|
||||
"description": "Plugin to deploy and promote Nx apps on Heroku",
|
||||
"url": "https://github.com/getlarge/nx-heroku"
|
||||
},
|
||||
{
|
||||
"name": "@huge-nx/conventions",
|
||||
"description": "Plugin to generate and manage Nx workspaces by adhering to established workspace conventions.",
|
||||
"url": "https://github.com/jogelin/huge-nx"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
title: Nx Cloud 3.0 — Faster Cache, More Powerful DTE, Better Ergonomics
|
||||
authors: [Juri Strumpflohner]
|
||||
cover_image: '/blog/images/2023-04-19/featured_img.webp'
|
||||
tags: [nx, nx-cloud]
|
||||
---
|
||||
|
||||
It has been almost 2 years since we released [Nx Cloud 2.0](https://nx.app/). Since then, it has saved over 400 years of computation by leveraging its distributed caching and task execution. And we keep adding 8 years every single week. Not only does this tremendously [impact our environment](https://dev.to/nx/helping-the-environment-by-saving-two-centuries-of-compute-time-4nep), but it also helps developers be more productive and companies save money.
|
||||
|
||||
In the last couple of months we have quadrupled the team and have done some amazing things. And we have some big plans for what is coming next. Here’s all you need to know!
|
||||
|
||||
**Table of Contents**
|
||||
|
||||
- [New, Streamlined UI](#new-streamlined-ui)
|
||||
- [Prefetching and Faster Cache Uploading](#prefetching-and-faster-cache-uploading)
|
||||
- [DTE Just got Better](#dte-just-got-better)
|
||||
- [Direct Integration With GitHub, GitLab and Bitbucket](#direct-integration-with-github-gitlab-and-bitbucket)
|
||||
- [Enterprise Support](#enterprise-support)
|
||||
- [New, Simplified Plans and Pricing Model](#new-simplified-plans-and-pricing-model)
|
||||
- [Coming Next](#coming-next)
|
||||
- [Learn more](#learn-more)
|
||||
|
||||
**Prefer a Video? We’ve got you Covered!**
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/cG2hEI5L3qI?si=9frDSD8_HK1iTNEi" /%}
|
||||
|
||||
## New, Streamlined UI
|
||||
|
||||
This latest release of Nx Cloud comes with a new, streamlined design that offers users a more modern and visually appealing experience. This includes the main [Nx Cloud website](https://nx.app/), where we improved our messaging, including interactive visualizations to better explain some core concepts around remote caching and distributed task execution.
|
||||
|
||||

|
||||
|
||||
The Nx Cloud application — showing your runs, cache saved, and stats — also got a significant overhaul, making the UI more lightweight and easier to parse.
|
||||
|
||||

|
||||
|
||||
More UI-related updates and improvements are already underway.
|
||||
|
||||
## Prefetching and Faster Cache Uploading
|
||||
|
||||

|
||||
|
||||
At Nx, we are performance addicts! Especially when it comes to local development, every millisecond counts! In the latest update of the Nx CLI, we added the ability to **offload some of the remote cache management to the [Nx Daemon](/concepts/nx-daemon)**. As a result you no longer have to wait for the cache to upload. This saves valuable time, allowing the command to complete instantly and immediately providing you with the necessary link.
|
||||
We also **prefetch cache results in the background** to have them ready when needed.
|
||||
|
||||
Both optimizations can save seconds.
|
||||
|
||||
## DTE Just got Better
|
||||
|
||||

|
||||
|
||||
[Distributed Task Execution (short DTE)](/ci/features/distribute-task-execution) is a core part of what makes Nx Cloud stand out compared to other solutions. And we made some significant improvements to both the ergonomics and speed.
|
||||
|
||||
**Identify failed tasks early** — You can now view information about the in-progress DTEs, allowing you to quickly identify and address any failed functions without waiting for the command to complete.
|
||||
|
||||
**Simplified CI setup** — We simplified the setup process for most CI systems, eliminating the need to pass environment variables manually. Instead, everything is automatically derived from the context.
|
||||
|
||||
**Improved performance and efficiency** — Nx Cloud now intelligently figures out which tasks will be cache hits before sending them to agents. Rather it can directly send them to the main job, reducing unnecessary round trips and drastically speeding up CI runs.
|
||||
|
||||
**Efficient agent management** — We have introduced a new command, `npx nx-cloud start-ci-run –stop-agents-after=e2e`, that allows you to notify Nx Cloud when specific commands, such as long-running e2e tasks, have started. This helps Nx Cloud proactively identify and shut down agents that will not be needed, improving compute efficiency.
|
||||
|
||||
**Reduce fix costs** — Even though cache hits are basically free, spinning processes still have fixed costs. We fixed that (see what I did there) by leveraging a new Nx feature that allows to have a long-running process on an agent to which we can arbitrarily feed new tasks. This removed the DTE overheads and also improved the predictability of runs.
|
||||
|
||||
## Direct Integration With GitHub, GitLab and Bitbucket
|
||||
|
||||
Our GitHub integration has been enhanced. Now, the list of runs is updated in real-time as soon as they are created or their status changes, providing developers with up-to-date information directly on GitHub.
|
||||
|
||||

|
||||
|
||||
In addition to the GitHub, we expanded our Nx Cloud live status updates to work on GitLab and BitBucket.
|
||||
|
||||

|
||||
|
||||
## Enterprise Support
|
||||
|
||||

|
||||
|
||||
We have extensive experience working with Fortune 500 companies, helping them scale their development using monorepos. This has given us valuable insight into the unique security requirements of these companies. Our [Enterprise plan](/enterprise) reflects that allowing organizations to have a **fully self-contained version of Nx Cloud** that can be **hosted on their own servers** and comes with dedicated support from the Nx and Nx Cloud core team.
|
||||
|
||||
We’ve recently made a couple of improvements to our enterprise offering.
|
||||
|
||||
- **Helm Charts** — We added a **Helm chart** to simplify the process of deploying Nx Cloud to on-premises infrastructure, allowing organizations to quickly set up and manage their own instance of Nx Cloud within their secure environment.
|
||||
- **Stability improvements** — We significantly reworked our on-premises solution to be identical to our SaaS deployment. This revamp resulted in a more robust and reliable on-premises deployment of Nx Cloud, ensuring enterprise-grade performance and reliability.
|
||||
- **SSO** — We now support AWS Identity and Access Management (IAM) for seamless integration with existing AWS environments and the SAML protocol for a more flexible single sign-on integration across various providers. This enables organizations to leverage their existing identity management systems for authentication and authorization.
|
||||
|
||||
Learn more at [enterprise](/enterprise).
|
||||
|
||||
## New, Simplified Plans and Pricing Model
|
||||
|
||||
Nx Cloud has evolved a lot since we first released it in 2020, and is changing even more in 2023. To better adapt to Nx Cloud being a critical CI tool, we changed our pricing model to be more consistent and predictable for CI workloads.
|
||||
|
||||
Nx Cloud’s previous pricing was based on time savings from Nx Cloud, which made sense when Nx Cloud was strictly a distributed caching service. The [new pricing model](https://nx.app/pricing) is based entirely on the number of CI pipeline executions per calendar month. We believe this is a simpler and more transparent model that should help you predict your costs far more easily.
|
||||
|
||||

|
||||
|
||||
Our Free plan allows one administrator and up to 300 CI pipeline executions per month. Our Pro plan allows more administrators, and uncapped CI pipeline executions, with a flat fee and incremental charges per 100 CI pipeline executions. The OSS plan comes with unlimited CI pipeline executions. Nx has been open source from the beginning and we care a lot about that ecosystem. So this is our contribution to help OSS projects and make their CI pipeline executions faster.
|
||||
|
||||
Finally, the **Enterprise plan** is for companies that want full control over where their data is hosted, get hands-on, dedicated support from the Nx & Nx Cloud team, and enterprise features such as SSO & SAML-based authentication support.
|
||||
|
||||
All these changes should allow developers to choose the plan that best suits their needs and budget more easily, ensuring a seamless and transparent experience regarding pricing and subscription management.
|
||||
|
||||
Learn more at [https://nx.app/pricing](https://nx.app/pricing).
|
||||
|
||||
## Coming Next
|
||||
|
||||
We’ve got some big plans for Nx Cloud. You really want to write your CI script by focusing on what you want to achieve rather than thinking about making it fast. We’re going to make this happen!
|
||||
|
||||
The current Distributed Task Execution (DTE) already goes a long way, but you still have to provision the agents by yourself. Providing the correct number of agents is crucial for maximizing efficiency and reducing idle time. And it is not even a static number but might depend on the actual run itself. Nx has extensive knowledge about the structure of the workspace and according tasks. We want to leverage that information. Imagine a setup where you have a roughly 20 line CI config for a repo with hundreds of developers and Nx Cloud automatically determines for each run the ideal number of agents required, provisions them, distributes all tasks efficiently and then disposes all agents again. All fully automatically. And it will be fast. To the point where you wouldn’t even need your Jenkins, CircleCI etc at all.
|
||||
|
||||
In addition, we are actively exploring ways to provide advanced analytics for your workspace, including insights into the frequency and duration of specific tasks. This valuable information can help identify large tasks that could benefit from being broken down into smaller ones, leveraging caching and other speed improvements to optimize performance. Stay tuned for more to come!
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -0,0 +1,337 @@
|
||||
---
|
||||
title: Nx Console gets Lit
|
||||
authors: [Max Kless]
|
||||
cover_image: '/blog/images/2023-06-29/featured_img.webp'
|
||||
tags: [nx, nx-console]
|
||||
---
|
||||
|
||||
Over the last few weeks, we rebuilt one of Nx Console’s most liked features from the ground up: The Generate UI. It looks better, loads faster, and preliminary research shows using it makes you happier, too ;)
|
||||
|
||||
You can use it today by installing the latest version of Nx Console for VSCode and JetBrains IDEs! 🎉🎉🎉
|
||||
|
||||
- [Nx Console on the VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
|
||||
- [Nx Console on the JetBrains Marketplace](https://plugins.jetbrains.com/plugin/21060-nx-console)
|
||||
|
||||
If you’re curious to learn more about the rewrite and the motivations behind it, this is the blog post for you! We’ll touch on these topics and more:
|
||||
|
||||
- Why did we choose to rewrite?
|
||||
- What’s Lit and why did we use it over Angular?
|
||||
- How did the rewrite go and what Lit features were important for us?
|
||||
- What does the performance look like before and after?
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/p455D4W7330?si=FRbiKJhGxT8dYzf9" /%}
|
||||
|
||||
## Background: Why Migrate from Angular to Lit?
|
||||
|
||||
### A Short History of Nx Console
|
||||
|
||||
Let’s go back in time: Nx Console has been around for a while. [It first launched in 2018](https://blog.nrwl.io/announcing-the-first-stable-release-of-angular-console-the-ui-for-the-angular-cli-bb19093a92d4?source=friends_link&sk=d955094b2cb872a130b47c8040ec820e) — then called Angular Console — as a standalone Electron app which let you run Angular schematics and builders from a graphical interface. Of course, it was built with Angular and looked something like this:
|
||||
|
||||

|
||||
|
||||
In 2019, [it was ported to a VSCode extension](https://blog.nrwl.io/brand-new-ui-custom-vscode-task-support-more-in-angular-console-9-0-5e4d3a109fb9?source=friends_link&sk=47fd72d5700b4cb3de09e559c5524ce5) with the now familiar UI and support for the standalone app was dropped.
|
||||
|
||||
In 2020, support for the entire Nx ecosystem was added, it was renamed to Nx Console and an amazing transformation began: Today, Nx Console is much more than just a single form — it tightly integrates Nx into your IDE, gives you the overview of your projects that you need and puts your task-running just a click away.
|
||||
|
||||
### Rewriting in Lit
|
||||
|
||||
This evolution brought significant improvements to the usability of Nx Console and the value we could provide to developers, but not without presenting its own set of challenges. Inevitably, the codebase grew complex and convoluted over time — the context in which it ran changed, the scope of the product changed, yet the technology remained the same. Adding small features or fixing bugs became increasingly time consuming, and every PR compounded the problem.
|
||||
|
||||
The UI looked somewhat outdated and had been built with only VSCode in mind — which became painfully obvious when support for JetBrains IDEs was added. While the web-based nature of the Generate UI allowed us to reuse the code in the new environment, the design looked out of place.
|
||||
|
||||
In addition, we started questioning our usage of Angular. Angular is a great framework for building web apps, and in the original context of Angular Console, it made a lot of sense: A tool built by and for Angular engineers — of course it’s written in Angular. But things changed, and Angular started to feel overkill for what we needed. Angular has a huge number of features right out of the box. But for our simple form, we didn’t need routing, http requests or modules to organize our code. The amount of boilerplate and overhead Angular introduces is significant.
|
||||
|
||||
So, ultimately, **we decided to pull the plug and rewrite the entire thing in [Lit](https://lit.dev/).**
|
||||
|
||||
Lit is a lightweight framework built on top of web components and “adds just what you need to be happy and productive: reactivity, declarative templates and a handful of thoughtful features to reduce boilerplate and make your job easier” (taken from their docs). We had used it before to [build the Nx Cloud view](https://blog.nrwl.io/nx-console-meets-nx-cloud-d45dc099dc5d?source=friends_link&sk=90215eb316ef332c1324f2d50cd3ad85) and were happy with the simple setup and great DX. So the decision to reuse it here was an easy one, since it allowed us to reuse code, build tooling and expertise. The rewrite also gave us the opportunity to improve the design for both supported IDEs and give the entire UI a clean, new coat of paint.
|
||||
|
||||

|
||||
|
||||
Before I dive deeper into specifics, let’s have a look at the general architecture of Nx Console first.
|
||||
|
||||
## Nx Console Architectural Overview
|
||||
|
||||
Nx Console is composed of 3 core parts:
|
||||
|
||||
- The **nxls** is a language server based on the [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) and acts as the “brain” of Nx Console. It analyzes your Nx workspace and provides information on it, including code completion and more.
|
||||
- The **Generate UI** is the form-based view for running Nx generators.
|
||||
- The **platform-specific wrappers**. These are written in Typescript and Kotlin and connect the rest of Nx Console to IDE-specific APIs. Having the other parts separate greatly reduces the amount of duplicated code we have to write in order to support multiple IDEs
|
||||
|
||||
This architecture’s modularity meant we could quickly switch out the Generate UI for a new version without significantly impacting the rest of the codebase — only the parts that actually render the UI and communicate with it had to be adjusted slightly. It also allowed us to ensure backward compatibility: the old generate UI is still available via a feature toggle in the settings.
|
||||
|
||||
If you want to dive deeper, there are many more resources on the architecture of Nx Console and how it’s built:
|
||||
|
||||
- [In-depth blog post about expanding to JetBrains IDEs](https://blog.nrwl.io/expanding-nx-console-to-jetbrains-ides-8a5b80fff2d7?source=friends_link&sk=967080ea30bdbf9f8132f098a2cdd188)
|
||||
- [Accompanying Youtube video by Zack DeRose](https://www.youtube.com/watch?v=xUTm6GDqwJM)
|
||||
- [The Power of Nx Console — talk by Jon Cammisuli](https://www.youtube.com/watch?v=3C_9g9kt2KM)
|
||||
|
||||
## Migrating to Lit: Step by Step
|
||||
|
||||
To rebuild our UI, we first needed a new Lit app to work on. While there’s no native Nx plugin for Lit, generating the code we need was still very straightforward:
|
||||
|
||||
`nx generate @nx/web:app --name generate-ui-v2`
|
||||
|
||||
This generates an entire project for us, with a `tsconfig.json`, `index.html`, `main.ts`, and a `project.json`, where our Nx-specific config lives.
|
||||
|
||||
I also installed a couple of dependencies:
|
||||
|
||||
- The `@nx/esbuild` plugin because I like fast build times 🏎️
|
||||
- TailwindCSS because I don’t like writing CSS 🤫
|
||||
- `@vscode/webview-ui-toolkit` because it does all of the VSCode work for me 🤖
|
||||
|
||||
This is really where Nx shines, because it allows you to take these tools and quickly patch them together and build a pipeline that does exactly what you need. And it also allows you to think about your workspace visually. This is what this is what my task graph for building the Lit app ultimately looks like:
|
||||
|
||||

|
||||
|
||||
You can see three build steps:
|
||||
|
||||
- `generate-ui-v2:_build` uses esbuild to bundle my Lit components written in Typescript and spits out a `main.js` file
|
||||
- `generate-ui-v2:extract-dependencies` copies the third party assets we need into the dist folder. Right now it’s just codicons `.css` and `.ttf` files.
|
||||
- `generate-ui-v2:build` finally runs tailwind over the bundled code. This could also be done with `postCss` or a custom `esbuild` plugin but running tailwind directly is the easier, so why complicate things?
|
||||
|
||||
> 💡 There are different ways to generate this visualisation for your own workspaces:
|
||||
>
|
||||
> - In VSCode, use the Nx Project View or the `Nx: Focus task in Graph` action
|
||||
> - In JetBrains IDEs, use the Nx Toolwindow or context menus
|
||||
> - In the command line, run `nx build {{your project}} --graph`
|
||||
|
||||
In the bigger context of Nx Console, here’s what happens when you build the VSCode extension:
|
||||
|
||||

|
||||
|
||||
You can see that we’re still building both the new & old generate UI as well as the Nxls and the Nx Cloud webview before combining them all into one VSCode extension artifact.
|
||||
|
||||
### Building the Form
|
||||
|
||||
Lit is a very small library that provides useful abstractions over browser-native features like web components and messages. Here’s what a simple Lit component, written with Typescript, looks like:
|
||||
|
||||
```ts {% fileName="main.ts" %}
|
||||
@customElement('root-element')
|
||||
export class Root extends LitElement {
|
||||
render() {
|
||||
return html`<p>Hello World</p>`;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```html {% fileName="index.html" %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<script type="module" src="main.js"></script>
|
||||
<root-element></root-element>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
If you need to pass information up the DOM, you use normal events and you can set properties to send information to descendants. Check out the [Lit Docs](https://lit.dev/docs/components/rendering/) to learn more about how the render() method works, how to leverage reactivity, the shadow DOM and so much more.
|
||||
|
||||
> 💡 All code samples in this section have been adapted for brevity and clarity. So you won’t find this exact code anywhere, but it demonstrates the concepts well.
|
||||
|
||||
### Communicating with the IDE — using Reactive Controllers
|
||||
|
||||
To communicate with the host IDE, we were able to reuse almost all the logic from the previous UI (for more details, see [Communicating with IntelliJ](https://blog.nrwl.io/expanding-nx-console-to-jetbrains-ides-8a5b80fff2d7?source=friends_link&sk=967080ea30bdbf9f8132f098a2cdd188#d151) from the last blog post). Instead of a service that exposes observables that our component can consume, we used a [Reactive Controller](https://lit.dev/docs/composition/controllers/). Controllers are a neat feature of Lit — they hook into a component and can request DOM updates on their behalf. This eliminates the need for observable streams and subscriptions while keeping the communication code self-contained. Look at this example:
|
||||
|
||||
```ts {% fileName="main.ts" %}
|
||||
@customElement('root-element')
|
||||
export class Root extends LitElement {
|
||||
icc: IdeCommunicationController;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.icc = new IdeCommunicationController(this);
|
||||
}
|
||||
render() {
|
||||
return html`${JSON.stringify(this.icc.generatorSchema)}`;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts {% fileName="ide-communication-controller.ts" %}
|
||||
// ide-communication-controller.ts
|
||||
export class IdeCommunicationController implements ReactiveController {
|
||||
generatorSchema: GeneratorSchema | undefined;
|
||||
constructor(private host: ReactiveControllerHost) {}
|
||||
// ...
|
||||
private handleMessageFromIde(message: InputMessage) {
|
||||
// ...
|
||||
this.generatorSchema = message.payload;
|
||||
this.host.requestUpdate();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can see that `root-element` can really just deal with rendering the form contents, delegating communicating with the IDE and when to update the DOM to the controller.
|
||||
|
||||
### Rendering the form fields — using Mixins
|
||||
|
||||
The core part of the UI is the form. We built all kinds of inputs: text fields, checkboxes, (multi-) select boxes and array fields. While those each have unique implementations, displaying them is also going to take a lot of repeated code. Every fields needs a label and description. Every field needs to know about its validation state, how dispatch change events and what aria attributes to set. In order to keep this code clean and DRY, we used [Class Mixins](https://lit.dev/docs/composition/mixins/). Mixins aren’t really a Lit-specific feature, but I don’t see them used much in other frameworks. A mixin is essentially a factory that takes a class and returns another, modified class. Check out this example:
|
||||
|
||||
```ts {% fileName="field-mixin.ts" %}
|
||||
const Field = (superClass) =>
|
||||
class extends superClass {
|
||||
// we can define (reactive) properties that every field is going to need
|
||||
@property()
|
||||
option: Option;
|
||||
protected get fieldId(): string {
|
||||
return `${this.option.name}-field`;
|
||||
}
|
||||
|
||||
// we can define methods that should be available to all fields
|
||||
dispatchValue(value: string) {
|
||||
// ...
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```ts {% fileName="field-wrapper-mixin.ts" %}
|
||||
const FieldWrapper = (superClass) =>
|
||||
class extends superClass {
|
||||
// we can define a render() method so that fields are all rendered the same
|
||||
protected render() {
|
||||
return html` <label for="${this.fieldId}">${this.option.name}</label>
|
||||
<p>${this.option.description}</p>
|
||||
${this.renderField()}`;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```ts {% fileName="input-field.ts" %}
|
||||
@customElement('input-field')
|
||||
export class InputField extends FieldWrapper(Field(LitElement)) {
|
||||
renderField() {
|
||||
return html` <input
|
||||
id="${this.fieldId}"
|
||||
@input="${(e) => this.dispatchValue(e.target.value)}"
|
||||
/>`;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can see that each component and mixin deals with a specific subset of the overall logic, keeping our code cleanly separated and reusable. A checkbox, for example, is a special case because it’s layout on the page is slightly different — no problem, we simply wrote a CheckboxWrapper with some modifications without having to worry about changing the checkbox logic itself.
|
||||
|
||||
> 💡 Properly typing mixins is complicated so I left that part out. Refer to [Mixins in Typescript](https://lit.dev/docs/composition/mixins/#mixins-in-typescript) to learn more or [check out our source code on GitHub](https://github.com/nrwl/nx-console).
|
||||
|
||||
### Injecting Services & Data — Lit Context
|
||||
|
||||
If you’re coming from the Angular world, you probably appreciate the great dependency injection (DI) mechanism they have. You can centrally define some services and reuse them across your app, without thinking about passing on props from component to component — the DI system takes care of it. Lit provides something similar via the []`@lit-labs/context`](https://lit.dev/docs/data/context/) package. It’s based on the [Context Community Protocol](https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md) and similar to React’s context API.
|
||||
|
||||
Under the hood, it still works with normal browser events, but it abstracts it away from you so you can easily share data and services across your app.
|
||||
|
||||
The Generate UI is rendered in both VSCode and JetBrains IDEs. In order to look appropriate, components need to know which environment they’re in and adjust styling accordingly. Instead of passing this information from component to component, we can make it available contextually! And with a proper mixin, reading the editor context only has to be implemented once, too.
|
||||
|
||||
Have a look at the following example:
|
||||
|
||||
```ts {% fileName="editor-context.ts" %}
|
||||
export const editorContext = createContext<'vscode' | 'intellij'>(
|
||||
Symbol('editor')
|
||||
);
|
||||
|
||||
const EditorContext = (superClass) =>
|
||||
class extends superClass {
|
||||
@consume({ context: editorContext })
|
||||
@state()
|
||||
editor: 'vscode' | 'intellij';
|
||||
};
|
||||
```
|
||||
|
||||
```ts {% fileName="ide-communication-controller.ts" %}
|
||||
export class IdeCommunicationController implements ReactiveController {
|
||||
// ...
|
||||
constructor(private host: ReactiveElement) {
|
||||
const editor = isVscode() ? 'vscode' : 'intellij';
|
||||
// provide the context to all DOM children of the host element
|
||||
new ContextProvider(host, {
|
||||
context: editorContext,
|
||||
initialValue: editor,
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts {% fileName="some-component.ts" %}
|
||||
@customElement('some-component')
|
||||
export class SomeComponent extends EditorContext(LitElement) {
|
||||
render() {
|
||||
return html`<p>I am rendered in ${this.editor}</p>`;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### VSCode Webview UI Toolkit
|
||||
|
||||
As we mentioned above, a big part of why we rewrote the UI is that it looked quite out of place in JetBrains IDEs. It was still useful, of course, but it’s important to make sure the form _feels_ right.
|
||||
|
||||
In VSCode, this is very easy to achieve, thanks to the [VSCode Webview UI Toolkit](https://github.com/microsoft/vscode-webview-ui-toolkit). It’s a set of web components, provided by Microsoft, that are designed to look good and be used in VSCode webviews.
|
||||
|
||||

|
||||
|
||||
Using it, you get the native look, a11y, and theme-aware styling for free! Thanks to everyone who built it, it’s a huge help!
|
||||
|
||||
### E2E Testing with Cypress
|
||||
|
||||
One big upside of using a webview is the huge Javascript ecosystem is available to you! To make sure that no regressions are introduced later on, we use [Cypress](https://www.cypress.io/). We can mock the editor communication and provide different schemas, make sure the form is rendered correctly and the right messages are sent back to the IDE.
|
||||
|
||||
While there’s no particular Lit integration for Cypress, the tool itself is framework agnostic so it still works perfectly fine. Using the [`@nx/cypress`](/nx-api/cypress) executors did most of the work for us so setup was pretty quick too.
|
||||
|
||||
### Results: Comparing Performance
|
||||
|
||||
There’s a number of different aspects to performance we can compare between the two implementations. The biggest one by far is not really quantifiable: The maintainability and looks of the new UI. In my opinion, it looks a lot fresher and more native in both environments. We got rid of a lot of legacy code and the new version is easier to reason about and work with.
|
||||
But there are thing we _can_ measure, so let’s talk numbers!
|
||||
|
||||
### Startup Time
|
||||
|
||||
It takes time to bootstrap a large framework like Angular, so skipping that, the UI should load quicker than before.
|
||||
|
||||
We measured the median time it took to render all options of the `@nx/angular:application` generator in both VSCode and IntelliJ. You can see that the results are pretty clear-cut, even though they are not hugely impactful.
|
||||
|
||||
Old UI (Angular)New UI (Lit)SpeedupVSCode65 ms39 ms~ 1.7xIntelliJ189 ms122 ms~ 1.5x
|
||||
|
||||
### Bundle Size
|
||||
|
||||
As mentioned earlier, Angular comes with a lot more features out-of-the-box than Lit, so it would make sense that the built bundle will be bigger.
|
||||
|
||||
We were able to reduce the bundle size (w/o compression) from about 733 kB to 282 kB, which comes out to about a 2,6x decrease. Unlike a website, where the bundle needs to be shipped to users when they load a page, Nx Console users only need to download it once when installing the plugin. This means we’re not affected by network speeds after installation, which makes the bundle size less critical.
|
||||
|
||||
> 💡 Because of a misconfiguration from a few Angular versions ago, the bundle size that we reported in:
|
||||
|
||||
{% tweet url="https://twitter.com/MaxKless/status/1671095858182381569" /%}
|
||||
|
||||
was overly bloated. We corrected it, but Lit still came out ahead in terms of size and rendering times.
|
||||
|
||||
### Build Time
|
||||
|
||||
While it might not be important to users of Nx Console, the time it takes to build the project makes a difference to us developers.
|
||||
|
||||
Since Lit is just javascript files that don’t require a custom compiler or build tooling, we decided to use [`esbuild`](https://esbuild.github.io/) (via `@nx/esbuild`), which is written in Go and extremely fast. On the other hand, the old UI used the `@angular-builders/custom-webpack:browser` builder, which uses webpack under the hood.
|
||||
|
||||
We went from about 3.5 seconds to less than 2 seconds of build time, which is less of an improvement than we expected. Since we also have to run tailwind over our files, some of that additional `esbuild` speed seems to be relativized.
|
||||
|
||||
## Looking Ahead
|
||||
|
||||
Rebuilding the UI has paved the road to reduce a lot of the maintenance burden of Nx Console. It will allow us to move even quicker on building new features to provide the best developer experience possible for you.
|
||||
|
||||
Specifically, the updated architecture enabled us to build a (still secret and WIP) plugin feature for Nx Console. Just like Nx, there are always going to be things that are unique to your workspace. We want to make it easy for you to extend and modify Nx Console in ways that help you make the most of using it.
|
||||
|
||||
So keep your eyes peeled for announcements and let us know via GitHub or Twitter if you have any ideas! We’d love to chat.
|
||||
|
||||
## One more thing!
|
||||
|
||||
Nx Console is a tool by developers for developers and there’s one thing we love — keyboard shortcuts. So of course we had to build some in. In addition to being keyboard-friendly and tabbable, you can do the following:
|
||||
|
||||
- `Cmd/Ctrl + Enter` to run the generator
|
||||
- `Cmd/Ctrl + Shift + Enter` to start a dry run
|
||||
- `Cmd/Ctrl + Shift + S` to focus the search bar and look for a specific option. Just `tab` to get back to the form
|
||||
|
||||
If the prettier UI and better performance haven’t convinced you, this surely will! 😉
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -5,7 +5,7 @@ cover_image: '/blog/images/2023-08-15/featured_img.png'
|
||||
tags: [nx, changelog, release]
|
||||
---
|
||||
|
||||
In the ever-evolving web development landscape, efficiency and modularity have become paramount. This is where [Nx](https://nx.dev) and [Qwik](https://qwik.dev/) come into play.
|
||||
In the ever-evolving web development landscape, efficiency and modularity have become paramount. This is where [Nx]() and [Qwik](https://qwik.dev/) come into play.
|
||||
|
||||
Qwik is a modern web framework that focuses on application performance by reducing the amount of JavaScript that needs to be shipped to the browser. You can learn more about how Qwik achieves this with [Resumability in their docs](https://qwik.dev/docs/concepts/resumable/).
|
||||
|
||||
@@ -13,7 +13,7 @@ Nx is a powerful tool that helps you build extensible and maintainable codebases
|
||||
|
||||
In this blog post, we’ll explore how to combine the strengths of Nx and Qwik to create a todo app. To do this, we’ll take advantage of an Nx Plugin that was created by the Qwikifiers team to maximise the integration between Qwik and Nx, called [`qwik-nx`](https://github.com/qwikifiers/qwik-nx).
|
||||
|
||||
> You do not necessarily need to use an Nx Plugin for Qwik. Instead, you could use the [Qwik CLI](https://qwik.dev/docs/getting-started/#create-an-app-using-the-cli) to create your application and [add Nx later](/recipes/adopting-nx/adding-to-existing-project#installing-nx-on-a-non-monorepo-project).
|
||||
> You do not necessarily need to use an Nx Plugin for Qwik. Instead, you could use the [Qwik CLI](https://qwik.dev/docs/getting-started/#create-an-app-using-the-cli) to create your application and [add Nx later](/recipes/adopting-nx/adding-to-existing-project#install-nx-on-a-nonmonorepo-project).
|
||||
> In this blog post we use the `qwik-nx` plugin to leverage better DX provided by the generators offered by the Plugin.
|
||||
|
||||
**Table of Contents**
|
||||
@@ -25,11 +25,12 @@ In this blog post, we’ll explore how to combine the strengths of Nx and Qwik t
|
||||
- [Generate a Library](#generate-a-library)
|
||||
- [Add a Qwik Context](#add-a-qwik-context)
|
||||
- [Using the Context](#using-the-context)
|
||||
- [Adding a routeLoader$ to load data on Navigation](#adding-a-to-load-data-on-navigation)
|
||||
- [Adding a `routeLoader$` to load data on Navigation](#adding-a-routeloader-to-load-data-on-navigation)
|
||||
- [Handle the Form Action to add todos](#handle-the-form-action-to-add-todos)
|
||||
- [Improve the Architecture](#improve-the-architecture)
|
||||
- [Conclusion](#conclusion)
|
||||
- [Further Reading](#further-reading)
|
||||
- [Learn more](#learn-more)
|
||||
|
||||
You can learn more about this integration in the video below:
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Nx Raises $16M Series A
|
||||
authors: [Jeff Cross]
|
||||
tags: [nx]
|
||||
---
|
||||
|
||||
Victor and I are excited to announce that Nx has raised another $16M in a Series A funding round with Nexus Venture Partners and a16z! See our announcement video for more, and be sure to check out the [live stream of Nx Conf 2023](https://youtube.com/live/IQ5YyEYZw68?feature=share) tomorrow to see what we’re up to!
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/KuyYhC4ClW8?si=qoZL6i6X1E7wjChD" %}
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -0,0 +1,497 @@
|
||||
---
|
||||
title: Nx Conf 2023 — Recap
|
||||
authors: [Juri Strumpflohner]
|
||||
cover_image: '/blog/images/2023-10-13/featured_img.webp'
|
||||
tags: [nx, nx-conf]
|
||||
---
|
||||
|
||||
The 3rd edition of [Nx Conf](/conf), this year live from New York City. If you missed the talks, no worries, we’ve got you covered. This article does a brief recap of all the presentations and has links to the individual recordings and slides.
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/P_W8MwX25a0?si=gpjul3hdqmOiBdev" /%}
|
||||
|
||||
## Keynote
|
||||
|
||||
**Speaker:** [Juri Strumpflohner](https://twitter.com/juristr) & [Victor Savkin](https://twitter.com/victorsavkin)
|
||||
|
||||
{% youtube src="https://www.youtube.com/watch?v=WSqivWlEDFw" /%}
|
||||
|
||||
Juri Strumpflohner (me 😅) opens the keynote. He focuses on the Nx ecosystem, how it is [much more than monorepos](/getting-started/why-nx) by helping you integrate your framework of choice (whether that is Angular, React, or Vue) with tooling such as ESLint, Playwright, Cypress, Webpack, ESBuild, Vite etc.
|
||||
|
||||

|
||||
|
||||
Such integration capabilities really help push the developer productivity, whether that’s in single-project workspaces or monorepos.
|
||||
Juri also dives deeper into efforts from the team to provide high quality educational content around Nx and its capabilities. The [Nx docs](/getting-started/intro) have been restructured to follow the [Diataxis](https://diataxis.fr/) framework, dividing content into into learning-, task-, understanding- and information-oriented sections.
|
||||
|
||||

|
||||
|
||||
This makes it easier to find keep the content organized and focused and makes it easier for the reader to choose between solution-oriented [recipes](/recipes) vs learning-oriented [tutorials](/getting-started/tutorials).
|
||||
|
||||
The Nx team not only produces written content, but also video content mainly on the [Nx YouTube Channel](https://www.youtube.com/@nxdevtools). Juri shows some of the growth stats, with the channel now having more than 14k subscribers and around 3.7k hours of watch time per month. The channel serves mostly short-form videos about new releases, highlighting new features as well as longer-form tutorial videos.
|
||||
|
||||
The Nx Community also got a special place in the keynote. Juri highlighted in particular the transition from the “Nrwl Community Slack” to the new “Nx Community” on Discord.
|
||||
|
||||

|
||||
|
||||
Discord is built for managing communities and will open up a series of features to come. Things like a built-in forum to ask questions, the ability to highlight Nx events (e.g. the Nx live stream) and having powerful automation and moderation tools. Since the launch a couple of weeks ago, already 1500+ members have signed up. If you didn’t sign up yet, go to [https://go.nx.dev/community](https://go.nx.dev/community).
|
||||
Juri also highlighted the [Nx Champions](/community) program that got launched this year which helps with efforts to grow the Nx community. The program features members that stood out in the Nx community by helping support others, producing content or speaking at conferences about Nx and related tech.
|
||||
|
||||
Finally there were also two **announcements**:
|
||||
|
||||
- the Nx team decided to move off Medium for a better publishing experience but mainly also to avoid the paywall, something that the team has no control over. The new blog is currently being built and will be hosted at [blog](/blog). This also allows to better resurface information by being able to integrate blog articles into the Nx docs search and make them also accessible to the Nx AI Assistant which was the 2nd announcement.
|
||||
- the **Nx AI Assistant** is an experiment the team is running to use AI to improve discoverability on the Nx docs. The ChatGPT powered assistant allows to ask natural language questions and responds based on the Nx docs training data, also including links to the sources. Try it out at [ai-chat](/ai-chat) and use the feedback thumbs-up/down buttons to help improve it over time 🙏.
|
||||
|
||||
Also, Nx is open source: [https://github.com/nrwl/nx](https://github.com/nrwl/nx). Contribute! And while you’re there, don’t forget to give us a star 😃.
|
||||
|
||||
**Victor Savkin** began the second segment of the keynote discussing the hidden expenses that often plague large teams.
|
||||
|
||||

|
||||
|
||||
He emphasized that as an organization grows, so does the supporting work. This isn’t limited to just communication and management. Every artifact, be it code, process, or otherwise, needs to be assimilated into the broader context. This supporting work becomes intricate and demanding. He pointed out that the remote work trend, while it started with a lot of momentum, struggles in larger corporations because it demands even more coordination and effort. In contrast, smaller entities often outshine their larger counterparts due to the reduced overhead of supporting work.
|
||||
|
||||
One of Victor’s main points was the potential of software developers. Given the right tools and environment, they can achieve remarkable feats. CI is one such tool.
|
||||
|
||||

|
||||
|
||||
The state of CI configuration, Victor explained, is essentially a meticulous blueprint of tasks for the CI tool. This blueprint defines everything from the number of machines to their precise roles. Historically, these processes were performed manually, with individuals running test cases and subsequently approving or rejecting them.
|
||||
|
||||
However, scaling CI is a challenge. In larger workspace, up to 50 agents is pretty common, all requiring careful coordination and configuration to ensure tasks run in the correct order.
|
||||
|
||||

|
||||
|
||||
This might be manageable in a static repository setup, but monorepos introduce an added layer of complexity. Here, static “CI recipes” just won’t cut it. The result is either an overuse of computational resources, leading to waste of money, or a painfully slow CI.
|
||||
|
||||
Victor critiqued that most current CI setups are:
|
||||
|
||||
- Oriented towards machines
|
||||
- Low-level in their configuration
|
||||
- Maintenance-heavy
|
||||
- Detached from developer intentions
|
||||
- Challenging to implement with monorepos
|
||||
|
||||
The big question: how can we revolutionize CI? Victor then showcased a demo workspace and highlights where the complexity of setting up CI comes from:
|
||||
|
||||

|
||||
|
||||
Even running e2e tests on CI requires:
|
||||
|
||||
- Building the application to be tested to produce an artifact
|
||||
- That usually requires first building all libraries the app depends on, in the correct order
|
||||
- Once all libraries are built, the application itself can be build
|
||||
- Finally e2e can be run on the application artifact
|
||||
|
||||
Notice, since we want to do this as fast as possible, we want to parallelize these operations across machines. This involves also taking care of transferring build artifacts between them.
|
||||
|
||||
This is where **Nx Cloud Workflows** shines. It enables developers to draft CI configurations at a far more abstract level. Instead of delving into the minutiae of tasks, developers specify **what** commands to execute, with the **how** being implicitly managed by Nx Cloud.
|
||||
|
||||
```yaml
|
||||
env:
|
||||
NODE_OPTIONS: '--max_old_space_size=4096'
|
||||
setup:
|
||||
- name: Git Checkout
|
||||
uses: 'nx-cloud-steps/checkout'
|
||||
- name: Npm Install
|
||||
uses: 'nx-cloud-steps/npm-install'
|
||||
steps:
|
||||
- name: CI Checks
|
||||
parallel-scripts: |
|
||||
nx affected -t build e2e --parallel=1
|
||||
nx affected -t test lint --parallel=3
|
||||
```
|
||||
|
||||
This elevated abstraction is possible because Nx Cloud & Nx are intimately familiar with the workspace, understanding the interdependencies between projects and tasks.
|
||||
|
||||

|
||||
|
||||
Beyond simplifying CI configurations, Nx Cloud Workflows helps optimize computational resource use. Agents are instantiated dynamically based on the project’s requirements.
|
||||
|
||||

|
||||
|
||||
Victor highlighted that most current CI setups:
|
||||
|
||||
- Consistently utilize a predetermined number of agents, irrespective of the actual needs of the PR
|
||||
- Possess non-reusable agents since each is tailored to a specific task, like building or testing
|
||||
- Struggle with granular retries
|
||||
|
||||
As a metaphor Victor mentions that **Nx Cloud Workflows is to CI what S3 is to file uploads.**
|
||||
|
||||

|
||||
|
||||
Sounds interesting? Watch the entire talk below:
|
||||
|
||||
{% youtube src="https://www.youtube.com/watch?v=WSqivWlEDFw" /%}
|
||||
|
||||
## Nx Cloud Workflows: Next-Gen CI with First-Class Monorepo Support
|
||||
|
||||
**Speaker:** Simon Critchley
|
||||
[Slides](https://docs.google.com/presentation/d/18EHfZ4UUtnAlzl15Ul_GPsr5lxNFtEEFPuT1uvxIEAk/edit?usp=sharing)
|
||||
|
||||
{% youtube src="https://youtu.be/JG1FWfZFByM?si=pNQNCLsbn5U0uSFB" /%}
|
||||
|
||||
Simon Critchley (Senior Software Architect at Nx) dives into the more technical details of the newly announced **Nx Cloud Workflows** (which is in private beta as of this writing).
|
||||
|
||||

|
||||
|
||||
Apart from the distributed caching, Nx Cloud already offers [DTE (Distributed Task Execution)](/ci/features/distribute-task-execution), which is a mechanism to seamlessly distribute tasks across various machines to achieve a high degree of parallelism. Up until now it was on you to configure your existing CI in a way to provision machines (agents) to Nx Cloud DTE. This required some fine-tuning to understand the best level of parallelism given the underlying monorepo and tasks that need to be run. If you have too many machines, it’ll be wasteful, if you have to few your CI will be slower.
|
||||
|
||||
Nx Cloud Workflow is an advancement of the DTE mechanism, where machines can be automatically provisioned and scaled based on the tasks that need to be run. Essentially it is a replacement for your existing CI but way smarter because it is able to leverage the knowledge it has about the Nx workspace, historical data and can thus do a series of optimizations. Traditional CI systems are running low-level commands on machines. Nx Cloud Workflows is task oriented instead: you tell it to run builds, tests, e2e, linting on the affected projects of the Nx workspace and it figures out how to split them up into fine-grained tasks and then distributes them among dynamically provisioned agents.
|
||||
|
||||
From a developer’s perspective, Nx Cloud Workflows are written in Yaml (or alternatively in JSON which is handy if you need to generate them). The format is very similar to existing CI providers to make sure the knowledge you have easily transfers. If you want an example, we’re dog-fooding Nx Cloud Workflows on the Nx repo (note the config will change as the product progresses): [https://github.com/nrwl/nx/blob/master/.nx/workflows/agents.yaml](https://github.com/nrwl/nx/blob/master/.nx/workflows/agents.yaml)
|
||||
|
||||
Simon then dives way deeper into the underlying architecture. In particular, how scheduling in Kubernetes works, which is used at the infrastructure level for Nx Cloud Workflows.
|
||||
|
||||

|
||||
|
||||
Workflow scheduling is handled by Kubernetes, specifically through a “Workflow Controller” that interacts with the K8s API Server and triggers Kubernetes Pods. Each Pod contains a Workflow executor and sidecar containers. All containers in the Nx Cloud workflow share a workspace volume for collaborative access. This allows for interesting optimizations in terms of sharing `node_modules` and restoring cache results.
|
||||
|
||||

|
||||
|
||||
The Workflow executor, written in Go, is responsible for receiving and executing workflow steps, capturing output, buffering logs, and communicating with the Workflow Controller. It also exposes its own grpc API for distributed locking, file system cache operations, and setting output parameters for each step, ensuring efficient workflow execution.
|
||||
|
||||
Nx Cloud Workflow is in its early development phase. The Kubernetes scheduler supports Docker based executors (basically any Docker image can be used as build image).
|
||||
|
||||

|
||||
|
||||
Windows, macOS and Linux is currently in development which will use a Cloud VM scheduler on the cloud of your choice.
|
||||
|
||||
## United by Nxcellent DX
|
||||
|
||||
**Speaker:** [Michael Hladky](https://twitter.com/Michael_Hladky)
|
||||
[Slides](https://docs.google.com/presentation/d/1F6_x3Jiu_3b9tZpxQnCrU60Eb1FhYR8E5jVnb1t7DjA/edit?usp=sharing)
|
||||
|
||||
{% youtube src="https://youtu.be/i0UdoImryJQ?si=a5lx6VnS__qhiyex" /%}
|
||||
|
||||
Michael talks about how to leverage Nx to migrate multiple repositories into a monorepo to streamline development and increase developer productivity. He goes through
|
||||
|
||||
- how a project gets started
|
||||
- how to prep moving to a monorepo from a polyrepo situation
|
||||
- how to do the move in parallel
|
||||
- how to measure the progress
|
||||
|
||||
The project usually starts with an architectural audit. That involves a detailed analysis of the underlying codebase, also including an executive summary for non technical folks. Once the audit is done, the actual move is planned and prepared. A part of that is to define “Nx migration goals”, like
|
||||
|
||||
- Single Version Policy
|
||||
- Improved Maintenance
|
||||
- Shared Infrastructure
|
||||
- Shared Architecture
|
||||
- Efficient Task Runs
|
||||
- Frictionless Code-Sharing
|
||||
- Frequent Deployments
|
||||
- Decouple Deployment
|
||||
|
||||
To prioritize which ones to address first, Michael uses the following metaphor:
|
||||
|
||||

|
||||
|
||||
The important part here is to understand why “apples get bad” in the first place. Is it the harvesting process?
|
||||
|
||||
Once the priorities are defined and roadmap laid out, the goal is to **move in parallel.**
|
||||
As part of that move the following gets produced:
|
||||
|
||||
- Migration Guide
|
||||
- Training Program
|
||||
- Communication Strategy
|
||||
- Impact Measurement
|
||||
|
||||
The migration guide defines where to start, what the company goals are, how the deliveries will be integrated into the existing process and how the interaction with the various teams will happen.
|
||||
|
||||
The training program is there to tackle the bottleneck of missing knowledge, right from the beginning. Each stage of the process will have a different training content and collect feedback.
|
||||
|
||||
Finally the impact measurement; Nx Cloud already has graphs to measure how much time got saved in CI due to the improvements made. Michael mentions they go further, also measuring communication and productivity.
|
||||
|
||||
An interesting part is also how they perform the repository synching (from polyrepo to monorepo). They leverage an Nx plugin that
|
||||
|
||||
- contains shared build logic
|
||||
- has rules to run that produce actionable feedback about what is needed to sync/align the polyrepo repository s.t. it can be merged into the monorepo
|
||||
- it also allows to track progress and produce according reporting of where the company is at
|
||||
|
||||
Sounds interesting? Watch the full talk below:
|
||||
|
||||
{% youtube src="https://www.youtube.com/watch?v=i0UdoImryJQ" /%}
|
||||
|
||||
## Redefining Projects with Nx: A Dive into the New Inference API
|
||||
|
||||
**Speaker:** [Craigory Coppola](https://twitter.com/enderagent)
|
||||
[Slides](https://craigory.dev/presentations/view/nx-conf-2023-inference/#1)
|
||||
|
||||
Demo Repo:
|
||||
{% github-repository url="https://github.com/AgentEnder/inference-demo" /%}
|
||||
|
||||
{% youtube src="https://www.youtube.com/watch?v=bnjOu7iOrMg" /%}
|
||||
|
||||
Craigory did a deep dive into the new Nx inference API. This is particularly interesting if you’re developing [Nx plugins](/extending-nx/intro/getting-started) or if you have leverage/build some more advanced automation for your Nx workspace.
|
||||
|
||||
What is project inference:
|
||||
|
||||
- how Nx reads your project configuration
|
||||
- introduced between v13.3 and v14
|
||||
- initially to support package-based monorepos which use package.json scripts rather than `project.json`. Generalizing the project config reading mechanism also allowed to define an API that community plugins can leverage and which allows to integrate even languages outside the JS ecosystem into Nx (e.g. where projects are just defined differently, such as .Net, Java, Python,..)
|
||||
|
||||
Inference API v1
|
||||
|
||||
- `projectFilePatterns` - identify files that represent the root of a project
|
||||
- `registerProjectTargets` - takes a project file and converts to a list of targets that Nx knows how to run
|
||||
|
||||
Shortcomings have been
|
||||
|
||||
- strict 1–1 mapping between project files and projects
|
||||
- the logic of finding proj files and targets had to be decoupled which introduced potential failure points
|
||||
- no way to add dynamic metadata to a project
|
||||
|
||||
Project graph API v2
|
||||
|
||||
- `createNodes` - finds graph nodes based on files on disk
|
||||
- `createDependencies` - finds edges to be added to the graph
|
||||
|
||||
Still 2 parts, but there’s no overlap between these two and they have very specific purposes.
|
||||
|
||||
`createNodes` is a tuple composed of:
|
||||
|
||||
- `projectFilePattern`
|
||||
- `CreateNodesFunction` It can return a map of projects and external nodes, so there's no more the shortcoming of a 1-1 as it was in v1 API. With this new setup multiple plugins might detect the same project. Nx merges the configuration that has been identified. Kinda what happens right now if you mix `package.json` and `project.json` targets in an Nx workspace.
|
||||
|
||||
Craigory demos the inference API by building a spell checking plugin for Nx.
|
||||
|
||||
`createDependencies` replaces `processProjectGraph`. It is more constrained but mainly because things like adding nodes should be done in a different function now (e.g. `createNodes`). This has also advantages for Nx itself, as it knows all nodes will have been created after the `createNodes` has terminated.
|
||||
|
||||
This API is still marked as experimental, next steps will be
|
||||
|
||||
- mark as stable
|
||||
- remove v1 API after deprecation period
|
||||
- plugin authors should start looking into the new API, provide feedback and think about migration scenarios
|
||||
|
||||
## Package-based to Integrated: One Small Step or One Giant Leap?
|
||||
|
||||
**Speaker:** [Isaac Mann](https://twitter.com/MannIsaac)
|
||||
[Slides](https://drive.google.com/file/d/1V1ocFIjYkRrcNXWuvUK1T8dQEceDcjvw/view?pli=1)
|
||||
|
||||
Repo:
|
||||
{% github-repository url="https://github.com/isaacplmann/space-station-tracker/tree/final" /%}
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=nY0_o7zWBLM" /%}
|
||||
|
||||
Isaac initiated his talk by drawing an analogy between software development and the moon landing. While Neil Armstrong is often singularly celebrated for setting foot on the moon, Isaac emphasized that the monumental achievement was the collective effort of countless individuals on the ground crew, from engineers to support staff.
|
||||
|
||||
> Isaac: Nx wants to be that indispensable ground support crew for developers, allowing them to push the boundaries of software development.
|
||||
|
||||
Currently, Nx offers support for two predominant monorepo styles: package-based and integrated.
|
||||
|
||||
### Package-based Monorepos:
|
||||
|
||||
- These are tailored for flexibility and innovation.
|
||||
- Packages within this setup can have diverse configurations.
|
||||
- Every package boasts its individual node_modules and dependencies.
|
||||
- Crucially, each can be upgraded independently, offering a high degree of autonomy.
|
||||
|
||||
### Integrated Monorepos:
|
||||
|
||||
- These are structured to prioritize consistency and maintainability.
|
||||
- Updates within this framework are automated, and the setup adheres to a single-version policy.
|
||||
|
||||
Isaac then drew parallels between the Apollo program and the package-based mindset. The Apollo missions were evolutionary in nature, constantly pushing the envelope and embracing innovation with each successive mission. However, this trailblazing approach wasn’t without its perils, as evidenced by tragic accidents. This experimental approach was feasible because the core team, responsible for creating the setup, remained consistent throughout the project’s duration.
|
||||
|
||||
In contrast, Isaac likened the International Space Station (ISS) to the integrated mindset. The ISS epitomizes the challenges of coordination, given its international collaboration involving numerous countries. Emphasizing longevity, the ISS necessitates that every new crew member be proficient in operating its intricate machinery.
|
||||
|
||||
Shifting gears, Isaac delved into a hands-on demonstration. He outlined the process of transitioning from a package-based monorepo to an integrated one, including demoing:
|
||||
|
||||
- Initializing Nx with `nx init`.
|
||||
- Establishing new projects to facilitate type sharing across applications.
|
||||
- Harnessing the power of the Nx graph visualization to navigate and understand the project structure.
|
||||
- Employing the module boundary rule, ensuring constraints are maintained in the revamped structure.
|
||||
- Devising a novel Nx generator, streamlining the process of setting up new libraries within the workspace.
|
||||
- Finally, he showcased the seamless upgrade mechanism, ensuring the workspace is always aligned with the latest version.
|
||||
|
||||
## Nx’t Level Publishing
|
||||
|
||||
**Speaker:** [James Henry](https://twitter.com/MrJamesHenry)
|
||||
[Slides](https://main--idyllic-dieffenbachia-3699ec.netlify.app/1)
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=p5qW5-2nKqI" /%}
|
||||
|
||||
James Henry unveils the new versioning and publishing functionality that is now built into Nx itself.
|
||||
|
||||
Nx has always given you the building blocks to do integrate the versioning and publishing; you could easily use Lerna with Nx, or changesets, release-it as well as a series of Nx Community plugins
|
||||
The nx core team decided to go into this problem space and provide an opinionated approach that is easy to use within existing Nx workspaces; something that works and scales; also something that works outside the JS ecosystem which Nx can also be used with
|
||||
|
||||
New command `nx release`
|
||||
|
||||
- `nx release version` to determine and apply version updates
|
||||
- `nx release` changelog generate a CHANGELOG.md file and optional GitHub releases based on git commits
|
||||
- `nx release` publish takes a newly versioned project and publishes them to a remote registry (e.g. NPM)
|
||||
|
||||
This new command is not tight to `package.json` files but is general purpose; clearly publishing JS/TS packages is the main use case right now in Nx
|
||||
Important to note that all the existing plugins are still valid and will still be going forward.
|
||||
|
||||
James goes forward demoing how `nx release` works in a simple NPM package: [jump directly into the video](https://www.youtube.com/watch?si=xoIW0Q-mQWTGgrek&t=411&v=p5qW5-2nKqI&feature=youtu.be).
|
||||
|
||||
Nx release can be added to any npm package. All that’s needed is the `nx` and `@nx/js` package and a `nx: {}` node in the `package.json`.
|
||||
|
||||
Nx release has a dry-run mode; `nx release version --dry-run`. This will output a diff of what version would be created and on which `package.json` files (if there are multiple).
|
||||
The same mechanism also works for the `changelog` command, e.g. `nx release changelog --dry-run`. In addition to just dry-run, the `changelog` command also has an `--interactive` mode that allows to get the generated changelog in an interactive editor where you can adjust and add extra stuff.
|
||||
|
||||
James then moves on to show how the release process works in a monorepo scenario using pnpm workspaces, where there are multiple NPM packages that need to be published: [jump to the video](https://www.youtube.com/watch?si=BvFvRQjgtwOxu-Dv&t=777&v=p5qW5-2nKqI&feature=youtu.be).
|
||||
|
||||
The monorepo has a `pkg-a` and `pkg-b` where there's a relationship between them as follows: `pkg-a --> pkg-b`.
|
||||
If the `version` command is used in such scenario, it will also be applied to the dependent packages (`pkg-b`) since Nx knows about the dependencies via the project graph.
|
||||
A nice feature is also that the changelog will...
|
||||
|
||||
- automatically group first by type (e.g. features grouped together, fixes etc)
|
||||
- within each type grouping it will be grouped by scope such as pkg-a etc which will be alphabetized
|
||||
- if there’s a fix on the entire repo that’ll come first before the per-package changes
|
||||
|
||||
`nx release changelog --create-release=github` allows to also automatically push the changelog to a Github release.
|
||||
|
||||
When running `nx release publish`, Nx also takes into account the right order of how the packages should go on NPM. Like if there's a relationship `pkg-a --> pkg-b`, Nx automatically detects such dependency and will go and publish pkg-b first and then `pkg-a` which depends on it. That to make sure that even if there's a network error in between packages, you'd still not break anything.
|
||||
|
||||
Future roadmap:
|
||||
|
||||
- ability to customize how the release works by defining it in `nx.json`
|
||||
- “release groups” will allow to group packages and define whether versions should be in sync or versioned independently; filter by projects, or even just publish a subset of projects of a workspace
|
||||
- publishing also automatically takes into account the provenance data on NPM
|
||||
|
||||
## Lightning Talk: What if your stories were — already — your e2e tests?
|
||||
|
||||
**Speaker:** [Katerina Skroumpelou](https://twitter.com/psybercity)
|
||||
[Slides](https://drive.google.com/file/d/1XY8tefqqcM4k4swNPhlSrJiKxurMGiup/view)
|
||||
|
||||
Repo
|
||||
{% github-repository url="https://github.com/mandarini/storybook-play" /%}
|
||||
|
||||
[Live Demo](https://storybook-play.vercel.app/?path=/story/app--primary)
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=SWlvsDNXCsQ" /%}
|
||||
|
||||
Katerina starts by introducing the concept of UI testing for error detection, usability verification, regression prevention but also for validating the user journey and making sure the software is reliability.
|
||||
|
||||
Nx had support to use Storybook for doing component-level tests, both using a Cypress e2e setup as well as Cypress component tests. This is where Nx would fill in to launch Storybook to render a single component and then launch Cypress and run dedicated tests against that served component.
|
||||
Meanwhile Storybook has introduced so-called [Interaction Tests](https://storybook.js.org/docs/writing-tests/interaction-testing) which allow you to do something similar.
|
||||
|
||||
You can read more on [our docs](https://storybook.js.org/docs/writing-tests/interaction-testing). Or check out our corresponding video on Youtube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=SaHoUx-TUs8" /%}
|
||||
|
||||
## Lightning Talk: Nx Cloud Demo
|
||||
|
||||
**Speaker:** [Johanna Pearce](https://twitter.com/jhannapearce)
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=xc6fJpwk4Lo" /%}
|
||||
|
||||
Johanna gives us a tour through the Nx Cloud UI. So there’s not much to say other than [go watch the talk](https://www.youtube.com/watch?v=xc6fJpwk4Lo&feature=youtu.be) :)
|
||||
|
||||
## From DIY to DTE — An Enterprise Experience
|
||||
|
||||
**Speaker:** Adrian Baran
|
||||
[Slides](https://docs.google.com/presentation/d/1LPgCuYoVEIJqqhk8TLq4RAcHrJ5phJuiHHEGA3y_aws/edit?pli=1#slide=id.g25ac4b0c8f6_0_72)
|
||||
{% youtube src="https://www.youtube.com/watch?v=MsUN0wQHPAs" /%}
|
||||
|
||||
Adrian Baran, a Senior Software Engineer at Cisco, embarked on his talk by presenting the status quo of their monorepo which encompasses approximately 150 projects at the start of the experiment.
|
||||
|
||||

|
||||
|
||||
Their CI workflow is powered by CircleCI. For the purpose of clarity, Adrian zoomed in on the frequently executed tasks: `build`, `lint`, and `test`. To execute these tasks, they leverage the [Nx affected](/features/run-tasks#run-tasks-on-projects-affected-by-a-pr) command to avoid running all commands on all projects.
|
||||
|
||||

|
||||
|
||||
Despite that, on average CI runs on PRs still lingered around the 1-hour mark. The immediate remedy? Harnessing CircleCI to parallelize tasks across multiple machines, while continuing to utilize Nx affected. Adrian wrote about that journey in a blog post last year, titled [Nx Affected + CircleCI Parallelism = Faster CI/CD Pipelines](https://medium.com/@abaran30/nx-affected-circleci-parallelism-faster-ci-cd-pipelines-b4edc4caaaac).
|
||||
|
||||
They ended up with a loooot of parallelism:
|
||||
|
||||

|
||||
|
||||
The outcome was promising though — they witnessed a significant reduction, approximately 75%, in execution time, even in scenarios where all projects were influenced by a PR. Done, right?
|
||||
|
||||
However, as their monorepo burgeoned to encompass 400+ projects, the DIY solution began to show its limitations. The incessant parallelization implied the addition of more agents, leading to escalating costs. Furthermore, they observed considerable variability in task durations.
|
||||
|
||||

|
||||
|
||||
Their workaround was to manually allocate specific tasks to distinct agents. This method in addition to capping on a max number of agents helped keep costs under control, but regrettably, it also compromised performance due to the lowered parallelism.
|
||||
|
||||
This is when Cisco looked into running an [Nx Enterprise](/enterprise) pilot, specifically with the goal of adopting [DTE](/ci/features/distribute-task-execution). In the 2nd part of the talk, Adrian outlined their journey of setting up DTE, starting with the generation of the initial CI setup:
|
||||
|
||||
```shell
|
||||
nx g @nx/workspace:ci-workflow --ci=circleci
|
||||
```
|
||||
|
||||
They tuned the generated configuration, but failed to get it properly running, many of the issues leading to resource exhaustion. As a result, they went the route of going on a 1–1 mapping setup between DIY and DTE. That made sure the DTE setup was as close as possible and allowed for a gradual transition approach, which proved invaluable, allowing them to maintain stability whilst progressively migrating to DTE.
|
||||
|
||||
The comparative analysis of their DIY solution versus DTE revealed roughly equivalent performance metrics. However, the DTE framework shone in its simplicity, maintainability, and resource efficiency, achieving similar outcomes with a 75% reduction in resource utilization.
|
||||
|
||||

|
||||
|
||||
### Adrian’s Key Insights:
|
||||
|
||||
- DTE setup warrants a dual-pronged strategy: an immediate plan for initiation and a long-term vision for transition. Notably, Nx DTE supports incremental adoption.
|
||||
- Patience is paramount during the tuning phase to determine the optimal number of agents.
|
||||
- While results might vary, Adrian humorously assures that one can always bank on the Nx team for support. 😅
|
||||
|
||||
## Vanquishing Deployment Dragons with Nx wizardry
|
||||
|
||||
**Speaker:** [Miroslav Jonas](https://twitter.com/meeroslav)
|
||||
[Slides](https://speakerdeck.com/meeroslav/vanquishing-deployment-dragons-with-nx-wizardry)
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=jGF8vo2ChfI" /%}
|
||||
|
||||
There’s not much to say here. Lean back and [immerse yourself into the world of dragons and wizards.](https://www.youtube.com/watch?v=jGF8vo2ChfI)
|
||||
|
||||
## Optimizing your OSS infrastructure with Nx Plugins
|
||||
|
||||
**Speaker:** [Brandon Roberts](https://twitter.com/brandontroberts)
|
||||
[Slides](https://github.com/brandonroberts/nx-conf-2023/blob/main/nx-oss-infrastructure.pdf)
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=bNuXH25CTO0" /%}
|
||||
|
||||
Brandon discussed his work on the open-source tool [Analog](https://analogjs.org/) and how Nx Plugins are crucial to its development.
|
||||
|
||||
He introduced Analog, shedding light on its foundational ecosystem and the its core features.
|
||||
|
||||

|
||||
|
||||
Nx plays a crucial role in helping integrate and maintain these different tools:
|
||||
|
||||

|
||||
|
||||
How? Brandon dives straight into it by explaining how Nx plugins in particular can be useful, explaining:
|
||||
|
||||
- features of Nx plugins such as generators, executors, automated migrations, presets and how to use them just locally to automate your workspace
|
||||
- how to create a new plugin
|
||||
- the anatomy of a generator and how they can be useful in scaffolding new setups, but also integrating technology, like adding tRPC to your stack, etc.
|
||||
- similarly Nx executors provide a thin abstraction layer over the actual commands, allowing the plugin developer to update the underlying tooling without necessarily disrupting the end user
|
||||
- most importantly allowing to write automatic migrations he can leverage with Analog, like running `nx migrate @analogjs/platform@latest` to update a given workspace automatically to the latest version, across potentially breaking changes
|
||||
|
||||
Brandon highlighted a pivotal aspect for OSS package/framework authors: the power to not just assimilate into pre-existing Nx workspaces via custom Nx plugins but also to steer the entire workspace setup process. This is particularly beneficial when tailored setups specific to individual use cases are required. By leveraging an [Nx preset](/extending-nx/recipes/create-preset), one can achieve this tailored configuration. Brandon also touched upon the possibility of advancing further by constructing an [install package](/extending-nx/recipes/create-install-package) through Nx.
|
||||
|
||||
## Level Up Your Productivity with Nx Console
|
||||
|
||||
**Speaker:** [Jonathan Cammisuli](https://twitter.com/jcammisuli) & [Max Kless](https://twitter.com/MaxKless)
|
||||
[Slides](https://github.com/Cammisuli/nx-conf-2023/tree/main/tools/presentation)
|
||||
|
||||
Watch on YouTube:
|
||||
{% youtube src="https://www.youtube.com/watch?v=TTjVcWCdwVY" /%}
|
||||
|
||||
Jon and Max are the masterminds behind [Nx Console](/getting-started/editor-setup), the Nx IDE extension for Code and JetBrains.
|
||||
|
||||
They mention the release of the JetBrains IDE support earlier this year and give a big shoutout to [Issam](https://github.com/iguissouma) who was the original author of the Nx Console Webstorm community plugin and who helped a lot with the official Nx Console version for JetBrains IDE.
|
||||
|
||||
Jon and Max demo the new IntelliJ version of Nx console and how it properly integrates as well as how they wrote the new UI completely from the ground up [using Lit](/blog/2023-06-29-nx-console-gets-lit).
|
||||
|
||||
Clearly they did not spare showing off the awesome new graph capabilities built into Nx Console that allow you to directly navigate to files.
|
||||
|
||||

|
||||
|
||||
## That’s a wrap
|
||||
|
||||
If you enjoyed these, [subscribe to our YouTube channel](https://www.youtube.com/@nxdevtools) where we keep releasing educational content and fun videos.
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -46,7 +46,7 @@ And you’ll have access to Nx generators so that you can generate Vue applicati
|
||||
|
||||
We’re very excited for this support to land, and we’re eager to get it into our user’s hands and see what Nx can do to help Vue developers so we can continue to refine our support and make Vue with Nx an excellent developer experience.
|
||||
|
||||
If you’re eager to learn more, make sure to check out our new [Vue standalone tutorial](https://nx.dev/getting-started/tutorials/vue-standalone-tutorial).
|
||||
If you’re eager to learn more, make sure to check out our new [Vue standalone tutorial](/getting-started/tutorials/vue-standalone-tutorial).
|
||||
|
||||
## Enhancements to Module Federation Support
|
||||
|
||||
@@ -141,7 +141,7 @@ Finally, generators will now factory in your current working directory, so you c
|
||||
|
||||
## The NEW Nx AI ChatBot
|
||||
|
||||
We’ve added a new AI ChatBot to our docs site. You can access it now at [https://nx.dev/ai-chat](https://nx.dev/ai-chat).
|
||||
We’ve added a new AI ChatBot to our docs site. You can access it now at [https://nx.dev/ai-chat](/ai-chat).
|
||||
|
||||

|
||||
|
||||
@@ -170,9 +170,9 @@ We’ve also removed the need to specify `cacheableOperations` at the task-runne
|
||||
}
|
||||
```
|
||||
|
||||
If you use the `nx migrate` command, all updates will be handled for you using the `targetDefaults` in your `nx.json` file. [More in the docs.](https://nx.dev/features/cache-task-results)
|
||||
If you use the `nx migrate` command, all updates will be handled for you using the `targetDefaults` in your `nx.json` file. [More in the docs.](/features/cache-task-results)
|
||||
|
||||
We’ve been working hard at reducing and simplifying all the configuration required for your Nx workspaces. Checkout our latest guide on how to [Reduce Repetitive Configuration](https://nx.dev/recipes/running-tasks/reduce-repetitive-configuration) for more, and stay tuned as we’ve got new efforts underway to make this simplification even more appealing!
|
||||
We’ve been working hard at reducing and simplifying all the configuration required for your Nx workspaces. Checkout our latest guide on how to [Reduce Repetitive Configuration](/recipes/running-tasks/reduce-repetitive-configuration) for more, and stay tuned as we’ve got new efforts underway to make this simplification even more appealing!
|
||||
|
||||
## Nx Repo Dog-Fooding Nx Workflows
|
||||
|
||||
@@ -226,15 +226,15 @@ In Nx 17, we removed any remaining traces of `tslint` from our linter package, s
|
||||
|
||||
As we solidify this command, we intend to bring robust support for various versioning and publishing strategies, as well as built-in support for publishing packages or modules to a variety of languages, registries, and platforms.
|
||||
|
||||
For more [checkout our API docs](https://nx.dev/nx-api/nx/documents/release), and be sure to catch James Henry’s announcement of this new command at [Nx Conf](https://dev.to/nx/nx-conf-2023-recap-53ep):
|
||||
For more [checkout our API docs](/nx-api/nx/documents/release), and be sure to catch James Henry’s announcement of this new command at [Nx Conf](https://dev.to/nx/nx-conf-2023-recap-53ep):
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/p5qW5-2nKqI?si=FzpGMJwPVINc1hgL" /%}
|
||||
|
||||
## Experimental: Nx Project Inference API v2
|
||||
|
||||
At Nx, we’re OBSESSED with building a better, more robust experience for our developers. Towards this end, we’re now in [v2 of our Project Inference API](https://nx.dev/extending-nx/recipes/project-graph-plugins).
|
||||
At Nx, we’re OBSESSED with building a better, more robust experience for our developers. Towards this end, we’re now in [v2 of our Project Inference API](/extending-nx/recipes/project-graph-plugins).
|
||||
|
||||
This API is a way of extending the Nx project graph, which can be particularly helpful for extending Nx to support other languages, allowing Nx to determine where to find and draw boundaries around projects in your workspace. A great example is our very own [Vue plugin](https://nx.dev/getting-started/tutorials/vue-standalone-tutorial).
|
||||
This API is a way of extending the Nx project graph, which can be particularly helpful for extending Nx to support other languages, allowing Nx to determine where to find and draw boundaries around projects in your workspace. A great example is our very own [Vue plugin](/getting-started/tutorials/vue-standalone-tutorial).
|
||||
|
||||
Interestingly, v2 includes support for dynamic targets as well. This opens up exciting new doors to reducing configuration, and we hope to expand on this to better support our first-party plugins in the near future.
|
||||
|
||||
@@ -244,7 +244,7 @@ For most developers, the main thing you need to know is that plugins may now add
|
||||
> nx show project <project_name>
|
||||
```
|
||||
|
||||
For plugin authors, check out the [v2 documentation](https://nx.dev/extending-nx/recipes/project-graph-plugins) to see how you can take advantage of the new API to deliver a better experience to your users.
|
||||
For plugin authors, check out the [v2 documentation](/extending-nx/recipes/project-graph-plugins) to see how you can take advantage of the new API to deliver a better experience to your users.
|
||||
|
||||
## 20k Github Stars!!
|
||||
|
||||
@@ -254,7 +254,7 @@ Nx is SOOO CLOSE to 20,000 stars on github! If Nx has been helpful to you, [plea
|
||||
|
||||
## How to Update Nx
|
||||
|
||||
Nx is known to [help you automatically migrate](https://nx.dev/features/automate-updating-dependencies) to the new version (including potentially breaking changes). To update simply run:
|
||||
Nx is known to [help you automatically migrate](/features/automate-updating-dependencies) to the new version (including potentially breaking changes). To update simply run:
|
||||
|
||||
```shell
|
||||
> npx nx migrate latest
|
||||
@@ -274,7 +274,7 @@ That’s all for now folks! We’re just starting up a new iteration of developm
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](https://nx.dev/getting-started/intro)
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
|
||||
@@ -0,0 +1,623 @@
|
||||
---
|
||||
title: State Management Nx React Native/Expo Apps with TanStack Query and Redux
|
||||
authors: [Emily Xiong]
|
||||
image: '/blog/images/2023-11-08/featured_img.webp'
|
||||
tags: [nx, React Native]
|
||||
---
|
||||
|
||||
There are currently countless numbers of state management libraries out there. This blog will show you how to use state management for React Native in Nx monorepo with [TanStack Query](https://tanstack.com/query/latest) (which happens to use [Nx on their repo](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6412c827e6da5d7b4a0b1fe3/overview)) and Redux.
|
||||
|
||||
This blog will show:
|
||||
|
||||
- How to set up these libraries and their dev tools
|
||||
- How to build the sample page below in React Native / Expo with state management
|
||||
- How to do unit testing
|
||||
|
||||
It will call an API and show a cat fact on the page, allowing users to like or dislike the data.
|
||||
|
||||

|
||||
|
||||
Github repo: [https://github.com/xiongemi/nx-expo-monorepo](https://github.com/xiongemi/nx-expo-monorepo)
|
||||
|
||||
---
|
||||
|
||||
## Before We Start
|
||||
|
||||
From [TanStack Query documentation](https://tanstack.com/query/latest/docs/framework/react/guides/does-this-replace-client-state), it says:
|
||||
|
||||
- [TanStack Query](https://tanstack.com/query/latest/docs/framework/react/overview) is a **server-state** library.
|
||||
- [Redux](https://redux.js.org/) is a client-state library.
|
||||
|
||||
What is the difference between the server state and the client state?
|
||||
|
||||
In short:
|
||||
|
||||
- Calling an API, dealing with asynchronous data-> server state
|
||||
- Everything else about UI, dealing with synchronous data -> client state
|
||||
|
||||
## Installation
|
||||
|
||||
To use **[TanStack Query / React Query](https://tanstack.com/query/latest)** for the server state, I need to install:
|
||||
|
||||
- Library: [@tanstack/react-query](https://tanstack.com/query/latest)
|
||||
- Dev tools: [@tanstack/react-query-devtools](https://tanstack.com/query/latest/docs/framework/react/devtools)
|
||||
|
||||
I will use **Redux** for everything else.
|
||||
|
||||
- Library: [redux](https://github.com/reduxjs/redux), react-redux, @reduxjs/toolkit
|
||||
- Dev tools: [@redux-devtools/extension](https://github.com/zalmoxisus/redux-devtools-extension)
|
||||
- Logger: [redux-logger](https://github.com/LogRocket/redux-logger), [@types/redux-logger](https://www.npmjs.com/package/@types/redux-logger)
|
||||
- Storage: [redux-persist](https://github.com/rt2zz/redux-persist), [@react-native-async-storage/async-storage](https://github.com/react-native-async-storage/async-storage)
|
||||
|
||||
To install all the above packages:
|
||||
|
||||
```shell
|
||||
#npm
|
||||
npm install @tanstack/react-query @tanstack/react-query-devtools redux react-redux @reduxjs/toolkit @redux-devtools/extension redux-logger @types/redux-logger redux-persist @react-native-async-storage/async-storage --save-dev
|
||||
|
||||
#yarn
|
||||
yarn add @tanstack/react-query @tanstack/react-query-devtools redux react-redux @reduxjs/toolkit @redux-devtools/extension redux-logger @types/redux-logger redux-persist @react-native-async-storage/async-storage --dev
|
||||
|
||||
#pnpm
|
||||
pnpm add @tanstack/react-query @tanstack/react-query-devtools redux react-redux @reduxjs/toolkit @redux-devtools/extension redux-logger @types/redux-logger redux-persist @react-native-async-storage/async-storage --save-dev
|
||||
```
|
||||
|
||||
## Server State with React Query
|
||||
|
||||
### Setup Devtools
|
||||
|
||||
First, you need to add React Query / TanStack Query in the `App.tsx`:
|
||||
|
||||
```tsx
|
||||
import React from 'react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
const App = () => {
|
||||
const queryClient = new QueryClient();
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{Platform.OS === 'web' && <ReactQueryDevtools />}
|
||||
...
|
||||
</QueryClientProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
```
|
||||
|
||||
Note: the [React Query Devtools](https://tanstack.com/query/latest/docs/framework/react/devtools) currently do not support react native, and it only works on the web, so there is a condition: `{ Platform.OS === ‘web’ && <ReactQueryDevtools />}.`
|
||||
|
||||
For the react native apps, in order to use this tool, you need to use [react-native-web](https://necolas.github.io/react-native-web/) to interpolate your native app to the web app first.
|
||||
|
||||
If you open my Expo app on the web by running `nx start cats` and choose the options `Press w │ open web`, you should be able to use the dev tools and see the state of my react queries:
|
||||
|
||||

|
||||
|
||||
Or you can run npx nx serve cats to launch the app in a web browser and debug from there.
|
||||
|
||||
### Create a Query
|
||||
|
||||
What is a query?
|
||||
|
||||
> “A query is a declarative dependency on an asynchronous source of data that is tied to a unique key. A query can be used with any Promise-based method (including GET and POST methods) to fetch data from a server.” [(https://tanstack.com/query/v4/docs/react/guides/queries)](https://tanstack.com/query/v4/docs/react/guides/queries)
|
||||
|
||||
Now let’s add our first query. In this example, it will be added under `lib/queries` folder. To create a query to fetch a new fact about cats, run the command:
|
||||
|
||||
```shell
|
||||
# expo workspace
|
||||
npx nx generate @nx/expo:lib use-cat-fact --directory=queries
|
||||
|
||||
# react-native workspace
|
||||
npx nx generate @nx/react-native:lib use-cat-fact --directory=queries
|
||||
```
|
||||
|
||||
Or use [Nx Console](/recipes/nx-console):
|
||||
|
||||

|
||||
|
||||
Now notice under libs folder, `use-cat-fact` folder got created under `libs/queries`:
|
||||
|
||||

|
||||
|
||||
If you use React Native CLI, just add a folder in your workspace root.
|
||||
|
||||
For this app, let’s use this API: [https://catfact.ninja/](https://catfact.ninja/). At `libs/queries/use-cat-fact/src/lib/use-cat-fact.ts`, add code to fetch the data from this API:
|
||||
|
||||
```ts
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
export const fetchCatFact = async (): Promise<string> => {
|
||||
const response = await fetch('https://catfact.ninja/fact');
|
||||
const data = await response.json();
|
||||
return data.fact;
|
||||
};
|
||||
|
||||
export const useCatFact = () => {
|
||||
return useQuery({
|
||||
queryKey: ['cat-fact'],
|
||||
queryFn: fetchCatFact,
|
||||
enabled: false,
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
Essentially, you have created a custom hook that calls useQuery function from the TanStack Query library.
|
||||
|
||||
### Unit Testing
|
||||
|
||||
If you render this hook directly and run the unit test with the command `npx nx test queries-use-cat-fact`, this error will show up in the console:
|
||||
|
||||
```shell
|
||||
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
||||
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
||||
2. You might be breaking the Rules of Hooks
|
||||
3. You might have more than one copy of React in the same app
|
||||
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
|
||||
```
|
||||
|
||||
To solve this, you need to wrap your component inside the renderHook function from `@testing-library/react-native` library:
|
||||
|
||||
1. **Install Library to Mock Fetch**
|
||||
|
||||
Depending on which library you use to make HTTP requests. (e.g. fetch, axios), you need to install a library to mock the response.
|
||||
|
||||
- If you use `fetch` to fetch data, you need to install `jest*fetch-mock`.
|
||||
- If you use `axios` to fetch data, you need to install `axio*-mock-adapter`.
|
||||
|
||||
For this example, since it uses `fetch`, you need to install `jest-fetch-mock`:
|
||||
|
||||
```shell
|
||||
#npm
|
||||
npm install jest-fetch-mock --save-dev
|
||||
|
||||
#yarn
|
||||
yard add jest-fetch-mock --dev
|
||||
```
|
||||
|
||||
You also need to mock `fetch` library in `libs/queries/use-cat-fact/test-setup.ts`:
|
||||
|
||||
```ts
|
||||
import fetchMock from 'jest-fetch-mock';
|
||||
|
||||
fetchMock.enableMocks();
|
||||
```
|
||||
|
||||
2. **Create Mock Query Provider**
|
||||
|
||||
In order to test out `useQuery` hook, you need to wrap it inside a mock `QueryClientProvider`. Since this mock query provider is going to be used more than once, let’s create a library for this wrapper:
|
||||
|
||||
```shell
|
||||
# expo library
|
||||
npx nx generate @nx/expo:library test-wrapper --directory=queries
|
||||
|
||||
# react native library
|
||||
npx nx generate @nx/react-native:library test-wrapper --directory=queries
|
||||
```
|
||||
|
||||
Then a component inside this library:
|
||||
|
||||
```shell
|
||||
# expo library
|
||||
npx nx generate @nx/expo:component test-wrapper --project=queries-test-wrapper
|
||||
|
||||
# react native library
|
||||
npx nx generate @nx/react-native:component test-wrapper --project=queries-test-wrapper
|
||||
```
|
||||
|
||||
Add the mock `QueryClientProvider` in `libs/queries/test-wrapper/src/lib/test-wrapper/test-wrapper.tsx`:
|
||||
|
||||
```tsx
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import React from 'react';
|
||||
|
||||
export interface TestWrapperProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function TestWrapper({ children }: TestWrapperProps) {
|
||||
const queryClient = new QueryClient();
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default TestWrapper;
|
||||
```
|
||||
|
||||
3. **Use Mock Responses in Unit Test**
|
||||
|
||||
Then this is what the unit test for my query would look like:
|
||||
|
||||
```tsx
|
||||
import { TestWrapper } from '@nx-expo-monorepo/queries/test-wrapper';
|
||||
import { renderHook, waitFor } from '@testing-library/react-native';
|
||||
import { useCatFact } from './use-cat-fact';
|
||||
import fetchMock from 'jest-fetch-mock';
|
||||
|
||||
describe('useCatFact', () => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it('status should be success', async () => {
|
||||
// simulating a server response
|
||||
fetchMock.mockResponseOnce(
|
||||
JSON.stringify({
|
||||
fact: 'random cat fact',
|
||||
})
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCatFact(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
result.current.refetch(); // refetching the query
|
||||
expect(result.current.isLoading).toBeTruthy();
|
||||
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
expect(result.current.data).toEqual('random cat fact');
|
||||
});
|
||||
|
||||
it('status should be error', async () => {
|
||||
fetchMock.mockRejectOnce();
|
||||
|
||||
const { result } = renderHook(() => useCatFact(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
result.current.refetch(); // refetching the query
|
||||
expect(result.current.isLoading).toBeTruthy();
|
||||
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
||||
expect(result.current.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
If you use `axios`, your unit test would look like this:
|
||||
|
||||
```tsx
|
||||
// If you use axios, your unit test would look like this:
|
||||
import { TestWrapper } from '@nx-expo-monorepo/queries/test-wrapper';
|
||||
import { renderHook, waitFor } from '@testing-library/react-native';
|
||||
import { useCatFact } from './use-cat-fact';
|
||||
import axios from 'axios';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
|
||||
// This sets the mock adapter on the default instance
|
||||
const mockAxios = new MockAdapter(axios);
|
||||
|
||||
describe('useCatFact', () => {
|
||||
afterEach(() => {
|
||||
mockAxios.reset();
|
||||
});
|
||||
|
||||
it('status should be success', async () => {
|
||||
// simulating a server response
|
||||
mockAxios.onGet().replyOnce(200, {
|
||||
fact: 'random cat fact',
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useCatFact(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
result.current.refetch(); // refetching the query
|
||||
expect(result.current.isLoading).toBeTruthy();
|
||||
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
expect(result.current.data).toEqual('random cat fact');
|
||||
});
|
||||
|
||||
it('status should be error', async () => {
|
||||
mockAxios.onGet().replyOnce(500);
|
||||
|
||||
const { result } = renderHook(() => useCatFact(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
result.current.refetch(); // refetching the query
|
||||
expect(result.current.isLoading).toBeTruthy();
|
||||
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
||||
expect(result.current.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Notice that this file imports `TestWrapper` from `@nx-expo-monorepo/queries/test-wrapper`, and it is added to `renderHook` function with `{ wrapper: TestWrapper }`.
|
||||
|
||||
Now you run the test command `nx test queries-use-cat-fact`, it should pass:
|
||||
|
||||
```shell
|
||||
PASS queries-use-cat-fact libs/queries/use-cat-fact/src/lib/use-cat-fact.spec.ts (5.158 s)
|
||||
useCatFact
|
||||
✓ status should be success (44 ms)
|
||||
✓ status should be error (96 ms)
|
||||
```
|
||||
|
||||
### Integrate with Component
|
||||
|
||||
Currently `userQuery` returns the following properties:
|
||||
|
||||
- `isLoading` or `status === 'loading'` - The query has no data yet
|
||||
- `isError` or `status === 'error'` - The query encountered an error
|
||||
- `isSuccess` or `status === 'success'` - The query was successful and data is available
|
||||
|
||||
Now with components controlled by the server state, you can leverage the above properties and change your component to follow the below pattern:
|
||||
|
||||
```ts
|
||||
export interface CarouselProps {
|
||||
isError: boolean;
|
||||
isLoading: boolean;
|
||||
isSuccess: boolean;
|
||||
}
|
||||
|
||||
|
||||
export function Carousel({
|
||||
isSuccess,
|
||||
isError,
|
||||
isLoading,
|
||||
}: CarouselProps) {
|
||||
return (
|
||||
<>
|
||||
{isSuccess && (
|
||||
...
|
||||
)}
|
||||
{isLoading && (
|
||||
...
|
||||
)}
|
||||
{isError && (
|
||||
...
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Carousel;
|
||||
```
|
||||
|
||||
Then in the parent component, you can use the query created above:
|
||||
|
||||
```tsx
|
||||
import { useCatFact } from '@nx-expo-monorepo/queries/use-cat-fact';
|
||||
import { Carousel } from '@nx-expo-monorepo/ui';
|
||||
import React from 'react';
|
||||
|
||||
export function Facts() {
|
||||
const { data, isLoading, isSuccess, isError, refetch, isFetching } =
|
||||
useCatFact();
|
||||
|
||||
return (
|
||||
<Carousel
|
||||
content={data}
|
||||
isLoading={isLoading || isFetching}
|
||||
isSuccess={isSuccess}
|
||||
isError={isError}
|
||||
onReload={refetch}
|
||||
>
|
||||
...
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
If you serve the app on the web and open the [React Query Devtools](https://tanstack.com/query/v4/docs/framework/react/devtools), you should be able to see the query I created `cat-fact` and data in the query.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Redux
|
||||
|
||||
### Create a Library
|
||||
|
||||
First, you need to create a library for redux:
|
||||
|
||||
```shell
|
||||
# expo library
|
||||
npx nx generate @nx/expo:lib cat --directory=states
|
||||
|
||||
# react native library
|
||||
npx nx generate @nx/react-native:lib cat --directory=states
|
||||
```
|
||||
|
||||
This should create a folder under libs:
|
||||
|
||||

|
||||
|
||||
### Create a State
|
||||
|
||||
For this app, it is going to track when users click the like button, so you need to create a state called `likes`.
|
||||
|
||||

|
||||
|
||||
You can use the [Nx Console](/recipes/nx-console) to create a redux slice:
|
||||
|
||||

|
||||
|
||||
Or run this command:
|
||||
|
||||
```shell
|
||||
npx nx generate @nx/react:redux likes --project=states-cat --directory=likes
|
||||
```
|
||||
|
||||
Then update the redux slice at `libs/states/cat/src/lib/likes/likes.slice.ts`:
|
||||
|
||||
```ts
|
||||
import {
|
||||
createEntityAdapter,
|
||||
createSelector,
|
||||
createSlice,
|
||||
EntityState,
|
||||
} from '@reduxjs/toolkit';
|
||||
|
||||
export const LIKES_FEATURE_KEY = 'likes';
|
||||
|
||||
export interface LikesEntity {
|
||||
id: string;
|
||||
content: string;
|
||||
dateAdded: number;
|
||||
}
|
||||
|
||||
export type LikesState = EntityState<LikesEntity>;
|
||||
|
||||
export const likesAdapter = createEntityAdapter<LikesEntity>();
|
||||
|
||||
export const initialLikesState: LikesState = likesAdapter.getInitialState();
|
||||
|
||||
export const likesSlice = createSlice({
|
||||
name: LIKES_FEATURE_KEY,
|
||||
initialState: initialLikesState,
|
||||
reducers: {
|
||||
like: likesAdapter.addOne,
|
||||
remove: likesAdapter.removeOne,
|
||||
clear: likesAdapter.removeAll,
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
* Export reducer for store configuration.
|
||||
*/
|
||||
export const likesReducer = likesSlice.reducer;
|
||||
|
||||
export const likesActions = likesSlice.actions;
|
||||
|
||||
const { selectAll } = likesAdapter.getSelectors();
|
||||
|
||||
const getlikesState = <ROOT extends { likes: LikesState }>(
|
||||
rootState: ROOT
|
||||
): LikesState => rootState[LIKES_FEATURE_KEY];
|
||||
|
||||
const selectAllLikes = createSelector(getlikesState, selectAll);
|
||||
|
||||
export const likesSelectors = {
|
||||
selectAllLikes,
|
||||
};
|
||||
```
|
||||
|
||||
Every time the “like” button gets clicked, you want to store the content of what users liked. So you need to create an entity to store this information.
|
||||
|
||||
```ts
|
||||
export interface LikesEntity {
|
||||
id: string;
|
||||
content: string;
|
||||
dateAdded: number;
|
||||
}
|
||||
```
|
||||
|
||||
This state has 3 actions:
|
||||
|
||||
- like: when users click like
|
||||
- remove: when users cancel the like
|
||||
- clear: when users clear all the likes
|
||||
|
||||
### Root Store
|
||||
|
||||
Then you have to add the root store and create a transform function to stringify the redux state:
|
||||
|
||||
```html
|
||||
<script src="https://gist.github.com/xiongemi/5f364d84f89b647dcaaf7e5437ea789c.js"></script>
|
||||
```
|
||||
|
||||
### Connect Redux State with UI
|
||||
|
||||
Then in `apps/cats/src/app/App.tsx`, you have to:
|
||||
|
||||
- wrap the app inside the `StoreProvider` with the root store to connect with the Redux state.
|
||||
- wrap the app inside `PersistGate` to persist the redux state in the storage
|
||||
|
||||
```tsx
|
||||
import React from 'react';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { PersistGate } from 'redux-persist/integration/react';
|
||||
import {
|
||||
createRootStore,
|
||||
transformEntityStateToPersist,
|
||||
} from '@nx-expo-monorepo/states/cat';
|
||||
import { Loading } from '@nx-expo-monorepo/ui';
|
||||
import { Provider as StoreProvider } from 'react-redux';
|
||||
|
||||
const App = () => {
|
||||
const persistConfig = {
|
||||
key: 'root',
|
||||
storage: AsyncStorage,
|
||||
transforms: [transformEntityStateToPersist],
|
||||
};
|
||||
const { store, persistor } = createRootStore(persistConfig);
|
||||
|
||||
return (
|
||||
<PersistGate loading={<Loading />} persistor={persistor}>
|
||||
<StoreProvider store={store}>...</StoreProvider>
|
||||
</PersistGate>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
```
|
||||
|
||||
In your component where the like button is located, you need to dispatch the like action. I created a file at `apps/cats/src/app/facts/facts.props.ts`:
|
||||
|
||||
```ts
|
||||
import {
|
||||
likesActions,
|
||||
LikesEntity,
|
||||
RootState,
|
||||
} from '@nx-expo-monorepo/states/cat';
|
||||
import { AnyAction, ThunkDispatch } from '@reduxjs/toolkit';
|
||||
|
||||
const mapDispatchToProps = (
|
||||
dispatch: ThunkDispatch<RootState, void, AnyAction>
|
||||
) => {
|
||||
return {
|
||||
like(item: LikesEntity) {
|
||||
dispatch(likesActions.like(item));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
type mapDispatchToPropsType = ReturnType<typeof mapDispatchToProps>;
|
||||
|
||||
type FactsProps = mapDispatchToPropsType;
|
||||
|
||||
export { mapDispatchToProps };
|
||||
export type { FactsProps };
|
||||
```
|
||||
|
||||
Now you have passed the `like` function to the props of the facts component. Now inside the facts component, you can call the like function from props to dispatch the like action.
|
||||
|
||||
### Debugging
|
||||
|
||||
To debug redux with Expo, I can simply open the Debugger Menu by entering “d” in the console or in the app, then choose the option “Open JS Debugger”.
|
||||
|
||||

|
||||
|
||||
Then you can view my redux logs in the JS Debugger console:
|
||||
|
||||

|
||||
|
||||
Or you can run `npx nx serve cats` to launch the app in web view. Then you can use Redux Devtools and debug the native app like a web app:
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Here is a simple app that uses TanStack Query and Redux for state management. These 2 tools are pretty powerful and they manage both server and client state for you, which is easy to scale, test, and debug.
|
||||
|
||||
Nx is a powerful monorepo tool. Together with Nx and these 2 state management tools, it will be very easy to scale up any app.
|
||||
|
||||
- TanStack Query site: [https://tanstack.com/query/latest](https://tanstack.com/query/latest)
|
||||
- Official @nx/expo plugin: [/nx-api/expo](/nx-api/expo)
|
||||
- Official @nx/react-native plugin: [/nx-api/react-native](/nx-api/react-native)
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -0,0 +1,314 @@
|
||||
---
|
||||
title: Nx Docs AI Assistant
|
||||
authors: [Katerina Skroumpelou]
|
||||
cover_image: '/blog/images/2023-11-21/featured_img.webp'
|
||||
tags: [nx, docs, AI]
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
The [Nx Docs AI Assistant](/ai-chat) is a tool designed to provide users with answers straight from the Nx documentation. In this article I will explain how it is built, and how we ensure accuracy and relevance.
|
||||
|
||||
In the end of this document I have added a [“glossary”](#glossary) of terms that are used throughout this document.
|
||||
|
||||
## Why have an AI assistant for documentation?
|
||||
|
||||
First of all, let’s answer this simple question: why do you need an AI assistant for a documentation site in the first place? Using an AI assistant for documentation search and retrieval can offer a number of benefits for both users and authors. For users, the challenges of navigating through a large volume and density of documentation are alleviated. Unlike static keyword matching, AI enables more personalized and contextual search, allowing for more complex or sophisticated queries beyond simple keywords. This creates a dynamic feedback loop where users can ask follow-up questions, mix and combine documents, and ultimately enjoy an enhanced user experience that goes beyond basic documentation retrieval.
|
||||
|
||||
For authors, a docs AI assistant provides valuable insights into user behavior. It can identify the questions users are frequently asking, pointing to areas where more documentation may be needed. Additionally, if the AI consistently provides unsatisfactory or incorrect responses to certain queries, it could highlight unclear or lacking portions of the documentation. This not only allows for targeted improvements but also makes more parts of the documentation easily accessible to users through intelligent linking. Overall, it can enrich user interaction and help with future content strategy.
|
||||
|
||||
## The Nx Docs AI Assistant Workflow
|
||||
|
||||
### Overview
|
||||
|
||||
In a nutshell, the Nx Docs AI Assistant works in the following way:
|
||||
|
||||
1. Split our docs into smaller chunks
|
||||
2. Create an [embedding](#embeddings) for each chunk
|
||||
3. Save all these embeddings in [Postgres using pgvector (Supabase!)](https://supabase.com/docs/guides/database/extensions/pgvector)
|
||||
4. Get question from the user
|
||||
5. Create embedding for user’s question
|
||||
6. Perform a vector similarity search on your database — bring back all the chunks of your documentation that are similar to the user’s question
|
||||
7. Use the [GPT chat completion](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) function. Pass a prompt, the user’s question and the retrieved chunks from the docs. GPT will then try to extract the relevant facts from these chunks, in order to formulate a coherent answer.
|
||||
|
||||
This is based on the Web Q&A Tutorial from OpenAI [(https://platform.openai.com/docs/tutorials/web-qa-embeddings)](https://platform.openai.com/docs/tutorials/web-qa-embeddings) and Supabase’s Vector Search example [(https://supabase.com/docs/guides/ai/examples/nextjs-vector-search)](https://supabase.com/docs/guides/ai/examples/nextjs-vector-search).
|
||||
|
||||
It’s important to note here that we are not “training the model on our docs”. The model is pretrained. We are just giving the model parts of our docs which are relevant to the user’s question, and the model creates a coherent answer to the question. It’s basically like pasting in ChatGPT a docs page and asking it “how do I do that?”. Except in this case, we’re first searching our documentation and giving GPT only the relevant parts (more about how we do that later in this article), which it can “read” and extract information from.
|
||||
|
||||
## Step 1: Preprocessing our docs
|
||||
|
||||
Every few days, we run an [automated script that will generate embeddings](https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/.github/workflows/generate-embeddings.yml) (numeric/vector representations of words and phrases) for our documentation, and store these embeddings in Supabase. As mentioned above, this step has 3 parts:
|
||||
|
||||
### Split our docs into smaller chunks
|
||||
|
||||
Most of this code follows the example from [Supabase’s Clippy](https://github.com/supabase-community/nextjs-openai-doc-search). It breaks the markdown tree into chunks, it keeps the heading and it also creates a checksum, to keep track of changes.
|
||||
|
||||
Ref in the code: [https://github.com/nrwl/nx/blob/0197444df5ea906f38f06913b2bc366e04b0acc2/tools/documentation/create-embeddings/src/main.mts#L66](https://github.com/nrwl/nx/blob/0197444df5ea906f38f06913b2bc366e04b0acc2/tools/documentation/create-embeddings/src/main.mts#L66)
|
||||
|
||||
This part is copied from: [https://github.com/supabase-community/nextjs-openai-doc-search/blob/main/lib/generate-embeddings.ts](https://github.com/supabase-community/nextjs-openai-doc-search/blob/main/lib/generate-embeddings.ts)
|
||||
|
||||
```js
|
||||
export function processMdxForSearch(content: string) {
|
||||
// …
|
||||
const mdTree = fromMarkdown(content, {});
|
||||
const sectionTrees = splitTreeBy(mdTree, (node) => node.type === 'heading');
|
||||
// …
|
||||
const sections = sectionTrees.map((tree: any) => {
|
||||
const [firstNode] = tree.children;
|
||||
const heading =
|
||||
firstNode.type === 'heading' ? toString(firstNode) : undefined;
|
||||
return {
|
||||
content: toMarkdown(tree),
|
||||
heading,
|
||||
slug,
|
||||
};
|
||||
});
|
||||
return {
|
||||
checksum,
|
||||
sections,
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Create an embedding for each chunk
|
||||
|
||||
Using `openai.embeddings.create` function with the model “text-embedding-ada-002” we are creating an embedding for each chunk.
|
||||
|
||||
Ref in the code: [https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/tools/documentation/create-embeddings/src/main.mts#L314](https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/tools/documentation/create-embeddings/src/main.mts#L314)
|
||||
|
||||
```js
|
||||
const embeddingResponse = await openai.embeddings.create({
|
||||
model: 'text-embedding-ada-002',
|
||||
input,
|
||||
});
|
||||
```
|
||||
|
||||
### Save all these embeddings in Postgres using pgvector, on Supabase.
|
||||
|
||||
Store this embedding in Supabase, in a database that has already been created, following the steps mentioned here:
|
||||
|
||||
[https://supabase.com/docs/guides/ai/examples/nextjs-vector-search?database-method=dashboard#prepare-the-database](https://supabase.com/docs/guides/ai/examples/nextjs-vector-search?database-method=dashboard#prepare-the-database)
|
||||
|
||||
Essentially, we are setting up two PostgreSQL tables on Supabase. Then, we are inserting the embeddings into these tables.
|
||||
|
||||
Ref in code: [https://github.com/nrwl/nx/blob/master/tools/documentation/create-embeddings/src/main.mts#L327](https://github.com/nrwl/nx/blob/master/tools/documentation/create-embeddings/src/main.mts#L327)
|
||||
|
||||
```js
|
||||
const { data: pageSection } = await supabaseClient
|
||||
.from('nods_page_section')
|
||||
.insert({
|
||||
page_id: page.id,
|
||||
slug,
|
||||
heading,
|
||||
longer_heading,
|
||||
content,
|
||||
url_partial,
|
||||
token_count,
|
||||
embedding,
|
||||
}); // …
|
||||
```
|
||||
|
||||
## Step 2: User query analysis and search
|
||||
|
||||
When a user poses a question to the assistant, we calculate the embedding for the user’s question. The way we do that is, again, using openai.embeddings.create function with the model text-embedding-ada-002.
|
||||
|
||||
Ref in code: [https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/nx-dev/nx-dev/pages/api/query-ai-handler.ts#L58](https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/nx-dev/nx-dev/pages/api/query-ai-handler.ts#L58)
|
||||
|
||||
```js
|
||||
const embeddingResponse: OpenAI.Embeddings.CreateEmbeddingResponse =
|
||||
await openai.embeddings.create({
|
||||
model: 'text-embedding-ada-002',
|
||||
input: sanitizedQuery + getLastAssistantMessageContent(messages),
|
||||
});
|
||||
```
|
||||
|
||||
The assistant compares the query embedding with these documentation embeddings to identify relevant sections. This comparison is essentially measuring how close the query’s vector is to the documentation vectors. The closer they are, the more related the content. The way this works is that it sends the user’s question embedding to Supabase, to a PostgreSQL function, which runs a vector comparison between the user’s question embedding and the stored embeddings in the table. The PostgreSQL function returns all the similar documentation chunks.
|
||||
|
||||
The function that is used uses the dot product between vectors to calculate similarity. For normalized vectors, the dot product is equivalent to cosine similarity. Specifically, when two vectors A and B are normalized (i.e., their magnitudes are each 1), the cosine similarity between them is the same as their dot product. The OpenAI embeddings are normalized to length 1, so cosine similarity and dot product will produce the same results.
|
||||
|
||||
Ref in code: [https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/nx-dev/nx-dev/pages/api/query-ai-handler.ts#L70](https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/nx-dev/nx-dev/pages/api/query-ai-handler.ts#L70)
|
||||
|
||||
```js
|
||||
const { data: pageSections } = await supabaseClient.rpc('match_page_sections', {
|
||||
embedding,
|
||||
// …
|
||||
});
|
||||
```
|
||||
|
||||
## Step 3: Generating a Response
|
||||
|
||||
With the relevant sections (documentation chunks) identified and retrieved, GPT (the generative AI) steps in. Using the relevant sections as context and following a systematic approach, GPT crafts a response.
|
||||
|
||||
This approach the AI is instructed to use (in the **prompt**) is the following:
|
||||
|
||||
- Identify CLUES from the query and documentation.
|
||||
- Deduce REASONING based solely on the provided Nx Documentation.
|
||||
- EVALUATE its reasoning, ensuring alignment with Nx Documentation.
|
||||
- Rely on previous messages for contextual continuity.
|
||||
|
||||
### Ensuring Quality
|
||||
|
||||
If there’s no matching section in the documentation for a query, the script throws a “no_results” error. So, after the initial search in the docs (PostgreSQL function), if the search returns no results (no vectors found that are similar enough to the user’s question vector), the process stops, and our Assistant replies that it does not know the answer.
|
||||
|
||||
### The use of useChat function
|
||||
|
||||
It’s necessary here to clarify that we use the useChat [(https://sdk.vercel.ai/docs/api-reference/use-chat)](https://sdk.vercel.ai/docs/api-reference/use-chat) function of the [Vercel AI SDK](https://sdk.vercel.ai/docs/introduction). This function, as mentioned in the docs, does the following:
|
||||
|
||||
> It enables the streaming of chat messages from your AI provider, manages the state for chat input, and updates the UI automatically as new messages are received.
|
||||
|
||||
It essentially takes care of the following things:
|
||||
|
||||
1. You don’t have to worry about manually creating a “messages” array to store your “conversation” (messages you exchange) with the GPT endpoint
|
||||
2. You don’t have to manually implement the streaming functionality in your UI
|
||||
|
||||
Then, in your React component, you can call this function directly, and get the messages object from it, to render your messages in your UI. It exposes input, handleInputChange and handleSubmit which you can use in your React form, and it will take care of all the rest. You can pass an api string to it, to tell it which endpoint to use as the chat provider.
|
||||
|
||||
### Creating the query
|
||||
|
||||
If you look at our [query-ai-handler.ts](https://github.com/nrwl/nx/blob/76306f0bedc1297b64da6e58b4f7b9c39711cd82/nx-dev/nx-dev/pages/api/query-ai-handler.ts) function, this is an edge function, living under an endpoint, which is called by the useChat function. The request contains the messages array as created by useChat. If we just wanted to create an AI chat with no context, we could directly pass this messages array to the openai.chat.completions.create endpoint, and have our back-and-forth chat with GPT. However, in our case, we need to add context to our conversation, and specifically to each query we end up sending to OpenAI.
|
||||
|
||||
So, the first thing we need to do is to **get the last message the user posted**, which is essentially the user’s question. We search the messages array, and we get the last message which has the role “user”. That is our user’s question.
|
||||
|
||||
Now, we can use the user’s question to get the relevant documentation chunks from the database. To do that, as explained before, we need to **create an embedding for the user’s question** (a vector) and then compare that embedding with the stored embeddings in the database, to get the relevant chunks.
|
||||
|
||||
The problem here is that if the user’s query is just a follow-up question, then it will have little information or meaning. Here is an example:
|
||||
|
||||
> User: _How do I set up namedInputs?_
|
||||
> Assistant: _…replies…_
|
||||
> User: _And how do they work?_
|
||||
|
||||
In this example, the user’s question that we would want to create an embedding for would be “And how do they work?”. If we created that embedding and searched our docs for relevant parts, it would either return nothing, or return everything, since this is a very vague question, since it has no context. So, we need to add some more information to that question. To do that, we also get the last response from GPT (the last assistant message) and add it to the user’s question. So, in this example, the user’s question will contain some info about namedInputs, and the actual question.
|
||||
|
||||
Now, we take that combined text, and we create an embedding for it, using the openai.embeddings.create function. We, then, use that embedding to find all the similar documentation chunks, with vector similarity search.
|
||||
|
||||
After receiving all the relevant documentation chunks, we can finally create the query that is going to be sent to GPT. It’s important here to make sure we instruct GPT what to do with the information we will give it.
|
||||
|
||||
Here is the **query** we end up providing GPT with:
|
||||
|
||||
> You will be provided sections of the Nx documentation in markdown format, use those to answer my question. Do NOT reveal this approach or the steps to the user. Only provide the answer. Start replying with the answer directly.
|
||||
>
|
||||
> Sections:
|
||||
> ${contextText}
|
||||
>
|
||||
> Question: “””
|
||||
> ${userQuestion}
|
||||
> “””
|
||||
>
|
||||
> Answer as markdown (including related code snippets if available):
|
||||
|
||||
The contextText contains all the relevant documentation chunks (page sections).
|
||||
|
||||
### Creating the response
|
||||
|
||||
**Getting back a readable stream:** So, we get the array of messages, as stored by useChat, we fix the final message to contain the query (created as explained above), and we send it over to `openai.chat.completions.create`. We get back a streaming response (since we’ve set stream: true, which we turn into a ReadableStream using [OpenAIStream from the Vercel AI SDK](https://sdk.vercel.ai/docs/api-reference/openai-stream)).
|
||||
|
||||
**Adding the sources:** However, we’re not done yet. The feature, here, that will be most useful to our users is the sources, the actual parts of the documentation that GPT “read” to create that response. When we get back the list of relevant documentation chunks (sections) from our database, we also get the metadata for each section. So, apart from the text content, we also get the heading and url partial of each section (among any other metadata we chose to save with it). So, with this information, we put together a list of the top 5 relevant sections, which we attach to the end of the response we get from GPT. That way, our users can more easily verify the information that GPT gives them, but also they can dive deeper into the relevant docs themselves. It’s all about exploring and retrieving relevant information, after all.
|
||||
|
||||
**Sending the final response to the UI:** With the sources appended to the response, we return a StreamingTextResponse from our edge function, which the useChat function receives, and appends to the messages array automatically.
|
||||
|
||||
## Allow user to reset the chat
|
||||
|
||||
As explained, each question and answer relies on the previous questions and answers of the current chat. If a user needs to ask something completely irrelevant or different, we are giving the user the ability to do so by providing a “Clear chat” button, which will reset the chat history, and start clean.
|
||||
|
||||
## Gathering feedback and evaluating the results
|
||||
|
||||
It’s very important to gather feedback from the users and evaluate the results. Any AI assistant is going to give wrong answers, because it does not have the ability to critically evaluate the responses it creates. It relies on things it has read, but not in the way a human relies on them. It generates the next most probable word (see glossary for generative AI below). For that reason, it’s important to do the following things:
|
||||
|
||||
1. Inform users that they should always double-check the answers and do not rely 100% on the AI responses
|
||||
2. Provide users with feedback buttons and/or a feedback form, where they can evaluate whether a response was good or bad. At Nx we do that, and we also associate each button click with the question the user asked, which will give us an idea around which questions the AI gets right or wrong.
|
||||
3. Have a list of questions that you ask the AI assistant, and evaluate its responses internally. Use these questions as a standard for any changes made in the assistant.
|
||||
|
||||
## Wrapping up
|
||||
|
||||
In this guide, we’ve explored the intricacies of the Nx Docs AI Assistant, an innovative tool that enhances the experience of both users and authors of Nx documentation. From understanding the need for an AI assistant in navigating complex documentation to the detailed workflow of the Nx Docs AI Assistant, we have covered the journey from preprocessing documentation to generating coherent and context-aware responses.
|
||||
|
||||
Let’s see at some key takeaways:
|
||||
|
||||
**Enhanced User Experience:** The AI assistant significantly improves user interaction with documentation by offering personalized, context-aware responses to queries. This not only makes information retrieval more efficient but also elevates the overall user experience.
|
||||
|
||||
**Insights for Authors:** By analyzing frequently asked questions and areas where the AI struggles, authors can pinpoint documentation gaps and areas for improvement, ensuring that the Nx documentation is as clear and comprehensive as possible.
|
||||
|
||||
**OpenAI API utilization:** The use of embeddings, vector similarity search, and GPT’s generative AI capabilities demonstrate a sophisticated approach to AI-driven documentation assistance. This blend of technologies ensures that users receive accurate and relevant responses.
|
||||
|
||||
**Continuous Learning and Improvement:** The system’s design includes mechanisms for gathering user feedback and evaluating AI responses, which are crucial for ongoing refinement and enhancement of the assistant’s capabilities.
|
||||
|
||||
**Transparency and User Trust:** By openly communicating the limitations of the AI and encouraging users to verify the information, the system fosters trust and promotes responsible use of AI technology.
|
||||
|
||||
**Accessibility and Efficiency:** The AI assistant makes Nx documentation more accessible and navigable, especially for complex or nuanced queries, thereby saving time and enhancing productivity and developer experience.
|
||||
|
||||
## Future steps
|
||||
|
||||
OpenAI released the Assistants API, which takes the burden of chunking the docs, creating embeddings, storing the docs in a vector database, and querying that database off the shoulders of the developers. This new API offers all these features out of the box, removing the need to create a customized solution, as the one explained above. It’s still in beta, and it remains to be seen how it’s going to evolve, and if it’s going to overcome some burdens it poses at the moment. You can [read more about the new Assistants API in this blog post](https://pakotinia.medium.com/openais-assistants-api-a-hands-on-demo-110a861cf2d0), which contains a detailed demo on how to use it for documentation q&a.
|
||||
|
||||
## Glossary
|
||||
|
||||
### Core concepts
|
||||
|
||||
I find it useful to start by explaining what some terms — which are going to be used quite a lot throughout this blog post — mean.
|
||||
|
||||
### Embeddings
|
||||
|
||||
#### What they are
|
||||
|
||||
In the context of machine learning, embeddings are a type of representation for text data. Instead of treating words as mere strings of characters, embeddings transform them into **vectors** (lists of numbers) in a way that captures their meanings. In embeddings, vectors are like digital fingerprints for words or phrases, converting their essence into a series of numbers that can be easily analyzed and compared.
|
||||
|
||||
#### Why they matter
|
||||
|
||||
With embeddings, words or phrases with similar meanings end up having **vectors** that are close to each other, making it easier to compare and identify related content.
|
||||
|
||||
### Generative AI
|
||||
|
||||
#### What it is
|
||||
|
||||
Generative AI, the technology driving the Nx Docs AI Assistant, is a subset of AI that’s trained, not just to classify input data, but to generate new content.
|
||||
|
||||
#### How it works
|
||||
|
||||
Generative AI operates like a sophisticated software compiler. Just as a compiler takes in high-level code and translates it into machine instructions, generative AI takes in textual prompts and processes them through layers of neural network operations, resulting in detailed and coherent text outputs. It’s like providing a programmer with a high-level task description, and they write the necessary code to achieve it, except here the ‘programmer’ is the AI, and the ‘code’ is the generated text response.
|
||||
|
||||
#### What Does “Generation” Mean in AI Context?
|
||||
|
||||
In AI, especially with natural language processing models, “generation” refers to the process of producing sequences of data, in our case, text. It’s about creating content that wasn’t explicitly in the training data but follows the same patterns and structures.
|
||||
|
||||
#### How Does GPT Predict the Next Word?
|
||||
|
||||
For our Nx Docs AI assistant we use GPT. GPT, which stands for “Generative Pre-trained Transformer”, works using a predictive mechanism. At its core, it’s trained to predict the next word in a sentence. When you provide GPT with a prompt, it uses that as a starting point and keeps predicting the next word until it completes the response or reaches a set limit.
|
||||
|
||||
It’s like reading a sentence and trying to guess the next word based on what you’ve read so far. GPT does this but by using a massive amount of textual data it has seen during training, enabling it to make highly informed predictions.
|
||||
|
||||
### Context and Prompting — their role in AI models
|
||||
|
||||
#### Context
|
||||
|
||||
In the context of AI, “context” refers to the surrounding information, data, or conditions that provide a framework or background for understanding and interpreting a specific input, ensuring that the AI’s responses or actions are relevant, coherent, and meaningful in a given situation
|
||||
|
||||
#### Prompts
|
||||
|
||||
The prompt acts as an initial “seed” that guides the AI’s output. While the AI is trained on vast amounts of text, it relies on the prompt for context. For example, a prompt like “tell me about cats” might result in a broad answer, but “summarize the history of domesticated cats” narrows the model’s focus.
|
||||
|
||||
By refining prompts, users can better direct the AI’s response, ensuring the output matches their intent. In essence, the prompt is a tool to direct the AI’s vast capabilities to a desired outcome.
|
||||
|
||||
### The GPT Chat Completion Roles
|
||||
|
||||
### System
|
||||
|
||||
The “System” role typically sets the “persona” or the “character” of the AI. It gives high-level instructions on how the model should behave during the conversation. We start the instructions with “You are a knowledgeable Nx representative.” We also instruct the model about the format of its answer: “Your answer should be in the form of a Markdown article”. You can read the full instructions on GitHub.
|
||||
|
||||
#### User
|
||||
|
||||
The “User” role is straightforward. This is the input from the end-user, which the AI responds to. The user’s query becomes the User role message. This role guides what the AI should be talking about in its response. It’s a direct prompt to the AI to generate a specific answer. In our case, we take the user’s query, and we add it in a longer prompt, which specific steps the model must follow (as explained above). That way, the model focuses on the specific steps we’ve laid out, making it the immediate context for generating the answer. This is one more step towards more accurate answers based on our documentation only. Inside the prompt, which has the instructions, and the user’s query, we always add the context text as well, which are the relevant parts that are retrieved from the Nx Documentation.
|
||||
|
||||
#### Assistant
|
||||
|
||||
This role, in the context of OpenAI’s chat models, is the response of the AI. Previous Assistant responses can be included in the chat history to provide context, especially if a conversation has back-and-forth elements. This helps the model generate coherent and contextually relevant responses in a multi-turn conversation.
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -0,0 +1,335 @@
|
||||
---
|
||||
title: Unit Testing Expo Apps With Jest
|
||||
authors: [Emily Xiong]
|
||||
cover_image: '/blog/images/2023-11-22/featured_img.webp'
|
||||
tags: [nx, unit testing]
|
||||
---
|
||||
|
||||
In my latest [blog](https://dev.to/nx/step-by-step-guide-to-creating-an-expo-monorepo-with-nx-3b17), I successfully navigated through the steps of setting up an Expo Monorepo with [Nx](). The next challenge? Testing! This blog dives into:
|
||||
|
||||
- Crafting effective unit tests for Expo components utilizing Jest
|
||||
- Addressing common issues encountered during unit testing
|
||||
|
||||
Repo:
|
||||
{% github-repository url="https://github.com/xiongemi/nx-expo-monorepo" /%}
|
||||
|
||||
## Stacks
|
||||
|
||||
Here’s my setup
|
||||
|
||||
- Testing framework: [jest](https://jestjs.io/)
|
||||
- Testing library: [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/)
|
||||
- Jest Preset: [jest-expo](https://www.npmjs.com/package/jest-expo)
|
||||
|
||||
## Writing and Running Unit Tests
|
||||
|
||||
When you use Nx, it not only configures and sets up Jest, but also creates a default unit test for every expo component that is being generated. Here’s what that looks like:
|
||||
|
||||
```typescript
|
||||
import { render } from '@testing-library/react-native';
|
||||
import React from 'react';
|
||||
|
||||
import Loading from './loading';
|
||||
|
||||
describe('Loading', () => {
|
||||
it('should render successfully', () => {
|
||||
const { root } = render(<Loading />);
|
||||
expect(root).toBeTruthy();
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
To run all unit tests for a given project, use:
|
||||
|
||||
```shell
|
||||
npx nx test <project-name>
|
||||
```
|
||||
|
||||
Here’s the output of running this for my example app:
|
||||
|
||||

|
||||
|
||||
When it comes to writing tests, the [React Native Testing Library](https://callstack.github.io/react-native-testing-library/docs/api-queries) is a game-changer for writing cleaner unit tests in React Native applications. Its intuitive query API simplifies the process of selecting elements within your components, making it straightforward to write more maintainable and readable tests. You mark elements with a `testID`
|
||||
|
||||
```html
|
||||
<Headline testID="title">{film.title}</Headline>
|
||||
```
|
||||
|
||||
Then in the test file, you can use the function `getByTestId` to query `testID`:
|
||||
|
||||
```typescript
|
||||
const { getByTestId } = render(<your component>);
|
||||
expect(getByTestId('title')).toHaveTextContent(...);
|
||||
```
|
||||
|
||||
You can find more options for querying elements on the official React Native Testing Library docs: [https://callstack.github.io/react-native-testing-library/docs/api-queries](https://callstack.github.io/react-native-testing-library/docs/api-queries).
|
||||
|
||||
## Troubleshooting Common Issues When Writing Tests
|
||||
|
||||
However, unit tests do not always pass. Here are some common errors I ran into and how to resolve them.
|
||||
|
||||
### **Error: AsyncStorage is null.**
|
||||
|
||||
I am using the library `@react-native-async-storage/async-storage`, and I got the below error when running unit testing:
|
||||
|
||||
```shell
|
||||
\[@RNC/AsyncStorage\]: NativeModule: AsyncStorage is null.
|
||||
|
||||
To fix this issue try these steps:
|
||||
|
||||
• Rebuild and restart the app.
|
||||
|
||||
• Run the packager with \`--reset-cache\` flag.
|
||||
|
||||
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app.
|
||||
|
||||
• If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
|
||||
|
||||
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/async-storage/issues
|
||||
|
||||
5 | import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
6 | import { Platform } from 'react-native';
|
||||
> 7 | import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
```
|
||||
|
||||
The issue is that `@react-native-async-storage/async-storage` library can only be used in `NativeModule`. Since unit testing with Jest only tests JS/TS file logic, I need to mock this library.
|
||||
|
||||
In the app’s test-setup.ts file, add the below lines:
|
||||
|
||||
```typescript
|
||||
jest.mock('@react-native-async-storage/async-storage', () =>
|
||||
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
|
||||
);
|
||||
```
|
||||
|
||||
## Error: Could not find “store”
|
||||
|
||||
I am using Redux for state management, and I got this error for my stateful components:
|
||||
|
||||
```
|
||||
Could not find "store" in the context of "Connect(Bookmarks)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(Bookmarks) in connect options.
|
||||
```
|
||||
|
||||
To fix this, the simple way is to mock a redux store. I need to install [redux-mock-store](https://github.com/reduxjs/redux-mock-store) and its typing:
|
||||
|
||||
{% tabs %}
|
||||
{% tab label="npm" %}
|
||||
|
||||
```shell
|
||||
npm install redux-mock-store @types/redux-mock-store --save-dev
|
||||
```
|
||||
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="yarn" %}
|
||||
|
||||
```shell
|
||||
yarn add redux-mock-store @types/redux-mock-store --dev
|
||||
```
|
||||
|
||||
{% /tab %}
|
||||
{% /tabs %}
|
||||
|
||||
Then I can create a mock store using this library like the below code:
|
||||
|
||||
```typescript
|
||||
import configureStore, { MockStoreEnhanced } from 'redux-mock-store';
|
||||
|
||||
const mockStore = configureStore<any>(\[\]);
|
||||
|
||||
let store: MockStoreEnhanced<any>;
|
||||
|
||||
beforeEach(() => {
|
||||
store = mockStore({});
|
||||
store.dispatch = jest.fn();
|
||||
});
|
||||
```
|
||||
|
||||
For example, one of my stateful components’ unit test will become:
|
||||
|
||||
```typescript
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react-native';
|
||||
import { Provider } from 'react-redux';
|
||||
import configureStore, { MockStoreEnhanced } from 'redux-mock-store';
|
||||
import { RootState, initialRootState } from '@nx-expo-monorepo/states/cat';
|
||||
|
||||
import Bookmarks from './bookmarks';
|
||||
|
||||
describe('Bookmarks', () => {
|
||||
const mockStore = configureStore<RootState>(\[\]);
|
||||
|
||||
let store: MockStoreEnhanced<RootState>;
|
||||
|
||||
beforeEach(() => {
|
||||
store = mockStore(initialRootState);
|
||||
store.dispatch = jest.fn();
|
||||
});
|
||||
|
||||
it('should render successfully', () => {
|
||||
const { container } = render(
|
||||
<Provider store={store}>
|
||||
<Bookmarks />
|
||||
</Provider>
|
||||
);
|
||||
expect(container).toBeTruthy();
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The above code will apply the initial redux state to my components.
|
||||
|
||||
### Error: No QueryClient set
|
||||
|
||||
Because I use [TanStack Query](https://tanstack.com/query/latest) , when I run unit tests, I have this error:
|
||||
|
||||
```
|
||||
No QueryClient set, use QueryClientProvider to set one
|
||||
```
|
||||
|
||||
This error occurred because I used `useQuery` from `@tanstack/react-query` in my component; however, in this unit test, the context of this hook is not provided.
|
||||
|
||||
To solve this, I can just mock the `useQuery` function:
|
||||
|
||||
```typescript
|
||||
import * as ReactQuery from '@tanstack/react-query';
|
||||
|
||||
jest.spyOn(ReactQuery, 'useQuery').mockImplementation(
|
||||
jest.fn().mockReturnValue({
|
||||
data: 'random cat fact',
|
||||
isLoading: false,
|
||||
isSuccess: true,
|
||||
refetch: jest.fn(),
|
||||
isFetching: false,
|
||||
isError: false,
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
### Error: Couldn’t find a navigation object
|
||||
|
||||
If you use `@react-navigation` library for navigation, and inside your component, there are hooks from this library like `useNavigation` and `useRoute`, you are likely to get this error:
|
||||
|
||||
```
|
||||
Couldn't find a navigation object. Is your component inside NavigationContainer?
|
||||
```
|
||||
|
||||
The fix this, I need to mock the `@react-nativgation/native` library. In the app’s test-setup.ts file, I need to add:
|
||||
|
||||
```typescript
|
||||
jest.mock('@react-navigation/native', () => {
|
||||
return {
|
||||
useNavigation: () => ({
|
||||
navigate: jest.fn(),
|
||||
dispatch: jest.fn(),
|
||||
setOptions: jest.fn(),
|
||||
}),
|
||||
useRoute: () => ({
|
||||
params: {
|
||||
id: '123',
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
### SyntaxError: Unexpected token ‘export’
|
||||
|
||||
I got this error when using a library with ECMAScript Module (ESM), such as `[udid](https://github.com/uuidjs/uuid)`:
|
||||
|
||||
```
|
||||
/Users/emilyxiong/Code/nx-expo-monorepo/node\_modules/uuid/dist/esm-browser/index.js:1
|
||||
({"Object.<anonymous>":function(module,exports,require,\_\_dirname,\_\_filename,jest){export { default as v1 } from './v1.js';
|
||||
^^^^^^
|
||||
|
||||
SyntaxError: Unexpected token 'export'
|
||||
|
||||
5 | import { connect } from 'react-redux';
|
||||
6 | import 'react-native-get-random-values';
|
||||
> 7 | import { v4 as uuidv4 } from 'uuid';
|
||||
```
|
||||
|
||||
Jest does not work with ESM out of the box. The simple solution is to map this library to the CommonJS version of this library.
|
||||
|
||||
In the app’s `jest.config.ts`, there should be an option called `moduleNameMapper`. The library I used is called `uuid`, so I need to add the map `uuid: require.resolve(‘uuid’)` under `moduleNameMapper`. So when the code encounters imports from `uuid` library, it will resolve the CommonJS version of it:
|
||||
|
||||
```typescript
|
||||
module.exports = {
|
||||
moduleNameMapper: {
|
||||
uuid: require.resolve('uuid'),
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Alternatively, I can also mock this library in the test files:
|
||||
|
||||
```typescript
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
jest.mock('uuid', () => {
|
||||
return {
|
||||
v4: jest.fn(() => 1),
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
## Error: Jest encountered an unexpected token
|
||||
|
||||
I got this error when I was importing from a library such as [react-native-vector-icons](https://github.com/oblador/react-native-vector-icons):
|
||||
|
||||
```
|
||||
console.error
|
||||
Jest encountered an unexpected token
|
||||
|
||||
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
|
||||
|
||||
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
|
||||
|
||||
By default "node\_modules" folder is ignored by transformers.
|
||||
|
||||
Here's what you can do:
|
||||
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
|
||||
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
|
||||
• To have some of your "node\_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
|
||||
• If you need a custom transformation specify a "transform" option in your config.
|
||||
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
|
||||
|
||||
You'll find more details and examples of these config options in the docs:
|
||||
https://jestjs.io/docs/configuration
|
||||
For information about custom transformations, see:
|
||||
https://jestjs.io/docs/code-transformation
|
||||
```
|
||||
|
||||
To fix this, add this library name to `transformIgnorePatterns` in the app's jest.config.ts.
|
||||
|
||||
What is `transformIgnorePatterns`? The `transformIgnorePatterns` allows developers to specify which files shall be transformed by Babel. `transformIgnorePatterns` is an array of regexp pattern strings that should be matched against all source file paths before the transformation. If the file path matches any patterns, it will not be transformed by Babel.
|
||||
|
||||
By default, Jest will ignore all the files under node_modules and only transform the files under the project’s src.
|
||||
|
||||
However, some libraries such as `react-native-paper` or `react-native-svg`, the library files are in `.ts` or `.tsx`. These files are not compiled to `js`. So I need to add these libraries' names to `transformIgnorePatterns`, so these libraries will be transformed by Babel along with my project. source file. The default generated `jest.config.js` already has:
|
||||
|
||||
```
|
||||
transformIgnorePatterns: \[
|
||||
'node\_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.\*|@expo-google-fonts/.\*|react-navigation|@react-navigation/.\*|@unimodules/.\*|unimodules|sentry-expo|native-base|react-native-svg)',
|
||||
\]
|
||||
```
|
||||
|
||||
If I have an error related to a library with an unexpected token, I need to check whether they are compiled or not.
|
||||
|
||||
- If this library source files are already transformed to `.js`, then its name should match regex, so it would be ignored, so it will NOT be transformed.
|
||||
- If this library source files are NOT transformed to `.js` (e.g. still in `.ts` or `.tsx`), then its name should NOT match regex, so it will be transformed.
|
||||
|
||||
## Summary
|
||||
|
||||
Here are some common errors that I will probably run into while doing unit testing. The solution to most problems is to find a way to mock a library that is not relevant to my component logic.
|
||||
|
||||
With Nx, you do not need to explicitly install any testing library, so you can dive right in and focus on writing the tests rather than spending time on setup.
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Add Cypress, Playwright, and Storybook to Nx Expo Apps](https://medium.com/@emilyxiong/add-cypress-playwright-and-storybook-to-nx-expo-apps-1d3e409ce834)
|
||||
- 🧠 [Nx Docs](/getting-started/intro)
|
||||
- 👩💻 [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- 💬 [Nx Community Discord](https://go.nx.dev/community)
|
||||
- 📹 [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- 🚀 [Speed up your CI](https://nx.app/)
|
||||
@@ -109,7 +109,7 @@ nx release version patch --project=my-project
|
||||
|
||||

|
||||
|
||||
[Angular](https://angular.dev/) is in the middle of [a HUGE renaissance](https://blog.angular.io/introducing-angular-v17-4d7033312e4b), between their new logo, new docs site, and introduction of some awesome features like Signals.
|
||||
[Angular](https://angular.dev/) is in the middle of [a HUGE renaissance](https://blog.angular.dev/introducing-angular-v17-4d7033312e4b), between their new logo, new docs site, and introduction of some awesome features like Signals.
|
||||
|
||||
Nx is here to support the transition! Nx has always been a great fit for Angular, and now supports Angular 17 as well as NgRx 17.
|
||||
|
||||
@@ -209,6 +209,6 @@ That’s all for now folks! We’re just starting up a new iteration of developm
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
|
||||
@@ -31,7 +31,7 @@ It is that time again: getting flooded by Year of Review blog posts. We did it l
|
||||
|
||||
## Top 10 Nx Highlights of 2023
|
||||
|
||||
We shipped a ton of features in 2023. You can find all our release blog posts and release-related info here: [https://nx.dev/changelog](https://nx.dev/changelog) or check out our [Dev.to collection](https://dev.to/nx).
|
||||
We shipped a ton of features in 2023. You can find all our release blog posts and release-related info here: [https://nx.dev/changelog](/changelog) or check out our [Dev.to collection](https://dev.to/nx).
|
||||
|
||||
We've picked out 10 highlights for you.
|
||||
|
||||
@@ -45,7 +45,7 @@ Following this, we revamped the TypeScript dependency resolution, observing an a
|
||||
|
||||
{% tweet url="https://twitter.com/juristr/status/1726977598218199302" /%}
|
||||
|
||||
Such enhancements are especially crucial for the efficient [project graph calculation](https://nx.dev/features/explore-graph). As we continue to evolve Nx, Rust will play a key role in optimizing performance-critical components. This strategic use of Rust complements our ongoing commitment to TypeScript, ensuring Nx remains as extensible and powerful as ever.
|
||||
Such enhancements are especially crucial for the efficient [project graph calculation](/features/explore-graph). As we continue to evolve Nx, Rust will play a key role in optimizing performance-critical components. This strategic use of Rust complements our ongoing commitment to TypeScript, ensuring Nx remains as extensible and powerful as ever.
|
||||
|
||||
### First Class Vite Support
|
||||
|
||||
@@ -55,7 +55,7 @@ Our collaboration with our friends in the Vite core team has been incredibly fru
|
||||
|
||||

|
||||
|
||||
We also built some powerful code generators that not only facilitate a seamless [transition from Webpack to Vite](https://nx.dev/nx-api/vite/generators/configuration#nxviteconfiguration) but also pave the way for an effortless [migration from a CRA-based setup](https://nx.dev/recipes/adopting-nx/adding-to-existing-project) to a modern Nx + Vite based workspace. To see this process in action, [check out this short video](https://www.youtube.com/watch?v=zvYb7XCLQzU).
|
||||
We also built some powerful code generators that not only facilitate a seamless [transition from Webpack to Vite](/nx-api/vite/generators/configuration#nxviteconfiguration) but also pave the way for an effortless [migration from a CRA-based setup](/recipes/adopting-nx/adding-to-existing-project) to a modern Nx + Vite based workspace. To see this process in action, [check out this short video](https://www.youtube.com/watch?v=zvYb7XCLQzU).
|
||||
|
||||
[AnalogJS](https://analogjs.org/) — the fullstack Angular meta-framework which also heavily builds on top of Vite — is using the `@nx/vite` plugin to power its Angular and Nx based workspaces.
|
||||
|
||||
@@ -65,7 +65,7 @@ We also spoke at both editions of [ViteConf](https://viteconf.org/23/). If you
|
||||
|
||||
Open source libraries and frameworks share a common necessity: the need to develop multiple packages cohesively and efficiently while managing their versioning and publishing to NPM. Nx has emerged as a go-to choice for handling such open source monorepos (as we’ll explore further in the next section of this blog post). Until recently, one area Nx did not address directly was versioning and release management. Traditionally, this gap has been filled with tools like [release-it](https://github.com/release-it/release-it), [changesets](https://github.com/changesets/changesets), or custom Node scripts, similar to our approach in the Nx repository.
|
||||
|
||||
However, many in our community have expressed a desire for a more native, integrated experience for versioning and publishing, akin to what Lerna offers. In response to this feedback, we’ve introduced [the “nx release” command](https://nx.dev/features/manage-releases), a solution designed to seamlessly integrate these processes into the Nx workflow.
|
||||
However, many in our community have expressed a desire for a more native, integrated experience for versioning and publishing, akin to what Lerna offers. In response to this feedback, we’ve introduced [the “nx release” command](/features/manage-releases), a solution designed to seamlessly integrate these processes into the Nx workflow.
|
||||
|
||||
James Henry gave a deep dive talk of an early version of it at this year’s Nx Conf:
|
||||
|
||||
@@ -76,7 +76,7 @@ Since its introduction, the “nx release” feature has significantly evolved,
|
||||
- Versioning packages offering support for both independent and “locked” versioning strategies.
|
||||
- Releasing packages in the correct sequence, ensuring dependency integrity.
|
||||
|
||||
Beyond these core functionalities, the feature also includes a robust grouping mechanism, supports semantic versioning, and changelog generation. Additionally, it provides various release targets, such as GitHub and NPM. For those having special requirements, the [programmatic API](https://nx.dev/features/manage-releases#using-the-programmatic-api-for-nx-release) offers maximum flexibility.
|
||||
Beyond these core functionalities, the feature also includes a robust grouping mechanism, supports semantic versioning, and changelog generation. Additionally, it provides various release targets, such as GitHub and NPM. For those having special requirements, the [programmatic API](/features/manage-releases#using-the-programmatic-api-for-nx-release) offers maximum flexibility.
|
||||
|
||||
### Improved Node Backend Development: Fastify and Docker
|
||||
|
||||
@@ -192,7 +192,7 @@ Here’s a video that walks you through:
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/Vy4d0-SF5cY?si=mHatqRPRqHAK0X9o" /%}
|
||||
|
||||
But we wouldn’t be talking about Nx if we didn’t also look into speeding up TypeScript compilation for large monorepos. We called it “[batch mode](https://nx.dev/showcase/benchmarks/tsc-batch-mode)”. When enabling batch mode, Nx leverages the underlying [project graph](https://nx.dev/features/explore-graph) to generate TypeScript project references behind the scenes for you, to fully leverage TS incremental building. The results are amazing. According to [our benchmarks](https://github.com/nrwl/large-ts-monorepo), batch mode has the potential to speed up Typescript compilation by up to 5x for large monorepos.
|
||||
But we wouldn’t be talking about Nx if we didn’t also look into speeding up TypeScript compilation for large monorepos. We called it “[batch mode](/showcase/benchmarks/tsc-batch-mode)”. When enabling batch mode, Nx leverages the underlying [project graph](/features/explore-graph) to generate TypeScript project references behind the scenes for you, to fully leverage TS incremental building. The results are amazing. According to [our benchmarks](https://github.com/nrwl/large-ts-monorepo), batch mode has the potential to speed up Typescript compilation by up to 5x for large monorepos.
|
||||
|
||||

|
||||
|
||||
@@ -218,17 +218,17 @@ And you’ll then have access to Nx generators so you can create Vue application
|
||||
|
||||

|
||||
|
||||
Checkout out our [Vue standalone tutorial](https://nx.dev/getting-started/tutorials/vue-standalone-tutorial) for more, as well as our [Vue API docs](https://nx.dev/nx-api/vue), and stay tuned as Nx prepares to offer more Vue support (including support for [Nuxt](https://nuxt.com/), a full-stack framework built around Vue) in the near future!
|
||||
Checkout out our [Vue standalone tutorial](/getting-started/tutorials/vue-standalone-tutorial) for more, as well as our [Vue API docs](/nx-api/vue), and stay tuned as Nx prepares to offer more Vue support (including support for [Nuxt](https://nuxt.com/), a full-stack framework built around Vue) in the near future!
|
||||
|
||||
### Extending Nx: Local Generators, Build your Own CLI, Verdaccio Support
|
||||
|
||||
Extensibility is at the heart of Nx, serving as the cornerstone of its flexibility. It enables the Nx core team to continually expand capabilities through dedicated plugins and simultaneously paves the way for a rich array of [community plugin contributions](https://nx.dev/plugin-registry). Furthermore, Nx’s adaptable nature is particularly beneficial for large enterprises, as it allows for the creation of custom automation solutions, specifically tailored to meet their unique organizational needs.
|
||||
Extensibility is at the heart of Nx, serving as the cornerstone of its flexibility. It enables the Nx core team to continually expand capabilities through dedicated plugins and simultaneously paves the way for a rich array of [community plugin contributions](/plugin-registry). Furthermore, Nx’s adaptable nature is particularly beneficial for large enterprises, as it allows for the creation of custom automation solutions, specifically tailored to meet their unique organizational needs.
|
||||
|
||||
In 2023 we kept improving Nx’s extensibility, unifying the Nx plugin development model and how you develop workspace-local automations. You can now scaffold a new plugin into your Nx workspace and run it right away which makes it an interesting approach to automate your monorepo.
|
||||
|
||||
{% youtube src="https://www.youtube.com/embed/myqfGDWC2go?si=q6_9JReS1nF8d3pZ" /%}
|
||||
|
||||
When creating automations with Nx you cannot just enhance existing Nx workspaces, but also develop a complete [Nx preset](https://nx.dev/extending-nx/recipes/create-preset) that controls the entire appearance of an Nx workspace. Basically your own, personalized `create-nx-workspace`. You can publish and then use your preset like:
|
||||
When creating automations with Nx you cannot just enhance existing Nx workspaces, but also develop a complete [Nx preset](/extending-nx/recipes/create-preset) that controls the entire appearance of an Nx workspace. Basically your own, personalized `create-nx-workspace`. You can publish and then use your preset like:
|
||||
|
||||
```shell
|
||||
npx create-nx-workspace myrepo --preset=@yourpkg/nx-preset
|
||||
@@ -250,7 +250,7 @@ Simply put, Module Federation allows a Javascript application running in a brows
|
||||
|
||||
This is an exciting development as it allows a paradigm shift in how you can architect, build, and deploy Javascript applications! And this is especially exciting for monorepo fans, as Nx has best-in-class support for module federation that makes a Module Federation approach easy to adopt and simple to understand!
|
||||
|
||||
Currently, our `@nx/angular` and `@nx/react` plugins both have generators to [create a “host” application](https://nx.dev/recipes/module-federation/create-a-host) that will load and consume federated modules from [“remote” applications](https://nx.dev/recipes/module-federation/create-a-remote), which you can also generate using Nx. Then, by running a simple command with Nx, you can serve all applications required for your host application with the command:
|
||||
Currently, our `@nx/angular` and `@nx/react` plugins both have generators to [create a “host” application](/recipes/module-federation/create-a-host) that will load and consume federated modules from [“remote” applications](/recipes/module-federation/create-a-remote), which you can also generate using Nx. Then, by running a simple command with Nx, you can serve all applications required for your host application with the command:
|
||||
|
||||
```shell
|
||||
nx serve host-application --devRemotes=remote-application
|
||||
@@ -258,9 +258,9 @@ nx serve host-application --devRemotes=remote-application
|
||||
|
||||
Where in the example above your host application is named “host-application” and a remote application that you want live updates on as you’re developing is named “remote-application”.
|
||||
|
||||
Throughout 2023, we’ve continued to increase Nx’s support and general dev experience around Module Federation, including [adding a generator to federate an existing module](https://nx.dev/recipes/module-federation/federate-a-module), improving the local developer experience by improving local webserver performance, and introducing the concept of [Dynamic Module Federation](https://nx.dev/recipes/angular/dynamic-module-federation-with-angular#advanced-angular-micro-frontends-with-dynamic-module-federation) which will allow you to dynamically specify the location of your remote applications via a “module-federation.manifest.json” file!
|
||||
Throughout 2023, we’ve continued to increase Nx’s support and general dev experience around Module Federation, including [adding a generator to federate an existing module](/recipes/module-federation/federate-a-module), improving the local developer experience by improving local webserver performance, and introducing the concept of [Dynamic Module Federation](/recipes/angular/dynamic-module-federation-with-angular#advanced-angular-micro-frontends-with-dynamic-module-federation) which will allow you to dynamically specify the location of your remote applications via a “module-federation.manifest.json” file!
|
||||
|
||||
At Nx, we’re excited about the Module Federation support we offer for our users, and think that it has many interesting applications when paired with Nx’s CI capabilities, in particular allowing for [much shorter build times](https://nx.dev/concepts/module-federation/faster-builds-with-module-federation#faster-builds-with-module-federation) especially for larger Angular applications.
|
||||
At Nx, we’re excited about the Module Federation support we offer for our users, and think that it has many interesting applications when paired with Nx’s CI capabilities, in particular allowing for [much shorter build times](/concepts/module-federation/faster-builds-with-module-federation#faster-builds-with-module-federation) especially for larger Angular applications.
|
||||
|
||||
## Many OSS repos adopt Nx
|
||||
|
||||
@@ -281,11 +281,11 @@ I picked out some of the more well-known OSS repos that started using Nx this ye
|
||||
|
||||
[**RxJS**](https://github.com/ReactiveX/rxjs) — The library for reactive programming in JavaScript. It is widely popular, with over 40 million downloads/week on NPM. RxJS only recently adopted Nx, not only leveraging speed improvements via caching, but also leveraging Nx’s latest `nx release` feature to publish packages to NPM.
|
||||
|
||||
[**AnalogJS**](https://analogjs.org/) — Analog is a full-stack Angular meta-framework that brings exciting features to Angular, like faster Vite setup, support for both server-side and static rendering, and easy file-based routing. Analog uses an Nx monorepo for its development and also uses [Nx’s DevKit](https://nx.dev/extending-nx/intro/getting-started) to create tools that work great in both Nx and Angular CLI workspaces.
|
||||
[**AnalogJS**](https://analogjs.org/) — Analog is a full-stack Angular meta-framework that brings exciting features to Angular, like faster Vite setup, support for both server-side and static rendering, and easy file-based routing. Analog uses an Nx monorepo for its development and also uses [Nx’s DevKit](/extending-nx/intro/getting-started) to create tools that work great in both Nx and Angular CLI workspaces.
|
||||
|
||||
[**Qwikifier**](https://github.com/qwikifiers/qwik-nx) — The Qwikifiers community built a dedicated Nx plugin to combine the power of Qwik and Nx. Their repo is a great example of building Nx plugins and [using Nx to build your own CLI](https://nx.dev/extending-nx/recipes/create-install-package).
|
||||
[**Qwikifier**](https://github.com/qwikifiers/qwik-nx) — The Qwikifiers community built a dedicated Nx plugin to combine the power of Qwik and Nx. Their repo is a great example of building Nx plugins and [using Nx to build your own CLI](/extending-nx/recipes/create-install-package).
|
||||
|
||||
[**Builder.io Mitosis**](https://github.com/BuilderIO/mitosis) — [BuilderIO](https://www.builder.io/) has an ambitious compiler project that allows you to write a component once and then compile it to different frameworks. Check out their [mind-blowing demo page](https://mitosis.builder.io/?outputTab=G4VwpkA%3D). They adopted Nx to [coordinate task dependencies](https://nx.dev/concepts/task-pipeline-configuration) and speed up their CI builds.
|
||||
[**Builder.io Mitosis**](https://github.com/BuilderIO/mitosis) — [BuilderIO](https://www.builder.io/) has an ambitious compiler project that allows you to write a component once and then compile it to different frameworks. Check out their [mind-blowing demo page](https://mitosis.builder.io/?outputTab=G4VwpkA%3D). They adopted Nx to [coordinate task dependencies](/concepts/task-pipeline-configuration) and speed up their CI builds.
|
||||
|
||||
[**Ghost**](https://github.com/TryGhost/Ghost) — Are you into blogging? You might want to look at [Ghost](https://ghost.org/). They were using Lerna in the past and migrated to a fully Nx-powered workspace.
|
||||
|
||||
@@ -293,13 +293,13 @@ And these are just some of them that joined in 2023. If I missed some cool ones
|
||||
|
||||
## Nx Community
|
||||
|
||||
Nx has a huge community! We’re lucky to have so many folks rooting for Nx, whether on socials, talking at conferences, writing blog posts or [creating awesome plugins](https://nx.dev/plugin-registry).
|
||||
Nx has a huge community! We’re lucky to have so many folks rooting for Nx, whether on socials, talking at conferences, writing blog posts or [creating awesome plugins](/plugin-registry).
|
||||
|
||||
**Nx Champions** — This year we finally launched which we had planned for a long time. Our [Nx Champions](https://nx.dev/community) program.
|
||||
**Nx Champions** — This year we finally launched which we had planned for a long time. Our [Nx Champions](/community) program.
|
||||
|
||||

|
||||
|
||||
These are individuals who stood out for their contributions and passion for helping within the Nx community. We wanted to build a more connected relationship with these folks and have a channel to gather more direct feedback as well. Get to know [all of our champions](https://nx.dev/community).
|
||||
These are individuals who stood out for their contributions and passion for helping within the Nx community. We wanted to build a more connected relationship with these folks and have a channel to gather more direct feedback as well. Get to know [all of our champions](/community).
|
||||
|
||||
**New Discord server** — Around September we also switched over from our previous Nx Slack community to a brand new [**Nx community Discord**](https://go.nx.dev/community), which is already 2,600 members and counting. Discord is popular among OSS communities and allows new folks to join easily. In addition, we now have a dedicated forum integrated, as well as a couple of useful automations. More coming next year!
|
||||
|
||||
@@ -309,16 +309,16 @@ Make sure [you join](https://go.nx.dev/community)!
|
||||
|
||||
Our [Youtube channel](https://www.youtube.com/@nxdevtools) has grown to over 15k subscribers and peaks of 65k views a month. We love to provide educational video content, so make sure to subscribe! It got a little silent towards the end of the year, but we’ve been working a lot behind the scenes. So stay tuned!
|
||||
|
||||
We also poured a lot of [effort into the docs](https://nx.dev/getting-started/intro). We restructured them following the [Diataxis](https://diataxis.fr/) to make pages less overwhelming and more structured based on their type of content. You’ll find
|
||||
We also poured a lot of [effort into the docs](/getting-started/intro). We restructured them following the [Diataxis](https://diataxis.fr/) to make pages less overwhelming and more structured based on their type of content. You’ll find
|
||||
|
||||
- [**Concept docs**](https://nx.dev/concepts) — which explain some of the inner workings and mental model behind certain features. Like [how caching works](https://nx.dev/concepts/how-caching-works).
|
||||
- [**Recipes**](https://nx.dev/recipes) — which are solution oriented. You already know how to cook, we provide the exact recipe for it.
|
||||
- [**Tutorials**](https://nx.dev/getting-started/tutorials) — for when you just want to sit down and follow along, step by step to learn how to use Nx in a certain context.
|
||||
- [**Reference**](https://nx.dev/reference) and [**API docs**](https://nx.dev/nx-api) — pure, raw and to the point.
|
||||
- [**Concept docs**](/concepts) — which explain some of the inner workings and mental model behind certain features. Like [how caching works](/concepts/how-caching-works).
|
||||
- [**Recipes**](/recipes) — which are solution oriented. You already know how to cook, we provide the exact recipe for it.
|
||||
- [**Tutorials**](/getting-started/tutorials) — for when you just want to sit down and follow along, step by step to learn how to use Nx in a certain context.
|
||||
- [**Reference**](/reference) and [**API docs**](/nx-api) — pure, raw and to the point.
|
||||
|
||||
We created a brand new [“Why Nx”](https://nx.dev/getting-started/why-nx) page explaining the overall architecture of Nx including a [brand new video](https://www.youtube.com/watch?v=-_4WMl-Fn0w) giving you a holistic overview of what Nx is capable of.
|
||||
We created a brand new [“Why Nx”](/getting-started/why-nx) page explaining the overall architecture of Nx including a [brand new video](https://www.youtube.com/watch?v=-_4WMl-Fn0w) giving you a holistic overview of what Nx is capable of.
|
||||
|
||||
We also refreshed our [entry pages](https://nx.dev/getting-started/intro), including dedicated examples of using Nx with popular stacks:
|
||||
We also refreshed our [entry pages](/getting-started/intro), including dedicated examples of using Nx with popular stacks:
|
||||
|
||||

|
||||
|
||||
@@ -328,19 +328,19 @@ You can also browse them in the [nx-recipes](https://github.com/nrwl/nx-recipes)
|
||||
|
||||
{% tweet url="https://twitter.com/juristr/status/1726977598218199302" /%}
|
||||
|
||||
And obviously, we jumped on the AI train as well. A couple of months ago, we added the [Nx Assistant](https://nx.dev/ai-chat). A ChatGPT-powered interface trained on our docs. [Katerina](https://twitter.com/psybercity) wrote about it [on our blog](https://blog.nrwl.io/nx-docs-ai-assistant-433d238e45d4). The AI chat allows to interactively ask questions about Nx and will give you relevant answers from our docs (including linking to the sources).
|
||||
And obviously, we jumped on the AI train as well. A couple of months ago, we added the [Nx Assistant](/ai-chat). A ChatGPT-powered interface trained on our docs. [Katerina](https://twitter.com/psybercity) wrote about it [on our blog](https://blog.nrwl.io/nx-docs-ai-assistant-433d238e45d4). The AI chat allows to interactively ask questions about Nx and will give you relevant answers from our docs (including linking to the sources).
|
||||
|
||||
## New Tagline: Smart Monorepos — Fast CI
|
||||
|
||||
Nx stands out for its flexibility, accommodating for both monorepo and non-monorepo project structures. This approach allows users to begin with simpler project configurations, leveraging the benefits of Nx’s robust tooling, and later, when the need arises, seamlessly [migrate to a monorepo](https://nx.dev/recipes/tips-n-tricks/standalone-to-integrated).
|
||||
Nx stands out for its flexibility, accommodating for both monorepo and non-monorepo project structures. This approach allows users to begin with simpler project configurations, leveraging the benefits of Nx’s robust tooling, and later, when the need arises, seamlessly [migrate to a monorepo](/recipes/tips-n-tricks/standalone-to-integrated).
|
||||
|
||||
However, Nx’s true strength becomes most apparent at scale, typically within a monorepo setup. We wanted to capture it in our new tagline: **Smart Monorepos — Fast CI**.
|
||||
|
||||
{% twitter url="https://twitter.com/juristr/status/1734558895547568634" /%}
|
||||
|
||||
Setting up an efficient and maintainable CI process for monorepos can be a complex task, so we’ve also made it a focal point in our new tagline. Nx expands beyond the local development experience, helping you set up an efficient CI process. We’re publicly launching [Nx Agents](https://nx.dev/ci/features/distribute-task-execution) to add seamless distribution to your CI pipeline, and more are coming in 2024.
|
||||
Setting up an efficient and maintainable CI process for monorepos can be a complex task, so we’ve also made it a focal point in our new tagline. Nx expands beyond the local development experience, helping you set up an efficient CI process. We’re publicly launching [Nx Agents](/ci/features/distribute-task-execution) to add seamless distribution to your CI pipeline, and more are coming in 2024.
|
||||
|
||||
As part of that, we also restructured our docs to have a section entirely dedicated to CI: [https://nx.dev/ci](https://nx.dev/ci/intro/ci-with-nx).
|
||||
As part of that, we also restructured our docs to have a section entirely dedicated to CI: [https://nx.dev/ci](/ci/intro/ci-with-nx).
|
||||
|
||||
## Nx Conf
|
||||
|
||||
@@ -360,8 +360,8 @@ Legacy CI systems are a performance and productivity bottleneck if you use a pow
|
||||
|
||||
It has three components:
|
||||
|
||||
- [**Nx Cach**](https://nx.dev/ci/features/remote-cache): Built-in local and remote caching to speed up your tasks and save you time and money. Available now.
|
||||
- [**Nx Agents**](https://nx.dev/ci/features/distribute-task-execution): A single line to enable distributed computation, across multiple machines. Fully managed agents, dynamically allocated based on PR size. Available early Feb.
|
||||
- [**Nx Cach**](/ci/features/remote-cache): Built-in local and remote caching to speed up your tasks and save you time and money. Available now.
|
||||
- [**Nx Agents**](/ci/features/distribute-task-execution): A single line to enable distributed computation, across multiple machines. Fully managed agents, dynamically allocated based on PR size. Available early Feb.
|
||||
- **Nx Workflows**: Next generation, fully managed CI solution with distribution at its core, designed from the ground up for monorepos. _Available later in 2024._
|
||||
|
||||
Optimal parallelization and distribution, using the right numbers of agents for each PR, rerunning flaky tests, splitting and distributing large test suites, handling dependencies between tasks across machines — are just some of the things we can now handle automatically for you. Turn it on and enjoy the speed.
|
||||
@@ -374,7 +374,7 @@ We took inspiration from VSCode. Any project you open in VSCode will work right
|
||||
|
||||
The whole team is excited about it as the new experience feels much more elegant.
|
||||
|
||||
As always, we try very hard not to break folks, so all your current workspaces will keep working, and we will [provide automatic migrations](https://nx.dev/features/automate-updating-dependencies) to bring you to this new way of using Nx.
|
||||
As always, we try very hard not to break folks, so all your current workspaces will keep working, and we will [provide automatic migrations](/features/automate-updating-dependencies) to bring you to this new way of using Nx.
|
||||
|
||||
Exciting stuff! So keep an eye on our channels, and subscribe if you haven’t already ;)
|
||||
|
||||
@@ -382,7 +382,7 @@ Exciting stuff! So keep an eye on our channels, and subscribe if you haven’t a
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](https://nx.dev/getting-started/intro)
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools)
|
||||
- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
|
||||
@@ -182,6 +182,6 @@ We just released Project Crystal, so this is just the beginning of it. While we
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
|
||||
@@ -184,6 +184,6 @@ Whether you're starting a new Nuxt project or looking to enhance an existing one
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X / Twitter](https://twitter.com/nxdevtools) - [LinkedIn](https://www.linkedin.com/company/nrwl)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Community Discord](/community)
|
||||
- [Nx Community Discord](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app)
|
||||
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
|
||||
The only reason to modify this file is if you need to change the number of agent machines or there is another type of task that needs to run in CI.
|
||||
|
||||
The `linux-medium-js` name in the CI configuration refers to a built-in launch template that Nx provides. If you can not find a template in [the default list](https://github.com/nrwl/nx-cloud-workflows/blob/main/launch-templates/linux.yaml) that meets your needs, you can provide your own. [With a single yaml file](/ci/features/distribute-task-execution#launch-templates), you can set up your agent environment in exactly the way you want with your own launch template.
|
||||
The `linux-medium-js` name in the CI configuration refers to a built-in launch template that Nx provides. If you can not find a template in [the default list](https://github.com/nrwl/nx-cloud-workflows/blob/main/launch-templates/linux.yaml) that meets your needs, you can provide your own. [With a single yaml file](/ci/reference/launch-templates), you can set up your agent environment in exactly the way you want with your own launch template.
|
||||
|
||||
## Dynamically Allocate Agents
|
||||
|
||||
@@ -121,6 +121,6 @@ If you have a task that can’t be run on Nx Agents for some reason, you can eas
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
|
||||
@@ -142,6 +142,6 @@ That’s all for now folks! We’re just starting up a new iteration of developm
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
|
||||
@@ -99,6 +99,6 @@ Nx provides an unparalleled toolkit for developers and teams looking to optimize
|
||||
- [X / Twitter](https://twitter.com/nxdevtools)
|
||||
- [LinkedIn](https://www.linkedin.com/company/nrwl)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Community Discord](/community)
|
||||
- [Nx Community Discord](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app)
|
||||
|
||||
@@ -169,8 +169,20 @@ The spirit of this post is similar to Alan Kay's quote, "A change of perspective
|
||||
|
||||
---
|
||||
|
||||
You can learn more about Nx Cloud on [nx.app](https://nx.app) and Nx open source on [nx.dev](https://nx.dev).
|
||||
You can learn more about Nx Cloud on [nx.app](https://nx.app) and Nx open source on [nx.dev]().
|
||||
|
||||
**Nx Cloud Pro includes a 2-month free trial** that is definitely worth trying out if you're curious what Cloud Pro can do for your CI. You can try out Nx Agents, e2e test splitting, deflaking and more. [Learn more about Nx Cloud Pro.](https://nx.app/campaigns/pro)
|
||||
|
||||
We also have a **Pro for Startups** plan which offers agents that are 3.5x cheaper than analogous VMs on CircleCI or Github Actions. [Learn more about Nx Pro for Startups.](https://nx.app/campaigns/pro-for-startups)
|
||||
|
||||
---
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X / Twitter](https://twitter.com/nxdevtools)
|
||||
- [LinkedIn](https://www.linkedin.com/company/nrwl)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Community Discord](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app)
|
||||
|
||||
@@ -25,7 +25,7 @@ This blog will show you:
|
||||
|
||||
Before we start, let’s answer this question: what is Nx and why should we use it?
|
||||
|
||||
From [nx.dev](https://nx.dev): “Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.” It sounds good, what benefits does it bring?
|
||||
From [nx.dev](): “Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.” It sounds good, what benefits does it bring?
|
||||
|
||||
Nx adds the following features to your workspace:
|
||||
|
||||
@@ -212,6 +212,6 @@ Here is how to set up Nx with the Gradle workspace. Hopefully, this gives you a
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](/community)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
---
|
||||
title: Nx 19.0 Release!!
|
||||
authors: ['Zack DeRose']
|
||||
cover_image: '/blog/images/2024-05-08/nx-19-thumbnail.png'
|
||||
tags: [nx, release]
|
||||
---
|
||||
|
||||
{% youtube
|
||||
src="https://youtu.be/U6eO8-w9DR0"
|
||||
title="Nx 19.0 Has Landed!!"
|
||||
width="100%" /%}
|
||||
|
||||
Hey folks!
|
||||
|
||||
It's been awhile since February, where in the midsts our big launch week, we launched Nx 18. Nx 18 introduced the biggest new enhancement to Nx to date: Project Crystal.
|
||||
|
||||
[](/blog/2024-02-05-nx-18-project-crystal)
|
||||
|
||||
You can read more on project crystal [here](/blog/2024-02-05-nx-18-project-crystal). The main thing to know though is that Project Crystal adjusts the idea of Nx plugins, so that the mere presence of the plugin in your Nx Workspace removes the need to maintain any configuration for most cases.
|
||||
|
||||
Nx 18 was a significant departure for us in several ways - maybe the most noteworthy was that we broke our years-long cadence of releasing a new major version every 6 months.
|
||||
|
||||
Nx 19 represents a return to form, matching the reliable 6-month schedule. Nx 19 is releasing now 6 months from when Nx 17 released, making Nx 18 a special case to match the impact that Project Crystal had on Nx as a whole.
|
||||
|
||||
Here's the rundown of the major things we'll cover in this update:
|
||||
|
||||
- [NEW PLUGIN: @nx/gradle](#new-plugin-nxgradle)
|
||||
- [Nx Atomizer Enhancements](#nx-atomizer-enhancements)
|
||||
- [Associated Technologies Added To Tasks](#associated-technologies-added-to-tasks)
|
||||
- [Generators to Convert to Project Crystal](#generators-to-convert-to-project-crystal)
|
||||
- [BREAKING CHANGE: Updating Bundled Environment Variables: `NX_` to `NX_PUBLIC_`](#breaking-change-updating-bundled-environment-variables-to)
|
||||
- [General Crystal Polishing](#general-crystal-polishing)
|
||||
- [Nx Cloud Updates!](#nx-cloud-updates)
|
||||
- [More Miscellaneous Updates!](#more-miscellaneous-updates)
|
||||
- [New Conference: Monorepo World 2024](#new-conference-monorepo-world-2024)
|
||||
- [Wrapping Up, And A Heartfelt Thank You](#wrapping-up-and-a-heartfelt-thank-you)
|
||||
- [Learn More](#learn-more)
|
||||
|
||||
## NEW PLUGIN: @nx/gradle
|
||||
|
||||
[](/blog/2024-04-19-manage-your-gradle)
|
||||
|
||||
We've launched a new first-party plugin for Gradle!
|
||||
|
||||
Emily, the engineer that worked on this effort, posted an entire article where you can find the full details [here](/blog/2024-04-19-manage-your-gradle).
|
||||
|
||||
Thanks to the benefits of Project Crystal - which allows us to determine information to create Nx Tasks based on the way your Gradle projects are setup - by adding this plugin, it makes it easy to add Gradle into an existing workspace without needing any Nx-specific configuration.
|
||||
|
||||
In addition, you can now find [a new tutorial on using Nx with Gradle](/getting-started/tutorials/gradle-tutorial) which will expand on the [Spring framework](https://spring.io/)'s tutorial for multi-module projects and show you how Nx further enhances the developer experience of that workspace. This tutorial takes you all the way through setting up your CI pipeline with Nx Cloud, so be sure to check it out!
|
||||
|
||||
As an editorial note, this Gradle plugin is a big step for Nx, as it represents the first major step we're taking outside of the Javascript ecosystem. This has always been the goal: to robustly support monorepos and full-stack development, even across language and ecosystem barriers. We're using this Gradle plugin internally for our closed-sourced projects (in particular Nx Cloud) and in [Nx Console](https://github.com/nrwl/nx-console/blob/master/package.json#L74) and we're very proud of this plugin and all that it represents.
|
||||
|
||||
## Nx Atomizer Enhancements
|
||||
|
||||
The Nx Atomizer launched in Nx 18 with Project Crystal. Essentially, "Atomizer" is the name we use to describe how Nx will automatically shard your e2e tests in your CI pipelines via our first party plugins. You can find out more information in the video below:
|
||||
|
||||
{% youtube
|
||||
src="https://youtu.be/0YxcxIR7QU0"
|
||||
title="10x Faster e2e Tests!"
|
||||
width="100%" /%}
|
||||
|
||||
While the Atomizer was great for reducing the time of end-to-end tests in CI pipelines, one unfortunate trade-off of the Atomizer was that rather than having a single task to represent your end-to-end validation tasks, you instead had a collection of tasks. This tended to clutter up tools when viewing your Nx Tasks. It also wasn't very clear which tasks belonged to which group!
|
||||
|
||||
We've addressed this in Nx 19 by introducing the concept of Task Grouping inside of our tooling.
|
||||
|
||||
Now, when running the command:
|
||||
|
||||
```shell
|
||||
nx show project nx-dev-e2e --web
|
||||
```
|
||||
|
||||
You'll see the following in the project view:
|
||||
|
||||

|
||||
|
||||
Notice how all tasks are now appropriately grouped in the `E2E (CI)` group!
|
||||
|
||||
You can also find the same enhancements in Nx Cloud. Below is a view of all tasks in the [CI pipeline](https://staging.nx.app/runs/ctbAZfiLy3):
|
||||
|
||||
[](https://staging.nx.app/runs/ctbAZfiLy3)
|
||||
|
||||
Notice how all e2e groups are collapsed by default to give a concise view, while allowing you to expand to see how each individual task is progressing!
|
||||
|
||||
Project Crystal is gathering the information to group your tasks, so this is automatically inferred for you based on the actual contents of your workspace. You can see this information by running the command:
|
||||
|
||||
```shell
|
||||
nx show project nx-dev-e2e --json | jq
|
||||
```
|
||||
|
||||

|
||||
|
||||
All Nx Plugins that support this concept of "Atomization" will do this automatically for you, and if you are writing a custom plugin for your own tool or special use-case, you can implect this inferrence to group your targets in Nx and Nx Cloud tooling as well. We'll be adding more documentation on how to implement this in your own plugins in the future.
|
||||
|
||||
## Associated Technologies Added To Tasks
|
||||
|
||||
We've added icons for associated technologies on tasks in the project detail web view:
|
||||
|
||||

|
||||
|
||||
And in Nx Cloud:
|
||||
|
||||

|
||||
|
||||
This will help easily identify at-a-glance the technology your tasks are associated with. All this is supported out of the box by our plugins and you should see this as soon as updating to Nx 19.
|
||||
|
||||
To see how we support this new feature, checkout the json view of our project again:
|
||||
|
||||
```shell
|
||||
nx show project e2e-angular --json | jq
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Generators to Convert to Project Crystal
|
||||
|
||||
As part of Nx 19, we've included generators to our Playwright, Cypress, and ESLint plugins to allow you to easily convert your projects to opt into Project Crystal features!
|
||||
|
||||
To convert your workspace, you can use the command:
|
||||
|
||||
```shell
|
||||
nx generate convert-to-inferred
|
||||
```
|
||||
|
||||
Before running this command you could expect your project detail view to look like this:
|
||||
|
||||
```shell
|
||||
nx show project my-react-app-e2e --web
|
||||
```
|
||||
|
||||

|
||||
|
||||
And after running the generator, you can expect your project detail view to look like this:
|
||||
|
||||

|
||||
|
||||
Notice that in addition to reducing the configuration in your `project.json` file, this generator will also turn on the Nx Atomizer for your Cypress and Playwright projects, so Nx will allow sharding for your end-to-end tasks in CI based on the tests present in your workspace going forward. Note that Nx Agents are very highly highly encouraged as a way of taking advantage of this sharding capability.
|
||||
|
||||
As a note, if you cannot see `e2e-ci` tasks after converting your cypress projects, you can [take a closer look here](/nx-api/cypress/documents/overview#splitting-e2e-tasks-by-file) at how to configure them correctly.
|
||||
|
||||
## BREAKING CHANGE: Updating Bundled Environment Variables: `NX_` to `NX_PUBLIC_`
|
||||
|
||||
An important update for folks using environment variables in their builds!
|
||||
|
||||
Previously, when building your projects in an Nx workspace, our builds were setup to include any environment variables prefixed with `NX_` and include them in the built artifact so they would be accessible there. This is often used for setting things like urls for different versions of external services to hit - for example, sending requests to your local development server while developing, but pointing to the production service for your production build.
|
||||
|
||||
Going forward, these environment variables will need to be prefixed with `NX_PUBLIC_`. This is a security consideration - by requiring a more specific prefix we're making sure that no secrets end up in your production builds unintentionally!
|
||||
|
||||
Because of the nature of this change we will NOT be providing an automatic migration. So be sure to manually update any environment variables that you want bundled into your builds from `NX_` to `NX_PUBLIC_`.
|
||||
|
||||
## General Crystal Polishing
|
||||
|
||||
Along with the features above (many of which further build upon Nx Project Crystal), we've done quite a bit since Nx 18 to polish the features that we introduced with Project Crystal.
|
||||
|
||||
Since Nx 18 release, we also started using Project Crystal inside of the Nx repo itself (as well as in Nx Console and in our closed-source monorepo as well). This has allowed us to find many improvements we can make, as well as issues we can fix.
|
||||
|
||||
You can find a full list of fixes and features applied in this major release [here](https://github.com/nrwl/nx/releases/tag/19.0.0).
|
||||
|
||||
[](https://github.com/nrwl/nx/releases/tag/19.0.0)
|
||||
|
||||
With Project Crystal landed now, we're also adjusting our priorities to place a higher importance on stability. You should see this reflected in Nx 19.
|
||||
|
||||
As a note, we had noticed an increase in the rate of Github issues since Nx 18 launched. Previously, we had not allocated enough time to handling these issues. To address this, our team is going to be doubling the amount of time focusing on maintainence.
|
||||
|
||||
In addition - we are adding more process to make the triage of these issues more efficient. Github issues will now be assigned directly to specific members of the Nx Core Team. The main intention of this change is to increase the efficiency of the time that we do spend on addressing issues.
|
||||
|
||||
## Nx Cloud Updates!
|
||||
|
||||
[](https://nx.app/#deep-understanding)
|
||||
|
||||
We've got some cool stats to share from our users regarding the benefits of [Nx Cloud](https://nx.app), our premium CI service. The three areas we've identified as the critical aspects of a CI provider are: speed, cost, and reliablity. In these areas we've seen:
|
||||
|
||||
- **speed**: Reported 30% - 70% faster CI
|
||||
- **cost**: Reported 40% - 75% reduction in CI costs
|
||||
- **reliability**: Nx Cloud's automatic detection and retrying of flaky tests makes the issue of flaky tests largely go away entirely. You can read more on [our thoughts on reliability here](/blog/2024-03-21-reliable-ci).
|
||||
|
||||
In February, we launched two big enhancements to Nx Cloud: the [Atomizer](/ci/features/split-e2e-tasks) and [Nx Agents](https://nx.app/products/agents#content).
|
||||
|
||||
Since then, the Atomizer has received a nice UI update (as we had seen earlier):
|
||||
|
||||
[](https://staging.nx.app/runs/ctbAZfiLy3)
|
||||
|
||||
Since February, we also revamped our task distribution algorithms. This has resulted in a 5-20% (depending on the repo) increase in both speed and cost efficiency for our users.
|
||||
|
||||
If you are interested in trying Nx Cloud, go to [https://nx.app](https://nx.app).
|
||||
|
||||
## More Miscellaneous updates!
|
||||
|
||||
We've been updating our docs site. We've tweeked the search to make it more helpful, updated navigation, and as you can tell since you're reading it, we've moved our blog to [nx.dev/blog](blog) as well.
|
||||
|
||||
We've also added a page for [Nx Enterprise](/enterprise):
|
||||
|
||||
[](/enterprise)
|
||||
|
||||
And! We've revamped our newsletter, written by our CTO, Victor Savkin. [Subscribe here](https://go.nx.dev/nx-newsletter) to start receiving it!
|
||||
|
||||
## NEW CONFERENCE: Monorepo World 2024
|
||||
|
||||
[](https://monorepo.tools/conf)
|
||||
|
||||
We've got a new conference coming up: [Monorepo World 2024](https://monorepo.tools/conf)!
|
||||
|
||||
This conference will cover all things dealing with monorepos, and we're excited to host it at the Computer History Museum in Mountain View, California this October 7th!
|
||||
|
||||
You can [reserve your tickets now](https://ti.to/nx-conf/monorepoworld2024)! In person tickets start at $300 a piece for Early Bird (open until May 31), and online attendance is free.
|
||||
|
||||
The [Call for Speakers](https://sessionize.com/monorepo-world) is open now, and will close on June 20, 2024.
|
||||
|
||||
We'll be excited to see y'all there!
|
||||
|
||||
## Wrapping Up, And A Heartfelt Thank You
|
||||
|
||||
That's it for now!
|
||||
|
||||
I did want to take a moment to give a heartfelt thank you to everyone out there. If you weren't aware, I had something of a [personal tragedy](https://twitter.com/zackderose/status/1759695615573864758) in February, not long after our big launch week.
|
||||
|
||||
[](https://twitter.com/zackderose/status/1759695615573864758)
|
||||
|
||||
For me, this blogpost represents the beginning of my return to Nx, and to the larger dev community.
|
||||
|
||||
To everyone out there - your kindness and care meant more to me than you could know. I intend to return that the positivity and care you invested in me in those dark days back as best I can. So here's looking forward to hard work, more releases, and better days to come.
|
||||
|
||||
With Many Thanks,
|
||||
|
||||
Zack
|
||||
|
||||
## Learn more
|
||||
|
||||
- [Nx Docs](/getting-started/intro)
|
||||
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
|
||||
- [Nx GitHub](https://github.com/nrwl/nx)
|
||||
- [Nx Official Discord Server](https://go.nx.dev/community)
|
||||
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Speed up your CI](https://nx.app/)
|
||||
@@ -0,0 +1,56 @@
|
||||
[
|
||||
{
|
||||
"name": "Juri Strumpflohner",
|
||||
"image": "/blog/images/Juri Strumpfloner.jpeg",
|
||||
"twitter": "juristr",
|
||||
"github": "juristr"
|
||||
},
|
||||
{
|
||||
"name": "Colum Ferry",
|
||||
"image": "/blog/images/Colum Ferry.jpeg",
|
||||
"twitter": "FerryColum",
|
||||
"github": "Coly010"
|
||||
},
|
||||
{
|
||||
"name": "Emily Xiong",
|
||||
"image": "/blog/images/Emily Xiong.jpeg",
|
||||
"twitter": "xiongemily",
|
||||
"github": "xiongemi"
|
||||
},
|
||||
{
|
||||
"name": "Isaac Mann",
|
||||
"image": "/blog/images/Isaac Mann.jpeg",
|
||||
"twitter": "mannisaac",
|
||||
"github": "isaacplmann"
|
||||
},
|
||||
{
|
||||
"name": "Katerina Skroumpelou",
|
||||
"image": "/blog/images/Katerina Skroumpelou.jpeg",
|
||||
"twitter": "psybercity",
|
||||
"github": "mandarini"
|
||||
},
|
||||
{
|
||||
"name": "Max Kless",
|
||||
"image": "/blog/images/Max Kless.jpeg",
|
||||
"twitter": "MaxKless",
|
||||
"github": "MaxKless"
|
||||
},
|
||||
{
|
||||
"name": "Victor Savkin",
|
||||
"image": "/blog/images/Victor Savkin.jpeg",
|
||||
"twitter": "victorsavkin",
|
||||
"github": "vsavkin"
|
||||
},
|
||||
{
|
||||
"name": "Zack DeRose",
|
||||
"image": "/blog/images/Zack DeRose.jpeg",
|
||||
"twitter": "zackderose",
|
||||
"github": "ZackDeRose"
|
||||
},
|
||||
{
|
||||
"name": "Jeff Cross",
|
||||
"image": "/blog/images/Jeff Cross.jpeg",
|
||||
"twitter": "jeffbcross",
|
||||
"github": "jeffbcross"
|
||||
}
|
||||
]
|
||||
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 409 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 185 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 199 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 695 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 35 MiB |
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 8.5 MiB |
|
After Width: | Height: | Size: 965 KiB |
|
After Width: | Height: | Size: 17 MiB |
|
After Width: | Height: | Size: 328 KiB |
|
After Width: | Height: | Size: 2.1 MiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 6.3 KiB |