@codecompose/typescript-config 2.1.0-0 → 2.1.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/README.md CHANGED
@@ -1,22 +1,17 @@
1
1
  # typescript-config
2
2
 
3
- Opinionated reusable Typescript configurations. Out-of-the-box we assume:
3
+ Opinionated and reusable Typescript configurations, geared towards modern build tooling in both monorepos and single repositories.
4
4
 
5
- - You transpile using a bundler
6
- - You want strict rules
7
- - Use of `src` and `dist` directories
8
- - Use of `~/` as path alias for `src`
5
+ - Only use Typescript for type-checking and incremental builds (but no emit).
6
+ - Use your bundler to output code, source-maps and type declarations where needed.
7
+ - Use strict settings, incl `noUncheckedIndexedAccess` and `erasableSyntaxOnly`.
8
+ - Assume `src` and `dist` directories
9
+ - Use of `~/` or `@/` as path alias for `src`
10
+ - Leverages TS 5.5 feature `${configDir}` to remove all client configuration.
9
11
 
10
- Of course, you can still choose to override any of the defaults in your own
11
- config.
12
12
 
13
- ## Structure
13
+ To use this successfully, you would need a modern bundler like [tsdown](https://tsdown.dev/). You can check out the [mono-ts](https://github.com/0x80/mono-ts) boilerplate for a working example of a modern monorepo setup with tsdown.
14
14
 
15
- Configurations are organized based on their intended use:
16
-
17
- - **Root configurations**: For stand-alone projects or general use
18
- - **Monorepo configurations**: Under the `/monorepo` path for monorepo-specific
19
- setups
20
15
 
21
16
  ## Install
22
17
 
@@ -30,38 +25,27 @@ Configurations are organized based on their intended use:
30
25
  }
