@@ -12,7 +12,7 @@ use std::{
12
12
13
13
use napi:: { Task , bindgen_prelude:: AsyncTask } ;
14
14
use napi_derive:: napi;
15
- use oxc_resolver:: { PackageJson , ResolveOptions , Resolver } ;
15
+ use oxc_resolver:: { PackageJson , ResolveError , ResolveOptions , Resolver } ;
16
16
17
17
use self :: options:: { NapiResolveOptions , StrOrStrList } ;
18
18
@@ -24,6 +24,7 @@ mod tracing;
24
24
pub struct ResolveResult {
25
25
pub path : Option < String > ,
26
26
pub error : Option < String > ,
27
+ pub builtin : Option < Builtin > ,
27
28
/// Module type for this path.
28
29
///
29
30
/// Enable with `ResolveOptions#moduleType`.
@@ -37,23 +38,47 @@ pub struct ResolveResult {
37
38
pub package_json_path : Option < String > ,
38
39
}
39
40
41
+ /// Node.js builtin module when `Options::builtin_modules` is enabled.
42
+ #[ napi( object) ]
43
+ pub struct Builtin {
44
+ /// Resolved module.
45
+ ///
46
+ /// Always prefixed with "node:" in compliance with the ESM specification.
47
+ pub resolved : String ,
48
+
49
+ /// Whether the request was prefixed with `node:` or not.
50
+ /// `fs` -> `false`.
51
+ /// `node:fs` returns `true`.
52
+ pub is_runtime_module : bool ,
53
+ }
54
+
40
55
fn resolve ( resolver : & Resolver , path : & Path , request : & str ) -> ResolveResult {
41
56
match resolver. resolve ( path, request) {
42
57
Ok ( resolution) => ResolveResult {
43
58
path : Some ( resolution. full_path ( ) . to_string_lossy ( ) . to_string ( ) ) ,
44
59
error : None ,
60
+ builtin : None ,
45
61
module_type : resolution. module_type ( ) . map ( ModuleType :: from) ,
46
62
package_json_path : resolution
47
63
. package_json ( )
48
64
. and_then ( |p| p. path ( ) . to_str ( ) )
49
65
. map ( |p| p. to_string ( ) ) ,
50
66
} ,
51
- Err ( err) => ResolveResult {
52
- path : None ,
53
- module_type : None ,
54
- error : Some ( err. to_string ( ) ) ,
55
- package_json_path : None ,
56
- } ,
67
+ Err ( err) => {
68
+ let error = err. to_string ( ) ;
69
+ ResolveResult {
70
+ path : None ,
71
+ builtin : match err {
72
+ ResolveError :: Builtin { resolved, is_runtime_module } => {
73
+ Some ( Builtin { resolved, is_runtime_module } )
74
+ }
75
+ _ => None ,
76
+ } ,
77
+ module_type : None ,
78
+ error : Some ( error) ,
79
+ package_json_path : None ,
80
+ }
81
+ }
57
82
}
58
83
}
59
84
@@ -250,11 +275,11 @@ impl ResolverFactory {
250
275
symlinks : op. symlinks . unwrap_or ( default. symlinks ) ,
251
276
builtin_modules : op. builtin_modules . unwrap_or ( default. builtin_modules ) ,
252
277
module_type : op. module_type . unwrap_or ( default. module_type ) ,
253
- #[ cfg( feature = "yarn_pnp" ) ]
254
- pnp_manifest : default. pnp_manifest ,
255
278
allow_package_exports_in_directory_resolve : op
256
279
. allow_package_exports_in_directory_resolve
257
280
. unwrap_or ( default. allow_package_exports_in_directory_resolve ) ,
281
+ #[ cfg( feature = "yarn_pnp" ) ]
282
+ pnp_manifest : default. pnp_manifest ,
258
283
}
259
284
}
260
285
}
0 commit comments