Skip to content

Conversation

@aws-cdk-automation
Copy link
Collaborator

Backport

This will backport the following commits from main to maintenance/v5.8:

Questions ?

Please refer to the Backport tool documentation

Extends the target configuration validation from #2398 to also validate
`.jsiirc.json` files used for submodule-specific target configurations.

Additionally enhances validation to ensure target configurations are
well-formed objects with only valid keys for each language.

## Why

Submodules can have their own target configurations via `.jsiirc.json`
files (for directory-based submodules) or `.<filename>.jsiirc.json`
files (for file-based submodules). These configurations were not being
validated, allowing invalid configurations to slip through until code
generation time.

This PR ensures configuration errors are caught early during compilation
with clear error messages, rather than failing later during package
generation.

## Changes

* Exports `validateTargets` function from `project-info.ts` for reuse
* Calls `validateTargets` when loading `.jsiirc.json` files in
`assembler.ts`
* Adds comprehensive validation for target configuration structure
* Adds 21 new tests covering:
  - File-based `.jsiirc.json` validation (e.g., `.subfile.jsiirc.json`)
  - Namespace conflict detection across all target languages
  - Target configuration structure validation
  - Unknown language and key detection

## Validation Rules

### Identifier Validation

Target language package names must contain only valid identifier
characters:

* **Go**: `packageName` must be a valid identifier
* **.NET**: `namespace` parts (split by `.`) must be valid identifiers
* **Java**: `package` parts (split by `.`) must be valid identifiers
* **Python**: `module` parts (split by `.`) must be valid identifiers

An identifier is defined as matching the regex: `/^[\w_][\w\d_]*$/u`

### Structure Validation

* Target language entries must be objects (not strings or primitives)
* Only known target languages are allowed: `java`, `python`, `dotnet`,
`go`
* Only valid configuration keys are allowed for each language:
  - **Java**: `package`, `maven`, `versionSuffix`
  - **Python**: `module`, `distName`, `classifiers`
  - **.NET**: `namespace`, `packageId`, `iconUrl`, `versionSuffix`
  - **Go**: `moduleName`, `packageName`, `versionSuffix`

### Namespace Conflict Detection

Warns when multiple submodules emit to the same target language
namespace, which would cause conflicts during code generation.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0
license](https://www.apache.org/licenses/LICENSE-2.0).

---------

Signed-off-by: github-actions <github-actions@github.com>
Co-authored-by: github-actions <github-actions@github.com>
(cherry picked from commit 558c3ee)
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Nov 12, 2025
Merged via the queue into maintenance/v5.8 with commit 9c3cfda Nov 12, 2025
84 checks passed
@aws-cdk-automation aws-cdk-automation deleted the backport/maintenance/v5.8-pr-2415 branch November 12, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-approve Automatically approve this PR backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants