diff --git a/fixtures/pnp/.pnp.cjs b/fixtures/pnp/.pnp.cjs index 575adac..47358b7 100755 --- a/fixtures/pnp/.pnp.cjs +++ b/fixtures/pnp/.pnp.cjs @@ -29,7 +29,8 @@ const RAW_RUNTIME_STATE = "packageDependencies": [\ ["is-even", "npm:1.0.0"],\ ["is-odd", "npm:3.0.1"],\ - ["lodash.zip", "npm:4.2.0"]\ + ["lodash.zip", "npm:4.2.0"],\ + ["preact", "npm:10.25.4"]\ ],\ "linkType": "SOFT"\ }]\ @@ -114,10 +115,20 @@ const RAW_RUNTIME_STATE = ["pnp", "workspace:."],\ ["is-even", "npm:1.0.0"],\ ["is-odd", "npm:3.0.1"],\ - ["lodash.zip", "npm:4.2.0"]\ + ["lodash.zip", "npm:4.2.0"],\ + ["preact", "npm:10.25.4"]\ ],\ "linkType": "SOFT"\ }]\ + ]],\ + ["preact", [\ + ["npm:10.25.4", {\ + "packageLocation": "./.yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip/node_modules/preact/",\ + "packageDependencies": [\ + ["preact", "npm:10.25.4"]\ + ],\ + "linkType": "HARD"\ + }]\ ]]\ ]\ }'; diff --git a/fixtures/pnp/.yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip b/fixtures/pnp/.yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip new file mode 100644 index 0000000..244b3bd Binary files /dev/null and b/fixtures/pnp/.yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip differ diff --git a/fixtures/pnp/.yarn/install-state.gz b/fixtures/pnp/.yarn/install-state.gz index f8122bc..ba4dd48 100644 Binary files a/fixtures/pnp/.yarn/install-state.gz and b/fixtures/pnp/.yarn/install-state.gz differ diff --git a/fixtures/pnp/package.json b/fixtures/pnp/package.json index f64c4af..5866808 100644 --- a/fixtures/pnp/package.json +++ b/fixtures/pnp/package.json @@ -4,6 +4,7 @@ "dependencies": { "is-even": "^1.0.0", "is-odd": "^3.0.1", - "lodash.zip": "^4.2.0" + "lodash.zip": "^4.2.0", + "preact": "^10.25.4" } } diff --git a/fixtures/pnp/yarn.lock b/fixtures/pnp/yarn.lock index aa97f58..048269c 100644 --- a/fixtures/pnp/yarn.lock +++ b/fixtures/pnp/yarn.lock @@ -78,5 +78,13 @@ __metadata: is-even: "npm:^1.0.0" is-odd: "npm:^3.0.1" lodash.zip: "npm:^4.2.0" + preact: "npm:^10.25.4" languageName: unknown linkType: soft + +"preact@npm:^10.25.4": + version: 10.25.4 + resolution: "preact@npm:10.25.4" + checksum: 10c0/33a009d614d2b47df1c867935fe057c1dfd2bae1aaab41d6e981434b761f75b88e82eac7847ae486b4dbcffc74af814b8dc59ccef17b10625e3effefa2e1ef67 + languageName: node + linkType: hard diff --git a/src/lib.rs b/src/lib.rs index cddcfe7..2c3c90b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -792,9 +792,13 @@ impl ResolverGeneric { pnp::resolve_to_unqualified_via_manifest(pnp_manifest, specifier, path); match resolution { - Ok(pnp::Resolution::Resolved(path, subpath)) => { + Ok(pnp::Resolution::Resolved(path, mut subpath)) => { let cached_path = self.cache.value(&path); + if let Some(subpath) = subpath.as_mut() { + subpath.insert(0, '/'); + } + let export_resolution = self.load_package_exports( specifier, &subpath.unwrap_or_default(), diff --git a/src/tests/pnp.rs b/src/tests/pnp.rs index 6a6f38c..fea8546 100644 --- a/src/tests/pnp.rs +++ b/src/tests/pnp.rs @@ -11,6 +11,7 @@ fn pnp1() { let resolver = Resolver::new(ResolveOptions { extensions: vec![".js".into()], + condition_names: vec!["import".into()], ..ResolveOptions::default() }); @@ -48,4 +49,18 @@ fn pnp1() { ".yarn/cache/is-odd-npm-3.0.1-93c3c3f41b-89ee2e353c.zip/node_modules/is-odd/index.js" )), ); + + assert_eq!( + resolver.resolve(&fixture, "preact").map(|r| r.full_path()), + Ok(fixture.join( + ".yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip/node_modules/preact/dist/preact.mjs" + )), + ); + + assert_eq!( + resolver.resolve(&fixture, "preact/devtools").map(|r| r.full_path()), + Ok(fixture.join( + ".yarn/cache/preact-npm-10.25.4-2dd2c0aa44-33a009d614.zip/node_modules/preact/devtools/dist/devtools.mjs" + )), + ); }