@uxfront/typescript-config 0.1.1 → 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 +6 -0
- package/README.md +23 -11
- package/library.json +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @uxfront/typescript-config
|
|
2
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
|
+
|
|
3
9
|
## 0.1.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @uxfront/typescript-config
|
|
2
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.
|
|
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
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -57,20 +57,32 @@ Two of these are worth a second look:
|
|
|
57
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
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
59
|
|
|
60
|
-
|
|
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`:
|
|
61
74
|
|
|
62
75
|
```json
|
|
63
76
|
{
|
|
64
|
-
"extends": "@uxfront/typescript-config/
|
|
65
|
-
"compilerOptions": {
|
|
66
|
-
"noEmit": false,
|
|
67
|
-
"declaration": true,
|
|
68
|
-
"emitDeclarationOnly": true,
|
|
69
|
-
"rootDir": "src",
|
|
70
|
-
"outDir": "dist"
|
|
71
|
-
},
|
|
77
|
+
"extends": "@uxfront/typescript-config/library.json",
|
|
72
78
|
"include": ["src"]
|
|
73
79
|
}
|
|
74
80
|
```
|
|
75
81
|
|
|
76
|
-
|
|
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
|
+
}
|