Skip to content

Commit

Permalink
chore: better ts-config
Browse files Browse the repository at this point in the history
Previously we had a separate ts-config for tests. This was because we don't want test code to be emitted to lib.

This however caused issues with WebStorm, at least for me, because the IDE was not capable of correctly tracking two ts-configs live.

The fix is to use one ts-config for the whole projects (including tests), but then have a separate ts-config just for building, which extends the first one, but excludes tests.

Inspired by: https://stackoverflow.com/a/60223923
  • Loading branch information
ComradeVanti committed Dec 28, 2023
1 parent 2ea42f0 commit deec70c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"scripts": {
"test": "cross-env NODE_ENV=test ts-mocha test/**/*.ts",
"clean": "rimraf lib",
"build": "npm run clean && tsc -p tsconfig.json",
"build:watch": "tsc -w -p tsconfig.json",
"build": "npm run clean && tsc -p tsconfig.build.json",
"build:watch": "tsc -w -p tsconfig.build.json",
"semantic-release": "semantic-release"
},
"bin": {
Expand Down
16 changes: 9 additions & 7 deletions test/tsconfig.json → tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

Expand Down Expand Up @@ -32,7 +32,7 @@
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "typeRoots": [] /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
Expand All @@ -53,12 +53,12 @@
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": false, /* Create source map files for emitted JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./lib", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
"noEmit": true /* Disable emitting files from a compilation. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
Expand All @@ -83,7 +83,7 @@
// "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

/* Type Checking */
//"strict": true, /* Enable all strict type-checking options. */
// "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
Expand All @@ -105,7 +105,9 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
// "skipLibCheck": true /* Skip type checking all .d.ts files. */
// "skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["./**/*"]
"exclude": [
"./test/**/*"
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": [
"./src/**/*"
"./src/**/*",
"./test/**/*"
]
}

0 comments on commit deec70c

Please sign in to comment.