Skip to content

Commit 4240341

Browse files
authored
chore(pkglint): require jsii.dotnet.packageId in package.json (#25816)
Guards against the following error when creating new packages: ```bash Error: The module @aws-cdk/app-staging-synthesizer-alpha does not have a dotnet.packageId setting ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3694670 commit 4240341

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

tools/@aws-cdk/pkglint/lib/rules.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ function cdkModuleName(name: string) {
910910
javaPackage: `software.amazon.awscdk${isLegacyCdkPkg ? '' : `.${suffix.replace(/aws-/, 'services-').replace(/-/g, '.')}`}`,
911911
mavenArtifactId,
912912
dotnetNamespace: `Amazon.CDK${isCdkPkg ? '' : `.${dotnetSuffix}`}`,
913+
dotnetPackageId: `Amazon.CDK${isCdkPkg ? '' : `.${dotnetSuffix}`}`,
913914
python: {
914915
distName: `aws-cdk.${pythonName}`,
915916
module: `aws_cdk.${pythonName.replace(/-/g, '_')}`,
@@ -926,10 +927,6 @@ export class JSIIDotNetNamespaceIsRequired extends ValidationRule {
926927
public validate(pkg: PackageJson): void {
927928
if (!isJSII(pkg)) { return; }
928929

929-
// skip the legacy @aws-cdk/cdk because we actually did not rename
930-
// the .NET module, so we are not publishing the deprecated one
931-
if (pkg.packageName === '@aws-cdk/cdk') { return; }
932-
933930
const dotnet = deepGet(pkg.json, ['jsii', 'targets', 'dotnet', 'namespace']) as string | undefined;
934931
const moduleName = cdkModuleName(pkg.json.name);
935932
expectJSON(this.name, pkg, 'jsii.targets.dotnet.namespace', moduleName.dotnetNamespace, /\./g, /*case insensitive*/ true);
@@ -949,7 +946,34 @@ export class JSIIDotNetNamespaceIsRequired extends ValidationRule {
949946
}
950947

951948
/**
952-
* JSII .NET namespace is required and must look sane
949+
* JSII .NET packageId is required and must look sane
950+
*/
951+
export class JSIIDotNetPackageIdIsRequired extends ValidationRule {
952+
public readonly name = 'jsii/dotnet';
953+
954+
public validate(pkg: PackageJson): void {
955+
if (!isJSII(pkg)) { return; }
956+
957+
const dotnet = deepGet(pkg.json, ['jsii', 'targets', 'dotnet', 'namespace']) as string | undefined;
958+
const moduleName = cdkModuleName(pkg.json.name);
959+
expectJSON(this.name, pkg, 'jsii.targets.dotnet.packageId', moduleName.dotnetPackageId, /\./g, /*case insensitive*/ true);
960+
961+
if (dotnet) {
962+
const actualPrefix = dotnet.split('.').slice(0, 2).join('.');
963+
const expectedPrefix = moduleName.dotnetPackageId.split('.').slice(0, 2).join('.');
964+
if (actualPrefix !== expectedPrefix) {
965+
pkg.report({
966+
ruleName: this.name,
967+
message: `.NET packageId must share the first two segments of the default namespace, '${expectedPrefix}' vs '${actualPrefix}'`,
968+
fix: () => deepSet(pkg.json, ['jsii', 'targets', 'dotnet', 'packageId'], moduleName.dotnetPackageId),
969+
});
970+
}
971+
}
972+
}
973+
}
974+
975+
/**
976+
* JSII .NET icon url is required and must look sane
953977
*/
954978
export class JSIIDotNetIconUrlIsRequired extends ValidationRule {
955979
public readonly name = 'jsii/dotnet/icon-url';

0 commit comments

Comments
 (0)