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: 🐛 edge case one package cached and unplugged in same time #5

Merged
merged 1 commit into from
Feb 17, 2025
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
15 changes: 8 additions & 7 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ arca = "^0.7"
byteorder = "1"
concurrent_lru = "^0.2"
fancy-regex = "^0.13.0"
indexmap = { version = "2.7.1", features = ["serde"] }
lazy_static = "1"
miniz_oxide = "^0.7"
mmap-rs = { version = "^0.6", optional = true }
pathdiff = "^0.2"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_with = "3"
serde_with = { version = "3", features = ["indexmap_2"] }
thiserror = "1"

[features]
Expand Down
117 changes: 117 additions & 0 deletions data/edge_case_manifest_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"__info": [
"This file is automatically generated. Do not touch it, or risk",
"your modifications being lost."
],
"dependencyTreeRoots": [
{
"name": "rspack-link",
"reference": "workspace:."
}
],
"enableTopLevelFallback": true,
"ignorePatternData": "(^(?:\\.yarn\\/sdks(?:\\/(?!\\.{1,2}(?:\\/|$))(?:(?:(?!(?:^|\\/)\\.{1,2}(?:\\/|$)).)*?)|$))$)",
"fallbackExclusionList": [
[
"rspack-link",
[
"workspace:."
]
]
],
"fallbackPool": [],
"packageRegistryData": [
[
null,
[
[
null,
{
"packageLocation": "./",
"packageDependencies": [
],
"linkType": "SOFT"
}
]
]
],

[
"@carbon/icon-helpers",
[
[
"npm:10.54.0",
{
"packageLocation": "./.yarn/unplugged/@carbon-icon-helpers-npm-10.54.0-a58f8b7b6c/node_modules/@carbon/icon-helpers/",
"packageDependencies": [
[
"@carbon/icon-helpers",
"npm:10.54.0"
],
[
"@ibm/telemetry-js",
"npm:1.9.1"
]
],
"linkType": "HARD"
}
]
]
],
[
"@carbon/icons-react",
[
[
"npm:11.54.0",
{
"packageLocation": "./.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/",
"packageDependencies": [
[
"@carbon/icons-react",
"npm:11.54.0"
]
],
"linkType": "SOFT"
}
],
[
"virtual:ed977161de61e6995bdb8c18ad719dac99ebc9dc1b7317c42e54ab394643509c7ea342abb2b214efc589efcb79dc9deae3ca4092870cbe691d6377887658443c#npm:11.54.0",
{
"packageLocation": "./.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/",
"packageDependencies": [
[
"@carbon/icons-react",
"virtual:ed977161de61e6995bdb8c18ad719dac99ebc9dc1b7317c42e54ab394643509c7ea342abb2b214efc589efcb79dc9deae3ca4092870cbe691d6377887658443c#npm:11.54.0"
],
[
"@carbon/icon-helpers",
"npm:10.54.0"
],
[
"@ibm/telemetry-js",
"npm:1.9.1"
],
[
"@types/react",
null
],
[
"prop-types",
"npm:15.8.1"
],
[
"react",
"npm:19.0.0"
]
],
"packagePeers": [
"@types/react",
"react"
],
"linkType": "HARD"
}
]
]
]
]
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod util;
mod zip;

use fancy_regex::Regex;
use indexmap::IndexMap;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DefaultOnNull};
Expand Down Expand Up @@ -164,7 +165,7 @@ pub struct Manifest {
// }]
// ]
#[serde_as(as = "Vec<(DefaultOnNull<_>, Vec<(DefaultOnNull<_>, _)>)>")]
package_registry_data: HashMap<String, HashMap<String, PackageInformation>>,
package_registry_data: HashMap<String, IndexMap<String, PackageInformation>>,
}

pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>), Error> {
Expand All @@ -184,7 +185,7 @@ pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>)
if let Some(ident) = ident_option {
Ok((ident, segments.next().map(|v| v.to_string())))
} else {
Err(Error::BadSpecifier{
Err(Error::BadSpecifier {
message: String::from("Invalid specifier"),
specifier: specifier.to_string(),
})
Expand Down
34 changes: 32 additions & 2 deletions src/lib_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;

use crate::{ResolutionConfig, Resolution, Manifest};
use crate::{Manifest, Resolution, ResolutionConfig};

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

use crate::{init_pnp_manifest, load_pnp_manifest, resolve_to_unqualified, ResolutionHost};
use super::*;
use crate::{
init_pnp_manifest, load_pnp_manifest, resolve_to_unqualified,
resolve_to_unqualified_via_manifest, ResolutionHost,
};

#[test]
fn example() {
Expand Down Expand Up @@ -119,4 +122,31 @@ mod tests {
}
}
}

#[test]
fn test_edge_case_one_pkg_cached_and_unplugged() {
let manifest = {
let manifest_json_path = std::env::current_dir().unwrap().join("./data/edge_case_manifest_state.json");
let manifest_content = fs::read_to_string(&manifest_json_path).unwrap();
let mut manifest = serde_json::from_str::<Manifest>(&manifest_content).unwrap();
init_pnp_manifest(&mut manifest, manifest_json_path);
manifest
};

let issuer = std::env::current_dir().unwrap().
join("data/.yarn/unplugged/@carbon-icons-react-virtual-379302d360/node_modules/@carbon/icons-react/es/");

let resolution =
resolve_to_unqualified_via_manifest(&manifest, "@carbon/icon-helpers", &issuer)
.unwrap();

match resolution {
Resolution::Resolved(resolved, _) => {
assert!(resolved.ends_with(".yarn/unplugged/@carbon-icon-helpers-npm-10.54.0-a58f8b7b6c/node_modules/@carbon/icon-helpers"))
}
_ => {
panic!("Unexpected resolve failed");
}
}
}
}