File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -60,14 +60,20 @@ def add_web_module(
6060 source : Union [Path , str ],
6161) -> None :
6262 """Add a web module from source"""
63- if web_module_exists (package_name ):
64- raise ValueError (f"Web module { package_name !r} already exists" )
65- source = Path (source )
66- if not source .exists ():
63+ resolved_source = Path (source ).resolve ()
64+ if not resolved_source .exists ():
6765 raise FileNotFoundError (f"Package source file does not exist: { str (source )!r} " )
6866 target = web_module_path (package_name )
67+ if target .resolve () == resolved_source :
68+ return None # already added
6969 target .parent .mkdir (parents = True , exist_ok = True )
70- target .symlink_to (source .absolute ())
70+ # this will raise an error if already exists
71+ target .symlink_to (resolved_source )
72+
73+
74+ def remove_web_module (package_name : str , must_exist : bool = False ) -> None :
75+ """Remove a web module"""
76+ web_module_path (package_name , must_exist ).unlink ()
7177
7278
7379def restore () -> None :
Original file line number Diff line number Diff line change 44from idom .client .manage import (
55 add_web_module ,
66 build ,
7+ remove_web_module ,
78 restore ,
89 web_module_exists ,
910 web_module_exports ,
@@ -31,11 +32,25 @@ def test_add_web_module_source_must_exist(tmp_path):
3132
3233
3334def test_cannot_add_web_module_if_already_exists (tmp_path ):
35+ first_temp_file = tmp_path / "temp-1.js"
36+ second_temp_file = tmp_path / "temp-2.js"
37+
38+ first_temp_file .write_text ("console.log('hello!')" ) # this won't get run
39+ second_temp_file .write_text ("console.log('hello!')" ) # this won't get run
40+
41+ add_web_module ("test" , first_temp_file )
42+ with pytest .raises (FileExistsError ):
43+ add_web_module ("test" , second_temp_file )
44+
45+ remove_web_module ("test" )
46+
47+
48+ def test_can_add_web_module_if_already_exists_and_source_is_same (tmp_path ):
3449 temp_file = tmp_path / "temp.js"
35- temp_file .write_text ("console.log('hello!')" ) # this won't get run
50+ temp_file .write_text ("console.log('hello!')" )
51+ add_web_module ("test" , temp_file )
3652 add_web_module ("test" , temp_file )
37- with pytest .raises (ValueError , match = "already exists" ):
38- add_web_module ("test" , temp_file )
53+ remove_web_module ("test" )
3954
4055
4156def test_web_module_path_must_exist ():
You can’t perform that action at this time.
0 commit comments