Skip to content

Commit

Permalink
feat: add initial tsconfig bases
Browse files Browse the repository at this point in the history
- base, library, and library-build, same as the package exports
  - initially started with library, but if I wanted to use this repo
    for apps as well, I wouldn't want some configurations like
    declarations or declaration maps as they're unused by apps
    - so split off library and base
  - library-build doesn't add much and is for a particular use-case, so
    I also may end up removing that at some point

- NOTE: `extends` resolves relative paths based on the location of the
  _extended_ config file, not the one doing the extension
  - https://www.typescriptlang.org/tsconfig#extends
  - This effectively means that all "path-based compiler options" like
    `outDir`, `outFile`, `rootDir`, `include`, `exclude`, and `files`
    have to be repeated in all tsconfigs
    - c.f. microsoft/TypeScript#29172,
      microsoft/TypeScript#25430
    - so the usage of them here is more of as an "example" of sorts of
      what should be repeated, as installing from NPM would result in
      the paths here being _inside_ `node_modules` (or elsewhere pending
      the NPM client you use)
  • Loading branch information
agilgur5 committed May 20, 2022
1 parent 29b7792 commit 22ac082
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// https://github.com/tsconfig/bases
"extends": "@tsconfig/strictest/tsconfig.json",
// exclude node_modules (the default), dist dir, coverage dir
"exclude": ["node_modules/", "dist/", "coverage/"],
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"compilerOptions": {
// output to dist/ dir
"outDir": "dist/",
// output .js.map sourcemap files for consumers / debugging
"sourceMap": true,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
// resolve JSON files
"resolveJsonModule": true,
// transpile JSX to React.createElement
"jsx": "react",
// ignored during builds, but commonly used when type-checking with `tsc`
"noEmit": true,
},
}
14 changes: 14 additions & 0 deletions src/tsconfig.library-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// tsconfig.library.json is used for type-checking _all_ files, tsconfig.library-build.json is just used for the build
"extends": "./tsconfig.library.json",
// allowlist of files to build
"files": ["src/index.ts"],
"compilerOptions": {
// override the base
"noEmit": false,
// don't output JS files, only declarations (Rollup outputs the JS)
"emitDeclarationOnly": true,
},
// read this file as a tsconfig even though it's named slightly differently
"$schema": "https://json.schemastore.org/tsconfig",
}
13 changes: 13 additions & 0 deletions src/tsconfig.library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// small library-specific additions on top of the base
"extends": "./tsconfig.json",
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"compilerOptions": {
// output .d.ts declaration files for consumers
"declaration": true,
// output .d.ts.map declaration map files for consumers
"declarationMap": true,
},
// read this file as a tsconfig even though it's named slightly differently
"$schema": "https://json.schemastore.org/tsconfig",
}

0 comments on commit 22ac082

Please sign in to comment.