generated from amazon-archives/__template_Apache-2.0
- Notifications
You must be signed in to change notification settings - Fork 18
feat: allow configuring jsii namespaces for files-as-submodules (in addition to directories) #2407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+91 −3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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`.
mrgrain approved these changes Nov 10, 2025
Contributor
| pls update PR title and description to be a feature and explain the feature in readme style. For consideration: Should the new |
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
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)
Collaborator
💚 All backports created successfully
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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.jsonfile.We already used to look for
.jsiirc.jsonin 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.jsonfile, but that would mean they all share the same submodule namespaces which is nonsenical.Consider:
In this PR, we make it so the directory-level
.jsiirc.jsonis only read if the exported file isindex.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.