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 <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 6, 2023
1 parent 139f6c4 commit 6c70b97
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 9 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/typescript-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: typescript-canary
on:
schedule:
# every day, 3 hours after typescript@next release
# https://github.com/microsoft/TypeScript/blob/v4.9.4/.github/workflows/nightly.yaml
# https://github.com/microsoft/TypeScript/blob/v4.9.5/.github/workflows/nightly.yaml
- cron: 0 10 * * *
workflow_dispatch:
permissions:
Expand Down Expand Up @@ -57,9 +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
run: echo $TYPESCRIPT_VERSION
- id: tsconfig
name: Prepare tsconfig.json
if: matrix.typescript-version == 'next'
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/*"]
}
54 changes: 54 additions & 0 deletions config/ts/v4/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"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": ["dom", "dom.iterable", "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": {
"#fixtures/*": ["__fixtures__/*"],
"#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 @@ -40,7 +40,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:coverage": "trash ./coverage",
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/*"]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"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
15 changes: 13 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ 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)
},
mode: NodeEnv.TEST,
plugins: [tsconfigpaths({ projects: [path.resolve('tsconfig.json')] })],
test: {
allowOnly: !ci,
Expand Down Expand Up @@ -118,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 6c70b97

Please sign in to comment.