-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wing Platform overrides do not work on extended classes #6093
Comments
**NOTE: ** This is really actually only a bandaid solution. It fixes half the problem. There is a larger issue at hand described in: #6093 The real issue is that we need a way to pass App instance or Platform manager to non-entrypoint files to use methods like `typeForFqn` or `new` but theres a pretty nasty cyclical dependency issue. currently working on another pr, that will probably take more time, in the meantime this unblocks: #4791 ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
I just wanted to point out what are the functional implications of this issue for users: They can't both add a custom platform that overrides a specific resource factory and also I'm struggling with finding an example of a real-world use case for doing both resource customizations in the same Wing project. |
One use case might be "I'm using the AWSCDK Wing platform for base implementations of cloud resources, and I'm extending those classes in my own Wing app" |
I think this bug also applies to non-entrypoint files, see the example below:
// my-platform.js
const aws = require("@cdktf/provider-aws");
exports.Platform = class MyPlatform {
target = "tf-aws"
newInstance(type, scope, id, props) {
if (type === "@cdktf/provider-aws.s3Bucket.S3Bucket") {
return new aws.s3Bucket.S3Bucket(scope, id, {
...props,
bucketPrefix: "foo",
})
}
}
} A possible solution could be to refactor the API of Wing Platforms so instead of directly constructing instances for you, a platform returns types instead: exports.Platform = class MyPlatform {
target = "tf-aws";
typeForFqn(fqn) {
if (fqn === "@cdktf/provider-aws.s3Bucket.S3Bucket") {
return class extends aws.s3Bucket.S3Bucket {
constructor(scope, id, props) {
super(scope, id, {
...props,
bucketPrefix: "bar",
})
}
}
}
}
} |
@Chriscbr yea this is the same issue. I think for sure class CustomBucket extends (this.node.root.typeForFqn("@winglang/sdk.cloud.Bucket") ?? cloud.Bucket) { Where |
I tried this:
when extending in non-entrypoint files
// main.w
// lib.w
Produces preflight code like
The issue is that within this non-entrypoint preflight code, the class
this.node.root
happens at the top level where there is nothis
.We need to somehow provide the
App
orPlatformManager
to non entrypoint files so they can callapp.node.root
This happened:
resource instantiating does not go through proper polycon hook process.
I expected this:
No response
Is there a workaround?
No response
Anything else?
No response
Wing Version
No response
Node.js Version
No response
Platform(s)
No response
Community Notes
The text was updated successfully, but these errors were encountered: