Skip to content

Commit cc5f4c8

Browse files
mizdraclaude
andauthored
feat(core, ts-plugin, codegen)!: require cmkOptions.enabled: true to activate (#357)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b1dfcc8 commit cc5f4c8

25 files changed

+48
-40
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@css-modules-kit/core': major
3+
'@css-modules-kit/ts-plugin': major
4+
'@css-modules-kit/codegen': major
5+
---
6+
7+
feat(core, ts-plugin, codegen)!: require `cmkOptions.enabled: true` to activate
8+
9+
ts-plugin and codegen are now only enabled when `cmkOptions.enabled` is explicitly set to `true` in tsconfig.json.
10+
Previously they worked even without the option. See #289 for background.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ css-modules-kit uses `tsconfig.json` as its configuration file. This configurati
122122

123123
### `cmkOptions.enabled`
124124

125-
Type: `boolean`, Default: `true`
125+
Type: `boolean`, Default: `false`
126+
127+
Enables or disables css-modules-kit. Language features in the ts-plugin and code generation in codegen are only activated when this option is set to `true`. When set to `false` or omitted, codegen will exit with an error and ts-plugin will not provide language features.
126128

127-
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).
129+
All `cmkOptions.*` options (including this one) can be inherited via `extends` in `tsconfig.json`, so you can share settings across multiple projects by putting them in a base config.
128130

129131
```jsonc
130132
{

packages/codegen/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class CMKDisabledError extends SystemError {
2323
constructor(config: CMKConfig) {
2424
super(
2525
'CMK_DISABLED_ERROR',
26-
`css-modules-kit is disabled by configuration. Set \`"cmkOptions": { "enabled": true }\` in ${relative(config.basePath, config.configFileName)} to enable it.`,
26+
`css-modules-kit is disabled for this project. Set \`"cmkOptions": { "enabled": true }\` in ${relative(config.basePath, config.configFileName)} to enable it.`,
2727
);
2828
}
2929
}

