aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.63k stars 244 forks source link

go: jsii doesn't handle module imports for private modules #4097

Open yuriy-yarosh opened 1 year ago

yuriy-yarosh commented 1 year ago

Describe the bug

In case of a private monorepo, that uses manually rewritten module paths.

module github.com/org/privaterepo/platform/packages/my-cdk8s-turbochart

go 1.20

require (
    github.com/org/privaterepo/platform/utility/crds v0.0.0
)

replace github.com/org/privaterepo/platform/utility/crds => ../../utility/crds

JSII is unable to pick import the shared replaced module.

Expected Behavior

It should be able to pick modules using their respective absolute paths.

Current Behavior

It panics with a failed import

panic: Passed to parameter props of new xrd_apiextensionscrossplaneio.CompositeResourceDefinition: Unable to deserialize value as xrd_apiextensionscrossplaneio.CompositeResourceDefinitionProps | undefined
├── 🛑 Failing value is an object
│      { '$jsii.struct': [Object] }
╰── 🔍 Failure reason(s):
    ╰─ Key 'spec': Unable to deserialize value as xrd_apiextensionscrossplaneio.CompositeResourceDefinitionSpec | undefined
        ├── 🛑 Failing value is an object
        │      { '$jsii.struct': [Object] }
        ╰── 🔍 Failure reason(s):
            ╰─ Key 'versions': Unable to deserialize value as array<xrd_apiextensionscrossplaneio.CompositeResourceDefinitionSpecVersions>
                ├── 🛑 Failing value is an array
                │      [ [Object] ]
                ╰── 🔍 Failure reason(s):
                    ╰─ Index 0: Unable to deserialize value as xrd_apiextensionscrossplaneio.CompositeResourceDefinitionSpecVersions
                        ├── 🛑 Failing value is an object
                        │      { '$jsii.struct': [Object] }
                        ╰── 🔍 Failure reason(s):
                            ╰─ Key 'schema': Unable to deserialize value as xrd_apiextensionscrossplaneio.CompositeResourceDefinitionSpecVersionsSchema | undefined
                                ├── 🛑 Failing value is an object
                                │      { '$jsii.struct': [Object] }
                                ╰── 🔍 Failure reason(s):
                                    ╰─ Key 'openApiv3Schema': Unable to deserialize value as any | undefined
                                        ├── 🛑 Failing value is an object
                                        │      { '$jsii.struct': [Object] }
                                        ╰── 🔍 Failure reason(s):
                                            ╰─ Module 'k8s' not found

Reproduction Steps

Create two golang modules

  1. github.com/org/repo/module1, github.com/org/repo/module2
  2. make a direct replacement in module1 referencing module2 using relative path
module github.com/org/repo/module1

go 1.20

require (
    github.com/org/repo/module2 v0.0.0
)

replace     github.com/org/repo/module2 => ../module2
  1. JSII will fail to import.

Possible Solution

Implement the respective module rewriting handler for go.mod.

Additional Information/Context

I'm using cdk8s specifically for codegen but not sure if it's a cdk8s issue and the respective handler should be implemented there, as well.

Can provide a sample cdk8s project, for reference and reproducibility.

I've created a separate CDK8S issue with more details regarding my cdk8s use case.

It's an issue where jsii does not generate anything for struct passed into interface{}, also not sure if it's relevant to CDK8S or jsii, but I'd like to get some form of exception, instead of completely blank synthesis.

SDK version used

github.com/aws/jsii-runtime-go v1.81.0 github.com/aws/constructs-go/constructs/v10 v10.2.22

Environment details (OS name and version, etc.)

ArchLinux node.js lts-hydrogen go 1.20

yuriy-yarosh commented 1 year ago

I don't think it's all about monorepo's - I've switched to a single private go module and JSII still unable to find the k8s imported package.