Skip to content

Commit 3417711

Browse files
committed
wip
1 parent 7b51f78 commit 3417711

File tree

5 files changed

+13
-36
lines changed

5 files changed

+13
-36
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[package]
2-
name = "pnp-rs"
2+
name = "pnp"
33
version = "0.1.0"
44
edition = "2021"
5+
license = "BSD-2-Clause"
6+
description = "Resolution primitives for Yarn PnP"
7+
homepage = "https://yarnpkg.com"
8+
repository = "https://github.com/yarnpkg/berry/"
59

610
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
711

src/lib.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum Error {
2929

3030
pub enum Resolution {
3131
Specifier(String),
32-
Path(PathBuf),
32+
Package(PathBuf, Option<String>),
3333
}
3434

3535
pub struct ResolutionHost {
@@ -118,18 +118,6 @@ pub struct Manifest {
118118
package_registry_data: HashMap<String, HashMap<String, PackageInformation>>,
119119
}
120120

121-
pub fn is_builtin(specifier: &str, config: &ResolutionConfig) -> bool {
122-
config.builtins.contains(specifier)
123-
}
124-
125-
pub fn is_path_specifier(specifier: &str) -> bool {
126-
lazy_static! {
127-
static ref RE: Regex = Regex::new("^\\.{0,2}/").unwrap();
128-
}
129-
130-
RE.is_match(specifier).unwrap()
131-
}
132-
133121
pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>), Error> {
134122
let mut segments = specifier.splitn(3, '/');
135123
let mut ident_option: Option<String> = None;
@@ -275,18 +263,6 @@ pub fn is_excluded_from_fallback(manifest: &Manifest, locator: &PackageLocator)
275263
}
276264
}
277265

278-
pub fn pnp_resolve(specifier: &str, parent: &Path, config: &ResolutionConfig) -> Result<Resolution, Error> {
279-
if is_builtin(specifier, config) {
280-
return Ok(Resolution::Specifier(specifier.to_string()))
281-
}
282-
283-
if is_path_specifier(specifier) {
284-
return Ok(Resolution::Specifier(specifier.to_string()))
285-
}
286-
287-
resolve_to_unqualified(specifier, parent, config)
288-
}
289-
290266
pub fn resolve_to_unqualified(specifier: &str, parent: &Path, config: &ResolutionConfig) -> Result<Resolution, Error> {
291267
let (ident, module_path) = parse_bare_identifier(specifier)?;
292268

@@ -321,10 +297,7 @@ pub fn resolve_to_unqualified(specifier: &str, parent: &Path, config: &Resolutio
321297
PackageDependency::Alias(name, reference) => get_package(&manifest, &PackageLocator { name, reference }),
322298
}?;
323299

324-
let joined_path = dependency_pkg.package_location.clone() + &module_path.unwrap_or_default();
325-
let normalized_path = util::normalize_path(joined_path);
326-
327-
Ok(Resolution::Path(PathBuf::from(normalized_path)))
300+
Ok(Resolution::Package(PathBuf::from(dependency_pkg.package_location.clone()), module_path.clone()))
328301
} else {
329302
return Err(Error::FailedResolution);
330303
}

src/lib_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod tests {
5858
let resolution = resolve_to_unqualified(specifier, parent, &config);
5959

6060
match resolution {
61-
Ok(Resolution::Path(path)) => {
61+
Ok(Resolution::Package(path, _subpath)) => {
6262
assert_eq!(path.to_string_lossy(), test.expected, "{}", test.it);
6363
},
6464
Ok(Resolution::Specifier(specifier)) => {

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pnp_rs::{pnp_resolve, ResolutionConfig, Resolution};
1+
use pnp::{ResolutionConfig, Resolution};
22
use std::path::PathBuf;
33

44
fn main() {
@@ -17,15 +17,15 @@ fn main() {
1717
println!("specifier = {}", specifier);
1818
println!("parent = {:?}", parent);
1919

20-
let resolution = pnp_resolve(&specifier, &parent, &ResolutionConfig {
20+
let resolution = pnp::resolve_to_unqualified(&specifier, &parent, &ResolutionConfig {
2121
..Default::default()
2222
});
2323

2424
match resolution {
2525
Ok(res) => {
2626
match res {
27-
Resolution::Path(p) => {
28-
println!("result = Path ({:?})", p);
27+
Resolution::Package(p, subpath) => {
28+
println!("result = Package ({:?}, {:?})", p, subpath);
2929
}
3030
Resolution::Specifier(specifier) => {
3131
println!("result = Specifier ({})", specifier);

0 commit comments

Comments
 (0)