packages/codegen/src/project.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,6 @@ describe('getDiagnostics', () => {
394394
const diagnostics = project.getDiagnostics();
395395
expect(diagnostics).toEqual([]);
396396
});
397-
test('returns warning when enabled is not specified', async () => {
398-
const iff = await createIFF({
399-
'tsconfig.json': '{}',
400-
'src/a.module.css': '.a_1 { color: red; }',
401-
});
402-
const project = createProject({ project: iff.rootDir });
403-
const diagnostics = project.getDiagnostics();
404-
expect(formatDiagnostics(diagnostics, iff.rootDir)).toMatchInlineSnapshot(`
405-
[
406-
{
407-
"category": "warning",
408-
"text": ""cmkOptions.enabled" will be required in a future version of css-modules-kit. Add \`"cmkOptions": { "enabled": true }\` to tsconfig.json. See https://github.com/mizdra/css-modules-kit/issues/289 for details.",
409-
},
410-
]
411-
`);
412-
});
413397
test('returns project diagnostics', async () => {
414398
const iff = await createIFF({
415399
'tsconfig.json': '{ "cmkOptions": { "enabled": true, "dtsOutDir": 1 } }',

packages/codegen/src/project.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
getFileNamesByPattern,
1111
parseCSSModule,
1212
readConfigFile,
13-
relative,
1413
} from '@css-modules-kit/core';
1514
import ts from 'typescript';
1615
import { writeDtsFile } from './dts-writer.js';
@@ -167,12 +166,6 @@ export function createProject(args: ProjectArgs): Project {
167166
function getProjectDiagnostics() {
168167
const diagnostics: Diagnostic[] = [];
169168
diagnostics.push(...config.diagnostics);
170-
if (config.enabled === undefined) {
171-
diagnostics.push({
172-
category: 'warning',
173-
text: `"cmkOptions.enabled" will be required in a future version of css-modules-kit. Add \`"cmkOptions": { "enabled": true }\` to ${relative(config.basePath, config.configFileName)}. See https://github.com/mizdra/css-modules-kit/issues/289 for details.`,
174-
});
175-
}
176169
if (cssModuleMap.size === 0) {
177170
diagnostics.push({
178171
category: 'error',

packages/codegen/src/runner.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('runCMK', () => {
2020
const iff = await createIFF({
2121
'tsconfig.json': dedent`
2222
{
23-
"cmkOptions": { "dtsOutDir": "generated" }
23+
"cmkOptions": { "enabled": true, "dtsOutDir": "generated" }
2424
}
2525
`,
2626
'src/a.module.css': '.a_1 { color: red; }',
@@ -101,7 +101,7 @@ describe('runCMK', () => {
101101
await expect(access(iff.join('generated/src/a.module.css.d.ts'))).resolves.not.toThrow();
102102
await expect(access(iff.join('generated/src/old.module.css.d.ts'))).rejects.toThrow();
103103
});
104-
test('throws CMKDisabledError if enabled is false', async () => {
104+
test('throws CMKDisabledError if enabled is not true', async () => {
105105
const iff = await createIFF({
106106
'tsconfig.json': '{ "cmkOptions": { "enabled": false } }',
107107
'src/a.module.css': '.a_1 { color: red; }',
@@ -122,7 +122,7 @@ describe('runCMKInWatchMode', () => {
122122
const iff = await createIFF({
123123
'tsconfig.json': dedent`
124124
{
125-
"cmkOptions": { "dtsOutDir": "generated" }
125+
"cmkOptions": { "enabled": true, "dtsOutDir": "generated" }
126126
}
127127
`,
128128
'src/a.module.css': '.a_1 { color: red; }',
@@ -313,7 +313,7 @@ describe('runCMKInWatchMode', () => {
313313
watcher = await runCMKInWatchMode(fakeParsedArgs({ project: iff.rootDir, preserveWatchOutput: true }), loggerSpy2);
314314
expect(loggerSpy2.clearScreen).toHaveBeenCalledTimes(0);
315315
});
316-
test('throws CMKDisabledError if enabled is false', async () => {
316+
test('throws CMKDisabledError if enabled is not true', async () => {
317317
const iff = await createIFF({
318318
'tsconfig.json': '{ "cmkOptions": { "enabled": false } }',
319319
'src/a.module.css': '.a_1 { color: red; }',

packages/codegen/src/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface Watcher {
3434
*/
3535
export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean> {
3636
const project = createProject(args);
37-
if (project.config.enabled === false) {
37+
if (!project.config.enabled) {
3838
throw new CMKDisabledError(project.config);
3939
}
4040
if (args.clean) {
@@ -66,7 +66,7 @@ export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean>
6666
export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promise<Watcher> {
6767
const fsWatchers: FSWatcher[] = [];
6868
const project = createProject(args);
69-
if (project.config.enabled === false) {
69+
if (!project.config.enabled) {
7070
throw new CMKDisabledError(project.config);
7171
}
7272
let emitAndReportDiagnosticsTimer: NodeJS.Timeout | undefined = undefined;

packages/core/src/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('readConfigFile', () => {
2727
namedExports: false,
2828
prioritizeNamedImports: false,
2929
keyframes: true,
30-
enabled: undefined,
30+
enabled: false,
3131
compilerOptions: expect.any(Object),
3232
wildcardDirectories: [{ fileName: iff.rootDir, recursive: true }],
3333
}),

packages/core/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const DEFAULT_INCLUDE_SPEC = '**/*';
1313
export interface CMKConfig {
1414
includes: string[];
1515
excludes: string[];
16-
enabled: boolean | undefined;
16+
enabled: boolean;
1717
dtsOutDir: string;
1818
arbitraryExtensions: boolean;
1919
namedExports: boolean;
@@ -266,7 +266,7 @@ export function readConfigFile(project: string): CMKConfig {
266266
namedExports: parsedTsConfig.config.namedExports ?? false,
267267
prioritizeNamedImports: parsedTsConfig.config.prioritizeNamedImports ?? false,
268268
keyframes: parsedTsConfig.config.keyframes ?? true,
269-
enabled: parsedTsConfig.config.enabled,
269+
enabled: parsedTsConfig.config.enabled ?? false,
270270
basePath,
271271
configFileName,
272272
compilerOptions: parsedTsConfig.compilerOptions,

packages/ts-plugin/e2e-test/feature/code-fix.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Get Code Fixes', async () => {
3535
{
3636
"compilerOptions": {},
3737
"cmkOptions": {
38+
"enabled": true,
3839
"dtsOutDir": "generated"
3940
}
4041
}

0 commit comments

Comments
 (0)