Skip to content

Commit a8fe7ee

Browse files
authored
Merge pull request TeamSupercell#22 from raphael-leger/fix/namespace-and-module-name-conflict
fix: ensure the namespace and module names do not conflict
2 parents 09f7afd + 780649e commit a8fe7ee

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ const filenameToTypingsFilename = filename => {
5050
const generateGenericExportInterface = (cssModuleKeys, pascalCaseFileName) => {
5151
const interfaceName = `I${pascalCaseFileName}`;
5252
const moduleName = `${pascalCaseFileName}Module`;
53+
const namespaceName = `${pascalCaseFileName}Namespace`;
5354

5455
const interfaceProperties = cssModuleToTypescriptInterfaceProperties(
5556
cssModuleKeys,
5657
" "
5758
);
58-
return `declare namespace ${moduleName} {
59+
return `declare namespace ${namespaceName} {
5960
export interface I${pascalCaseFileName} {
6061
${interfaceProperties}
6162
}
6263
}
6364
64-
declare const ${moduleName}: ${moduleName}.${interfaceName} & {
65+
declare const ${moduleName}: ${namespaceName}.${interfaceName} & {
6566
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
66-
locals: ${moduleName}.${interfaceName};
67+
locals: ${namespaceName}.${interfaceName};
6768
};
6869
6970
export = ${moduleName};`;

test/__snapshots__/index.test.js.snap

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`default options 1`] = `
4-
"declare namespace ExampleCssModule {
4+
"declare namespace ExampleCssNamespace {
55
export interface IExampleCss {
66
\\"bar-baz\\": string;
77
composed: string;
88
foo: string;
99
}
1010
}
1111
12-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
12+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
1313
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
14-
locals: ExampleCssModule.IExampleCss;
14+
locals: ExampleCssNamespace.IExampleCss;
1515
};
1616
1717
export = ExampleCssModule;
1818
"
1919
`;
2020

2121
exports[`localsConvention asIs 1`] = `
22-
"declare namespace ExampleCssModule {
22+
"declare namespace ExampleCssNamespace {
2323
export interface IExampleCss {
2424
\\"bar-baz\\": string;
2525
composed: string;
2626
foo: string;
2727
}
2828
}
2929
30-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
30+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
3131
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
32-
locals: ExampleCssModule.IExampleCss;
32+
locals: ExampleCssNamespace.IExampleCss;
3333
};
3434
3535
export = ExampleCssModule;
3636
"
3737
`;
3838

3939
exports[`localsConvention camelCase 1`] = `
40-
"declare namespace ExampleCssModule {
40+
"declare namespace ExampleCssNamespace {
4141
export interface IExampleCss {
4242
\\"bar-baz\\": string;
4343
barBaz: string;
@@ -46,9 +46,9 @@ exports[`localsConvention camelCase 1`] = `
4646
}
4747
}
4848
49-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
49+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
5050
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
51-
locals: ExampleCssModule.IExampleCss;
51+
locals: ExampleCssNamespace.IExampleCss;
5252
};
5353
5454
export = ExampleCssModule;
@@ -57,70 +57,70 @@ export = ExampleCssModule;
5757

5858
exports[`with banner 1`] = `
5959
"// autogenerated by typings-for-css-modules-loader
60-
declare namespace ExampleCssModule {
60+
declare namespace ExampleCssNamespace {
6161
export interface IExampleCss {
6262
\\"bar-baz\\": string;
6363
composed: string;
6464
foo: string;
6565
}
6666
}
6767
68-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
68+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
6969
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
70-
locals: ExampleCssModule.IExampleCss;
70+
locals: ExampleCssNamespace.IExampleCss;
7171
};
7272
7373
export = ExampleCssModule;
7474
"
7575
`;
7676

7777
exports[`with no formatter 1`] = `
78-
"declare namespace ExampleCssModule {
78+
"declare namespace ExampleCssNamespace {
7979
export interface IExampleCss {
8080
'bar-baz': string;
8181
'composed': string;
8282
'foo': string;
8383
}
8484
}
8585
86-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
86+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
8787
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
88-
locals: ExampleCssModule.IExampleCss;
88+
locals: ExampleCssNamespace.IExampleCss;
8989
};
9090
9191
export = ExampleCssModule;"
9292
`;
9393

9494
exports[`with prettier 1`] = `
95-
"declare namespace ExampleCssModule {
95+
"declare namespace ExampleCssNamespace {
9696
export interface IExampleCss {
9797
\\"bar-baz\\": string;
9898
composed: string;
9999
foo: string;
100100
}
101101
}
102102
103-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
103+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
104104
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
105-
locals: ExampleCssModule.IExampleCss;
105+
locals: ExampleCssNamespace.IExampleCss;
106106
};
107107
108108
export = ExampleCssModule;
109109
"
110110
`;
111111

112112
exports[`with sourcemap 1`] = `
113-
"declare namespace ExampleCssModule {
113+
"declare namespace ExampleCssNamespace {
114114
export interface IExampleCss {
115115
\\"bar-baz\\": string;
116116
composed: string;
117117
foo: string;
118118
}
119119
}
120120
121-
declare const ExampleCssModule: ExampleCssModule.IExampleCss & {
121+
declare const ExampleCssModule: ExampleCssNamespace.IExampleCss & {
122122
/** WARNING: Only available when \`css-loader\` is used without \`style-loader\` or \`mini-css-extract-plugin\` */
123-
locals: ExampleCssModule.IExampleCss;
123+
locals: ExampleCssNamespace.IExampleCss;
124124
};
125125
126126
export = ExampleCssModule;

0 commit comments

Comments
 (0)