diff --git a/.all-contributorsrc b/.all-contributorsrc index 511fce6f28..7dcd0d9258 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1457,6 +1457,15 @@ "contributions": [ "review" ] + }, + { + "login": "cn-cit", + "name": "cn-cit", + "avatar_url": "https://avatars.githubusercontent.com/u/27255477?v=4", + "profile": "https://github.com/cn-cit", + "contributions": [ + "bug" + ] } ], "repoType": "github", diff --git a/README.md b/README.md index 2c8dd27f8e..5fcd7d82f0 100644 --- a/README.md +++ b/README.md @@ -228,23 +228,24 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
arnogeurts-sqills

🐛 💻 +
cn-cit

🐛
deccy-mcc

🐛
dependabot-preview[bot]

🐛 🚧
dependabot[bot]

🚧
dheffx

🐛
gregswdl

🐛 -
guyroberts21

📖 +
guyroberts21

📖
mattBrzezinski

📖
mergify

🚧
mergify[bot]

🚧
nathannaveen

🚧
seiyashima42

🐛 💻 📖
sullis

💻 -
vaneek

🐛 +
vaneek

🐛
wendysophie

🐛 diff --git a/gh-pages/content/specification/6-compliance-report.md b/gh-pages/content/specification/6-compliance-report.md index ee54cee7a2..4e70f767cd 100644 --- a/gh-pages/content/specification/6-compliance-report.md +++ b/gh-pages/content/specification/6-compliance-report.md @@ -5,7 +5,7 @@ This section details the current state of each language binding with respect to our standard compliance suite. -| number | test | java (98.33%) | golang (79.17%) | Dotnet | Python | +| number | test | java (98.35%) | golang (79.34%) | Dotnet | Python | | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------------------------------------------- | ------ | ------ | | 1 | asyncOverrides_overrideCallsSuper | 🟢 | [🔴](https://github.com/aws/jsii/issues/2670) | ⭕ | ⭕ | | 2 | [arrayReturnedByMethodCanBeRead]("Array created in the kernel can be queried for its elements") | 🟢 | 🟢 | ⭕ | ⭕ | @@ -127,3 +127,4 @@ This section details the current state of each language binding with respect to | 118 | [callbackParameterIsInterface]("Validates pure interfaces can be passed to callbacks") | ⭕ | 🟢 | ⭕ | ⭕ | | 119 | [classCanBeUsedWhenNotExpressedlyLoaded]("Validates that types not explicitly loaded by the user can safely be returned by JS code") | 🟢 | 🟢 | ⭕ | ⭕ | | 120 | [downcasting]("Ensures unsafe-cast features work as expected") | ⭕ | 🟢 | ⭕ | ⭕ | +| 121 | [strippedDeprecatedMemberCanBeReceived]("Ensures --strip-deprecated does not cause odd runtime errors") | 🟢 | 🟢 | ⭕ | ⭕ | diff --git a/packages/@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs b/packages/@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs index d3df89f7a1..7a7bef2ee5 100644 --- a/packages/@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs +++ b/packages/@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs @@ -7,6 +7,7 @@ using CompositeOperation = Amazon.JSII.Tests.CalculatorNamespace.Composition.CompositeOperation; using Amazon.JSII.Tests.CalculatorNamespace.LibNamespace; using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace; +using Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval; using Newtonsoft.Json.Linq; using Xunit; using Xunit.Abstractions; @@ -1534,9 +1535,15 @@ public void ClassCanBeUsedWhenNotExpressedlyLoaded() } private sealed class Cdk16625Impl: Cdk16625 { - protected override double Unwrap(IRandomNumberGenerator rng) { - return rng.Next(); - } + protected override double Unwrap(IRandomNumberGenerator rng) { + return rng.Next(); } + } + + [Fact(DisplayName = Prefix + nameof(StrippedDeprecatedMemberCanBeReceived))] + public void StrippedDeprecatedMemberCanBeReceived() + { + Assert.NotNull(InterfaceFactory.Create()); + } } } diff --git a/packages/@jsii/go-runtime-test/project/compliance_test.go b/packages/@jsii/go-runtime-test/project/compliance_test.go index 529f596476..656ec2d0a9 100644 --- a/packages/@jsii/go-runtime-test/project/compliance_test.go +++ b/packages/@jsii/go-runtime-test/project/compliance_test.go @@ -24,6 +24,7 @@ import ( "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/submodule/child" calclib "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib" "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/customsubmodulename" + "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/deprecationremoval" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -1655,6 +1656,12 @@ func (suite *ComplianceSuite) TestDownCasting() { require.Equal(realValue.Foo(), jsii.Number(1337)) } +func (suite *ComplianceSuite) TestStrippedDeprecatedMemberCanBeReceived() { + require := suite.Require() + + require.NotNil(deprecationremoval.InterfaceFactory_Create()) +} + // required to make `go test` recognize the suite. func TestComplianceSuite(t *testing.T) { suite.Run(t, new(ComplianceSuite)) diff --git a/packages/@jsii/java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java b/packages/@jsii/java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java index ada75214ac..264bd0ab65 100644 --- a/packages/@jsii/java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java +++ b/packages/@jsii/java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import software.amazon.jsii.ComplianceSuiteHarness; @@ -14,6 +15,7 @@ import software.amazon.jsii.tests.calculator.cdk16625.Cdk16625; import software.amazon.jsii.tests.calculator.composition.CompositeOperation; import software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass.NestedStruct; +import software.amazon.jsii.tests.calculator.lib.deprecation_removal.InterfaceFactory; import software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule; import software.amazon.jsii.tests.calculator.lib.IFriendly; import software.amazon.jsii.tests.calculator.lib.MyFirstStruct; @@ -24,10 +26,6 @@ import java.io.IOException; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Instant; @@ -1790,13 +1788,17 @@ public void iso8601DoesNotDeserializeToDate() { final String nowAsISO = df.format(new Date()); final IWallClock wallClock = new IWallClock() { + @NotNull + @Override public String iso8601Now() { return nowAsISO; } }; final Entropy entropy = new Entropy(wallClock) { - public String repeat(final String word) { + @NotNull + @Override + public String repeat(@NotNull final String word) { return word; } }; @@ -1807,6 +1809,7 @@ public String repeat(final String word) { @Test public void classCanBeUsedWhenNotExpressedlyLoaded() { final Cdk16625 subject = new Cdk16625() { + @NotNull @Override protected java.lang.Number unwrap(final IRandomNumberGenerator rng) { return rng.next(); @@ -1814,4 +1817,9 @@ protected java.lang.Number unwrap(final IRandomNumberGenerator rng) { }; subject.test(); } + + @Test + public void strippedDeprecatedMemberCanBeReceived() { + assertNotNull(InterfaceFactory.create()); + } } diff --git a/packages/@jsii/kernel/src/kernel.ts b/packages/@jsii/kernel/src/kernel.ts index 5100b490c7..36d2ee571d 100644 --- a/packages/@jsii/kernel/src/kernel.ts +++ b/packages/@jsii/kernel/src/kernel.ts @@ -583,7 +583,7 @@ export class Kernel { case spec.TypeKind.Class: case spec.TypeKind.Enum: const constructor = this._findSymbol(fqn); - tagJsiiConstructor(constructor, fqn, assm.metadata.version); + tagJsiiConstructor(constructor, fqn); } } } diff --git a/packages/@jsii/kernel/src/objects.ts b/packages/@jsii/kernel/src/objects.ts index 425420a3af..ea7d78fd76 100644 --- a/packages/@jsii/kernel/src/objects.ts +++ b/packages/@jsii/kernel/src/objects.ts @@ -1,4 +1,5 @@ import * as spec from '@jsii/spec'; +import * as assert from 'assert'; import * as api from './api'; import { JsiiFault } from './kernel'; @@ -15,15 +16,12 @@ const OBJID_SYMBOL = Symbol.for('$__jsii__objid__$'); const IFACES_SYMBOL = Symbol.for('$__jsii__interfaces__$'); /** - * Symbol we use to tag the constructor of a JSII class + * Symbol we use to tag constructors that are exported from a JSII module. */ -const JSII_RTTI_SYMBOL = Symbol.for('jsii.rtti'); +const JSII_TYPE_FQN_SYMBOL = Symbol('$__jsii__fqn__$'); interface ManagedConstructor { - readonly [JSII_RTTI_SYMBOL]: { - readonly fqn: string; - readonly version: string; - }; + readonly [JSII_TYPE_FQN_SYMBOL]: string; } type MaybeManagedConstructor = Partial; @@ -36,7 +34,7 @@ type MaybeManagedConstructor = Partial; * information. */ export function jsiiTypeFqn(obj: any): string | undefined { - return (obj.constructor as MaybeManagedConstructor)[JSII_RTTI_SYMBOL]?.fqn; + return (obj.constructor as MaybeManagedConstructor)[JSII_TYPE_FQN_SYMBOL]; } /** @@ -96,19 +94,21 @@ function tagObject(obj: unknown, objid: string, interfaces?: string[]) { /** * Set the JSII FQN for classes produced by a given constructor */ -export function tagJsiiConstructor( - constructor: any, - fqn: string, - version: string, -) { - if (Object.prototype.hasOwnProperty.call(constructor, JSII_RTTI_SYMBOL)) { - return; +export function tagJsiiConstructor(constructor: any, fqn: string) { + if (Object.prototype.hasOwnProperty.call(constructor, JSII_TYPE_FQN_SYMBOL)) { + return assert( + constructor[JSII_TYPE_FQN_SYMBOL] === fqn, + `Unable to register ${constructor.name} as ${fqn}: it is already registerd with FQN ${constructor[JSII_TYPE_FQN_SYMBOL]}`, + ); } - Object.defineProperty(constructor, JSII_RTTI_SYMBOL, { + + // Mark this constructor as exported from a jsii module, so we know we + // should be considering it's FQN as a valid exported type. + Object.defineProperty(constructor, JSII_TYPE_FQN_SYMBOL, { configurable: false, enumerable: false, writable: false, - value: { fqn, version }, + value: fqn, }); } diff --git a/packages/@jsii/python-runtime/tests/test_compliance.py b/packages/@jsii/python-runtime/tests/test_compliance.py index 046ae13839..329aabfca6 100644 --- a/packages/@jsii/python-runtime/tests/test_compliance.py +++ b/packages/@jsii/python-runtime/tests/test_compliance.py @@ -86,6 +86,7 @@ from jsii_calc.submodule.child import SomeEnum from scope.jsii_calc_lib import IFriendly, EnumFromScopedModule, Number from scope.jsii_calc_lib.custom_submodule_name import IReflectable, ReflectableEntry +from scope.jsii_calc_lib.deprecation_removal import InterfaceFactory # Note: The names of these test functions have been chosen to map as closely to the # Java Compliance tests as possible. @@ -1343,3 +1344,7 @@ def _unwrap(self, rng: IRandomNumberGenerator): # This should NOT throw Subject().test() + + +def test_stripped_deprecated_member_can_be_received(): + assert InterfaceFactory.create() is not None diff --git a/packages/@scope/jsii-calc-lib/deprecated-to-strip.txt b/packages/@scope/jsii-calc-lib/deprecated-to-strip.txt new file mode 100644 index 0000000000..c685eefe76 --- /dev/null +++ b/packages/@scope/jsii-calc-lib/deprecated-to-strip.txt @@ -0,0 +1 @@ +@scope/jsii-calc-lib.deprecationRemoval.DeprecatedImplementation diff --git a/packages/@scope/jsii-calc-lib/lib/deprecation-removal.ts b/packages/@scope/jsii-calc-lib/lib/deprecation-removal.ts new file mode 100644 index 0000000000..75e18b6776 --- /dev/null +++ b/packages/@scope/jsii-calc-lib/lib/deprecation-removal.ts @@ -0,0 +1,16 @@ +export interface IInterface { + method(): void; +} + +/** @deprecated do not use me! */ +export class DeprecatedImplementation implements IInterface { + public method(): void { } +} + +export class InterfaceFactory { + public static create(): IInterface { + return new DeprecatedImplementation(); + } + + private constructor() { } +} diff --git a/packages/@scope/jsii-calc-lib/lib/index.ts b/packages/@scope/jsii-calc-lib/lib/index.ts index beeee50442..46c4bd4045 100644 --- a/packages/@scope/jsii-calc-lib/lib/index.ts +++ b/packages/@scope/jsii-calc-lib/lib/index.ts @@ -129,3 +129,4 @@ export class BaseFor2647 { export * as submodule from './submodule'; export * from './duplicate-inherited-prop'; +export * as deprecationRemoval from './deprecation-removal'; diff --git a/packages/@scope/jsii-calc-lib/package.json b/packages/@scope/jsii-calc-lib/package.json index 5f44f71d9c..d3bc5c4f32 100644 --- a/packages/@scope/jsii-calc-lib/package.json +++ b/packages/@scope/jsii-calc-lib/package.json @@ -26,7 +26,7 @@ "main": "build/index.js", "types": "build/index.d.ts", "scripts": { - "build": "jsii --project-references && jsii-rosetta", + "build": "jsii --project-references --strip-deprecated=deprecated-to-strip.txt && jsii-rosetta", "pacmak": "jsii-pacmak", "test": "diff-test test/assembly.jsii .jsii", "test:update": "npm run build && UPDATE_DIFF=1 npm run test" diff --git a/packages/@scope/jsii-calc-lib/test/assembly.jsii b/packages/@scope/jsii-calc-lib/test/assembly.jsii index 671057ad68..318b1a07be 100644 --- a/packages/@scope/jsii-calc-lib/test/assembly.jsii +++ b/packages/@scope/jsii-calc-lib/test/assembly.jsii @@ -92,6 +92,13 @@ }, "schema": "jsii/0.10.0", "submodules": { + "@scope/jsii-calc-lib.deprecationRemoval": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 132 + }, + "symbolId": "lib/deprecation-removal:" + }, "@scope/jsii-calc-lib.submodule": { "locationInModule": { "filename": "lib/index.ts", @@ -729,6 +736,67 @@ ], "symbolId": "lib/index:StructWithOnlyOptionals" }, + "@scope/jsii-calc-lib.deprecationRemoval.IInterface": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "stability": "deprecated" + }, + "fqn": "@scope/jsii-calc-lib.deprecationRemoval.IInterface", + "kind": "interface", + "locationInModule": { + "filename": "lib/deprecation-removal.ts", + "line": 1 + }, + "methods": [ + { + "abstract": true, + "docs": { + "stability": "deprecated" + }, + "locationInModule": { + "filename": "lib/deprecation-removal.ts", + "line": 2 + }, + "name": "method" + } + ], + "name": "IInterface", + "namespace": "deprecationRemoval", + "symbolId": "lib/deprecation-removal:IInterface" + }, + "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "stability": "deprecated" + }, + "fqn": "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory", + "kind": "class", + "locationInModule": { + "filename": "lib/deprecation-removal.ts", + "line": 10 + }, + "methods": [ + { + "docs": { + "stability": "deprecated" + }, + "locationInModule": { + "filename": "lib/deprecation-removal.ts", + "line": 11 + }, + "name": "create", + "returns": { + "type": { + "fqn": "@scope/jsii-calc-lib.deprecationRemoval.IInterface" + } + }, + "static": true + } + ], + "name": "InterfaceFactory", + "namespace": "deprecationRemoval", + "symbolId": "lib/deprecation-removal:InterfaceFactory" + }, "@scope/jsii-calc-lib.submodule.IReflectable": { "assembly": "@scope/jsii-calc-lib", "docs": { @@ -954,5 +1022,5 @@ } }, "version": "0.0.0", - "fingerprint": "kYLYyNyPod3JTyJWmgPJL1Z85k0HEEhQeMIs4zH4bEQ=" + "fingerprint": "XDMAZYhhgc09X8VS8hpn3ch21YxKDn+HB0w82IofsRM=" } \ No newline at end of file diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index d392689d96..d98342303c 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -95,6 +95,7 @@ }, "@scope/jsii-calc-lib": { "submodules": { + "@scope/jsii-calc-lib.deprecationRemoval": {}, "@scope/jsii-calc-lib.submodule": { "targets": { "dotnet": { @@ -18326,5 +18327,5 @@ } }, "version": "3.20.120", - "fingerprint": "OaHwYmdPa8tbAJnlREahLGpRaNNBor2aoG04vsA/SvM=" + "fingerprint": "O7e7hA2s4dwiCigDIFE0ANjlmeXIQydXdSodi9WHja4=" } \ No newline at end of file diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.js.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.js.snap index ee78fe8a21..0e038f7652 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.js.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.js.snap @@ -1011,6 +1011,9 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┣━ 📁 CalculatorNamespace ┃ ┃ ┗━ 📁 LibNamespace ┃ ┃ ┣━ 📄 BaseFor2647.cs + ┃ ┃ ┣━ 📁 DeprecationRemoval + ┃ ┃ ┃ ┣━ 📄 IInterface.cs + ┃ ┃ ┃ ┗━ 📄 InterfaceFactory.cs ┃ ┃ ┣━ 📄 DiamondLeft.cs ┃ ┃ ┣━ 📄 DiamondRight.cs ┃ ┃ ┣━ 📄 EnumFromScopedModule.cs @@ -1151,6 +1154,95 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace `; +exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CalculatorNamespace/LibNamespace/DeprecationRemoval/IInterface.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval +{ + /// + /// Stability: Deprecated + /// + [JsiiInterface(nativeType: typeof(IInterface), fullyQualifiedName: "@scope/jsii-calc-lib.deprecationRemoval.IInterface")] + [System.Obsolete()] + public interface IInterface + { + /// + /// Stability: Deprecated + /// + [JsiiMethod(name: "method")] + [System.Obsolete()] + void Method(); + + /// + /// Stability: Deprecated + /// + [JsiiTypeProxy(nativeType: typeof(IInterface), fullyQualifiedName: "@scope/jsii-calc-lib.deprecationRemoval.IInterface")] + [System.Obsolete()] + internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval.IInterface + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + /// + /// Stability: Deprecated + /// + [JsiiMethod(name: "method")] + [System.Obsolete()] + public void Method() + { + InvokeInstanceVoidMethod(new System.Type[]{}, new object[]{}); + } + } + } +} + +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CalculatorNamespace/LibNamespace/DeprecationRemoval/InterfaceFactory.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval +{ + /// + /// Stability: Deprecated + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval.InterfaceFactory), fullyQualifiedName: "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory")] + [System.Obsolete()] + public class InterfaceFactory : DeputyBase + { + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected InterfaceFactory(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected InterfaceFactory(DeputyProps props): base(props) + { + } + + /// + /// Stability: Deprecated + /// + [JsiiMethod(name: "create", returnsJson: "{\\"type\\":{\\"fqn\\":\\"@scope/jsii-calc-lib.deprecationRemoval.IInterface\\"}}")] + [System.Obsolete()] + public static Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval.IInterface Create() + { + return InvokeStaticMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.DeprecationRemoval.InterfaceFactory), new System.Type[]{}, new object[]{})!; + } + } +} + +`; + exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CalculatorNamespace/LibNamespace/DiamondLeft.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.js.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.js.snap index 76f3a65330..170650e4a5 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.js.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.js.snap @@ -971,6 +971,10 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┣━ 📄 customsubmodulename_Reflector.go ┃ ┣━ 📄 customsubmodulename.go ┃ ┗━ 📄 README.md + ┣━ 📁 deprecationremoval + ┃ ┣━ 📄 deprecationremoval_IInterface.go + ┃ ┣━ 📄 deprecationremoval_InterfaceFactory.go + ┃ ┗━ 📄 deprecationremoval.go ┣━ 📄 go.mod ┣━ 📁 internal ┃ ┗━ 📄 types.go @@ -1471,6 +1475,103 @@ func (r *jsiiProxy_Reflector) AsMap(reflectable IReflectable) *map[string]interf } +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /go/scopejsiicalclib/deprecationremoval/deprecationremoval.go 1`] = ` +package deprecationremoval + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go/runtime" +) + +func init() { + _jsii_.RegisterInterface( + "@scope/jsii-calc-lib.deprecationRemoval.IInterface", + reflect.TypeOf((*IInterface)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "method", GoMethod: "Method"}, + }, + func() interface{} { + return &jsiiProxy_IInterface{} + }, + ) + _jsii_.RegisterClass( + "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory", + reflect.TypeOf((*InterfaceFactory)(nil)).Elem(), + nil, // no members + func() interface{} { + return &jsiiProxy_InterfaceFactory{} + }, + ) +} + +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /go/scopejsiicalclib/deprecationremoval/deprecationremoval_IInterface.go 1`] = ` +package deprecationremoval + +import ( + _jsii_ "github.com/aws/jsii-runtime-go/runtime" +) + +// Deprecated. +type IInterface interface { + // Deprecated. + Method() +} + +// The jsii proxy for IInterface +type jsiiProxy_IInterface struct { + _ byte // padding +} + +func (i *jsiiProxy_IInterface) Method() { + _jsii_.InvokeVoid( + i, + "method", + nil, // no parameters + ) +} + + +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /go/scopejsiicalclib/deprecationremoval/deprecationremoval_InterfaceFactory.go 1`] = ` +package deprecationremoval + +import ( + _jsii_ "github.com/aws/jsii-runtime-go/runtime" + _init_ "github.com/aws/jsii/jsii-calc/go/scopejsiicalclib/jsii" +) + +// Deprecated. +type InterfaceFactory interface { +} + +// The jsii proxy struct for InterfaceFactory +type jsiiProxy_InterfaceFactory struct { + _ byte // padding +} + +// Deprecated. +func InterfaceFactory_Create() IInterface { + _init_.Initialize() + + var returns IInterface + + _jsii_.StaticInvoke( + "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory", + "create", + nil, // no parameters + &returns, + ) + + return returns +} + + `; exports[`Generated code for "@scope/jsii-calc-lib": /go/scopejsiicalclib/go.mod 1`] = ` diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.js.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.js.snap index 2a8ec40c46..43dda414da 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.js.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.js.snap @@ -1434,6 +1434,9 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┗━ 📁 lib ┃ ┣━ 📄 $Module.java ┃ ┣━ 📄 BaseFor2647.java + ┃ ┣━ 📁 deprecation_removal + ┃ ┃ ┣━ 📄 IInterface.java + ┃ ┃ ┗━ 📄 InterfaceFactory.java ┃ ┣━ 📄 DiamondLeft.java ┃ ┣━ 📄 DiamondRight.java ┃ ┣━ 📄 EnumFromScopedModule.java @@ -3539,6 +3542,92 @@ public interface StructWithOnlyOptionals extends software.amazon.jsii.JsiiSerial `; +exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/lib/deprecation_removal/IInterface.java 1`] = ` +package software.amazon.jsii.tests.calculator.lib.deprecation_removal; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = "@scope/jsii-calc-lib.deprecationRemoval.IInterface") +@software.amazon.jsii.Jsii.Proxy(IInterface.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) +@Deprecated +public interface IInterface extends software.amazon.jsii.JsiiSerializable { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + void method(); + + /** + * A proxy class which represents a concrete javascript instance of this type. + */ + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.lib.deprecation_removal.IInterface.Jsii$Default { + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + @Override + public final void method() { + software.amazon.jsii.Kernel.call(this, "method", software.amazon.jsii.NativeType.VOID); + } + } + + /** + * Internal default implementation for {@link IInterface}. + */ + @software.amazon.jsii.Internal + interface Jsii$Default extends IInterface { + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + @Override + default void method() { + software.amazon.jsii.Kernel.call(this, "method", software.amazon.jsii.NativeType.VOID); + } + } +} + +`; + +exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/lib/deprecation_removal/InterfaceFactory.java 1`] = ` +package software.amazon.jsii.tests.calculator.lib.deprecation_removal; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) +@Deprecated +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory") +public class InterfaceFactory extends software.amazon.jsii.JsiiObject { + + protected InterfaceFactory(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected InterfaceFactory(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public static @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.lib.deprecation_removal.IInterface create() { + return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.lib.deprecation_removal.InterfaceFactory.class, "create", software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.lib.deprecation_removal.IInterface.class)); + } +} + +`; + exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/lib/package-info.java 1`] = ` /** * @@ -3563,6 +3652,8 @@ exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/resou @scope/jsii-calc-lib.NumericValue=software.amazon.jsii.tests.calculator.lib.NumericValue @scope/jsii-calc-lib.Operation=software.amazon.jsii.tests.calculator.lib.Operation @scope/jsii-calc-lib.StructWithOnlyOptionals=software.amazon.jsii.tests.calculator.lib.StructWithOnlyOptionals +@scope/jsii-calc-lib.deprecationRemoval.IInterface=software.amazon.jsii.tests.calculator.lib.deprecation_removal.IInterface +@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory=software.amazon.jsii.tests.calculator.lib.deprecation_removal.InterfaceFactory @scope/jsii-calc-lib.submodule.IReflectable=software.amazon.jsii.tests.calculator.custom_submodule_name.IReflectable @scope/jsii-calc-lib.submodule.NestingClass=software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass @scope/jsii-calc-lib.submodule.NestingClass.NestedClass=software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass$NestedClass diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap index 5e135fbd7d..41546e4ee8 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap @@ -1056,6 +1056,8 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┗━ 📄 jsii-calc-lib@0.0.0.jsii.tgz ┣━ 📁 custom_submodule_name ┃ ┗━ 📄 __init__.py + ┣━ 📁 deprecation_removal + ┃ ┗━ 📄 __init__.py ┗━ 📄 py.typed `; @@ -1320,7 +1322,8 @@ kwargs = json.loads( "packages": [ "scope.jsii_calc_lib", "scope.jsii_calc_lib._jsii", - "scope.jsii_calc_lib.custom_submodule_name" + "scope.jsii_calc_lib.custom_submodule_name", + "scope.jsii_calc_lib.deprecation_removal" ], "package_data": { "scope.jsii_calc_lib._jsii": [ @@ -1944,12 +1947,14 @@ __all__ = [ "Operation", "StructWithOnlyOptionals", "custom_submodule_name", + "deprecation_removal", ] publication.publish() # Loading modules to ensure their types are registered with the jsii runtime library from . import custom_submodule_name +from . import deprecation_removal `; @@ -2196,6 +2201,80 @@ publication.publish() `; +exports[`Generated code for "@scope/jsii-calc-lib": /python/src/scope/jsii_calc_lib/deprecation_removal/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from typeguard import check_type + +from .._jsii import * + + +@jsii.interface(jsii_type="@scope/jsii-calc-lib.deprecationRemoval.IInterface") +class IInterface(typing_extensions.Protocol): + ''' + :stability: deprecated + ''' + + @jsii.member(jsii_name="method") + def method(self) -> None: + ''' + :stability: deprecated + ''' + ... + + +class _IInterfaceProxy: + ''' + :stability: deprecated + ''' + + __jsii_type__: typing.ClassVar[str] = "@scope/jsii-calc-lib.deprecationRemoval.IInterface" + + @jsii.member(jsii_name="method") + def method(self) -> None: + ''' + :stability: deprecated + ''' + return typing.cast(None, jsii.invoke(self, "method", [])) + +# Adding a "__jsii_proxy_class__(): typing.Type" function to the interface +typing.cast(typing.Any, IInterface).__jsii_proxy_class__ = lambda : _IInterfaceProxy + + +class InterfaceFactory( + metaclass=jsii.JSIIMeta, + jsii_type="@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory", +): + ''' + :stability: deprecated + ''' + + @jsii.member(jsii_name="create") + @builtins.classmethod + def create(cls) -> IInterface: + ''' + :stability: deprecated + ''' + return typing.cast(IInterface, jsii.sinvoke(cls, "create", [])) + + +__all__ = [ + "IInterface", + "InterfaceFactory", +] + +publication.publish() + +`; + exports[`Generated code for "@scope/jsii-calc-lib": /python/src/scope/jsii_calc_lib/py.typed 1`] = ` diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap index 4ac15cf9f7..c8be186d6e 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap @@ -3378,6 +3378,18 @@ exports[`jsii-tree --all 1`] = ` │ ├── @scope/jsii-calc-base │ └── @scope/jsii-calc-base-of-base ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├─┬ class InterfaceFactory (deprecated) + │ │ │ └─┬ members + │ │ │ └─┬ static create() method (deprecated) + │ │ │ ├── static + │ │ │ └── returns: @scope/jsii-calc-lib.deprecationRemoval.IInterface + │ │ └─┬ interface IInterface (deprecated) + │ │ └─┬ members + │ │ └─┬ method() method (deprecated) + │ │ ├── abstract + │ │ └── returns: void │ └─┬ submodule │ └─┬ types │ ├─┬ class NestingClass (deprecated) @@ -4011,6 +4023,10 @@ exports[`jsii-tree --inheritance 1`] = ` │ └── interface VeryBaseProps └─┬ @scope/jsii-calc-lib ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├── class InterfaceFactory + │ │ └── interface IInterface │ └─┬ submodule │ └─┬ types │ ├── class NestingClass @@ -5568,6 +5584,14 @@ exports[`jsii-tree --members 1`] = ` │ └── foo property └─┬ @scope/jsii-calc-lib ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├─┬ class InterfaceFactory + │ │ │ └─┬ members + │ │ │ └── static create() method + │ │ └─┬ interface IInterface + │ │ └─┬ members + │ │ └── method() method │ └─┬ submodule │ └─┬ types │ ├─┬ class NestingClass @@ -5691,6 +5715,7 @@ exports[`jsii-tree --signatures 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; @@ -6074,6 +6099,10 @@ exports[`jsii-tree --types 1`] = ` │ └── interface VeryBaseProps └─┬ @scope/jsii-calc-lib ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├── class InterfaceFactory + │ │ └── interface IInterface │ └─┬ submodule │ └─┬ types │ ├── class NestingClass @@ -6147,6 +6176,7 @@ exports[`jsii-tree 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.js.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.js.snap index e3d1791aee..a349bff7b0 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.js.snap @@ -49,6 +49,7 @@ exports[`defaults 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; @@ -102,6 +103,7 @@ exports[`inheritance 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; @@ -155,6 +157,7 @@ exports[`members 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; @@ -3537,6 +3540,18 @@ exports[`showAll 1`] = ` │ ├── @scope/jsii-calc-base │ └── @scope/jsii-calc-base-of-base ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├─┬ class InterfaceFactory + │ │ │ └─┬ members + │ │ │ └─┬ static create() method + │ │ │ ├── static + │ │ │ └── returns: @scope/jsii-calc-lib.deprecationRemoval.IInterface + │ │ └─┬ interface IInterface + │ │ └─┬ members + │ │ └─┬ method() method + │ │ ├── abstract + │ │ └── returns: void │ └─┬ submodule │ └─┬ types │ ├─┬ class NestingClass @@ -3741,6 +3756,7 @@ exports[`signatures 1`] = ` ├── @scope/jsii-calc-base-of-base └─┬ @scope/jsii-calc-lib └─┬ submodules + ├── deprecationRemoval └── submodule " `; @@ -4124,6 +4140,10 @@ exports[`types 1`] = ` │ └── interface VeryBaseProps └─┬ @scope/jsii-calc-lib ├─┬ submodules + │ ├─┬ deprecationRemoval + │ │ └─┬ types + │ │ ├── class InterfaceFactory + │ │ └── interface IInterface │ └─┬ submodule │ └─┬ types │ ├── class NestingClass diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap index 4175895716..8e045fcafd 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap @@ -19,6 +19,7 @@ exports[`TypeSystem.classes lists all the classes in the typesystem 1`] = ` "@scope/jsii-calc-lib.Number", "@scope/jsii-calc-lib.NumericValue", "@scope/jsii-calc-lib.Operation", + "@scope/jsii-calc-lib.deprecationRemoval.InterfaceFactory", "@scope/jsii-calc-lib.submodule.NestingClass", "@scope/jsii-calc-lib.submodule.NestingClass.NestedClass", "@scope/jsii-calc-lib.submodule.Reflector", diff --git a/packages/jsii/bin/jsii.ts b/packages/jsii/bin/jsii.ts index 838f523fb4..c2fb14cb54 100644 --- a/packages/jsii/bin/jsii.ts +++ b/packages/jsii/bin/jsii.ts @@ -114,7 +114,7 @@ const warningTypes = Object.keys(enabledWarnings); projectInfo, projectReferences: argv['project-references'], failOnWarnings: argv['fail-on-warnings'], - stripDeprecated: !!argv['strip-deprecated'], + stripDeprecated: argv['strip-deprecated'] != null, stripDeprecatedAllowListFile: argv['strip-deprecated'], addDeprecationWarnings: argv['add-deprecation-warnings'], generateTypeScriptConfig: argv['generate-tsconfig'], diff --git a/packages/jsii/test/deprecation-warnings.test.ts b/packages/jsii/test/deprecation-warnings.test.ts index c57a64cbfb..b62541b8e1 100644 --- a/packages/jsii/test/deprecation-warnings.test.ts +++ b/packages/jsii/test/deprecation-warnings.test.ts @@ -383,10 +383,14 @@ function testpkg_Baz(p) { ); const calcBaseRoot = resolveModuleDir('@scope/jsii-calc-base'); const calcLibRoot = resolveModuleDir('@scope/jsii-calc-lib'); + const calcLibStripDeprecated = path.join( + calcLibRoot, + 'deprecated-to-strip.txt', + ); compile(calcBaseOfBaseRoot, false); compile(calcBaseRoot, true); - compile(calcLibRoot, true); + compile(calcLibRoot, true, calcLibStripDeprecated); const warningsFile = loadWarningsFile(calcBaseRoot); // jsii-calc-base was compiled with warnings. So we expect to see handlers for its types in the warnings file @@ -397,7 +401,7 @@ function testpkg_Baz(p) { // Recompiling without deprecation warning to leave the packages in a clean state compile(calcBaseRoot, false); - compile(calcLibRoot, false); + compile(calcLibRoot, false, calcLibStripDeprecated); }, 120000); }); @@ -905,12 +909,18 @@ function resolveModuleDir(name: string) { return path.dirname(require.resolve(`${name}/package.json`)); } -function compile(projectRoot: string, addDeprecationWarnings: boolean) { +function compile( + projectRoot: string, + addDeprecationWarnings: boolean, + stripDeprecated?: string, +) { const { projectInfo } = loadProjectInfo(projectRoot); const compiler = new Compiler({ projectInfo, addDeprecationWarnings, + stripDeprecated: stripDeprecated != null, + stripDeprecatedAllowListFile: stripDeprecated, }); compiler.emit(); diff --git a/tools/jsii-compliance/suite.ts b/tools/jsii-compliance/suite.ts index 7616aa1206..6f3f2455e8 100644 --- a/tools/jsii-compliance/suite.ts +++ b/tools/jsii-compliance/suite.ts @@ -516,5 +516,9 @@ export const suite: schema.Suite = { name: 'downcasting', description: 'Ensures unsafe-cast features work as expected', }, + { + name: 'strippedDeprecatedMemberCanBeReceived', + description: 'Ensures --strip-deprecated does not cause odd runtime errors', + }, ], };