Skip to content

Commit

Permalink
fix(lambda-nodejs): esbuild preCompilation tsconfig precedence is wro…
Browse files Browse the repository at this point in the history
…ng (#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*
  • Loading branch information
Sébastiaan authored Mar 2, 2023
1 parent b9ec3c9 commit 790a709
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ function extractTsConfig(tsconfigPath: string, previousCompilerOptions?: Record<
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { extends: extendedConfig, compilerOptions } = require(tsconfigPath);
const updatedCompilerOptions = {
...(previousCompilerOptions ?? {}),
...compilerOptions,
...(previousCompilerOptions ?? {}),
};
if (extendedConfig) {
return extractTsConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./testtsconfig.json",
"compilerOptions": {
"target": "ES2022"
}
}
33 changes: 33 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,37 @@ describe('getTsconfigCompilerOptions', () => {
'--target ES2020',
].join(' '));
});

test('should extract compiler options with extended config overriding', () => {
const tsconfig = path.join(__dirname, 'testtsconfig-extended.json');
const compilerOptions = getTsconfigCompilerOptions(tsconfig);
expect(compilerOptions).toEqual([
'--alwaysStrict',
'--charset utf8',
'--declaration',
'--declarationMap false',
'--experimentalDecorators',
'--incremental false',
'--inlineSourceMap',
'--inlineSources',
'--lib es2020',
'--module CommonJS',
'--newLine lf',
'--noEmitOnError',
'--noFallthroughCasesInSwitch',
'--noImplicitAny',
'--noImplicitReturns',
'--noImplicitThis',
'--noUnusedLocals',
'--noUnusedParameters',
'--outDir ./',
'--resolveJsonModule',
'--rootDir ./',
'--strict',
'--strictNullChecks',
'--strictPropertyInitialization',
'--stripInternal false',
'--target ES2022',
].join(' '));
});
});

0 comments on commit 790a709

Please sign in to comment.