Skip to content

Commit bbca614

Browse files
feat: supports multiple composes (#1582)
1 parent e022e3b commit bbca614

File tree

8 files changed

+208
-16
lines changed

8 files changed

+208
-16
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,15 @@ To import a local classname from another module.
487487

488488
To import from multiple modules use multiple `composes:` rules.
489489

490+
```css
491+
:local(.className) {
492+
composes: edit highlight from "./edit.css", button from "module/button.css", classFromThisModule;
493+
background: red;
494+
}
495+
```
496+
497+
or
498+
490499
```css
491500
:local(.className) {
492501
composes: edit highlight from "./edit.css";

package-lock.json

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"dependencies": {
5858
"icss-utils": "^5.1.0",
5959
"postcss": "^8.4.33",
60-
"postcss-modules-extract-imports": "^3.0.0",
60+
"postcss-modules-extract-imports": "^3.1.0",
6161
"postcss-modules-local-by-default": "^4.0.5",
62-
"postcss-modules-scope": "^3.1.2",
62+
"postcss-modules-scope": "^3.2.0",
6363
"postcss-modules-values": "^4.0.0",
6464
"postcss-value-parser": "^4.2.0",
6565
"semver": "^7.5.4"

test/__snapshots__/modules-option.test.js.snap

+117
Original file line numberDiff line numberDiff line change
@@ -21031,6 +21031,123 @@ Array [
2103121031

2103221032
exports[`"modules" option should work with global compose: warnings 1`] = `Array []`;
2103321033

21034+
exports[`"modules" option should work with multiple compose: errors 1`] = `Array []`;
21035+
21036+
exports[`"modules" option should work with multiple compose: module 1`] = `
21037+
"// Imports
21038+
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
21039+
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
21040+
import ___CSS_LOADER_ICSS_IMPORT_0___ from \\"-!../../../../src/index.js??ruleSet[1].rules[0].use[0]!./alias.css\\";
21041+
import ___CSS_LOADER_ICSS_IMPORT_1___ from \\"-!../../../../src/index.js??ruleSet[1].rules[0].use[0]!./alias-1.css\\";
21042+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
21043+
___CSS_LOADER_EXPORT___.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true);
21044+
___CSS_LOADER_EXPORT___.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true);
21045+
// Module
21046+
___CSS_LOADER_EXPORT___.push([module.id, \`.RsClSIMkfTMmUvwYT4aD {
21047+
color: red;
21048+
}
21049+
21050+
.OdpZEdUc2oHF96Xqdoba {
21051+
color: blue;
21052+
}
21053+
21054+
.A3lCTIjOyIaMw91SUTt_ {
21055+
color: blue;
21056+
}
21057+
21058+
.global-class {
21059+
padding: 10px;
21060+
}
21061+
21062+
.global-class-1 {
21063+
padding: 10px;
21064+
}
21065+
21066+
.global-class-2 {
21067+
padding: 10px;
21068+
}
21069+
21070+
.BwiLdQraIwYyRAA53QEQ {
21071+
color: gainsboro;
21072+
}
21073+
21074+
.DemABT8Zz2xVnnu848uO {
21075+
}
21076+
\`, \\"\\"]);
21077+
// Exports
21078+
___CSS_LOADER_EXPORT___.locals = {
21079+
\\"other-class\\": \`RsClSIMkfTMmUvwYT4aD\`,
21080+
\\"class-1\\": \`OdpZEdUc2oHF96Xqdoba\`,
21081+
\\"class-2\\": \`A3lCTIjOyIaMw91SUTt_\`,
21082+
\\"class\\": \`BwiLdQraIwYyRAA53QEQ RsClSIMkfTMmUvwYT4aD OdpZEdUc2oHF96Xqdoba A3lCTIjOyIaMw91SUTt_ \${___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"imported-alias\\"]} \${___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"imported-alias-2\\"]} \${___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"imported-alias-3\\"]} global-class global-class-1 global-class-2\`,
21083+
\\"class-other\\": \`DemABT8Zz2xVnnu848uO RsClSIMkfTMmUvwYT4aD OdpZEdUc2oHF96Xqdoba\`
21084+
};
21085+
export default ___CSS_LOADER_EXPORT___;
21086+
"
21087+
`;
21088+
21089+
exports[`"modules" option should work with multiple compose: result 1`] = `
21090+
Array [
21091+
Array [
21092+
"../../src/index.js??ruleSet[1].rules[0].use[0]!./modules/composes/alias.css",
21093+
".dnhKs1AYKq4KodZdfzcx {
21094+
display: table;
21095+
}
21096+
",
21097+
"",
21098+
],
21099+
Array [
21100+
"../../src/index.js??ruleSet[1].rules[0].use[0]!./modules/composes/alias-1.css",
21101+
".Lg5UPByIZH1XWiASCk_q {
21102+
background: red;
21103+
}
21104+
21105+
.QllkotlwlKJ4pFhiIzqP {
21106+
background: red;
21107+
}
21108+
",
21109+
"",
21110+
],
21111+
Array [
21112+
"./modules/composes/multiple.css",
21113+
".RsClSIMkfTMmUvwYT4aD {
21114+
color: red;
21115+
}
21116+
21117+
.OdpZEdUc2oHF96Xqdoba {
21118+
color: blue;
21119+
}
21120+
21121+
.A3lCTIjOyIaMw91SUTt_ {
21122+
color: blue;
21123+
}
21124+
21125+
.global-class {
21126+
padding: 10px;
21127+
}
21128+
21129+
.global-class-1 {
21130+
padding: 10px;
21131+
}
21132+
21133+
.global-class-2 {
21134+
padding: 10px;
21135+
}
21136+
21137+
.BwiLdQraIwYyRAA53QEQ {
21138+
color: gainsboro;
21139+
}
21140+
21141+
.DemABT8Zz2xVnnu848uO {
21142+
}
21143+
",
21144+
"",
21145+
],
21146+
]
21147+
`;
21148+
21149+
exports[`"modules" option should work with multiple compose: warnings 1`] = `Array []`;
21150+
2103421151
exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: errors 1`] = `Array []`;
2103521152

2103621153
exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: module 1`] = `
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.imported-alias-2 {
2+
background: red;
3+
}
4+
5+
.imported-alias-3 {
6+
background: red;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.other-class {
2+
color: red;
3+
}
4+
5+
.class-1 {
6+
color: blue;
7+
}
8+
9+
.class-2 {
10+
color: blue;
11+
}
12+
13+
:global(.global-class) {
14+
padding: 10px;
15+
}
16+
17+
:global(.global-class-1) {
18+
padding: 10px;
19+
}
20+
21+
:global(.global-class-2) {
22+
padding: 10px;
23+
}
24+
25+
.class {
26+
composes:
27+
other-class,
28+
class-1 class-2,
29+
imported-alias from './alias.css',
30+
imported-alias-2 imported-alias-3 from './alias-1.css',
31+
global-class from global,
32+
global-class-1 global-class-2 from global;
33+
color: gainsboro;
34+
}
35+
36+
.class-other {
37+
composes: other-class class-1;
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './multiple.css';
2+
3+
__export__ = css;
4+
5+
export default css;

test/modules-option.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -2433,4 +2433,20 @@ describe('"modules" option', () => {
24332433
expect(getWarnings(stats)).toMatchSnapshot("warnings");
24342434
expect(getErrors(stats)).toMatchSnapshot("errors");
24352435
});
2436+
2437+
it("should work with multiple compose", async () => {
2438+
const compiler = getCompiler("./modules/composes/multiple.js", {
2439+
modules: true,
2440+
});
2441+
const stats = await compile(compiler);
2442+
2443+
expect(
2444+
getModuleSource("./modules/composes/multiple.css", stats)
2445+
).toMatchSnapshot("module");
2446+
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
2447+
"result"
2448+
);
2449+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
2450+
expect(getErrors(stats)).toMatchSnapshot("errors");
2451+
});
24362452
});

0 commit comments

Comments
 (0)