Skip to content

feat: optionally allow any additional classes #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,56 @@ exports[`utils / cssSnapshots with a custom renderer should process a file and l
}
`;

exports[`utils / cssSnapshots with allowAdditionalClasses enabled should return a dts file that allows any string value 1`] = `
"declare let classes: {
'localClassInsideGlobal': string;
'localClass': string;
'localClass2': string;
'localClassInsideLocal': string;
'reservedWords': string;
'default': string;
'const': string;
'nestedClassParent': string;
'childClass': string;
'nestedClassParentExtended': string;
'section1': string;
'section2': string;
'section3': string;
'section4': string;
'section5': string;
'section6': string;
'section7': string;
'section8': string;
'section9': string;
'classWithMixin': string;
'appLogo': string;
'appLogo': string;
[key: string]: string;
};
export default classes;
export let localClassInsideGlobal: string;
export let localClass: string;
export let localClass2: string;
export let localClassInsideLocal: string;
export let reservedWords: string;
export let nestedClassParent: string;
export let childClass: string;
export let nestedClassParentExtended: string;
export let section1: string;
export let section2: string;
export let section3: string;
export let section4: string;
export let section5: string;
export let section6: string;
export let section7: string;
export let section8: string;
export let section9: string;
export let classWithMixin: string;
export let appLogo: string;
export let appLogo: string;
"
`;

exports[`utils / cssSnapshots with baseUrl and paths in compilerOptions sass should find the files 1`] = `
{
"big-font": "tsconfig-paths-module__big-font---3FOK9",
Expand Down
29 changes: 29 additions & 0 deletions src/helpers/__tests__/getDtsSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,33 @@ describe('utils / cssSnapshots', () => {
expect(dts).toMatchSnapshot();
});
});

describe('with allowAdditionalClasses enabled', () => {
const fileName = join(__dirname, 'fixtures', 'test.module.scss');
const css = readFileSync(fileName, 'utf8');
const options: Options = {
classnameTransform: 'camelCaseOnly',
allowAdditionalClasses: true,
};

const cssExports = getCssExports({
css,
fileName,
logger,
options,
processor,
compilerOptions,
directory: __dirname,
});

it('should return a dts file that allows any string value', () => {
const dts = createDtsExports({
cssExports,
fileName,
logger,
options,
});
expect(dts).toMatchSnapshot();
});
});
});
4 changes: 3 additions & 1 deletion src/helpers/createDtsExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export const createDtsExports = ({

let dts = `\
declare let classes: {
${processedClasses.map(classNameToProperty).join('\n ')}
${processedClasses.map(classNameToProperty).join('\n ')}${
options.allowAdditionalClasses ? '\n [key: string]: string;' : ''
}
};
export default classes;
`;
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RendererOptions {
}

export interface Options {
allowAdditionalClasses?: boolean;
classnameTransform?: ClassnameTransformOptions;
customMatcher?: string;
customRenderer?: string;
Expand Down