Define Code Ownership at the Project Level
The atomic unit of code in an Nx workspace is a project. Tasks, module boundaries and the Nx graph all train us to conceptualize the workspace as a collection of projects. The CODEOWNERS file, however, requires you to switch from a project mental model to a more low-level definition based on the folder structure of your workspace. The @nx/powerpack-owners plugin enables you to stay in the mental model that your workspace is a collection of projects as you define the ownership rules for your workspace. Nx will take care of compiling the project ownership rules into file-based ownership rules that GitHub, Bitbucket or GitLab can understand in the CODEOWNERS file.
Owners Plugin Requires Nx Powerpack
The @nx/powerpack-owners plugin requires an Nx Powerpack license to function. Activating Powerpack is a simple process.
Buy a Powerpack LicenseUnlock all the features of Nx
Project or File-based Configuration
The ownership configuration is defined in the nx.json file or in individual project configuration files. Nx then uses a sync generator to automatically compile those settings into a valid CODEOWNERS file for GitHub, Bitbucket or GitLab. See the plugin documentation for more details.
Define Project Owners
Nx Generates the CODEOWNERS file
1{
2  "owners": {
3    "format": "github",
4    "patterns": [
5      {
6        "description": "Joe's Rust projects",
7        "projects": ["tag:rust"],
8        "owners": ["@joelovesrust"]
9      },
10      {
11        "description": "Finance projects",
12        "projects": ["finance-*"],
13        "owners": ["@finance-team"]
14      },
15      {
16        "description": "Alphabet soup",
17        "projects": ["admin", "books", "cart"],
18        "owners": ["@alice", "@bob", "@cecil"]
19      },
20      {
21        "description": "CI Workflows",
22        "files": [".github/workflows/**/*"],
23        "owners": ["@devops"]
24      }
25    ]
26  }
27}
281# Joe's Rust projects
2/packages/rust-api @joelovesrust
3/packages/experimental-rust @joelovesrust
4
5# Finance projects
6/packages/finance-ui @finance-team
7/packages/finance-data @finance-team
8
9# Alphabet soup
10/packages/admin @alice @bob @cecil
11/packages/books @alice @bob @cecil
12/packages/cart @alice @bob @cecil
13
14# CI Workflows
15.github/workflows/**/* @devops
16
17/packages/my-project/ @ahmed @petra
18/packages/my-project/package.json @ahmed
191{
2  "owners": {
3    "**/*": ["@ahmed", "@petra"],
4    "package.json": ["@ahmed"]
5  },
6};
7