@@ -725,6 +725,24 @@ impl ConfigFile {
725
725
self . json . unstable . iter ( ) . any ( |v| v == name)
726
726
}
727
727
728
+ /// Resolve the export values in a config file to their URLs.
729
+ pub fn resolve_export_value_urls ( & self ) -> Result < Vec < Url > , AnyError > {
730
+ let exports_config = self
731
+ . to_exports_config ( )
732
+ . with_context ( || {
733
+ format ! ( "Failed to parse exports at {}" , self . specifier)
734
+ } ) ?
735
+ . into_map ( ) ;
736
+ let mut exports = Vec :: with_capacity ( exports_config. len ( ) ) ;
737
+ for ( _, value) in exports_config {
738
+ let entry_point = self . specifier . join ( & value) . with_context ( || {
739
+ format ! ( "Failed to join {} with {}" , self . specifier, value)
740
+ } ) ?;
741
+ exports. push ( entry_point) ;
742
+ }
743
+ Ok ( exports)
744
+ }
745
+
728
746
pub fn to_exports_config ( & self ) -> Result < ExportsConfig , AnyError > {
729
747
fn has_extension ( value : & str ) -> bool {
730
748
let search_text = & value[ value. rfind ( '/' ) . unwrap_or ( 0 ) ..] ;
@@ -2140,6 +2158,44 @@ mod tests {
2140
2158
) ;
2141
2159
}
2142
2160
2161
+ #[ test]
2162
+ fn resolve_export_value_urls ( ) {
2163
+ fn get_exports ( config_text : & str ) -> Vec < String > {
2164
+ let config_dir = Url :: parse ( "file:///deno/" ) . unwrap ( ) ;
2165
+ let config_specifier = config_dir. join ( "tsconfig.json" ) . unwrap ( ) ;
2166
+ let config_file = ConfigFile :: new ( config_text, config_specifier) . unwrap ( ) ;
2167
+ config_file
2168
+ . resolve_export_value_urls ( )
2169
+ . unwrap ( )
2170
+ . into_iter ( )
2171
+ . map ( |u| u. to_string ( ) )
2172
+ . collect ( )
2173
+ }
2174
+
2175
+ // no exports
2176
+ assert_eq ! ( get_exports( "{}" ) , Vec :: <String >:: new( ) ) ;
2177
+ // string export
2178
+ assert_eq ! (
2179
+ get_exports( r#"{ "exports": "./mod.ts" }"# ) ,
2180
+ vec![ "file:///deno/mod.ts" . to_string( ) ]
2181
+ ) ;
2182
+ // map export
2183
+ assert_eq ! (
2184
+ get_exports( r#"{ "exports": { "./export": "./mod.ts" } }"# ) ,
2185
+ vec![ "file:///deno/mod.ts" . to_string( ) ]
2186
+ ) ;
2187
+ // multiple
2188
+ assert_eq ! (
2189
+ get_exports(
2190
+ r#"{ "exports": { "./export": "./mod.ts", "./other": "./other.ts" } }"#
2191
+ ) ,
2192
+ vec![
2193
+ "file:///deno/mod.ts" . to_string( ) ,
2194
+ "file:///deno/other.ts" . to_string( ) ,
2195
+ ]
2196
+ ) ;
2197
+ }
2198
+
2143
2199
#[ test]
2144
2200
fn test_empty_workspaces ( ) {
2145
2201
let config_text = r#"{
0 commit comments