Skip to content

Commit a78d82e

Browse files
author
Luke Hoban
authored
Avoid importing full root @pulumi/aws module (#2569)
Every folder inside the AWS Node.js SDK that has a mixin was importing "../utils", which imports "./awsMixins" which itself was forcing import of "." which then goes back and tries to force import of everything. There is no clear reason why forcing this root module import was ever necesary. Nothing that imports utils.ts depends on the side effects caused by "awsMixins", and the primary effect of adding the `sdk` getter onto the root module is only relevant if the end user loads that root module itself so they can access this property. Also expands some existing test coverage to test this and use of `aws.sdk`, which is the related feature that could in principle be impacted by removing this forced side effect Fixes #772.
1 parent c0dcccb commit a78d82e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

examples/bucket/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16+
// Import the nested module directly to regression test:
17+
// https://github.com/pulumi/pulumi-aws/issues/772
18+
import { Bucket } from "@pulumi/aws/s3";
1619
import * as aws from "@pulumi/aws";
1720

1821
const config = new pulumi.Config("aws");
1922
const providerOpts = { provider: new aws.Provider("prov", { region: <aws.Region>config.require("envRegion") }) };
2023

21-
const bucket = new aws.s3.Bucket("testbucket", {
24+
const bucket = new Bucket("testbucket", {
2225
serverSideEncryptionConfiguration: {
2326
rule: {
2427
applyServerSideEncryptionByDefault: {
@@ -30,8 +33,9 @@ const bucket = new aws.s3.Bucket("testbucket", {
3033
}, providerOpts);
3134

3235
bucket.onObjectCreated("bucket-callback", async (event) => {
33-
const awssdk = await import("aws-sdk");
34-
const s3 = new awssdk.S3();
36+
// Use `aws.sdk` property directly to validate it resolves both
37+
// at type checking time and at runtime correctly.
38+
const s3 = new aws.sdk.S3();
3539

3640
const recordFile = "lastPutFile.json";
3741

sdk/nodejs/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Directly import awsMixins. We want to execute the code within it, but we don't want to import or
16-
// export any values from it. Specifically, awsMixins adds a *getter* property (called "runtime")
17-
// to this @pulumi/aws module. If we actually *import* or *export* that property, the getter will
18-
// execute, which is not what we want at all. Instead, we want to really just expose that we have
19-
// this "runtime" property on the typing, and we want to execute the code that jams the getter on.
20-
21-
import "./awsMixins";
22-
2315
import * as pulumi from "@pulumi/pulumi";
2416
import * as crypto from "crypto";
2517

0 commit comments

Comments
 (0)