-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat: add resolve_id plugin hook #1625
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||||||||||||
use std::fmt; | ||||||||||||||||||
use std::path::{Path, PathBuf}; | ||||||||||||||||||
use std::sync::Arc; | ||||||||||||||||||
|
||||||||||||||||||
use oxc_resolver::PackageJson; | ||||||||||||||||||
|
||||||||||||||||||
#[derive(Clone)] | ||||||||||||||||||
pub struct Resolution { | ||||||||||||||||||
pub path: PathBuf, | ||||||||||||||||||
pub query: Option<String>, | ||||||||||||||||||
pub fragment: Option<String>, | ||||||||||||||||||
pub package_json: Option<Arc<PackageJson>>, | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+7
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议将结构体字段设为私有以增强封装性 当前, |
||||||||||||||||||
|
||||||||||||||||||
impl Resolution { | ||||||||||||||||||
/// Returns the path without query and fragment | ||||||||||||||||||
pub fn path(&self) -> &Path { | ||||||||||||||||||
&self.path | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/// Returns the path without query and fragment | ||||||||||||||||||
pub fn into_path_buf(self) -> PathBuf { | ||||||||||||||||||
self.path | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/// Returns the path query `?query`, contains the leading `?` | ||||||||||||||||||
pub fn query(&self) -> Option<&str> { | ||||||||||||||||||
self.query.as_deref() | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/// Returns the path fragment `#fragment`, contains the leading `#` | ||||||||||||||||||
pub fn fragment(&self) -> Option<&str> { | ||||||||||||||||||
self.fragment.as_deref() | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/// Returns serialized package_json | ||||||||||||||||||
pub fn package_json(&self) -> Option<&Arc<PackageJson>> { | ||||||||||||||||||
self.package_json.as_ref() | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 更新方法注释以反映实际返回值
修改建议: - /// 返回序列化的package_json
+ /// 返回与路径关联的`PackageJson`引用(如果存在)
pub fn package_json(&self) -> Option<&Arc<PackageJson>> {
self.package_json.as_ref()
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
/// Returns the full path with query and fragment | ||||||||||||||||||
pub fn full_path(&self) -> PathBuf { | ||||||||||||||||||
let mut path = self.path.clone().into_os_string(); | ||||||||||||||||||
if let Some(query) = &self.query { | ||||||||||||||||||
path.push(query); | ||||||||||||||||||
} | ||||||||||||||||||
if let Some(fragment) = &self.fragment { | ||||||||||||||||||
path.push(fragment); | ||||||||||||||||||
} | ||||||||||||||||||
PathBuf::from(path) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
impl fmt::Debug for Resolution { | ||||||||||||||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||||||||||||||
f.debug_struct("Resolution") | ||||||||||||||||||
.field("path", &self.path) | ||||||||||||||||||
.field("query", &self.query) | ||||||||||||||||||
.field("fragment", &self.fragment) | ||||||||||||||||||
.field("package_json", &self.package_json.as_ref().map(|p| &p.path)) | ||||||||||||||||||
.finish() | ||||||||||||||||||
} | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('resolve_id mocked'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要支持下 package json 的内容的传递,以保证需要使用报名的场景 or package.json 中 side effects