Nx 14.5 - Cypess v10, Output globs, Linter perf, React Tailwind support
Published: 2022-08-02 16:16:55

---
title: Nx 14.5 - Cypess v10, Output globs, Linter perf, React Tailwind support
canonical_url: https://blog.nrwl.io/nx-14-5-cypess-v10-output-globs-linter-perf-react-tailwind-support-c15f0b5dc2fc?source=friends_link&sk=a0f5d7791cf6cef929168cc7780a46aa
published: true
description: All the cool new features that went into 14.5
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83ipwtt5ml9avfdzkn3d.png
---

Here we go! After not even a month of [releasing v14.4](https://blog.nrwl.io/nx-14-4-inputs-optional-npm-scope-project-graph-cache-directory-and-more-2f92e3437ae0), Nx v14.5 is out!! Here's all you need to know.

**TL;DR:** https://github.com/nrwl/nx/releases/tag/14.5.0

## Cypress v10 and Component Testing 
Cypress v10 is probably the most significant update since Cypress was released. It comes with a new, exciting [Cypress App](https://docs.cypress.io/guides/core-concepts/cypress-app), component testing beta, a new JS/TS-based configuration file and much more. Read all the details in [their official announcement](https://www.cypress.io/blog/2022/06/01/cypress-10-release/).

One of the strengths of Nx is to integrate various tools into a cohesive, high-quality experience. Working together with other companies and open source projects is key to making sure we meet this goal. We have had an ongoing relationship with the folks over at Cypress for years already and have been working closely with them since earlier this year to integrate v10 into Nx in the best possible way.

This includes an upgrade script to automatically migrate Nx users using Cypress v9 seamlessly to v10. By running...
```bash
nx g @nrwl/cypress:migrate-to-cypress-10
```
...your workspace will be automatically upgraded to the latest Cypress version. See our [docs for more](https://nx.dev/packages/cypress/generators/migrate-to-cypress-10)

Cypress v10 also comes with a beta version of [Component Testing](https://docs.cypress.io/guides/component-testing/writing-your-first-component-test). Nx v14.5 comes with an integrated generator to add component testing support to React-based project:

```bash
nx g @nrwl/react:cypress-component-configuration --project=my-react-project --generate-tests
```

You can also append the `--generate-tests` to automatically generate Cypress component tests for the existing components in the target project (`my-react-project`).
```bash
nx g @nrwl/react:cypress-component-configuration --project=my-react-project --generate-tests
```
Check out our [generator docs](https://nx.dev/packages/react/generators/cypress-component-configuration) for more info.

{% embed https://youtu.be/QDWN4C7T-Ck %}

## Globs for Task Outputs
In v14.4 we [introduced inputs and namedInputs](https://blog.nrwl.io/nx-14-4-inputs-optional-npm-scope-project-graph-cache-directory-and-more-2f92e3437ae0?source=friends_link&sk=8fd7618a527fffce7f8e759bc115af3e). They allow you to fine-tune how caching works and when it should be invalidated. 

```json
// nx.json
{
	...
	"targetDefaults": {
		"build": {
			"inputs": ["!{projectRoot}/**/*.spec.ts"]
		}
	}
}
```
Specifying such inputs can drastically increase the number of cache hits!

{% embed https://twitter.com/victorsavkin/status/1550187124678205440?s=20&t=yq7bP6CwIfUzXgPy2RS_dw %}

In this release, we also allow specifying globs for `outputs`. Outputs are optional as Nx comes with reasonable defaults, but you can specify your own if your setup differs from the most commonly used ones:

```json
// nx.json
{
	...
	"targetDefaults": {
		"build": {
			...
			"outputs": ["dist/libs/mylib"]
		}
	}
}
```
Globs are particularly useful when multiple targets write to the same directory. Say you have a `build-js` and `build-css` command and both write into `dist/libs/mylib`. For reasons of clarity, if possible, our recommendation is to split them up. Like:

```json
// nx.json
{
  "build-js": {
    "outputs": ["dist/libs/mylib/js"]
  },
  "build-css": {
    "outputs": ["dist/libs/mylib/css"]
  }
}
```

Sometimes that's not feasible though. In that case, globs come in handy:

```json
// nx.json
{
  "build-js": {
    "outputs": ["dist/libs/mylib/**/*.js"]
  },
  "build-css": {
    "outputs": ["dist/libs/mylib/**/*.css"]
  }
}
```

More [on our docs](https://nx.dev/configuration/packagejson#outputs).

## Parameter Forwarding when building dependent projects

Besides the speed aspect, one key feature of Nx is the ability to build dependent projects automatically. Let's say you have `project-a` which depends on `project-b`, then whenever you run the build for `project-a`, thanks to its project graph, Nx will automatically run the build for `project-b` first. You can define such dependencies either directly in your [project.json](https://nx.dev/configuration/projectjson) or [package.json](https://nx.dev/configuration/packagejson) file, or globally for an entire workspace in `nx.json`:

```json
// nx.json
{
	"targetDefaults": {
		"build": {
			"dependsOn": ["^build"]
		}
	}
}
```

The `^` is a short-hand notation for
```json
// nx.json
{
	"targetDefaults": {
		"build": {
			"dependsOn": [{ "projects": "dependencies", "target": "build"}]
		}
	}
}
```
..and defines that the `build` task should be run for all its dependencies first.

> You have a PNPM,NPM or Yarn workspace? Adding Nx doesn't only benefit you in terms of speed improvements, but also to define such build dependencies. Have a look at this video to learn more: [Setup a monorepo with PNPM workspaces and add Nx for speed: Defining task dependencies aka build pipelines](https://youtu.be/ngdoUQBvAjo?t=1485)

What happens to parameters when invoking the target on a project's dependencies? By default, they are not forwarded but starting with 14.5 you can. Here are some configuration options:
```json
"build": {
   // forward params passed to this target to the dependency targets
  "dependsOn": [
	  { "projects": "dependencies", "target": "build", "params": "forward" }
  ]
},
"test": {
  // ignore params passed to this target, won't be forwarded to the dependency targets
  "dependsOn": [
	  { "projects": "self", "target": "build", "params": "ignore" }
  ]
}
"lint": {
  // ignore params passed to this target, won't be forwarded to the dependency targets
  "dependsOn": [
	  { "projects": "self", "target": "build" }
  ]
}
```

More on our docs:
- https://nx.dev/configuration/projectjson#dependson
- https://nx.dev/configuration/packagejson#dependson

## Linting Performance

We are obsessed with performance, yes we are! And I have good news: the Nx module boundary lint rule just got an order of magnitude faster 🤯.

{% embed https://twitter.com/meeroslav/status/1550058325236191232?s=20&t=raYfXwL9RFg1rvneMX2GtA %}

Replacing `Sets`, `foreach`, `reduce` with plain `for` loops can often have quite a significant impact. You won't notice much on smaller projects, but on large Nx workspaces with 500+ projects you should see some huge improvements 🚀.

## Support for banned external imports lint checks on transitive dependencies
The [Nx Module Boundary lint rule](https://nx.dev/structure/monorepo-tags) is a powerful concept especially when it comes to the maintainability aspect of projects and monorepos. Learn more in our blog article on [Taming Code Organization with Module Boundaries in Nx](https://blog.nrwl.io/mastering-the-project-boundaries-in-nx-f095852f5bf4).

The Module Boundary rule allows for much more though. It also allows to ban external imports. Say you have a frontend project where you want to make sure none of the "backend-type" dependencies accidentally get imported. Or vice-versa, a backend project where you wouldn't necessarily want to depend on any "frontend-type" package references. You can use the `bannedExternalImports` for that. For example:
```json
//.eslintrc.json
{
  // ... more ESLint config here

  // nx-enforce-module-boundaries should already exist at the top-level of your config
  "nx-enforce-module-boundaries": [
    "error",
    {
      "allow": [],
      // update depConstraints based on your tags
      "depConstraints": [
        // projects tagged with "frontend" can't import from "@nestjs/common"
        {
          "sourceTag": "frontend",
          "bannedExternalImports": ["@nestjs/common"]
        },
        // projects tagged with "backend" can't import from "@angular/core"
        {
          "sourceTag": "backend",
          "bannedExternalImports": ["@angular/core"]
        }
      ]
    }
  ]

  // ... more ESLint config here
}
```

Note, the `frontend` and `backend` `sourceTag` definition is something you define. You could have easily named it differently. It is a string that can be attached to a project by adding it to the `tag` property of its `project.json` configuration file. Read more about banned external imports [in our docs](https://nx.dev/structure/monorepo-tags#banning-external-imports).

Starting with 14.5 we now support such checks also on transitive dependencies. Assume we have `project-a` and `project-b`, both of which are tagged as `framework-agnostic` and have `react` in their banned external imports. Also, assume there's a relationship like `project-a -> project-b`. If `project-b` imports `react` and we run linting, it fails correctly. However, if we run linting on `project-a`, it succeeds as `project-a` is not importing `react` at all, thus not breaking the lint rule. In most situations, this is fine because linting happens at a project level, but sometimes you might want to have a "transitive" behavior where linting would also fail for `project-a` because it imports `project-a` which imports `react`.

You can now enable such behavior by setting `checkNestedExternalImports` to `true`:
```json
//.eslintrc.json
{
  // ... more ESLint config here

  // nx-enforce-module-boundaries should already exist at the top-level of your config
  "nx-enforce-module-boundaries": [
    "error",
    {
      "allow": [],
      "checkNestedExternalImports": true,
      // update depConstraints based on your tags
      "depConstraints": [
        // projects tagged with "frontend" can't import from "@nestjs/common"
        {
          "sourceTag": "framework-agnostic",
          "bannedExternalImports": ["*react*"]
        }
      ]
    }
  ]
  // ... more ESLint config here
}
```

## Improved automated Module Boundary Lint Rule fixes
In v13.10 we introduced automated fixes for the Nx Module Boundary rules. Wrong relative imports such as the following can be easily adjusted automatically by providing the `--fix` when running linting on the project.

![Wrong relative imports](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyflgttffyk3d3su6iny.png)

This is a huge time saver, especially on large projects. With Nx v14.5 the automated fixes now also support automated resolution of absolute imports across library boundaries, such as

```
// WRONG
import { libSayHi } from 'libs/tslib-a/src/index';

// automatically fixed to 
import { libSayHi } from '@myorg/tslib-a';
```

## Nx Migrate improvements and Nx Repair

We improved our log output from the Nx automated code migration run to make it more clear what a code migration actually changes. Also, those migrations that don't do anything because they don't apply to your workspace are not shown in the output at all.

![Improved log output when running Nx migrations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5n5xcb5sl0k8i3gowb3a.png)

## Tailwind Setup Generator for React
It has never been easier to add [Tailwind](https://tailwindcss.com/) support to your React app or library. Just run the `setup-tailwind` generator:

```bash
npx nx g @nrwl/react:setup-tailwind --project=<project-name>
```

![VSCode screenshot of using Nx Console to run the setup-tailwind](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncmxg8jf0k8fnfvodcg5.png)

This automatically sets up your project with a PostCSS and Tailwind configuration.

## React Native: Add Detox config to Expo apps

We also improved our React Native support by adding the possibility to generate a [Detox](https://wix.github.io/Detox/) config for Expo applications.

## Deprecating Angular Protractor e2e tests
[Protractor](https://github.com/angular/protractor/issues/5502) has been deprecated for a while on the Angular CLI side and given Nx has had [Cypress](https://cypress.io) support for a while it has never been a popular choice. Starting with this release we're deprecating the generator for setting up Protractor and we're planning on removing support entirely in Nx v15.

## Other Package updates
Here are some more package updates that come with this release and will automatically be bumped when you run the Nx migration:

- Angular v14.1.0
- Express 14.18.1
- Nest v9
- Next.js v12.2.2
- React Native 0.69.1
- React Native Metro v0.71.3
- React 18.0.15
- `eslint-plugin-jsx-a11y` v6.6.1

For an exhaustive list check our release changelog on GitHub: https://github.com/nrwl/nx/releases/tag/14.5.0

## How to Update Nx

Updating Nx is done with the following command, and will update your Nx workspace dependencies and code to the latest version:  

```
npx nx migrate latest
```

After updating your dependencies, run any necessary migrations.  

```
npx nx migrate --run-migrations
```

---

## Learn more

- 🧠 [Nx Docs](https://nx.dev)
- 👩‍💻 [Nx GitHub](https://github.com/nrwl/nx)
- 💬 [Nrwl Community Slack](https://go.nrwl.io/join-slack)
- 📹 [Nrwl Youtube Channel](https://www.youtube.com/nrwl_io)
- 🥚 [Free Egghead course](https://egghead.io/courses/scale-react-development-with-nx-4038)
- 🧐 [Need help with Angular, React, Monorepos, Lerna or Nx? Talk to us 😃](https://nrwl.io/contact-us)

Also, if you liked this, click the :heart: and make sure to follow [Nx](https://twitter.com/nxdevtools) on Twitter for more!

{% embed https://dev.to/t/nx %}