From c887959474b5e178f0305104bce6f9542872d5d4 Mon Sep 17 00:00:00 2001 From: Timo van Veenendaal Date: Thu, 21 Mar 2024 14:40:37 -0700 Subject: [PATCH] Take "target" from base tsconfig when present --- .tshy/build.json | 1 - README.md | 2 +- src/tsconfig.ts | 12 ++++++++---- tap-snapshots/test/tsconfig.ts.test.cjs | 1 - test/fixtures/basic-custom-project/.tshy/build.json | 1 - .../basic-imports-only-deps/.tshy/build.json | 1 - test/fixtures/basic/.tshy/build.json | 1 - test/fixtures/imports-with-star/.tshy/build.json | 1 - test/fixtures/imports/.tshy/build.json | 1 - 9 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.tshy/build.json b/.tshy/build.json index c51b7f5..aea1a9e 100644 --- a/.tshy/build.json +++ b/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" } diff --git a/README.md b/README.md index 870836d..178ba7e 100644 --- a/README.md +++ b/README.md @@ -701,7 +701,7 @@ following caveats: - `outDir` - will be overridden based on build, best omitted - `rootDir` - will be set to `./src` in the build, can only cause annoying errors otherwise. - - `target` - will be set to `es2022` + - `target` - will be set to `es2022` if not specified - `module` - will be set to `NodeNext` - `moduleResolution` - will be set to `NodeNext` diff --git a/src/tsconfig.ts b/src/tsconfig.ts index f3dd3d0..49d36ae 100644 --- a/src/tsconfig.ts +++ b/src/tsconfig.ts @@ -14,6 +14,7 @@ import * as console from './console.js' import config from './config.js' import polyfills from './polyfills.js' import preventVerbatimModuleSyntax from './prevent-verbatim-module-syntax.js' +import readTypescriptConfig from './read-typescript-config.js' const { dialects = ['esm', 'commonjs'], @@ -43,18 +44,21 @@ const recommended: Record = { }, } -const build: Record = { +const build = (): Record => ({ extends: config.project === undefined ? '../tsconfig.json' : join('..', config.project), compilerOptions: { + target: + readTypescriptConfig().options.target === undefined + ? 'es2022' + : undefined, rootDir: '../src', - target: 'es2022', module: 'nodenext', moduleResolution: 'nodenext', }, -} +}) const commonjs = (dialect: string): Record => { const exclude = [...relativeExclude, '../src/**/*.mts'] @@ -112,7 +116,7 @@ if (config.project === undefined && !existsSync('tsconfig.json')) { for (const f of readdirSync('.tshy')) { unlinkSync(resolve('.tshy', f)) } -writeConfig('build', build) +writeConfig('build', build()) if (dialects.includes('commonjs')) { writeConfig('commonjs', commonjs('cjs')) for (const d of commonjsDialects) { diff --git a/tap-snapshots/test/tsconfig.ts.test.cjs b/tap-snapshots/test/tsconfig.ts.test.cjs index bb2424f..6db2d05 100644 --- a/tap-snapshots/test/tsconfig.ts.test.cjs +++ b/tap-snapshots/test/tsconfig.ts.test.cjs @@ -116,7 +116,6 @@ Object { "module": "nodenext", "moduleResolution": "nodenext", "rootDir": "../src", - "target": "es2022", }, "extends": "../tsconfig.json", } diff --git a/test/fixtures/basic-custom-project/.tshy/build.json b/test/fixtures/basic-custom-project/.tshy/build.json index b0321b6..1365f23 100644 --- a/test/fixtures/basic-custom-project/.tshy/build.json +++ b/test/fixtures/basic-custom-project/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.custom.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" } diff --git a/test/fixtures/basic-imports-only-deps/.tshy/build.json b/test/fixtures/basic-imports-only-deps/.tshy/build.json index c51b7f5..aea1a9e 100644 --- a/test/fixtures/basic-imports-only-deps/.tshy/build.json +++ b/test/fixtures/basic-imports-only-deps/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" } diff --git a/test/fixtures/basic/.tshy/build.json b/test/fixtures/basic/.tshy/build.json index c51b7f5..aea1a9e 100644 --- a/test/fixtures/basic/.tshy/build.json +++ b/test/fixtures/basic/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" } diff --git a/test/fixtures/imports-with-star/.tshy/build.json b/test/fixtures/imports-with-star/.tshy/build.json index c51b7f5..aea1a9e 100644 --- a/test/fixtures/imports-with-star/.tshy/build.json +++ b/test/fixtures/imports-with-star/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" } diff --git a/test/fixtures/imports/.tshy/build.json b/test/fixtures/imports/.tshy/build.json index c51b7f5..aea1a9e 100644 --- a/test/fixtures/imports/.tshy/build.json +++ b/test/fixtures/imports/.tshy/build.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.json", "compilerOptions": { "rootDir": "../src", - "target": "es2022", "module": "nodenext", "moduleResolution": "nodenext" }