Skip to content

Commit

Permalink
Take "target" from base tsconfig when present
Browse files Browse the repository at this point in the history
  • Loading branch information
timovv committed Mar 22, 2024
1 parent 8fda22e commit c887959
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion .tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
12 changes: 8 additions & 4 deletions src/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -43,18 +44,21 @@ const recommended: Record<string, any> = {
},
}

const build: Record<string, any> = {
const build = (): Record<string, any> => ({
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<string, any> => {
const exclude = [...relativeExclude, '../src/**/*.mts']
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion tap-snapshots/test/tsconfig.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Object {
"module": "nodenext",
"moduleResolution": "nodenext",
"rootDir": "../src",
"target": "es2022",
},
"extends": "../tsconfig.json",
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/basic-custom-project/.tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.custom.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/basic-imports-only-deps/.tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/basic/.tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/imports-with-star/.tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/imports/.tshy/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
Expand Down

0 comments on commit c887959

Please sign in to comment.