@uxfront/typescript-config 0.1.1 → 0.2.1

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @uxfront/typescript-config
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ab39625: Indent the source files with tabs, to follow `@uxfront/oxfmt-config`. Only whitespace changes, so nothing behaves differently, and code blocks in the READMEs indent with tabs too.
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 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.
14
+
3
15
  ## 0.1.1
4
16
 
5
17
  ### 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
 
@@ -14,8 +14,8 @@ Create a `tsconfig.json` that extends the shared config and lists your own files
14
14
 
15
15
  ```json
16
16
  {
17
- "extends": "@uxfront/typescript-config/tsconfig.json",
18
- "include": ["src"]
17
+ "extends": "@uxfront/typescript-config/tsconfig.json",
18
+ "include": ["src"]
19
19
  }
20
20
  ```
21
21
 
@@ -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
- If you want `tsc` to write the declaration files for a library, turn emit back on for declarations only:
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/tsconfig.json",
65
- "compilerOptions": {
66
- "noEmit": false,
67
- "declaration": true,
68
- "emitDeclarationOnly": true,
69
- "rootDir": "src",
70
- "outDir": "dist"
71
- },
72
- "include": ["src"]
77
+ "extends": "@uxfront/typescript-config/library.json",
78
+ "include": ["src"]
73
79
  }
74
80
  ```
75
81
 
76
- This writes a `.d.ts` file to `dist` for each file in `src`, and no JavaScript. Setting `noEmit` to `false` on its own writes a `.js` file beside each source file and no declarations.
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxfront/typescript-config",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "publishConfig": {
package/tsconfig.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- "esModuleInterop": true,
5
- "skipLibCheck": true,
6
- "target": "es2022",
7
- "allowJs": true,
8
- "resolveJsonModule": true,
9
- "moduleDetection": "force",
10
- "isolatedModules": true,
11
- "verbatimModuleSyntax": true,
12
- "strict": true,
13
- "noUncheckedIndexedAccess": true,
14
- "noImplicitOverride": true,
15
- "module": "preserve",
16
- "noEmit": true,
17
- "lib": ["es2022", "dom", "dom.iterable"]
18
- },
19
- "include": ["**/*.ts", "**/*.tsx"],
20
- "exclude": ["node_modules"]
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "esModuleInterop": true,
5
+ "skipLibCheck": true,
6
+ "target": "es2022",
7
+ "allowJs": true,
8
+ "resolveJsonModule": true,
9
+ "moduleDetection": "force",
10
+ "isolatedModules": true,
11
+ "verbatimModuleSyntax": true,
12
+ "strict": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ "noImplicitOverride": true,
15
+ "module": "preserve",
16
+ "noEmit": true,
17
+ "lib": ["es2022", "dom", "dom.iterable"]
18
+ },
19
+ "include": ["**/*.ts", "**/*.tsx"],
20
+ "exclude": ["node_modules"]
21
21
  }