From c343dfed96403d28ae750a4d0656cf8c1f7cbcf7 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 29 Sep 2023 21:27:36 +0100 Subject: [PATCH 1/5] chore: Adopt `@guardian/tsconfig` to simplify `tsconfig.json` --- package-lock.json | 7 +++++++ package.json | 1 + tsconfig.json | 11 +---------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7d403ddb9..0ced3fe060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "devDependencies": { "@guardian/eslint-config-typescript": "7.0.0", "@guardian/eslint-plugin-tsdoc-required": "^0.1.3", + "@guardian/tsconfig": "^0.2.0", "@types/git-url-parse": "^9.0.1", "@types/jest": "^29.5.5", "@types/js-yaml": "^4.0.6", @@ -880,6 +881,12 @@ "integrity": "sha512-ohk4/a0Kq9oEq4sSBFS+0XU3AjANwcEbK5HgBHNyIBZgc+7SU0ws+3/7W9QrBZts1lXkOhqBrIW+D+PG5Rk39A==", "dev": true }, + "node_modules/@guardian/tsconfig": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@guardian/tsconfig/-/tsconfig-0.2.0.tgz", + "integrity": "sha512-RauppalK+cQZDRK6IssVmDSnU/VyqMNuVOxPxhmI03kVRxEdwcmBuRqexHwDbnClVUxW/N9hYLbFNuAb9V/p+A==", + "dev": true + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.11", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz", diff --git a/package.json b/package.json index 29493389b9..f2fbd905eb 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "devDependencies": { "@guardian/eslint-config-typescript": "7.0.0", "@guardian/eslint-plugin-tsdoc-required": "^0.1.3", + "@guardian/tsconfig": "^0.2.0", "@types/git-url-parse": "^9.0.1", "@types/jest": "^29.5.5", "@types/js-yaml": "^4.0.6", diff --git a/tsconfig.json b/tsconfig.json index 14832762d3..6c9467df93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,22 +1,13 @@ { + "extends": "@guardian/tsconfig/tsconfig.json", "compilerOptions": { "target": "ES2020", "module": "commonjs", - "moduleResolution": "node", "declaration": true, "declarationMap": true, - "esModuleInterop": true, - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedIndexedAccess": true, "sourceMap": true, "inlineSourceMap": false, "inlineSources": true, - "experimentalDecorators": true, - "typeRoots": ["./node_modules/@types"], "outDir": "lib" }, "include": ["src/**/*"], From 5cfece5d44881093382a6775b7cee95ac29e4797 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 29 Sep 2023 21:49:15 +0100 Subject: [PATCH 2/5] chore(integration-test): Adopt `@guardian/tsconfig` to simplify `tsconfig.json` --- tools/integration-test/package.json | 1 + tools/integration-test/tsconfig.json | 28 ++-------------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/tools/integration-test/package.json b/tools/integration-test/package.json index 607d1d8947..ae3ae17b7f 100644 --- a/tools/integration-test/package.json +++ b/tools/integration-test/package.json @@ -17,6 +17,7 @@ }, "devDependencies": { "@guardian/eslint-config-typescript": "7.0.0", + "@guardian/tsconfig": "^0.2.0", "@types/jest": "^29.1.2", "@types/node": "20.8.2", "aws-cdk": "2.95.1", diff --git a/tools/integration-test/tsconfig.json b/tools/integration-test/tsconfig.json index 44c26517fe..7110e735b4 100644 --- a/tools/integration-test/tsconfig.json +++ b/tools/integration-test/tsconfig.json @@ -1,31 +1,7 @@ { - "ts-node": { - "compilerOptions": { - "module": "CommonJS" - } - }, + "extends": "@guardian/tsconfig/tsconfig.json", "compilerOptions": { - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "node", - "lib": ["ES2020"], - "declaration": true, - "strict": true, - "noImplicitAny": true, - "strictNullChecks": true, - "esModuleInterop": true, - "noImplicitThis": true, - "alwaysStrict": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": false, - "inlineSourceMap": true, - "inlineSources": true, - "experimentalDecorators": true, - "strictPropertyInitialization": false, - "typeRoots": ["./node_modules/@types"], - "outDir": "dist" + "module": "CommonJS" }, "include": [ "src/**/*", "bin/**/*" From f43ee8a2892edaadc71650f6fb8d72a59abd3941 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 29 Sep 2023 21:54:58 +0100 Subject: [PATCH 3/5] chore: gitignore `tsconfig.tsbuildinfo` file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1989315ace..df1bf1fedf 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ yarn-error.log node_modules # This repository currently uses npm over yarn due to some complications in releasing the library with yarn yarn.lock + +tsconfig.tsbuildinfo From 16404a789a1b9ec813d4eab153f66cea5e0e156b Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 29 Sep 2023 22:07:36 +0100 Subject: [PATCH 4/5] fix(project-generator): Use `@guardian/tsconfig` to simplify `tsconfig.json` --- .../template/tsconfig.json.template | 28 ++----------------- src/bin/commands/new-project/utils/init.ts | 1 + 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/bin/commands/new-project/template/tsconfig.json.template b/src/bin/commands/new-project/template/tsconfig.json.template index dc83b2ce96..d3899d53df 100644 --- a/src/bin/commands/new-project/template/tsconfig.json.template +++ b/src/bin/commands/new-project/template/tsconfig.json.template @@ -1,31 +1,7 @@ { - "ts-node": { - "compilerOptions": { - "module": "CommonJS" - } - }, + "extends": "@guardian/tsconfig/tsconfig.json", "compilerOptions": { - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "node", - "lib": ["ES2020"], - "declaration": true, - "strict": true, - "noImplicitAny": true, - "strictNullChecks": true, - "esModuleInterop": true, - "noImplicitThis": true, - "alwaysStrict": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": false, - "inlineSourceMap": true, - "inlineSources": true, - "experimentalDecorators": true, - "strictPropertyInitialization": false, - "typeRoots": ["./node_modules/@types"], - "outDir": "dist" + "module": "CommonJS" }, "include": ["lib/**/*", "bin/**/*"], "exclude": [ diff --git a/src/bin/commands/new-project/utils/init.ts b/src/bin/commands/new-project/utils/init.ts index 49f98f36d6..db2b6dbe22 100644 --- a/src/bin/commands/new-project/utils/init.ts +++ b/src/bin/commands/new-project/utils/init.ts @@ -72,6 +72,7 @@ function createPackageJson(outputDirectory: string): void { const coreDeps: Record = [ "@guardian/eslint-config-typescript", + "@guardian/tsconfig", "@types/jest", "@types/node", "eslint", From d43919ac65f9500f1ad16ce11d496e7f84266250 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 29 Sep 2023 22:23:26 +0100 Subject: [PATCH 5/5] fix(project generator): Add `join` and `CfnInclude` imports only when needed --- src/bin/commands/new-project/index.ts | 2 +- src/bin/commands/new-project/utils/imports.ts | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bin/commands/new-project/index.ts b/src/bin/commands/new-project/index.ts index 55179ff0fd..eba4e95ca6 100644 --- a/src/bin/commands/new-project/index.ts +++ b/src/bin/commands/new-project/index.ts @@ -117,7 +117,7 @@ export const newCdkProject = async (props: NewProjectProps): CliCommandResponse // lib directory await constructStack({ - imports: Imports.newStackImports(), + imports: Imports.newStackImports(!!config.yamlTemplateLocation), appName: config.appName, outputFile: basename(config.stackPath), outputDir: dirname(config.stackPath), diff --git a/src/bin/commands/new-project/utils/imports.ts b/src/bin/commands/new-project/utils/imports.ts index 699cae6ed6..04079cfc30 100644 --- a/src/bin/commands/new-project/utils/imports.ts +++ b/src/bin/commands/new-project/utils/imports.ts @@ -14,16 +14,18 @@ export class Imports { this.imports = imports; } - public static newStackImports(): Imports { + public static newStackImports(addCfnIncludeImports: boolean): Imports { return new Imports({ - path: { - types: [], - components: ["join"], - }, - "aws-cdk-lib/cloudformation-include": { - types: [], - components: ["CfnInclude"], - }, + ...(addCfnIncludeImports && { + path: { + types: [], + components: ["join"], + }, + "aws-cdk-lib/cloudformation-include": { + types: [], + components: ["CfnInclude"], + }, + }), "aws-cdk-lib": { types: ["App"], components: [],