Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 7, 2025

When a submodule is created, it needs to have a namespace assigned for each target language (e.g. My.Library.SubmoduleName, my_library.submodule_name, etc).. Those names are usually derived, but can be configured explicitly via a .jsiirc.json file.

We already used to look for .jsiirc.json in the same directory to read the jsii language namespaces for the classes in the subdirectories, but this was intended for use only when a directory is exported as a submodule.

It starts to conflict when multiple source files in the same directory are exported as submodules: they would all share the same .jsiirc.json file, but that would mean they all share the same submodule namespaces which is nonsenical.

Consider:

- root.ts export * as submodule from './submodule'; - submodule +-- index.ts export * as subsubmodule from './subsubmodule'; +-- subsubmodule.ts +-- .jsiirc.json // <-- gets used for both submodules! 

In this PR, we make it so the directory-level .jsiirc.json is only read if the exported file is index.ts. This works both when the directory is exported, as well as if the file is directly exported.

Otherwise, for files-as-submodules, read the jsii config from .<file-base-name>.jsiirc.json.

This also adds a validation for multiple submodules not accidentally sharing the same Python module name (or Go, or Java, ...), which did in fact happen for us but doesn't make sense and should be caught.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

When a submodule is exported from a file in a directory, we look for `.jsiirc.json` in the same directory. That was only intended for exporting a `directory/index.ts` as a submodule, and is wrong when submodules are exported from files in the same directory. Consider: ``` - root.ts export * from './submodule'; - submodule +-- index.ts export * from './subsubmodule'; +-- subsubmodule.ts +-- .jsiirc.json // <-- gets used for both submodules! ``` Instead, only use the directory-level `.jsiirc.json` if the exported file is `index.ts`. Otherwise, for submodules read the jsii config from `subsubmodule.jsiirc.json`.
@rix0rrr rix0rrr requested a review from a team November 7, 2025 14:11
@mrgrain mrgrain disabled auto-merge November 10, 2025 09:19
@mrgrain
Copy link
Contributor

mrgrain commented Nov 10, 2025

pls update PR title and description to be a feature and explain the feature in readme style.

For consideration: Should the new submodule.jsiirc.json files also be hidden (prefix with .)?

rix0rrr added a commit to aws/jsii that referenced this pull request Nov 10, 2025
Add documentation for submodules, and submodule configuration. Includes aws/jsii-compiler#2407
@rix0rrr rix0rrr changed the title fix: submodule config for files is erroneously loaded from directory feat: allow configuring jsii namespaces for files-as-submodules (in addition to directories) Nov 10, 2025
@rix0rrr rix0rrr added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit cc3e9a8 Nov 10, 2025
82 checks passed
@rix0rrr rix0rrr deleted the huijbers/submodule-config branch November 10, 2025 10:16
aws-cdk-automation pushed a commit that referenced this pull request Nov 10, 2025
…ddition to directories) (#2407) When a submodule is created, it needs to have a namespace assigned for each target language (e.g. `My.Library.SubmoduleName`, `my_library.submodule_name`, etc).. Those names are usually derived, but can be configured explicitly via a `.jsiirc.json` file. We already used to look for `.jsiirc.json` in the same directory to read the jsii language namespaces for the classes in the subdirectories, but this was intended for use only when a *directory* is exported as a submodule. It starts to conflict when multiple source files in the same directory are exported as submodules: they would all share the same `.jsiirc.json` file, but that would mean they all share the same submodule namespaces which is nonsenical. Consider: ``` - root.ts export * as submodule from './submodule'; - submodule +-- index.ts export * as subsubmodule from './subsubmodule'; +-- subsubmodule.ts +-- .jsiirc.json // <-- gets used for both submodules! ``` In this PR, we make it so the directory-level `.jsiirc.json` is only read if the exported file is `index.ts`. This works both when the directory is exported, as well as if the file is directly exported. Otherwise, for files-as-submodules, read the jsii config from `.<file-base-name>.jsiirc.json`. This also adds a validation for multiple submodules not accidentally sharing the same Python module name (or Go, or Java, ...), which did in fact happen for us but doesn't make sense and should be caught. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 (cherry picked from commit cc3e9a8)
@aws-cdk-automation
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
maintenance/v5.8

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

github-merge-queue bot pushed a commit that referenced this pull request Nov 10, 2025
…ddition to directories) (backport #2407) (#2412) # Backport This will backport the following commits from `main` to `maintenance/v5.8`: - [feat: allow configuring jsii namespaces for files-as-submodules (in addition to directories) (#2407)](#2407) <!--- Backport version: 9.5.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) Co-authored-by: Rico Hermans <rix0rrr@gmail.com>
rix0rrr added a commit to aws/jsii that referenced this pull request Nov 10, 2025
Add documentation for submodules, and submodule configuration. Includes aws/jsii-compiler#2407 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment