Skip to content

Commit c8187a9

Browse files
committed
chore: reproduce global cache issue
1 parent a096bd9 commit c8187a9

File tree

11 files changed

+206
-6
lines changed

11 files changed

+206
-6
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ jobs:
2222
with:
2323
save-cache: ${{ github.ref_name == 'main' }}
2424

25-
- run: cargo check
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: lts/*
28+
29+
- name: Prepare fixtures
30+
run: |
31+
corepack enable
32+
cd fixtures/global-cache
33+
yarn install
34+
35+
- name: Build
36+
run: cargo build
37+
38+
- name: Check
39+
run: cargo check
2640

27-
- run: cargo test
41+
- name: Run tests
42+
run: cargo test
2843

2944
clippy:
3045
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde = { version = "1", features = ["derive"] }
2121
serde_json = "1"
2222
thiserror = "2"
2323
rustc-hash = "2"
24+
dirs = "6.0.0"
2425

2526
[dev-dependencies]
2627
rstest = "0.26.0"

fixtures/global-cache/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.yarn/*
2+
.pnp.*

fixtures/global-cache/.yarnrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
enableGlobalCache: true
2+
3+
nodeLinker: pnp

fixtures/global-cache/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "global-cache",
3+
"dependencies": {
4+
"source-map-support": "^0.5.21"
5+
},
6+
"packageManager": "yarn@4.9.2"
7+
}

fixtures/global-cache/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(require.resolve('source-map-support'));

fixtures/global-cache/yarn.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 8
6+
cacheKey: 10c0
7+
8+
"buffer-from@npm:^1.0.0":
9+
version: 1.1.2
10+
resolution: "buffer-from@npm:1.1.2"
11+
checksum: 10c0/124fff9d66d691a86d3b062eff4663fe437a9d9ee4b47b1b9e97f5a5d14f6d5399345db80f796827be7c95e70a8e765dd404b7c3ff3b3324f98e9b0c8826cc34
12+
languageName: node
13+
linkType: hard
14+
15+
"global-cache@workspace:.":
16+
version: 0.0.0-use.local
17+
resolution: "global-cache@workspace:."
18+
dependencies:
19+
source-map-support: "npm:^0.5.21"
20+
languageName: unknown
21+
linkType: soft
22+
23+
"source-map-support@npm:^0.5.21":
24+
version: 0.5.21
25+
resolution: "source-map-support@npm:0.5.21"
26+
dependencies:
27+
buffer-from: "npm:^1.0.0"
28+
source-map: "npm:^0.6.0"
29+
checksum: 10c0/9ee09942f415e0f721d6daad3917ec1516af746a8120bba7bb56278707a37f1eb8642bde456e98454b8a885023af81a16e646869975f06afc1a711fb90484e7d
30+
languageName: node
31+
linkType: hard
32+
33+
"source-map@npm:^0.6.0":
34+
version: 0.6.1
35+
resolution: "source-map@npm:0.6.1"
36+
checksum: 10c0/ab55398007c5e5532957cb0beee2368529618ac0ab372d789806f5718123cc4367d57de3904b4e6a4170eb5a0b0f41373066d02ca0735a0c4d75c7d328d3e011
37+
languageName: node
38+
linkType: hard

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,18 @@ pub fn init_pnp_manifest(manifest: &mut Manifest, p: &Path) {
160160

161161
for (name, ranges) in manifest.package_registry_data.iter_mut() {
162162
for (reference, info) in ranges.iter_mut() {
163+
println!("manifest.manifest_dir, {}", manifest.manifest_dir.to_string_lossy());
164+
165+
println!("info.package_location: {}", info.package_location.to_string_lossy());
166+
163167
let package_location = manifest.manifest_dir.join(info.package_location.clone());
164168

169+
println!("package_location: {}", package_location.to_string_lossy());
170+
165171
let normalized_location = util::normalize_path(package_location.to_string_lossy());
166172

173+
println!("normalized_location: {normalized_location}");
174+
167175
info.package_location = PathBuf::from(normalized_location);
168176

169177
if !info.discard_from_lookup {
@@ -208,6 +216,12 @@ pub fn find_locator<'a>(manifest: &'a Manifest, path: &Path) -> Option<&'a Packa
208216
}
209217
}
210218

219+
println!("path {}", path.to_string_lossy());
220+
221+
let path = util::normalize_path(path.to_string_lossy());
222+
223+
println!("path {path}");
224+
211225
manifest.location_trie.get_ancestor_value(&path)
212226
}
213227

src/lib_tests.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ struct TestSuite {
2020

2121
#[cfg(test)]
2222
mod tests {
23-
use std::{fs, path::PathBuf};
23+
use std::{env, fs, path::PathBuf};
2424

2525
use super::*;
2626
use crate::{
2727
ResolutionConfig, ResolutionHost, init_pnp_manifest, load_pnp_manifest,
28-
parse_bare_identifier, resolve_to_unqualified, resolve_to_unqualified_via_manifest,
28+
parse_bare_identifier, resolve_to_unqualified, resolve_to_unqualified_via_manifest, util,
2929
};
3030

3131
#[test]
@@ -162,4 +162,55 @@ mod tests {
162162
let parsed = parse_bare_identifier("@scope/pkg/a/b/c/index.js");
163163
assert_eq!(parsed, Ok(("@scope/pkg".to_string(), Some("a/b/c/index.js".to_string()))));
164164
}
165+
166+
#[test]
167+
fn test_global_cache() {
168+
let manifest = load_pnp_manifest(
169+
env::current_dir()
170+
.unwrap()
171+
.join("fixtures")
172+
.join("global-cache")
173+
.join(".pnp.cjs")
174+
.as_path(),
175+
)
176+
.unwrap();
177+
178+
let home_dir = dirs::home_dir().unwrap();
179+
180+
#[cfg(windows)]
181+
let global_cache = home_dir.join("AppData\\Local\\Yarn\\Berry\\cache");
182+
#[cfg(not(windows))]
183+
let global_cache = home_dir.join(".yarn/berry/cache");
184+
185+
let result = resolve_to_unqualified_via_manifest(
186+
&manifest,
187+
"source-map",
188+
global_cache
189+
.join("source-map-support-npm-0.5.21-09ca99e250-10c0.zip")
190+
.join("node_modules")
191+
.join("source-map-support")
192+
.join("")
193+
.as_path(),
194+
);
195+
196+
match result {
197+
Ok(Resolution::Resolved(path, subpath)) => {
198+
assert_eq!(
199+
path.to_string_lossy(),
200+
util::normalize_path(
201+
global_cache
202+
.join("source-map-npm-0.6.1-1a3621db16-10c0.zip")
203+
.join("node_modules")
204+
.join("source-map")
205+
.join("")
206+
.to_string_lossy()
207+
)
208+
);
209+
assert_eq!(subpath, None);
210+
}
211+
_ => {
212+
panic!("Unexpected resolve failed");
213+
}
214+
}
215+
}
165216
}

0 commit comments

Comments
 (0)