@@ -57,8 +57,18 @@ def build(config_items: Iterable[ConfigItem] = ()) -> None:
5757 py_pkg_configs , errors = find_python_packages_build_config_items ()
5858 for e in errors : # pragma: no cover
5959 console .echo (f"{ e } because { e .__cause__ } " , message_color = "red" )
60- config .update (py_pkg_configs + list (config_items ))
60+ config .update_items (py_pkg_configs + list (config_items ))
61+ _build_and_save_config ()
6162
63+
64+ def restore () -> None :
65+ config = build_config ()
66+ config .clear_items ()
67+ _build_and_save_config ()
68+
69+
70+ def _build_and_save_config () -> None :
71+ config = build_config ()
6272 with TemporaryDirectory () as tempdir :
6373 tempdir_path = Path (tempdir )
6474 temp_app_dir = tempdir_path / "app"
@@ -72,9 +82,15 @@ def build(config_items: Iterable[ConfigItem] = ()) -> None:
7282
7383 with open_modifiable_json (package_json_path ) as package_json :
7484 snowpack_config = package_json .setdefault ("snowpack" , {})
85+
7586 snowpack_install = snowpack_config .setdefault ("install" , [])
7687 snowpack_install .extend (config .all_js_dependency_names ())
7788
89+ snowpack_build = snowpack_config .setdefault ("buildOptions" , {})
90+ snowpack_build ["clean" ] = True
91+
92+ console .echo (f"Current config: { config .data } " , debug = True )
93+
7894 with console .spinner (
7995 f"Installing { len (packages_to_install )} dependencies"
8096 if packages_to_install
@@ -89,20 +105,9 @@ def build(config_items: Iterable[ConfigItem] = ()) -> None:
89105 shutil .rmtree (BUILD_DIR )
90106
91107 shutil .copytree (temp_build_dir , BUILD_DIR , symlinks = True )
92-
93- print (BUILD_DIR .exists ())
94-
95108 config .save ()
96109
97110
98- def restore () -> None :
99- with console .spinner ("Restoring" ):
100- if BUILD_DIR .exists ():
101- shutil .rmtree (BUILD_DIR )
102- _run_subprocess (["npm" , "install" ], APP_DIR )
103- _run_subprocess (["npm" , "run" , "build" ], APP_DIR )
104-
105-
106111def _get_web_module_name_and_file_path (
107112 source_name : str , package_name : str
108113) -> Tuple [str , Path ]:
@@ -111,12 +116,12 @@ def _get_web_module_name_and_file_path(
111116 raise WebModuleError (
112117 f"Package { package_name !r} is not declared as a dependency of { source_name !r} "
113118 )
114- builtin_path = BUILD_DIR .joinpath ("web_modules" , * f"{ pkg_name } .js" .split ("/" ))
115- if not builtin_path .exists ():
119+ build_path = BUILD_DIR .joinpath ("web_modules" , * f"{ pkg_name } .js" .split ("/" ))
120+ if not build_path .exists ():
116121 raise WebModuleError (
117122 f"Dependency { package_name !r} of { source_name !r} was not installed"
118123 )
119- return pkg_name , builtin_path
124+ return pkg_name , build_path
120125
121126
122127def _npm_install (packages : Sequence [str ], cwd : Path ) -> None :
@@ -132,6 +137,6 @@ def _run_subprocess(args: List[str], cwd: Path) -> None:
132137 subprocess .run (
133138 args , cwd = cwd , check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE
134139 )
135- except subprocess .CalledProcessError as error :
140+ except subprocess .CalledProcessError as error : # pragma: no cover
136141 raise subprocess .SubprocessError (error .stderr .decode ()) from error
137142 return None
0 commit comments