The @nx/powerpack-owners plugin extends the CODEOWNERS functionality to allow you to define code ownership based on projects in addition to the standard file-based definitions. It leverages the nx sync command to compile owners configuration settings from nx.json and project configuration files into valid CODEOWNERS files for GitHub, Bitbucket or GitLab.

With this plugin, you can specify code ownership using the same project matcher syntax as nx run-many. This allows you to easily define rules for multiple projects that may not be located in the same directory. Also, the CODEOWNERS rules will not need to be revisited if a project location is changed or a new project is added.

This plugin requires an active Nx Powerpack license

In order to use @nx/powerpack-owners, you need to have an active Powerpack license. If you don't have a license or it has expired, the syncing process will stop working and you'll need to manually maintain your CODEOWNERS file.

Set Up @nx/powerpack-owners

  1. Activate Powerpack if you haven't already

  2. Install the package

    nx add @nx/powerpack-owners

  3. Configure Ownership

    Configure the @nx/powerpack-owners plugin in the nx.json file or in individual project configuration files. Consult the Owners Configuration Reference section for more details.

  4. Configure the Sync Generator and CI

The nx add @nx/powerpack-owners command should have registered the @nx/powerpack-owners:sync-codeowners-file generator as a globalGenerator in nx.json. You can double check to make sure:

nx.json
1{ 2 "sync": { 3 "globalGenerators": ["@nx/powerpack-owners:sync-codeowners-file"] 4 } 5} 6

Add nx sync:check to the beginning of the CI process.

1- name: Ensure the workspace configuration is in sync 2 run: npx nx sync:check 3

It is also often helpful to add nx sync as a git push hook or git commit hook.

Owners Configuration Reference

nx.json
1{ 2 // Can be set to true instead of an object to accept all defaults 3 "owners": { 4 // Options are `github`, `bitbucket` or `gitlab`. (Optional) Defaults to `github` 5 "format": "github", 6 // (Optional) Default changes based on format: `.github/CODEOWNERS`, `.bitbucket/CODEOWNERS`, `.gitlab/CODEOWNERS` 7 "outputPath": "CODEOWNERS", 8 // (Optional) 9 "patterns": [ 10 { 11 "description": "A description of the rule", 12 "owners": ["@joelovesrust"], 13 // specify either projects or files, not both 14 // Can be any project specifier that could be used in `nx run-many` 15 // See https://nx.dev/nx-api/nx/documents/run-many 16 "projects": ["my-rust-app", "rust-*", "tag:rust"], 17 // File globs 18 "files": [".github/workflows/**/*"] 19 } 20 ] 21 } 22} 23

Examples:

nx.json
1{ 2 "owners": { 3 // defaults to "github" 4 "format": "github", 5 // defaults to ".github/CODEOWNERS" 6 "outputPath": "CODEOWNERS", 7 "patterns": [ 8 { 9 "description": "Joe should double check all changes to rust code", 10 "projects": ["tag:rust"], 11 "owners": ["@joelovesrust"] 12 }, 13 { 14 "description": "The Finance team owns these projects", 15 "projects": ["finance-*"], 16 "owners": ["@finance-team"] 17 }, 18 { 19 "description": "Alice, Bob and Cecil work together on these projects", 20 "projects": ["admin", "booking", "cart"], 21 "owners": ["@alice", "@bob", "@cecil"] 22 }, 23 { 24 "description": "CI Workflows", 25 "files": [".github/workflows/**/*"], 26 "owners": ["@devops"] 27 } 28 ] 29 } 30} 31
packages/my-project/project.json
1{ 2 "owners": { 3 "**/*": ["@ahmed", "@petra"], 4 "package.json": ["@ahmed"], 5 "README.md": { 6 "owners": ["@jared"], 7 "description": "Jared is very particular about the README file" 8 } 9 }, 10}; 11