Skip to content

Commit 33b1723

Browse files
authoredFeb 17, 2025··
Merge pull request #5 from stormslowly/fix/cached_unplugged
fix: 🐛 edge case one package cached and unplugged in same time
2 parents 80e67fc + 381f70b commit 33b1723

File tree

5 files changed

+162
-12
lines changed

5 files changed

+162
-12
lines changed
 

‎Cargo.lock

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

‎Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ arca = "^0.7"
1212
byteorder = "1"
1313
concurrent_lru = "^0.2"
1414
fancy-regex = "^0.13.0"
15+
indexmap = { version = "2.7.1", features = ["serde"] }
1516
lazy_static = "1"
1617
miniz_oxide = "^0.7"
1718
mmap-rs = { version = "^0.6", optional = true }
1819
pathdiff = "^0.2"
1920
regex = "1"
2021
serde = { version = "1", features = ["derive"] }
2122
serde_json = "1"
22-
serde_with = "3"
23+
serde_with = { version = "3", features = ["indexmap_2"] }
2324
thiserror = "1"
2425

2526
[features]

‎data/edge_case_manifest_state.json

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"__info": [
3+
"This file is automatically generated. Do not touch it, or risk",
4+
"your modifications being lost."
5+
],
6+
"dependencyTreeRoots": [
7+
{
8+
"name": "rspack-link",
9+
"reference": "workspace:."
10+
}
11+
],
12+
"enableTopLevelFallback": true,
13+
"ignorePatternData": "(^(?:\\.yarn\\/sdks(?:\\/(?!\\.{1,2}(?:\\/|$))(?:(?:(?!(?:^|\\/)\\.{1,2}(?:\\/|$)).)*?)|$))$)",
14+
"fallbackExclusionList": [
15+
[
16+
"rspack-link",
17+
[
18+
"workspace:."
19+
]
20+
]
21+
],
22+
"fallbackPool": [],
23+
"packageRegistryData": [
24+
[
25+
null,
26+
[
27+
[
28+
null,
29+
{
30+
"packageLocation": "./",
31+
"packageDependencies": [
32+
],
33+
"linkType": "SOFT"
34+
}
35+
]
36+
]
37+
],
38+
39+
[
40+
"@carbon/icon-helpers",
41+
[
42+
[
43+
"npm:10.54.0",
44+
{
45+
"packageLocation": "./.yarn/unplugged/@carbon-icon-helpers-npm-10.54.0-a58f8b7b6c/node_modules/@carbon/icon-helpers/",
46+
"packageDependencies": [
47+
[
48+
"@carbon/icon-helpers",
49+
"npm:10.54.0"
50+
],
51+
[
52+
"@ibm/telemetry-js",
53+
"npm:1.9.1"
54+
]
55+
],
56+
"linkType": "HARD"
57+
}
58+
]
59+
]
60+
],
61+
[
62+
"@carbon/icons-react",
63+
[
64+
[
65+
"npm:11.54.0",
66+
{
67+
"packageLocation": "./.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/",
68+
"packageDependencies": [
69+
[
70+
"@carbon/icons-react",
71+
"npm:11.54.0"
72+
]
73+
],
74+
"linkType": "SOFT"
75+
}
76+
],
77+
[
78+
"virtual:ed977161de61e6995bdb8c18ad719dac99ebc9dc1b7317c42e54ab394643509c7ea342abb2b214efc589efcb79dc9deae3ca4092870cbe691d6377887658443c#npm:11.54.0",
79+
{
80+
"packageLocation": "./.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/",
81+
"packageDependencies": [
82+
[
83+
"@carbon/icons-react",
84+
"virtual:ed977161de61e6995bdb8c18ad719dac99ebc9dc1b7317c42e54ab394643509c7ea342abb2b214efc589efcb79dc9deae3ca4092870cbe691d6377887658443c#npm:11.54.0"
85+
],
86+
[
87+
"@carbon/icon-helpers",
88+
"npm:10.54.0"
89+
],
90+
[
91+
"@ibm/telemetry-js",
92+
"npm:1.9.1"
93+
],
94+
[
95+
"@types/react",
96+
null
97+
],
98+
[
99+
"prop-types",
100+
"npm:15.8.1"
101+
],
102+
[
103+
"react",
104+
"npm:19.0.0"
105+
]
106+
],
107+
"packagePeers": [
108+
"@types/react",
109+
"react"
110+
],
111+
"linkType": "HARD"
112+
}
113+
]
114+
]
115+
]
116+
]
117+
}

