aws / aws/jsii

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

Open
#4,097 1 comment 0 reactions 0 assignees View on GitHub
bug p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

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

```go
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
β”œβ”€β”€ πŸ›‘ 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

```go
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
```

3. 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](https://github.com/cdk8s-team/cdk8s/issues/1326) 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

Contributor guide

Open the contributing guide

Research direction

Start with the go.mod examples for module1 and module2 and reproduce the relative replace failure in jsii. Trace the module import handling for replaced Go modules; done means the private replaced module resolves by its absolute path and the reproduction no longer panics with β€œModule 'k8s' not found”.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, node.js, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.