2
2
3
3
use std:: borrow:: Cow ;
4
4
use std:: collections:: HashMap ;
5
+ use std:: path:: PathBuf ;
5
6
use std:: sync:: atomic:: AtomicBool ;
6
7
use std:: sync:: Arc ;
7
8
@@ -11,6 +12,7 @@ use deno_config::deno_json::ConfigFileRc;
11
12
use deno_config:: workspace:: Workspace ;
12
13
use deno_config:: workspace:: WorkspaceDirectory ;
13
14
use deno_core:: anyhow:: bail;
15
+ use deno_core:: anyhow:: Context ;
14
16
use deno_core:: error:: AnyError ;
15
17
use deno_core:: futures:: future:: try_join;
16
18
use deno_core:: futures:: stream:: FuturesOrdered ;
@@ -43,10 +45,10 @@ use crate::npm::NpmFetchResolver;
43
45
44
46
use super :: ConfigUpdater ;
45
47
46
- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
48
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
47
49
pub enum ImportMapKind {
48
50
Inline ,
49
- Outline ,
51
+ Outline ( PathBuf ) ,
50
52
}
51
53
52
54
#[ derive( Clone ) ]
@@ -62,9 +64,12 @@ impl DepLocation {
62
64
63
65
pub fn file_path ( & self ) -> Cow < std:: path:: Path > {
64
66
match self {
65
- DepLocation :: DenoJson ( arc, _, _) => {
66
- Cow :: Owned ( arc. specifier . to_file_path ( ) . unwrap ( ) )
67
- }
67
+ DepLocation :: DenoJson ( arc, _, kind) => match kind {
68
+ ImportMapKind :: Inline => {
69
+ Cow :: Owned ( arc. specifier . to_file_path ( ) . unwrap ( ) )
70
+ }
71
+ ImportMapKind :: Outline ( path) => Cow :: Borrowed ( path. as_path ( ) ) ,
72
+ } ,
68
73
DepLocation :: PackageJson ( arc, _) => Cow :: Borrowed ( arc. path . as_ref ( ) ) ,
69
74
}
70
75
}
@@ -238,22 +243,30 @@ fn to_import_map_value_from_imports(
238
243
fn deno_json_import_map (
239
244
deno_json : & ConfigFile ,
240
245
) -> Result < Option < ( ImportMapWithDiagnostics , ImportMapKind ) > , AnyError > {
241
- let ( value, kind) =
242
- if deno_json. json . imports . is_some ( ) || deno_json. json . scopes . is_some ( ) {
243
- (
244
- to_import_map_value_from_imports ( deno_json) ,
245
- ImportMapKind :: Inline ,
246
- )
247
- } else {
248
- match deno_json. to_import_map_path ( ) ? {
249
- Some ( path) => {
250
- let text = std:: fs:: read_to_string ( & path) ?;
251
- let value = serde_json:: from_str ( & text) ?;
252
- ( value, ImportMapKind :: Outline )
253
- }
254
- None => return Ok ( None ) ,
246
+ let ( value, kind) = if deno_json. json . imports . is_some ( )
247
+ || deno_json. json . scopes . is_some ( )
248
+ {
249
+ (
250
+ to_import_map_value_from_imports ( deno_json) ,
251
+ ImportMapKind :: Inline ,
252
+ )
253
+ } else {
254
+ match deno_json. to_import_map_path ( ) ? {
255
+ Some ( path) => {
256
+ let err_context = || {
257
+ format ! (
258
+ "loading import map at '{}' (from \" importMap\" field in '{}')" ,
259
+ path. display( ) ,
260
+ deno_json. specifier
261
+ )
262
+ } ;
263
+ let text = std:: fs:: read_to_string ( & path) . with_context ( err_context) ?;
264
+ let value = serde_json:: from_str ( & text) . with_context ( err_context) ?;
265
+ ( value, ImportMapKind :: Outline ( path) )
255
266
}
256
- } ;
267
+ None => return Ok ( None ) ,
268
+ }
269
+ } ;
257
270
258
271
import_map:: parse_from_value ( deno_json. specifier . clone ( ) , value)
259
272
. map_err ( Into :: into)
@@ -303,7 +316,7 @@ fn add_deps_from_deno_json(
303
316
location : DepLocation :: DenoJson (
304
317
deno_json. clone ( ) ,
305
318
key_path,
306
- import_map_kind,
319
+ import_map_kind. clone ( ) ,
307
320
) ,
308
321
kind,
309
322
req,
@@ -747,11 +760,7 @@ impl DepManager {
747
760
let dep = & mut self . deps [ dep_id. 0 ] ;
748
761
dep. req . version_req = version_req. clone ( ) ;
749
762
match & dep. location {
750
- DepLocation :: DenoJson ( arc, key_path, import_map_kind) => {
751
- if matches ! ( import_map_kind, ImportMapKind :: Outline ) {
752
- // not supported
753
- continue ;
754
- }
763
+ DepLocation :: DenoJson ( arc, key_path, _) => {
755
764
let updater =
756
765
get_or_create_updater ( & mut config_updaters, & dep. location ) ?;
757
766
0 commit comments