Skip to content

Commit f1b0373

Browse files
authored
feat: optionally allow any additional classes (#180)
1 parent fb79442 commit f1b0373

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,56 @@ exports[`utils / cssSnapshots with a custom renderer should process a file and l
99
}
1010
`;
1111

12+
exports[`utils / cssSnapshots with allowAdditionalClasses enabled should return a dts file that allows any string value 1`] = `
13+
"declare let classes: {
14+
'localClassInsideGlobal': string;
15+
'localClass': string;
16+
'localClass2': string;
17+
'localClassInsideLocal': string;
18+
'reservedWords': string;
19+
'default': string;
20+
'const': string;
21+
'nestedClassParent': string;
22+
'childClass': string;
23+
'nestedClassParentExtended': string;
24+
'section1': string;
25+
'section2': string;
26+
'section3': string;
27+
'section4': string;
28+
'section5': string;
29+
'section6': string;
30+
'section7': string;
31+
'section8': string;
32+
'section9': string;
33+
'classWithMixin': string;
34+
'appLogo': string;
35+
'appLogo': string;
36+
[key: string]: string;
37+
};
38+
export default classes;
39+
export let localClassInsideGlobal: string;
40+
export let localClass: string;
41+
export let localClass2: string;
42+
export let localClassInsideLocal: string;
43+
export let reservedWords: string;
44+
export let nestedClassParent: string;
45+
export let childClass: string;
46+
export let nestedClassParentExtended: string;
47+
export let section1: string;
48+
export let section2: string;
49+
export let section3: string;
50+
export let section4: string;
51+
export let section5: string;
52+
export let section6: string;
53+
export let section7: string;
54+
export let section8: string;
55+
export let section9: string;
56+
export let classWithMixin: string;
57+
export let appLogo: string;
58+
export let appLogo: string;
59+
"
60+
`;
61+
1262
exports[`utils / cssSnapshots with baseUrl and paths in compilerOptions sass should find the files 1`] = `
1363
{
1464
"big-font": "tsconfig-paths-module__big-font---3FOK9",

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,33 @@ describe('utils / cssSnapshots', () => {
290290
expect(dts).toMatchSnapshot();
291291
});
292292
});
293+
294+
describe('with allowAdditionalClasses enabled', () => {
295+
const fileName = join(__dirname, 'fixtures', 'test.module.scss');
296+
const css = readFileSync(fileName, 'utf8');
297+
const options: Options = {
298+
classnameTransform: 'camelCaseOnly',
299+
allowAdditionalClasses: true,
300+
};
301+
302+
const cssExports = getCssExports({
303+
css,
304+
fileName,
305+
logger,
306+
options,
307+
processor,
308+
compilerOptions,
309+
directory: __dirname,
310+
});
311+
312+
it('should return a dts file that allows any string value', () => {
313+
const dts = createDtsExports({
314+
cssExports,
315+
fileName,
316+
logger,
317+
options,
318+
});
319+
expect(dts).toMatchSnapshot();
320+
});
321+
});
293322
});

src/helpers/createDtsExports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export const createDtsExports = ({
4242

4343
let dts = `\
4444
declare let classes: {
45-
${processedClasses.map(classNameToProperty).join('\n ')}
45+
${processedClasses.map(classNameToProperty).join('\n ')}${
46+
options.allowAdditionalClasses ? '\n [key: string]: string;' : ''
47+
}
4648
};
4749
export default classes;
4850
`;

src/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface RendererOptions {
2020
}
2121

2222
export interface Options {
23+
allowAdditionalClasses?: boolean;
2324
classnameTransform?: ClassnameTransformOptions;
2425
customMatcher?: string;
2526
customRenderer?: string;

0 commit comments

Comments
 (0)