Skip to content

Commit 790a709

Browse files
author
Sébastiaan
authored
fix(lambda-nodejs): esbuild preCompilation tsconfig precedence is wrong (#23871)
The current implementation of the `extractTsConfig` function overrides previously found compiler options by new ones in extended files. So if you override parameters in your tsconfig.json that extends from a different one higher up in the project, the parameters in the base configuration file take precedence over those in the tsconfig that is specified for this specific build task. This change turns around the importance of those parameters so that it matches the behaviour of tsc, where any parameters in the tsconfig override those of the tsconfigs it may extend from. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b9ec3c9 commit 790a709

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/@aws-cdk/aws-lambda-nodejs/lib/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ function extractTsConfig(tsconfigPath: string, previousCompilerOptions?: Record<
197197
// eslint-disable-next-line @typescript-eslint/no-require-imports
198198
const { extends: extendedConfig, compilerOptions } = require(tsconfigPath);
199199
const updatedCompilerOptions = {
200-
...(previousCompilerOptions ?? {}),
201200
...compilerOptions,
201+
...(previousCompilerOptions ?? {}),
202202
};
203203
if (extendedConfig) {
204204
return extractTsConfig(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./testtsconfig.json",
3+
"compilerOptions": {
4+
"target": "ES2022"
5+
}
6+
}

packages/@aws-cdk/aws-lambda-nodejs/test/util.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,37 @@ describe('getTsconfigCompilerOptions', () => {
213213
'--target ES2020',
214214
].join(' '));
215215
});
216+
217+
test('should extract compiler options with extended config overriding', () => {
218+
const tsconfig = path.join(__dirname, 'testtsconfig-extended.json');
219+
const compilerOptions = getTsconfigCompilerOptions(tsconfig);
220+
expect(compilerOptions).toEqual([
221+
'--alwaysStrict',
222+
'--charset utf8',
223+
'--declaration',
224+
'--declarationMap false',
225+
'--experimentalDecorators',
226+
'--incremental false',
227+
'--inlineSourceMap',
228+
'--inlineSources',
229+
'--lib es2020',
230+
'--module CommonJS',
231+
'--newLine lf',
232+
'--noEmitOnError',
233+
'--noFallthroughCasesInSwitch',
234+
'--noImplicitAny',
235+
'--noImplicitReturns',
236+
'--noImplicitThis',
237+
'--noUnusedLocals',
238+
'--noUnusedParameters',
239+
'--outDir ./',
240+
'--resolveJsonModule',
241+
'--rootDir ./',
242+
'--strict',
243+
'--strictNullChecks',
244+
'--strictPropertyInitialization',
245+
'--stripInternal false',
246+
'--target ES2022',
247+
].join(' '));
248+
});
216249
});

0 commit comments

Comments
 (0)