Skip to content

Commit 3c918d3

Browse files
authored
Merge pull request #12 from insistence/feat-skip_build
feat: add `skip_build` parameter to control build execution
1 parent 50da1b0 commit 3c918d3

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

README-zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ VitePlugin 是负责管理 Vite 构建过程的主要插件类。
131131
| download_node | bool | False | 如果未找到是否下载 Node.js |
132132
| node_version | str | '18.17.0' | 要下载的 Node.js 版本 |
133133
| clean_after | bool | False | 构建后是否清理生成的文件 |
134+
| skip_build | bool | False | 是否跳过构建执行 |
134135
| skip_build_if_recent | bool | True | 如果构建文件是最近生成的是否跳过构建 |
135136
| skip_build_time_threshold | int | 5 | 考虑构建文件为最近的时间阈值(秒)|
136137

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ VitePlugin is the main plugin class responsible for managing the Vite build proc
130130
| download_node | bool | False | Whether to download Node.js if not found |
131131
| node_version | str | '18.17.0' | Node.js version to download |
132132
| clean_after | bool | False | Whether to clean up generated files after build |
133+
| skip_build | bool | False | Whether to skip build execution |
133134
| skip_build_if_recent | bool | True | Whether to skip build if built file was recently generated |
134135
| skip_build_time_threshold | int | 5 | Time threshold in seconds to consider built file as recent |
135136

dash_vite_plugin/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(
2929
download_node: bool = False,
3030
node_version: str = '18.20.8',
3131
clean_after: bool = False,
32+
skip_build: bool = False,
3233
skip_build_if_recent: bool = True,
3334
skip_build_time_threshold: int = 5,
3435
) -> None:
@@ -45,6 +46,7 @@ def __init__(
4546
download_node (bool): Whether to download Node.js if not found
4647
node_version (str): Node.js version to download if download_node is True
4748
clean_after (bool): Whether to clean up generated files after build
49+
skip_build (bool): Whether to skip build execution
4850
skip_build_if_recent (bool): Whether to skip build if built file was recently generated
4951
skip_build_time_threshold (int): Time threshold in seconds to consider built file as recent
5052
"""
@@ -57,6 +59,7 @@ def __init__(
5759
self.download_node = download_node
5860
self.node_version = node_version
5961
self.clean_after = clean_after
62+
self.skip_build = skip_build
6063
self.skip_build_if_recent = skip_build_if_recent
6164
self.skip_build_time_threshold = skip_build_time_threshold
6265
self.vite_command = ViteCommand(
@@ -194,6 +197,8 @@ def _should_skip_build(self) -> bool:
194197
Returns:
195198
bool: True if the build should be skipped, False otherwise
196199
"""
200+
if self.skip_build:
201+
return True
197202
# Check if CSS file exists and was generated recently (within threshold seconds)
198203
check_index_path = os.path.join(self.plugin_tmp_dir, 'dist', 'index.html')
199204
if self.skip_build_if_recent and os.path.exists(check_index_path):

tests/test_plugin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_plugin_initialization(self):
4242
assert plugin.clean_after is False
4343
assert plugin.skip_build_if_recent is True
4444
assert plugin.skip_build_time_threshold == 5
45+
assert plugin.skip_build is False
4546

4647
def test_plugin_initialization_with_custom_parameters(self):
4748
"""Test plugin initialization with custom parameters."""
@@ -59,6 +60,7 @@ def test_plugin_initialization_with_custom_parameters(self):
5960
download_node=True,
6061
node_version='20.0.0',
6162
clean_after=True,
63+
skip_build=True,
6264
skip_build_if_recent=False,
6365
skip_build_time_threshold=10,
6466
)
@@ -72,6 +74,7 @@ def test_plugin_initialization_with_custom_parameters(self):
7274
assert plugin.download_node is True
7375
assert plugin.node_version == '20.0.0'
7476
assert plugin.clean_after is True
77+
assert plugin.skip_build is True
7578
assert plugin.skip_build_if_recent is False
7679
assert plugin.skip_build_time_threshold == 10
7780

@@ -399,6 +402,25 @@ def test_extract_assets_tags_no_file(self):
399402
# Should return empty string
400403
assert tags == ''
401404

405+
def test_skip_build_param(self):
406+
"""Test the skip build logic when skip_build param is True."""
407+
build_assets_paths = ['assets/js']
408+
entry_js_paths = ['assets/js/main.js']
409+
npm_packages = [NpmPackage('react')]
410+
411+
plugin = VitePlugin(
412+
build_assets_paths=build_assets_paths,
413+
entry_js_paths=entry_js_paths,
414+
npm_packages=npm_packages,
415+
skip_build=True,
416+
)
417+
418+
# Check the skip logic directly
419+
should_skip = plugin._should_skip_build()
420+
421+
# Should be True
422+
assert should_skip is True
423+
402424
def test_skip_build_logic_recent_file(self):
403425
"""Test the skip build logic when file is recent."""
404426
build_assets_paths = ['assets/js']

0 commit comments

Comments
 (0)