‎src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod util;
55
mod zip;
66

77
use fancy_regex::Regex;
8+
use indexmap::IndexMap;
89
use lazy_static::lazy_static;
910
use serde::{Deserialize, Serialize};
1011
use serde_with::{serde_as, DefaultOnNull};
@@ -164,7 +165,7 @@ pub struct Manifest {
164165
// }]
165166
// ]
166167
#[serde_as(as = "Vec<(DefaultOnNull<_>, Vec<(DefaultOnNull<_>, _)>)>")]
167-
package_registry_data: HashMap<String, HashMap<String, PackageInformation>>,
168+
package_registry_data: HashMap<String, IndexMap<String, PackageInformation>>,
168169
}
169170

170171
pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>), Error> {
@@ -184,7 +185,7 @@ pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>)
184185
if let Some(ident) = ident_option {
185186
Ok((ident, segments.next().map(|v| v.to_string())))
186187
} else {
187-
Err(Error::BadSpecifier{
188+
Err(Error::BadSpecifier {
188189
message: String::from("Invalid specifier"),
189190
specifier: specifier.to_string(),
190191
})

‎src/lib_tests.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::Deserialize;
22

3-
use crate::{ResolutionConfig, Resolution, Manifest};
3+
use crate::{Manifest, Resolution, ResolutionConfig};
44

55
#[derive(Deserialize)]
66
struct Test {
@@ -20,8 +20,11 @@ struct TestSuite {
2020
mod tests {
2121
use std::{fs, path::PathBuf};
2222

23-
use crate::{init_pnp_manifest, load_pnp_manifest, resolve_to_unqualified, ResolutionHost};
2423
use super::*;
24+
use crate::{
25+
init_pnp_manifest, load_pnp_manifest, resolve_to_unqualified,
26+
resolve_to_unqualified_via_manifest, ResolutionHost,
27+
};
2528

2629
#[test]
2730
fn example() {
@@ -119,4 +122,31 @@ mod tests {
119122
}
120123
}
121124
}
125+
126+
#[test]
127+
fn test_edge_case_one_pkg_cached_and_unplugged() {
128+
let manifest = {
129+
let manifest_json_path = std::env::current_dir().unwrap().join("./data/edge_case_manifest_state.json");
130+
let manifest_content = fs::read_to_string(&manifest_json_path).unwrap();
131+
let mut manifest = serde_json::from_str::<Manifest>(&manifest_content).unwrap();
132+
init_pnp_manifest(&mut manifest, manifest_json_path);
133+
manifest
134+
};
135+
136+
let issuer = std::env::current_dir().unwrap().
137+
join("data/.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/es/");
138+
139+
let resolution =
140+
resolve_to_unqualified_via_manifest(&manifest, "@carbon/icon-helpers", &issuer)
141+
.unwrap();
142+
143+
match resolution {
144+
Resolution::Resolved(resolved, _) => {
145+
assert!(resolved.ends_with(".yarn/unplugged/@carbon-icon-helpers-npm-10.54.0-a58f8b7b6c/node_modules/@carbon/icon-helpers"))
146+
}
147+
_ => {
148+
panic!("Unexpected resolve failed");
149+
}
150+
}
151+
}
122152
}

0 commit comments

Comments
 (0)
Please sign in to comment.