@uxfront/typescript-config 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +88 -0
- package/library.json +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @uxfront/typescript-config
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a1bf5e6: Add `library.json`, a variant for packages that ship declaration files. Until now, a library that wanted `tsc` to write its `.d.ts` files had to copy the shared config or turn emit back on by hand. Extend `@uxfront/typescript-config/library.json` instead: it keeps every option of `tsconfig.json` and sets `noEmit` to `false`, `declaration` and `composite` to `true`, and `outDir` to `${configDir}/dist`, so the output lands in your own project's `dist` (TypeScript 5.5 or later). It also excludes `${configDir}/node_modules` and `${configDir}/dist`, so a second build doesn't read the first one's output as input.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5bf4d27: Widen the peer ranges to the tool versions the configs work with: `@uxfront/oxfmt-config` now peers on oxfmt `>=0.70.0 <1`, and `@uxfront/oxlint-config` on oxlint `^1.45.0`. Before, the oxfmt peer stopped at 0.70 and the oxlint peer started at 1.85, so a project on a later oxfmt 0.x or an earlier oxlint 1.x got a peer warning and needed an override. `@uxfront/typescript-config` now has a README that lists what it sets and how to extend it.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @uxfront/typescript-config
|
|
2
|
+
|
|
3
|
+
Shared TypeScript configuration for uxfront projects. It type-checks strictly and leaves the output to your bundler, so every project that extends it catches the same mistakes and compiles the same way. For a library that ships its own declaration files, [`library.json`](#library-variant) turns emit back on.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D typescript @uxfront/typescript-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Create a `tsconfig.json` that extends the shared config and lists your own files:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"extends": "@uxfront/typescript-config/tsconfig.json",
|
|
18
|
+
"include": ["src"]
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Keep the `include`: TypeScript resolves an extended config's `include` from the folder that config lives in, so without your own it looks for files inside `node_modules/@uxfront/typescript-config` and stops with `TS18003: No inputs were found`. Override any option under `compilerOptions` in the same file.
|
|
23
|
+
|
|
24
|
+
## What it sets
|
|
25
|
+
|
|
26
|
+
Let's start with strictness, which is where you'll notice the config most:
|
|
27
|
+
|
|
28
|
+
| Option | Value | What it does for you |
|
|
29
|
+
| -------------------------- | ------ | --------------------------------------------------------------------------------------- |
|
|
30
|
+
| `strict` | `true` | Turns on every strict check, like `strictNullChecks` and `noImplicitAny` |
|
|
31
|
+
| `noUncheckedIndexedAccess` | `true` | Types `items[0]` and `record[key]` as possibly `undefined`, so you check before you use |
|
|
32
|
+
| `noImplicitOverride` | `true` | Asks for `override` on a method that replaces one from its base class |
|
|
33
|
+
|
|
34
|
+
Modules are written the way a bundler reads them:
|
|
35
|
+
|
|
36
|
+
| Option | Value | What it does for you |
|
|
37
|
+
| ---------------------- | ------------ | --------------------------------------------------------------------------------------- |
|
|
38
|
+
| `module` | `"preserve"` | Keeps `import` and `export` as you wrote them, and resolves imports the way bundlers do |
|
|
39
|
+
| `verbatimModuleSyntax` | `true` | Asks for `import type` on an import that only brings in types |
|
|
40
|
+
| `isolatedModules` | `true` | Flags code that a tool compiling one file at a time can't compile |
|
|
41
|
+
| `moduleDetection` | `"force"` | Treats every file as a module, even one without `import` or `export` |
|
|
42
|
+
| `esModuleInterop` | `true` | Lets you default-import a CommonJS package |
|
|
43
|
+
| `resolveJsonModule` | `true` | Lets you import a `.json` file, typed from its contents |
|
|
44
|
+
| `allowJs` | `true` | Includes `.js` files in the project |
|
|
45
|
+
|
|
46
|
+
And the target and output:
|
|
47
|
+
|
|
48
|
+
| Option | Value | What it does for you |
|
|
49
|
+
| -------------- | ----------------------------------- | -------------------------------------------------------------------- |
|
|
50
|
+
| `target` | `"es2022"` | Leaves ES2022 syntax, like class fields and top-level `await`, as is |
|
|
51
|
+
| `lib` | `["es2022", "dom", "dom.iterable"]` | Types the ES2022 built-ins and the browser DOM |
|
|
52
|
+
| `noEmit` | `true` | Type-checks only and writes no files |
|
|
53
|
+
| `skipLibCheck` | `true` | Skips type-checking the `.d.ts` files of your dependencies |
|
|
54
|
+
|
|
55
|
+
Two of these are worth a second look:
|
|
56
|
+
|
|
57
|
+
- **`verbatimModuleSyntax`** fails the type-check on `import { Foo } from "./types"` when `Foo` is only a type, with `TS1484`. Write `import type { Foo } from "./types"` instead. [`@uxfront/oxlint-config`](../oxlint-config) has the matching `typescript/consistent-type-imports` rule, so your editor flags it as you type.
|
|
58
|
+
- **`noEmit`** means `tsc` never writes files. A bundler like Vite or a library builder like tsdown compiles your code, and `tsc` only checks it.
|
|
59
|
+
|
|
60
|
+
For a library that ships its own declaration files, extend the [library variant](#library-variant) instead, which turns emit back on.
|
|
61
|
+
|
|
62
|
+
## Library variant
|
|
63
|
+
|
|
64
|
+
Let's look at `library.json`, for a package that ships declaration files, like one that `tsc` builds or one that a bundler builds and `tsc` describes. It extends `tsconfig.json`, so you keep every check above, and sets four compiler options:
|
|
65
|
+
|
|
66
|
+
| Option | Value | What it does for you |
|
|
67
|
+
| ------------- | --------------------- | ------------------------------------------------------------------------------------------ |
|
|
68
|
+
| `noEmit` | `false` | Lets `tsc` write files again |
|
|
69
|
+
| `declaration` | `true` | Writes a `.d.ts` file for each source file |
|
|
70
|
+
| `composite` | `true` | Lets other projects point at this one through `references`, and rebuilds only what changed |
|
|
71
|
+
| `outDir` | `"${configDir}/dist"` | Writes the output to your own project's `dist` folder |
|
|
72
|
+
|
|
73
|
+
Extend it the same way, with your own `include`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"extends": "@uxfront/typescript-config/library.json",
|
|
78
|
+
"include": ["src"]
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Running `tsc -p .` then writes `dist/src/index.js`, `dist/src/index.d.ts` and `dist/tsconfig.tsbuildinfo`. The variant sets no `rootDir`, so your `include` can also cover files beside `src`, like `vite.config.ts`, and the output keeps the `src` folder. For `dist/index.js`, add `"rootDir": "src"` under `compilerOptions`, and add `tsconfig.tsbuildinfo` to your `.gitignore`, since TypeScript then writes it beside your `tsconfig.json`. To leave the JavaScript to your bundler, add `"emitDeclarationOnly": true`.
|
|
83
|
+
|
|
84
|
+
A few things are worth knowing before your first build:
|
|
85
|
+
|
|
86
|
+
- **`outDir` is your project's `dist`.** `${configDir}` stands for the folder of your own `tsconfig.json`. A plain `"dist"` would resolve next to `library.json`, inside `node_modules`. `${configDir}` needs TypeScript 5.5 or later.
|
|
87
|
+
- **`composite` needs every file in your `include`.** It writes a `.tsbuildinfo` file, so the next build only redoes what changed. A file that's imported but not in `include` stops the build with `TS6307`.
|
|
88
|
+
- **It excludes your `node_modules` and `dist`.** That way a second build doesn't read the first one's output as input, which stops it with `TS5055: Cannot write file … because it would overwrite input file`. Your own `exclude` replaces this one, so if you set one, keep `"${configDir}/dist"` in it.
|
package/library.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "./tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"noEmit": false,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"composite": true,
|
|
8
|
+
"outDir": "${configDir}/dist"
|
|
9
|
+
},
|
|
10
|
+
"exclude": ["${configDir}/node_modules", "${configDir}/dist"]
|
|
11
|
+
}
|