From 4fb9fc1fa48ed46ccfd4012789ea4b246fc87703 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 14 Jan 2026 15:20:02 +0800 Subject: [PATCH] fix: fix Windows console display issues caused by unspecified encoding --- dash_vite_plugin/utils.py | 41 ++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/dash_vite_plugin/utils.py b/dash_vite_plugin/utils.py index c9f5670..5700436 100644 --- a/dash_vite_plugin/utils.py +++ b/dash_vite_plugin/utils.py @@ -163,7 +163,9 @@ def _check_vite(self) -> bool: """ check_cmd = [self.npx_path, 'vite --help'] - result = subprocess.run(check_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env) + result = subprocess.run( + check_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env, encoding='utf-8' + ) return result.returncode == 0 def _check_npm_package(self, package_name: str, package_type: Literal['devDependencies', 'dependencies']) -> bool: @@ -225,7 +227,12 @@ def _install_vite(self) -> None: '@vitejs/plugin-vue', ] result = subprocess.run( - install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + install_cmd, + capture_output=True, + text=True, + cwd=self.plugin_tmp_dir, + env=self.node_env, + encoding='utf-8', ) if result.returncode != 0: raise RuntimeError(result.stderr) @@ -253,7 +260,12 @@ def _install_less(self) -> None: 'less', ] result = subprocess.run( - install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + install_cmd, + capture_output=True, + text=True, + cwd=self.plugin_tmp_dir, + env=self.node_env, + encoding='utf-8', ) if result.returncode != 0: raise RuntimeError(result.stderr) @@ -281,7 +293,12 @@ def _install_sass(self) -> None: 'sass', ] result = subprocess.run( - install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + install_cmd, + capture_output=True, + text=True, + cwd=self.plugin_tmp_dir, + env=self.node_env, + encoding='utf-8', ) if result.returncode != 0: raise RuntimeError(result.stderr) @@ -309,7 +326,12 @@ def _install_npm_packages(self) -> None: f'{package.name}@{package.version}', ] result = subprocess.run( - install_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + install_cmd, + capture_output=True, + text=True, + cwd=self.plugin_tmp_dir, + env=self.node_env, + encoding='utf-8', ) if result.returncode != 0: raise RuntimeError(result.stderr) @@ -353,7 +375,12 @@ def init(self) -> Self: if not self._check_npm_init(): init_cmd = [self.npm_path, 'init', '-y'] result = subprocess.run( - init_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + init_cmd, + capture_output=True, + text=True, + cwd=self.plugin_tmp_dir, + env=self.node_env, + encoding='utf-8', ) if result.returncode != 0: raise RuntimeError(result.stderr) @@ -394,7 +421,7 @@ def build(self) -> Self: build_cmd: List[str] = [self.npx_path, 'vite', 'build'] result = subprocess.run( - build_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env + build_cmd, capture_output=True, text=True, cwd=self.plugin_tmp_dir, env=self.node_env, encoding='utf-8' ) if result.returncode != 0: