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

fix: css/global not handle the exports name #18341

Merged
merged 3 commits into from Apr 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions declarations/WebpackOptions.d.ts
Expand Up @@ -2888,10 +2888,6 @@ export interface CssAutoParserOptions {
* Generator options for css modules.
*/
export interface CssGeneratorOptions {
/**
* Specifies the convention of exported names.
*/
exportsConvention?: CssGeneratorExportsConvention;
/**
* Avoid generating and loading a stylesheet and only embed exports from css into output javascript files.
*/
Expand Down
4 changes: 3 additions & 1 deletion lib/config/defaults.js
Expand Up @@ -553,7 +553,6 @@ const applyCssGeneratorOptionsDefaults = (
"exportsOnly",
!targetProperties || !targetProperties.document
);
D(generatorOptions, "exportsConvention", "as-is");
};

/**
Expand Down Expand Up @@ -648,20 +647,23 @@ const applyModuleDefaults = (
"localIdentName",
"[uniqueName]-[id]-[local]"
);
D(module.generator["css/auto"], "exportsConvention", "as-is");

F(module.generator, "css/module", () => ({}));
D(
module.generator["css/module"],
"localIdentName",
"[uniqueName]-[id]-[local]"
);
D(module.generator["css/module"], "exportsConvention", "as-is");

F(module.generator, "css/global", () => ({}));
D(
module.generator["css/global"],
"localIdentName",
"[uniqueName]-[id]-[local]"
);
D(module.generator["css/global"], "exportsConvention", "as-is");
}

A(module, "defaultRules", () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/css/CssExportsGenerator.js
Expand Up @@ -31,12 +31,12 @@ const TYPES = new Set(["javascript"]);

class CssExportsGenerator extends Generator {
/**
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
*/
constructor(convention, localIdentName) {
super();
/** @type {CssGeneratorExportsConvention} */
/** @type {CssGeneratorExportsConvention | undefined} */
this.convention = convention;
/** @type {CssGeneratorLocalIdentName | undefined} */
this.localIdentName = localIdentName;
Expand Down
4 changes: 2 additions & 2 deletions lib/css/CssGenerator.js
Expand Up @@ -24,12 +24,12 @@ const TYPES = new Set(["css"]);

class CssGenerator extends Generator {
/**
* @param {CssGeneratorExportsConvention} convention the convention of the exports name
* @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
* @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
*/
constructor(convention, localIdentName) {
super();
/** @type {CssGeneratorExportsConvention} */
/** @type {CssGeneratorExportsConvention | undefined} */
this.convention = convention;
/** @type {CssGeneratorLocalIdentName | undefined} */
this.localIdentName = localIdentName;
Expand Down
4 changes: 2 additions & 2 deletions lib/css/CssModulesPlugin.js
Expand Up @@ -219,12 +219,12 @@ class CssModulesPlugin {
const { namedExports } = parserOptions;

switch (type) {
case CSS_MODULE_TYPE:
case CSS_MODULE_TYPE_GLOBAL:
case CSS_MODULE_TYPE_AUTO:
return new CssParser({
namedExports
});
case CSS_MODULE_TYPE_GLOBAL:
case CSS_MODULE_TYPE:
return new CssParser({
allowModeSwitch: false,
namedExports
Expand Down
32 changes: 18 additions & 14 deletions lib/css/CssParser.js
Expand Up @@ -600,11 +600,13 @@ class CssParser extends Parser {

return newPos;
}
const { line: sl, column: sc } = locConverter.get(pos);
const { line: el, column: ec } = locConverter.get(newPos);
const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
dep.setLoc(sl, sc, el, ec);
module.addDependency(dep);
if (isLocalMode()) {
const { line: sl, column: sc } = locConverter.get(pos);
const { line: el, column: ec } = locConverter.get(newPos);
const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
dep.setLoc(sl, sc, el, ec);
module.addDependency(dep);
}
pos = newPos;
return pos + 1;
} else if (this.allowModeSwitch && name === "@property") {
Expand All @@ -630,17 +632,19 @@ class CssParser extends Parser {

return propertyNameEnd;
}
const { line: sl, column: sc } = locConverter.get(pos);
const { line: el, column: ec } = locConverter.get(propertyNameEnd);
const name = propertyName.slice(2);
const dep = new CssLocalIdentifierDependency(
name,
[propertyNameStart, propertyNameEnd],
"--"
);
dep.setLoc(sl, sc, el, ec);
module.addDependency(dep);
declaredCssVariables.add(name);
if (isLocalMode()) {
const { line: sl, column: sc } = locConverter.get(pos);
const { line: el, column: ec } = locConverter.get(propertyNameEnd);
const dep = new CssLocalIdentifierDependency(
name,
[propertyNameStart, propertyNameEnd],
"--"
);
dep.setLoc(sl, sc, el, ec);
module.addDependency(dep);
}
pos = propertyNameEnd;
return pos + 1;
} else if (
Expand Down
2 changes: 1 addition & 1 deletion lib/util/conventions.js
Expand Up @@ -9,7 +9,7 @@

/**
* @param {string} input input
* @param {CssGeneratorExportsConvention} convention convention
* @param {CssGeneratorExportsConvention | undefined} convention convention
* @returns {Set<string>} results
*/
exports.cssExportConvention = (input, convention) => {
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.check.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions schemas/WebpackOptions.json
Expand Up @@ -432,9 +432,6 @@
"type": "object",
"additionalProperties": false,
"properties": {
"exportsConvention": {
"$ref": "#/definitions/CssGeneratorExportsConvention"
},
"exportsOnly": {
"$ref": "#/definitions/CssGeneratorExportsOnly"
}
Expand Down
2 changes: 1 addition & 1 deletion schemas/plugins/css/CssGeneratorOptions.check.js

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

11 changes: 7 additions & 4 deletions test/Defaults.unittest.js
Expand Up @@ -2255,6 +2255,7 @@ describe("snapshots", () => {
+ "css": true,
+ "futureDefaults": true,
@@ ... @@
+ },
+ Object {
+ "rules": Array [
+ Object {
Expand All @@ -2272,18 +2273,18 @@ describe("snapshots", () => {
+ Object {
+ "mimetype": "application/wasm",
+ "rules": Array [
@@ ... @@
+ Object {
+ "descriptionData": Object {
+ "type": "module",
+ },
+ "resolve": Object {
+ "fullySpecified": true,
+ },
+ },
@@ ... @@
+ ],
+ "type": "webassembly/async",
+ },
+ Object {
@@ ... @@
+ "resolve": Object {
+ "fullySpecified": true,
+ "preferRelative": true,
Expand Down Expand Up @@ -2312,16 +2313,18 @@ describe("snapshots", () => {
- "generator": Object {},
+ "generator": Object {
+ "css": Object {
+ "exportsConvention": "as-is",
+ "exportsOnly": false,
+ },
+ "css/auto": Object {
+ "exportsConvention": "as-is",
+ "localIdentName": "[uniqueName]-[id]-[local]",
+ },
+ "css/global": Object {
+ "exportsConvention": "as-is",
+ "localIdentName": "[uniqueName]-[id]-[local]",
+ },
+ "css/module": Object {
+ "exportsConvention": "as-is",
+ "localIdentName": "[uniqueName]-[id]-[local]",
+ },
+ },
Expand Down
20 changes: 0 additions & 20 deletions test/__snapshots__/Cli.basictest.js.snap
Expand Up @@ -1475,26 +1475,6 @@ Object {
"multiple": false,
"simpleType": "string",
},
"module-generator-css-exports-convention": Object {
"configs": Array [
Object {
"description": "Specifies the convention of exported names.",
"multiple": false,
"path": "module.generator.css.exportsConvention",
"type": "enum",
"values": Array [
"as-is",
"camel-case",
"camel-case-only",
"dashes",
"dashes-only",
],
},
],
"description": "Specifies the convention of exported names.",
"multiple": false,
"simpleType": "string",
},
"module-generator-css-exports-only": Object {
"configs": Array [
Object {
Expand Down