Skip to content

test: add a new test case for global cache #10

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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

- 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
143 changes: 141 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ thiserror = "2"
rustc-hash = "2"

[dev-dependencies]
dirs = "6.0.0"
rstest = "0.25.0"

[features]
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
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ pub fn init_pnp_manifest<P: AsRef<Path>>(manifest: &mut Manifest, p: P) {

for (name, ranges) in manifest.package_registry_data.iter_mut() {
for (reference, info) in ranges.iter_mut() {
println!("manifest.manifest_dir, {}", manifest.manifest_dir.to_string_lossy());

let package_location = manifest.manifest_dir.join(info.package_location.clone());

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

println!("normalized_location: {normalized_location}");

info.package_location = PathBuf::from(normalized_location);

println!("info.package_location: {}", info.package_location.to_string_lossy());

if !info.discard_from_lookup {
manifest.location_trie.insert(
&info.package_location,
Expand Down Expand Up @@ -207,6 +213,12 @@ pub fn find_locator<'a, P: AsRef<Path>>(
}
}

println!("path {}", path.as_ref().to_string_lossy());

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

println!("path {path}");

manifest.location_trie.get_ancestor_value(&path)
}

Expand Down
Loading
Loading