Skip to content

fix: ensure the namespace and module names do not conflict #22

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
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
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ const filenameToTypingsFilename = filename => {
const generateGenericExportInterface = (cssModuleKeys, pascalCaseFileName) => {
const interfaceName = `I${pascalCaseFileName}`;
const moduleName = `${pascalCaseFileName}Module`;
const namespaceName = `${pascalCaseFileName}Namespace`;

const interfaceProperties = cssModuleToTypescriptInterfaceProperties(
cssModuleKeys,
" "
);
return `declare namespace ${moduleName} {
return `declare namespace ${namespaceName} {
export interface I${pascalCaseFileName} {
${interfaceProperties}
}
}

declare const ${moduleName}: ${moduleName}.${interfaceName} & {
declare const ${moduleName}: ${namespaceName}.${interfaceName} & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ${moduleName}.${interfaceName};
locals: ${namespaceName}.${interfaceName};
};

export = ${moduleName};`;
Expand Down
42 changes: 21 additions & 21 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`default options 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
composed: string;
foo: string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
"
`;

exports[`localsConvention asIs 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
composed: string;
foo: string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
"
`;

exports[`localsConvention camelCase 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
barBaz: string;
Expand All @@ -46,9 +46,9 @@ exports[`localsConvention camelCase 1`] = `
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
Expand All @@ -57,70 +57,70 @@ export = ExampleCssModule;

exports[`with banner 1`] = `
"// autogenerated by typings-for-css-modules-loader
declare namespace ExampleCssModule {
declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
composed: string;
foo: string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
"
`;

exports[`with no formatter 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
'bar-baz': string;
'composed': string;
'foo': string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;"
`;

exports[`with prettier 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
composed: string;
foo: string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
"
`;

exports[`with sourcemap 1`] = `
"declare namespace ExampleCssModule {
"declare namespace ExampleCssNamespace {
export interface IExampleCss {
\\"bar-baz\\": string;
composed: string;
foo: string;
}
}

declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
locals: ExampleCssModule.IExampleCss;
locals: ExampleCssNamespace.IExampleCss;
};

export = ExampleCssModule;
Expand Down