10
10
from pathlib import Path
11
11
from typing import Any , List , NewType , Optional , Set , Tuple , Union , overload
12
12
13
- from idom .config import IDOM_DEBUG_MODE
13
+ from idom .config import IDOM_DEBUG_MODE , IDOM_WED_MODULES_DIR
14
14
from idom .core .vdom import ImportSourceDict , VdomDictConstructor , make_vdom_constructor
15
15
16
16
from .utils import (
17
+ module_name_suffix ,
17
18
resolve_module_exports_from_file ,
18
19
resolve_module_exports_from_url ,
19
- url_suffix ,
20
- web_module_path ,
21
20
)
22
21
23
22
@@ -59,21 +58,21 @@ def module_from_template(
59
58
) -> WebModule :
60
59
cdn = cdn .rstrip ("/" )
61
60
template_file = (
62
- Path (__file__ ).parent / "templates" / f"{ template } { url_suffix (name )} "
61
+ Path (__file__ ).parent / "templates" / f"{ template } { module_name_suffix (name )} "
63
62
)
64
63
65
64
if not template_file .exists ():
66
65
raise ValueError (f"No template for { template !r} exists" )
67
66
68
- target_file = web_module_path (name )
67
+ target_file = _web_module_path (name )
69
68
if not target_file .exists ():
70
69
target_file .parent .mkdir (parents = True , exist_ok = True )
71
70
target_file .write_text (
72
71
template_file .read_text ().replace ("$PACKAGE" , name ).replace ("$CDN" , cdn )
73
72
)
74
73
75
74
return WebModule (
76
- source = name ,
75
+ source = name + module_name_suffix ( name ) ,
77
76
source_type = NAME_SOURCE ,
78
77
default_fallback = fallback ,
79
78
file = target_file ,
@@ -93,15 +92,15 @@ def module_from_file(
93
92
resolve_exports_depth : int = 5 ,
94
93
) -> WebModule :
95
94
source_file = Path (file )
96
- target_file = web_module_path (name )
95
+ target_file = _web_module_path (name )
97
96
if target_file .exists ():
98
97
if target_file .resolve () != source_file .resolve ():
99
98
raise ValueError (f"{ name !r} already exists as { target_file .resolve ()} " )
100
99
else :
101
100
target_file .parent .mkdir (parents = True , exist_ok = True )
102
101
target_file .symlink_to (source_file )
103
102
return WebModule (
104
- source = name ,
103
+ source = name + module_name_suffix ( name ) ,
105
104
source_type = NAME_SOURCE ,
106
105
default_fallback = fallback ,
107
106
file = target_file ,
@@ -180,3 +179,9 @@ def _make_export(
180
179
fallback = (fallback or web_module .default_fallback ),
181
180
),
182
181
)
182
+
183
+
184
+ def _web_module_path (name : str ) -> Path :
185
+ name += module_name_suffix (name )
186
+ path = IDOM_WED_MODULES_DIR .current .joinpath (* name .split ("/" ))
187
+ return path .with_suffix (path .suffix )
0 commit comments