Skip to content
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

feat: supports multiple composes #1582

Merged
merged 1 commit into from
Apr 3, 2024
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ To import a local classname from another module.

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

```css
:local(.className) {
composes: edit highlight from "./edit.css", button from "module/button.css", classFromThisModule;
background: red;
}
```

or

```css
:local(.className) {
composes: edit highlight from "./edit.css";
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"dependencies": {
"icss-utils": "^5.1.0",
"postcss": "^8.4.33",
"postcss-modules-extract-imports": "^3.0.0",
"postcss-modules-extract-imports": "^3.1.0",
"postcss-modules-local-by-default": "^4.0.5",
"postcss-modules-scope": "^3.1.2",
"postcss-modules-scope": "^3.2.0",
"postcss-modules-values": "^4.0.0",
"postcss-value-parser": "^4.2.0",
"semver": "^7.5.4"
Expand Down
117 changes: 117 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21031,6 +21031,123 @@ Array [

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

exports[`"modules" option should work with multiple compose: errors 1`] = `Array []`;

exports[`"modules" option should work with multiple compose: module 1`] = `
"// Imports
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
import ___CSS_LOADER_ICSS_IMPORT_0___ from \\"-!../../../../src/index.js??ruleSet[1].rules[0].use[0]!./alias.css\\";
import ___CSS_LOADER_ICSS_IMPORT_1___ from \\"-!../../../../src/index.js??ruleSet[1].rules[0].use[0]!./alias-1.css\\";
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
___CSS_LOADER_EXPORT___.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true);
___CSS_LOADER_EXPORT___.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true);
// Module
___CSS_LOADER_EXPORT___.push([module.id, \`.RsClSIMkfTMmUvwYT4aD {
color: red;
}

.OdpZEdUc2oHF96Xqdoba {
color: blue;
}

.A3lCTIjOyIaMw91SUTt_ {
color: blue;
}

.global-class {
padding: 10px;
}

.global-class-1 {
padding: 10px;
}

.global-class-2 {
padding: 10px;
}

.BwiLdQraIwYyRAA53QEQ {
color: gainsboro;
}

.DemABT8Zz2xVnnu848uO {
}
\`, \\"\\"]);
// Exports
___CSS_LOADER_EXPORT___.locals = {
\\"other-class\\": \`RsClSIMkfTMmUvwYT4aD\`,
\\"class-1\\": \`OdpZEdUc2oHF96Xqdoba\`,
\\"class-2\\": \`A3lCTIjOyIaMw91SUTt_\`,
\\"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\`,
\\"class-other\\": \`DemABT8Zz2xVnnu848uO RsClSIMkfTMmUvwYT4aD OdpZEdUc2oHF96Xqdoba\`
};
export default ___CSS_LOADER_EXPORT___;
"
`;

exports[`"modules" option should work with multiple compose: result 1`] = `
Array [
Array [
"../../src/index.js??ruleSet[1].rules[0].use[0]!./modules/composes/alias.css",
".dnhKs1AYKq4KodZdfzcx {
display: table;
}
",
"",
],
Array [
"../../src/index.js??ruleSet[1].rules[0].use[0]!./modules/composes/alias-1.css",
".Lg5UPByIZH1XWiASCk_q {
background: red;
}

.QllkotlwlKJ4pFhiIzqP {
background: red;
}
",
"",
],
Array [
"./modules/composes/multiple.css",
".RsClSIMkfTMmUvwYT4aD {
color: red;
}

.OdpZEdUc2oHF96Xqdoba {
color: blue;
}

.A3lCTIjOyIaMw91SUTt_ {
color: blue;
}

.global-class {
padding: 10px;
}

.global-class-1 {
padding: 10px;
}

.global-class-2 {
padding: 10px;
}

.BwiLdQraIwYyRAA53QEQ {
color: gainsboro;
}

.DemABT8Zz2xVnnu848uO {
}
",
"",
],
]
`;

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

exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: errors 1`] = `Array []`;

exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: module 1`] = `
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/modules/composes/alias-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.imported-alias-2 {
background: red;
}

.imported-alias-3 {
background: red;
}
38 changes: 38 additions & 0 deletions test/fixtures/modules/composes/multiple.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.other-class {
color: red;
}

.class-1 {
color: blue;
}

.class-2 {
color: blue;
}

:global(.global-class) {
padding: 10px;
}

:global(.global-class-1) {
padding: 10px;
}

:global(.global-class-2) {
padding: 10px;
}

.class {
composes:
other-class,
class-1 class-2,
imported-alias from './alias.css',
imported-alias-2 imported-alias-3 from './alias-1.css',
global-class from global,
global-class-1 global-class-2 from global;
color: gainsboro;
}

.class-other {
composes: other-class class-1;
}
5 changes: 5 additions & 0 deletions test/fixtures/modules/composes/multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './multiple.css';

__export__ = css;

export default css;
16 changes: 16 additions & 0 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2433,4 +2433,20 @@ describe('"modules" option', () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work with multiple compose", async () => {
const compiler = getCompiler("./modules/composes/multiple.js", {
modules: true,
});
const stats = await compile(compiler);

expect(
getModuleSource("./modules/composes/multiple.css", stats)
).toMatchSnapshot("module");
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
"result"
);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});
Loading