Skip to content

Commit d75f75f

Browse files
mizdraclaude
andauthored
Warn when cmkOptions.enabled is not set, and exit with error when cmkOptions.enabled is false (#290)
* wip: support warning in codegen logger * implement warning for missing `cmkOptions.enabled` * feat: exit with error when `cmkOptions.enabled` is false When css-modules-kit is disabled by configuration (`enabled: false`), the codegen now throws CMKDisabledError and exits with code 1 instead of silently proceeding. This applies to both normal and watch modes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * update documentation * add changelog * update example --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 89f11a5 commit d75f75f

25 files changed

Lines changed: 211 additions & 69 deletions

File tree

.changeset/great-weeks-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@css-modules-kit/codegen': minor
3+
---
4+
5+
feat: exit with error when `cmkOptions.enabled` is false

.changeset/silly-results-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@css-modules-kit/codegen': minor
3+
---
4+
5+
feat: warn when `cmkOptions.enabled` is not set

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ In TypeScript, the `include`/`exclude` properties specify which `*.ts` files to
127127
}
128128
```
129129

130+
### `cmkOptions.enabled`
131+
132+
Type: `boolean`, Default: `true`
133+
134+
Enables or disables css-modules-kit. When set to `false`, codegen will exit with an error. Currently, both codegen and the ts-plugin will work even if this option is omitted, but in the future, they will not work unless this option is set to `true`. For more details, see [#289](https://github.com/mizdra/css-modules-kit/issues/289).
135+
136+
```jsonc
137+
{
138+
"compilerOptions": {
139+
// ...
140+
},
141+
"cmkOptions": {
142+
"enabled": true,
143+
},
144+
}
145+
```
146+
130147
### `cmkOptions.dtsOutDir`
131148

132149
Type: `string`, Default: `"generated"`

docs/get-started.md

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,50 +47,33 @@ Configure npm-script to run `cmk` command before building and type checking. Thi
4747

4848
## Configure `tsconfig.json`
4949

50-
Finally, you need to configure your tsconfig.json so that the ts-plugin and codegen work correctly.
51-
52-
- Set the `include` option so that files like `*.module.css` are considered for type-checking:
53-
- For example: `["src"]`, `["src/**/*"]`, or omitting the `include` option (which is equivalent to `["**/*"]`)
54-
- Not recommended: `["src/**/*.ts"]`, `["src/index.ts"]`
50+
Finally, you need to configure your tsconfig.json so that css-modules-kit works correctly.
51+
52+
- Set `cmkOptions.enabled` to `true` to enable css-modules-kit.
53+
- Omit the `include` options or ensure that `*.module.css` files are included when specifying them explicitly.
54+
- ✅ Good cases:
55+
- Omit `include` (equivalent to `["**/*"]`)
56+
- Use patterns like `["src"]`, `["src/**/*"]`
57+
- ❌ Bad cases:
58+
- `["src/**/*.ts"]`
59+
- `["src/index.ts"]` (excludes `*.module.css` files)
5560
- Set the `rootDirs` option to include both the directory containing `tsconfig.json` and the `generated` directory.
5661
- Example: `[".", "generated"]`
5762

5863
Below is an example configuration:
5964

6065
```jsonc
6166
{
62-
// Omitting the `include` option is equivalent to using `["**/*"]`
6367
"compilerOptions": {
64-
/* Projects */
6568
"rootDirs": [".", "generated"],
66-
67-
/* Language and Environment */
68-
"target": "ESNext",
69-
"lib": ["ESNext"],
70-
71-
/* Modules */
72-
"module": "NodeNext",
73-
"moduleResolution": "NodeNext",
74-
75-
/* Emit */
76-
"noEmit": true,
77-
78-
/* Interop Constraints */
79-
"verbatimModuleSyntax": true,
80-
"esModuleInterop": true,
81-
"forceConsistentCasingInFileNames": true,
82-
83-
/* Type Checking */
84-
"strict": true,
85-
86-
/* Completeness */
87-
"skipLibCheck": true,
69+
// ...
70+
},
71+
"cmkOptions": {
72+
"enabled": true,
8873
},
8974
}
9075
```
9176

92-
This completes the minimal setup.
93-
9477
## Install linter plugin (Optional)
9578

9679
We provide linter plugin for CSS Modules. Currently, we support the following linters:

examples/1-basic/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"incremental": false,
1212
"rootDirs": [".", "generated"],
1313
"types": [] // Simplify tsserver.log
14+
},
15+
"cmkOptions": {
16+
"enabled": true
1417
}
1518
}

examples/2-named-exports/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"types": [] // Simplify tsserver.log
1414
},
1515
"cmkOptions": {
16+
"enabled": true,
1617
"namedExports": true
1718
}
1819
}

examples/3-import-alias/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"types": [], // Simplify tsserver.log
1414

1515
"paths": { "@/*": ["./*"] }
16+
},
17+
"cmkOptions": {
18+
"enabled": true
1619
}
1720
}

examples/4-multiple-tsconfig/tsconfig.dir-1.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"types": [], // Simplify tsserver.log
1515

1616
"paths": { "@/*": ["./*"] }
17+
},
18+
"cmkOptions": {
19+
"enabled": true
1720
}
1821
}

examples/4-multiple-tsconfig/tsconfig.dir-2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"types": [], // Simplify tsserver.log
1515

1616
"paths": { "@/*": ["./*"] }
17+
},
18+
"cmkOptions": {
19+
"enabled": true
1720
}
1821
}

examples/5-normal-css/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"incremental": false,
1212
"rootDirs": [".", "generated"],
1313
"types": [] // Simplify tsserver.log
14+
},
15+
"cmkOptions": {
16+
"enabled": true
1417
}
1518
}

0 commit comments

Comments
 (0)