Skip to content

Commit aac81c9

Browse files
authored
chore: cannot write file 'aws-iam/index.d.ts' because it would overwrite input file (#36262)
We have been starting to get the above error, because of the style of imports we've been using. If *inside* `aws-cdk-lib` we use an import of the form: ```ts import * as iam from 'aws-cdk-lib/aws-iam'; ``` Then we add an `index.d.ts` file to the set of inputs, despite there being an `index.ts` right next to it. This code was being generated by the Grants module generator. Fix it to use a relative import. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1f4a224 commit aac81c9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

tools/@aws-cdk/spec2cdk/lib/cdk/aws-cdk-lib.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
159159

160160
private createGrantsModule(moduleName: string, service: Service, grantsConfig: string): LocatedModule<GrantsModule> {
161161
const filePath = this.pathsFor(moduleName, service).grants;
162-
return {
163-
module: new GrantsModule(service, this.db, JSON.parse(grantsConfig)),
162+
const imports = this.resolveImportPaths(filePath);
163+
164+
const module = {
165+
module: new GrantsModule(service, this.db, JSON.parse(grantsConfig), imports.iam),
164166
filePath,
165167
};
168+
169+
return module;
166170
}
167171

168172
protected addResourceToSubmodule(submodule: AwsCdkLibServiceSubmodule, resource: Resource, props?: AddServiceProps): void {
@@ -284,6 +288,7 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
284288
coreHelpers: 'aws-cdk-lib/core/lib/helpers-internal',
285289
coreErrors: 'aws-cdk-lib/core/lib/errors',
286290
cloudwatch: 'aws-cdk-lib/aws-cloudwatch',
291+
iam: 'aws-cdk-lib/aws-iam',
287292
};
288293
}
289294

@@ -293,6 +298,7 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
293298
coreHelpers: relativeImportPath(sourceModule, 'core/lib/helpers-internal'),
294299
coreErrors: relativeImportPath(sourceModule, 'core/lib/errors'),
295300
cloudwatch: relativeImportPath(sourceModule, 'aws-cloudwatch'),
301+
iam: relativeImportPath(sourceModule, 'aws-iam'),
296302
};
297303
}
298304

@@ -337,4 +343,9 @@ export interface ImportPaths {
337343
* The import name used to import the CloudWatch module
338344
*/
339345
readonly cloudwatch: string;
346+
347+
/**
348+
* The import name used to import the IAM module
349+
*/
350+
readonly iam: string;
340351
}

tools/@aws-cdk/spec2cdk/lib/cdk/grants-module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const $this = $E(expr.this_());
2525
* repository.
2626
*/
2727
export class GrantsModule extends Module {
28-
public constructor(private readonly service: Service, private readonly db: SpecDatabase, private readonly schema: GrantsFileSchema) {
28+
public constructor(
29+
private readonly service: Service,
30+
private readonly db: SpecDatabase,
31+
private readonly schema: GrantsFileSchema,
32+
private readonly iamModulePath: string,
33+
) {
2934
super(`${service.shortName}.grants`);
3035
}
3136

@@ -261,7 +266,7 @@ export class GrantsModule extends Module {
261266
if (hasContent) {
262267
new ExternalModule(`aws-cdk-lib/aws-${this.service.shortName}`)
263268
.import(this, this.service.shortName, { fromLocation: `./${this.service.shortName}.generated` });
264-
new ExternalModule('aws-cdk-lib/aws-iam').import(this, 'iam');
269+
new ExternalModule('aws-cdk-lib/aws-iam').import(this, 'iam', { fromLocation: this.iamModulePath });
265270
}
266271
}
267272
}

tools/@aws-cdk/spec2cdk/test/grants.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test('generates grants for methods with and without key actions', async () => {
2929
},
3030
};
3131
const service = db.lookup('service', 'name', 'equals', 'aws-sns').only();
32-
const module = new GrantsModule(service, db, config);
32+
const module = new GrantsModule(service, db, config, 'aws-cdk-lib/aws-iam');
3333

3434
const scope = new Module('@aws-cdk/aws-sns');
3535
const refInterface = new InterfaceType(scope, {

0 commit comments

Comments
 (0)