Skip to content
Open
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
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ jobs:
with:
save-cache: ${{ github.ref_name == 'main' }}

- run: cargo check
- uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Prepare fixtures
run: |
corepack enable
cd fixtures/global-cache
yarn install
Copy link
Member

Choose a reason for hiding this comment

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

We should just check-in the .pnp.cjs file

Copy link
Contributor Author

@JounQin JounQin Aug 27, 2025

Choose a reason for hiding this comment

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

It would be different on different OS, so I'm not sure how to make it work.

- name: Build
run: cargo build

- name: Check
run: cargo check

- run: cargo test
- name: Run tests
run: cargo test

clippy:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
target
target
74 changes: 63 additions & 11 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ repository = "https://github.com/yarnpkg/pnp-rs"

[dependencies]
byteorder = "1"
clean-path = "0.2.1"
concurrent_lru = "^0.2"
fancy-regex = { version = "^0.16.0", default-features = false, features = ["std"] }
miniz_oxide = "^0.8"
mmap-rs = { version = "^0.6", optional = true }
path-slash = "0.2.1"
pathdiff = "^0.2"
radix_trie = "0.2.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
rustc-hash = "2"
dirs = "6.0.0"

[dev-dependencies]
rstest = "0.26.0"
Expand Down
2 changes: 2 additions & 0 deletions fixtures/global-cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.yarn/*
.pnp.*
3 changes: 3 additions & 0 deletions fixtures/global-cache/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enableGlobalCache: true

nodeLinker: pnp
7 changes: 7 additions & 0 deletions fixtures/global-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "global-cache",
"dependencies": {
"source-map-support": "^0.5.21"
},
"packageManager": "[email protected]"
}
1 change: 1 addition & 0 deletions fixtures/global-cache/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(require.resolve('source-map-support'));
38 changes: 38 additions & 0 deletions fixtures/global-cache/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 8
cacheKey: 10c0

"buffer-from@npm:^1.0.0":
version: 1.1.2
resolution: "buffer-from@npm:1.1.2"
checksum: 10c0/124fff9d66d691a86d3b062eff4663fe437a9d9ee4b47b1b9e97f5a5d14f6d5399345db80f796827be7c95e70a8e765dd404b7c3ff3b3324f98e9b0c8826cc34
languageName: node
linkType: hard

"global-cache@workspace:.":
version: 0.0.0-use.local
resolution: "global-cache@workspace:."
dependencies:
source-map-support: "npm:^0.5.21"
languageName: unknown
linkType: soft

"source-map-support@npm:^0.5.21":
version: 0.5.21
resolution: "source-map-support@npm:0.5.21"
dependencies:
buffer-from: "npm:^1.0.0"
source-map: "npm:^0.6.0"
checksum: 10c0/9ee09942f415e0f721d6daad3917ec1516af746a8120bba7bb56278707a37f1eb8642bde456e98454b8a885023af81a16e646869975f06afc1a711fb90484e7d
languageName: node
linkType: hard

"source-map@npm:^0.6.0":
version: 0.6.1
resolution: "source-map@npm:0.6.1"
checksum: 10c0/ab55398007c5e5532957cb0beee2368529618ac0ab372d789806f5718123cc4367d57de3904b4e6a4170eb5a0b0f41373066d02ca0735a0c4d75c7d328d3e011
languageName: node
linkType: hard
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ pub fn init_pnp_manifest(manifest: &mut Manifest, p: &Path) {
for (name, ranges) in manifest.package_registry_data.iter_mut() {
for (reference, info) in ranges.iter_mut() {
let package_location = manifest.manifest_dir.join(info.package_location.clone());

let normalized_location = util::normalize_path(package_location.to_string_lossy());

info.package_location = PathBuf::from(normalized_location);
Expand Down Expand Up @@ -208,6 +207,8 @@ pub fn find_locator<'a>(manifest: &'a Manifest, path: &Path) -> Option<&'a Packa
}
}

let path = util::normalize_path(path.to_string_lossy());

manifest.location_trie.get_ancestor_value(&path)
}

Expand Down
55 changes: 53 additions & 2 deletions src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ struct TestSuite {

#[cfg(test)]
mod tests {
use std::{fs, path::PathBuf};
use std::{env, fs, path::PathBuf};

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

#[test]
Expand Down Expand Up @@ -162,4 +162,55 @@ mod tests {
let parsed = parse_bare_identifier("@scope/pkg/a/b/c/index.js");
assert_eq!(parsed, Ok(("@scope/pkg".to_string(), Some("a/b/c/index.js".to_string()))));
}

#[test]
fn test_global_cache() {
let manifest = load_pnp_manifest(
env::current_dir()
.unwrap()
.join("fixtures")
.join("global-cache")
.join(".pnp.cjs")
.as_path(),
)
.unwrap();

let home_dir = dirs::home_dir().unwrap();

#[cfg(windows)]
let global_cache = home_dir.join("AppData\\Local\\Yarn\\Berry\\cache");
#[cfg(not(windows))]
let global_cache = home_dir.join(".yarn/berry/cache");

let result = resolve_to_unqualified_via_manifest(
&manifest,
"source-map",
global_cache
.join("source-map-support-npm-0.5.21-09ca99e250-10c0.zip")
.join("node_modules")
.join("source-map-support")
.join("")
.as_path(),
);

match result {
Ok(Resolution::Resolved(path, subpath)) => {
assert_eq!(
path.to_string_lossy(),
util::normalize_path(
global_cache
.join("source-map-npm-0.6.1-1a3621db16-10c0.zip")
.join("node_modules")
.join("source-map")
.join("")
.to_string_lossy()
)
);
assert_eq!(subpath, None);
}
_ => {
panic!("Unexpected resolve failed");
}
}
}
}
Loading
Loading