Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/interfaces/.jsiirc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
},
"python": {
"module": "aws_cdk.interfaces"
},
"go": {
"packageName": "interfaces"
}
}
}
24 changes: 13 additions & 11 deletions packages/aws-cdk-lib/scripts/submodules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'node:path';
import { createLibraryReadme, ModuleDefinition } from '@aws-cdk/pkglint';
import { createLibraryReadme } from '@aws-cdk/pkglint';
import { topo } from '@aws-cdk/spec2cdk';
import * as fs from 'fs-extra';

Expand Down Expand Up @@ -84,25 +84,27 @@ async function ensureInterfaceSubmoduleJsiiJsonRc(submodule: topo.ModuleMapEntry
const interfacesModuleJsiiRcPath = path.join(interfacesModulePath, '.jsiirc.json');
const interfacesModuleJsiiRc = JSON.parse(await fs.readFile(interfacesModuleJsiiRcPath, 'utf-8'));

const jsiiRcPath = path.join(interfacesModulePath, 'generated', `${submodule.name}-interfaces.generated.jsiirc.json`);
const jsiiRcPath = path.join(interfacesModulePath, 'generated', `.${submodule.name}-interfaces.generated.jsiirc.json`);

const jsiirc = {
targets: {
...combineLanguageNamespace('java', 'package', 'javaPackage'),
...combineLanguageNamespace('dotnet', 'namespace', 'dotnetPackage'),
...combineLanguageNamespace('python', 'module', 'pythonModuleName'),
// No Go...
...combineLanguageNamespace('java', 'package', submodule.definition?.javaPackage),
...combineLanguageNamespace('dotnet', 'namespace', submodule.definition?.dotnetPackage),
...combineLanguageNamespace('python', 'module', submodule.definition?.pythonModuleName),
...combineLanguageNamespace('go', 'packageName', submodule.definition?.moduleName.replace(/[^a-z0-9.]/gi, '')),
},
};
await fs.writeJson(jsiiRcPath, jsiirc, { spaces: 2 });

function combineLanguageNamespace(language: string, whatName: string, k: keyof ModuleDefinition) {
const ns = `${interfacesModuleJsiiRc.targets[language][whatName]}.${lastPart(submodule.definition?.[k] ?? 'undefined')}`;
if (ns.includes('undefined')) {
throw new Error(`Could not build child namespace for language ${language} from ${JSON.stringify(interfacesModuleJsiiRc.targets[language])} and ${k} from ${JSON.stringify(submodule.definition)}`);
function combineLanguageNamespace(language: string, whatName: string, fromDef?: string) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seemed overly complicated just to get the key name into the error message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay better :)

if (fromDef == null) {
throw new Error(`Could not build child namespace for language ${language} from ${JSON.stringify(interfacesModuleJsiiRc.targets[language])} and definition ${JSON.stringify(submodule.definition)}`);
}

return { [language]: { [whatName]: ns } };
const nsParts = [interfacesModuleJsiiRc.targets[language][whatName], lastPart(fromDef)];
const nsSep = language === 'go' ? '' : '.';

return { [language]: { [whatName]: nsParts.join(nsSep) } };
}
}

Expand Down
16 changes: 9 additions & 7 deletions tools/@aws-cdk/spec2cdk/lib/util/jsii.ts
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just adding some comments for better understanding

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ModuleDefinition } from '@aws-cdk/pkglint';
import * as naming from '../naming';

export interface PackageBaseNames {
Expand All @@ -21,15 +22,16 @@ export const AWS_CDK_LIB_BASE_NAMES: PackageBaseNames = {
* @param bases - provide different package base names and overwrite jsii targets
* @returns the module definition
*/
export function namespaceToModuleDefinition(namespace: string, bases: PackageBaseNames = AWS_CDK_LIB_BASE_NAMES) {
export function namespaceToModuleDefinition(namespace: string, bases: PackageBaseNames = AWS_CDK_LIB_BASE_NAMES): ModuleDefinition {
// [aws-s3, AWS, S3]
const { moduleName, moduleFamily, moduleBaseName } = naming.modulePartsFromNamespace(namespace);
const submoduleName = moduleName.replace('-', '_');
const submoduleName = moduleName.replace('-', '_'); // aws_s3

const lowcaseModuleName = moduleBaseName.toLocaleLowerCase();
const packageName = `${bases.javascript}/${moduleName}`;
const lowcaseModuleName = moduleBaseName.toLocaleLowerCase(); // s3
const packageName = `${bases.javascript}/${moduleName}`; // aws-cdk-lib/aws-s3

// dotnet names
const dotnetPackage = `${bases.dotnet}.${moduleFamily}.${moduleBaseName}`;
const dotnetPackage = `${bases.dotnet}.${moduleFamily}.${moduleBaseName}`; // Amazon.CDK.AWS.S3

// java names
const javaGroupId = bases.java;
Expand All @@ -41,8 +43,8 @@ export function namespaceToModuleDefinition(namespace: string, bases: PackageBas
moduleFamily === 'AWS' ? lowcaseModuleName : `${moduleFamily.toLocaleLowerCase()}-${lowcaseModuleName}`;

// python names
const pythonDistName = `${bases.python}.${moduleName}`;
const pythonModuleName = pythonDistName.replace(/-/g, '_');
const pythonDistName = `${bases.python}.${moduleName}`; // aws-cdk.aws-s3
const pythonModuleName = pythonDistName.replace(/-/g, '_'); // aws_cdk.aws_s3

return {
namespace,
Expand Down
Loading