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: nested byDependency not merge #2666

Merged
merged 3 commits into from
Apr 8, 2023
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
5 changes: 5 additions & 0 deletions crates/rspack_core/src/options/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ impl ByDependency {
// TODO: maybe a Merge trait for implementing cleverMerge in rust side?
pub fn merge(mut self, value: Self) -> Self {
for (k, v) in value.0 {
let v = if let Some(origin) = self.0.remove(&k) {
origin.merge(v)
} else {
v
};
self.0.insert(k, v);
}
self
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_core/src/utils/module_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ pub async fn module_rule_matcher_inner<'a>(
if let Some(description_data) = &module_rule.description_data
&& let Some(resource_description) = &resource_data.resource_description {
for (k, matcher) in description_data {
if let Some(v) = resource_description.data().raw().get(k).and_then(|v| v.as_str())
&& !matcher.try_match(v).await? {
if let Some(v) = resource_description.data().raw().get(k).and_then(|v| v.as_str()) {
if !matcher.try_match(v).await? {
return Ok(None);
}
} else {
return Ok(None);
}
}
Expand Down
10 changes: 1 addition & 9 deletions examples/bundle-splitting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,5 @@
},
"keywords": [],
"author": "",
"license": "MIT",
"rspack": {
"manualChunks": {
"vendor": [
"manual",
"common"
]
}
}
"license": "MIT"
}
7 changes: 7 additions & 0 deletions packages/rspack/tests/Defaults.unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ describe("snapshots", () => {
"descriptionData": {
"type": "module",
},
"resolve": {
"byDependency": {
"esm": {
"fullySpecified": true,
},
},
},
"test": /\\\\\\.js\\$/i,
"type": "javascript/esm",
},
Expand Down
24 changes: 12 additions & 12 deletions packages/rspack/tests/Stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ describe("Stats", () => {
"chunks": [
"main",
],
"id": "658",
"identifier": "javascript/dynamic|<PROJECT_ROOT>/tests/fixtures/a.js",
"id": "777",
"identifier": "javascript/auto|<PROJECT_ROOT>/tests/fixtures/a.js",
"issuerPath": [],
"moduleType": "javascript/dynamic",
"moduleType": "javascript/auto",
"name": "./fixtures/a.js",
"size": 55,
"type": "module",
Expand Down Expand Up @@ -98,10 +98,10 @@ describe("Stats", () => {
"chunks": [
"main",
],
"id": "658",
"identifier": "javascript/dynamic|<PROJECT_ROOT>/tests/fixtures/a.js",
"id": "777",
"identifier": "javascript/auto|<PROJECT_ROOT>/tests/fixtures/a.js",
"issuerPath": [],
"moduleType": "javascript/dynamic",
"moduleType": "javascript/auto",
"name": "./fixtures/a.js",
"size": 55,
"type": "module",
Expand Down Expand Up @@ -135,8 +135,8 @@ describe("Stats", () => {
main.js 215 bytes main [emitted] main
Entrypoint main = main.js
chunk {main} main.js (main) 55 bytes [entry]
[658] ./fixtures/a.js 55 bytes {main}
[658] ./fixtures/a.js 55 bytes {main}"
[777] ./fixtures/a.js 55 bytes {main}
[777] ./fixtures/a.js 55 bytes {main}"
`);
});

Expand All @@ -163,10 +163,10 @@ describe("Stats", () => {
Asset Size Chunks Chunk Names
main.js 419 bytes main [emitted] main
Entrypoint main = main.js
[658] ./fixtures/a.js 55 bytes {main}
[385] ./fixtures/b.js 94 bytes {main}
[586] ./fixtures/c.js 72 bytes {main}
[939] ./fixtures/abc.js 83 bytes {main}
[777] ./fixtures/a.js 55 bytes {main}
[510] ./fixtures/b.js 94 bytes {main}
[906] ./fixtures/c.js 72 bytes {main}
[492] ./fixtures/abc.js 83 bytes {main}

error[javascript]: JavaScript parsing error
┌─ tests/fixtures/b.js:6:1
Expand Down
Loading