31
26
  ```
32
27
 
33
- ## Available Configurations
34
-
35
- ### Base Configuration
36
-
37
- - `base` - Base configuration with common settings
28
+ Often no other configuration is needed besides extends.
38
29
 
39
- ### Stand-alone Configurations
40
-
41
- - `base` - For anything non-specific
42
- - `library` - For general libraries
43
- - `react-library` - For React component libraries
44
- - `nextjs` - For Next.js applications
45
- - `service` - For a backend service like and API server or cloud function
30
+ ## Available Configurations
46
31
 
47
- ### Monorepo Configurations
32
+ - `base` - Anything non-specific
33
+ - `library` - Standalone libraries (not part of a monorepo)
34
+ - `shared-library` - Shared libraries in a monorepo
35
+ - `react-library` - Standalone React component libraries (not part of a monorepo)
36
+ - `shared-react-library` - Shared React component libraries in a monorepo
37
+ - `nextjs` - Next.js applications
38
+ - `service` - A backend service like and API server or cloud function
48
39
 
49
- When using a monorepo, the packages that other packages depend on should use the
50
- "shared" variant.
51
40
 
52
- - `shared-library` - For shared libraries in a monorepo
53
- - `shared-react-library` - For shared React component libraries in a monorepo
41
+ For other project types, like a CLI or E2E app, you can use the `base` configuration.
54
42
 
55
- The `nextjs` and `service` configs are compatible with both monorepo and
56
- non-monorepo.
43
+ ## Assuming Bundler Output
57
44
 
58
- For other project types, like a CLI or E2E app, you can use the `base`
59
- configuration.
45
+ Output like source maps, and type declarations is disabled, because it is assumed that your bundler will handle that.
60
46
 
61
- ## Assumptions and Recommendations
62
47
 
63
- Source maps are not enabled, because we assume that your bundler will handle
64
- that.
48
+ ## Incremental Builds
65
49
 
66
50
  All configurations have `incremental` set to `true`. In my experience, it can
67
51
  happen that builds get stuck in limbo and you need to delete the
@@ -70,13 +54,25 @@ recommend adding the following script to your manifest based on `del-cli`:
70
54
 
71
55
  `"clean": "del-cli dist tsconfig.tsbuildinfo"`
72
56
 
73
- ## Known Issues
57
+ ## Project References
58
+
59
+ The shared-library and shared-react-library configurations have `composite` set to `true`. This is required for Typescript "project references" to work in a monorepo. They provide IDE go-to-definition, without having to emit the module output.
60
+
61
+ In practice, this means that if you alter code in a shared package, the consuming app or library will pick up the changes, without requiring a watch task on the shared package to trigger a rebuild on every change.
62
+
63
+ Without project references, the consuming code would only see the `dist` output of the shared package.
64
+
65
+ If you prefer to work without project references, you should set your bundler to also [output declaration maps](https://tsdown.dev/options/dts#declaration-map), but not all bundlers can do this.
66
+
67
+ ## Publishing to NPM
68
+
69
+ If you publish your package, it is recommended to include the Typescript source and type declaration maps. This allows the consumer to jump straight to the original source code, which is nice for readability and learning.
70
+
71
+ To export source files next to your dist output, you define the `files` field in your package.json as `["src", "dist"]`.
72
+
73
+ ## Caveats
74
+
75
+ Older tooling might not correctly interpret the use of `${configDir}` introduced in TS v5.5 that this package depends on.
74
76
 
75
- At the time of writing, not all tooling correctly interprets the use of
76
- `${configDir}` introduced in TS v5.5 that this package depends on.
77
+ Next.js v15 seems to require you to explicitly define "includes". If you give it just "src" it will inject its own types on startup. I assume this will improve in the future.
77
78
 
78
- - Next.js will require you to explicitly defined "includes". Give it "src" and
79
- it will inject its types on startup.
80
- - TSUP will not understand the tsconfig if you ask it to generate type
81
- definitions. I use tsc to generate the types, as demonstrated in
82
- [mono-ts](https://github.com/0x80/mono-ts).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecompose/typescript-config",
3
3
  "description": "Opinionated reusable TypeScript configurations",
4
- "version": "2.1.0-0",
4
+ "version": "2.1.0",
5
5
  "license": "MIT",
6
6
  "author": "Thijs Koerselman",
7
7
  "publishConfig": {
@@ -10,14 +10,14 @@
10
10
  "keywords": [
11
11
  "typescript",
12
12
  "config",
13
- "configuration",
14
13
  "monorepo",
15
14
  "strict",
16
15
  "reusable",
17
16
  "nextjs",
18
17
  "react",
19
18
  "library",
20
- "service"
19
+ "service",
20
+ "bundler"
21
21
  ],
22
22
  "files": [
23
23
  "src"
package/src/base.json CHANGED
@@ -17,10 +17,8 @@
17
17
  "strict": true,
18
18
  "noUncheckedIndexedAccess": true,
19
19
  "noImplicitOverride": true,
20
+ "erasableSyntaxOnly": true,
20
21
 
21
- /* Assuming bundler will output EVERYTHING. You'll need a modern bundler
22
- like tsdown to output declarationMaps for shared monorepo libraries. */
23
- "noEmit": true,
24
22
  /* Opinion */
25
23
  "incremental": true,
26
24
  "tsBuildInfoFile": "${configDir}/tsconfig.tsbuildinfo",
package/src/library.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
- "display": "Standalone shared library",
3
+ "display": "Standalone library (not part of a monorepo)",
4
4
  "extends": "./base.json",
5
5
  "compilerOptions": {
6
- /* Assuming your bundler will output declaration and declarationMap */
6
+ /* Assuming your bundler will output everything. */
7
+ "noEmit": true,
7
8
  }
8
9
  }
package/src/nextjs.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "compilerOptions": {
6
6
  "jsx": "preserve", // next does its own jsx transformation
7
7
  "lib": ["dom", "dom.iterable", "esnext"],
8
+ "noEmit": true, // nextjs bundler will output everything
8
9
  "rootDir": "${configDir}", // nextjs targets files outside of src in root as well
9
10
  "plugins": [
10
11
  {
@@ -4,6 +4,8 @@
4
4
  "extends": "./base.json",
5
5
  "compilerOptions": {
6
6
  "lib": ["dom", "dom.iterable", "esnext"],
7
- "jsx": "react-jsx"
7
+ "jsx": "react-jsx",
8
+ /* Assuming your bundler will output everything. */
9
+ "noEmit": true
8
10
  }
9
11
  }
package/src/service.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
- "display": "Backend service",
3
+ "display": "Backend service / app",
4
4
  "extends": "./base.json",
5
- "compilerOptions": {}
5
+ "compilerOptions": {
6
+ /* Assuming your bundler will output everything. */
7
+ "noEmit": true,
8
+ }
6
9
  }
@@ -3,8 +3,10 @@
3
3
  "display": "Monorepo shared library",
4
4
  "extends": "./library.json",
5
5
  "compilerOptions": {
6
- /* Required for project references, which provide go-to-definition in your IDE without first having to build the module, which is essential during development. */
6
+ /* Required for project references, which provide go-to-definition in your
7
+ IDE without first having to build the module, which is essential during development. */
7
8
  "composite": true
8
- /* Assuming your bundler will output type declarations and declaration-maps */
9
+ /* Assuming your bundler will output everything, but we can not have noEmit
10
+ enabled because it is not compatible with composite / project references */
9
11
  }
10
12
  }
@@ -3,8 +3,10 @@
3
3
  "display": "Monorepo shared React component library",
4
4
  "extends": "./react-library.json",
5
5
  "compilerOptions": {
6
- /* Required for project references, which provide go-to-definition in your IDE without first having to build the module, which is essential during development. */
6
+ /* Required for project references, which provide go-to-definition in your
7
+ IDE without first having to build the module, which is essential during development. */
7
8
  "composite": true
8
- /* Assuming your bundler will output type declarations and declaration-maps */
9
+ /* Assuming your bundler will output everything, but we can not have noEmit
10
+ enabled because it is not compatible with composite / project references */
9
11
  }
10
12
  }