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: resolve style fields in package json #17346

Merged
merged 29 commits into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
11 changes: 10 additions & 1 deletion lib/config/defaults.js
Expand Up @@ -1435,6 +1435,14 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
extensions: [...jsExtensions]
});

/** @type {function(): ResolveOptions} */
const styleDeps = () => ({
conditionNames: ["style"],
mainFields: ["style", "main", "..."],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need the main here, because it already in list, please try to remove it from here and test it

mainFiles: ["index", "..."],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need it here, becaue it will resolve index.css when you have @import "./directory", it was in css-loader only for legacy purposes, we don't need to put it here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need a test case here too

extensions: [".css", "..."]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about [".css", "..."], because it will allow to use @import url("file.js");, it is wrong, so we need to add test cases, also please add testcases on each property here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on it

const jsExtensions = [".js", ".json", ".wasm"];
, there is only css should be

});

/** @type {ResolveOptions} */
const resolveOptions = {
cache,
Expand Down Expand Up @@ -1464,7 +1472,8 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
// for backward-compat: Custom Dependency
unknown: cjsDeps(),
// for backward-compat: getResolve without dependencyType
undefined: cjsDeps()
undefined: cjsDeps(),
"css-import": styleDeps()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think rename it to just css, we need to replace it in dependency from css-import to css, I think it has more sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS is already a module type. Wont that cause a collision?
https://github.com/webpack/webpack/blob/main/lib/css/CssModulesPlugin.js#L632

After renaming css-import to css in ExternalModule and CSSModule, the snapshots are failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not because, it is just a dependecy type

}
};

Expand Down
18 changes: 18 additions & 0 deletions test/Defaults.unittest.js
Expand Up @@ -430,6 +430,24 @@ describe("snapshots", () => {
"...",
],
},
"css-import": Object {
"conditionNames": Array [
"style",
],
"extensions": Array [
".css",
"...",
],
"mainFields": Array [
"style",
"main",
"...",
],
"mainFiles": Array [
"index",
"...",
],
},
"esm": Object {
"aliasFields": Array [
"browser",
Expand Down
15 changes: 14 additions & 1 deletion test/__snapshots__/ConfigCacheTestCases.longtest.js.snap

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion test/__snapshots__/ConfigTestCases.basictest.js.snap

Large diffs are not rendered by default.

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

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

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

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

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

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

3 changes: 3 additions & 0 deletions test/configCases/css/css-import/style-import.css
@@ -0,0 +1,3 @@
@import "style-library";
@import "main-field";
@import "package-with-exports";
1 change: 1 addition & 0 deletions test/configCases/css/css-import/style.css
@@ -1,3 +1,4 @@
@import "./style-import.css";
@import "print.css?foo=1";
@import url("print.css?foo=2");
@import "print.css?foo=3" layer(default);
Expand Down