License
Automatically manage LICENSE files and source code headers in your workspace.
This generator registers a sync generator to execute as part of your lint targets which will ensure that your source files conform to the desired license content and format, as well as ensuring that your project’s LICENSE files are correct, and licensing information is included in relevant project files (package.json, pyproject.toml).
Run the Generator
Section titled “Run the Generator”- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - license - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:licenseyarn nx g @aws/nx-plugin:licensenpx nx g @aws/nx-plugin:licensebunx nx g @aws/nx-plugin:licenseYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:license --dry-runyarn nx g @aws/nx-plugin:license --dry-runnpx nx g @aws/nx-plugin:license --dry-runbunx nx g @aws/nx-plugin:license --dry-runOptions
Section titled “Options”| Parameter | Type | Default | Description |
|---|---|---|---|
| license | string | Apache-2.0 | SPDX License Identifier for your chosen license |
| copyrightHolder | string | Amazon.com, Inc. or its affiliates | The copyright holder, included in the LICENSE file and source file headers by default. |
Generator Output
Section titled “Generator Output”The generator will create or update the following files:
- nx.json The lint target is configured to run the license sync generator
- aws-nx-plugin.config.mts Configuration for the license sync generator
Some default configuration for license header content and format is added to aws-nx-plugin.config.mts to write appropriate headers for a handful of file types. You may wish to customise this further; please see the configuration section below.
Workflow
Section titled “Workflow”Whenever you build your projects (and a lint target runs), the license sync generator will make sure that the licensing in your project matches your configuration (see license sync behaviour below). If it detects that anything is out of sync, you will receive a message such as:
NX The workspace is out of sync
[@aws/nx-plugin:license#sync]: Project LICENSE files are out of sync:- LICENSE- packages/<my-project>LICENSE
Project package.json files are out of sync:- package.json
Project pyproject.toml files are out of sync:- pyproject.toml- packages/<my-python-project>/pyproject.toml
License headers are out of sync in the following source files:- packages/<my-project>/src/index.ts- packages/<my-python-project>/main.py
This will result in an error in CI.
? Would you like to sync the identified changes to get your workspace up to date?Yes, sync the changes and run the tasksNo, run the tasks without syncing the changesSelect Yes to sync the changes.
License Sync Behaviour
Section titled “License Sync Behaviour”The license sync generator performs three main tasks:
1. Synchronise Source File License Headers
Section titled “1. Synchronise Source File License Headers”When the sync generator is run, it will ensure that all source code files in your workspace (based on your configuration) contain the appropriate license header. The header is written as the first block comment or consecutive series of line comments in the file (besides the shebang/hashbang if present in a file).
You can update the configuration at any time to change which files should be included or excluded, as well as the content or format of license headers for different file types. For more details, please see the configuration section below.
2. Synchronise LICENSE Files
Section titled “2. Synchronise LICENSE Files”When the sync generator is run, it will ensure that the root LICENSE file corresponds to your configured license, as well as ensuring that all subprojects in your workspace also contain the correct LICENSE file.
You can exclude projects in the configuration if required. For more details, please see the configuration section below.
3. Synchronise licensing information in project files
Section titled “3. Synchronise licensing information in project files”When the sync generator is run, it will ensure the license fields in package.json and pyproject.toml files are set to your configured license.
You can exclude projects in the configuration if required. For more details, please see the configuration section below.
Configuration
Section titled “Configuration”Configuration is defined in the aws-nx-plugin.config.mts file in the root of your workspace.
SPDX and Copyright Holder
Section titled “SPDX and Copyright Holder”Your chosen license can be updated at any time via the spdx configuration property:
export default { license: { spdx: 'MIT', },} satisfies AwsNxPluginConfig;When the sync generator runs, all LICENSE files, package.json and pyproject.toml files will be updated to reflect the configured license.
You can additionally configure the copyright holder and copyright year, which are included in some LICENSE files:
export default { license: { spdx: 'MIT', copyrightHolder: 'Amazon.com, Inc. or its affiliates', copyrightYear: 2025, },} satisfies AwsNxPluginConfig;License Headers
Section titled “License Headers”Content
Section titled “Content”The license header content can be configured in two ways:
- Using inline content:
export default { license: { header: { content: { lines: [ 'Copyright: My Company, Incorporated.', 'Licensed under the MIT License', 'All rights reserved', ]; } // ... format configuration } }} satisfies AwsNxPluginConfig;- Loading from a file:
export default { license: { header: { content: { filePath: 'license-header.txt'; // relative to workspace root } // ... format configuration } }} satisfies AwsNxPluginConfig;Format
Section titled “Format”You can specify how license headers should be formatted for different file types using glob patterns. The format configuration supports line comments, block comments, or a combination of both:
export default { license: { header: { content: { lines: ['Copyright notice here'], }, format: { // Line comments '**/*.ts': { lineStart: '// ', }, // Block comments '**/*.css': { blockStart: '/*', blockEnd: '*/', }, // Block comments with line prefixes '**/*.java': { blockStart: '/*', lineStart: ' * ', blockEnd: ' */', }, // Line comments with header/footer '**/*.py': { blockStart: '# ------------', lineStart: '# ', blockEnd: '# ------------', }, }, }, },} satisfies AwsNxPluginConfig;The format configuration supports:
blockStart: Text written before the license content (e.g. to start a block comment)lineStart: Text prepended to each line of the license contentlineEnd: Text appended to each line of the license contentblockEnd: Text written after the license content (e.g. to end a block comment)
Custom Comment Syntax
Section titled “Custom Comment Syntax”For file types that aren’t natively supported, you can specify custom comment syntax to tell the sync generator how to identify existing license headers in these file types.
export default { license: { header: { content: { lines: ['My license header'], }, format: { '**/*.xyz': { lineStart: '## ', }, }, commentSyntax: { xyz: { line: '##', // Define line comment syntax }, abc: { block: { // Define block comment syntax start: '<!--', end: '-->', }, }, }, }, },} satisfies AwsNxPluginConfig;Excluding files
Section titled “Excluding files”By default, in a git repository, all .gitignore files are honored to ensure that only files managed by version control are synchronized. In non-git repositories, all files are considered unless explicitly excluded in configuration.
You can exclude additional files from license header synchronization using glob patterns:
export default { license: { header: { content: { lines: ['My license header'], }, format: { '**/*.ts': { lineStart: '// ', }, }, exclude: ['**/generated/**', '**/dist/**', 'some-specific-file.ts'], }, },} satisfies AwsNxPluginConfig;Excluding project files from sync
Section titled “Excluding project files from sync”All LICENSE files, package.json files and pyproject.toml files are synchronised with the configured license by default.
You can exclude specific projects or files from synchronization using glob patterns:
export default { license: { files: { exclude: [ // do not sync LICENSE file, package.json or pyproject.toml 'packages/excluded-project', // do not sync LICENSE file, but sync package.json and/or pyproject.toml 'apps/internal/LICENSE', ]; } }} satisfies AwsNxPluginConfig;Disabling license sync
Section titled “Disabling license sync”To disable the license sync generator:
- Remove the
licensesection from your configuration inaws-nx-plugin.config.mts(or remove theaws-nx-plugin.config.mtsfile) - Remove the
@aws/nx-plugin:license#syncgenerator fromtargetDefaults.lint.syncGenerators
To re-enable license sync, simply run the license generator again.