Skip to content

Commit

Permalink
chore(ts): switch tsconfig based on typescript version
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Feb 5, 2023
1 parent 2efbb22 commit f280fcb
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 23 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ jobs:
- id: debug
name: Print environment variables and event payload
uses: hmarr/[email protected]
- id: tsconfig
name: Prepare tsconfig.json
if: matrix.typescript-version != needs.metadata.outputs.version-typescript
run: echo $(jq 'del(.compilerOptions.ignoreDeprecations)' $TSCONFIG) > $TSCONFIG
env:
TSCONFIG: tsconfig.json
- id: typecheck
name: Run typecheck
run: yarn typecheck
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/typescript-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ jobs:
- id: typescript
name: Install typescript@${{ matrix.typescript-version }}
run: yarn add -D typescript@${{ matrix.typescript-version }}
- id: typescript-version
- id: set-typescript-version
name: Set env.TYPESCRIPT_VERSION
run: |
echo "TYPESCRIPT_VERSION=$(jq .devDependencies.typescript package.json -r)" >> $GITHUB_ENV
- id: print-typescript-version
name: Print TypeScript version
run: jq .devDependencies.typescript package.json -r
- id: tsconfig
name: Prepare tsconfig.json
if: matrix.typescript-version != 'next'
run: echo $(jq 'del(.compilerOptions.ignoreDeprecations)' $TSCONFIG) > $TSCONFIG
env:
TSCONFIG: tsconfig.json
run: echo $TYPESCRIPT_VERSION
- id: build
name: Build project
run: yarn build
Expand Down
10 changes: 10 additions & 0 deletions config/ts/v4/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"noEmitOnError": true,
"skipLibCheck": false,
"target": "es2020"
},
"exclude": ["**/__mocks__", "**/__tests__"],
"extends": "./tsconfig.json",
"include": ["../../../dist/*", "../../../src/*"]
}
53 changes: 53 additions & 0 deletions config/ts/v4/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"compilerOptions": {
"allowJs": true,
"allowUnreachableCode": false,
"alwaysStrict": false,
"baseUrl": "../../..",
"checkJs": false,
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"lib": ["es2020"],
"module": "esnext",
"moduleDetection": "force",
"moduleResolution": "node",
"newLine": "lf",
"noEmit": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"outDir": "../../../dist",
"paths": {
"#src": ["src/index"],
"#src/*": ["src/*"],
"#tests/*": ["__tests__/*"]
},
"preserveConstEnums": true,
"preserveSymlinks": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": "../../..",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "esnext",
"useDefineForClassFields": true,
"useUnknownInCatchVariables": true
},
"exclude": ["**/coverage", "**/dist", "**/node_modules"],
"include": ["**/**.cjs", "**/**.mjs", "**/**.ts", "**/.*.cjs"]
}
6 changes: 6 additions & 0 deletions config/ts/v4/tsconfig.typecheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "es2020"
},
"extends": "./tsconfig.json"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"check:lint": "eslint --exit-on-fatal-error --ext cjs,gql,json,jsonc,md,mjs,ts,yml --max-warnings 0 .",
"check:spelling": "cspell lint --color --no-progress --relative $@ \"**\"",
"check:types": "tsc -p tsconfig.typecheck.json",
"check:types:build": "tsc -p tsconfig.build.json",
"check:types:build": "bash ./scripts/typecheck-build.sh",
"check:upgrades": "yarn upgrade-interactive",
"clean:build": "trash ./{dist,*.tgz}",
"clean:modules": "trash ./.yarn/{cache,*.gz} ./node_modules",
Expand Down
12 changes: 12 additions & 0 deletions scripts/typecheck-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Postbuild Typecheck Workflow

# set initial tsconfig file
TSCONFIG='tsconfig.build.json'

# change tsconfig file if typescript version is not at least 5
[[ ! $(jq .devDependencies.typescript package.json -r) = 5* ]] && TSCONFIG=config/ts/v4/$TSCONFIG

# run typecheck
tsc -p $TSCONFIG
4 changes: 2 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"skipLibCheck": false,
"target": "es2020"
},
"exclude": ["**/__mocks__/**", "**/__tests__/**"],
"exclude": ["**/__mocks__", "**/__tests__"],
"extends": "./tsconfig.json",
"include": ["./dist", "./src"]
"include": ["./dist/*", "./src/*"]
}
7 changes: 2 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"exactOptionalPropertyTypes": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"ignoreDeprecations": "5.0",
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"lib": ["es2020"],
"module": "esnext",
"moduleDetection": "force",
Expand Down Expand Up @@ -45,11 +42,11 @@
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"suppressImplicitAnyIndexErrors": true,
"target": "esnext",
"verbatimModuleSyntax": true,
"useDefineForClassFields": true,
"useUnknownInCatchVariables": true
},
"exclude": ["./coverage", "./dist", "./node_modules"],
"exclude": ["**/coverage", "**/dist", "**/node_modules"],
"include": ["**/**.cjs", "**/**.mjs", "**/**.ts", "**/.*.cjs"]
}
1 change: 1 addition & 0 deletions vitest-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ImportMetaEnv {
readonly PWD: string
readonly SSR: '1' | import('@flex-development/tutils').EmptyString
readonly TEST: 'true'
readonly TYPESCRIPT_VERSION?: string
readonly USER: string
readonly VITEST: 'true'
readonly VITEST_CLI_WRAPPER: 'true'
Expand Down
14 changes: 13 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const config: UserConfigExport = defineConfig((): UserConfig => {
*/
const LINT_STAGED: boolean = !!Number.parseInt(process.env.LINT_STAGED ?? '0')

/**
* Boolean indicating if the currently running version of [`typescript`][1] is
* at least `5`.
*
* @const {boolean} TYPESCRIPT_V5
*/
const TYPESCRIPT_V5: boolean =
process.env.TYPESCRIPT_VERSION?.startsWith('5') ?? true

return {
define: {
'import.meta.env.NODE_ENV': JSON.stringify(NodeEnv.TEST)
Expand Down Expand Up @@ -117,7 +126,10 @@ const config: UserConfigExport = defineConfig((): UserConfig => {
checker: 'tsc',
ignoreSourceErrors: false,
include: ['**/__tests__/*.spec-d.ts'],
tsconfig: path.resolve('tsconfig.typecheck.json')
tsconfig: path.resolve(
TYPESCRIPT_V5 ? '' : 'config/ts/v4/',
'tsconfig.typecheck.json'
)
}
}
}
Expand Down

0 comments on commit f280fcb

Please sign in to comment.