1212CORE_MODULES = CLIENT_DIR / "core_modules"
1313NODE_MODULES = CLIENT_DIR / "node_modules"
1414WEB_MODULES = CLIENT_DIR / "web_modules"
15- USER_MODULES = CLIENT_DIR / "user_modules"
1615
1716
18- def import_path (prefix : str , name : str ) -> str :
19- path = f"../{ prefix } /{ name } .js"
20- if not module_exists (prefix , name ):
17+ def import_path (name : str ) -> str :
18+ path = f"../{ WEB_MODULES . name } /{ name } .js"
19+ if not module_exists (name ):
2120 raise ValueError (f"Module '{ path } ' does not exist." )
2221 return path
2322
2423
2524def define_module (name : str , source : str ) -> str :
26- path = _create_module_os_path ( USER_MODULES , name )
25+ path = _create_web_module_os_path ( name )
2726 with path .open ("w+" ) as f :
2827 f .write (source )
29- return import_path ("user_modules" , name )
28+ return import_path (name )
3029
3130
32- def delete_module (prefix : str , name : str ) -> None :
33- path = _find_module_os_path ( prefix , name )
31+ def delete_module (name : str ) -> None :
32+ path = _find_web_module_os_path ( name )
3433 if path is None :
35- raise ValueError (f"Module '{ import_path ( prefix , name ) } ' does not exist." )
34+ raise ValueError (f"Module '{ name } ' does not exist." )
3635 _delete_os_paths (path )
3736
3837
39- def module_exists (prefix : Union [ str , Path ], name : str ) -> bool :
40- return _find_module_os_path ( prefix , name ) is not None
38+ def module_exists (name : str ) -> bool :
39+ return _find_web_module_os_path ( name ) is not None
4140
4241
4342def install (dependencies : Dict [str , str ]) -> None :
@@ -65,7 +64,7 @@ def install(dependencies: Dict[str, str]) -> None:
6564
6665
6766def restore () -> None :
68- _delete_os_paths (WEB_MODULES , NODE_MODULES , USER_MODULES )
67+ _delete_os_paths (WEB_MODULES , NODE_MODULES )
6968 _run_subprocess (["npm" , "install" ], CLIENT_DIR )
7069 _run_subprocess (["npm" , "run" , "snowpack" ], CLIENT_DIR )
7170
@@ -99,11 +98,8 @@ def _run_subprocess(args: List[str], cwd: Union[str, Path]):
9998 raise
10099
101100
102- def _find_module_os_path (prefix : Union [str , Path ], name : str ) -> Optional [Path ]:
103- if isinstance (prefix , str ):
104- path = CLIENT_DIR / prefix
105- else :
106- path = prefix
101+ def _find_web_module_os_path (name : str ) -> Optional [Path ]:
102+ path = WEB_MODULES
107103 for name_part in name .split ("/" ):
108104 if not path .is_dir ():
109105 return None
@@ -114,11 +110,8 @@ def _find_module_os_path(prefix: Union[str, Path], name: str) -> Optional[Path]:
114110 return full_path
115111
116112
117- def _create_module_os_path (prefix : Union [str , Path ], name : str ) -> Path :
118- if isinstance (prefix , str ):
119- path = CLIENT_DIR / prefix
120- else :
121- path = prefix
113+ def _create_web_module_os_path (name : str ) -> Path :
114+ path = WEB_MODULES
122115 for n in name .split ("/" ):
123116 if not path .exists ():
124117 path .mkdir ()
0 commit comments