nodejs_resolver/
resource.rs1use crate::{description::DescriptionData, info::Info, Resolver};
2use std::{path::PathBuf, sync::Arc};
3
4#[derive(Debug, Clone)]
5pub struct Resource {
6 pub path: PathBuf,
7 pub query: Option<String>,
8 pub fragment: Option<String>,
9 pub description: Option<Arc<DescriptionData>>,
10}
11
12impl Resource {
13 pub(crate) fn new(info: Info, resolver: &Resolver) -> Self {
14 let path = info.normalized_path().as_ref().to_path_buf();
15 let query = info.request().query();
16 let fragment = info.request().fragment();
17 let description = resolver
18 .load_entry(&path)
19 .pkg_info(resolver)
20 .unwrap()
21 .clone();
22 Resource {
23 path,
24 query: (!query.is_empty()).then(|| query.into()),
25 fragment: (!fragment.is_empty()).then(|| fragment.into()),
26 description,
27 }
28 }
29
30 pub fn join(&self) -> PathBuf {
31 let mut buf = format!("{}", self.path.display());
32 if let Some(query) = self.query.as_ref() {
33 buf.push_str(query);
34 }
35 if let Some(fragment) = self.fragment.as_ref() {
36 buf.push_str(fragment);
37 }
38 PathBuf::from(buf)
39 }
40}