Skip to content
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

fix(projen.component.awscdk-ts-esm-lambda): correct path.dirname reference, fix duplicative marker #166

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Project,
TextFile,
typescript,
javascript,
} from 'projen'

export interface AwsCdkTsEsmLambdaOptions {
Expand Down Expand Up @@ -52,12 +53,13 @@ export class AwsCdkTsEsmLambda extends Component {
}

this.tsFile = new TypeScriptSourceFile(this.project, this.lambdaFile.path, {
marker: true,
marker: false,
recreate: true,
source,
format: true,
format: false,
})
this.applyTransforms()
javascript.Eslint.of(project)?.addIgnorePattern?.(this.tsFile.path)
}

/**
Expand All @@ -78,8 +80,9 @@ export class AwsCdkTsEsmLambda extends Component {
throw new Error('Could not find class constructor in entrypoint file')
functionCtor.insertStatements(0, [
'const __filename = fileURLToPath(import.meta.url);',
'const __dirname = dirname(__filename);',
'const __dirname = path.dirname(__filename);',
])
sourceFile.formatText()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ describe('AwsCdkTsEsmLambda', () => {
const synth = Testing.synth(ctx.project)
expect(synth['src/test-function.ts']).toBeDefined()
expect(synth['src/test-function.ts']).toMatchInlineSnapshot(`
"// ~~ Generated by projen. To modify, edit .projenrc.js and run \\"npx projen\\".

"
// ~~ Generated by projen. To modify, edit .projenrc.js and run \\"npx projen\\".
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
Expand All @@ -64,19 +63,20 @@ describe('AwsCdkTsEsmLambda', () => {
* An AWS Lambda function which executes src/test.
*/
export class TestFunction extends lambda.Function {
constructor(scope: Construct, id: string, props?: TestFunctionProps) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
super(scope, id, {
description: 'src/test.lambda.ts',
...props,
runtime: new lambda.Runtime('nodejs18.x', lambda.RuntimeFamily.NODEJS),
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../assets/test.lambda')),
});
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true });
}
}"
constructor(scope: Construct, id: string, props?: TestFunctionProps) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
super(scope, id, {
description: 'src/test.lambda.ts',
...props,
runtime: new lambda.Runtime('nodejs18.x', lambda.RuntimeFamily.NODEJS),
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../assets/test.lambda')),
});
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true });
}
}
"
`)
})

Expand Down